Udev rule for syfs classdevice attributes - Stack Overflow

时间: 2025-01-06 admin 业界

I have a driver that exposes class and device attributes under sysfs. I'm using udev to make the devices that appear in /dev read/writable by a certain group, but I can't figure out how to make the attributes read/writable by the same group without a shell script.

ls -l /dev/foobar
crw-rw---- 1 root my_group 241, 0 Jan  4 21:57 /dev/foobar # ownership fixed by udev
ls -l /sys/class/my_class/rw_attribute
--w--w---- 1 root root 4096 Jan  4 22:02 rw_attribute # still owned by root group :/
ls -l /sys/class/my_class/foobar/rw_attribute
-rw-rw-r-- 1 root root 4096 Jan  4 22:13 rw_attribute # ditto

I've tried using udevadm info to match the KERNEL and SUBSYSTEM keys of the sysfs path to no effect. I've also found the udev_event and get_ownership fields of struct class; I haven't had luck with the former and the latter works for device attributes, but I have to hard code my_group's gid which is not ideal.

Does udev only work with devices under /dev, or is there a way to apply the rules to sysfs attributes?