35extern "C" uint32_t FIM_RESERVED_OFFSET;
39namespace fs = std::filesystem;
51 constexpr static uint64_t
const fim_reserved_offset_permissions_begin = 0;
52 constexpr static uint64_t
const fim_reserved_offset_permissions_end = fim_reserved_offset_permissions_begin + 8;
54 constexpr static uint64_t
const fim_reserved_offset_notify_begin = fim_reserved_offset_permissions_end;
55 constexpr static uint64_t
const fim_reserved_offset_notify_end = fim_reserved_offset_notify_begin + 1;
57 constexpr static uint64_t
const fim_reserved_offset_overlay_begin = fim_reserved_offset_notify_end;
58 constexpr static uint64_t
const fim_reserved_offset_overlay_end = fim_reserved_offset_overlay_begin + 1;
60 constexpr static uint64_t
const fim_reserved_offset_casefold_begin = fim_reserved_offset_overlay_end;
61 constexpr static uint64_t
const fim_reserved_offset_casefold_end = fim_reserved_offset_casefold_begin + 1;
63 constexpr static uint64_t
const fim_reserved_offset_desktop_begin = fim_reserved_offset_casefold_end;
64 constexpr static uint64_t
const fim_reserved_offset_desktop_end = fim_reserved_offset_desktop_begin + 4_kib;
66 constexpr static uint64_t
const fim_reserved_offset_boot_begin = fim_reserved_offset_desktop_end;
67 constexpr static uint64_t
const fim_reserved_offset_boot_end = fim_reserved_offset_boot_begin + 8_kib;
69 constexpr static uint64_t
const fim_reserved_offset_icon_begin = fim_reserved_offset_boot_end;
70 constexpr static uint64_t
const fim_reserved_offset_icon_end = fim_reserved_offset_icon_begin + 1_mib;
72 constexpr static uint64_t
const fim_reserved_offset_environment_begin = fim_reserved_offset_icon_end;
73 constexpr static uint64_t
const fim_reserved_offset_environment_end = fim_reserved_offset_environment_begin + 1_mib;
75 constexpr static uint64_t
const fim_reserved_offset_bindings_begin = fim_reserved_offset_environment_end;
76 constexpr static uint64_t
const fim_reserved_offset_bindings_end = fim_reserved_offset_bindings_begin + 1_mib;
78 constexpr static uint64_t
const fim_reserved_offset_remote_begin = fim_reserved_offset_bindings_end;
79 constexpr static uint64_t
const fim_reserved_offset_remote_end = fim_reserved_offset_remote_begin + 4_kib;
81 constexpr static uint64_t
const fim_reserved_offset_unshare_begin = fim_reserved_offset_remote_end;
82 constexpr static uint64_t
const fim_reserved_offset_unshare_end = fim_reserved_offset_unshare_begin + 2;
89 static_assert(fim_reserved_offset_unshare_end < FIM_RESERVED_SIZE,
"Insufficient reserved space");
93constexpr Reserved reserved;
97uint64_t
const FIM_RESERVED_OFFSET_PERMISSIONS_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_permissions_begin;
98uint64_t
const FIM_RESERVED_OFFSET_PERMISSIONS_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_permissions_end;
100uint64_t
const FIM_RESERVED_OFFSET_NOTIFY_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_notify_begin;
101uint64_t
const FIM_RESERVED_OFFSET_NOTIFY_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_notify_end;
103uint64_t
const FIM_RESERVED_OFFSET_OVERLAY_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_overlay_begin;
104uint64_t
const FIM_RESERVED_OFFSET_OVERLAY_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_overlay_end;
106uint64_t
const FIM_RESERVED_OFFSET_CASEFOLD_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_casefold_begin;
107uint64_t
const FIM_RESERVED_OFFSET_CASEFOLD_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_casefold_end;
109uint64_t
const FIM_RESERVED_OFFSET_DESKTOP_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_desktop_begin;
110uint64_t
const FIM_RESERVED_OFFSET_DESKTOP_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_desktop_end;
112uint64_t
const FIM_RESERVED_OFFSET_BOOT_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_boot_begin;
113uint64_t
const FIM_RESERVED_OFFSET_BOOT_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_boot_end;
115uint64_t
const FIM_RESERVED_OFFSET_ICON_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_icon_begin;
116uint64_t
const FIM_RESERVED_OFFSET_ICON_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_icon_end;
118uint64_t
const FIM_RESERVED_OFFSET_ENVIRONMENT_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_environment_begin;
119uint64_t
const FIM_RESERVED_OFFSET_ENVIRONMENT_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_environment_end;
121uint64_t
const FIM_RESERVED_OFFSET_BINDINGS_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_bindings_begin;
122uint64_t
const FIM_RESERVED_OFFSET_BINDINGS_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_bindings_end;
124uint64_t
const FIM_RESERVED_OFFSET_REMOTE_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_remote_begin;
125uint64_t
const FIM_RESERVED_OFFSET_REMOTE_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_remote_end;
127uint64_t
const FIM_RESERVED_OFFSET_UNSHARE_BEGIN = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_unshare_begin;
128uint64_t
const FIM_RESERVED_OFFSET_UNSHARE_END = FIM_RESERVED_OFFSET + reserved.fim_reserved_offset_unshare_end;
143 , uint64_t offset_begin
144 , uint64_t offset_end
146 , uint64_t length)
noexcept
148 uint64_t size = offset_end - offset_begin;
149 return_if(length > size, Error(
"E::Size of data exceeds available space"));
151 std::fstream file_binary(path_file_binary, std::ios::binary | std::ios::in | std::ios::out);
152 return_if(not file_binary.is_open(), Error(
"E::Failed to open input file"));
154 std::vector<char> blank(size, 0);
155 return_if(not file_binary.seekp(offset_begin), Error(
"E::Failed to seek offset to blank"));
156 return_if(not file_binary.write(blank.data(), size), Error(
"E::Failed to write blank data"));
158 return_if(not file_binary.seekp(offset_begin), Error(
"E::Failed to seek offset to write data"));
159 return_if(not file_binary.write(data, length), Error(
"E::Failed to write data"));
175 , uint64_t length)
noexcept
178 std::ifstream file_binary(path_file_binary, std::ios::binary | std::ios::in);
179 return_if(not file_binary.is_open(), Error(
"E::Failed to open input file"));
181 return_if(not file_binary.seekg(offset), Error(
"E::Failed to seek to file offset for read"));
183 return_if(not file_binary.read(data, length), Error(
"E::Failed to read data from binary file"));
185 return file_binary.gcount();
Common utility functions and helpers used throughout FlatImage.
Enhanced error handling framework built on std::expected.
Simplified macros for common control flow patterns with optional logging.
Management of ELF binary reserved space for configuration storage.
Value< void > write(fs::path const &path_file_binary, uint64_t offset_begin, uint64_t offset_end, const char *data, uint64_t length) noexcept
Writes data to a file in binary format.
Value< std::streamsize > read(fs::path const &path_file_binary, uint64_t offset, char *data, uint64_t length) noexcept
Reads data from a file in binary format.
Enhanced expected type with integrated logging capabilities.
constexpr Reserved()
Validates reserved space layout at compile-time.