
디스크의 남은 디스크 공간을 표시할 수 있는 도구가 있다는 것을 알고 있지만 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가 유지되어야 한다고 생각한다슈퍼블록 어딘가의 사용 가능한 블록 수, 블록 크기와 함께 사용하여 여유 공간을 확보합니다.