跳转到内容

Sysfs:修订间差异

维基百科,自由的百科全书
删除的内容 添加的内容
Alexbot留言 | 贡献
機器人 正在新增: en:Sysfs
无编辑摘要
第40行: 第40行:
Sysfs is used by several utilities to access information about hardware and its driver ([[Module (Linux)|kernel modules]]) such as [[udev]] or [[HAL (software)|HAL]]. Scripts have been written to access information previously obtained via procfs, and some scripts configure device drivers and devices via their attributes.
Sysfs is used by several utilities to access information about hardware and its driver ([[Module (Linux)|kernel modules]]) such as [[udev]] or [[HAL (software)|HAL]]. Scripts have been written to access information previously obtained via procfs, and some scripts configure device drivers and devices via their attributes.


==See also==
==參看==
*[[configfs]]
*[[configfs]]
*[[kobject]]
*[[kobject]]


==External links==
==外部連結==
*[http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf The sysfs Filesystem(pdf), by Patrick Mochel]
*[http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf The sysfs Filesystem(pdf), by Patrick Mochel]
*[http://lwn.net/Articles/31185/ Driver model overview from the LWN porting to 2.6 series]
*[http://lwn.net/Articles/31185/ Driver model overview from the LWN porting to 2.6 series]

2008年8月4日 (一) 00:44的版本

Sysfs 是 Linux 2.6 所提供的一種虛擬檔案系統。這個檔案系統不僅可以把裝置(devices)和驅動程式(drivers) 的資訊從 kernel space 輸出到 user space,也可以用來對裝置和驅動程式做設定。

歷史

Linux 核心開發團隊2.5 核心的開發過程中,引入了『Linux 驅動程式模型』(Linux driver model),以解決 2.4 核心所遭遇的底下問題:

  • 沒有統一的機制表達驅動程式和裝置的關係。
  • 不存在一般的熱插拔(hotplug)機制。
  • procfs 檔案系統過度混亂,包含了許多不是行程(process)的資訊。

sysfs 的目的是把一些原本在 procfs 中的,關於裝置的部份,獨立出來,以『裝置階層架構』(device tree)的形式呈現。這個檔案系統由 Patrick Mochel 所寫,稍後 Maneesh Soni 撰寫 "sysfs backing store path",以降低在大型系統中對記憶體的需求量。

sysfs 一開始以 ramfs 為基礎,也是一個只存在於記憶體中的檔案系統。ramfs 是在 2.4 核心處於穩定階段時加入的。ramfs 是一個優雅的實做,證明了要在當時仍很新的虛擬檔案系統(VFS)下寫一個簡單的檔案系統是多麼容易的一件事。由於 ramfs 的簡潔以及使用了 VFS,稍後的一些記憶體形式的檔案系統都以它作為開發基礎。

sysfs 剛開始被命名成 ddfs (Device Driver Filesystem),當初只是為了要對新的驅動程式模型除錯而開發出來的。它在除錯時,會把裝置架構(device tree)的資訊輸出到 procfs 檔案系統中。但在 Linus Torvalds 的急切督促下,ddfs 被轉型成一個以 ramfs 為基礎的檔案系統。在新的驅動程式模型被整合進 2.5.1 核心時,ddfs 被改名成 driverfs,以更確切描述它的用途。

在 2.5 核心開發的次年,新的『驅動程式模型』和『driverfs』證明了對核心中的其他子系統也有用處。kobjects 被開發出來,作為核心物件的中央管理機制,而此時 driverfs 也被改名成 sysfs。

技術概觀

For each object added in the driver model tree (drivers, devices including class devices) a directory in sysfs is created. The parent/child relationship is reflected with subdirectories under /sys/devices/ (reflecting the physical layout). The subdirectory /sys/bus/ is populated with symbolic links, reflecting how the devices belong to different busses. /sys/class/ shows devices grouped according to classes, like network, while /sys/block/ contains the block devices.

每個被加入 driver model tree 內的物件,包括驅動程式、裝置以及 class 裝置,都會在 sysfs 檔案系統中以一個目錄呈現。

For device drivers and devices, attributes may be created. These are simple files; the rule is that they should only contain a single value and/or allow a single value to be set (unlike some files in procfs, which need to be heavily parsed). These files show up in the subdirectory of the device driver respective to the device. Using attribute groups, a subdirectory filled with attributes may also be created.

Some buses

PCI

Exports information about PCI devices.

USB

Contains both USB devices and USB hosts.

S/390 buses

As the S/390 architecture contains devices not found elsewhere, special buses have been created:

  • css: Contains subchannels (currently the only driver provided is for I/O subchannels).
  • ccw: Contains channel attached devices (driven by CCWs).
  • ccwgroup: Artificial devices, created by the user and consisting of ccw devices. Replaces some of the 2.4 chandev functionality.
  • iucv: Artificial devices like netiucv devices which use VM's IUCV interface.

Sysfs and userspace

Sysfs is used by several utilities to access information about hardware and its driver (kernel modules) such as udev or HAL. Scripts have been written to access information previously obtained via procfs, and some scripts configure device drivers and devices via their attributes.

參看

外部連結