文档介绍:http://lxr.linux.no/linux+v2.6.37/Documentation/filesystems/sysfs.txt

The sysfs Filesystem

Sysfs was developed initially as an extension of the driver model. Sysfs is a mechanism for representing kernel objects, their attributes, and their relationships with each other. It provides two components: a kernel programming interface for exporting these items via sysfs, and a user interface to view and manipulate these items that maps back to the kernel objects which they represent. The table below shows the mapping between internel (kernel) constructs and their external (userspace) sysfs mappings.

Internal            External
Kernel Objects        Directories
Object Attributes      Regular Files
Object Relationships    Symbolic Links
This information is strictly organized and usually formatted simply in ASCII, making it very accessible to users and applications. It provides a clear window into the kernel data structures and the physical or virtual objects that they control.
sysfs呈现给用户的信息大部分是ASCII普通文件,此外还有二进制文件(Binary Files)和属性组(Attribute Groups)。

history

sysfs is an in-memory filesystem that was originally based on ramfs. ramfs was written around the time the 2.4.0 kernel was being stabilized. It was an exercise in elegance, as it showed just how easy it was to write a simple filesystem using the then-new VFS layer. Because of its simplicity and use of the VFS, it provided a good base from which to derive other in-memory based filesystems.
sysfs was originally called ddfs (Device Driver Filesystem) and was written to debug the new driver model as it was being written. That debug code had originally used procfs to export a device tree, but under strict urging from Linus Torvalds, it was converted to use a new filesystem based on ramfs.

sys/devices

The devices directory contains the global device hierarchy. This contains every physical device that has been discovered by the bus types registered with the kernel. It represents them in an ancestrally correct way—each device is shown as a subordinate device of the device that it is physically (electrically) subordinate to.像物理从属关系一样呈现设备分层。
两类设备除外:platform设备和system设备。There are two types of devices that are exceptions to this representation: platform devices and system devices. Platform devices are peripheral devices that are inherent to a particular platform. They usually have some I/O ports, or MMIO, that exists at a known, fixed location. Examples of platform devices are legacy x86 devices like a serial controller or a floppy controller, or the embedded devices of a SoC solution.
System devices are non-peripheral devices that are integral components of the system. In many ways, they are nothing like any other device. They may have some hardware register access for configuration, but do not have the capability to transfer data. They usually do not have drivers which can be bound to them. But, at least for those represented through sysfs, have some architecture-specific code that configures them and treats them enough as objects to export them. Examples of system devices are CPUs, APICs, and timers.

linux设备驱动开发详解理论

linux 2.6的内核引入了sysfs文件系统,sysfs被看作是与proc、devfs和devpty同类别的文件系统,它可以产生一个包括所有系统硬件的层级视图,与提供进程和状态信息的proc文件系统十分类似。
sysfs把连接在系统上的设备和总线组织成一个分级的文件,他们可以由用户空间存取、向用户空间导出内核数据结构以及他们的属性。sysfs的一个目的就是展示设备驱动模型中各组件的层次关系,其顶级目录包括block、device、bus、drivers、class、power和firmware。
linux2.6内核开发了全新的设备、总线、类和驱动环环相扣的设备模型。linux内核中,分别使用bus_type、device_driver和device来描述总线、驱动和设备,这3个结构体定义于include/linux/device.h头文件中。

device_driver和device分别表示驱动和设备,而这两者必须依附于一种总线,因此都包含struct bus_type指针。在linux内核中,设备和驱动是分开注册的,注册1个设备的时候,并不需要驱动已经存在,而1个驱动被注册时,也不需要驱动的设备已经被注册。设备和驱动各自涌向内核,而每个设备和驱动涌入的时候,都会去寻找自己的另一半。茫茫人海,何处寻觅?正是bus_type的match()成员函数将两者捆绑在一起。
总线、驱动和设备都可以认为是kobject的派生类(device结构体直接包含了kobject kobj成员,bus_type和device_driver则通过bus_type_private、driver_private间接包含kobject),kobject可看作所有总线、设备和驱动的抽象基类,1个kobject对应sysfs中的1个目录。
总线、设备和驱动中的各个attribute则直接落实为sysfs中的1个文件,attribute会伴随着show()和store()这两个函数,分别用于读写该attribute对应的sysfs文件结点。

事实上,udev规则中各信息的来源实际上就是bus_type、device_driver、device以及attribute等所对应的sysfs节点。

