您的位置:首页 > 其它

1.如何建立一个sys调试节点

2017-12-29 09:30 323 查看
sys_debug_inode.c

#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/export.h>
#include <linux/init.h>

static struct kobject *parent_kobj;
static void __init psysfs_init(void)
{
parent_kobj = kobject_create_and_add("jun_debug",NULL);
}

void jun_create_sysfs(const char *name,struct attribute_group group)
{
struct kobject *debug_kobj;
debug_kobj = kobject_create_and_add(name,parent_kobj);
if (debug_kobj)
sysfs_create_group(debug_kobj, &group );
}

EXPORT_SYMBOL_GPL(jun_create_sysfs);

core_initcall(psysfs_init);//高优先级别调用该函数创建 sys/jun_debug/ 目录


xxxx.c 其他模块调用,如tp驱动中的使用

static ssize_t gslx680_show_monitor(struct kobject *kobj, struct kobj_attribute *attr,char *buf)
{
return sprintf(buf, "gsl_log_enable = %d\n", gsl_monitor);
}
static ssize_t gslx680_store_monitor(struct kobject *kobj, struct kobj_attribute *attr,const char *buf, size_t count)
{
gsl_monitor = (int)simple_strtoul(buf, NULL, 10);
return count;
}

static struct kobj_attribute monitor_attr = {
.attr = {
.name = "monitor",
.mode = S_IRUGO |S_IWUGO,
},
.show = &gslx680_show_monitor,
.store = &gslx680_store_monitor,
};

static struct attribute *debug_attrs[] = {
&monitor_attr.attr,
NULL
};
static struct attribute_group debug_attrs_group = {
.attrs = debug_attrs,
};
extern void jun_create_sysfs(const char *name, struct attribute_group group);
static int tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {
...
jun_create_sysfs("tpd",debug_attrs_group);
...
}
//这样就创建了 sys/jun_debug/tpd/monitor 文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sys-节点