73 TRACE(
"Entering process_data_block(%p, %p)", ctx, entry);
76 size_t read_bytes = 0;
78 uint8_t *cmp_data = NULL;
79 uint8_t *cst_data = NULL;
86 if(ctx == NULL || entry == NULL || ctx->
imageStream == NULL)
88 FATAL(
"Invalid context or image stream.");
96 FATAL(
"Could not seek to %" PRIu64
" as indicated by index entry...", entry->
offset);
106 TRACE(
"NoData block found, skipping");
107 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
111 TRACE(
"Reading block header at position %" PRIu64, entry->
offset);
116 FATAL(
"Could not read block header at %" PRIu64, entry->
offset);
118 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
129 TRACE(
"Setting sector size to %" PRIu64
" bytes", block_header.
sectorSize);
133 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
139 TRACE(
"Incorrect identifier for data block at position %" PRIu64, entry->
offset);
141 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
147 TRACE(
"Expected block with data type %4.4s at position %" PRIu64
" but found data type %4.4s",
150 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
154 TRACE(
"Found data block with type %4.4s at position %" PRIu64, (
char *)&entry->
blockType, entry->
offset);
161 TRACE(
"Invalid compression type %u for block with data type %u, continuing...", block_header.
compression,
164 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
170 TRACE(
"Compressed block length %" PRIu32
" too small for LZMA properties, continuing...",
172 TRACE(
"Exiting process_data_block() = AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK");
178 cmp_data = (lzma_size == 0) ? NULL : (uint8_t *)malloc(lzma_size);
179 if(lzma_size != 0 && cmp_data == NULL)
181 TRACE(
"Cannot allocate memory for block, continuing...");
183 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
187 if(block_header.
length != 0)
189 data = (uint8_t *)malloc(block_header.
length);
192 TRACE(
"Cannot allocate memory for block, continuing...");
195 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
205 TRACE(
"Could not read LZMA properties, continuing...");
209 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
215 read_bytes = fread(cmp_data, 1, lzma_size, ctx->
imageStream);
216 if(read_bytes != lzma_size)
218 TRACE(
"Could not read compressed block, continuing...");
222 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
227 if(block_header.
length != 0)
229 read_bytes = block_header.
length;
235 TRACE(
"Got error %d from LZMA, continuing...", error_no);
239 TRACE(
"Exiting process_data_block() = AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK");
243 if(read_bytes != block_header.
length)
245 TRACE(
"Error decompressing block, expected %" PRIu32
" bytes but got %zu bytes, continuing...",
246 block_header.
length, read_bytes);
250 TRACE(
"Exiting process_data_block() = AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK");
254 else if(lzma_size != 0)
256 TRACE(
"Compressed payload present for zero-length block, continuing...");
259 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
265 cst_data = (uint8_t *)malloc(block_header.
length);
268 TRACE(
"Cannot allocate memory for block, continuing...");
272 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
286 if(block_header.
length != 0)
288 data = (uint8_t *)malloc(block_header.
length);
291 TRACE(
"Cannot allocate memory for block, continuing...");
293 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
302 if(block_header.
length != 0 && read_bytes != block_header.
length)
305 TRACE(
"Could not read block, continuing...");
307 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
313 TRACE(
"Found unknown compression type %d, continuing...", block_header.
compression);
315 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
319 if(block_header.
length > 0)
326 if(crc64 != block_header.
crc64)
328 TRACE(
"Incorrect CRC found: 0x%" PRIx64
" found, expected 0x%" PRIx64
", continuing...", crc64,
332 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
406 if(media_tag == NULL)
408 TRACE(
"Cannot allocate memory for media tag entry.");
416 media_tag->
data = data;
419 HASH_REPLACE_INT(ctx->
mediaTags, type, media_tag, old_media_tag);
421 if(old_media_tag != NULL)
423 TRACE(
"Replaced media tag with type %d", old_media_tag->
type);
424 free(old_media_tag->
data);
426 old_media_tag = NULL;
432 TRACE(
"Exiting process_data_block() = AARUF_STATUS_OK");
#define LZMA_PROPERTIES_LENGTH
Size in bytes of the fixed LZMA properties header (lc/lp/pb + dictionary size).
#define AARUF_VERSION_V1
First on‑disk version (C# implementation).
int32_t process_data_block(aaruformat_context *ctx, IndexEntry *entry)
Processes a data block from the image stream.
uint64_t aaruf_crc64_data(const uint8_t *data, uint32_t len)
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.
int32_t aaruf_get_media_tag_type_for_datatype(int32_t type)
Converts an image data type to an Aaru media tag type.
int32_t aaruf_cst_untransform(const uint8_t *sequential, uint8_t *interleaved, size_t length)
Reverses the CST (Claunia's Subchannel Transform) transformation from sequential to interleaved data.
@ CdSectorSubchannel
Compact Disc subchannel data.
@ AppleProfileTag
Apple Profile (20‑byte) tag.
@ DvdSectorIed
DVD ID Error Detection Code (IED)
@ CdSectorPrefixCorrected
Compact Disc sector prefix (sync, header) corrected-only stored.
@ DvdSectorCprMai
DVD Copyright Management Information (CPR_MAI)
@ AppleSonyTag
Apple Sony (12‑byte) tag.
@ CdSectorPrefix
Compact Disc sector prefix (sync, header).
@ CdSectorSuffixCorrected
Compact Disc sector suffix (EDC, ECC P, ECC Q) corrected-only stored.
@ PriamDataTowerTag
Priam Data Tower (24‑byte) tag.
@ UserData
User (main) data.
@ DvdSectorEdc
DVD Error Detection Code (EDC)
@ DvdSectorTitleKeyDecrypted
Decrypted DVD Title Key.
@ DvdSectorId
DVD Identification Data (ID)
@ CdSectorSuffix
Compact Disc sector suffix (EDC, ECC P, ECC Q).
@ CompactDiscMode2Subheader
Compact Disc MODE 2 subheader.
@ LzmaClauniaSubchannelTransform
LZMA applied to Claunia Subchannel Transform processed data.
#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_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
#define AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK
Decompression routine failed or size mismatch.
uint32_t SectorSize
Size of each logical sector in bytes (512, 2048, 2352, 4096, etc.)
uint64_t ImageSize
Size of the image payload in bytes (excludes headers/metadata)
Single index entry describing a block's type, (optional) data classification, and file offset.
uint32_t blockType
Block identifier of the referenced block (value from BlockType).
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.
uint8_t * sector_cpr_mai
DVD sector CPR_MAI (6 bytes) if present.
uint8_t * sector_prefix_corrected
Corrected variant (post error correction) if stored.
uint8_t * sector_ied
DVD sector IED (2 bytes) if present.
uint8_t * sector_prefix
Raw per-sector prefix (e.g., sync+header) uncorrected.
uint8_t * sector_edc
DVD sector EDC (4 bytes) if present.
uint8_t * sector_suffix
Raw per-sector suffix (EDC/ECC) uncorrected.
AaruHeaderV2 header
Parsed container header (v2).
mediaTagEntry * mediaTags
Hash table of extra media tags (uthash root).
uint8_t * sector_decrypted_title_key
DVD decrypted title key (5 bytes) if present.
uint8_t * sector_subchannel
Raw 96-byte subchannel (if captured).
FILE * imageStream
Underlying FILE* stream (binary mode).
uint8_t * mode2_subheaders
MODE2 Form1/Form2 8-byte subheaders (concatenated).
ImageInfo image_info
Exposed high-level image info summary.
uint8_t * sector_id
DVD sector ID (4 bytes) if present.
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
uint8_t * sector_suffix_corrected
Corrected suffix if stored separately.
Hash table entry for an arbitrary media tag (e.g., proprietary drive/medium descriptor).
uint8_t * data
Tag data blob (opaque to library core); length bytes long.
int32_t type
Numeric type identifier.
uint32_t length
Length in bytes of data.