static DEVICE_ATTR(switch, 0666, xx_read, xx_write);
#define DEVICE_ATTR(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
/* interface for exporting device attributes */
struct device_attribute {
struct attribute attr;
ssize_t (*show)(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count);
};
show是读取该文件的回调,store是写该文件的回调。
static ssize_t xxx_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t n)
{
printk("Hello world!!!!!!\n");
return n;
}
这样在写该文件的时候,就会看到Hello world!!!的log.
阅读(1204) | 评论(0) | 转发(0) |