Skip to content
Advertisement

More explanation on `statfs64`

According to documentation, the structure fields explanation follows:

struct statfs {
__SWORD_TYPE f_type; /* type of file system (see below) */
__SWORD_TYPE f_bsize; /* optimal transfer block size */
fsblkcnt_t f_blocks; /* total data blocks in file system */
fsblkcnt_t f_bfree; /* free blocks in fs */
fsblkcnt_t f_bavail; /* free blocks available to
unprivileged user */
fsfilcnt_t f_files; /* total file nodes in file system */
fsfilcnt_t f_ffree; /* free file nodes in fs */
fsid_t f_fsid; /* file system id */
__SWORD_TYPE f_namelen; /* maximum length of filenames */
__SWORD_TYPE f_frsize; /* fragment size (since Linux 2.6) */
__SWORD_TYPE f_spare[5];
};

Does “total file nodes in file system” mean how much existing files we have? Does it include directories and links?

What does mean “free file nodes in fs“?

What is f_spare?

In some Linux forks (for example, in Android) I see that f_spare size is 4, and additional field f_flags is defined. What flags are defined for f_flags?

Is f_fsid just random number that uniquely identifies the file system, or what is it?

Advertisement

Answer

Does “total file nodes in file system” mean how much existing files we have? Does it include directories and links?

Almost. Yes, it includes directories and softlinks, but two files can can share the same inode. In that case, they are hardlinked and share the same space on hard disk, but is viewed as different files in the filesystem. Example to illustrate:

% echo Hello > test1.txt
% ln test1.txt test2.txt
% ls -i test1.txt test2.txt
14946320 test1.txt  14946320 test2.txt

The number you’ll see to the left of the filenames are the inodes (you’ll have a different number than in my example). As you can see, they have the same inode. If you make a change to one file, the same change will be visible through the other file.

What does mean “free file nodes in fs”?

A filesystem often have an upper limit of inodes it can keep track of. The actual type fsfilcnt_t sets one limit (18446744073709551615 on my system), but it’s most probably something lower. Unless you use your filesystem in very special ways, this limit is usually not a problem.

What is f_spare? In some Linux forks (for example, in Android) I see that f_spare size is 4, and additional field f_flags is defined.

f_spare is just spare bytes to pad the struct itself. The padding bytes are reserved for future use. If one __fsword_t of info is added to the struct in the future, they’ll remove one spare __fsword_t from f_spare. My system only has 4 spare __fsword_ts for example (32 bytes).

What flags are defined for f_flags?

The mount flags defined for your system may be different, but my man statfs64 page shows these:

   ST_MANDLOCK
          Mandatory locking is permitted on the filesystem (see fcntl(2)).

   ST_NOATIME
          Do not update access times; see mount(2).

   ST_NODEV
          Disallow access to device special files on this filesystem.

   ST_NODIRATIME
          Do not update directory access times; see mount(2).

   ST_NOEXEC
          Execution of programs is disallowed on this filesystem.

   ST_NOSUID
          The set-user-ID and set-group-ID bits are ignored by exec(3) for executable files on this filesystem

   ST_RDONLY
          This filesystem is mounted read-only.

   ST_RELATIME
          Update atime relative to mtime/ctime; see mount(2).

   ST_SYNCHRONOUS
          Writes are synched to the filesystem immediately (see the description of O_SYNC in open(2)).
   ST_MANDLOCK
          Mandatory locking is permitted on the filesystem (see fcntl(2)).

   ST_NOATIME
          Do not update access times; see mount(2).

   ST_NODEV
          Disallow access to device special files on this filesystem.

   ST_NODIRATIME
          Do not update directory access times; see mount(2).

   ST_NOEXEC
          Execution of programs is disallowed on this filesystem.

   ST_NOSUID
          The set-user-ID and set-group-ID bits are ignored by exec(3) for executable files on this filesystem

   ST_RDONLY
          This filesystem is mounted read-only.

   ST_RELATIME
          Update atime relative to mtime/ctime; see mount(2).

   ST_SYNCHRONOUS
          Writes are synched to the filesystem immediately (see the description of O_SYNC in open(2)).

Is f_fsid just random number that uniquely identifies the file system, or what is it?

Directly from the man statfs64 page: “Nobody knows what f_fsid is supposed to contain (but see below)” and further below:

The f_fsid field

Solaris, Irix and POSIX have a system call statvfs(2) that returns a struct statvfs (defined in ) containing an unsigned long f_fsid. Linux, SunOS, HP-UX, 4.4BSD have a system call statfs() that returns a struct statfs (defined in ) containing a fsid_t f_fsid, where fsid_t is defined as struct { int val[2]; }. The same holds for FreeBSD, except that it uses the include file .

The general idea is that f_fsid contains some random stuff such that the pair (f_fsid,ino) uniquely determines a file. Some operating systems use (a variation on) the device number, or the device number combined with the filesystem type. Several operating systems 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 operating systems, the fsid can be used as the second argument to the sysfs(2) system call.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement