我正在弄乱stat structure 并试图理解它,但是大多数文档都相当神秘,具体来说,我无法理解第一个成员的目的, st_dev ,究竟是什么“ inode <的设备< / em>的“?
答案 0 :(得分:2)
In the field st_dev you find a system-dependent number of the device which backs this file. It usually is the major/minor number (combined with makedev(3)
) of the block device which contains the filesystem where the file is located on. If the file is a device node, it is the major/minor number of the device itself.
For example:
$ ls -la /dev/null
crw-rw-rw- 1 root root 1, 3 May 17 09:52 /dev/null
st_dev will contain makedev(1,3)
(which is 259 on linux), or
for /etc/passwd
, st_dev will contain makedev(8,1)
(which is 2049 on linux), if the file is located on /dev/sda1.
You can extract the major/minor number with the corresponding macros major(st_dev)
and minor(st_dev)
, as described in the manpage for makedev(3)
.