1. Home
  2. Explore
  3. Computer Science
  4. File System Implementation

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

File System Implementation

File Systems, Storage Devices, and Disk Management

File systems as layers

A file system gives programs a consistent way to create, find, read, and modify files without requiring them to know how data is physically stored. The operating system connects a file’s logical name and organization to the blocks that hold its data on a storage device.

A file operation typically passes through several layers:

  1. Application program: Requests an operation such as opening or reading a file.

  2. Logical file system: Handles file names, directories, permissions, and other logical information.

  3. File-organization module: Maps logical files to physical storage blocks and manages their allocation.

  4. Basic file system: Issues general block-read and block-write requests.

  5. I/O control and device driver: Translates requests into commands that the specific device can carry out.

  6. Storage device: Reads or writes the data.

This layered design lets an application use the same file operations whether the data is on an internal hard disk, a USB drive, or a network-accessible device. The operating system and its drivers handle device-specific details.

Layering reduces complexity and supports different devices and file systems, but each layer can add processing overhead.

Storage can also be attached or removed while a system is running. When a USB drive is connected, for example, the operating system identifies the device, loads or uses an appropriate driver, recognizes its file system, and makes its contents accessible through the system’s logical file interface.


Logical files and physical storage

From file names to blocks

A user may request notes.txt, but the storage device does not generally locate data by that name. The operating system uses file-system metadata to translate the name into the location of the file’s data.

A file-control structure records information associated with a file. Depending on the file system, this may include:

  • The file’s name or references needed to locate its name.

  • Its size and status.

  • Access or modification information.

  • Pointers or other mappings to its data blocks.

  • Links to related structures, such as indexes or tables.

A request to open a file therefore involves finding the relevant directory entry and file-control information, then determining which storage blocks contain the file’s data. The requested blocks are read into memory before a program can work with them.

Blocks, tracks, sectors, and cylinders

Storage devices expose data in units called blocks. A block is a logical unit that the operating system and device use to transfer data. The size of a block affects both storage efficiency and the amount of metadata needed to manage storage.

On a traditional magnetic hard disk:

  • A track is a circular path on a platter.

  • A sector is a subdivision of a track.

  • A cylinder is a set of tracks at the same radius across multiple platters.

  • A block is a logical unit of data that the system can address and transfer.

The operating system generally works with logical block addresses rather than requiring applications to specify physical platter, track, or sector locations. Device controllers translate between the logical requests and the device’s physical organization.

Block-size trade-offs

Block size involves a balance:

  • Small blocks reduce wasted space when a file is small or does not fill its final block. However, more blocks are needed to represent the same amount of data, increasing the amount of allocation information the system must manage.

  • Large blocks reduce the number of block references needed, but can waste space when a file uses only part of a block.

The choice resembles the choice of memory allocation units: smaller units can fit data more closely but require more bookkeeping, while larger units simplify management at the cost of potential internal waste.

Volumes and partitions

A partition is a division of a physical storage device into separately managed regions. It is a physical-layout concept: one physical disk can be divided into several partitions.

A volume is a logical storage unit presented to the operating system or user. A volume may correspond to one partition, but it can also be assembled from multiple physical devices. For example, a logical volume can be extended across more than one disk.

Thus, a partition describes a division of storage, while a volume describes a logical unit that the system can use and present.

Mounting file systems

Before a file system can be used through the operating system’s directory structure, it must be made available, or mounted. A mount operation identifies the device or volume, its file-system type, and the location in the system’s directory structure through which its contents will be accessed.

Some devices, such as an internal system disk, are commonly mounted during startup. Others, such as removable USB drives, may be mounted when they are connected.

Different devices may use different file systems. A system may fail to read a drive because:

  • It does not support the file system used on the drive.

  • The file system’s metadata, such as directory information or file-control structures, has been damaged.

  • The device has physical defects, such as unreadable sectors.

Because directories and allocation metadata explain where files are stored, damage to this information can make otherwise intact file data difficult or impossible to locate.


Directory organization and file lookup

A directory maps file names to the information needed to locate and manage files. The organization used for directory entries affects how quickly a file can be found.

Linear lists

