3 ms·
Kernel newb w/ a question on this. When you register the device with register_chrdev you also have to create the file in userspace with mknod ?
by djohnston 9y ago
Kernel newb w/ a question on this. When you register the device with
register_chrdev
you also have to create the file in userspace with
mknod
?
- JoshTriplett 9y agoYou never need to use mknod yourself anymore. Based on the metadata you provide to the kernel, the kernel will create the device itself in devtmpfs, and even set appropriate baseline permissions (e.g. root-only, world-readable, world-writable). udev will then handle any additional permissions you might need, such as ACLs or groups.
- anitil 9y agoOut of historical interest, why was it necessary before? Was it an intentional separation between userspace/kernel responsibilities?
- JoshTriplett 9y agoA few reasons. Prior to the existence of udev, all devices had to be created with mknod and have permissions set; a script called "MAKEDEV" did that. That didn't handle dynamically created devices, so (skipping "hotplug" and an old attempt called "devfs" which was filled with race conditions) the kernel started sending events to userspace for dynamic devices, and udev created those. Then, it made sense to "coldplug" all the existing devices and have udev create those, to use the same unified path for everything, and use udev to set groups and permissions. But that did take some time at boot time, and it meant that you needed either udev or a manually created /dev for tiny embedded systems. devtmpfs handled that use case, automatically creating devices from the kernel. But then, if the kernel knows how to create devices, why not have it do so all the time? So, udev jettisoned the code to create devices itself, and started requiring devtmpfs.