Skip to content
API Documentation
BastionGuard™
anonymous_namespace{ext4_recovery.cpp} Namespace Reference

Classes

struct  ExportRange
struct  Ext4Inode
struct  ExtentRef
struct  JournalDirentCandidate
class  Ext4RecoveryImpl

Functions

uint16_t le16 (const unsigned char *p)
uint32_t le32 (const unsigned char *p)
uint64_t le64 (const unsigned char *p)
uint32_t be32 (const unsigned char *p)
std::string sanitize_path_component (const std::string &in)
template<typename ReadFn>
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)

Function Documentation

◆ be32()

uint32_t anonymous_namespace{ext4_recovery.cpp}::be32 ( const unsigned char * p)

Definition at line 40 of file ext4_recovery.cpp.

40 {
41 return (static_cast<uint32_t>(p[0]) << 24) |
42 (static_cast<uint32_t>(p[1]) << 16) |
43 (static_cast<uint32_t>(p[2]) << 8) |
44 static_cast<uint32_t>(p[3]);
45}

References be32().

Referenced by be32(), anonymous_namespace{ext4_recovery.cpp}::Ext4RecoveryImpl::build_journal_replay_map(), and anonymous_namespace{ext4_recovery.cpp}::Ext4RecoveryImpl::export_journal().

◆ le16()

◆ le32()

◆ le64()

uint64_t anonymous_namespace{ext4_recovery.cpp}::le64 ( const unsigned char * p)

Definition at line 30 of file ext4_recovery.cpp.

30 {
31 return static_cast<uint64_t>(p[0]) |
32 (static_cast<uint64_t>(p[1]) << 8) |
33 (static_cast<uint64_t>(p[2]) << 16) |
34 (static_cast<uint64_t>(p[3]) << 24) |
35 (static_cast<uint64_t>(p[4]) << 32) |
36 (static_cast<uint64_t>(p[5]) << 40) |
37 (static_cast<uint64_t>(p[6]) << 48) |
38 (static_cast<uint64_t>(p[7]) << 56);
39}

References le64().

Referenced by le64().

◆ sanitize_path_component()

std::string anonymous_namespace{ext4_recovery.cpp}::sanitize_path_component ( const std::string & in)
inline

◆ write_ranges_to_file()

template<typename ReadFn>
bool anonymous_namespace{ext4_recovery.cpp}::write_ranges_to_file ( ReadFn && read_fn,
const std::vector< ExportRange > & ranges,
const fs::path & out_path,
uint64_t expected_size,
std::string & error )

Definition at line 66 of file ext4_recovery.cpp.

70 {
71 std::ofstream out(out_path, std::ios::binary);
72 if (!out) {
73 error = trs("Unable to create output file") + std::string(": ") + out_path.string();
74 return false;
75 }
76 std::vector<unsigned char> buffer(1024 * 1024);
77 uint64_t written = 0;
78 for (const auto& r : ranges) {
79 uint64_t remaining = r.length;
80 uint64_t cursor = r.offset;
81 while (remaining > 0 && written < expected_size) {
82 const uint64_t allowed = std::min<uint64_t>(remaining, expected_size - written);
83 const size_t chunk = static_cast<size_t>(std::min<uint64_t>(buffer.size(), allowed));
84 if (r.zero_fill) {
85 std::fill(buffer.begin(), buffer.begin() + chunk, 0u);
86 } else if (!read_fn(cursor, buffer.data(), chunk)) {
87 error = trs("Read error while exporting recovered file");
88 return false;
89 }
90 out.write(reinterpret_cast<const char*>(buffer.data()), static_cast<std::streamsize>(chunk));
91 if (!out) {
92 error = trs("Write error while exporting recovered file");
93 return false;
94 }
95 cursor += chunk;
96 remaining -= chunk;
97 written += chunk;
98 }
99 if (written >= expected_size) break;
100 }
101 return true;
102}
std::string trs(const char *msgid)
Definition i18n.cpp:22

References trs(), and write_ranges_to_file().

Referenced by anonymous_namespace{ext4_recovery.cpp}::Ext4RecoveryImpl::export_file(), anonymous_namespace{ext4_recovery.cpp}::Ext4RecoveryImpl::export_journal(), and write_ranges_to_file().