Linux 内核设备属性

sysfs 中的设备入口可有属性. 相关的结构是:

struct device_attribute { struct attribute attr;

ssize_t (*show)(struct device *dev, char *buf); ssize_t (*store)(struct device *dev, const char *buf, size_t count);

};

这些属性结构可在编译时建立, 使用这些宏: DEVICE_ATTR(name, mode, show, store);

结果结构通过前缀 dev_attr_ 到给定名子上来命名. 属性文件的实际管理使用通常的函 数对来处理:

int device_create_file(struct device *device, struct device_attribute *entry); void device_remove_file(struct device *dev, struct device_attribute *attr);

struct bus_type 的 dev_attrs 成员指向一个缺省的属性列表, 这些属性给添加到总线 的每个设备创建.

原文地址:https://www.cnblogs.com/fanweisheng/p/11147953.html