4.2.33 · D1Operating Systems

Foundations — Directory structure — tree, DAG (hard links, symbolic links)

2,059 words9 min readBack to topic

Before you can read the parent note on trees, DAGs, hard links and symbolic links, you must earn every word it uses. This page defines them one at a time, each with a picture, each building on the one before. If you have never seen the words inode, link count, or DAG, start at line one and do not skip.


1. A file, from zero

Figure — Directory structure — tree, DAG (hard links, symbolic links)

The topic needs this split because every advanced idea — hard links, symbolic links, the DAG — is just a different way of connecting names to numbered lockers.


2. The inode — the numbered locker

You need the inode because it is the "one blob" that many names will share. Its metadata (especially a counter) is what makes sharing safe. See Inodes and File Metadata for the full contents, and File System Implementation — Block Allocation for how the block pointers reach real disk.


3. A directory — the wall of sticky notes

Figure — Directory structure — tree, DAG (hard links, symbolic links)
Recall What are the two columns of a directory entry?

Question ::: What does each entry (name, inode number) store, and which one is the "identity" of the file? Answer ::: A human-readable name and a numeric inode number. The inode number is the file's true identity; the name is just a label pointing at it.


4. A path — the route through walls

Following a path from / down to a target is called path resolution; the Unix routine that does it is named namei() (see Path Resolution and the namei() routine). The tool question it answers is: given a string of names, which inode do I end at?


Figure — Directory structure — tree, DAG (hard links, symbolic links)

You need because without it, the moment you had two names for one file, nobody could know whether deleting one name should also free the data. The counter answers that.


6. Trees vs DAGs — the shape of the whole map

Figure — Directory structure — tree, DAG (hard links, symbolic links)

7. Two ways to add a second name (preview)

The parent note builds two mechanisms on top of everything above. Here is just enough to know what each is:

You now have every symbol the parent note assumes: file, inode, inode number, directory, directory entry, path, root, ./.., link count , node/edge, tree, and DAG.


How these foundations feed the topic

bytes vs name split

inode = numbered locker

directory = list of name to inode

inode number identity

path resolution walk

link count n

tree default shape

free when n equals zero

two names one inode

DAG shape

hard links and symbolic links

Read it top to bottom: the split (A) forces separate inodes (B) and directories (C), which meet at the inode number (D). From there you get walking paths (E), the counter (F), the default tree (G), and — once two names share one inode (I) — the DAG (J) on which hard and symbolic links are built.


Equipment checklist

Cover the right side and test yourself. If any answer is fuzzy, reread that section before the parent note.

  • A file separates two things — which two? ::: The bytes (data) and the name (label); joined only by an inode number.
  • What is an inode, and what does it deliberately NOT store? ::: The record of a file's metadata and data-block pointers; it does not store the file's name.
  • What are the two columns of a directory entry? ::: (name, inode number).
  • What do . and .. point at? ::: . points at the directory's own inode; .. points at its parent's inode.
  • In words, what is the link count ? ::: The number of directory entries currently pointing at that inode.
  • When may a filesystem free a file's data blocks? ::: When and no process still has the file open.
  • What makes a graph a tree? ::: Every node except the root has exactly one parent, and there are no cycles — so one unique path per file.
  • What three properties define a DAG? ::: Directed edges, no cycles (acyclic), but a node may have more than one incoming edge.
  • What single event turns the tree into a DAG? ::: Two different names (paths) pointing at the same inode, giving it more than one incoming arrow.
  • Why must directory cycles be forbidden? ::: So traversal terminates and "reachable ⇒ link count > 0" stays well-defined.