创建文件节点

1 .  static struct kobject *ex_ctl_obj;

2.   

	ex_ctl_obj = kobject_create_and_add("ex_ctl",NULL);
	if(!ex_ctl_obj)
		return -ENOMEM;
		for(i=0;i<ARRAY_SIZE(ex_ctl_attrs);i++){
			ret = sysfs_create_file(ex_ctl_obj, &ex_ctl_attrs[i].attr);
			if (ret != 0) {
				printk("create ex_ctl index %d error\n", i);
				return ret;
			}
		}

  

3. 创建函数

static ssize_t gpio_ctl_show(struct device *dev, struct device_attribute *attr, char *buf)

static ssize_t gpio_ctl_store(struct device *device,struct device_attribute *attr,const char *buf, size_t count)

 

4.

static struct device_attribute ex_ctl_attrs[] = {
	/*     node_name	permision		show_func	store_func */
	__ATTR(fanswitch,	0777,	fanswitch_show,	fanswitch_wrtie),
	__ATTR(gpio_ctl,	0777,	gpio_ctl_show,	gpio_ctl_store),

};

  

posted on 2017-11-14 21:01  xjxhxhl  阅读(127)  评论(0编辑  收藏  举报

导航