On disk format
The superblock is the first thing to be read when accessing a bcachefs filesystem. It is located 4kb from the start of the device, with redundant copies elsewhere - typically one immediately after the first superblock, and one at the end of the device.
bch_sb_layout records the amount of space reserved for the
superblock as well as the locations of all the superblocks. It is
included with every superblock, and additionally written 3584 bytes from
the start of the device (512 bytes before the first superblock).
Most of the superblock is identical across each device. The exceptions
dev_idx field, and the journal section which gives the
location of the journal.
The main section of the superblock contains UUIDs, version numbers, number of devices within the filesystem and device index, block size, filesystem creation time, and various options and settings. The superblock also has a number of variable length sections:
struct jset): btree roots, as well as filesystem usage and read/write counters (total amount of data read/written to this filesystem). This allows reading the journal to be skipped after clean shutdowns.
Every journal write (
struct jset) contains a list of entries:
struct jset_entry. Below are listed the various journal entry types.
struct bkey), and the
jset_entryrecord the btree ID and level the key belongs to.
KEY_TYPE_btree_ptr_v2, and the btree_id and level fields of
jset_entryrecord the btree ID and depth.