根据文件,结构字段解释如下:
struct statfs {
__SWORD_TYPE f_type; /* type of file system (see below) */
__SWORD_TYPE f_bsize; /* optimal transfer block size */
fsblkcnt_t f_blocks; /* total data blocks in file system */
fsblkcnt_t f_bfree; /* free blocks in fs */
fsblkcnt_t f_bavail; /* free blocks available to
unprivileged user */
fsfilcnt_t f_files; /* total file nodes in file system */
fsfilcnt_t f_ffree; /* free file nodes in fs */
fsid_t f_fsid; /* file system id */
__SWORD_TYPE f_namelen; /* maximum length of filenames */
__SWORD_TYPE f_frsize; /* fragment size (since Linux 2.6) */
__SWORD_TYPE f_spare[5];
};“文件系统中的文件节点”是否意味着我们有多少现有文件?它包括目录和链接吗?
“fs中的空闲文件节点”是什么意思?
什么是f_spare?
在一些Linux分叉中(例如,在Android中),我看到f_spare大小为4,并定义了附加字段f_flags。为f_flags定义了哪些标志
f_fsid只是唯一标识文件系统的随机数,还是什么?
发布于 2019-12-04 16:56:52
“文件系统中的总文件节点”是否意味着我们有多少现有文件?它包括目录和链接吗?
差不多了。是的,它包括目录和软链接,但是两个文件可以共享相同的inode。在这种情况下,它们是硬链接的,在硬盘上共享相同的空间,但在文件系统中被视为不同的文件。举例说明:
% echo Hello > test1.txt
% ln test1.txt test2.txt
% ls -i test1.txt test2.txt
14946320 test1.txt 14946320 test2.txt文件名左边的数字是inode(与我的示例中的数字不同)。正如您所看到的,它们具有相同的inode。如果对一个文件进行更改,则通过另一个文件可以看到相同的更改。
“fs中的空闲文件节点”是什么意思?
文件系统通常有一个可以跟踪的索引的上限。实际类型的fsfilcnt_t设置了一个限制(在我的系统中为18446744073709551615),但它很可能更低。除非您以非常特殊的方式使用您的文件系统,否则这个限制通常不是问题。
f_spare是什么?在一些Linux分叉中(例如,在Android中),我看到f_spare大小为4,并定义了附加字段f_flags。
f_spare只是用来填充结构本身的备用字节。填充字节保留给以后使用。如果将来将一个__fsword_t的信息添加到结构中,他们将从f_spare中删除一个备用的__fsword_t。例如,我的系统只有4个备用__fsword_t(32个字节)。
为f_flags定义了哪些标志?
为您的系统定义的挂载标志可能不同,但我的man statfs64页面显示了以下内容:
ST_MANDLOCK
Mandatory locking is permitted on the filesystem (see fcntl(2)).
ST_NOATIME
Do not update access times; see mount(2).
ST_NODEV
Disallow access to device special files on this filesystem.
ST_NODIRATIME
Do not update directory access times; see mount(2).
ST_NOEXEC
Execution of programs is disallowed on this filesystem.
ST_NOSUID
The set-user-ID and set-group-ID bits are ignored by exec(3) for executable files on this filesystem
ST_RDONLY
This filesystem is mounted read-only.
ST_RELATIME
Update atime relative to mtime/ctime; see mount(2).
ST_SYNCHRONOUS
Writes are synched to the filesystem immediately (see the description of O_SYNC in open(2)).
ST_MANDLOCK
Mandatory locking is permitted on the filesystem (see fcntl(2)).
ST_NOATIME
Do not update access times; see mount(2).
ST_NODEV
Disallow access to device special files on this filesystem.
ST_NODIRATIME
Do not update directory access times; see mount(2).
ST_NOEXEC
Execution of programs is disallowed on this filesystem.
ST_NOSUID
The set-user-ID and set-group-ID bits are ignored by exec(3) for executable files on this filesystem
ST_RDONLY
This filesystem is mounted read-only.
ST_RELATIME
Update atime relative to mtime/ctime; see mount(2).
ST_SYNCHRONOUS
Writes are synched to the filesystem immediately (see the description of O_SYNC in open(2)).是f_fsid唯一标识文件系统的随机数,或者是什么?
直接来自man statfs64页面:“没有人知道f_fsid应该包含什么(但请参阅下面)”,下面是:
f_fsid 字段
Solaris、Irix和POSIX有一个系统调用statvfs(2),它返回包含无符号长f_fsid的statvfs (定义在其中)。Linux、SunOS、HP-UX、4.4BSD有一个系统调用statfs(),它返回包含fsid_t f_fsid的statfs (定义在其中),其中fsid_t被定义为struct { int val2;}。对于FreeBSD也是如此,但它使用的是包含文件。
一般的想法是,f_fsid包含一些随机的东西,使得这对(f_fsid,ino)唯一地决定一个文件。一些操作系统使用(对)设备号或与文件系统类型相结合的设备号。有几个操作系统限制只将f_fsid字段分配给超级用户(对于非特权用户则为零),因为当NFS导出时,该字段将用于文件系统的文件句柄中,并将其分发出去是一个安全问题。
在某些操作系统下,fsid可用作sysfs(2)系统调用的第二个参数。
https://stackoverflow.com/questions/59180592
复制相似问题