88 TRACE(
"Entering process_ddt_v1(%p, %p, %d)", ctx, entry, *found_user_data_ddt);
91 size_t read_bytes = 0;
93 uint8_t *cmp_data = NULL;
94 uint32_t *cd_ddt = NULL;
102 FATAL(
"Invalid context or image stream.");
104 TRACE(
"Exiting process_ddt_v1() = AARUF_ERROR_NOT_AARUFORMAT");
109 TRACE(
"Seeking to DDT block at position %" PRIu64, entry->
offset);
113 FATAL(
"Could not seek to %" PRIu64
" as indicated by index entry...", entry->
offset);
115 TRACE(
"Exiting process_ddt_v1() = AARUF_ERROR_CANNOT_READ_BLOCK");
120 TRACE(
"Reading DDT block header at position %" PRIu64, entry->
offset);
125 FATAL(
"Could not read block header at %" PRIu64
"", entry->
offset);
127 TRACE(
"Exiting process_ddt_v1() = AARUF_ERROR_CANNOT_READ_BLOCK");
131 *found_user_data_ddt =
true;
148 FATAL(
"Compressed DDT payload too small (%" PRIu64
") for LZMA properties.", ddt_header.
cmpLength);
154 cmp_data = (uint8_t *)malloc(lzma_size);
157 TRACE(
"Cannot allocate memory for DDT, continuing...");
164 TRACE(
"Cannot allocate memory for DDT, continuing...");
172 TRACE(
"Could not read LZMA properties, continuing...");
179 read_bytes = fread(cmp_data, 1, lzma_size, ctx->
imageStream);
180 if(read_bytes != lzma_size)
182 TRACE(
"Could not read compressed block, continuing...");
189 read_bytes = ddt_header.
length;
190 TRACE(
"Decompressing block of size %zu bytes", ddt_header.
length);
196 FATAL(
"Got error %d from LZMA, stopping...", error_no);
203 if(read_bytes != ddt_header.
length)
205 FATAL(
"Error decompressing block, should be {0} bytes but got {1} bytes., stopping...");
216 *found_user_data_ddt =
true;
220 cmp_data = (uint8_t *)malloc(ddt_header.
cmpLength);
223 TRACE(
"Cannot allocate memory for DDT, continuing...");
230 TRACE(
"Cannot allocate memory for DDT, continuing...");
238 TRACE(
"Could not read compressed block, continuing...");
247 if(read_bytes != ddt_header.
length)
249 FATAL(
"Error decompressing zstd DDT block, expected %zu got %zu", ddt_header.
length, read_bytes);
260 *found_user_data_ddt =
true;
268 TRACE(
"Cannot allocate memory for DDT, continuing...");
274 if(read_bytes != ddt_header.
entries *
sizeof(uint64_t))
277 TRACE(
"Could not read deduplication table, continuing...");
282 *found_user_data_ddt =
true;
286 TRACE(
"Found unknown compression type %d, continuing...", ddt_header.
compression);
287 *found_user_data_ddt =
false;
299 FATAL(
"Compressed DDT payload too small (%" PRIu64
") for LZMA properties.", ddt_header.
cmpLength);
305 cmp_data = (uint8_t *)malloc(lzma_size);
308 TRACE(
"Cannot allocate memory for DDT, continuing...");
312 cd_ddt = (uint32_t *)malloc(ddt_header.
length);
315 TRACE(
"Cannot allocate memory for DDT, continuing...");
323 TRACE(
"Could not read LZMA properties, continuing...");
329 read_bytes = fread(cmp_data, 1, lzma_size, ctx->
imageStream);
330 if(read_bytes != lzma_size)
332 TRACE(
"Could not read compressed block, continuing...");
338 read_bytes = ddt_header.
length;
339 TRACE(
"Decompressing block of size %zu bytes", ddt_header.
length);
345 FATAL(
"Got error %d from LZMA, stopping...", error_no);
351 if(read_bytes != ddt_header.
length)
353 FATAL(
"Error decompressing block, should be {0} bytes but got {1} bytes., stopping...");
371 cmp_data = (uint8_t *)malloc(ddt_header.
cmpLength);
374 TRACE(
"Cannot allocate memory for DDT, continuing...");
378 cd_ddt = (uint32_t *)malloc(ddt_header.
length);
381 TRACE(
"Cannot allocate memory for DDT, continuing...");
389 TRACE(
"Could not read compressed block, continuing...");
397 if(read_bytes != ddt_header.
length)
399 FATAL(
"Error decompressing zstd DDT block, expected %zu got %zu", ddt_header.
length, read_bytes);
419 cd_ddt = (uint32_t *)malloc(ddt_header.
entries *
sizeof(uint32_t));
423 TRACE(
"Cannot allocate memory for deduplication table.");
427 read_bytes = fread(cd_ddt, 1, ddt_header.
entries *
sizeof(uint32_t), ctx->
imageStream);
429 if(read_bytes != ddt_header.
entries *
sizeof(uint32_t))
432 TRACE(
"Could not read deduplication table, continuing...");
445 TRACE(
"Found unknown compression type %d, continuing...", ddt_header.
compression);
450 TRACE(
"Exiting process_ddt_v1() = AARUF_STATUS_OK");
497 uint64_t *block_offset, uint8_t *sector_status)
499 TRACE(
"Entering decode_ddt_entry_v1(%p, %" PRIu64
", %p, %p, %p)", ctx, sector_address, offset, block_offset,
505 FATAL(
"Invalid context or image stream.");
506 TRACE(
"Exiting decode_ddt_entry_v1() = AARUF_ERROR_NOT_AARUFORMAT");
512 FATAL(
"User data DDT not loaded.");
513 TRACE(
"Exiting decode_ddt_entry_v1() = AARUF_ERROR_NOT_AARUFORMAT");
519 FATAL(
"Invalid DDT shift value %u", ctx->
shift);
520 TRACE(
"Exiting decode_ddt_entry_v1() = AARUF_ERROR_INCORRECT_DATA_SIZE");
524 const uint64_t ddt_entry = ctx->
user_data_ddt[sector_address];
525 const uint64_t offset_mask64 = (UINT64_C(1) << ctx->
shift) - UINT64_C(1);
526 *offset = ddt_entry & offset_mask64;
527 *block_offset = ddt_entry >> ctx->
shift;
535 TRACE(
"Exiting decode_ddt_entry_v1(%p, %" PRIu64
", %llu, %llu, %d) = AARUF_STATUS_OK", ctx, sector_address,
536 *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.
size_t aaruf_zstd_decode_buffer(uint8_t *dst_buffer, size_t dst_size, const uint8_t *src_buffer, size_t src_size)
Decodes a Zstandard-compressed buffer.
@ SectorStatusDumped
Sector(s) successfully dumped without error.
@ SectorStatusNotDumped
Sector(s) not yet acquired during image dumping.
@ kDataTypeCdSectorSuffixCorrected
Compact Disc sector suffix (EDC, ECC P, ECC Q) corrected-only stored.
@ kDataTypeUserData
User (main) data.
@ kDataTypeCdSectorPrefixCorrected
Compact Disc sector prefix (sync, header) corrected-only stored.
@ kCompressionLzma
LZMA compression.
@ kCompressionNone
Not compressed.
@ kCompressionZstd
Zstandard compression.
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.
static int aaruf_fseek(FILE *stream, aaru_off_t offset, int origin)
static aaru_off_t aaruf_ftell(FILE *stream)
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).