Yeraze
Yeraze

Reputation: 3289

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.

Upvotes: 5

Views: 5894

Answers (1)

Federico
Federico

Reputation: 3892

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,
    [...]
};

Upvotes: 14

Related Questions