当前位置: 动力学知识库 > 问答 > 编程问答 >

Linux Kernel Module Character Device Permissions

问题描述:

Is it possible to create a character device in a linux kernel module that starts off mod 666? Right now it's always 600 (owned by root), and I have to chmod it. I could create udev entries to resolve it, but I'ld really rather the module do it automagically.

Is it possible? I can't find any information in the cdev_init or cdev_add documentation on this.

网友答案:

You can do it by setting the dev_uevent method in the class structure. In this method you have to set the DEVMODE uevent variable. Here an example

static int my_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
{
    add_uevent_var(env, "DEVMODE=%#o", 0440);
    return 0;
}

static struct class my_class = {
    .name                = "myname",
    .owner                = THIS_MODULE,
    .dev_uevent        = my_dev_uevent,
    [...]
};
分享给朋友:
您可能感兴趣的文章:
随机阅读: