Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a device in /dev automatically upon loading of the kernel module for a device driver?

Tags:

People also ask

How do I create a device on Linux?

So you can make a device file with a command, mknod or mknod, the name of the file, then either a c or a b for character or block, and then a number which will be known as the major device number and another number known as the minor.

Which command is used to create device special file in dev?

Description. The mknod command makes a directory entry and corresponding i-node for a special file. The first parameter is the name of the entry device. Select a name that is descriptive of the device.

How do I prevent a kernel module from loading automatically?

In order to prevent kernel modules loading during boot, the module name must be added to a configuration file for the "modprobe" utility. This file must reside in /etc/modprobe. d . Ensure the module is not configured to get loaded in either /etc/modprobe.

How do I register a character device driver?

The classic way to register a char device driver is with: int register_chrdev(unsigned int major, const char *name, struct file_operations *fops); Here, major is the major number of interest, name is the name of the driver (it appears in /proc/devices), and fops is the default file_operations structure.


I am attempting to develop Linux device drivers and as my first attempt I am trying to develop a char device driver that has the following file options,

struct file_operations fops{  
.open=open_fun,  
.release=release_fun,  
.write=write_fun,  
.read=read_fun,  
};  

When I load the driver using insmod, I see that /proc/devices lists the driver under char devices but I can't find it in /dev. A Google search suggested use of mknod to create a deivce in /dev and associate it with the driver's major and minor. However, an attempt to do so resulted in "Permission denied" error even when done as a super user.

What should I do to make the device appear in /dev when the kernel module is loaded? I tried both the older (register_chrdev) and the newer version (cdev_init & cdev_add) of registering the device but none of them works.

Thanks,
Mir