linux驱动模型中的 DEVICE_ATTR 宏分析
来源:互联网 发布:程序员鼓励师是真的吗 编辑:程序博客网 时间:2024/05/20 05:27
定义于 "include/linux/device.h" 文件中:
#define DEVICE_ATTR(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
而 "kernel/include/linux/sysfs.h" 也定义了 __ATTR , 这个宏被多个设备模型的宏使用到了。
/**
* Use these macros to make defining attributes easier. See include/linux/device.h
* for examples..
*/
#define __ATTR(_name,_mode,_show,_store) { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.show = _show, \
.store = _store, \
}
#define __ATTR_RO(_name) { \
.attr = { .name = __stringify(_name), .mode = 0444 }, \
.show = _name##_show, \
}
#define __ATTR_NULL { .attr = { .name = NULL } }
#define attr_name(_attr) (_attr).attr.name
sysfs.h 也定义了 struct attribute
/* FIXME
* The *owner field is no longer used.
* x86 tree has been cleaned up. The owner
* attribute is still left for other arches.
*/
struct attribute {
const char *name;
struct module *owner;
mode_t mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key *key;
struct lock_class_key skey;
#endif
};
struct device_attribute 也 定义于 "include/linux/device.h" 文件中:
/* interface for exporting device attributes */
struct device_attribute {
struct attribute attr;
ssize_t (*show)(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count);
};
所以, DEVICE_ATTR 这个宏实际上是定义并初始化了一个 名叫 “dev_attr_##_name”的 struct device_attribute 类型的结构体。
关于mode_t这个类型
include/linux/types.h:
typedef __kernel_mode_t mode_t;
arch/arm/include/asm/posix_types.h
typedef unsigned short __kernel_mode_t;
实际上 mode_t 这个类型,就是 unsigned short
include/asm-generic/posix_types.h
typedef unsigned int __kernel_mode_t; // 因为我们的平台是arm架构的所以,用的应该是“arch/arm/include/asm/posix_types.h” 这个文件对__kernel_mode_t的定义。
include/asm-generic/types.h
typedef unsigned short umode_t;
arch/arm/include/asm/types.h
typedef unsigned short umode_t;
- linux驱动模型中的 DEVICE_ATTR 宏分析
- DEVICE_ATTR分析
- linux驱动模型分析总括
- linux MISC 驱动模型分析
- linux platform 驱动模型分析
- linux RTC 驱动模型分析
- linux platform 驱动模型分析
- Linux RTC 驱动模型分析
- linux platform 驱动模型分析
- linux MISC 驱动模型分析
- linux platform 驱动模型分析
- linux platform 驱动模型分析
- Linux platform驱动模型分析
- linux MISC 驱动模型分析
- linux platform 驱动模型分析
- linux RTC 驱动模型分析
- linux MISC 驱动模型分析
- linux RTC 驱动模型分析
- iPhone: Duplicate Symbol Error?
- oracle中 count(1) 是什么意思
- ARC , event,UIScrillView
- windows下32位汇编语言学习笔记
- 大学是用来做什么的
- linux驱动模型中的 DEVICE_ATTR 宏分析
- linux学习入门15——网络原理(linuxcast.net)(网络编址,IP,ARP,DNS,域名)
- 解决linux/config.h: No such file or directory
- VC++ CDC::Arc 汉化参数明说及举例
- 开源Web开发资源
- 类设计的5个基本原则
- Jeecg,值得推荐的j2ee快速开发框架
- [raspberry pi] 树莓派 Kernel 编译笔记
- MFC Paint的流程