In-depth theoretical explanation of Linux sysfs system attributes

Source: Internet
Author: User

The Linux sysfs system has been developing for a long time and many users are familiar with the Linux sysfs system. Here I will share my personal understanding and discuss it with you. In a Linux sysfs system, a host is connected by using a SCSI bus. Similar to PCI, four numbers are used as a group to describe a device, with scsi_host at the top. The Fedora Core Linux is developed in a community-supported way, and the development team of Red Hat Linux will continue to participate in the development of this release. Red Hat regards the Fedora Project as a new technology development field and encourages interested free software developers to participate in the development of this Project, we hope that this release will truly become an operating system based on free software development.

We start from the device category/class:
# Ls-lU/sys/class/scsi_host total 0
Lrwxrwxrwx 1 root 0 12-13 0:59 host0-> \
.../../Devices/pci0000: 00/0000: 00: 02.5/host0/scsi_host/host0
Lrwxrwxrwx 1 root 0 12-13 0:59 host1-> \
.../../Devices/pci0000: 00/0000: 00: 02.5/host1/scsi_host/host1

Note that this is the latest kernel change from/sys/class/to symbolic link. Real kobject exists in/sys/devices; here we will explore the SCSI controller host0:
# Readlink-f/sys/class/scsi_host/host0
/Sys/devices/pci0000: 00/0000: 00: 02.5/host0/scsi_host/host0
# Ls-lU/sys/devices/pci0000: 00/0000: 00: 02.5/host0/scsi_host/host0
Total 0
-Rw-r -- 1 root 4096 12-13 uevent
Lrwxrwxrwx 1 root 0 12-13 subsystem->.../../class/scsi_host
Lrwxrwxrwx 1 root 0 12-13 device->.../host0
-R -- 1 root 4096 12-13 02: 02 unique_id
-R -- 1 root 4096 12-13 02: 02 host_busy
-R -- 1 root 4096 12-13 1__per_lun
-R -- 1 root 4096 12-13 can_queue
-R -- 1 root 4096 12-13 02: 02 sg_tablesize
-R -- 1 root 4096 12-13 unchecked_isa_dma
-R -- 1 root 4096 12-13 02: 02 proc_name
-- W ------- 1 root 4096 12-13 scan
-Rw-r -- 1 root 4096 12-13 state
-Rw-r -- 1 root 4096 12-13 supported_mode
-Rw-r -- 1 root 4096 12-13 active_mode
-R -- 1 root 4096 12-13 prot_capabilities
-R -- 1 root 4096 12-13 02: 02 prot_guard_type
Drwxr-xr-x 2 root 0 12-13 power


These attribute files are described as follows:
Four SCSI-specific writable parameters are available: scan, state, supported_mode, and active_mode. Different parameters can be written to these parameters to control the various statuses of the SCSI controller;
Other readable attributes are used to read some current values of the SCSI controller;
The scan attribute file is useful when debugging some SCSI hardware drivers. It is only written. Three to four integers separated by spaces can be written to specify the corresponding host, channel, id, and lun. The scan attribute supports "-" as the wildcard. You can run the following command to re-search the entire scsi_host, this function is useful for debugging some SCSI drivers that are not fully implemented by the hot tappet:
# Echo '---'>/sys/devices/pci0000: 00/0000: 00: 02.5/host0/scsi_host/host0/scan

Linux sysfs system attribute file in the kernel module

Take an 8139too module as an example to explain the usage of each attribute in this kboject;
# Find/sys/module/8139too/-ls
6408 0-r -- 1 root 4096 December 13 02:17 \
/Sys/module/8139too/version
6412 0 drwxr-xr-x 2 root 0 December 13 02:17 \
/Sys/module/8139too/sections
6433 0 drwxr-xr-x 2 root 0 December 13 02:17 \
/Sys/module/8139too/notes
6434 0-r -- 1 root 36 December 13 02:17 \
/Sys/module/8139too/notes/. note. gnu. build-id
6486 0 drwxr-xr-x 2 root 0 December 13 02:17 \
/Sys/module/8139too/drivers
6487 0 lrwxrwxrwx 1 root 0 December 13 02:17 \
/Sys/module/8139too/drivers/pci: 8139too->.../bus/pci/drivers/8139too

Attribute files are read-only and used to provide information. From version and srcversion, we can understand the version number declared by this module. The source code version number, refcnt indicates the module reference count, and the sections attribute group contains the corresponding section information for Loading modules to the memory, the drivers/directory contains links to the provided drivers;

Because the module is the best choice for Linux sysfs kernel driver programming, a module may provide multiple Linux sysfs system drivers, therefore, if you do not know which driver a device uses, You can first find the corresponding module from/sys/module/and then find the real driver from drivers. Alternatively, you can use this information to find the device nodes under/sys/devices/by using tools such as lspci/lshw, find the device_driver under/sys/bus/*/drivers/from the driver link of the device, and find/sys/module/*/From the module Link under device_driver /*/, in this way, we can obtain which module of the loaded module is providing drivers to a device.

More Linux sysfs system attribute files

The above examples are just some common Linux sysfs system attribute usage. In actual systems, there are often many other Linux sysfs system attributes that have never been seen before. Therefore, only examples are not enough, even if you have maintained a Linux sysfs system attribute usage reference book, there will be new Linux sysfs system attributes in future kernel versions, therefore, you must understand the Linux kernel code to find the code location for implementing these attributes, so as to learn to analyze the Linux sysfs system attribute functions from the kernel source code without the corresponding attribute documentation.

  1. Easily retrieve the lost root password in the Linux operating system
  2. Analyze the Linux and Windows operating systems for you
  3. Describes the hardware supported by Linux operating system installation and recognition.
  4. Complete Linux localization and easily apply Linux
  5. Linux technology is getting better than NEC

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.