← Operating System Concepts

BOOK NOTES · OPERATING SYSTEMS · CHAPTER 13

Operating System Concepts Chapter 13 — File-System Interface.

operating-systemschapter-13filesdirectoriespermissionsmounting

// the one-minute version

A file is the OS's clean abstraction over raw storage blocks — named bytes with attributes (size, owner, dates, permissions). Directories organize files into a tree. Mounting grafts a storage volume into that tree. Permissions decide who can read, write, or execute each file, and links give a file more than one name. This is the file system as the user sees it — the next two chapters are how it's built.

Underneath, a disk is billions of numbered blocks. Nobody wants to think in block numbers. The file system turns that raw expanse into something humans handle effortlessly: named files in folders. This chapter is that human-facing interface.

01 What a file is

A file is a named collection of related bytes on storage. The OS attaches attributes: name, a unique identifier, type, size, location on disk, owner, timestamps, and protection bits. The bytes are the content; the attributes are the metadata the OS tracks. Notice the name lives separately from the file's data record — important when we get to links.

02 File operations and the open-file table

The OS provides operations as system calls: create, open, read, write, seek (jump to a position), close, delete. Opening a file returns a handle (a file descriptor) the OS uses to track your position and rights via an open-file table, so later reads and writes are fast and pre-checked.

noteopen matters more than it looks. It checks permissions once and creates the open-file-table entry holding the current read/write position. Then every later read/write is fast and pre-authorized, instead of re-walking the directory and re-checking access each time. That's why you open once and read many times.

03 Access methods

Sequential access

Read/write from start to end in order — like a tape. The most common pattern (reading a log, streaming a video).

Direct (random) access

Jump straight to any position by number — like an array. Essential for databases that need record #4,000,000 without reading the first 3,999,999.

04 Directory structure

A directory maps names to files. Early systems had a single flat directory (chaos at scale). Then per-user directories. Modern systems use a tree: directories contain files and other directories, giving the nested folders you know — names are unique by full path. Some systems allow a more general acyclic graph so a file can appear in multiple directories (via links), which is powerful but complicates deletion.

/ (root)/home/etcnotes.txtphotos/hosts

Fig 1 — A directory tree. Every file is uniquely named by its full path from root, and directories nest without limit.

05 Mounting

A storage device's file system doesn't appear on its own — it must be mounted: attached at a directory (the mount point) so its contents appear as a branch of the existing tree. Plug in a USB drive and the OS mounts it somewhere; from then on it's just another folder. Unmounting detaches it cleanly so buffered writes are flushed first.

06 Sharing and permissions

When users share files, the OS must control access. The classic UNIX model gives each file an owner and three permission sets — owner, group, and others — each granting read, write, execute. So a file can be owner-writable but world-readable-only. Simple, and it covers a huge fraction of real access control. Windows generalizes this into richer per-user/per-group access control lists (Chapter 17).

watch outPermissions are checked at open, not on every read. If a file's permissions change after you've opened it, your existing handle may still work — the check already passed. This surprises people and matters for security reasoning.

07 Links: a file with many names

A link lets one file appear in multiple places. A hard link is a second name pointing at the same underlying file data (both are equally "the file"; the data survives until the last name is deleted). A symbolic (soft) link is a small file holding a path to another name — like a shortcut — and it breaks if the target is moved or deleted.

the catchHard links are why deleting a file doesn't always free its space. UNIX tracks a link count; the data is only reclaimed when the count hits zero (the last name is removed). Symbolic links, by contrast, can dangle — point at something that no longer exists — and you won't know until you follow one.

common catches & gotchas

  • Open checks permissions, reads don't — Change a file's permissions after it's open and the existing handle may still work. The check happened at open time.
  • The name isn't the file — A file's data record (inode) is separate from its directory name. That separation is what makes hard links possible.
  • Hard link vs symlink — A hard link is another real name for the same data (survives target deletion); a symlink is a path pointer (dangles if the target moves).
  • Deleting ≠ freeing space — With multiple hard links, removing one name leaves the data until the last link is gone (link count zero).
  • Unmount before unplug — Pulling a drive without unmounting can lose buffered writes and corrupt the file system. Always unmount/eject.

08 Questions students actually ask

What's the difference between a file and its attributes?

The file's content is its bytes. Attributes are metadata — name, size, owner, timestamps, permissions, on-disk location. Both are tracked by the file system, but the name lives in the directory, separate from the data record.

Why open a file before reading it?

Opening checks permissions once and creates an open-file-table entry tracking your position and rights. Then every read/write is fast and pre-authorized, instead of re-walking the directory and re-checking access each time.

Sequential vs direct access?

Sequential reads bytes in order from the start — great for logs and streams. Direct access jumps to any position by number — essential for databases that need a specific record without scanning everything before it.

Hard link vs symbolic link?

A hard link is another real name for the same file data; delete one name and the data survives under the other until the link count hits zero. A symbolic link just stores a path to another name, like a shortcut, and breaks if the target moves or is deleted.

What does mounting do?

It attaches a storage volume's file system at a directory (the mount point) so its contents appear as part of the existing directory tree. That's how a USB drive or network share shows up as just another folder.

09 Key takeaways

  • A file is named bytes plus attributes; the name lives in the directory, separate from the data record.
  • Core operations — open, read, write, seek, close — are system calls; open sets up and authorizes access via the open-file table.
  • Access is sequential (in order) or direct (jump anywhere).
  • Directories form a tree (sometimes an acyclic graph); every file has a unique path.
  • Mounting grafts a volume into the tree at a mount point.
  • Permissions (owner/group/other × rwx) control sharing; links give a file multiple names.

10 Wrapping up

That's the file system you see and touch. But under the friendly tree of named files, the OS is juggling raw disk blocks. How it pulls that off is next. Next up: File-System Implementation.

← prev: Chapter 12next: Chapter 14 →
© cvam — written in plaintext, served warm