如何在sysfs中的文件夹内创建一个文件夹 [英] How to create a folder within a folder in sysfs

查看:355
本文介绍了如何在sysfs中的文件夹内创建一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建在Android的我的一个实施的sysfs并坚持在

I am trying to create a sysfs for an implementation of mine in android and stuck at creating a folder of my own in CLASS.

我的要求:

/sys/class/example_class/my_sysfs_directory/file_one.

code:

    #include<linux/module.h>
    #include<linux/kernel.h>
    #include<linux/device.h>
    #include <linux/err.h>

    MODULE_LICENSE("GPL");
    MODULE_AUTHOR("Manoj");

    static ssize_t sysfs_demo_show(struct class *class,
        struct class_attribute *attr, char *buf)
    {
    pr_info("%s [%d]: \n", __func__, __LINE__);
    return sprintf(buf, "%s \n", __func__);
    }

    static ssize_t sysfs_demo_store(struct class *class,
    struct class_attribute *attr, const char *buf, size_t size)
    {
    pr_info("%s [%d]: \n", __func__, __LINE__);
    return size;
    }

    static CLASS_ATTR(file_one, 0777, sysfs_demo_show, sysfs_demo_store);
    int  sysfs_my_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
    {
    pr_info("%s [%d]: \n", __func__, __LINE__);
    return 0;
    }

    struct class *example_class;

    int sysfs_demo_init(void)
    {
    int ret;
    pr_info("%s [%d]: \n", __func__, __LINE__);
    example_class = class_create(THIS_MODULE, "demo");
    if (IS_ERR(example_class)) {
    pr_err("Failed to create sys_class\n");
    return -1;
    }
    example_class->dev_uevent = sysfs_my_dev_uevent;
    ret = class_create_file(example_class, &class_attr_file_one);
    if (ret) {
    pr_err("Failed to create class file @ parent class dirs\n");
    return -1;
    }
    return 0;
    }

    void sysfs_demo_exit(void)
    {
    pr_info("%s [%d]: \n", __func__, __LINE__);
    class_remove_file(example_class, &class_attr_file_one);
    class_destroy(example_class);
    }


    module_init(sysfs_demo_init);
    module_exit(sysfs_demo_exit);

我在这里贴我的code,
请帮我在这方面。

I have pasted my code here, Please help me in this regard.

推荐答案

这不是raccomended创建的sysfs目录/文件手动。

It is not raccomended to create sysfs directory/file "manually".

每sysfs的属性应该被关联到设备。如果你的目的是用于设备的驱动程序,你迟早会用结构设备。在这里,一个<一个href=\"http://stackoverflow.com/questions/19529018/how-does-linux-kernel-creates-sysfs/19530495#19530495\">related回答

Every sysfs attribute should be associated to a device. If your aim is a driver for a device, sooner or later you will use the structure device. Here a related answer

这篇关于如何在sysfs中的文件夹内创建一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