File Systems Overview
File Systems
What is a File?
A file is a contiguous logical address space — "contiguous" and "logical" are important because the physical storage may be fragmented, but logically the file appears as a continuous sequence of bytes. The operating system abstracts the physical storage layout from the user.
File Attributes
Files typically have a set of attributes that describe them. Common attributes include:
Name: human-readable identifier
Type: indicates purpose (document, image, executable, etc.)
Size: current size in bytes
Location: pointer to where the file is stored on the device
Creation time: when the file was created
Last modification time: when the file content was last changed
Last access time: when the file was last read
Owner: user who owns the file
Permissions: who can read, write, or execute the file
Label/color (e.g., macOS): user-defined tags for organization
Sharing settings: which users or groups can access the file and with what privileges
Key takeaway: A file is the fundamental unit of storage, defined by its logical address space and a set of metadata that the operating system maintains.
File Operations
The operating system provides an API (Application Programming Interface) for programs to manipulate files without worrying about low-level details. Common operations include:
Create: allocate space and initialize attributes
Open: bring file metadata into memory and set up a handle for subsequent operations
Read: transfer data from the file into memory; a read pointer tracks the current position
Write: transfer data from memory into the file at the current position
Seek (reposition): move the read/write pointer to a specific location within the file
Delete: release space and remove the file from the directory
Truncate: keep file attributes but erase content (set size to zero)
Close: release the open-file handle and flush any buffered data
Open File Tracking
The operating system must maintain an open-file table for each process that includes:
Current file position (offset)
File pointer (location on disk)
Open count: number of processes or threads that have the file open
Locking information: whether the file is locked by another process
Important: Every
open()should have a matchingclose(). Failing to close files can exhaust system resources and lead to crashes.
File Locking
When multiple users or processes access the same file, file locking prevents conflicts:
Exclusive lock: only one process can write; others may be denied access or allowed read-only
Shared lock: multiple processes can read simultaneously; writing requires an exclusive lock
Record-level locking: only a specific record or byte range is locked, not the entire file (used in databases like Oracle)
Mandatory vs. advisory: mandatory locks are enforced by the OS; advisory locks are cooperative (processes must check them)
The OS tracks who has a file open and can warn users: "This file has changed since you started working on it. Would you like to save a copy instead?"
File Types
Files are categorized by how their internal structure is organized:
Simple (flat): sequence of bytes or lines (e.g.,
.txt,.html)Fixed-length records: each record has the same size, allowing direct calculation of position (e.g., transaction logs with fixed field widths)
Variable-length records: records can vary in length; markers or delimiters are used (e.g., CSV, text files with varying line lengths)
Binary files: complex structures interpreted by the application (e.g., executables, images, compressed archives). The file extension is only a convention; the OS may rely on a file signature or magic number.
Visible vs. hidden types: Windows/DOS require extensions (.exe, .txt), but Unix/Linux do not — the file type is stored in the inode or determined by magic numbers.
File Access Methods
Sequential Access
Data is read or written in order, one record after another. This is the natural method for tape drives — to skip 100 records, the tape must physically wind past them (slow random access). Still widely used for backups and archival storage because tape is cheap and holds large volumes (e.g., 8 TB per cartridge, robotic tape libraries in cloud data centers).
Direct Access (Random Access)
The storage device can jump to any block directly (e.g., hard disks, SSDs). The OS uses an index (like a file allocation table or directory) to locate a file's blocks. The index may be cached in memory for speed, but for a large number of files (hundreds of thousands) the entire index cannot be held in RAM, so multi-level indexing is used (e.g., directory index → file index → block pointers).
Indexed Sequential Access (ISAM)
A hybrid approach: an index tells where a record is located, but the underlying storage is still sequential (e.g., tape). The index is read first, then the tape positions to the correct block. Commonly used in legacy and modern database systems. Databases can have multiple indices (by name, date, ID, etc.) for fast lookups.
Key idea: The user never sees the access method — the OS abstracts it away.
Directory Structures
Directories (folders) organize files to make them easier to find and manage, avoid naming collisions, and enable grouping.
Single-Level Directory
All files in one flat list. Problems: naming conflicts (you can't have two dummy.txt files), no organization, slow search.
Two-Level Directory
Each user has their own directory. Files with the same name can exist in different user directories. Still no sub‑grouping.
Tree-Structured Directory (Hierarchical)
Users can create subdirectories to any depth. This is the standard on all modern operating systems (Windows, macOS, Linux). Each file is uniquely identified by its absolute path (starting from the root, e.g., C:\Users\Tony\Documents\notes.txt) or a relative path (based on the current working directory, e.g., ..\Documents\notes.txt).
Absolute path: complete from root, unambiguous
Relative path: depends on current directory, convenient for navigation
Graph-Structured Directory (with Links)
Unix/Linux allow links — additional directory entries that point to the same file (inode). This creates a directed acyclic graph rather than a tree. Two types:
Hard link: a second name for the same file (same inode). The file is deleted only when the last hard link is removed.
Symbolic link (symlink): a special file that contains the path to the target. If the target is moved or deleted, the symlink becomes dangling.
Links are useful when multiple applications need the same data (e.g., a word processor and a spell checker sharing a word list). But they complicate deletion: the OS must keep a reference count (back pointer) to decide whether to free the file's storage.
Loops can occur if links point back to a parent directory (cycle). The OS must detect cycles (e.g., during traversal) using techniques like garbage collection — periodically scanning to find and clean up unreachable files or dangling links.
Disk Organization
Partitioning
A physical disk can be divided into one or more partitions, each treated as a separate logical drive. Reasons:
Separate OS files from user data (easier backup: only data partition needed)
Multiple users each get their own partition
Different file systems for different workloads (e.g., one partition for large video files, another for many small files)
Formatting (Creating a File System)
Each partition must be formatted with a file system that organizes data into files and directories. Choosing the right file system depends on the intended use:
FAT32: widely compatible, max file size 4 GB
NTFS: supports large files, security, compression (Windows)
ext4: common on Linux, journaled
APFS: Apple's modern file system (SSD‑optimized)
Volumes
A formatted partition is called a volume. Volumes can span multiple physical disks (e.g., RAID, LVM) – the OS presents them as one logical unit. This is how cloud storage like OneDrive works: many physical disks are aggregated into a single logical volume.
Mounting File Systems
Before a storage device (partition, USB drive, network share) can be accessed, it must be mounted — attached to the existing directory tree at a mount point.
Automatic mounting: consumer OSes (Windows, macOS) automatically mount USB drives and assign drive letters (e.g.,
D:) or desktop icons.Manual mounting: Linux/Unix require the
mountcommand to attach a device to a directory (e.g.,/mnt/usb). Network file systems like NFS or SMB also need to be mounted.Any directory can serve as a mount point — the file system becomes a subtree under that directory.
In Windows, cloud storage (OneDrive) can be added as a mount point, making it appear like a local drive. Users can copy files as if they were local; the OS handles network transfers transparently.
File Sharing and Protection
Permissions Models
Unix/Linux (rwx + octal):
Three categories: owner, group, others (everyone else)
Each category gets three bits: r (read), w (write), x (execute)
Permissions are represented as an octal number (e.g.,
755= owner rwx, group r-x, others r-x)Command:
chmod 700 filenamegives owner full access, nothing to others
Windows:
Uses Access Control Lists (ACLs) with a graphical interface
Permissions include Full Control, Modify, Read & Execute, Read, Write
Separate entries for users and groups, with finer granularity (each user/group can be given different permissions)
Sharing Across a Network
Distributed File Systems (DFS) allow files to be accessed over a network as if they were local. Common protocols:
NFS (Network File System): widely used in Unix/Linux environments
SMB/CIFS: used by Windows (and Samba for Linux)
HTTP/HTTPS: web‑based access (e.g., OneDrive or SharePoint – URLs like
https://...with a unique 64‑character ID)
To make sharing work, supporting systems are needed:
DNS (Domain Name System): translates human‑readable names to IP addresses
LDAP (Lightweight Directory Access Protocol): provides user and group information
Access permissions determine who can read, write, or execute files, and directories inherit permissions by default. In shared environments, careful permission management prevents accidental data loss (e.g., someone overwriting a file that another user is editing).
File sharing is built on user IDs, group IDs, and well-defined protocols — the OS orchestrates everything transparently to the user.

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