The Linux Programming Interface

(nextflipdebug5) #1

DIRECTORIES AND LINKS


In this chapter, we conclude our discussion of file-related topics by looking at direc-
tories and links. After an overview of their implementation, we describe the system
calls used to create and remove directories and links. We then look at library func-
tions that allow a program to scan the contents of a single directory and to walk
through (i.e., examine each file in) a directory tree.
Each process has two directory-related attributes: a root directory, which deter-
mines the point from which absolute pathnames are interpreted, and a current
working directory, which determines the point from which relative pathnames are
interpreted. We look at the system calls that allow a process to change both of these
attributes.
We finish the chapter with a discussion of library functions that are used to
resolve pathnames and to parse them into directory and filename components.

18.1 Directories and (Hard) Links........................................................................................


A directory is stored in the file system in a similar way to a regular file. Two things
distinguish a directory from a regular file:

z A directory is marked with a different file type in its i-node entry (Section 14.4).
z A directory is a file with a special organization. Essentially, it is a table consist-
ing of filenames and i-node numbers.
Free download pdf