Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 310
Yeraze Avatar asked Dec 20 '22 18:12

Yeraze


1 Answers

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,
    [...]
};
like image 126
Federico Avatar answered Jan 07 '23 23:01

Federico