ECE344 Fall 2026 (Sec 1) Lec 24 - inodes
Overview
Jon Eyolfson explains how Linux inodes combine file metadata with direct and multi-level indirect block pointers, then shows how directories map names to inodes through hard links and symbolic links. He connects these structures to practical Unix behavior, including `ls`, `stat`, timestamps, permissions, setuid programs, and the filesystem cache, with capacity examples ranging from XV6's 268 KiB limit to roughly 64 TiB.
Key takeaways
- Linux inodes separate file identity and metadata from filenames: directories map names to inode numbers, while the inode records attributes and data-block locations.
- The 12 direct pointers in the described inode make small-file access faster, while single, double, and triple indirect blocks scale capacity at the cost of additional disk lookups.
- A hard link is another directory name for the same inode; removing one name does not free the inode until its link count reaches zero.
- A symbolic link stores a path in its own inode, so it can cross directories and follow a changing target name, but it can become broken or form a loop that the kernel reports as `ELOOP`.
- Unix permission checks apply owner, group, and other bits in sequence, and directory permissions control listing, traversal, and modification of names independently of file permissions.
- Filesystem caching exploits temporal and spatial locality, but delayed writeback means `fsync` or `sync` may be needed when changes must reach disk promptly.
Chapters
- A single index block with 8 KiB blocks and 4-byte pointers holds 2,048 entries, limiting a file to 16 MiB.
- Linux inodes extend indexed allocation with direct pointers plus single, double, and triple indirect pointers.
- An inode stores metadata such as file size, mode, ownership, timestamps, and disk-block locations.
- The described inode has 12 direct block pointers, allowing early file blocks to be located without reading an indirect block.
- Single, double, and triple indirect pointers add one, two, or three pointer-block lookups, respectively.
- Files fill pointer levels in order: direct blocks first, then single indirect, double indirect, and triple indirect.
- Some ext4 configurations store very small file contents directly inside the inode, avoiding a separate data block.
- The XV6 example has 1,024-byte blocks, 12 direct pointers, and one single-indirect block, yielding a 268 KiB maximum file.
- With 8 KiB blocks and 4-byte pointers, each indirect block holds 2,048 pointers; a triple-indirect structure supports roughly 64 TiB.
- `ls -l` displays file type and permissions, link count, owner, group, size, timestamp, and name.
- `ls -i` adds the inode number, revealing which names resolve to the same inode.
- A directory is fundamentally a collection of name-to-inode mappings rather than a container that gives files their identities.
- `ln a.txt c.txt` creates a second directory name for the same inode, so edits through either name affect the same contents.
- The link-count field in `ls -l` tracks how many hard links refer to an inode.
- `rm` uses the `unlink` operation to remove a directory name; the inode can be reclaimed after its link count reaches zero.
- A recycle-bin workflow can preserve a file by keeping another name that refers to its inode, while actual storage reclamation may happen later.
- `ln -s target link` creates a symbolic link with its own inode whose contents record the target path.
- Accessing a symbolic link resolves its stored name at access time, unlike a hard link that directly names the same inode as its target.
- System command aliases such as `python` pointing to `python3`, or `cc` pointing to GCC, can use symbolic links to follow changing versions.
- The target file's permissions govern access to the target, even though the symbolic link has a separate inode.
- Removing or renaming a symbolic link's target does not update the stored path, so using the link can fail with a missing-file error.
- A symbolic link can name a relative or absolute path, including a file in another directory.
- A cyclic chain of links is rejected by the kernel with `ELOOP`, meaning too many levels of symbolic links.
- `strace` can confirm the kernel detects the loop during the `open` system call rather than leaving `cat` to loop indefinitely.
- `touch -d` can set a file timestamp to a chosen past or future date because timestamps are inode metadata.
- Renaming a file changes its directory entry, not the inode it refers to.
- A symbolic link keeps its original target path after the target is renamed, while other hard-link names continue to refer to the same inode.
- Unix represents directories as files of directory type; their contents map names to inode numbers.
- The XV6 directory-entry example stores an inode number alongside a name.
- The special `.` and `..` entries are directory links, and `stat` can identify a directory inode and its type.
- An inode does not store its filename; names belong to the directory entries that refer to it.
- `stat` reports inode details including type, size, link count, and allocated blocks; its block count is expressed in 512-byte units.
- Inodes store a user ID and group ID, while processes run with their own user and group identities.
- Permission modes use read, write, and execute bits for owner, group, and others; octal `644` gives the owner read/write and the rest read access.
- The first character in a long listing indicates type, such as `-` for a regular file, `d` for a directory, or `l` for a symbolic link.
- For directories, read permits listing names, write permits creating or removing entries, and execute permits searching or traversing names.
- Removing a file requires write permission on its directory; the file's own mode bits do not determine whether its name can be removed.
- The kernel checks root first, then owner permissions, then matching group permissions, and finally other permissions.
- Because only the first matching class applies, an owner without read permission does not gain access merely because a matching group has read permission.
- A typical umask removes write bits from the default `666` file mode, producing files with mode `644`.
- The setuid bit runs an executable with the file owner's effective user ID rather than the launching user's ID.
- The `passwd` example uses setuid so it can update root-controlled password data on behalf of a user.
- A vulnerability in a setuid-root program can grant root access, which is why such programs require careful security controls.
- The kernel keeps recently used disk blocks in memory, taking advantage of temporal locality and spatial locality.
- A read of one file block makes nearby blocks, such as the next block, likely candidates for reuse.
- Writes can update cached blocks first, with a kernel thread writing changes to disk later.
- `fsync` requests that a file's changes be written promptly, while `sync` flushes filesystem changes more broadly.
Transcript excerpt
1:41 I >> All righty. Welcome back to operating
2:53 systems. So today, we get to talk about inodes. Fun. So recall we were talking before about how we store information about a file, how we would describe it. We left off with with indexed allocation where basically we have an array of blocks of the file. So at index zero, that's the first block of that file, whatever the value there would be would be where it is physically on disk and you'd go through like an array. So we discovered we would have a limit on the size of our file. If we only have one index block for our files, even if we had like 8 kilobyte blocks on our disk and only four byte pointers, well, that would still be blocks that can only hold two to the 11
3:41 entries. So in total, the maximum size of file would be 16 megabytes, which is still pretty lame. So what if some of these pointers pointed to blocks of more pointers? What does that sound like? >> Page table? >> Yeah, multi-level page right? Same idea. We don't have that many ideas in this course. We just use them for different things. So, small files, if you have a really small file, you only need one block of pointers. But if you have a much larger file you want to support, well, maybe you have like a two-level structure where one points to instead of just where the information is, where the next index block is, and then you use that and you go through two hops.
4:30 So, that exactly that's basically exactly what an inode is. So, inode on Linux describes all the metadata about a file, like where it lives on disk, and a few other things that we'll go into today,
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Jon Eyolfson.