A simple directory can store entries in a list. To find a particular file, the system searches entries until it finds a matching name.

  • Advantage: Simple to implement.

  • Disadvantage: Lookup can become slow as the directory grows, because many entries may need to be examined.

Search trees

A tree structure, such as a B-tree, organizes entries so that the system can search them more efficiently than by scanning a long list. Tree structures are particularly useful when directories or indexes contain many entries.

Hash tables

A hash function transforms a file name or other input into a value used to locate an entry. This can make lookup fast because the system can use the resulting value to find a likely location directly.

Hashing has limitations:

  • Calculating and maintaining a good hash structure adds complexity.

  • Different inputs can sometimes produce the same hash value, creating a collision.

  • The file system must have a strategy for resolving collisions and finding the correct entry.

The best directory organization depends on factors such as directory size, lookup frequency, and the cost of maintaining the structure.


File allocation methods

File allocation determines how a file’s data blocks are placed and how the system records their locations. The main designs trade off simplicity, speed, flexibility, and the amount of metadata required.

Contiguous allocation

With contiguous allocation, a file occupies consecutive blocks. The file can be described by its starting block and its length.

  • Advantages: Simple mapping; sequential access is efficient because the system can read a run of blocks in order.

  • Disadvantages: Finding a sufficiently large consecutive region can be difficult as the disk fills. Files that grow may no longer fit in their original space.

  • Fragmentation: Free space can become divided into separate gaps. There may be enough total free space for a file, but not enough consecutive space to hold it.

Moving files to combine scattered free regions is called defragmentation. It can help when the device and file system benefit from consolidating data, though its usefulness depends on the storage technology.

Extent-based allocation

An extent is a consecutive run of blocks. An extent-based file system stores a file in one or more extents.

A file might initially occupy one extent. If it grows beyond that extent, the system can assign another run of blocks and record where the new extent is located.

  • Advantages: Preserves the efficiency of consecutive access within each extent, while allowing a file to grow without requiring the entire file to remain in one continuous region.

  • Disadvantages: The system must track multiple extents when a file is spread across several runs.

Linked allocation

In linked allocation, each block contains a reference to the next block in the file. The file begins at a known block, and the system follows the chain until it reaches the end, commonly marked with a null or end-of-chain value.

  • Advantages: A file can grow by adding another block wherever free space is available; it does not need one large consecutive region.

  • Disadvantages: To reach a later block, the system may have to follow multiple pointers. Scattered blocks can require repeated device movement, which is costly on a mechanical disk.

  • Reliability concern: If a pointer is corrupted, the system may lose access to the rest of the chain.

Linked allocation is flexible, but its performance and reliability depend on how the links are stored and accessed.

File Allocation Table

A File Allocation Table (FAT) stores the links between blocks in a central table rather than storing each next-block pointer inside the data block itself. An entry identifies the next block in a file’s chain, and a special value marks the end.

The system can load some or all of the table into memory, making it faster to follow file chains than if every link had to be read from scattered locations on the disk.

  • Advantages: The table provides a centralized way to track block chains and can be cached in memory.

  • Disadvantages: The table itself requires space and must be kept accessible. If it is damaged, many files may become difficult to locate.

  • Scaling trade-off: Small blocks create many block entries and a larger table. Large blocks reduce the number of entries but may waste space within files.

FAT-style systems are common on removable storage because of their relative simplicity and broad compatibility. FAT variants differ in how much information they can represent; the size of an allocation entry affects the number of blocks that can be addressed, but it is only one part of a file system’s overall capacity limit.

Indexed allocation

In indexed allocation, a file has an index block that lists the data blocks belonging to it. The system reads the index to find the required blocks, without following a chain through all preceding data blocks.

  • Advantages: Supports direct access to listed blocks and avoids the need to traverse a linked chain.

  • Disadvantages: The index consumes space and may need to be read before the data blocks can be located.

If one index block cannot hold enough entries for a large file, additional levels can be used:

  • A single-indirect reference points to an index block containing data-block addresses.

  • A double-indirect reference points to an index block that points to further index blocks.

  • Further levels can extend the addressing range, at the cost of extra lookups.

