83 TRACE(
"Entering process_index_v2(%p)", ctx);
85 UT_array *index_entries = NULL;
88 if(ctx == NULL || ctx->
imageStream == NULL) {
return NULL; }
91 const UT_icd index_entry_icd = {
sizeof(
IndexEntry), NULL, NULL, NULL};
93 utarray_new(index_entries, &index_entry_icd);
95 if(index_entries == NULL)
97 FATAL(
"Could not allocate memory for index entries array.");
98 TRACE(
"Exiting process_index_v2() = NULL");
107 utarray_free(index_entries);
109 TRACE(
"Exiting process_index_v2() = NULL");
116 utarray_free(index_entries);
118 TRACE(
"Exiting process_index_v2() = NULL");
125 FATAL(
"Incorrect index identifier.");
126 utarray_free(index_entries);
128 TRACE(
"Exiting process_index_v2() = NULL");
132 for(uint64_t i = 0; i < idx_header.
entries; i++)
137 utarray_free(index_entries);
139 TRACE(
"Exiting process_index_v2() = NULL");
143 utarray_push_back(index_entries, &entry);
146 TRACE(
"Read %llu index entries from index block at position %llu", (
unsigned long long)idx_header.
entries,
148 return index_entries;
229 TRACE(
"Entering verify_index_v2(%p)", ctx);
231 size_t read_bytes = 0;
238 FATAL(
"Invalid context or image stream.");
240 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_AARUFORMAT");
250 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_HEADER");
260 FATAL(
"Could not read index header.");
262 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_HEADER");
268 FATAL(
"Incorrect index identifier.");
270 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
278 FATAL(
"Index entry count %llu is too large to process.", (
unsigned long long)index_header.
entries);
280 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
288 index_entries = malloc(entries_size);
290 if(index_entries == NULL)
292 FATAL(
"Cannot allocate memory for index entries.");
294 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
298 read_bytes = fread(index_entries, 1, entries_size, ctx->
imageStream);
300 if(read_bytes != entries_size)
302 FATAL(
"Could not read index entries.");
305 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
314 FATAL(
"Cannot initialize CRC64 context.");
317 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
323 const uint8_t *cursor = (
const uint8_t *)index_entries;
324 size_t remaining = entries_size;
328 const uint32_t chunk = remaining > UINT32_MAX ? UINT32_MAX : (uint32_t)remaining;
332 FATAL(
"Failed to update index CRC.");
336 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
347 FATAL(
"Failed to finalize index CRC.");
351 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
360 if(crc64 != index_header.
crc64)
362 FATAL(
"Expected index CRC 0x%16llX but got 0x%16llX.", index_header.
crc64, crc64);
365 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_INVALID_BLOCK_CRC");
371 TRACE(
"Exiting verify_index_v2() = 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.
@ IndexBlock2
Block containing the index v2.
#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.
UT_array * process_index_v2(aaruformat_context *ctx)
Processes an index block (version 2) from the image stream.
int32_t verify_index_v2(aaruformat_context *ctx)
Verifies the integrity of an index block (version 2) in the image stream.
Single index entry describing a block's type, (optional) data classification, and file offset.
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).