DEVICE_ATTR_RW 宏分析 举个例子 kernel/driver/rtc/rtc-sysfs.c 的宏分析 static DEVICE_ATTR_RW(wakealarm);
static DEVICE_ATTR_RW(wakealarm);
#define DEVICE_ATTR_RW(_name) \
struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
struct device_attribute dev_attr_(wakealarm) = __ATTR_RW(wakealarm);
#define __ATTR_RW(_name) __ATTR(_name, (S_IWUSR | S_IRUGO), _name##_show, _name##_store)
struct device_attribute dev_attr_(wakealarm) = __ATTR(wakealarm, (S_IWUSR | S_IRUGO),wakealarm_show, wakealarm_store)
#define __ATTR(_name, _mode, _show, _store) {
.attr = {.name = __stringify(_name),
.mode = VERIFY_OCTAL_PERMISSIONS(_mode) },
.show = _show,
.store = _store,
}
struct device_attribute dev_attr_(wakealarm) = {
.attr = {.name = __stringify(wakealarm),
.mode = VERIFY_OCTAL_PERMISSIONS((S_IWUSR | S_IRUGO)) },
.show = wakealarm_show,
.store = wakealarm_store,
}
最终这个宏 static DEVICE_ATTR_RW(wakealarm); 生成了
struct device_attribute dev_attr_(wakealarm) = {
.attr = {.name = __stringify(wakealarm),
.mode = VERIFY_OCTAL_PERMISSIONS((S_IWUSR | S_IRUGO)) },
.show = wakealarm_show,
.store = wakealarm_store,
}
这一结构体