C API

Defines

BCACHEFS_ITERATOR_CLEAN (Bcachefs_iterator){.type = BTREE_ID_NR}
BCACHEFS_CLEAN

(Bcachefs){ \

._extents_iter_begin = BCACHEFS_ITERATOR_CLEAN, \

._inodes_iter_begin = BCACHEFS_ITERATOR_CLEAN, \

._dirents_iter_begin = BCACHEFS_ITERATOR_CLEAN, \

._root_stats = (

Bcachefs_inode

){0}, \

._root_dirent = (

Bcachefs_dirent

){0} \

}

Typedefs

typedef struct Bcachefs_iterator Bcachefs_iterator

Functions

int Bcachefs_open(Bcachefs *this, const char *path)

Open a Bcachefs disk image for reading.

Return
1 on success, 0 on failure
Parameters
  • this: Bcachefs struct to initialize
  • path: path to the image

int Bcachefs_close(Bcachefs *this)

Close a Bcachefs disk image.

Return
1 on success, 0 on failure
Parameters
  • this: disk image to close

Bcachefs_iterator *Bcachefs_iter(const Bcachefs *this, enum btree_id type)

Create a Bcachefs iterator to go through a Bcachefs btree.

Return
initialized iterator struct or NULL on failure
Parameters
  • this: disk image
  • type: type of the btree to iterate over

Bcachefs_extent Bcachefs_find_extent(Bcachefs *this, uint64_t inode, uint64_t file_offset)

Find and parse an extent descriptor of a file at a particular offset.

The file offset needs to exist in the extents list

Return
parsed Bcachefs_extent or a zeroed struct on failure
Parameters
  • this: disk image
  • inode: inode of a file
  • file_offset: offset of a file extent

Bcachefs_inode Bcachefs_find_inode(Bcachefs *this, uint64_t inode)

Find and parse the inode informations of a file.

Return
parsed Bcachefs_inode or a zeroed struct on failure
Parameters
  • this: disk image
  • inode: inode of a file

Bcachefs_dirent Bcachefs_find_dirent(Bcachefs *this, uint64_t parent_inode, uint64_t hash_seed, const uint8_t *name, const uint8_t len)

Find and parse the dirent informations of a file.

Return
parsed Bcachefs_inode or a zeroed struct on failure
Parameters
  • this: disk image
  • parent_inode: inode of the parent directory
  • hash_seed: hash seed of the parent directory or 0
  • name: name of the dirent to find
  • len: length of the name string

const struct bch_val *Bcachefs_iter_next(const Bcachefs *this, Bcachefs_iterator *iter)

Fetch next value from an iterator.

Return
next bch_val or NULL if the end is reached
Parameters
  • this: disk image
  • iter: a disk image’s iterator struct

int Bcachefs_iter_fini(const Bcachefs *this, Bcachefs_iterator *iter)

Free the resources allocated by the iterator.

Return
1 on success, 0 on failure
Parameters
  • this: disk image
  • iter: a disk image’s iterator struct

Bcachefs_extent Bcachefs_iter_make_extent(const Bcachefs *this, Bcachefs_iterator *iter)

Extract extent descriptor from the current bch_val of an iterator.

Return
parsed Bcachefs_extent or a zeroed struct on failure
Parameters
  • this: disk image
  • iter: a disk image’s iterator struct

Bcachefs_inode Bcachefs_iter_make_inode(const Bcachefs *this, Bcachefs_iterator *iter)

Extract inode information from the current bch_val of an iterator.

Return
parsed Bcachefs_inode or a zeroed struct on failure
Parameters
  • this: disk image
  • iter: a disk image’s iterator struct

Bcachefs_dirent Bcachefs_iter_make_dirent(const Bcachefs *this, Bcachefs_iterator *iter)

Extract dirent information from the current bch_val of an iterator.

Return
parsed Bcachefs_dirent or a zeroed struct on failure
Parameters
  • this: the disk image we are reading from
  • iter: the iterator pointing to the value we want to extract

int Bcachefs_next_iter(const Bcachefs *this, Bcachefs_iterator *iter, const struct bch_btree_ptr_v2 *btree_ptr)
int Bcachefs_iter_reinit(const Bcachefs *this, Bcachefs_iterator *iter, enum btree_id type)
int Bcachefs_iter_minimal_copy(const Bcachefs *this, Bcachefs_iterator *iter, const Bcachefs_iterator *other)
const struct jset_entry *Bcachefs_iter_next_jset_entry(const Bcachefs *this, Bcachefs_iterator *iter)
const struct bch_btree_ptr_v2 *Bcachefs_iter_next_btree_ptr(const Bcachefs *this, Bcachefs_iterator *iter)
const struct bset *Bcachefs_iter_next_bset(const Bcachefs *this, Bcachefs_iterator *iter)
struct Bcachefs_extent
#include <bcachefs_iterator.h>

Decoded value from the extend btree.

Includes

Public Members

uint64_t Bcachefs_extentinode
uint64_t Bcachefs_extentfile_offset
uint64_t Bcachefs_extentoffset
uint64_t Bcachefs_extentsize
struct Bcachefs_inode
#include <bcachefs_iterator.h>

Decoded value from the inode btree.

Public Members

uint64_t Bcachefs_inodeinode
uint64_t Bcachefs_inodesize
uint64_t Bcachefs_inodehash_seed
struct Bcachefs_dirent
#include <bcachefs_iterator.h>

Decoded value from the dirent btree.

Public Members

uint64_t Bcachefs_direntparent_inode
uint64_t Bcachefs_direntinode
uint8_t Bcachefs_direnttype
const uint8_t *Bcachefs_direntname
uint8_t Bcachefs_direntname_len
struct Bcachefs_iterator

Public Members

btree_id Bcachefs_iteratortype
const struct jset_entry *Bcachefs_iteratorjset_entry

which btree are we iterating over

const struct bch_btree_ptr_v2 *Bcachefs_iteratorbtree_ptr

journal entry specifying the location of the btree root

const struct bch_val *Bcachefs_iteratorbch_val

current btree node location

const struct bkey *Bcachefs_iteratorbkey

current value stored inside along side the key

struct btree_node *Bcachefs_iteratorbtree_node
struct Bcachefs_iterator *Bcachefs_iteratornext_it

current btree node

const struct bkey **Bcachefs_iteratorkeys

pointer to the children btree node if iterating over nested Btrees

uint32_t Bcachefs_iteratornum_keys
uint32_t Bcachefs_iteratorpos
struct Bcachefs

Public Members

FILE *Bcachefsfp
long Bcachefssize
struct bch_sb *Bcachefssb
Bcachefs_iterator *Bcachefs_iter
Bcachefs_iterator Bcachefs_extents_iter_begin
Bcachefs_iterator Bcachefs_inodes_iter_begin
Bcachefs_iterator Bcachefs_dirents_iter_begin
Bcachefs_inode Bcachefs_root_stats
Bcachefs_dirent Bcachefs_root_dirent