advanced23 min studyLesson 171 in Engineering

Inodes, extents, and the names that find them

Separate file identity, directory names, and block mappings before tracing a read or explaining hard links and sparse files.

On this page

What you’ll understand

  • Trace a pathname through directory entries to an inode and file-block mapping.
  • Compute offsets within an extent without confusing file and device blocks.
  • Explain why link counts, open descriptors, and allocated bytes describe different state.

A file is not merely a row of bytes attached to a name. The name locates an identity, that identity describes attributes and a mapping, and the mapping locates stored contents. Keeping those layers separate explains several otherwise surprising behaviors: renaming need not move payload, two names can identify one file, and a very large logical file can occupy little device space. We use Linux ext4 as a concrete example rather than treating every filesystem as identical.

A pathname is a sequence of lookups

Think of /models/current/weights as a small program for resolving names. Starting at the relevant root, look up models in one directory, current in the next, and weights in the final directory. On ext4, directory entries associate names with inode numbers within that filesystem. An inode records file attributes and information needed to locate its contents. The filename therefore belongs to its containing directory, rather than being a unique intrinsic field of the regular file's inode.

A hard link adds another directory entry for the same inode. Updating contents through either name changes the same file, whereas replacing one name with a different inode leaves the other hard link pointing at the old file. A symbolic link is different: it stores a path to be resolved, which can cross filesystem boundaries or become dangling. Draw these relationships before debugging deployment scripts that exchange names. Also distinguish the on-disk directory structure from the kernel's in-memory lookup cache; cached resolution can avoid physical reads without changing file identity.

q=⌊oB⌋,r=o mod Bq=\left\lfloor\frac{o}{B}\right\rfloor,\qquad r=o\bmod B
For a byte offset o at least zero and filesystem block size B bytes, q is the zero-based file-block index and r is the byte offset inside that block. This arithmetic does not yet identify a device address.↔ Scroll wide equations horizontally.

An extent maps a run rather than every block

An extent describes a contiguous run in a file's block-number space and the corresponding contiguous run in the filesystem's storage address space. Suppose file blocks beginning at logical index L occupy blocks beginning at P for length n. A requested file block q inside that interval maps to P plus q minus L. An extent tree organizes multiple runs, so fragmentation increases the number of mappings without changing the byte offsets applications use. Filesystem block addresses still need translation through partitions, volume managers, or devices below them.

Logical size is not allocated size. A sparse file can contain holes that read as zeros without allocating a data block for every zero-filled region. A preallocated but unwritten extent has yet another state: space is reserved, but its readable semantics are not arbitrary old device contents. Compression, inline data, shared extents, and metadata can further separate apparent file length from storage consumption on other filesystems. When budgeting checkpoints, measure the quantity your limit actually constrains instead of multiplying logical lengths and calling the result physical usage.

p(q)=P+(q−L),L≤q<L+np(q)=P+(q-L),\qquad L\le q<L+n
q and L are file-block indices, P and p are filesystem storage-block indices, and n counts blocks in this single mapped extent. The formula applies only inside the stated extent, not to holes or arbitrary mappings.↔ Scroll wide equations horizontally.

Names and lifetimes need separate observations

Removing a directory entry changes reachability by that name; it does not invalidate an already open descriptor to the file. On ordinary Linux local-filesystem semantics, an unlinked regular file can remain accessible through open handles until its final references disappear. This is why a service may keep consuming storage after an operator deletes a log pathname. Conversely, a reader with an old open descriptor need not switch to replacement weights just because a publisher atomically changed the public name. Reopening and coordinating readers are application decisions.

Investigate with a hypothesis: identify the filesystem, compare inode identity and link counts, inspect open handles, and examine extent information using an appropriate read-only tool. Do not infer a physical platter location or NAND cell from an extent number. For the lab, imagine a sparse file whose logical blocks are one-quarter allocated, then independently sample twelve uniform logical block indices with replacement. Set p to 0.25 and n to twelve: predict three allocated hits on average. The binomial distribution describes sampled mapping categories, not inode lookup latency or physical reads; cache hits and metadata accesses remain separate.

Find a byte through one mapped extent

A simplified file uses 4,096-byte blocks. An extent maps file blocks 100 through 107 to filesystem storage blocks 5,000 through 5,007. Locate byte offset 421,900.

  1. Divide 421,900 by 4,096: file block q is 103 because 103 × 4,096 = 421,888, leaving r = 12 bytes.

  2. Check the extent boundary: 100 ≤ 103 < 108. The displacement from the extent's beginning is three blocks, giving storage block 5,003.

  3. Within the filesystem storage address space, the byte position is 5,003 × 4,096 + 12 = 20,492,300. Additional lower-layer mappings may change the device address.

The result

The byte is twelve bytes into storage block 5,003 in this mapping. Its pathname and inode number were lookup inputs, not terms in the block-address arithmetic.

Explore the model

Interactive lab

Interactive lab · probability

Sample allocated blocks in a sparse file

Set p to 0.25 and n to twelve for independent uniform logical-block samples with replacement from a file with one-quarter allocated blocks. Predict three allocated hits on average, then change p or n. This binomial model classifies samples; it does not count physical reads, cache misses, or inode-lookup steps.

Sample allocated blocks in a sparse fileThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forLogical size and allocated-block fraction describe different properties, and random logical-block samples need not all reach stored payload.

Check your understanding

Two directory entries are hard links to the same regular-file inode. One name is removed while a process holds the file open. What follows under ordinary Linux local-filesystem semantics?

Try it yourself

A 4,096-byte-block file has data only in logical blocks zero and 99. Its logical length is 409,600 bytes. Estimate allocated payload if each occupied block uses one full block, excluding metadata.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Count occupied blocks rather than every block below the logical end.

Compare with the solution

Two occupied blocks require 8,192 bytes of payload allocation under the stated model. The remaining logical range consists of holes and reads as zeros. Metadata, allocation policies, compression, or sharing can change reported usage; logical length alone does not determine it.

Take it with you

  • Directories associate names with inode identities within a filesystem.
  • Extent arithmetic maps a bounded run of file blocks to storage blocks.
  • Logical length, allocated space, hard links, and open-handle lifetime must be inspected separately.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.