File Systems 277
z Many native UNIX and Linux file systems support the notion of reserving a
certain portion of the blocks of a file system for the superuser, so that if the file
system fills up, the superuser can still log in to the system and do some work to
resolve the problem. If there are reserved blocks in the file system, then the dif-
ference in values of the f_bfree and f_bavail fields in the statvfs structure tells us
how many blocks are reserved.
z The f_flag field is a bit mask of the flags used to mount the file system; that is, it
contains information similar to the mountflags argument given to mount(2).
However, the constants used for the bits in this field have names starting with
ST_ instead of the MS_ used for mountflags. SUSv3 requires only the ST_RDONLY and
ST_NOSUID constants, but the glibc implementation supports a full range of con-
stants with names corresponding to the MS_* constants described for the
mount() mountflags argument.
z The f_fsid field is used on some UNIX implementations to return a unique
identifier for the file system—for example, a value based on the identifier of the
device on which the file system resides. For most Linux file systems, this field
contains 0.
SUSv3 specifies both statvfs() and fstatvfs(). On Linux (as on several other UNIX
implementations), these functions are layered on top of the quite similar statfs()
and fstatfs() system calls. (Some UNIX implementations provide a statfs() system
call, but don’t provide statvfs().) The principal differences (aside from some differ-
ently named fields) are as follows
z The statvfs() and fstatvfs() functions return the f_flag field, giving information
about the file-system mount flags. (The glibc implementation obtains this infor-
mation by scanning /proc/mounts or /etc/mtab.)
z The statfs() and fstatfs() system calls return the field f_type, giving the type of the
file system (e.g., the value 0xef53 indicates that this is an ext2 file system).
The filesys subdirectory in the source code distribution for this book contains
two files, t_statvfs.c and t_statfs.c, demonstrating the use of statvfs() and statfs().
14.12 Summary..................................................................................................................
Devices are represented by entries in the /dev directory. Each device has a corre-
sponding device driver, which implements a standard set of operations, including
those corresponding to the open(), read(), write(), and close() system calls. A device
may be real, meaning that there is a corresponding hardware device, or virtual,
meaning that no hardware device exists, but the kernel nevertheless provides a
device driver that implements an API that is the same as a real device.
A hard disk is divided into one or more partitions, each of which may contain a
file system. A file system is an organized collection of regular files and directories.
Linux implements a wide variety of file systems, including the traditional ext2 file
system. The ext2 file system is conceptually similar to early UNIX file systems, con-
sisting of a boot block, a superblock, an i-node table, and a data area containing file
data blocks. Each file has an entry in the file system’s i-node table. This entry contains