关于sys/device和/dev的区别
2016-02-25 15:05
483 查看
sysfs introduction:
----------------------------
sysfs is a mechanism for representing kernel objects, theirattributes, and their relationships
with each other.
It provides two components: a kernel programming interface forexporting these items via sysfs, and a user interface to view andmanipulate these items that maps back to the kernel objects whichthey represent.
The table below shows the mapping between internel (kernel)constructs and their external
(userspace) sysfs mappings.
---------------------------------------
|Internal
|External |
---------------------------------------
|KernelObjects | Directories |
---------------------------------------
|ObjectAttributes |Regular Files |
---------------------------------------
|Object Relationships | Symbolic Links|
---------------------------------------
(Reference:http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf)
/sys/dev:
------------------
Contains two directories char/ and block/. Inside these twodirectories there are symlinks named<major>:<minor>.These symlinks point to the sysfs directory for the given device./sys/dev provides a quick way to lookup the sysfs interface for adevice from the
result of a stat(2) operation.
Example:
root@AuxLinux:/sys# ls -l dev/block/8:1
lrwxrwxrwx 1 root root 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 specialfile
Device: 5h/5d Inode:5484 Links:1 Devicetype: 8,1
Access: (0660/brw-rw----) Uid:( 0/ root) Gid:( 6/ disk)
Access: 2011-08-24 18:25:02.902025252 +0800
Modify: 2011-08-18 15:14:17.281472005 +0800
Change: 2011-08-18 15:14:17.281472005 +0800
/sys/devices:
----------------------------
Contains a file system representation of the device tree. It maps directly to the internal kernel device tree, which is a hierarchy of struct device.
udev:
-----------------------------
udev is a device management 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 informs the udevd daemon when certain events happen. The udevd daemon is configured torespond
to some events with actions. Always, it means adding/removing device file under /dev dynamically.
* When the kernel detects that a device has been added or removed,a uevent is sent to
the udevd daemon through a netlink socket
* When udevd receives the uevent, it matches its configured rules against the available
device attributes provided in sysfs
* If a match is found, one or more actions (e.g., create device node, remove device node,
install firmware, etc.) are taken
(Usage Reference:http://www.ibm.com/developerworks/cn/linux/l-cn-udev/index.html?ca=drs-cn-0304)
----------------------------
sysfs is a mechanism for representing kernel objects, theirattributes, and their relationships
with each other.
It provides two components: a kernel programming interface forexporting these items via sysfs, and a user interface to view andmanipulate these items that maps back to the kernel objects whichthey represent.
The table below shows the mapping between internel (kernel)constructs and their external
(userspace) sysfs mappings.
---------------------------------------
|Internal
|External |
---------------------------------------
|KernelObjects | Directories |
---------------------------------------
|ObjectAttributes |Regular Files |
---------------------------------------
|Object Relationships | Symbolic Links|
---------------------------------------
(Reference:http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf)
/sys/dev:
------------------
Contains two directories char/ and block/. Inside these twodirectories there are symlinks named<major>:<minor>.These symlinks point to the sysfs directory for the given device./sys/dev provides a quick way to lookup the sysfs interface for adevice from the
result of a stat(2) operation.
Example:
root@AuxLinux:/sys# ls -l dev/block/8:1
lrwxrwxrwx 1 root root 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 specialfile
Device: 5h/5d Inode:5484 Links:1 Devicetype: 8,1
Access: (0660/brw-rw----) Uid:( 0/ root) Gid:( 6/ disk)
Access: 2011-08-24 18:25:02.902025252 +0800
Modify: 2011-08-18 15:14:17.281472005 +0800
Change: 2011-08-18 15:14:17.281472005 +0800
/sys/devices:
----------------------------
Contains a file system representation of the device tree. It maps directly to the internal kernel device tree, which is a hierarchy of struct device.
udev:
-----------------------------
udev is a device management 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 informs the udevd daemon when certain events happen. The udevd daemon is configured torespond
to some events with actions. Always, it means adding/removing device file under /dev dynamically.
* When the kernel detects that a device has been added or removed,a uevent is sent to
the udevd daemon through a netlink socket
* When udevd receives the uevent, it matches its configured rules against the available
device attributes provided in sysfs
* If a match is found, one or more actions (e.g., create device node, remove device node,
install firmware, etc.) are taken
(Usage Reference:http://www.ibm.com/developerworks/cn/linux/l-cn-udev/index.html?ca=drs-cn-0304)
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- 神器SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程