The Linux Programming Interface

(nextflipdebug5) #1
File Systems 259

One other benefit conferred by this design is that files can have holes, as
described in Section 4.7. Rather than allocate blocks of null bytes for the holes in a
file, the file system can just mark (with the value 0) appropriate pointers in the i-node
and in the indirect pointer blocks to indicate that they don’t refer to actual disk blocks.

14.5 The Virtual File System (VFS)


Each of the file systems available on Linux differs in the details of its implementa-
tion. Such differences include, for example, the way in which the blocks of a file are
allocated and the manner in which directories are organized. If every program that
worked with files needed to understand the specific details of each file system, the
task of writing programs that worked with all of the different file systems would be
nearly impossible. The virtual file system (VFS, sometimes also referred to as the
virtual file switch) is a kernel feature that resolves this problem by creating an
abstraction layer for file-system operations (see Figure 14-3). The ideas behind the
VFS are straightforward:

z The VFS defines a generic interface for file-system operations. All programs
that work with files specify their operations in terms of this generic interface.
z Each file system provides an implementation for the VFS interface.

Under this scheme, programs need to understand only the VFS interface and can
ignore details of individual file-system implementations.
The VFS interface includes operations corresponding to all of the usual system
calls for working with file systems and directories, such as open(), read(), write(),
lseek(), close(), truncate(), stat(), mount(), umount(), mmap(), mkdir(), link(), unlink(),
symlink(), and rename().
The VFS abstraction layer is closely modeled on the traditional UNIX file-system
model. Naturally, some file systems—especially non-UNIX file systems—don’t support
all of the VFS operations (e.g., Microsoft’s VFAT doesn’t support the notion of
symbolic links, created using symlink()). In such cases, the underlying file system
passes an error code back to the VFS layer indicating the lack of support, and the
VFS in turn passes this error code back to the application.

Figure 14-3: The virtual file system

Application

Virtual File System (VFS)

ext2 ext3 Reiserfs VFAT NFS
Free download pdf