7 File Systems and Storage

Learn how file systems organize files and directories, map data onto storage, and control access through permissions.

Files and

A presents information on a storage device as named files and directories, while keeping track of where data is stored and who may access it. Different file systems can organize storage differently even when programs use similar file operations.

A file is a named object that stores data or provides another kind of resource. Regular files can contain documents or programs; other file types can represent directories, symbolic links, or device interfaces. File systems associate files with , including properties such as type, size, owner, permissions, timestamps, and data locations.

Directories and paths

A directory organizes names into a hierarchy and conceptually maps each name to a file-system object. For example, /home/lee/notes.txt identifies an object by starting at the root directory and following each component. An begins at the root, while a begins at the process’s current working directory.

To resolve a path, the operating system looks up its components in turn. On Unix-like systems, a process generally needs search (execute) permission on each directory it traverses. Reading a directory and searching it are different: read permission allows listing names, while search permission allows looking up known names within it.

How file systems organize data

A keeps both file data and the needed to find and manage that data. A typical on-disk design includes:

  • Superblock or volume : information about the as a whole, such as its size and layout.

  • File records: structures such as inodes that describe individual files and point to their data.

  • Directory records: mappings from names to file records.

  • Allocation : records of which storage units and file records are in use or free.

  • Data blocks: units that store file contents and other file-system information.

On many Unix-like file systems, an stores and identifies a file’s data blocks. A directory entry usually stores the filename separately and maps it to an number. Because names and inodes are separate, multiple directory entries called hard links can refer to the same . A is different: it is a file that stores a path to another file.

The ext4 divides storage into groups and uses structures including a superblock, tables, and and bitmaps. These details are specific to ext4; other file systems use different on-disk structures. The operating system can make different file systems available through a common interface and attach one into the directory hierarchy by mounting it.

Storage allocation and free space

Storage devices are divided into addressable units, and a allocates space for file data while tracking which units belong to which files and which remain available. A is a file-system allocation unit, usually larger than a device sector. If a file occupies only part of its final , some space may go unused.

Common allocation approaches make different trade-offs:

  • Contiguous allocation: a file occupies consecutive blocks. Sequential access can be fast, but growing the file may be difficult if the following blocks are occupied, and free space can become fragmented.

  • Linked allocation: each points to the next in a file. A file can grow without adjacent space, but reaching a later portion can be slow because the chain must be followed.

  • Indexed allocation: an index structure records a file’s blocks, allowing the system to locate file data without following every earlier .

  • : a file is represented by ranges of consecutive blocks called extents. Extents can describe large files compactly while allowing nonadjacent ranges as files grow. For example, ext4 uses extent trees for file-to- mapping.

To track free space, a can use a bitmap, in which each bit represents whether a is free or allocated, or another structure that records available ranges. Allocation policies balance speed, space efficiency, and fragmentation. Keeping related data near each other can improve access efficiency on some storage devices.

Permissions and access

File systems help control access by associating files with owners, groups, and permissions. A common Unix-like model has three classes—owner, group, and others—and three basic permissions:

  • Read (r): read file contents; for a directory, list its names.

  • Write (w): modify file contents; for a directory, create, remove, or rename entries, subject to other rules.

  • Execute (x): run an executable file; for a directory, search it to access named entries.

The permissions rw-r--r-- mean that the owner can read and write, while group members and others can only read. Permission checks also depend on ownership and the identity of the accessing process. Access-control lists can provide more detailed rules, and a process’s may restrict the permissions requested when a new file is created.

Directory permissions govern access to entries, not just the contents of a file with the same name. A user might have permission to read a file but still be unable to reach it if they lack search permission on a directory in its path. Distinguishing file permissions from directory permissions is essential when diagnosing access errors.