DISK · 64 BLOCKS OF 4 KBblock 0sizesinodes 16-230000 1000blocks 8-151110 0000block 8dirINODE TABLE · BLOCKS 3-7inode2typedirptr 08inode20size6000ptr 09ptr 110ptr 2–block 9datablock 10datablock 11freeblock 12free… to block 631fd = open("/notes", O_RDWR);2pread(fd, b, 100, 5000);3pwrite(fd, b, 4000, 6000);fdbuf b282035000100 B999911
Back: the disk (superblock, bitmaps, inode table, data blocks)Front: the program's code and its memory (fd, buf)Tiles: the numbers the kernel follows, from name to inode to blockThe disk at the back, in block order: superblock, inode bitmap, data bitmap, the inode table with inode 2 (the root directory) and inode 20 (the file notes), then data blocks 8 to 12. The program and its memory in front. open walks inode 2 to directory block 8 to inode 20 and returns fd 3. pread turns byte 5000 into pointer 1, block 10. pwrite finds pointer 2 empty, takes block 11 from the data bitmap, writes blocks 10 and 11, then updates the inode. The disk is the "very simple file system" from OSTEP chapter 40: 64 blocks of 4 KB with the same regions in the same order. Real file systems are bigger and split the disk into groups, but the parts are the same.

The layout

  1. On disk a file is split in three. Its name sits in a directory. Its inode, a small fixed-size record, holds the facts about it and where its bytes are. The bytes themselves sit in data blocks of 4096 bytes.

Opening a file

Reading and growing

Bigger files

What happens

;; step 1/11 · three-parts
name     in a directory:   "notes" -> inode 20
inode    number 20: type, size, owner, times, links,
         and pointers to its data blocks
data     blocks 9 and 10: the 6000 bytes of the file

the inode number is the file's real identity;
the name is just an entry that points to it

The disk is the "very simple file system" from OSTEP chapter 40: 64 blocks of 4 KB with the same regions in the same order. Real file systems are bigger and split the disk into groups, but the parts are the same. The bitmaps on the figure show only the eight bits that matter: inodes 16 to 23 and data blocks 8 to 15. Each real bitmap fills a whole 4 KB block.