The Filesystem Stat Interface

The df command displays information about the filesystem usage such as the number of free and used blocks. Through the super_block operations vector, uxfs exports the ux_statfs() function, which is called in response to df invoking the stafs system call (once for each filesystem). The ux_statfs() function can be found on lines 1194 to 1210. The function prototype is shown below:

ux_statfs(struct super_block *sb, struct statfs *buf);

The df command will make a call to the statfs() system call for each mounted filesystem. Here is the prototype for statfs().

int statfs(const char *path, struct statfs *buf);

Note that it also uses the statfs structure which is defined below:

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 */

As mentioned earlier in the book, understanding the requirements of user level programs is essential to understanding some of the features that must be provided by filesystems. The information passed through the statfs structure corresponds to filesystem limits, such as the total number of files and blocks in the filesystem, and existing ...

Get UNIX Filesystems: Evolution, Design, and Implementation now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.