GSoC 2018 weeks 3-4 - understanding BTRFS internals

by extravert34 | June 14, 2018

Hi all!
This two weeks I was diving into btrfs structures and on-disk layout. Writing an ASM program from scratch is not that simple so I decided to convert a VirtualBox image with BTRFS filesystem in it to raw file and write a python script to parse and show internal filesystem structures.

It was also useful for understanding how files are stored in FS, because information on was not enough for me to understand some corner cases.

So here it is - in (/modules/rosapps/applications/rosinternals/btrfstools)

Listing directory items

This script:

  • understands the most basic BTRFS structures (header, key and item)
  • can display a lot of item types (not all of them, but the most useful for me)
  • implements a btree search function so you can walk through different BTRFS trees
  • automatically builds a chunk map for logical-to-physical address translation

With this script I was able to implement a "bootloader" in python - it finds and reads freeldr.sys file in filesystem blob (see in the same folder)

Now it's time to finally write this as VBR code in ASM. See you in next blog post!