我知道有些工具df
可以显示磁盘上剩余的磁盘空间,但是我找不到有关此工具如何实际获取此信息的任何信息。我想文件系统会以某种方式跟踪此信息,但是我也找不到任何信息。
关于如何从文件系统(特别是ext4)中收集此信息,或者是否有任何有助于查找此信息的术语,是否有明确的解释?
您可以看到df
使用什么strace
:
$ strace df / |& grep -i ext
statfs("/", {f_type=EXT2_SUPER_MAGIC, f_bsize=4096, f_blocks=4611519, f_bfree=864281, f_bavail=624269, f_files=1179648, f_ffree=620737, f_fsid={126240841, 1491846125}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_RELATIME}) = 0
来自man 2 statfs
:
The statfs() system call returns information about a mounted
filesystem. path is the pathname of any file within the mounted
filesystem. buf is a pointer to a statfs structure defined
approximately as follows:
struct statfs {
__fsword_t f_type; /* Type of filesystem (see below) */
__fsword_t f_bsize; /* Optimal transfer block size */
fsblkcnt_t f_blocks; /* Total data blocks in filesystem */
fsblkcnt_t f_bfree; /* Free blocks in filesystem */
fsblkcnt_t f_bavail; /* Free blocks available to
unprivileged user */
fsfilcnt_t f_files; /* Total file nodes in filesystem */
fsfilcnt_t f_ffree; /* Free file nodes in filesystem */
fsid_t f_fsid; /* Filesystem ID */
__fsword_t f_namelen; /* Maximum length of filenames */
__fsword_t f_frsize; /* Fragment size (since Linux 2.6) */
__fsword_t f_flags; /* Mount flags of filesystem
(since Linux 2.6.36) */
__fsword_t f_spare[xxx];
/* Padding bytes reserved for future use */
};
如果您只想挂载点的自由空间,则statfs
似乎是一个路要走。可用块*块大小=可用空间(-保留空间等)。
我想ext4必须将空闲块的计数保留在superblock中的某个位置,然后将其与块大小一起使用以获取可用空间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句