Linux Character Device learning note "original"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.