CSE Roadmap

Core tier · about 3 hours · 7 parts

Part 2 of 7 · 2 min read

The regions

Think of a warehouse. At the door is a sign that says how big the warehouse is. Inside are a list of which shelves are used, a card index for every item, and the shelves where the goods sit. The analogy stops in one place: a warehouse is rearranged by people, and a file system is changed by the OS in small steps that must stay correct after a crash.

In plain words: A file system divides the disk into blocks of one size, here 4 KiB. A few blocks hold bookkeeping, and the rest hold file data. The superblock records the size of the file system, the block size, the number of inodes and a magic number that says what kind of file system this is. A bitmap holds one bit for each block, or for each inode, which says whether it is free (0) or in use (1). The inode table is an array of fixed-size inode records. All other blocks are data blocks. They hold file contents, directory contents and the other structures.

A worked example. dumpe2fs on the test image printed these lines for its one group, which covers blocks 0 to 4,095:

Group 0: (Blocks 0-4095)
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-2
  Block bitmap at 3 (+3)
  Inode bitmap at 19 (+19)
  Inode table at 35-290 (+35)
  3567 free blocks, 4080 free inodes, 3 directories, 4080 unused inodes

The superblock sits at the start (the real one is at byte offset 1,024). The group descriptor in block 1 tells where this group keeps its bitmaps and its inode table. The block bitmap is in block 3 and the inode bitmap is in block 19. The inode table fills blocks 35 to 290, which is 256 blocks. That fits the arithmetic: 4,096 inodes of 256 bytes each is 1,048,576 bytes, which is 256 blocks of 4 KiB. All blocks from 291 on are data blocks.

The key lines. The size of the bookkeeping is not small. Here 291 of 4,096 blocks are not data blocks, which is 7.1% of the image. Large file systems have a smaller share, since the inode ratio is lower.

Superblock

The superblock is the block, at a fixed place near the start of a file system, that records the global facts about it: its type (a magic number), the block size, the number of blocks and inodes, and where the other structures begin. The OS reads it first when it mounts the file system.

Example: the superblock of the test image holds the magic number 0xEF53, which marks it as an ext-family file system, a block size of 4,096 and 4,096 inodes.

Check yourself: 1. Which structure tells you whether block 500 is free? 2. How many blocks does an inode table of 4,096 inodes of 256 bytes occupy at 4 KiB per block? 3. Why does the OS read the superblock before anything else?