2 . 4
B A S I C F I L E S Y S T E M O P E R AT I O N S
27
Writing Metadata
If there is the ability to read the metadata of a file, it is also likely that it
will be necessary to modify it. The write metadata operation allows a pro-
gram to modify fields of a file's i-node. At the user level there may be poten-
tially many different functions to modify each of the fields (
chown()
,
chmod()
,
utimes()
, etc.), but internally there need only be one function to do this. Of
course, not all fields of an i-node may be modifiable.
Opening Directories
Just as access to the contents of a file is initiated with
open()
, there is an
analog for directories, usually called
opendir()
. The notion of "opening" a
directory is simple. A directory needs to provide a mechanism to access the
list of files stored in the directory, and the
opendir
operation is the opera-
tion used to grant access to a directory. The argument to
opendir
is simply
a reference to a directory. The requesting program must have its permis-
sions checked; if nothing prevents the operation, a handle is returned that
the requesting program may use to call the
readdir
operation.
Internally the
opendir
function may need to allocate a state structure so
that successive calls to
readdir
to iterate through the contents of the direc-
tory can maintain their position in the directory.
Reading Directories
The
readdir
operation enumerates the contents of a directory. There is no
corresponding
WriteDir
(strictly speaking,
create
and
makedir
both "write"
to a directory). The
readdir
operation must iterate through the directory,
returning successive name/i-node pairs stored in the directory (and poten-
tially any other information also stored in the directory). The order in which
entries are returned depends on the underlying data structure.
If a file system has a complex data structure for storing the directory en-
tries, then there is also some associated state (allocated in
opendir
) that the
file system preserves between calls to
readdir
. Each call to
readdir
updates
the state information so that on the next call to
readdir
, the successive
element in the directory can be read and returned.
Without
readdir
it would be impossible for programs to navigate the file
system hierarchy.
Basic File System Operation Summary
The file system operations discussed in this section delineate a baseline of
functionality for any file system. The first operation any file system must
provide is a way to initialize a volume. Mounting a file system so that the
Practical File System Design:The Be File System
, Dominic Giampaolo
page 27