14 cze 2018



GSoC 2018 weeks 3-4 - understanding BTRFS internals


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 btrfs.wiki.kernel.org was not enough for me to understand some corner cases.

So here it is - btrfs_structures.py 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 btrfs_playground.py in the same folder)

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

This blog post represents the personal opinion of the author and is not representative of the position of the ReactOS Project.