100 TRACE(
"Entering process_index_v3(%p)", ctx);
102 UT_array *index_entries = NULL;
105 if(ctx == NULL || ctx->
imageStream == NULL)
return NULL;
108 const UT_icd index_entry_icd = {
sizeof(
IndexEntry), NULL, NULL, NULL};
110 utarray_new(index_entries, &index_entry_icd);
112 if(index_entries == NULL)
114 FATAL(
"Could not allocate memory for index entries array.");
115 TRACE(
"Exiting process_index_v3() = NULL");
124 utarray_free(index_entries);
126 TRACE(
"Exiting process_index_v3() = NULL");
133 utarray_free(index_entries);
135 TRACE(
"Exiting process_index_v3() = NULL");
142 FATAL(
"Incorrect index identifier.");
143 utarray_free(index_entries);
145 TRACE(
"Exiting process_index_v3() = NULL");
149 for(uint64_t i = 0; i < idx_header.
entries; i++)
154 utarray_free(index_entries);
156 TRACE(
"Exiting process_index_v3() = NULL");
165 utarray_free(index_entries);
167 TRACE(
"Exiting process_index_v3() = NULL");
172 utarray_push_back(index_entries, &entry);
175 TRACE(
"Read %llu index entries from index block at position %llu", (
unsigned long long)idx_header.
entries,
177 return index_entries;
249 TRACE(
"Entering add_subindex_entries(%p, %p, %p)", ctx, index_entries, subindex_entry);
254 if(ctx == NULL || ctx->
imageStream == NULL || index_entries == NULL || subindex_entry == NULL)
256 TRACE(
"Exiting add_subindex_entries() = false (invalid parameters)");
263 FATAL(
"Could not seek to subindex header at %llu.", (
unsigned long long)subindex_entry->
offset);
264 TRACE(
"Exiting add_subindex_entries() = false (seek failed)");
271 FATAL(
"Could not read subindex header at %llu.", (
unsigned long long)subindex_entry->
offset);
272 TRACE(
"Exiting add_subindex_entries() = false (header read failed)");
279 FATAL(
"Incorrect subindex identifier.");
281 TRACE(
"Exiting add_subindex_entries() = false (invalid identifier)");
287 FATAL(
"Subindex entry count %llu is too large to process.", (
unsigned long long)subindex_header.
entries);
288 TRACE(
"Exiting add_subindex_entries() = false (entry count overflow)");
293 for(uint64_t i = 0; i < subindex_header.
entries; i++)
297 FATAL(
"Could not read subindex entry %llu at %llu.", (
unsigned long long)i,
298 (
unsigned long long)subindex_entry->
offset);
299 TRACE(
"Exiting add_subindex_entries() = false (entry read failed)");
307 TRACE(
"Exiting add_subindex_entries() = false (nested subindex failed)");
312 utarray_push_back(index_entries, &entry);
315 TRACE(
"Exiting add_subindex_entries() = true after appending %llu entries",
316 (
unsigned long long)subindex_header.
entries);
410 TRACE(
"Entering verify_index_v3(%p)", ctx);
412 size_t read_bytes = 0;
419 FATAL(
"Invalid context or image stream.");
421 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_NOT_AARUFORMAT");
431 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_CANNOT_READ_HEADER");
441 FATAL(
"Could not read index header.");
443 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_CANNOT_READ_HEADER");
449 FATAL(
"Incorrect index identifier.");
451 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_CANNOT_READ_INDEX");
459 FATAL(
"Index entry count %llu is too large to process.", (
unsigned long long)index_header.
entries);
461 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
469 index_entries = malloc(entries_size);
471 if(index_entries == NULL)
473 FATAL(
"Cannot allocate memory for index entries.");
475 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
479 read_bytes = fread(index_entries, 1, entries_size, ctx->
imageStream);
481 if(read_bytes != entries_size)
483 FATAL(
"Could not read index entries.");
486 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_CANNOT_READ_INDEX");
495 FATAL(
"Cannot initialize CRC64 context.");
498 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
504 const uint8_t *cursor = (
const uint8_t *)index_entries;
505 size_t remaining = entries_size;
509 const uint32_t chunk = remaining > UINT32_MAX ? UINT32_MAX : (uint32_t)remaining;
513 FATAL(
"Failed to update index CRC.");
517 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_CANNOT_READ_INDEX");
528 FATAL(
"Failed to finalize index CRC.");
532 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_CANNOT_READ_INDEX");
541 if(crc64 != index_header.
crc64)
543 FATAL(
"Expected index CRC 0x%16llX but got 0x%16llX.", index_header.
crc64, crc64);
546 TRACE(
"Exiting verify_index_v3() = AARUF_ERROR_INVALID_BLOCK_CRC");
552 TRACE(
"Exiting verify_index_v3() = AARUF_OK");
#define AARUF_VERSION_V1
First on‑disk version (C# implementation).
int aaruf_crc64_update(crc64_ctx *ctx, const uint8_t *data, uint32_t len)
Updates the CRC64 context with new data.
void aaruf_crc64_free(crc64_ctx *ctx)
Frees a CRC64 context.
crc64_ctx * aaruf_crc64_init()
Initializes a CRC64 context.
int aaruf_crc64_final(crc64_ctx *ctx, uint64_t *crc)
Computes the final CRC64 value from the context.
@ IndexBlock3
Block containing the index v3.
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
#define AARUF_ERROR_CANNOT_READ_HEADER
Failed to read container header.
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
#define AARUF_ERROR_INVALID_BLOCK_CRC
CRC64 mismatch indicating corruption.
#define AARUF_ERROR_CANNOT_READ_INDEX
Index block unreadable / truncated / bad identifier.
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
static bool add_subindex_entries(aaruformat_context *ctx, UT_array *index_entries, const IndexEntry *subindex_entry)
Adds entries from a subindex block (version 3) to the main index entries array.
int32_t verify_index_v3(aaruformat_context *ctx)
Verifies the integrity of an index block (version 3) in the image stream.
UT_array * process_index_v3(aaruformat_context *ctx)
Processes an index block (version 3) from the image stream.
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.
Master context representing an open or in‑creation Aaru image.
AaruHeaderV2 header
Parsed container header (v2).
FILE * imageStream
Underlying FILE* stream (binary mode).
Minimal ECMA-182 CRC64 incremental state container (running value only).