Você pode ver o que o df
usa usando 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
E de 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 */
};
Se você quiser apenas o espaço livre de um ponto de montagem, statfs
parece ser o caminho a percorrer. Blocos grátis * tamanho do bloco = espaço livre (- espaço reservado, etc.).
Eu imagino que o ext4 deve manter a contagem de blocos livres em algum lugar no superbloco , que você usa com o tamanho do bloco para obter o espaço livre.