libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
open.c
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2025 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <errno.h>
20#include <inttypes.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include <aaruformat.h>
26
27#include "internal.h"
28#include "log.h"
29#include "utarray.h"
30
31 static void cleanup_open_failure(aaruformat_context *ctx)
32{
33 if(ctx == NULL) return;
34
35 if(ctx->imageStream != NULL)
36 {
37 fclose(ctx->imageStream);
38 ctx->imageStream = NULL;
39 }
40
41 free(ctx->readableSectorTags);
42 ctx->readableSectorTags = NULL;
43
44 free(ctx);
45}
46
223 AARU_EXPORT void AARU_CALL *aaruf_open(const char *filepath, const bool resume_mode,
224 const char *options) // NOLINT(readability-function-size)
225{
226 aaruformat_context *ctx = NULL;
227 int error_no = 0;
228 size_t read_bytes = 0;
229 long pos = 0;
230 int i = 0;
231 uint32_t signature = 0;
232 UT_array *index_entries = NULL;
233
234#ifdef USE_SLOG
235#include "slog.h"
236
237 slog_init("aaruformat.log", SLOG_FLAGS_ALL, 0);
238#endif
239
240 TRACE("Logging initialized");
241
242 TRACE("Entering aaruf_open(%s)", filepath);
243
244 TRACE("Allocating memory for context");
245 ctx = (aaruformat_context *)malloc(sizeof(aaruformat_context));
246
247 if(ctx == NULL)
248 {
249 FATAL("Not enough memory to create context");
250 errno = AARUF_ERROR_NOT_ENOUGH_MEMORY;
251
252 TRACE("Exiting aaruf_open() = NULL");
253 return NULL;
254 }
255
256 memset(ctx, 0, sizeof(aaruformat_context));
257
258 TRACE("Opening file %s", filepath);
259 if(resume_mode)
260 ctx->imageStream = fopen(filepath, "a+b");
261 else
262 ctx->imageStream = fopen(filepath, "rb");
263
264 if(ctx->imageStream == NULL)
265 {
266 FATAL("Error %d opening file %s for reading", errno, filepath);
267 error_no = errno;
268 cleanup_open_failure(ctx);
269 errno = error_no;
270
271 TRACE("Exiting aaruf_open() = NULL");
272 return NULL;
273 }
274
275 TRACE("Reading header at position 0");
276 fseek(ctx->imageStream, 0, SEEK_SET);
277 read_bytes = fread(&ctx->header, 1, sizeof(AaruHeader), ctx->imageStream);
278
279 if(read_bytes != sizeof(AaruHeader))
280 {
281 FATAL("Could not read header");
282 cleanup_open_failure(ctx);
283 errno = AARUF_ERROR_FILE_TOO_SMALL;
284
285 TRACE("Exiting aaruf_open() = NULL");
286 return NULL;
287 }
288
289 if(ctx->header.identifier != DIC_MAGIC && ctx->header.identifier != AARU_MAGIC)
290 {
291 FATAL("Incorrect identifier for AaruFormat file: %8.8s", (char *)&ctx->header.identifier);
292 cleanup_open_failure(ctx);
293 errno = AARUF_ERROR_NOT_AARUFORMAT;
294
295 TRACE("Exiting aaruf_open() = NULL");
296 return NULL;
297 }
298
299 if(ctx->header.imageMajorVersion < AARUF_VERSION_V2 && resume_mode)
300 {
301 TRACE("Cannot write to old images");
302 cleanup_open_failure(ctx);
303 errno = AARUF_ERROR_INCOMPATIBLE_VERSION;
304 TRACE("Exiting aaruf_open() = NULL");
305 return NULL;
306 }
307
308 // Read new header version
309 if(ctx->header.imageMajorVersion >= AARUF_VERSION_V2)
310 {
311 TRACE("Reading new header version at position 0");
312 fseek(ctx->imageStream, 0, SEEK_SET);
313 read_bytes = fread(&ctx->header, 1, sizeof(AaruHeaderV2), ctx->imageStream);
314
315 if(read_bytes != sizeof(AaruHeaderV2))
316 {
317 cleanup_open_failure(ctx);
318 errno = AARUF_ERROR_FILE_TOO_SMALL;
319
320 return NULL;
321 }
322 }
323
324 if(ctx->header.imageMajorVersion > AARUF_VERSION)
325 {
326 FATAL("Incompatible AaruFormat version %d.%d found, maximum supported is %d.%d", ctx->header.imageMajorVersion,
327 ctx->header.imageMinorVersion, AARUF_VERSION_V2, 0);
328 cleanup_open_failure(ctx);
329 errno = AARUF_ERROR_INCOMPATIBLE_VERSION;
330
331 TRACE("Exiting aaruf_open() = NULL");
332 return NULL;
333 }
334
335 TRACE("Opening image version %d.%d", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion);
336
337 TRACE("Allocating memory for readable sector tags bitmap");
338 ctx->readableSectorTags = (bool *)malloc(sizeof(bool) * MaxSectorTag);
339
340 if(ctx->readableSectorTags == NULL)
341 {
342 FATAL("Could not allocate memory for readable sector tags bitmap");
343 cleanup_open_failure(ctx);
344 errno = AARUF_ERROR_NOT_ENOUGH_MEMORY;
345
346 TRACE("Exiting aaruf_open() = NULL");
347 return NULL;
348 }
349
350 memset(ctx->readableSectorTags, 0, sizeof(bool) * MaxSectorTag);
351
352 TRACE("Setting up image info");
353
354 // Handle application name based on image version
355 memset(ctx->image_info.Application, 0, 64);
356
357 if(ctx->header.imageMajorVersion >= AARUF_VERSION_V2)
358 {
359 // Version 2+: application name is UTF-8, direct copy
360 TRACE("Converting application name (v2+): UTF-8 direct copy");
361 size_t copy_len = AARU_HEADER_APP_NAME_LEN < 63 ? AARU_HEADER_APP_NAME_LEN : 63;
362 memcpy(ctx->image_info.Application, ctx->header.application, copy_len);
363 ctx->image_info.Application[63] = '\0';
364 }
365 else
366 {
367 // Version 1: application name is UTF-16LE, convert by taking every other byte
368 TRACE("Converting application name (v1): UTF-16LE to ASCII");
369 int dest_idx = 0;
370 for(int j = 0; j < AARU_HEADER_APP_NAME_LEN && dest_idx < 63; j += 2)
371 // Take the low byte, skip the high byte (assuming it's 0x00 for ASCII)
372 if(ctx->header.application[j] != 0)
373 ctx->image_info.Application[dest_idx++] = ctx->header.application[j];
374 else
375 // Stop at null terminator
376 break;
377 ctx->image_info.Application[dest_idx] = '\0';
378 }
379
380 // Set application version string directly in the fixed-size array
381 memset(ctx->image_info.ApplicationVersion, 0, 32);
382 sprintf(ctx->image_info.ApplicationVersion, "%d.%d", ctx->header.applicationMajorVersion,
383 ctx->header.applicationMinorVersion);
384
385 // Set image version string directly in the fixed-size array
386 memset(ctx->image_info.Version, 0, 32);
387 sprintf(ctx->image_info.Version, "%d.%d", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion);
388
389 ctx->image_info.MediaType = ctx->header.mediaType;
390
391 // Read the index header
392 TRACE("Reading index header at position %" PRIu64, ctx->header.indexOffset);
393 pos = fseek(ctx->imageStream, ctx->header.indexOffset, SEEK_SET);
394 if(pos < 0)
395 {
396 cleanup_open_failure(ctx);
397 errno = AARUF_ERROR_CANNOT_READ_INDEX;
398
399 return NULL;
400 }
401
402 pos = ftell(ctx->imageStream);
403 if(pos != ctx->header.indexOffset)
404 {
405 cleanup_open_failure(ctx);
406 errno = AARUF_ERROR_CANNOT_READ_INDEX;
407
408 return NULL;
409 }
410
411 read_bytes = fread(&signature, 1, sizeof(uint32_t), ctx->imageStream);
412
413 if(read_bytes != sizeof(uint32_t) ||
414 (signature != IndexBlock && signature != IndexBlock2 && signature != IndexBlock3))
415 {
416 FATAL("Could not read index header or incorrect identifier %4.4s", (char *)&signature);
417 cleanup_open_failure(ctx);
418 errno = AARUF_ERROR_CANNOT_READ_INDEX;
419
420 TRACE("Exiting aaruf_open() = NULL");
421 return NULL;
422 }
423
424 if(signature == IndexBlock)
425 index_entries = process_index_v1(ctx);
426 else if(signature == IndexBlock2)
427 index_entries = process_index_v2(ctx);
428 else if(signature == IndexBlock3)
429 index_entries = process_index_v3(ctx);
430
431 if(index_entries == NULL)
432 {
433 FATAL("Could not process index.");
434 utarray_free(index_entries);
435 cleanup_open_failure(ctx);
436 errno = AARUF_ERROR_CANNOT_READ_INDEX;
437
438 TRACE("Exiting aaruf_open() = NULL");
439 return NULL;
440 }
441
442 TRACE("Index at %" PRIu64 " contains %d entries", ctx->header.indexOffset, utarray_len(index_entries));
443
444 for(i = 0; i < utarray_len(index_entries); i++)
445 {
446 IndexEntry *entry = utarray_eltptr(index_entries, i);
447 TRACE("Block type %4.4s with data type %d is indexed to be at %" PRIu64 "", (char *)&entry->blockType,
448 entry->dataType, entry->offset);
449 }
450
451 bool found_user_data_ddt = false;
452 ctx->image_info.ImageSize = 0;
453 for(i = 0; i < utarray_len(index_entries); i++)
454 {
455 IndexEntry *entry = utarray_eltptr(index_entries, i);
456 pos = fseek(ctx->imageStream, entry->offset, SEEK_SET);
457
458 if(pos < 0 || ftell(ctx->imageStream) != entry->offset)
459 {
460 TRACE("Could not seek to %" PRIu64 " as indicated by index entry %d, continuing...", entry->offset, i);
461
462 continue;
463 }
464
465 TRACE("Processing block type %4.4s with data type %d at position %" PRIu64 "", (char *)&entry->blockType,
466 entry->dataType, entry->offset);
467 switch(entry->blockType)
468 {
469 case DataBlock:
470 error_no = process_data_block(ctx, entry);
471
472 if(error_no != AARUF_STATUS_OK)
473 {
474 utarray_free(index_entries);
475 cleanup_open_failure(ctx);
476 errno = error_no;
477
478 return NULL;
479 }
480
481 break;
482
483 case DeDuplicationTable:
484 error_no = process_ddt_v1(ctx, entry, &found_user_data_ddt);
485
486 if(error_no != AARUF_STATUS_OK)
487 {
488 utarray_free(index_entries);
489 cleanup_open_failure(ctx);
490 errno = error_no;
491
492 return NULL;
493 }
494
495 break;
496 case DeDuplicationTable2:
497 error_no = process_ddt_v2(ctx, entry, &found_user_data_ddt);
498
499 if(error_no != AARUF_STATUS_OK)
500 {
501 utarray_free(index_entries);
502 cleanup_open_failure(ctx);
503 errno = error_no;
504
505 return NULL;
506 }
507
508 break;
509 case GeometryBlock:
510 process_geometry_block(ctx, entry);
511
512 break;
513 case MetadataBlock:
514 process_metadata_block(ctx, entry);
515
516 break;
517 case TracksBlock:
518 process_tracks_block(ctx, entry);
519
520 break;
521 case CicmBlock:
522 process_cicm_block(ctx, entry);
523
524 break;
525 case AaruMetadataJsonBlock:
526 process_aaru_metadata_json_block(ctx, entry);
527
528 break;
529 // Dump hardware block
530 case DumpHardwareBlock:
531 process_dumphw_block(ctx, entry);
532
533 break;
534 case ChecksumBlock:
535 process_checksum_block(ctx, entry);
536
537 break;
538 case TapeFileBlock:
539 process_tape_files_block(ctx, entry);
540
541 break;
542 case TapePartitionBlock:
543 process_tape_partitions_block(ctx, entry);
544
545 break;
546 default:
547 TRACE("Unhandled block type %4.4s with data type %d is indexed to be at %" PRIu64 "",
548 (char *)&entry->blockType, entry->dataType, entry->offset);
549 break;
550 }
551 }
552
553 ctx->index_entries = index_entries;
554
555 if(!found_user_data_ddt)
556 {
557 FATAL("Could not find user data deduplication table, aborting...");
558 aaruf_close(ctx);
559
560 TRACE("Exiting aaruf_open() = NULL");
561 return NULL;
562 }
563
564 ctx->image_info.CreationTime = ctx->header.creationTime;
565 ctx->image_info.LastModificationTime = ctx->header.lastWrittenTime;
566 ctx->image_info.MetadataMediaType = aaruf_get_xml_mediatype(ctx->header.mediaType);
567
568 if(ctx->geometry_block.identifier != GeometryBlock && ctx->image_info.MetadataMediaType == BlockMedia)
569 {
570 ctx->cylinders = (uint32_t)(ctx->image_info.Sectors / 16 / 63);
571 ctx->heads = 16;
572 ctx->sectors_per_track = 63;
573 }
574
575 // Initialize caches
576 TRACE("Initializing caches");
577 ctx->block_header_cache.cache = NULL;
578 ctx->block_cache.cache = NULL;
579
580 const uint64_t cache_divisor = (uint64_t)ctx->image_info.SectorSize * (1ULL << ctx->shift);
581 if(cache_divisor == 0)
582 {
583 ctx->block_header_cache.max_items = 0;
584 ctx->block_cache.max_items = 0;
585 }
586 else
587 {
588 ctx->block_header_cache.max_items = MAX_CACHE_SIZE / cache_divisor;
589 ctx->block_cache.max_items = ctx->block_header_cache.max_items;
590 }
591
592 // TODO: Cache tracks and sessions?
593
594 // Initialize ECC for Compact Disc
595 TRACE("Initializing ECC for Compact Disc");
596 ctx->ecc_cd_context = (CdEccContext *)aaruf_ecc_cd_init();
597
598 ctx->magic = AARU_MAGIC;
599 ctx->library_major_version = LIBAARUFORMAT_MAJOR_VERSION;
600 ctx->library_minor_version = LIBAARUFORMAT_MINOR_VERSION;
601
602 if(!resume_mode)
603 {
604 TRACE("Exiting aaruf_open() = %p", ctx);
605 return ctx;
606 }
607
608 // Parse the options
609 TRACE("Parsing options");
610 const aaru_options parsed_options = parse_options(options);
611
612 ctx->header.lastWrittenTime = get_filetime_uint64();
613 ctx->image_info.LastModificationTime = ctx->header.lastWrittenTime;
614
615 // Calculate aligned next block position
616 fseek(ctx->imageStream, 0, SEEK_END);
617 const uint64_t alignment_mask = (1ULL << ctx->user_data_ddt_header.blockAlignmentShift) - 1;
618 ctx->next_block_position = ftell(ctx->imageStream); // Start just after the header
619 ctx->next_block_position = ctx->next_block_position + alignment_mask & ~alignment_mask;
620
621 TRACE("Data blocks will start at position %" PRIu64, ctx->next_block_position);
622
623 // Position file pointer at the data start position
624 if(fseek(ctx->imageStream, ctx->next_block_position, SEEK_SET) != 0)
625 {
626 FATAL("Could not seek to data start position");
627 errno = AARUF_ERROR_CANNOT_CREATE_FILE;
628 TRACE("Exiting aaruf_open() = NULL");
629 cleanup_open_failure(ctx);
630 return NULL;
631 }
632
633 // Apply applicable options (we cannot change table or alignment options resuming)
634 ctx->compression_enabled = parsed_options.compress;
635 ctx->lzma_dict_size = parsed_options.dictionary;
636 ctx->deduplicate = parsed_options.deduplicate;
637 if(ctx->deduplicate)
638 ctx->sector_hash_map = create_map(ctx->user_data_ddt_header.blocks * 25 / 100); // 25% of total sectors
639
640 // Cannot checksum a resumed file
641 ctx->rewinded = true;
642
643 // Is writing
644 ctx->is_writing = true;
645
646 TRACE("Exiting aaruf_open() = %p", ctx);
647 // Return context
648 return ctx;
649}
aaruformat.h
LIBAARUFORMAT_MAJOR_VERSION
#define LIBAARUFORMAT_MAJOR_VERSION
Definition aaruformat.h:22
LIBAARUFORMAT_MINOR_VERSION
#define LIBAARUFORMAT_MINOR_VERSION
Definition aaruformat.h:23
DIC_MAGIC
#define DIC_MAGIC
Magic identifier for legacy DiscImageChef container (ASCII "DICMFRMT").
Definition consts.h:61
AARU_MAGIC
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
Definition consts.h:64
MAX_CACHE_SIZE
#define MAX_CACHE_SIZE
Maximum read cache size (bytes).
Definition consts.h:79
AARUF_VERSION_V2
#define AARUF_VERSION_V2
Second on‑disk version (C implementation).
Definition consts.h:75
AARUF_VERSION
#define AARUF_VERSION
Current image format major version (incompatible changes bump this).
Definition consts.h:68
AARU_CALL
#define AARU_CALL
Definition decls.h:45
aaruf_close
int aaruf_close(void *context)
Close an Aaru image context, flushing pending data structures and releasing resources.
Definition close.c:3997
AARU_EXPORT
#define AARU_EXPORT
Definition decls.h:54
aaruf_ecc_cd_init
void * aaruf_ecc_cd_init()
Initializes a Compact Disc ECC context.
Definition ecc_cd.c:35
aaruf_get_xml_mediatype
int32_t aaruf_get_xml_mediatype(int32_t type)
Definition helpers.c:347
IndexBlock3
@ IndexBlock3
Block containing the index v3.
Definition enums.h:147
ChecksumBlock
@ ChecksumBlock
Block containing contents checksums.
Definition enums.h:152
DataBlock
@ DataBlock
Block containing data.
Definition enums.h:141
TapePartitionBlock
@ TapePartitionBlock
Block containing list of partitions for a tape image.
Definition enums.h:158
IndexBlock2
@ IndexBlock2
Block containing the index v2.
Definition enums.h:146
GeometryBlock
@ GeometryBlock
Block containing logical geometry.
Definition enums.h:148
AaruMetadataJsonBlock
@ AaruMetadataJsonBlock
Block containing JSON version of Aaru Metadata.
Definition enums.h:159
CicmBlock
@ CicmBlock
Block containing CICM XML metadata.
Definition enums.h:151
IndexBlock
@ IndexBlock
Block containing the index (v1).
Definition enums.h:145
DeDuplicationTable2
@ DeDuplicationTable2
Block containing a deduplication table v2.
Definition enums.h:143
TapeFileBlock
@ TapeFileBlock
Block containing list of files for a tape image.
Definition enums.h:157
DeDuplicationTable
@ DeDuplicationTable
Block containing a deduplication table (v1).
Definition enums.h:142
DumpHardwareBlock
@ DumpHardwareBlock
Block containing an array of hardware used to create the image.
Definition enums.h:156
MetadataBlock
@ MetadataBlock
Block containing metadata.
Definition enums.h:149
TracksBlock
@ TracksBlock
Block containing optical disc tracks.
Definition enums.h:150
BlockMedia
@ BlockMedia
Media that is physically block-based or abstracted like that.
Definition enums.h:219
AARUF_ERROR_CANNOT_CREATE_FILE
#define AARUF_ERROR_CANNOT_CREATE_FILE
Output file could not be created / opened for write.
Definition errors.h:58
AARUF_STATUS_OK
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
Definition errors.h:75
AARUF_ERROR_NOT_ENOUGH_MEMORY
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
Definition errors.h:48
AARUF_ERROR_INCOMPATIBLE_VERSION
#define AARUF_ERROR_INCOMPATIBLE_VERSION
Image uses a newer incompatible on-disk version.
Definition errors.h:42
AARUF_ERROR_CANNOT_READ_INDEX
#define AARUF_ERROR_CANNOT_READ_INDEX
Index block unreadable / truncated / bad identifier.
Definition errors.h:43
AARUF_ERROR_NOT_AARUFORMAT
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
Definition errors.h:40
AARUF_ERROR_FILE_TOO_SMALL
#define AARUF_ERROR_FILE_TOO_SMALL
File size insufficient for mandatory header / structures.
Definition errors.h:41
MaxSectorTag
@ MaxSectorTag
Definition aaru.h:918
create_map
hash_map_t * create_map(size_t size)
Creates a new hash map with the specified initial size.
Definition hash_map.c:49
AARU_HEADER_APP_NAME_LEN
#define AARU_HEADER_APP_NAME_LEN
Size in bytes (UTF-16LE) of application name field (32 UTF-16 code units).
Definition header.h:59
internal.h
process_dumphw_block
void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a dump hardware block from the image stream.
Definition dump.c:107
process_index_v2
UT_array * process_index_v2(aaruformat_context *ctx)
Processes an index block (version 2) from the image stream.
Definition index_v2.c:81
process_ddt_v2
int32_t process_ddt_v2(aaruformat_context *ctx, IndexEntry *entry, bool *found_user_data_ddt)
Processes a DDT v2 block from the image stream.
Definition ddt_v2.c:96
process_data_block
int32_t process_data_block(aaruformat_context *ctx, IndexEntry *entry)
Processes a data block from the image stream.
Definition data.c:71
get_filetime_uint64
uint64_t get_filetime_uint64()
Gets the current time as a 64-bit FILETIME value.
Definition time.c:45
process_tracks_block
void process_tracks_block(aaruformat_context *ctx, const IndexEntry *entry)
Parse and integrate a Tracks block from the image stream into the context.
Definition optical.c:111
process_metadata_block
void process_metadata_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a metadata block from the image stream.
Definition metadata.c:35
process_checksum_block
void process_checksum_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a checksum block from the image stream.
Definition checksum.c:39
process_index_v1
UT_array * process_index_v1(aaruformat_context *ctx)
Processes an index block (version 1) from the image stream.
Definition index_v1.c:79
process_cicm_block
void process_cicm_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a CICM XML metadata block from the image stream.
Definition metadata.c:306
process_geometry_block
void process_geometry_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a logical geometry block from the image stream.
Definition metadata.c:246
process_tape_files_block
void process_tape_files_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a tape file metadata block from the image stream.
Definition tape.c:126
process_aaru_metadata_json_block
void process_aaru_metadata_json_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes an Aaru metadata JSON block from the image stream during image opening.
Definition metadata.c:470
process_tape_partitions_block
void process_tape_partitions_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a tape partition metadata block from the image stream.
Definition tape.c:346
parse_options
aaru_options parse_options(const char *options)
Parses the options string for AaruFormat image creation/opening.
Definition options.c:38
process_ddt_v1
int32_t process_ddt_v1(aaruformat_context *ctx, IndexEntry *entry, bool *found_user_data_ddt)
Processes a DDT v1 block from the image stream.
Definition ddt_v1.c:85
process_index_v3
UT_array * process_index_v3(aaruformat_context *ctx)
Processes an index block (version 3) from the image stream.
Definition index_v3.c:98
log.h
FATAL
#define FATAL(fmt,...)
Definition log.h:40
TRACE
#define TRACE(fmt,...)
Definition log.h:25
cleanup_open_failure
static void cleanup_open_failure(aaruformat_context *ctx)
Definition open.c:31
aaruf_open
void * aaruf_open(const char *filepath, const bool resume_mode, const char *options)
Opens an existing AaruFormat image file.
Definition open.c:223
AaruHeaderV2
Version 2 container header with GUID, alignment shifts, and feature negotiation bitmaps.
Definition header.h:107
AaruHeaderV2::application
uint8_t application[64]
UTF-8 creator application name (fixed 64 bytes).
Definition header.h:109
AaruHeaderV2::applicationMajorVersion
uint8_t applicationMajorVersion
Creator application major version.
Definition header.h:112
AaruHeaderV2::identifier
uint64_t identifier
File magic (AARU_MAGIC).
Definition header.h:108
AaruHeaderV2::lastWrittenTime
int64_t lastWrittenTime
Last modification FILETIME (100 ns since 1601-01-01 UTC).
Definition header.h:117
AaruHeaderV2::indexOffset
uint64_t indexOffset
Absolute byte offset to primary index block (MUST be > 0; 0 => corrupt/unreadable).
Definition header.h:115
AaruHeaderV2::applicationMinorVersion
uint8_t applicationMinorVersion
Creator application minor / patch version.
Definition header.h:113
AaruHeaderV2::mediaType
uint32_t mediaType
Media type enumeration (value from MediaType).
Definition header.h:114
AaruHeaderV2::imageMinorVersion
uint8_t imageMinorVersion
Container format minor version.
Definition header.h:111
AaruHeaderV2::creationTime
int64_t creationTime
Creation FILETIME (100 ns since 1601-01-01 UTC).
Definition header.h:116
AaruHeaderV2::imageMajorVersion
uint8_t imageMajorVersion
Container format major version.
Definition header.h:110
AaruHeader
Version 1 container header placed at offset 0 for legacy / initial format.
Definition header.h:77
CacheHeader::cache
struct CacheEntry * cache
Hash root (uthash). NULL when empty.
Definition lru.h:48
CacheHeader::max_items
uint64_t max_items
Hard limit for number of entries (policy: enforce/ignore depends on implementation).
Definition lru.h:47
CdEccContext
Lookup tables and state for Compact Disc EDC/ECC (P/Q) regeneration / verification.
Definition context.h:86
DdtHeader2::blocks
uint64_t blocks
Total internal span (negative + usable + overflow) in logical sectors.
Definition ddt.h:150
DdtHeader2::blockAlignmentShift
uint8_t blockAlignmentShift
2^blockAlignmentShift = block alignment boundary in bytes.
Definition ddt.h:154
GeometryBlockHeader::identifier
uint32_t identifier
Block identifier, must be BlockType::GeometryBlock.
Definition data.h:92
ImageInfo::MediaType
uint32_t MediaType
Media type identifier (see MediaType enum; 0=Unknown)
Definition aaru.h:881
ImageInfo::MetadataMediaType
uint8_t MetadataMediaType
Media type for sidecar generation (internal archival use)
Definition aaru.h:882
ImageInfo::SectorSize
uint32_t SectorSize
Size of each logical sector in bytes (512, 2048, 2352, 4096, etc.)
Definition aaru.h:875
ImageInfo::Application
char Application[64]
Name of application that created the image (NUL-terminated)
Definition aaru.h:877
ImageInfo::ImageSize
uint64_t ImageSize
Size of the image payload in bytes (excludes headers/metadata)
Definition aaru.h:873
ImageInfo::CreationTime
int64_t CreationTime
Image creation timestamp (Windows FILETIME: 100ns since 1601-01-01 UTC)
Definition aaru.h:879
ImageInfo::LastModificationTime
int64_t LastModificationTime
Last modification timestamp (Windows FILETIME format)
Definition aaru.h:880
ImageInfo::Version
char Version[32]
Image format version string (NUL-terminated, e.g., "6.0")
Definition aaru.h:876
ImageInfo::Sectors
uint64_t Sectors
Total count of addressable logical sectors/blocks.
Definition aaru.h:874
ImageInfo::ApplicationVersion
char ApplicationVersion[32]
Version of the creating application (NUL-terminated)
Definition aaru.h:878
IndexEntry
Single index entry describing a block's type, (optional) data classification, and file offset.
Definition index.h:109
IndexEntry::blockType
uint32_t blockType
Block identifier of the referenced block (value from BlockType).
Definition index.h:110
IndexEntry::offset
uint64_t offset
Absolute byte offset in the image where the referenced block header begins.
Definition index.h:112
IndexEntry::dataType
uint16_t dataType
Data classification (value from DataType) or unused for untyped blocks.
Definition index.h:111
aaru_options
Parsed user-specified tunables controlling compression, deduplication, hashing and DDT geometry.
Definition options.h:217
aaru_options::deduplicate
bool deduplicate
Storage dedup flag (DDT always exists).
Definition options.h:219
aaru_options::dictionary
uint32_t dictionary
LZMA dictionary size in bytes (>= 4096 recommended). Default: 33554432 (32 MiB).
Definition options.h:221
aaru_options::compress
bool compress
Enable adaptive compression (LZMA for data blocks, FLAC for audio). Default: true.
Definition options.h:218
aaruformat_context
Master context representing an open or in‑creation Aaru image.
Definition context.h:172
aaruformat_context::user_data_ddt_header
DdtHeader2 user_data_ddt_header
Active user data DDT v2 header (primary table meta).
Definition context.h:189
aaruformat_context::library_major_version
uint8_t library_major_version
Linked library major version.
Definition context.h:177
aaruformat_context::deduplicate
bool deduplicate
Storage deduplication active (duplicates coalesce).
Definition context.h:299
aaruformat_context::compression_enabled
bool compression_enabled
True if block compression enabled (writing path).
Definition context.h:300
aaruformat_context::sector_hash_map
hash_map_t * sector_hash_map
Deduplication hash map (fingerprint->entry mapping).
Definition context.h:253
aaruformat_context::cylinders
uint32_t cylinders
Cylinders of the media represented by the image.
Definition context.h:234
aaruformat_context::block_header_cache
struct CacheHeader block_header_cache
LRU/Cache header for block headers.
Definition context.h:256
aaruformat_context::shift
uint8_t shift
Legacy overall shift (deprecated by data_shift/table_shift).
Definition context.h:195
aaruformat_context::ecc_cd_context
CdEccContext * ecc_cd_context
CD ECC/EDC helper tables (allocated on demand).
Definition context.h:248
aaruformat_context::rewinded
bool rewinded
True if stream has been rewound after open (write path).
Definition context.h:293
aaruformat_context::block_cache
struct CacheHeader block_cache
LRU/Cache header for block payloads.
Definition context.h:257
aaruformat_context::header
AaruHeaderV2 header
Parsed container header (v2).
Definition context.h:175
aaruformat_context::is_writing
bool is_writing
True if context opened/created for writing.
Definition context.h:292
aaruformat_context::magic
uint64_t magic
File magic (AARU_MAGIC) post-open.
Definition context.h:174
aaruformat_context::library_minor_version
uint8_t library_minor_version
Linked library minor version;.
Definition context.h:178
aaruformat_context::next_block_position
uint64_t next_block_position
Absolute file offset where next block will be written.
Definition context.h:282
aaruformat_context::geometry_block
GeometryBlockHeader geometry_block
Logical geometry block (if present).
Definition context.h:229
aaruformat_context::sectors_per_track
uint32_t sectors_per_track
Sectors per track of the media represented by the image (for variable image, the smallest)
Definition context.h:236
aaruformat_context::heads
uint32_t heads
Heads of the media represented by the image.
Definition context.h:235
aaruformat_context::imageStream
FILE * imageStream
Underlying FILE* stream (binary mode).
Definition context.h:176
aaruformat_context::index_entries
UT_array * index_entries
Flattened index entries (UT_array of IndexEntry).
Definition context.h:252
aaruformat_context::image_info
ImageInfo image_info
Exposed high-level image info summary.
Definition context.h:260
aaruformat_context::readableSectorTags
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
Definition context.h:263
aaruformat_context::lzma_dict_size
uint32_t lzma_dict_size
LZMA dictionary size (writing path).
Definition context.h:298