/dev、/sys/dev 和/sys/devices 和udev的关系

/dev,设备文件存储目录,应用程序通过对这些文件的读写和控制,可以访问实际的设备;


/sys/devices目录,按照设备挂接的总线类型,组织成层次结构,保存了系统所有的设备;是文件系统管理设备的最重要的目录结构;

这是内核设备按总线类型分层放置的目录结构, devices 中的所有设备都是连接于某种总线之下,在这里的每一种具体总线之下可以

找到每一个具体设备的符号链接,它也是构成 Linux 统一设备模型的一部分;


/sys/dev下有两个子目录,block和char,存放的是块设备和字符设备的主次号码,形式为(major:minor),它指向/sys/devices目录下的

设备。


一直没有认真看过sysfs的文档,所以一直就迷迷糊糊的不知道/sys/dev和/sys/devices到底啥关系,另外对于udev也是一知半解。懒啊...

 

终于遇到了问题,不得不看看文档,总结了下:

 

sysfsintroduction:

----------------------------

sysfs is amechanism for representing kernel objects, their attributes, and theirrelationships

with each other.

 

It provides twocomponents: a kernel programming interface for exporting these items via sysfs,and a user interface to view and manipulate these items that maps back to thekernel objects which they represent.

 

The table belowshows the mapping between internel (kernel) constructs and their external

(userspace) sysfsmappings.

---------------------------------------

|Internal             | External      |

---------------------------------------

|KernelObjects       | Directories   |

---------------------------------------

|ObjectAttributes    | Regular Files |

---------------------------------------

|ObjectRelationships | Symbolic Links|

---------------------------------------

(Reference:http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf)

 

/sys/dev:

------------------

Contains twodirectories char/ and block/. Inside these two directories there are symlinksnamed <major>:<minor>. These symlinks point to the sysfs directoryfor the given device. /sys/dev provides a quick way to lookup the sysfsinterface for a device from the result of a stat(2) operation.

 

Example:

root@AuxLinux:/sys#ls -l dev/block/8:1

lrwxrwxrwx 1 rootroot 0 2011-08-26 10:13 dev/block/8:1 ->../../devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda/sda1

root@AuxLinux:/sys#stat /dev/sda1

  File: `/dev/sda1'

  Size: 0               Blocks: 0          IO Block: 4096   block special file

Device: 5h/5d   Inode: 5484        Links: 1     Device type: 8,1

Access:(0660/brw-rw----)  Uid: (    0/   root)   Gid: (    6/   disk)

Access: 2011-08-2418:25:02.902025252 +0800

Modify: 2011-08-1815:14:17.281472005 +0800

Change: 2011-08-1815:14:17.281472005 +0800

 

/sys/devices:

----------------------------

Contains afilesystem representation of the device tree. It maps directly to the internalkernel device tree, which is a hierarchy of struct device.

 

udev:

-----------------------------

udev is a devicemanagement framework that replaced the devfs facility in the Linux 2.6 kernel.It is composed of some kernel services and the udevd daemon. The kernel informsthe udevd daemon when certain events happen. The udevd daemon is configured torespond to some events with actions. Always, it means adding/removing devicefile under /dev dynamically.



posted on 2014-11-11 09:15  王亮1  阅读(304)  评论(0编辑  收藏  举报

导航