File systems
File questions combine names and metadata with block allocation. First determine whether the question asks for file data, occupied storage, pointer capacity or disk accesses. These quantities are related but are not equal.
8.1 Names, directories and open files
Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark
A directory maps names to file identifiers. An inode or file control block stores metadata and block-location information; it normally does not store every directory name referring to the file. An absolute path starts at the root; a relative path starts at the current working directory.
| Object | Holds or represents |
|---|---|
| Descriptor | Per-process handle, usually an integer |
| Open-file description | Current offset and open status; can be shared through fork or descriptor duplication |
| Inode/file control block | Identity, ownership, permissions, size, block references and other metadata |
| Directory entry | A name and its file reference |
| Mount point | Location where another file-system tree is attached |
In an unsorted linear directory with no auxiliary index, finding an existing name can stop at its entry. Proving a proposed new name absent requires scanning the whole list. Thus creation and a rename to a fresh name require an absence check; successful open or deletion need not scan past the found entry. These rules assume unique names and no overwrite-on-rename convention.
Two independent opens normally create distinct open-file descriptions and offsets. dup and inherited descriptors after fork refer to the same open-file description. Closing one descriptor does not close another live reference to it.
For Unix-style permissions, read/write/execute bits apply separately to owner, group and others. On a directory, execute permits searching/traversal and read permits listing names; modifying entries needs appropriate directory permissions. File execute permission is not a requirement for reading file contents.
8.2 Allocation methods and block counts
Past papers · CS 2014–2026 (23 papers): 3 questions, 4 marks
| Allocation | Random access | Growth and overhead |
|---|---|---|
| Contiguous | Compute block from start plus index | Needs a large contiguous extent; growth may require moving data |
| Linked | Follow the chain to the desired block | Link storage and pointer chasing; no need for one contiguous run |
| FAT | Follow links in a separate table | Table may be cached; one entry per disk block |
| Indexed/inode | Follow the index path | Index blocks consume space and may require reads |
| Extent based | Locate the extent, then add an offset | Stores runs rather than a pointer for every data block |
8.3 Direct and indirect inode addressing
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
Each extra indirection level multiplies the reachable data blocks by the index-block fan-out.
For one pointer of each indirect type, data-block index is direct for , single-indirect for , and double-indirect for the following indices. The next are triple-indirect. These are half-open ranges; an index equal to the upper endpoint belongs to the next range.
8.4 Counting accesses and file updates
Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks
A later access can reuse cached index blocks, so do not multiply the first-access cost by the number of data blocks without checking the cache model. Reading many adjacent blocks often amortises a single index-block read.
For insertion into a contiguous file, enumerate each displaced block's read and write, then the new block's write. For linked allocation, locate the predecessor, update its next pointer, write the inserted block, and count any metadata writes the question includes. If the predecessor was already read during traversal, do not charge a second read merely to edit its link.
8.5 Free-space management
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
A bitmap records one free/allocated bit per block. Its bit convention may be either 0-free or 1-free; use the question's convention. A simple free-block chain stores its next pointer inside free blocks. Grouping stores several free block numbers in one block of the list. Counting represents runs by a start block and run length.
8.6 Links, deletion and consistency
A hard link gives another directory name to the same inode. It does not duplicate data blocks and normally stays within one file system. A symbolic link is a separate object containing a target pathname; it may cross file systems and can dangle after target removal. Ordinary user-created hard links to directories are restricted to avoid cycles and bookkeeping problems.
Unlink removes a directory entry. A regular file's storage is reclaimable when no hard links and no open references remain, subject to the file system's implementation. Removing one of several names does not erase the object named by the others.
A crash can interrupt a multi-block metadata update. Consistency checking compares allocation and directory metadata after a crash. Journaling records changes in a log so recovery can finish or discard a transaction according to its commit state. Metadata-only journaling does not guarantee that every recent user-data write is durable. Buffering, caching and durable persistence are distinct concepts.
Last-minute recall
- Names refer to file identities; descriptors refer to open descriptions.
- Fork and dup can share offsets; independent opens normally do not.
- File length counts user data, not indirect index blocks.
- Divide block bytes by pointer bytes to get index fan-out.
- Count partially used indirect blocks and the roots above them.
- Include directory traversal only when the cache assumptions require it.
- A free-list grouping block loses space to its next pointer.
- Removing a name need not immediately reclaim the file's data.