驱动学习--SYS属性节点创建

这篇博客介绍了如何在Linux驱动程序中创建SYS属性节点,通过insmod命令加载模块后,可以在/sys/devices/platform目录下观察到新增的att_test节点。
摘要由CSDN通过智能技术生成
<pre name="code" class="objc">#include <linux/module.h>
#include <linux/slab.h>
#include <linux/kobject.h>
#include <linux/platform_device.h>

struct att_dev
{
    struct platform_device *pdev;
    struct kobject *kobj;
};

static struct att_dev *dev = NULL;

static ssize_t att_store(struct device *dev,
                         struct device_attribute *attr,
                         const char *buf, size_t count)
{
    printk("echo debug buf\n");

    return count;
}

static ssize_t att_show(struct device *dev,
                        struct device_attribute *attr,
                        char *buf)
{
    printk("cat debug buf\n");
    return 0;
}
static DEVICE_ATTR(test,0666,att_show,att_store);//使用DEVICE_ATTR,可以在sys fs中添加“文件”,通过修改该文件内容,可以实现在运行过程中动态控制device的目的


static __devinit int att_probe(struct platform_device *pdev)
{
    int ret;

    /* 增加节点/sys/devic
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值