Lecture 5

Basic File System Operations

By considering the fundamental operations we can carry out using file systems, we can see the inherent issues associated with their implementation.

Initialization

We must be able to turn a newly allocated region of a disk into a file system or part of a file system. In any file system there must be at least one fixed location structure. In more traditional unix file systems there are many fixed location structures. These must be laid out in order to allow one to manipulate files. We must also create an empty root (top-level) directory within the file system.

Mounting

Mounting is the act of making a physical file system representation on some medium available for use by the operating system and programs it may run. To do this, we must read the file system metadata from the medium.

Sometimes the system to be mounted may be inconsistent due to physical damage or due to premature termination of file system processes when it was last mounted. Most file systems nowadays will make a record of whether or not they are clean, that is whether or not proper shutdown occurred and the state of the file system can be considered to be consistent.

If a file system is known to be inconsistent, it must be checked (at least) and repaired (if necessary and possible). It is possible that a file system not marked as consistent will in fact be consistent, but this is not the norm.

Journalling can allow us to more easily repair any inconsistencies that may occur.

Even file systems marked as consistent may not be. The amount of work needed to completely verify the consistency of a file system, however, can be significant. The trade-off a file system makes between how scrupulously to verify consistency and how quickly to start up is an important engineering decision.

After verifying consistency of the file system, file system metadata will be read and stored in active memory. Tables maintained in the running operating system cache the file system metadata so that it is more easily accessible.

Unmounting

The primary task achieved by unmounting is to flush the cached metadata so that the representation on disk will be consistent and to mark the system as being clean. Once it is marked clean, the file system representation should only be accessed after a succeeding mount.

Creating Files

To create a file on a Unix system, you need the following information:

The name to i-node mapping will be inserted into the specified directory.

The data blocks of the file can be created at any time once the i-node has been allocated.

Creating Directories

All activities required to create a file must be carried out when creating a directory, but, in addition, the directory's data blocks must be initialized to represent an empty directory.

All directories in Unix file systems always contain the two entries `.' and `..' corresponding to the directory itself and its parent directory (the one in which it is contained).

Opening Files

A file open operation typically requires looking up a file path in the file system. This involves two parts: finding the directory containing the file, either from the root directory or from some other known directory, and finding the file's i-node within that directory. Once the file is found, the system must determine if the process requesting access to the file has appropriate authorization for the requested access.

Some attributes of the file such as the i-node address (or its equivalent), requested access mode, and so forth will be stored in memory and a handle referring to this data will be provided to the requesting process.

Writing to Files

A file system write involves a process identifying the file to be written (usually by giving its handle), data to be written to the file, and the location in which that data is to be written.

The data may be buffered by the file system and not be written immediately.

When the data are written, if they are to be appended to the file, new blocks must be allocated.

The file system must identify the specific blocks to be written and then transfer the data to those blocks.

Reading From Files

A file system read involves a process identifying the file to be read (usually by giving its handle), and the starting address and number of bytes to read from the file. This requires the block to be read to be identified and then read. The file system may request blocks other than those specified and store their contents in a buffer.