File System Implementation
File-System Implementation on Mass Storage
1. Purpose of a File System
A file system organizes data on a mass-storage device so that both users and operating systems can access files efficiently and reliably.
A file system must:
Provide users and application programs with a logical way to identify and access files.
Organize file data on a physical storage device.
Keep track of where files are stored.
Record which storage blocks are free and which are in use.
Preserve file and directory information when the computer is turned off.
Hide device-specific details from users and most applications.
Although hard disks are commonly used as examples, the same general principles can apply to many storage devices, including:
Solid-state drives
USB drives
Memory cards
Optical discs
Network storage
Other block-oriented mass-storage devices
A single computer may contain multiple physically different storage devices, but users should be able to interact with them through a consistent file-system interface.
A file system acts as the bridge between the logical view of files used by people and applications and the physical arrangement of blocks on a storage device.
2. Storage Units: Sectors, Blocks, and Logical Blocks
Storage devices are divided into small physical units, commonly called sectors. File systems usually work with larger units called blocks or logical blocks.
A logical block may consist of several physical sectors. For example, if a block contains four sectors, reading one logical block requires the device driver to perform four sector-level accesses, unless the device controller can combine them internally.
Why block sizes are coordinated
Storage units are commonly chosen as powers of two so that they divide neatly into one another. This avoids awkward arrangements in which the file-system block size does not align well with the device’s physical sectors.
For example:
A sector might be 512 bytes.
A file-system block might contain several sectors.
A larger logical file-system unit might consist of multiple blocks.
The exact sizes depend on the device and the file system.
3. Layers of File-System Access
File access typically passes through several layers. Each layer has a different responsibility.
3.1 User and application layer
Users and application programs view files through familiar concepts such as:
File names
Directories
File sizes
Creation and modification dates
Permissions
File types
Other metadata
Applications generally do not need to know which physical device contains a file or which sectors store its contents.
3.2 Logical file system
The logical file system manages the user-facing organization of files. It is responsible for:
File names
Directory structures
File permissions
File metadata
File-control information
File-opening and file-access operations
The logical file system translates operations such as “open report.txt” into lower-level requests.
3.3 File-control information
Each file has associated information commonly stored in a file control block, or an equivalent structure such as an inode.
A file-control structure may contain:
File name or a reference to the name
File type
File size
Ownership information
Access permissions
Creation, modification, and access times
Pointers or indexes identifying the file’s data blocks
Status information
The file-control structure is essential because the file’s contents and the information needed to locate those contents are separate.
3.4 Basic file system
The basic file system converts logical block requests into operations involving the storage device. It may:
Request a particular logical block.
Combine multiple sector requests into one logical-block operation.
Manage buffering.
Communicate with lower-level storage components.
3.5 Device drivers
A device driver performs device-specific operations. For a traditional hard disk, a driver may issue a command involving:
A drive
A cylinder
A track
A sector
A memory location where the data should be placed
For example, a low-level request might instruct the device to read a particular sector and transfer the result into memory.
Different devices require different drivers because their physical operation differs. A USB drive, hard disk, DVD-ROM, and network storage device do not necessarily use the same hardware commands.
3.6 Device controller and buffer
A storage device generally includes a controller and some temporary memory used as a buffer.
The controller:
Receives commands from the device driver.
Performs the physical read or write.
Temporarily stores transferred data.
Notifies the computer when the operation is complete.
The buffer prevents the entire computer system from having to wait in exact synchrony with the mechanical or electronic operation of the device. For a hard disk, the disk head may need to move before data can be read. The data can be placed in a controller buffer and transferred when the rest of the system is ready.
Buffering allows slow storage operations and faster processor activity to proceed with less strict synchronization.
4. Logical and Physical File Systems
A key design goal is to separate:
The logical view of a file used by users and applications.
The physical arrangement of that file on a device.
The logical file system may describe a file using its name, size, and metadata, while the physical file system determines which blocks contain the file’s actual data.
This separation makes it possible to support many different devices without changing the way applications access files.
Why multiple file systems exist
There is no single file system that is ideal for every purpose. Different file systems may be designed for:
Hard disks
Optical media
Removable drives
Network storage
High reliability
High performance
Large files
Many small files
Compatibility with a particular operating system
Special metadata requirements
For example, one system may support labels or color tags associated with files, while another may not provide space for such metadata. A file system designed for a CD-ROM may also have different requirements from one designed for a frequently modified hard disk.
Network drives may use separate file systems and device drivers from local storage, even though the user interacts with both through the same general file interface.
5. Persistent and In-Memory File-System Structures
File-system information must be stored persistently on the storage device because it must survive shutdowns and restarts.
Important persistent structures include:
Boot information
Volume information
Partition information
Directory structures
File-control blocks
File-allocation information
Free-space information
The actual file data
5.1 Boot control information
A storage device may contain a boot control block, which holds information needed to start an operating system from that device.
This can include information about:
How the volume is organized
Where boot code is located
Which structures must be loaded during startup
How the operating system can find the system files
5.2 Volume information
A device or partition needs information describing its layout, such as:
The number of blocks
The first and last usable blocks
The size of blocks
Which areas contain metadata
Which areas contain file data
Which blocks are currently free
5.3 Directory structures
Directories organize files into a hierarchy rather than placing every file in one large, unstructured list.
A directory may contain:
File names
References to file-control blocks
Subdirectory references
File type information
Other directory metadata
5.4 In-memory copies
Although the persistent versions remain on the device, frequently used file-system structures are often copied into main memory.
This may include:
Directory information
File-control blocks
File-allocation tables
Recently accessed data blocks
Free-space information
When an application opens a file, the operating system can search the in-memory directory structure instead of reading the directory from the storage device every time.
Without caching, opening a file could require:
Reading the directory from the device.
Locating the file’s metadata.
Reading the file-control information.
Performing another device access to retrieve the file data.
Keeping structures in memory reduces these extra device accesses.
Memory trade-off
Caching improves speed but consumes main memory. The amount of required memory increases with:
The size of the storage device
The number of storage devices
The number of directories
The number of active files
The amount of metadata being cached
The operating system must balance faster access against the memory cost of maintaining these caches.
6. Partitions and Mounting
A physical storage device may be divided into multiple partitions. Each partition is treated as a separate logical storage area and may contain its own file system.
Partitions can be used to:
Separate the operating system from user data.
Use different file systems for different purposes.
Isolate data for organization or protection.
Place relatively unchanging system files separately from frequently changing user files.
Support multiple operating systems.
Mounting
Mounting connects a partition or storage volume to the operating system’s existing file-system hierarchy.
Once mounted, the contents of the volume become accessible through a particular location.
Unix-style mounting
Unix-like systems commonly mount file systems at directory paths. For example:
The root file system is mounted at
/.A file system containing program binaries might be mounted at a path such as
/bin.A file system containing user data might be mounted at a path such as
/usror another designated directory.
The exact arrangement depends on the system configuration.
Windows-style mounting
Windows commonly assigns drive letters to volumes, such as C: or G:. A USB drive may automatically be assigned a drive letter when connected.
The underlying concept is the same: a logical file-system location is associated with a physical or network storage volume.
7. File-System Consistency and Safe Removal
File-system structures are frequently loaded into memory and modified there before being written back to the device. This applies to:
Directory entries
File-control blocks
Block-allocation information
Free-space information
File data
If a removable device is unplugged before these changes are written back, the persistent structures may become inconsistent.
Possible consequences include:
A file appearing in a directory but lacking valid data blocks.
Data blocks being allocated but not referenced by any file.
A directory pointing to the wrong location.
A file-control block containing an incorrect size.
Recently written data being lost.
Free-space information no longer matching actual usage.
This is why operating systems warn users to eject or safely remove removable storage devices.
File-system checking during startup
Many operating systems check storage volumes during startup. The check may verify that:
Directory entries point to valid files.
File-control blocks contain consistent information.
File data blocks are referenced correctly.
No two files incorrectly claim the same block.
Free-space information agrees with actual block usage.
The file-system structure is internally consistent.
If an earlier shutdown or removal was interrupted, the operating system may perform a more detailed repair or consistency check.
A file system is consistent when its metadata, allocation information, directories, and file data agree with one another.
Directory Implementation
8. Linear-List Directories
The simplest way to implement a directory is as a linear list of file entries.
Each entry may contain:
A file name
A reference to the file-control block
File attributes
Other metadata
To find a particular file, the system searches the entries one by one.
Advantages
Easy to implement.
Simple to understand.
Requires little additional structure.
Works adequately for very small directories.
Disadvantages
Searching becomes slow as the directory grows.
The system may need to inspect many entries before finding the desired file.
If the target is equally likely to be anywhere in the list, the average search examines approximately half of the entries.
A linear list has simple implementation but poor scalability.
9. Hash-Table Directories
A hash table uses a hash function to convert a file name or other key into an index or bucket location.
The general process is:
Apply a hash function to the file name.
Use the resulting value to identify a likely directory position.
Search only that position or a small associated group of entries.
Confirm that the stored name matches the requested name.
This avoids searching the entire directory in most cases.
Hash functions
A hash function produces a repeatable result:
The same file name should produce the same hash value.
Different file names ideally produce different values.
The result is used to locate the corresponding entry efficiently.
Collisions
A collision occurs when two different file names produce the same hash value.
Because collisions are possible, a hash-table directory needs a collision-handling method, such as:
Keeping multiple entries in the same bucket.
Searching a chain of entries.
Using an alternative open bucket.
Applying another probing strategy.
Hash tables are generally faster than linear lists for large directories, but their performance depends on the quality of the hash function, table size, and collision rate.
Hashing provides fast approximate location; the system still verifies the actual file name after reaching the hashed position.
File-Allocation Methods
File allocation determines how a file’s data blocks are placed on the storage device and how the operating system finds those blocks.
The major approaches discussed are:
Contiguous allocation
Extent-based allocation
Linked allocation
Indexed allocation
Multi-level indexed allocation
10. Contiguous Allocation
With contiguous allocation, all blocks belonging to a file are placed next to one another.
A directory or file-control entry needs to store:
The starting block
The number of blocks, or the file length
If a file begins at block s and the requested data is at offset r, the physical location can be calculated from the starting position and offset. If each block contains 512 bytes, the relevant block can be determined from the offset using the block size.
Example
Suppose a file:
Starts at block 0.
Occupies two blocks.
Another file starts at block 14 and occupies three blocks.
Each file can be described compactly by its starting block and length. The data blocks for each file form one continuous sequence.
Advantages
Very simple to implement.
Excellent sequential-access performance.
Excellent direct-access performance when the starting block and length are known.
Several consecutive blocks can often be read in one efficient operation.
Minimizes disk-head movement on traditional hard disks.
Disadvantages
The main problem is external fragmentation.
As files are created, deleted, and resized, unused gaps may appear between allocated files. The total free space may be sufficient for a new file, but no single gap may be large enough to hold it.
A growing file creates additional difficulties:
Space may have been allocated immediately after it.
The file may need to be moved to a larger free region.
A sufficiently large free region may not exist.
Moving files causes additional input/output operations.
The system may need to perform compaction.
Compaction
Compaction rearranges allocated files so that scattered free spaces are combined into a larger contiguous region.
Compaction can reduce fragmentation, but it is expensive because blocks must be moved and all affected references must remain correct.
Appropriate uses
Contiguous allocation is particularly suitable for:
Files whose sizes do not change.
Read-only data.
System partitions containing relatively stable operating-system files.
Workloads requiring very fast sequential access.
Using a separate partition for stable operating-system files and a different allocation method for changing user data can combine the strengths of different file-system designs.
11. Extent-Based Allocation
An extent is a contiguous run of blocks. Extent-based allocation allows a file to consist of one or more extents rather than requiring the entire file to occupy one continuous region.
When a file is created, the system may allocate an initial extent containing a requested number of contiguous blocks.
If the file grows beyond that space, the system can allocate another extent elsewhere on the device.
Example
A file might be stored as:
Extent 1: blocks 100–109
Extent 2: blocks 250–254
Extent 3: blocks 600–615
Each extent is internally contiguous, but the extents do not need to be adjacent to one another.
Advantages
Preserves much of the sequential-access performance of contiguous allocation.
Files can grow without being moved entirely.
Reduces the need to reserve a very large amount of unused space initially.
Requires fewer allocation references than allocating every block individually.
Works well for large files and databases.
Disadvantages
The system must maintain a list of extents.
A file can become fragmented across multiple extents.
Access may require movement between distant regions of a hard disk.
The system must decide how large each extent should be.
Allocating excessively large extents wastes space.
Extent allocation often involves a trade-off:
Larger extents improve performance and reduce metadata overhead.
Smaller extents reduce wasted space and adapt better to files that grow unpredictably.
On systems where storage space is charged or carefully managed, users or applications may need to estimate the amount of storage they will require before requesting an extent.
12. Linked Allocation
With linked allocation, a file’s blocks can be stored anywhere on the device. Each block contains a pointer to the next block belonging to the same file.
The file-control information stores the first block, and the chain continues until the final block.
Example
A file might be organized as:
The final block contains an end-of-file marker rather than a pointer to another block.
Advantages
Files can grow easily.
Blocks do not need to be contiguous.
External fragmentation is largely avoided.
A file can use individual free blocks as they become available.
Space does not need to be reserved in advance.
Disadvantages
Sequential access can be slow because the blocks may be spread across the device.
The storage head may move frequently on a hard disk.
A block must be read before the system knows the location of the next block.
Direct access is inefficient because the chain must be followed from the beginning.
A damaged pointer can make the rest of the file inaccessible.
Pointer storage consumes part of each block.
A fragmented linked file may take a long time to read because its blocks are scattered across the disk.
Defragmentation
A defragmentation utility can rearrange linked file blocks so that they are placed closer together or contiguously. This reduces the physical movement required during access and can improve performance.
Defragmentation does not change the logical contents of files; it changes the physical arrangement of their blocks.
13. File Allocation Tables
A file allocation table, or FAT-style structure, stores the links between blocks in a separate table rather than placing the next-block pointer directly inside every data block.
The file’s directory entry stores the first block. The allocation table then identifies the next block in the chain.
Example
A directory entry may indicate that a file starts at block 217. The allocation table might then specify:
The operating system follows the table entries to locate the complete file.
Advantages over pointers stored in data blocks
The data blocks can contain only file data.
The allocation information is centralized.
The chain can be inspected or cached separately.
The entire allocation table can potentially be loaded into memory.
Common removable-storage formats can be supported simply.
Disadvantages
If the allocation table is not cached, reading a file may require repeated accesses:
Read the first block.
Consult the table to find the next block.
Read the next block.
Consult the table again.
Continue until the end of the file.
If the table or a chain pointer is corrupted, the system may lose track of part or all of the file.
A basic linked allocation scheme may also fail to detect that a file is incomplete if the chain simply ends unexpectedly. Storing additional information, such as the expected final block or file size, can provide a consistency check.
14. Indexed Allocation
Indexed allocation stores a list of a file’s data-block addresses in a separate index block.
Instead of following a pointer from one data block to the next, the file-control structure points to the index block. The index block contains entries such as:
Block 9
Block 16
Block 110
Block 25
The system can use this list to locate all or many of the file’s data blocks.
Advantages
Avoids following a linked chain through every data block.
Supports more efficient direct access.
Makes it possible to request multiple file blocks together.
Data blocks can be located anywhere on the device.
Avoids external fragmentation associated with requiring one contiguous region.
Disadvantages
The index block consumes storage space.
A small file may not use all entries in its index block.
Very large files may require more than one index block.
The index block must itself be located and read.
A damaged index block may make much of the file inaccessible.
The space used by unused index entries is an overhead, but the performance benefit may justify it.
15. Multi-Level Indexed Allocation
A single index block may not contain enough entries for a large file. The system can extend indexed allocation by allowing index blocks to point to other index blocks.
15.1 Direct blocks
A file-control structure may contain direct pointers that point straight to data blocks.
This is efficient for small files because no additional index block is required.
15.2 Single indirect blocks
A single indirect pointer points to an index block. The index block contains pointers to data blocks.
The access path is:
15.3 Double indirect blocks
A double indirect pointer points to an index block whose entries point to further index blocks. Those lower-level index blocks finally point to data blocks.
The access path is:
15.4 Triple indirect blocks
A triple indirect pointer adds another level of indexing:
Combining methods
A file system may use all of these methods simultaneously:
Several direct pointers for small files.
A single indirect pointer for moderately larger files.
Double indirect pointers for large files.
Triple indirect pointers for extremely large files.
This design avoids imposing the cost of multiple levels of indexing on every file. Small files can be accessed quickly, while large files still have room to grow.
Trade-offs
Direct pointers provide fast access but limited capacity.
Indirect pointers support larger files but add lookup overhead.
Multiple index levels increase the number of metadata blocks.
Caching index blocks in memory can reduce repeated storage accesses.
The file-system designer chooses the combination based on expected file sizes, storage capacity, and access patterns.
Free-Space Management
16. Why Free-Space Tracking Is Needed
The file system must know which blocks are available before it can create or extend a file.
Free-space management records:
Which blocks are occupied.
Which blocks are unused.
Where large contiguous free regions exist.
How many free blocks remain.
Which blocks can be allocated to a new file.
Free-space management must be updated whenever blocks are:
Allocated to a file.
Released after a file is deleted.
Moved during defragmentation.
Reassigned during file growth.
17. Bitmap or Bit Vector
A bitmap uses one bit for each storage block.
For example:
A bit value of 1 can represent a free block.
A bit value of 0 can represent an allocated block.
The exact convention may be reversed, but the meaning must be defined consistently.
Finding free blocks
To allocate space, the operating system searches for a bit indicating a free block. Some processors provide instructions that locate the first set bit in a word or bit string.
For example, a processor may examine a machine word and return the offset of the first 1 bit. If that bit corresponds to a free block, the operating system can allocate it without performing another storage-device access.
Advantages
Compact representation.
Easy to update.
Makes it possible to identify individual free blocks.
Can help locate contiguous runs of free blocks.
Efficient when the bitmap is held in memory.
Disadvantages
The bitmap consumes memory.
Large storage devices require large bitmaps.
The operating system must keep the bitmap synchronized with actual allocation.
If one bit represents each block, a device with N blocks requires N bits of bitmap storage, or:
A very large storage device can therefore require a substantial amount of memory for its bitmap.
18. Linked List of Free Blocks
Instead of maintaining one bit for every block, the system can link free blocks together.
The free-space structure stores:
The first free block.
A pointer from each free block to the next free block.
Possibly the total number of free blocks.
When a block is allocated, the system removes it from the free-block chain and updates the first-free-block pointer.
Advantages
Can use less dedicated memory than a complete bitmap.
Free blocks are represented directly.
Easy to allocate individual blocks by following the chain.
Disadvantages
Finding many free blocks may require following many links.
The blocks may be scattered across the disk.
The method is inefficient for finding a large contiguous region.
Corruption of a link may make part of the free-space list inaccessible.
The system may need several storage accesses to traverse the list.
19. Grouping Free Blocks
A variation of linked free-space management groups multiple free blocks together.
One entry may record:
The starting block of a group.
The number of free blocks in the group.
The location of the next group.
For example, a free-space record might indicate:
A group begins at block 2 and contains 4 free blocks.
The next group begins at block 8 and contains 6 free blocks.
Another group begins at block 17 and contains 2 free blocks.
This representation captures not only where free space exists but also how much contiguous space is available.
Advantages
Reduces the number of links that must be followed.
Identifies contiguous regions efficiently.
Supports allocation of multiple adjacent blocks.
Can improve sequential file performance.
Grouping is especially useful when the system wants to allocate an entire file or file segment contiguously.
20. Free Extents
Free space can also be represented as a list of free extents. Each free extent records:
Its starting block.
Its length.
This is similar to extent-based file allocation, but it describes unused rather than allocated regions.
A free extent may be preferable when:
Large contiguous areas are important.
The device contains many consecutive free blocks.
The file system uses extent-based allocation.
The system wants to reduce metadata overhead.
As files are created and deleted, free extents may be split or merged.
21. Meta-Slabs and Very Large Storage Systems
For very large storage systems, such as systems containing hundreds of terabytes, it may be impractical to keep one complete free-space map in memory.
A solution is to divide the device into regions sometimes called meta-slabs or similarly organized allocation areas.
Each region has its own free-space map. Instead of maintaining one enormous structure for the entire device, the system maintains many smaller structures.
Benefits
Reduces the amount of free-space information that must be loaded at once.
Allows the system to manage storage region by region.
Makes large-scale allocation structures more practical.
Can improve locality by allocating related data within the same region.
The number and size of these regions depend on the file-system design and the scale of the storage device.
Performance Optimizations
22. Buffering
A buffer temporarily holds data while it is being transferred between the storage device and main memory.
Buffering helps because storage devices and processors operate at different speeds. Data can be read into a buffer before the requesting process is ready to use it.
Benefits include:
Reduced waiting.
Less synchronization between the device and processor.
More efficient transfer of multiple blocks.
Better handling of bursts of input and output.
23. Caching
A cache stores recently used or likely-to-be-used data in faster memory.
For file systems, the cache may contain:
Recently read file blocks.
Directory entries.
File-control blocks.
Allocation tables.
Index blocks.
Free-space information.
If the same information is requested again, it can be supplied from memory rather than read from the device.
Read-ahead
The operating system may predict that sequential access will continue and fetch additional blocks in advance.
For example, if block 10 is requested, the system may also read blocks 11 through 18 into the cache. If the application requests those blocks next, they are already available.
Read-ahead is especially effective for:
Sequential file reads.
Contiguous files.
Extent-based files.
Streaming data.
Cost of caching
Caching requires memory. The system must decide how much memory to devote to file data and metadata while leaving sufficient memory for applications and other operating-system tasks.
24. Delayed Writes and Write-Behind
The operating system may delay writing modified data to the storage device. Instead of immediately performing every individual write, it can group several writes together.
This can improve efficiency by:
Combining nearby writes.
Reducing the number of storage operations.
Ordering writes more effectively.
Taking advantage of sequential access.
Avoiding repeated updates to the same block.
For example, several updates to a directory and its file-control blocks may be collected and written together.
Risk of delayed writes
Delayed writes create a reliability risk. If power is lost or a removable device is disconnected before the changes are written, some updates may be lost.
File systems therefore use techniques such as:
Explicit synchronization operations.
Safe-ejection procedures.
Journaling.
Carefully ordered metadata updates.
Write barriers or flush operations.
The general performance principle is to reduce expensive device accesses, but this must be balanced against the need to preserve consistent data.
25. Choosing an Allocation Strategy
Each allocation method has different performance and reliability consequences.
Contiguous allocation
Very fast for sequential access.
Simple metadata.
Vulnerable to external fragmentation.
Difficult for files that grow unpredictably.
Extent-based allocation
Good sequential performance.
Files can grow through additional extents.
Less metadata than block-by-block allocation.
May still become fragmented across multiple extents.
Linked allocation
Flexible file growth.
Little external fragmentation.
Slow direct access.
Vulnerable to broken links and scattered blocks.
Indexed allocation
Supports direct and flexible access.
Requires index-block overhead.
Large files may require multiple levels of indexing.
Index caching can greatly improve performance.
Bitmap free-space management
Compact and easy to search in memory.
Requires memory proportional to the number of blocks.
Useful for identifying individual free blocks and contiguous runs.
Linked or grouped free-space management
Can reduce memory usage.
May require more searching or storage accesses.
Grouping improves the ability to find contiguous free regions.
The best design depends on:
Expected file sizes.
Whether files grow frequently.
Sequential versus random access.
Storage-device performance.
Available memory.
Reliability requirements.
The expected amount of fragmentation.
Whether the data is local, removable, optical, or network-based.
Key Takeaways
File-system implementation connects user-level file operations to the physical storage device through multiple abstraction layers.
Persistent structures such as directories, file-control blocks, allocation information, and free-space maps must be stored on the device, while frequently used copies may be cached in memory for speed.
Contiguous allocation is fast but vulnerable to fragmentation and difficult file growth; extent-based allocation preserves much of its performance while allowing files to expand.
Linked allocation supports flexible growth but can be slow and vulnerable to damaged links because each block identifies the next block.
Indexed and multi-level indexed allocation improve direct access by storing block addresses in index structures, although the index structures introduce overhead.
Free-space management may use bitmaps, linked lists, groups of free blocks, free extents, or region-based structures such as meta-slabs.
Buffering, caching, read-ahead, and delayed writes improve performance by reducing expensive storage accesses, but delayed updates must be handled carefully to prevent data loss and file-system inconsistency.

Ask anything
We've read this whole study set, so questions about it get the best answers.