内核交互--sysfs
文档介绍:http://lxr.linux.no/linux+v2.6.37/Documentation/filesystems/sysfs.txt
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的更多相关文章
- ifconfig源码分析之与内核交互数据
<ifconfig源码分析之与内核交互数据>本文档的Copyleft归rosetta所有,使用GPL发布,可以自由拷贝.转载,转载时请保持文档的完整性.参考资料:<Linux设备驱动 ...
- Linux 内核 低级 sysfs 操作
kobject 是在 sysfs 虚拟文件系统之后的机制. 对每个在 sysfs 中发现的目录, 有一个 kobject 潜伏在内核某处. 每个感兴趣的 kobject 也输出一个或多个属性, 它出现 ...
- 内核交互--debugfs_转
转载:Linux内核里的DebugFS DebugFS,顾名思义,是一种用于内核调试的虚拟文件系统,内核开发者通过debugfs和用户空间交换数据.类似的虚拟文件系统还有procfs和sysfs等,这 ...
- Linux内核文档翻译——sysfs.txt
sysfs - _The_ filesystem for exporting kernel objects. sysfs – 用于导出内核对象(kobject)的文件系统 Patrick Mochel ...
- Python IO内核交互了解
注:Unix \ Linux 环境下的network IO 用户空间与内核空间 现在操作系统都是采用虚拟存储器,那么对32位操作系统而言,它的寻址空间(虚拟存储空间)为4G(2的32次方).操作系 ...
- 内核交互--procfs
文档介绍:http://lxr.linux.no/linux+v2.6.37/Documentation/filesystems/proc.txt以下内容抄录linux设备驱动开发详解-宋宝华在/pr ...
- linux内核交互,设备驱动控制管理接口
1,ioctl preface--starting point ,format,mount volume,in addition to the above file system -- allows ...
- 深入理解Linux网络技术内幕——用户空间与内核空间交互
概述: 内核空间与用户空间经常需要进行交互.举个例子:当用户空间使用一些配置命令如ifconfig或route时,内核处理程序就要响应这些处理请求. 用户空间与内核有多种交互方式,最常 ...
- Linux 用户态与内核态的交互【转载】
Linux 用户态与内核态的交互 在 Linux 2.4 版以后版本的内核中,几乎全部的中断过程与用户态进程的通信都是使用 netlink 套接字实现的,例如iprote2网络管理工具,它与内核的交 ...
随机推荐
- Java高级架构师(一)第02节:分模块、分工程管理
本节课程的目标在于:利用Maven构建分工程.分模块的空项目. -------- 基本的构建大致相同,有一个强调调点: 在总web的pom里边(architecture01web中),加入要合并的wa ...
- Matlab与C++混合编程 编写独立外部应用程序时出现“无法定位序数3906于动态链接库LIBEAY32.dll上”错误
出现“无法定位序数3906于动态链接库LIBEAY32.dll上”错误,这种错误一般是同名函数出现在两个不同的头文件中了. 笔者的这个错误是由于 #include "mat.h" ...
- jquery ui autocomplete
//条码录入,自动完成功能 function addAutoComplete() { $('#txt_spuNo').autocomplete({ autoFocus: true, source: f ...
- VUE -- Vue.js每天必学之计算属性computed与$watch
在模板中绑定表达式是非常便利的,但是它们实际上只用于简单的操作.模板是为了描述视图的结构.在模板中放入太多的逻辑会让模板过重且难以维护.这就是为什么 Vue.js 将绑定表达式限制为一个表达式.如果需 ...
- Keen Team
Keen Team (碁震安全研究团队,KeenTeam)是一支由在信息安全理论和技术研究方面全球领先的中国“白帽”安全专家组成的信息安全研究队伍,成员主要来自微软的安全漏洞研究.安全攻击和防御技术研 ...
- Vue实例总结
一.登陆框的要点总结: 1.暂无数据就是要myData里没数据时候才出来:删除全部就是要有数据才出来.v-show的使用: 2.表格行就是需要循环数据,v-for.{{$index}}.{{item. ...
- Macro definition of snprintf conflicts with Standard Library function declaration
Macro definition of snprintf conflicts with Standard Library function declaration 即将此处的宏定义注释掉,因为在VS2 ...
- git删除历史
Git如何永久删除文件(包括历史记录) 有些时候不小心上传了一些敏感文件(例如密码), 或者不想上传的文件(没及时或忘了加到.gitignore里的), 而且上传的文件又特别大的时候, 这将导致别 ...
- ajax 底层源码解析
对象: XMLHttpRequest 属性:readyState请求状态,开始请求时值为0直到请求完成这个值增长到4 responseText目前为止接收到的响应体,readyState<3此属 ...
- Python基础之字符串的练习
练习1 #!/usr/bin/python -tt # Copyright 2010 Google Inc. # Licensed under the Apache License, Version ...