Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2936406
  • 博文数量: 401
  • 博客积分: 12926
  • 博客等级: 上将
  • 技术积分: 4588
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-22 14:51
文章分类

全部博文(401)

文章存档

2015年(16)

2014年(4)

2013年(12)

2012年(82)

2011年(98)

2010年(112)

2009年(77)

分类: LINUX

2010-01-07 16:44:30

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.
阅读(1161) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~