84 TRACE(
"Entering process_index_v2(%p)", ctx);
86 UT_array *index_entries = NULL;
89 if(ctx == NULL || ctx->
imageStream == NULL) {
return NULL; }
92 const UT_icd index_entry_icd = {
sizeof(
IndexEntry), NULL, NULL, NULL};
94 utarray_new(index_entries, &index_entry_icd);
96 if(index_entries == NULL)
98 FATAL(
"Could not allocate memory for index entries array.");
99 TRACE(
"Exiting process_index_v2() = NULL");
108 utarray_free(index_entries);
110 TRACE(
"Exiting process_index_v2() = NULL");
117 utarray_free(index_entries);
119 TRACE(
"Exiting process_index_v2() = NULL");
126 FATAL(
"Incorrect index identifier.");
127 utarray_free(index_entries);
129 TRACE(
"Exiting process_index_v2() = NULL");
133 for(uint64_t i = 0; i < idx_header.
entries; i++)
138 utarray_free(index_entries);
140 TRACE(
"Exiting process_index_v2() = NULL");
144 utarray_push_back(index_entries, &entry);
147 TRACE(
"Read %llu index entries from index block at position %llu", (
unsigned long long)idx_header.
entries,
149 return index_entries;
230 TRACE(
"Entering verify_index_v2(%p)", ctx);
232 size_t read_bytes = 0;
239 FATAL(
"Invalid context or image stream.");
241 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_AARUFORMAT");
251 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_HEADER");
261 FATAL(
"Could not read index header.");
263 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_HEADER");
269 FATAL(
"Incorrect index identifier.");
271 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
279 FATAL(
"Index entry count %llu is too large to process.", (
unsigned long long)index_header.
entries);
281 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
289 index_entries = malloc(entries_size);
291 if(index_entries == NULL)
293 FATAL(
"Cannot allocate memory for index entries.");
295 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
299 read_bytes = fread(index_entries, 1, entries_size, ctx->
imageStream);
301 if(read_bytes != entries_size)
303 FATAL(
"Could not read index entries.");
306 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
315 FATAL(
"Cannot initialize CRC64 context.");
318 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
324 const uint8_t *cursor = (
const uint8_t *)index_entries;
325 size_t remaining = entries_size;
329 const uint32_t chunk = remaining > UINT32_MAX ? UINT32_MAX : (uint32_t)remaining;
333 FATAL(
"Failed to update index CRC.");
337 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
348 FATAL(
"Failed to finalize index CRC.");
352 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_CANNOT_READ_INDEX");
361 if(crc64 != index_header.
crc64)
363 FATAL(
"Expected index CRC 0x%16llX but got 0x%16llX.", index_header.
crc64, crc64);
366 TRACE(
"Exiting verify_index_v2() = AARUF_ERROR_INVALID_BLOCK_CRC");
372 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.
static int aaruf_fseek(FILE *stream, aaru_off_t offset, int origin)
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).