Technical Women

001
Figure 1. Jean Bartik

Today

  • Finding data blocks

  • Caching and consistency

ASST3.2 Checkpoint

At this point:
  • If you have not started ASST3.2, you’re behind.

ASST3.2 is due in less than 2 weeks. Get started!

ext4 inodes

  • 1 inode per file.

  • 256 bytes, so 1 per sector or 16 per block.

Contains:
  • Location of file data blocks (contents).

  • Permissions including user, read/write/execute bits, etc.

  • Timestamps including creation (crtime), access (atime), content modification (mtime), attribute modification (ctime) and delete (dtime) times.

  • Named and located by number.

ext4 inodes

debugfs stat

Locating inodes

How does the system translate an inode number into an inode structure?
  • All inodes are created at format time at well-known locations.

inodelocations
What are the consequences of this?
  • inodes may not be located near file contents. ext4 creates multiple blocks of inodes within the drive to reduce seek times between inodes and data.

  • Fixed number of inodes for the file system. Can run out of inodes before we run out of data blocks! ext4 creates approximately one inode per 16 KB of data blocks, but this can be configured at format time.

Directories

Simply a special file the contents of which map inode numbers to relative names.

lsid

File System Names are inode Numbers, Directories Are Files

debugfs stat

Using debugfs

debugfs show super stats1

Using debugfs

debugfs show super stats2

open: Path Name Translation

open("/etc/default/keyboard") must translate "/etc/default/keyboard" to an inode number.

  1. Get inode number for root directory. This is usually a fixed agreed-on inode number, like 2.

  2. Open the directory with inode number 2. Look for "etc". Find "etc" with inode number 393218.

  3. Open the directory with inode number 393218. Look for "default". Find "default" with inode number 393247.

  4. Open the directory with inode number 393247. Look for "keyboard". Find keyboard with inode number 394692.

  5. Open the file with inode number 394692.

read/write: Retrieving and Modifying Data Blocks

  • read/write(filehandle, 345) must translate 345 to a data block within the open file to determine what data block to modify.

  • There are multiple ways of doing this.

Data Blocks: Linked List

One solution: organize data blocks into a linked list.

  • inode contains a pointer to the first data block.

  • Each data block contains a pointer to the previous and next data block.

Pros:
  • Simple.

  • Small amount of information in inode.

Cons:
  • Offset look ups are slow! O(n) in the size of the file.

Data Blocks: Flat Array

A second solution: store all data blocks in the inode in a single array allocated at file creation time.

Pros:
  • Also simple.

  • Offset look ups are fast, O(1).

Cons:
  • Small file size fixed at startup time.

  • Large portion of array may be unused.

Data Blocks: Multilevel Index

Observation: most files are small, but some can get very large.

Have inode store:
  • some pointers to blocks, which we refer to as direct blocks.

  • some pointers to blocks containing pointers to blocks, which we refer to as indirect blocks.

  • some pointers to blocks containing pointers to blocks containing pointers to blocks, which we refer to as doubly indirect blocks.

  • etc…​

Data Blocks: Multilevel Index

image

Data Blocks: Multilevel Index

Pros:
  • Index scales with the size of the file.

  • Offset look ups are still fairly fast.

  • Small files stay small, but big files can get extremely large.

Next Time

  • Consistency and caching.

  • Journaling.