On disk format
Superblock
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.
The 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
are the 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:
BCH_SB_FIELD_journalBCH_SB_FIELD_membersBCH_SB_FIELD_cryptBCH_SB_FIELD_replicasBCH_SB_FIELD_quotaBCH_SB_FIELD_disk_groupsBCH_SB_FIELD_cleanstruct 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.Journal
Every journal write (struct jset) contains a list of entries:
struct jset_entry. Below are listed the various journal entry types.
BCH_JSET_ENTRY_btree_keystruct bkey), and the
btree_id and level fields of jset_entry record the
btree ID and level the key belongs to.BCH_JSET_ENTRY_btree_rootKEY_TYPE_btree_ptr_v2, and the btree_id and level fields of
jset_entry record the btree ID and depth.BCH_JSET_ENTRY_clockBCH_JSET_ENTRY_usageBCH_JSET_ENTRY_data_usageBCH_JSET_ENTRY_dev_usageBtrees
Btree keys
KEY_TYPE_deleted
KEY_TYPE_whiteout
KEY_TYPE_error
KEY_TYPE_cookie
KEY_TYPE_hash_whiteout
KEY_TYPE_btree_ptr
KEY_TYPE_extent
KEY_TYPE_reservation
KEY_TYPE_inode
KEY_TYPE_inode_generation
KEY_TYPE_dirent
KEY_TYPE_xattr
KEY_TYPE_alloc
KEY_TYPE_quota
KEY_TYPE_stripe
KEY_TYPE_reflink_p
KEY_TYPE_reflink_v
KEY_TYPE_inline_data
KEY_TYPE_btree_ptr_v2
KEY_TYPE_indirect_inline_data
KEY_TYPE_alloc_v2
KEY_TYPE_subvolume
KEY_TYPE_snapshot
KEY_TYPE_inode_v2
KEY_TYPE_alloc_v3