Copyright © tutorialspoint.com
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);
struct statfs { long f_type; /* type of filesystem (see below) */ long f_bsize; /* optimal transfer block size */ long f_blocks; /* total data blocks in file system */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ long f_files; /* total file nodes in file system */ long f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */ long f_namelen; /* maximum length of filenames */ }; |
Nobody knows what f_fsid is supposed to contain (but see below).
Fields that are undefined for a particular file system are set to 0. fstatfs() returns the same information about an open file referenced by descriptor fd.
Tag | Description |
---|---|
EACCES | (statfs()) Search permission is denied for a component of the path prefix of path. (See also path_resolution(2).) |
EBADF | (fstatfs()) fd is not a valid open file descriptor. |
EFAULT | buf or path points to an invalid address. |
EINTR | This call was interrupted by a signal. |
EIO | An I/O error occurred while reading from the file system. |
ELOOP | (statfs()) Too many symbolic links were encountered in translating path. |
ENAMETOOLONG | |
(statfs()) path is too long. | |
ENOENT | (statfs()) The file referred to by path does not exist. |
ENOMEM | Insufficient kernel memory was available. |
ENOSYS | The file system does not support this call. |
ENOTDIR | |
(statfs()) A component of the path prefix of path is not a directory. | |
EOVERFLOW | |
Some values were too large to be represented in the returned struct. |
Some systems only have <sys/vfs.h>, other systems also have <sys/statfs.h>, where the former includes the latter. So it seems including the former is the best choice.
LSB has deprecated the library calls statfs() and fstatfs() and tells us to use statvfs() and fstatvfs() instead.
The general idea is that f_fsid contains some random stuff such that the pair (f_fsid,ino) uniquely determines a file. Some OSes use (a variation on) the device number, or the device number combined with the filesystem type. Several OSes restrict giving out the f_fsid field to the superuser only (and zero it for unprivileged users), because this field is used in the filehandle of the filesystem when NFS-exported, and giving it out is a security concern.
Under some OSes the fsid can be used as second parameter to the sysfs() system call.
Copyright © tutorialspoint.com