1. Overview
The xfs_btree.cpp file implements traversal and decoding of XFS allocation and metadata B-trees.
This is an implementation file. It contains executable logic for the subsystem, including parsing, I/O, validation, recovery flow, or graphical behavior declared by the corresponding interface.
Its paired source or interface file is xfs_btree.hpp.
Primary responsibilities:
- Decode short and long B-tree headers
- Read internal and leaf records
- Traverse blocks safely
- Support inode and extent recovery
2. File Identity and Scope
- Source path:
src/xfs_btree.cpp - Language: C++
- File role: implementation file
- Physical lines: 724
- Non-empty lines: 654
- SHA-256:
3e68b8a7239761c8889e63fa447ac9bb90a7774f6cecff155b3e0442f94f067a
Declared namespaces:
xfs
3. Dependencies
3.1 Project Headers
xfs_btree.hppdisk_reader.hppxfs_inode.hpp
3.2 Standard and External Headers
algorithmarraysetsstreamvector
These dependencies define the file’s compile-time integration with the recovery engine, GTK interface, on-disk format decoders, operating-system services, or C++ standard library.
4. Declared Types
- struct
LocalBmbtRec.
5. Constants and Configuration Values
No preprocessor or compile-time constants were detected as top-level declarations in this file.
5.1 Operational Strings, Paths, Formats, or Commands
The following code literals are operationally relevant and may identify filesystem paths, helper commands, formats, signatures, or subsystem labels:
xfs_btree.hppXFSXFS IBT (AGXFS FINOBT (AGxfs_inode.hppXFS BMBT: traversal cap reached (1M nodes), stoppingXFS BMBT: cycle at FSBXFS BMBT: read failed at FSBXFS BMBT: bad magic at FSBXFS BMBT: level mismatch at FSBXFS BMBT: extent cap reached (
6. Data Members and Persistent State
No class data members are declared directly in this file, or the file primarily implements methods declared elsewhere.
7. API and Function Inventory
The following callable interfaces or definitions were detected:
uint32_t ibt_maxrecs(uint32_t blocksize,uint32_t header_size,uint32_t level)– Implements the operation identified by this API and updates or returns the associated state.uint64_t ag_block_to_disk_offset(const VolumeContext&vol,uint32_t agno,uint32_t agbno)– Implements the operation identified by this API and updates or returns the associated state.bool parse_btree_header(const unsigned char*buf,uint32_t expected_magic_v4,uint32_t expected_magic_v5,BtreeNodeHeader&out)– Reads or derives the requested information and returns or stores the decoded result.void parse_inobt_record(const unsigned char*buf,bool is_v5_sparse,InobtRec&out)– Reads or derives the requested information and returns or stores the decoded result.bool walk_ibt_block(DiskReader&reader,const VolumeContext&vol,uint32_t agno,uint32_t agbno,uint32_t expected_level,uint32_t magic_v4,uint32_t magic_v5,const char*tree_label,const InobtRecordCallback&on_record,std::set<uint32_t>&visited,size_t&nodes_visited,std::vector<std::string>&logs,std::string&error,bool&callback_stopped)– Implements the operation identified by this API and updates or returns the associated state.bool walk_inode_btree(DiskReader&reader,const VolumeContext&vol,uint32_t agno,const InobtRecordCallback&on_record,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool walk_all_inode_records(DiskReader&reader,const VolumeContext&vol,const InobtRecordCallback&on_record,std::vector<std::string>&logs)– Implements the operation identified by this API and updates or returns the associated state.bool walk_free_inode_btree(DiskReader&reader,const VolumeContext&vol,uint32_t agno,const InobtRecordCallback&on_record,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool walk_all_free_inode_records(DiskReader&reader,const VolumeContext&vol,const InobtRecordCallback&on_record,std::vector<std::string>&logs)– Implements the operation identified by this API and updates or returns the associated state.void expand_chunk(const InobtRec&rec,uint32_t agno,const VolumeContext&vol,std::vector<AllocatedInode>&out)– Implements the operation identified by this API and updates or returns the associated state.void expand_chunk_free(const InobtRec&rec,uint32_t agno,const VolumeContext&vol,std::vector<AllocatedInode>&out)– Implements the operation identified by this API and updates or returns the associated state.bool parse_btree_long_header(const unsigned char*buf,uint32_t expected_magic_v4,uint32_t expected_magic_v5,BtreeLongHeader&out)– Reads or derives the requested information and returns or stores the decoded result.void decode_bmbt_record_local(const unsigned char*buf16,LocalBmbtRec&r)– Reads or derives the requested information and returns or stores the decoded result.uint64_t fsb_to_byte_offset_local(uint64_t fsb,const VolumeContext&vol)– Implements the operation identified by this API and updates or returns the associated state.void push_extent(std::vector<Extent>&out,const LocalBmbtRec&r)– Implements the operation identified by this API and updates or returns the associated state.bool walk_bmbt_block(DiskReader&reader,const VolumeContext&vol,uint64_t child_fsb,uint32_t expected_level,bool is_v5,std::vector<Extent>&out,std::vector<std::string>&logs,uint32_t max_extents,std::set<uint64_t>&visited,size_t&nodes_visited)– Implements the operation identified by this API and updates or returns the associated state.bool walk_extent_btree_root(DiskReader&reader,const VolumeContext&vol,const unsigned char*root_buf,uint32_t root_len,bool is_v5_volume,uint32_t max_extents,std::vector<Extent>&out,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.
8. Operational Flow
The subsystem represented by this file normally participates in the following flow:
- Decode short and long B-tree headers.
- Read internal and leaf records.
- Traverse blocks safely.
- Support inode and extent recovery.
- Expose or execute the detected APIs:
ibt_maxrecs, ag_block_to_disk_offset, parse_btree_header, parse_inobt_record, walk_ibt_block, walk_inode_btree, walk_all_inode_records, walk_free_inode_btree, walk_all_free_inode_records, expand_chunk, expand_chunk_free, parse_btree_long_header, decode_bmbt_record_local, fsb_to_byte_offset_local, push_extent, walk_bmbt_block, walk_extent_btree_root. - Return explicit results, progress data, recovered records, or diagnostics to the calling layer.
9. Validation and Error Handling
- Errors are propagated through Boolean results, error strings, logs, exceptions, or status records depending on the API.
- Byte offsets, sizes and lengths must be validated before arithmetic and before every read to avoid overflow and out-of-bounds access.
- On-disk structures are accepted only after validating signatures, magic values and structural constraints.
- Input and output paths require existence checks, permission handling and safe destination construction.
10. Runtime, Concurrency, and Resource Management
- Deterministic behavior: callers depend on explicit return values and stable data structures to distinguish successful recovery from partial or invalid results.
- Temporary loop devices, mappings and mounts require deterministic reverse-order cleanup.
11. Security and Data-Recovery Considerations
- Recovery code should prefer read-only source access and avoid writing to the original damaged medium.
- Raw devices and image files are treated as untrusted binary input; every offset and length must remain bounded by the source size.
12. Implementation Considerations
- The implementation should remain aligned with declarations in the paired header and preserve documented return-value semantics.
- Binary decoding uses low-level memory operations or casts; alignment, endianness and packed-structure assumptions require careful review.
- Large-device arithmetic uses 64-bit values; additions and multiplications should be checked before use as offsets or allocation sizes.
13. Integration with the Recovery Pipeline
- The file belongs to the source-discovery, parsing or support layer.
- Its results feed scanner, recovery or reporting modules through shared models.
- The API should remain deterministic so higher layers can combine results safely.
14. Licensing and Provenance
No explicit copyright or software-license statement was detected in the opening section of this individual file. Distribution terms should therefore be verified against the project-level license and repository metadata.
The SHA-256 value in this document can be used to associate the generated documentation with the exact source version analyzed.