Some Unix-like file-system designs combine direct and indirect references. Direct references make smaller files quick to access, while indirect levels provide a way to address larger files. Frequently used data can be reached with fewer steps than less frequently used data stored through deeper index structures.

An illustrative design with 2322^{32}232 addressable blocks of 444 KiB each could address up to 2442^{44}244 bytes, or 161616 TiB, before other design constraints are considered. Actual file-system limits can depend on more than the width of a block address.

Choosing an allocation method

No allocation method is best for every workload.

  • Contiguous layouts suit predictable, sequential access but are difficult to expand and can fragment free space.

  • Extents combine consecutive runs with flexibility to grow.

  • Linked allocation makes file growth straightforward but can make random access and recovery harder.

  • Table-based allocation centralizes block-chain information, but depends on the integrity and management of the table.

  • Indexed allocation supports direct access but needs index storage and may require extra reads for large files.

Different devices can use different file systems even when they are accessed through the same operating system.


Free-space management

A file system needs to track which blocks are available for new data. Free-space management affects both allocation speed and the amount of space used for bookkeeping.

Bitmaps

A bitmap uses one bit to represent each block. Depending on the convention, one value represents a free block and the other a used block.

A bitmap makes it possible to inspect block availability and identify runs of free blocks. Its cost depends on the number of blocks: one bit is needed for every block represented.

For example, a device with capacity 2402^{40}240 bytes divided into blocks of 2122^{12}212 bytes has:

240212=228\frac{2^{40}}{2^{12}} = 2^{28}212240​=228

blocks. A bitmap for this many blocks contains 2282^{28}228 bits, equivalent to 2252^{25}225 bytes, or approximately 323232 MiB, before accounting for implementation details.

Free lists

A free list links unused blocks together. The file system keeps track of the first free block, which points to the next, and so on.

When a block is needed, the system removes a block from the head of the list and updates the head to the next free block.

  • Advantage: The system can allocate a block without scanning an entire bitmap.

  • Disadvantage: Finding or allocating particular patterns of free space can be less convenient than with a bitmap.

Grouping and counting

Free-space structures can be refined. For example, a system may record groups of free blocks or the number of free blocks in a region, helping it find useful space more efficiently.

Large storage systems may use more sophisticated space maps and management units. Their techniques reflect the scale of the storage, the number of devices, and the workload.


Buffering and caching

Mechanical storage is much slower than main memory. File systems therefore use memory to reduce repeated device access.

  • A buffer temporarily holds data being transferred between a device and a program.

  • A cache keeps data or metadata that may be used again, so the system can satisfy a later request from memory instead of accessing the device.

  • Read-ahead fetches data in advance when the system expects it to be needed soon. If a program reads one block in a sequence, the system may also load following blocks.

  • Directory and metadata caching can speed up repeated operations on the same files by keeping lookup information in memory.

Caching and read-ahead can improve performance, but they use memory and may fetch data that is never needed. Their value depends on the workload and on whether the system can predict future access.


Storage media and device performance

Magnetic hard disks

A traditional hard disk stores data magnetically on rotating platters. Read/write heads move across the platters to access different regions. The heads normally remain slightly above the surface on an air bearing rather than touching it. A physical impact that makes a head contact the surface can damage the disk and its data.

Hard-disk performance depends on several components:

  • Seek time: Time for the head assembly to move to the required track or cylinder.

  • Rotational latency: Time spent waiting for the desired sector to rotate under the head.

  • Transfer time: Time needed to transfer the data once it is positioned.

  • Controller overhead: Time spent processing the request through the device controller.

A simplified access-time model is:

access time=seek time+rotational latency+transfer time+controller overhead\text{access time} = \text{seek time} + \text{rotational latency} + \text{transfer time} + \text{controller overhead}access time=seek time+rotational latency+transfer time+controller overhead

For a disk rotating at RRR revolutions per minute, the time for one full rotation is 60R\frac{60}{R}R60​ seconds. Assuming the desired position is equally likely to be anywhere around the disk, average rotational latency is approximately half a rotation:

average rotational latency=30R seconds\text{average rotational latency} = \frac{30}{R} \text{ seconds}average rotational latency=R30​ seconds

