linux sys节点创建

static ssize_t display_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
    //unsigned long val;
    //if (kstrtoul(buf, 10, &val))
    //    return -EINVAL;
    pr_err("displayd write debug buf\n");
    return count;
}

static ssize_t display_show(struct device *dev, struct device_attribute *attr, char *buf)
{
    pr_err("displayd read debug buf\n");
    return 0;
}
static DEVICE_ATTR(displayd, 0660, display_show, display_store);

static int init_sys_node()
{
   int ret;
    struct kobject *kobj = kobject_create_and_add("displayd_debug", NULL);
    if(kobj == NULL){
        return -ENOMEM;
    }

    ret = sysfs_create_file(kobj, &dev_attr_displayd.attr);
    
    if(ret < 0) {
        return -1;
    }
    return ret;
}

调用init_sys_node 函数即可创建文件节点:/sys/displayd_debug/displayd

next:sysfs_create_group批量创建sys文件节点.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值