Page 450 - DCAP103_Principle of operating system
P. 450
Unit 14: Case Study of Linux Operating System
The return code s is ~1 if an error has occurred; dir identifies a directory stream and dirent is a Notes
directory entry. The parameters should be self-explanatory. As we saw in Figure 14.29, linking
to a file creates a new directory entry that points to an existing file. The link system call creates
the link. The parameters specify the original and new names, respectively. Directory entries are
removed with unlink. When the last link to a file is removed, the file is automatically deleted. For
a file that has never been linked, the first unlink causes it to disappear. The working directory
is changed by the chdir system call. Doing so has the effect of changing the interpretation of
relative path names.
The last four calls of Figure 14.30 are for reading directories. They can be opened, closed, and
read, analogous to ordinary files. Each call to readdir returns exactly one directory entry in a
fixed format. There is no way for users to write in a directory (in order to maintain the integrity
of the file system). Files can be added to a directory using create or link and removed using
unlink. There is no way to seek to a specific file in a directory, but rewinddir allows an open
directory to be read again from the beginning.
14.6.3 Implementation of the Linux File System
In this section first we will look at the abstractions supported by the Virtual File System layer.
The VFS hides from higher level processes and applications the differences among many types
of file systems supported by Linux, whether they are residing on local devices or are stored
remotely and need to be accessed over the network. Devices and other special files are also
accessed through the VFS layer. Next, we will describe the implementation of the first wide-
spread Linux file system, ext2, or the second extended file system. Afterward, we will discuss
the improvements in the ext3 file system. A wide variety of other file systems are also in use.
All Linux systems can handle multiple disk partitions, each with a different file system on it.
14.6.4 Linux Virtual File System
In order to enable applications to interact with different file systems, implemented on different
types of local or remote devices, Linux adopts an approach used in other UNIX systems: the
Virtual File System (VFS). VFS defines a set of basic file system abstractions and the operations
which are allowed on these abstractions. Invocations of the system calls described in the previous
section, access the VFS data structures, determine the exact file system where the accessed file
belongs, and via function pointers stored in the VFS data structures invoke the corresponding
operation in the specified file system. Figure 14.30 summarizes the four main file system structures
supported by VFS. The superblock contains critical information about the layout of the file
system. Destruction of the superblock will render the file system unreadable. The i-nodes (short
for index-nodes, but never called that, although some lazy people drop the hyphen and call
them inodes) each describe exactly one file. Note that in Linux, directories and devices are also
represented as files, thus they will have corresponding i-nodes. Both superblocks and i-nodes
have a corresponding structure maintained on the physical disk where the file system resides.
Figure 14.30: File System Abstractions Supported by the VFS
Object Description Operation
Superblock specific filesystem read_inode, sync_fs
Dentry directory entry, single component of a path create, link
I-node specific file d_compare, d_delete
File open file associated with a process read, write
LOVELY PROFESSIONAL UNIVERSITY 443