接下来要了解的结构体为struct device_attribute,该结构体的定义在include /linux/device.h,其定义如下: /*interface for exporting device attributes*/structdevice_attribute {structattribute attr; ssize_t (*show)(structdevice *dev,structdevice_attribute *attr,char*buf); ssize_t (*store)(structdevice *...
使用DEVICE_ATTR宏,可以定义一个struct device_attribute设备属性,使用函数sysfs_create_group或sysfs_create_file便可以在设备目录下创建具有show和store方法的节点。能方便的进行调试。 一、使用DEVICE_ATTR构建device attribute 下面将顺着我们直接使用的DEVICE_ATTR来分析一下,这个宏究竟都做了哪些事情。 DEVICE_ATTR的...
宏DEVICE_ATTR实现的功能就是定义了一个struct device_attribute结构体变量dev_attr_name,并对里面的成员进行初始化,包括struct attribute结构体里面的name和mode成员变量,然后还有实现属性文件读写的show和store函数赋值。 案例: //读操作staticssize_tmydevice_show(structdevice*dev,structdevice_attribute*attr,char*bu...
void (*shutdown) (struct device *dev); int (*suspend) (struct device *dev, pm_message_t state); int (*resume) (struct device *dev); const struct attribute_group **groups; const struct attribute_group **dev_groups; const struct dev_pm_ops *pm; void (*coredump) (struct device *dev...
static const struct attribute_group *dev_groups[] = { &dev_group, NULL, }; 辅助宏可用于单个组的常见情况,因此可以使用 :: 声明上述两个结构: ATTRIBUTE_GROUPS(dev); 然后可以通过在调用 device_register() 之前在 struct device 中设置组指针,将这个组数组与设备相关联 ...
error = device_create_file(dev, &dev_attr_uevent); dev_attr_uevent是一个struct device_attribute类型的数据,该结构用于描述导出设备属性的接口,定义如下: struct device_attribute { struct attribute attr; ssize_t (*show)(struct device *dev, struct device_attribute *attr, ...
u32 id; /* device instance */ spinlock_t devres_lock; struct list_head devres_head; struct klist_node knode_class; struct class *class; const struct attribute_group **groups; /* optional groups */ void (*release)(struct device *dev); ...
原型是#define DEVICE_ATTR(_name, _mode, _show, _store) \ struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) 函数宏DEVICE_ATTR内封装的是__ATTR(_name,_mode,_show,_stroe)方法,_show表示的是读方法,_stroe表示的是写方法。
DEVICE_ATTR()定义位于include/linux/device.h中,定义如下所示: 代码语言:javascript 复制 #defineDEVICE_ATTR(_name,_mode,_show,_store)\ struct device_attribute dev_attr_##_name=__ATTR(_name,_mode,_show,_store) 其中_mode定义如下: 400 拥有者能够读,其他任何人不能进行任何操作; ...
structdevice*dev_root;//指向该总线上所有设备的链表的头指针 constchar*drvsubdir;//存储设备驱动程序的子目录的名称 conststructattribute_group**bus_groups;//总线类型的属性组 conststructattribute_group**dev_groups;//总线上所有设备的属性组 };