内核交互--sysfs的更多相关文章

  1. ifconfig源码分析之与内核交互数据

    <ifconfig源码分析之与内核交互数据>本文档的Copyleft归rosetta所有,使用GPL发布,可以自由拷贝.转载,转载时请保持文档的完整性.参考资料:<Linux设备驱动 ...

  2. Linux 内核 低级 sysfs 操作

    kobject 是在 sysfs 虚拟文件系统之后的机制. 对每个在 sysfs 中发现的目录, 有一个 kobject 潜伏在内核某处. 每个感兴趣的 kobject 也输出一个或多个属性, 它出现 ...

  3. 内核交互--debugfs_转

    转载:Linux内核里的DebugFS DebugFS,顾名思义,是一种用于内核调试的虚拟文件系统,内核开发者通过debugfs和用户空间交换数据.类似的虚拟文件系统还有procfs和sysfs等,这 ...

  4. Linux内核文档翻译——sysfs.txt

    sysfs - _The_ filesystem for exporting kernel objects. sysfs – 用于导出内核对象(kobject)的文件系统 Patrick Mochel ...

  5. Python IO内核交互了解

    注:Unix \ Linux 环境下的network IO   用户空间与内核空间 现在操作系统都是采用虚拟存储器,那么对32位操作系统而言,它的寻址空间(虚拟存储空间)为4G(2的32次方).操作系 ...

  6. 内核交互--procfs

    文档介绍:http://lxr.linux.no/linux+v2.6.37/Documentation/filesystems/proc.txt以下内容抄录linux设备驱动开发详解-宋宝华在/pr ...

  7. linux内核交互,设备驱动控制管理接口

    1,ioctl preface--starting point ,format,mount volume,in addition to the above file system -- allows ...

  8. 深入理解Linux网络技术内幕——用户空间与内核空间交互

    概述:     内核空间与用户空间经常需要进行交互.举个例子:当用户空间使用一些配置命令如ifconfig或route时,内核处理程序就要响应这些处理请求.     用户空间与内核有多种交互方式,最常 ...

  9. Linux 用户态与内核态的交互【转载】

    Linux 用户态与内核态的交互  在 Linux 2.4 版以后版本的内核中,几乎全部的中断过程与用户态进程的通信都是使用 netlink 套接字实现的,例如iprote2网络管理工具,它与内核的交 ...

随机推荐

  1. 记录一次Elasticsearch线上部署后出现:org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []的问题解决

    说明:ES部署了3个节点,而一般情况只要这三个节点的IP其中一个都可以连接,Web端口使用的是9500,Client连接使用的是9600,调用程序使用了ES原生Client进行连接. 解决方法: 1. ...

  2. 在WPF 4.5中跨线程更新集合

    WPF中一个非常强大的功能是数据绑定,我们可以把一个集合绑定到ListBox中,当集合的数据发生变更时,ListBox界面也会同步变更.本身这是一个非常美好的事情,但是美中不足的是:当把集合绑定到Li ...

  3. 如何让Ubuntu 14重启后,保存屏幕亮度的设置

    每次重新启动后,系统的屏幕亮度都会被调节到最大值,挺烦人的!如何让它保存设置值呢? 首先,我们必须知道自己系统的屏幕亮度取值范围,打开终端,按照下面的步骤进行: 进入backlight这个目录 cd ...

  4. MFC出现 error RC2108: expected numerical dialog constant错误解决办法

    MFC在使用picture console控件之后往往会弹出这个错误:error RC2108: expected numerical dialog constant. 此时,双击这个错误,会跳到提示 ...

  5. mongodb_命令行

    一.打开命令行 cmd --> cd C:\Program Files\MongoDB\Server\3.0\bin\ --> mongo.exe   二.连接远程机器命令行工具 1.连接 ...

  6. RMAN恢复 增加表空间后控制文件丢失

    查看目前的控制文件位置 SQL> select name from v$controlfile; NAME-------------------------------------------- ...

  7. CompileGLShader

    //-----------------------------------------------------------------------------// Purpose: Compiles ...

  8. javascript通过url向jsp页面传递中文参数乱码解决方法

    解决方法:在传递参数前将中文参数进行两次编码,jsp页面获取参数后对中文参数进行一次解码,中文参数就不会变为乱码了! 参考例子: <%@ page language="java&quo ...

  9. 警惕rapidxml的陷阱(二):在Android上默认内存池分配数组过大,容易导致栈溢出

    上一篇随笔中提到了,rapidxml在每个xml对象中维护了一个内存池,自己管理变量的生存周期.看起来很好,但我们在实际使用中还是出现了问题. 项目中我们的模块很快写好了,在windows和linux ...

  10. PostgreSQL数据库的安装与配置

    项目中要用PostgreSQL,所以专门学习了一下如何安装和调试postgresql,此博文用来记录自己的安装和调试过程,安装环境是centos7. 首先尝试了yum安装,因为毕竟yum安装简单粗暴, ...