1, Application equipment number
from Const Char *name)
Specifies the count number of device numbers to be requested from the device number from, and name in /proc/devices . Return value: Successfully returned 0, failure to return an error code.
2, the dynamic application equipment number
int Const Char *name)
The count number of device numbers starting with the second device number Baseminor , the name in /proc/devices , and the dev The pointer returns the assigned device number to the calling function person. Return value: Successfully returned 0, failure to return an error code.
3, uninstall the application of the device number
void from, unsigned count)
Use: Releases the count number of device numbers from start.
4. Registered character device
1) assigning cdev ;
2) Initialize cdev ;
3) add cdev ;
4.1 Assigning Cdev
struct cdev*= Cdev_alloc ();
4.2 Initializing Cdev
void cdev_init (structconststruct file_operations *fops)
Cdev: Previously I defined the cdev structure;fops: The file operation structure of the device. return value:( the function may fail to see the return value is necessary ); return 0successfully, the corresponding error code is returned;
4.3 Adding Cdev
int cdev_add (struct cdev *cdev, dev_t Dev, unsigned count)
Cdev: Specifies the CDEV structure to be added;Dev: the corresponding device number; Count: Add count devices from the device number dev . Return value: Successfully returned 0, failure to return the corresponding error code.
4.3 Uninstalling Cdev
void Cdev_del (struct cdev *p)
5. Error
Linux error handling is designed with the platform architecture in mind.
6. Driver, device file, device number, application relationship
The device number request is called by Register_chrdev_region () to request the device number, then call Cdev_init () to register the device into the kernel, to associate the device number with the driver call Cdev_add (), To provide an interface to the application to access the kernel driver, you need to create a text file that can be created manually
Mknod/dev/test C 250 0 The application can access the kernel by using the open path "/dev/test".
Linux Character Device learning note "original"