W H AT I S A F I L E S Y S T E M ?
composed of two operations. The first operation, lookup, takes a reference
to a directory and a name and looks up the name in that directory. Looking
up a name involves traversing the directory data structure looking to see if a
name exists and, if it does, returning the associated i-node. The efficiency of
the lookup operation is important. Many directories have only a few files, and
so the choice of data structure may not be as important, but large servers rou-
tinely have directories with thousands of entries in them. In those situations
the choice of directory data structure may be of critical importance.
Given an i-node number, the second half of an open operation involves
verifying that the user can access the file. In systems that have no permission
checking, this is a no-op. For systems that care about security, this involves
checking permissions to verify that the program wishing to access the file
is allowed to do so. If the security check is successful, the file system then
allocates an in-memory structure to maintain state about access to the file
(such as whether the file was opened read-only, for appending, etc.).
The result of an open operation is a handle that the requesting program
can use to make requests for I/O operations on the file. The handle returned
by the file system is used by the higher-level portions of the operating sys-
tem. The operating system has additional structures that it uses to store this
handle. The handle used by a user-level program is related indirectly to the
internal handle returned by the open operation. The operating system gener-
ally maps a user-level file descriptor through several tables before it reaches
the file system handle.
Writing to Files
The write operation of a file system allows programs to store data in files.
The arguments needed to write data to a file are a reference to the file, the
position in the file to begin writing the data at, a memory buffer, and the
length of the data to write. A write to a file is equivalent to asking the file
system to copy a chunk of data to a permanent location within the file.
The write operation takes the memory buffer and writes that data to the
file at the position specified. If the position given is already at the end of the
file, the file needs to grow before the write can take place. Growing the size
of a file involves allocating enough disk blocks to hold the data and adding
those blocks to the list of blocks "owned" by the file.
Growing a file causes updates to happen to the free/used block list, the file
i-node, and any indirect or double-indirect blocks involved in the transaction.
Potentially the superblock of the file system may also be modified.
Once there is enough space for the data, the file system must map from the
logical position in the file to the disk block address of where the data should
be written to. With the physical block address the file system can then write
the data to the underlying device, thus making it permanent.
Practical File System Design:The Be File System
, Dominic Giampaolo