Faster rotation generally reduces rotational latency. However, disk access also depends on seek distance, transfer rate, controller behavior, and the physical arrangement of data.

Solid-state drives

A solid-state drive (SSD) stores data in flash memory and has no moving read/write head or rotating platter.

Compared with a mechanical hard disk, an SSD generally offers much faster access because it avoids seek time and rotational latency. Its trade-offs include:

  • Higher cost per unit of storage in many comparisons.

  • Limited write endurance for individual memory cells.

  • The need for wear-leveling techniques.

Wear leveling distributes writes across the storage cells so that some cells are not used up much sooner than others. It helps extend the usable life of the drive. SSDs do not have mechanical seek or rotational latency, but they still have physical limits and can eventually fail.

Magnetic tape

Magnetic tape remains useful for storing large quantities of data at relatively low cost. Its main disadvantage is access speed: data is often accessed sequentially, so reaching a particular location can take time.

The broad storage trade-off is among speed, cost, and capacity. Storage designs generally cannot maximize all three at once:

  • Low-cost, high-capacity storage tends to be slower.

  • Fast, high-capacity storage tends to be more expensive.

  • Fast, inexpensive storage usually offers less capacity.

Device controllers and connections

A device controller sits between the computer and a storage device. The operating system communicates with the controller, which handles device-specific operations.

Storage devices connect through interfaces and buses such as USB or other device-specific connections. The performance of the connection can limit the rate at which data moves, even when the storage medium itself is capable of faster transfers.


Networked storage

Storage does not need to be inside the computer using it. Because file-system layers separate a logical file interface from the physical device, storage can be accessed across a network.

Storage Area Networks

A Storage Area Network (SAN) provides network-based access to storage devices. Multiple servers can access storage through the SAN, which may include hard disks, SSDs, or tape systems.

Large storage installations must account for:

  • The number and type of connected devices.

  • Network bandwidth and the number of access paths.

  • Many users or servers making requests at once.

  • Redundancy and backup.

  • The need to avoid bottlenecks.

A SAN makes storage available over a dedicated or specialized network rather than requiring each storage device to be directly attached to each server.

Network-attached storage

Network-attached storage (NAS) is storage made available over a network, often through a device connected to a local router or network. It can appear to users as a drive or shared location even though the data is held on a separate machine.

The operating system and network protocols handle the communication. The user-facing file interface can remain familiar, while network and device details are handled beneath it.

Cloud storage

Cloud storage is storage hosted on computers elsewhere and reached through a network. It is not a separate kind of physical substance: it is remote storage presented through software and network services.

Remote storage introduces additional delays and potential bottlenecks compared with local memory or storage. Systems may improve performance by using faster network links, caching data, or spreading data across multiple devices so requests can be served in parallel.


Disk scheduling

When several processes request data from a mechanical disk, the operating system can choose the order in which to serve those requests. Disk scheduling aims to reduce unnecessary head movement and waiting time.

Suppose requests refer to different locations on a disk. Serving them strictly in arrival order can make the head move back and forth across the disk. A different order may reduce total movement, although it can change how long individual requests wait.

First-Come, First-Served

First-Come, First-Served (FCFS) handles requests in the order they arrive.

  • Advantage: Fairly simple and preserves arrival order.

  • Disadvantage: The head may travel long distances between successive requests, producing high total movement and access time.

Shortest Seek Time First

Shortest Seek Time First (SSTF) selects the request closest to the head’s current position.

  • Advantage: Often reduces head movement compared with FCFS.

  • Disadvantage: Requests far from the current position can wait for a long time if closer requests keep arriving. This creates a risk of starvation.

An aging or priority-adjustment policy can help prevent a request from being postponed indefinitely, but it adds policy complexity.

SCAN

SCAN, sometimes described as the elevator algorithm, moves the head in one direction and serves requests encountered along the way. At the end of the disk’s range, it reverses direction and serves requests on the return trip.

  • Advantage: Avoids repeatedly jumping to whichever request is closest and gives requests along the scan path an opportunity to be served.

  • Disadvantage: A request may have to wait until the head reaches its region.

C-SCAN

Circular SCAN (C-SCAN) serves requests while moving in one direction. After reaching the end, the head returns to the beginning without serving requests during that return, then continues in the same direction.

