Inode Block Mapping

medium · os, filesystem, inode

Inode Block Mapping

Given an inode with direct and indirect pointers, return the physical block for a logical block index.

Types

type Inode struct {
    Direct   []int   // length 4
    Indirect []int   // length 4 (single indirect)
    Double   [][]int // length 4, each length 4 (double indirect)
}

func BlockAt(inode Inode, logical int) int

Layout

  • Direct blocks: logical 0..3
  • Single indirect: logical 4..7
  • Double indirect: logical 8..23 (4x4)

Behavior

  • Return the physical block number, or -1 if out of range or missing.
  • A missing pointer is represented by -1.
Run tests to see results
No issues detected