Application, kernel, and driver relationships

Source: Internet
Author: User

Relationship between applications and library functions, kernels, and drivers

Applications, libraries, kernels, and drivers: the application calls the application function library to complete the function, the application accesses various resources in the form of files, the application function library, some functions directly complete the function, and some functions are called through the system.

The kernel calls the kernel processing system.

Call the device driver to directly communicate with the hardware.

Shows the relationship between them.


Device Type:

Common devices include character devices, Block devices, and network devices.

Character device: When a read/write request is sent to a character device, the actual hardware I/O operation usually follows.

Block device: a block device uses the system memory as a buffer.

Network device: a network device is a special type of device. It is not accessed by a character device or block device through the corresponding device file node, nor can it directly access data through read or write.

Device No.

Hardware devices are differentiated by the master device number and slave device number. In device management, in addition to the device type, the kernel also needs parameters called Master/Slave Device numbers to uniquely identify a device. Devices with the same master device number use the same driver. device numbers are used to differentiate instances of specific devices. Use the ll command (ls
-L) You can view the device type and Master/Slave Device number of each device. Cat/proc/devices allows you to view the primary device numbers of all devices in the system.

 

Device Files

The device type and Master/Slave Device number are used when the kernel communicates with the device driver. The application uses the device file node to access the corresponding device. Linux 2.4 introduces all the device files in the Device File System (devfs) as a file system that can be attached. Each device with a Master/Slave Device number corresponds to a file node. Each device file has its file attributes (c indicates a character device or B indicates a block device). Each device has two device numbers: 1. The master device number, used to identify the driver; 2. Slave Device number: used to identify different hardware of the same driver. The master device number of the device file must be the same as the master device number applied by the device driver during registration. Note that system calls are interfaces between the kernel and applications, and device drivers are interfaces between the kernel and hardware.

 

Differences between drivers and Applications

1. The application starts with main, and the driver does not have main. It uses a module initialization function as the entry.

2. The application executes a task from start to end, and the driver does not run after initialization, waiting for the system to call.

3. Applications can use standard C libraries such as GLIBC, and drivers cannot use standard C libraries.

 

User and Kernel

Generally, the system runs in user and kernel modes. The data in these two operating modes is invisible to each other. The driver is a part of the kernel, working in the kernel state, and the application working in the user State. In this way, the data space access problem exists: the data addresses of the two cannot be directly transmitted through pointers. Solution: The system provides a series of functions to help complete data space conversion, such as get_user, put_user, copy_from_user, and copy_to_user.

And other functions.

 

Linux driver functions

The general functions of the driver are as follows: initialize and release devices, send data from the kernel to hardware, read data from hardware, read data from applications, send data to device files, and send data requested by applications, detect and process devices. errors.

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.