内核中已经使用sysfs实现了很多的读写函数,下面是几个典型的
设备 /* devices */ /* structure */ //include/linux/device.h) 512 /* interface for exporting device attributes */ 513 struct device_attribute { 514 struct attribute attr; 515 ssize_t (*show)(struct device *dev, struct device_attribute *attr, 516 char *buf); 517 ssize_t (*store)(struct device *dev, struct device_attribute *attr, 518 const char *buf, size_t count); 519 }; /* Declaring */ 539 #define DEVICE_ATTR(_name, _mode, _show, _store) \ 540 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) /* Creation/Removal */ 560 extern int device_create_file(struct device *device,const struct device_attribute *entry); 562 extern void device_remove_file(struct device *dev,const struct device_attribute *attr); 总线驱动 /* bus drivers */ /* Structure */ //include/linux/device.h 44 struct bus_attribute { 45 struct attribute attr; 46 ssize_t (*show)(struct bus_type *bus, char *buf); 47 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count); 48 }; /* Declaring */ 50 #define BUS_ATTR(_name, _mode, _show, _store) \ 51 struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) /* Creation/Removal */ 57 extern int __must_check bus_create_file(struct bus_type *,struct bus_attribute *); 59 extern void bus_remove_file(struct bus_type *, struct bus_attribute *); 设备驱动 /* device drivers */ /* Structure */ //include/linux/device.h 265 struct driver_attribute { 266 struct attribute attr; 267 ssize_t (*show)(struct device_driver *driver, char *buf); 268 ssize_t (*store)(struct device_driver *driver, const char *buf, 269 size_t count); 270 }; /* Declaring */ 272 #define DRIVER_ATTR(_name, _mode, _show, _store) \ 273 struct driver_attribute driver_attr_##_name = __ATTR(_name, _mode, _show, _store) /* Creation/Removal */ 281 extern int __must_check driver_create_file(struct device_driver *driver, 282 const struct driver_attribute *attr); 283 extern void driver_remove_file(struct device_driver *driver, 284 const struct driver_attribute *attr);Linux设备管理(四)(5)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/4660794135ab141263397c309971b569.html