This resembles a circular service pattern. It can provide more uniform waiting times than reversing direction at both ends.

LOOK and C-LOOK

SCAN-style algorithms can avoid travelling all the way to the physical end of the disk when no requests are waiting there.

  • LOOK moves in one direction only as far as the last pending request in that direction, then reverses.

  • C-LOOK moves in one direction to the last pending request, then returns to the first pending request and continues in the same direction.

These methods can avoid unnecessary movement into regions with no pending requests. Their value comes from the physical cost of moving a disk’s head, so their benefits do not apply in the same way to storage without mechanical heads.

Choosing a scheduling policy

The best policy depends on workload:

  • Under light load, SSTF may perform well because it can quickly serve nearby requests.

  • Under heavier load, SCAN-family algorithms may produce more predictable service patterns.

  • FCFS remains simple, but may produce poor movement patterns under some workloads.

Operating systems may use different policies depending on whether they serve a desktop, a server, or a larger shared system. Some specialized systems allow storage-scheduling components to be selected or configured to suit a particular workload.


Disk preparation and layout

A physical storage device does not automatically have the file-system structures needed for normal use. It must be prepared so that the operating system can organize and locate data.

Formatting

Formatting establishes structures that allow the device to be used as storage. This includes dividing the device into addressable units, such as sectors or logical blocks, and setting up the information needed by a file system.

The specific organization depends on the device and the file-system design.

Partitions and file systems

Once a device has usable addressable units, it can be divided into partitions. A file system can then be created on a partition or volume.

Different partitions on the same physical device can use different file systems. For example, one partition may hold a main operating system and another may contain recovery information.

Clusters

Some file systems manage allocation in groups of blocks called clusters. A file may be allocated in cluster-sized units, with each cluster representing several underlying blocks. As with block size, the cluster size affects both bookkeeping and the potential amount of unused space within allocated regions.

Raw disk access

Most applications use a file system to store and locate their data. Some applications instead request raw disk access, referring directly to a partition or device and managing its organization themselves.

Raw access can be useful when an application needs particular performance or layout characteristics, but it bypasses many of the abstractions normally provided by the file system.

Boot information

A computer needs to locate the code that starts the operating system. On some systems, a Master Boot Record (MBR) stores boot code and partition information. Boot procedures use this information to select a partition and continue loading the system.

A disk may contain multiple partitions with different operating systems, and boot information can provide a way to choose which one to start.

Swap space

Operating systems may reserve storage for swap space, which supports virtual memory by providing backing storage when memory pages need to be moved out of RAM.

Swap space may be set up as a separate partition or managed as a file, depending on the operating system. Its arrangement reflects a performance trade-off: a dedicated and suitably placed region can make access more predictable, while file-based approaches can be managed flexibly. Systems may also manage the size of swap space according to their configuration and needs.


Redundant storage with RAID

RAID—commonly expanded as Redundant Array of Independent Disks—combines multiple physical disks into a storage arrangement designed to improve performance, reliability, capacity, or some combination of these.

RAID levels use different strategies, including:

  • Striping: Splits data across disks. Independent disks can serve parts of a request in parallel, improving some forms of performance.

  • Mirroring: Stores duplicate copies of data on separate disks. If one disk fails, the other may still contain the data, but usable capacity is reduced.

  • Parity: Stores calculated redundancy information across disks. In some designs, this information can be used to reconstruct missing data after a disk failure.

  • Combinations of methods: Some RAID arrangements combine striping with mirroring or parity.

RAID is not one single layout. The appropriate level depends on the desired balance of capacity, speed, fault tolerance, and cost. Redundancy can reduce the risk that a single disk failure immediately makes data unavailable, but it is not a substitute for an independent backup: failures, damage, or mistakes can affect multiple copies.

Hot swapping and replacement

Some storage systems support hot swapping: a failed disk can be removed and replaced without shutting down the system. The RAID controller and software can then rebuild or restore the redundant data, depending on the RAID configuration.

A storage system’s reliability depends on both hardware and software. Controllers, buffers, caching, disk replacement procedures, and the chosen redundancy method all affect how well the system performs and recovers from failure.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent