← 🗂️ File Systems
Subtopic 1 of 4

7.1Files, directories and access methods

The idea

A file is a named collection of bytes; directories organise files. A hard link is another name for the same inode; a soft link is a file holding a path.

Think of it like this: A hard link is a second door to the same room; a soft link is a signpost that points to a door and goes wrong if the door moves.

Why it exists

Links explain deletion rules, and the directory structure decides sharing.

How it works

  1. Tree directories: unique path from the root.
  2. Hard link: new directory entry, same inode, link count +1; data goes when the count reaches 0.
  3. Soft link: new inode storing a path; may dangle.
  4. Hard links cannot cross file systems; soft links can.

Worked example: A file has two hard links and you delete one name

Link count goes from 2 to 1, the data stays. With a soft link, deleting the original leaves the link pointing to nothing.

Now play with it

  • →Use the tables to answer: which link type can cross file systems?
  • →Decide what happens to each link type after the original is deleted.
Directory structureIdeaProblem
Single-levelone directory for everythingname clashes
Two-levela directory per userno sharing, no grouping
Treedirectories nest; absolute and relative pathssharing needs links
Acyclic graphtree plus links, shared filesdeletion and dangling links
General graphcycles allowedcycle detection needed in traversals
Hard linkSoft (symbolic) link
What it isanother name for the same inodea small file holding a path
Across file systemsnoyes
If the original is deleteddata stays until the link count is 0link dangles
Directoriesnormally not allowedallowed
Extra inodenoyes

Check yourself

Deleting a file that has a hard link elsewhere

Remember: Hard link: same inode, same file system. Soft link: path, may dangle, may cross file systems.
Exam notes (the dense version)

A file is a named sequence of bytes with attributes (name, size, type, protection, times). Operations: create, open, read, write, seek, close. Access: sequential, direct (random) or indexed. Directories: single-level, two-level, tree (the usual one), acyclic graph (links), general graph. A hard link is another directory entry pointing to the same inode (the file survives until the last link is removed, same file system only); a soft (symbolic) link stores a path name and can dangle. The open-file tables are per process and system-wide.

Previous year questions: File Systems (5)

PYQs are grouped by topic, so this is the full set for File Systems; try the ones that match this subtopic. Open all 5 on the topic page.