ext4では、空きディスク容量はどのように計算されますか?

ext4では、空きディスク容量はどのように計算されますか?

ディスクの残りのディスク容量を表示できるツールがあることはわかっていますが、dfツールが実際にこの情報を取得する方法に関する情報は見つかりません。ファイルシステムが何らかの形でこの情報を追跡していると思いますが、それに関する情報も見つかりません。

ファイルシステム(特にext4)からこの情報を収集する方法の簡単な説明や、この情報を見つけるのに役立つ用語はありますか?

ベストアンサー1

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が維持されるべきだと思います。スーパーブロックのどこかで利用可能なブロック数、ブロックサイズとともに使用して空き容量を確保します。

おすすめ記事