Introduction to devfs, sysfs, and udev

Source: Internet
Author: User
Introduction to devfs, sysfs, and udev-Linux general technology-Linux programming and kernel information. The following is a detailed description. I. devfs

In linux, there is a dedicated File System for device management. devfs and sysfs are two of them.

Before kernel 2.6, devfs was used. devfs was mounted to the/dev directory and provides a file-like method to manage all devices in the/dev directory, we know that each file in the/dev directory corresponds to a device. Whether or not the current device exists or not, and these special files are located on the root file system, we have created these device files when creating a file system. Therefore, by operating these special files, we can interact with the kernel. However, the devfs file system has some disadvantages, such as uncertain device ing. Sometimes the device files mapped by a device may be different. For example, My USB flash drive may correspond to sda and may correspond to sdb; there are not enough primary/secondary device numbers. When there are too many devices, this will obviously become a problem; too many files in the/dev directory cannot represent the actual devices on the current system; naming is not flexible enough and cannot be specified at will.

Ii. sysfs

Because of these problems, a new file system sysfs was introduced after the Linux kernel, Which is mounted to the/sys directory. Like devfs, it is also a virtual file system, it is also used to manage system devices. It organizes the devices and bus actually connected to the system into a hierarchical file, user space programs can also use this information to interact with the kernel. This file system is an intuitive response to the actual device tree on the current system, it creates this information through the kobject subsystem. When a kobject is created, the corresponding file and directory are created, which is located in the relevant directory under/sys, since each device has a unique directory in sysfs, it can be read and written by user space. The user space tool udev uses the information provided by sysfs to implement all devfs functions, but the difference is that udev runs in the user space, while devfs runs in the kernel space, and udev does not have the inherent defects of devfs. Obviously, sysfs will be the future development direction.

The top level sysfs directory looks like:
Block/
Bus/
Class/
Devices/
Firmware/
Net/
Fs/

Devices/contains a filesystem representation of the device tree. It maps
Directly to the internal kernel device tree, which is a hierarchy
Struct device.

Bus/contains flat directory layout of the various bus types in
Kernel. Each bus's directory contains two subdirectories:
Devices/
Drivers/
Devices/contains symlinks for each device discovered in the system
That point to the device's directory under root /.

Drivers/contains a directory for each device driver that is loaded
For devices on that participating bus (this assumes that drivers do not
Span multiple bus types ).

Fs/contains a directory for some filesystems. Currently each
Filesystem wanting to export attributes must create its own hierarchy
Below fs/(see./fuse.txt for an example ).

Iii. udev

Udev is a tool that dynamically updates device files, including creating and deleting device files, based on the status of hardware devices in the system. The device files are usually stored in the/dev directory. After udev is used, only the real devices in the system are included in the/dev directory. It is independent of the hardware platform and is located in the user space. It requires support from the kernel sysfs and tmpfs. sysfs provides the device portal and uevent channel for udev, and tmpfs provides storage space for udev device files.

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.