1. Overview
The ext4_recovery.cpp file implements recovery of files and directory metadata from EXT-family filesystems.
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 ext4_recovery.hpp.
Primary responsibilities:
- Read superblocks and group descriptors
- Locate and decode inodes
- Traverse directory entries
- Resolve block extents
- Export recovered files
2. File Identity and Scope
- Source path:
src/ext4_recovery.cpp - Language: C++
- File role: implementation file
- Physical lines: 1130
- Non-empty lines: 1056
- SHA-256:
a5659c0426d5c224741c6a20028a11d041b1b38abc9493d9a20707d8942b93e6
The declarations in this file use the global namespace.
3. Dependencies
3.1 Project Headers
ext4_recovery.hppi18n.hpptext_utils.hpp
3.2 Standard and External Headers
algorithmarraycctypecstdintfilesystemfstreammapsetstringvector
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
ExportRange. - struct
Ext4Inode. - struct
ExtentRef. - struct
JournalDirentCandidate. - class
Ext4RecoveryImpl.
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:
ext4_recovery.hppext4ext4 recovery started at offsetext4 block sizeext4 recovery completed.Failed to read ext4 superblockInvalid ext4 superblock magicUnsupported ext4 geometryext4 journal replay overlay blocksext4 committed journal transactionsext4 journal revoke recordsInvalid ext4 inode numberFailed to read ext4 group descriptorInvalid ext4 inode table pointerFailed to read ext4 inodeFailed to read ext4 extent nodeInvalid ext4 extent headerext4 inode does not use extentsInvalid ext4 inode extent headerFailed to read ext4 indirect blockCannot create ext4 fileRecovered ext4 inline-data file withext4 inline_data file truncatedext4 inline_data file truncated to 60 bytesRecovered ext4 inline-data file:Skipped ext4 file without supported data mappingRecovered ext4 file:ext4 journal inode could not be readext4 journal mapping unsupported or unreadableext4 journal export failedext4 journal exportedSkipped ext4 directory without supported data mapping
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:
uint16_t le16(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.uint32_t le32(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.uint64_t le64(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.uint32_t be32(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.inline std::string sanitize_path_component(const std::string&in)– Implements the operation identified by this API and updates or returns the associated state.bool write_ranges_to_file(ReadFn&&read_fn,const std::vector<ExportRange>&ranges,const fs::path&out_path,uint64_t expected_size,std::string&error)– Persists or exports the supplied state to the relevant destination.explicit Ext4RecoveryImpl(DiskReader&reader): reader_(reader)– Implements the operation identified by this API and updates or returns the associated state.bool recover(uint64_t volume_offset,const std::string&output_dir,std::vector<RecoveredFileRecord>&recovered,std::vector<std::string>&logs,std::string&error)– Performs the associated recovery or extraction operation.bool load_superblock(std::string&error)– Reads or derives the requested information and returns or stores the decoded result.uint64_t block_to_offset(uint64_t block)const– Implements the operation identified by this API and updates or returns the associated state.bool read_fs_block(uint64_t block_no,unsigned char*buffer,size_t len)– Reads or derives the requested information and returns or stores the decoded result.bool read_volume_bytes_replayed(uint64_t volume_rel_offset,unsigned char*buffer,size_t len)– Reads or derives the requested information and returns or stores the decoded result.void build_journal_replay_map(std::vector<std::string>&logs)– Constructs the requested object, data structure or user-interface component.bool read_group_desc(uint32_t group,std::vector<unsigned char>&out)– Reads or derives the requested information and returns or stores the decoded result.bool inode_marked_allocated(uint32_t inode_no)– Implements the operation identified by this API and updates or returns the associated state.bool read_inode(uint32_t inode_no,Ext4Inode&inode,std::string&error)– Reads or derives the requested information and returns or stores the decoded result.uint64_t inode_size_bytes(const Ext4Inode&inode)const– Implements the operation identified by this API and updates or returns the associated state.bool inode_is_dir(const Ext4Inode&inode)const– Implements the operation identified by this API and updates or returns the associated state.bool inode_is_reg(const Ext4Inode&inode)const– Implements the operation identified by this API and updates or returns the associated state.bool inode_uses_extents(const Ext4Inode&inode)const– Implements the operation identified by this API and updates or returns the associated state.bool find_inline_xattr_system_data(const Ext4Inode&inode,std::vector<unsigned char>&out)const– Inspects the source and reports matching candidates or detected metadata.bool collect_extents_from_node(uint64_t node_phys_block,std::vector<ExtentRef>&extents,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool inode_extents(const Ext4Inode&inode,std::vector<ExtentRef>&extents,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool read_u32_block(uint64_t block_no,std::vector<uint32_t>&out,std::string&error)– Reads or derives the requested information and returns or stores the decoded result.bool inode_block_map_classic(const Ext4Inode&inode,std::vector<uint64_t>&blocks,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool inode_ranges(const Ext4Inode&inode,std::vector<ExportRange>&ranges,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool export_file(uint32_t inode_no,const std::string&name,const Ext4Inode&inode,const fs::path&out_dir,std::vector<RecoveredFileRecord>&recovered,std::vector<std::string>&logs,std::string&error)– Persists or exports the supplied state to the relevant destination.static bool looks_like_printable_name(const unsigned char*p,size_t len)– Implements the operation identified by this API and updates or returns the associated state.static std::string ext4_file_type_name(uint8_t t)– Implements the operation identified by this API and updates or returns the associated state.void scan_journal_dirents(const std::vector<unsigned char>&block,uint32_t target_block,uint32_t sequence,std::vector<JournalDirentCandidate>&out)– Inspects the source and reports matching candidates or detected metadata.void export_journal(const fs::path&out_root,std::vector<RecoveredFileRecord>&recovered,std::vector<std::string>&logs)– Persists or exports the supplied state to the relevant destination.bool recover_directory(uint32_t inode_no,const fs::path&out_dir,std::vector<RecoveredFileRecord>&recovered,std::vector<std::string>&logs,std::string&error,std::set<uint32_t>&dir_guard,int depth)– Performs the associated recovery or extraction operation.Ext4Recovery::Ext4Recovery(DiskReader&reader): reader_(reader)– Implements the operation identified by this API and updates or returns the associated state.bool Ext4Recovery::recover(uint64_t volume_offset,const std::string&output_dir,std::vector<RecoveredFileRecord>&recovered,std::vector<std::string>&logs,std::string&error)– Performs the associated recovery or extraction operation.
8. Operational Flow
The subsystem represented by this file normally participates in the following flow:
- Read superblocks and group descriptors.
- Locate and decode inodes.
- Traverse directory entries.
- Resolve block extents.
- Export recovered files.
- Expose or execute the detected APIs:
le16, le32, le64, be32, sanitize_path_component, write_ranges_to_file, Ext4RecoveryImpl, recover, load_superblock, block_to_offset, read_fs_block, read_volume_bytes_replayed, build_journal_replay_map, read_group_desc, inode_marked_allocated, read_inode, inode_size_bytes, inode_is_dirand additional helpers. - 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
- I/O: filesystem and raw-source operations can fail partially and must preserve exact byte counts and diagnostic context.
- File descriptors and streams must be closed on success, cancellation and error paths.
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.
- Recovered names and destination paths must be sanitized to prevent directory traversal and accidental overwrite outside the selected export directory.
12. Implementation Considerations
- The implementation should remain aligned with declarations in the paired header and preserve documented return-value semantics.
- The file is large and combines multiple parsing or recovery stages; refactoring should preserve byte-level behavior and regression coverage.
- 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.
- Filesystem operations can cross trust boundaries and should use normalized, contained destination paths.
13. Integration with the Recovery Pipeline
- The file belongs to the extraction layer and consumes scan candidates or validated filesystem metadata.
- Recovered output is represented through shared models and returned to the exporter or UI.
- Partial recovery must be reported explicitly rather than silently treated as complete.
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.
