文章目录
1.sysfs(属性)文件的创建、读、写
1.1 创建流程
device_add -》 error = device_create_file(dev, &dev_attr_dev);
先来看看 dev_attr_dev 的定义
static DEVICE_ATTR_RO(dev);
637 #define DEVICE_ATTR_RO(_name) \
638 struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
定义了一个 device_attribute 实例,变量名为 dev_attr_dev
__ATTR_RO 定义为:
624 ./include/linux/sysfs.h
625 #define __ATTR_RO(_name) {
\
626 .attr = {
.name = __stringify(_name), .mode = 0444 }, \
627 .show = _name##_show, \
628 }
上面的 .attr 是 struct attribute 类型
继续看 device_create_file(dev, &dev_attr_dev);
device_create_file -> sysfs_create_file(&dev->kobj, &attr->attr);
参数1是kobject实例,参数2是device_attribute下面的attribute实例
526 // sysfs中创建文件接口:在kobj对应的目录下创建属性文件
527 static inline int __must_check sysfs_create_file(struct kobject *kobj,
528 const struct attribute *attr)
529 {

最低0.47元/天 解锁文章
1615

被折叠的 条评论
为什么被折叠?



