/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.
總結
以上是生活随笔為你收集整理的/dev、/sys/dev 和/sys/devices 和udev的关系的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Makefile的obj-y 和 obj
- 下一篇: 如何搭建modem编译环境