87 TRACE(
"Entering process_ddt_v1(%p, %p, %d)", ctx, entry, *found_user_data_ddt);
90 size_t read_bytes = 0;
92 uint8_t *cmp_data = NULL;
93 uint32_t *cd_ddt = NULL;
101 FATAL(
"Invalid context or image stream.");
103 TRACE(
"Exiting process_ddt_v1() = AARUF_ERROR_NOT_AARUFORMAT");
108 TRACE(
"Seeking to DDT block at position %" PRIu64, entry->
offset);
112 FATAL(
"Could not seek to %" PRIu64
" as indicated by index entry...", entry->
offset);
114 TRACE(
"Exiting process_ddt_v1() = AARUF_ERROR_CANNOT_READ_BLOCK");
119 TRACE(
"Reading DDT block header at position %" PRIu64, entry->
offset);
124 FATAL(
"Could not read block header at %" PRIu64
"", entry->
offset);
126 TRACE(
"Exiting process_ddt_v1() = AARUF_ERROR_CANNOT_READ_BLOCK");
130 *found_user_data_ddt =
true;
147 FATAL(
"Compressed DDT payload too small (%" PRIu64
") for LZMA properties.", ddt_header.
cmpLength);
153 cmp_data = (uint8_t *)malloc(lzma_size);
156 TRACE(
"Cannot allocate memory for DDT, continuing...");
163 TRACE(
"Cannot allocate memory for DDT, continuing...");
171 TRACE(
"Could not read LZMA properties, continuing...");
178 read_bytes = fread(cmp_data, 1, lzma_size, ctx->
imageStream);
179 if(read_bytes != lzma_size)
181 TRACE(
"Could not read compressed block, continuing...");
188 read_bytes = ddt_header.
length;
189 TRACE(
"Decompressing block of size %zu bytes", ddt_header.
length);
195 FATAL(
"Got error %d from LZMA, stopping...", error_no);
202 if(read_bytes != ddt_header.
length)
204 FATAL(
"Error decompressing block, should be {0} bytes but got {1} bytes., stopping...");
215 *found_user_data_ddt =
true;
223 TRACE(
"Cannot allocate memory for DDT, continuing...");
229 if(read_bytes != ddt_header.
entries *
sizeof(uint64_t))
232 TRACE(
"Could not read deduplication table, continuing...");
237 *found_user_data_ddt =
true;
241 TRACE(
"Found unknown compression type %d, continuing...", ddt_header.
compression);
242 *found_user_data_ddt =
false;
254 FATAL(
"Compressed DDT payload too small (%" PRIu64
") for LZMA properties.", ddt_header.
cmpLength);
260 cmp_data = (uint8_t *)malloc(lzma_size);
263 TRACE(
"Cannot allocate memory for DDT, continuing...");
267 cd_ddt = (uint32_t *)malloc(ddt_header.
length);
270 TRACE(
"Cannot allocate memory for DDT, continuing...");
278 TRACE(
"Could not read LZMA properties, continuing...");
284 read_bytes = fread(cmp_data, 1, lzma_size, ctx->
imageStream);
285 if(read_bytes != lzma_size)
287 TRACE(
"Could not read compressed block, continuing...");
293 read_bytes = ddt_header.
length;
294 TRACE(
"Decompressing block of size %zu bytes", ddt_header.
length);
300 FATAL(
"Got error %d from LZMA, stopping...", error_no);
306 if(read_bytes != ddt_header.
length)
308 FATAL(
"Error decompressing block, should be {0} bytes but got {1} bytes., stopping...");
328 cd_ddt = (uint32_t *)malloc(ddt_header.
entries *
sizeof(uint32_t));
332 TRACE(
"Cannot allocate memory for deduplication table.");
336 read_bytes = fread(cd_ddt, 1, ddt_header.
entries *
sizeof(uint32_t), ctx->
imageStream);
338 if(read_bytes != ddt_header.
entries *
sizeof(uint32_t))
341 TRACE(
"Could not read deduplication table, continuing...");
354 TRACE(
"Found unknown compression type %d, continuing...", ddt_header.
compression);
359 TRACE(
"Exiting process_ddt_v1() = AARUF_STATUS_OK");
406 uint64_t *block_offset, uint8_t *sector_status)
408 TRACE(
"Entering decode_ddt_entry_v1(%p, %" PRIu64
", %p, %p, %p)", ctx, sector_address, offset, block_offset,
414 FATAL(
"Invalid context or image stream.");
415 TRACE(
"Exiting decode_ddt_entry_v1() = AARUF_ERROR_NOT_AARUFORMAT");
421 FATAL(
"User data DDT not loaded.");
422 TRACE(
"Exiting decode_ddt_entry_v1() = AARUF_ERROR_NOT_AARUFORMAT");
428 FATAL(
"Invalid DDT shift value %u", ctx->
shift);
429 TRACE(
"Exiting decode_ddt_entry_v1() = AARUF_ERROR_INCORRECT_DATA_SIZE");
433 const uint64_t ddt_entry = ctx->
user_data_ddt[sector_address];
434 const uint64_t offset_mask64 = (UINT64_C(1) << ctx->
shift) - UINT64_C(1);
435 *offset = ddt_entry & offset_mask64;
436 *block_offset = ddt_entry >> ctx->
shift;
444 TRACE(
"Exiting decode_ddt_entry_v1(%p, %" PRIu64
", %llu, %llu, %d) = AARUF_STATUS_OK", ctx, sector_address,
445 *offset, *block_offset, *sector_status);
#define LZMA_PROPERTIES_LENGTH
Size in bytes of the fixed LZMA properties header (lc/lp/pb + dictionary size).
int32_t decode_ddt_entry_v1(aaruformat_context *ctx, const uint64_t sector_address, uint64_t *offset, uint64_t *block_offset, uint8_t *sector_status)
Decodes a DDT v1 entry for a given sector address.
int32_t process_ddt_v1(aaruformat_context *ctx, IndexEntry *entry, bool *found_user_data_ddt)
Processes a DDT v1 block from the image stream.
int32_t aaruf_lzma_decode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer, size_t *src_size, const uint8_t *props, size_t props_size)
Decodes an LZMA-compressed buffer.
@ SectorStatusDumped
Sector(s) successfully dumped without error.
@ SectorStatusNotDumped
Sector(s) not yet acquired during image dumping.
@ CdSectorPrefixCorrected
Compact Disc sector prefix (sync, header) corrected-only stored.
@ CdSectorSuffixCorrected
Compact Disc sector suffix (EDC, ECC P, ECC Q) corrected-only stored.
@ UserData
User (main) data.
Public error and status code definitions for libaaruformat.
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
#define AARUF_ERROR_CANNOT_READ_BLOCK
Generic block read failure (seek/read error).
#define AARUF_ERROR_INCORRECT_DATA_SIZE
Data size does not match expected size.
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
#define AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK
Decompression routine failed or size mismatch.
uint64_t ImageSize
Size of the image payload in bytes (excludes headers/metadata)
uint64_t Sectors
Total count of addressable logical sectors/blocks.
Single index entry describing a block's type, (optional) data classification, and file offset.
uint64_t offset
Absolute byte offset in the image where the referenced block header begins.
uint16_t dataType
Data classification (value from DataType) or unused for untyped blocks.
Master context representing an open or in‑creation Aaru image.
uint64_t * user_data_ddt
Legacy flat DDT pointer (NULL when using v2 mini/big arrays).
uint8_t shift
Legacy overall shift (deprecated by data_shift/table_shift).
uint32_t * sector_suffix_ddt
Legacy CD sector suffix DDT.
bool in_memory_ddt
True if primary (and possibly secondary) DDT loaded.
int ddt_version
DDT version in use (1=legacy, 2=v2 hierarchical).
FILE * imageStream
Underlying FILE* stream (binary mode).
ImageInfo image_info
Exposed high-level image info summary.
uint32_t * sector_prefix_ddt
Legacy CD sector prefix DDT (deprecated by *2).