Purpose
Notes on chapter 11 of Operating Systems: Principles and Practice. This chapter sets up the file system abstraction; the implementation details live in files and directories.
A file system has to deliver several things at once:
- Reliability
- Large capacity and low cost
- High performance
- Named data
- Controlled sharing
Nonvolatile Storage
Unlike DRAM, nonvolatile storage is persistent, and it is generally cheaper with higher capacity. The price is speed. A magnetic disk access takes on the order of milliseconds against DRAM’s nanoseconds, roughly 5 orders of magnitude slower. Current nonvolatile storage technologies also do not allow random access to individual words. Data must be read and written in fixed-size blocks (e.g. 512 bytes). Both properties shape everything a file system does: it batches work into blocks and fights hard to avoid touching the device at all.
The File System Abstraction
A file is a named collection of data in a file system, consisting of the data itself plus metadata describing it (size, owner, permissions, timestamps, and where the data lives on disk).
Files can be executable. Executable binaries on Linux begin with a magic number telling the OS how to run the file. Scripts can be executable too, beginning with a shebang (#!) followed by the interpreter that should run them.
A traditional file is a single logical stream of bytes. MacOS’s HFS+ and Windows NTFS support multiple streams (forks) per file, and in those systems the read and write system calls take an argument naming which stream to touch.
Terms worth having down cold: directory, root directory, home directory, current working directory, path, absolute path, relative path.
Links
The mapping between a name and a file is a hard link. A file system that allows multiple hard links to one file stops being a tree and becomes a directed acyclic graph. A symbolic link maps a name to another file name instead of to the file itself, which lets you reference files on other volumes or systems. Some operating systems layer similar features above the file system. Windows has shortcuts, ordinary files that Windows recognizes and redirects through. MacOS has aliases, which behave like symbolic links and also fix themselves up when the target file moves.
flowchart LR subgraph HL[Hard links: two names, one file] A[Name: /home/a/notes.txt] B[Name: /home/b/shared.txt] end F[(File data + metadata)] A --> F B --> F subgraph SL[Symbolic link: a name for a name] S[Name: /home/c/link.txt] end S -.->|stores the path| A style F fill:#e3f2fd,stroke:#1565c0
Volumes
A volume is a collection of physical storage resources forming one logical storage device. In the simplest case a volume is a single disk. A disk can also be partitioned into multiple volumes, and a single volume can span multiple disks.