Automatically creating device nodes without the need of user using mknod

In our previous post, we have created a null device which acts a block hole. We will add logic in our driver code to avoid user using mknod to create /dev/my_null, instead allow driver to automatically create it on loading the module.


Code:




Output:


Notes:

Automatic creating/deleting of device nodes is handled by udev. For udev to work properly, device driver should expose major and minor number to sysfs, that is done by below API's

1. device_create — creates a device and registers it with sysfs. Verify it with (find /sys -name 'my_null')
2. class_create — create a struct class structure (ls -l /sys/class/my_driver_class)


Comments

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto