libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
create.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#include <errno.h>
19#include <stdbool.h>
20#include <stdint.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "aaruformat.h"
26#include "enums.h"
27#include "internal.h"
28#include "log.h"
29
30 static void cleanup_failed_create(aaruformat_context *ctx)
31{
32 if(ctx == NULL) return;
33
34 if(ctx->sector_hash_map != NULL)
35 {
36 free_map(ctx->sector_hash_map);
37 ctx->sector_hash_map = NULL;
38 }
39
40 if(ctx->index_entries != NULL)
41 {
42 utarray_free(ctx->index_entries);
43 ctx->index_entries = NULL;
44 }
45
46 if(ctx->user_data_ddt2 != NULL)
47 {
48 free(ctx->user_data_ddt2);
49 ctx->user_data_ddt2 = NULL;
50 }
51
52 if(ctx->spamsum_context != NULL)
53 {
54 aaruf_spamsum_free(ctx->spamsum_context);
55 ctx->spamsum_context = NULL;
56 }
57
58 if(ctx->blake3_context != NULL)
59 {
60 free(ctx->blake3_context);
61 ctx->blake3_context = NULL;
62 }
63
64 if(ctx->ecc_cd_context != NULL)
65 {
66 free(ctx->ecc_cd_context);
67 ctx->ecc_cd_context = NULL;
68 }
69
70 if(ctx->readableSectorTags != NULL)
71 {
72 free(ctx->readableSectorTags);
73 ctx->readableSectorTags = NULL;
74 }
75
76 // ApplicationVersion and Version are fixed-size arrays, not pointers - no need to free
77
78 if(ctx->imageStream != NULL)
79 {
80 fclose(ctx->imageStream);
81 ctx->imageStream = NULL;
82 }
83
84 free(ctx);
85}
86
279 AARU_EXPORT void AARU_CALL *aaruf_create(const char *filepath, const uint32_t media_type, const uint32_t sector_size,
280 const uint64_t user_sectors, const uint64_t negative_sectors,
281 const uint64_t overflow_sectors, const char *options,
282 const uint8_t *application_name, const uint8_t application_name_length,
283 const uint8_t application_major_version,
284 const uint8_t application_minor_version, const bool is_tape)
285{
286 TRACE("Entering aaruf_create(%s, %u, %u, %llu, %llu, %llu, %s, %s, %u, %u, %u, %d)", filepath, media_type,
287 sector_size, user_sectors, negative_sectors, overflow_sectors, options,
288 application_name ? (const char *)application_name : "NULL", application_name_length,
289 application_major_version, application_minor_version, is_tape);
290
291 // Parse the options
292 TRACE("Parsing options");
293 const aaru_options parsed_options = parse_options(options);
294
295 // Allocate context
296 TRACE("Allocating memory for context");
297 aaruformat_context *ctx = malloc(sizeof(aaruformat_context));
298 if(ctx == NULL)
299 {
300 FATAL("Not enough memory to create context");
301 errno = AARUF_ERROR_NOT_ENOUGH_MEMORY;
302
303 TRACE("Exiting aaruf_create() = NULL");
304 return NULL;
305 }
306
307 memset(ctx, 0, sizeof(aaruformat_context));
308
309 // Create the image file
310 TRACE("Creating image file %s", filepath);
311 ctx->imageStream = fopen(filepath, "wb+");
312 if(ctx->imageStream == NULL)
313 {
314 FATAL("Error %d opening file %s for writing", errno, filepath);
315 errno = AARUF_ERROR_CANNOT_CREATE_FILE;
316
317 TRACE("Exiting aaruf_create() = NULL");
318 cleanup_failed_create(ctx);
319 return NULL;
320 }
321
322 if(application_name_length > AARU_HEADER_APP_NAME_LEN)
323 {
324 FATAL("Application name too long (%u bytes, maximum %u bytes)", application_name_length,
325 AARU_HEADER_APP_NAME_LEN);
326 errno = AARUF_ERROR_INVALID_APP_NAME_LENGTH;
327
328 TRACE("Exiting aaruf_create() = NULL");
329 cleanup_failed_create(ctx);
330 return NULL;
331 }
332
333 // Initialize header
334 TRACE("Initializing header");
335 ctx->header.identifier = AARU_MAGIC;
336 memcpy(ctx->header.application, application_name, application_name_length);
337 ctx->header.imageMajorVersion = AARUF_VERSION_V2;
338 ctx->header.imageMinorVersion = 0;
339 ctx->header.applicationMajorVersion = application_major_version;
340 ctx->header.applicationMinorVersion = application_minor_version;
341 ctx->header.mediaType = media_type;
342 ctx->header.indexOffset = 0;
343 ctx->header.creationTime = get_filetime_uint64();
344 ctx->header.lastWrittenTime = get_filetime_uint64();
345
346 // Generate random GUID for the image
347 TRACE("Generating random GUID");
348 generate_random_bytes(ctx->header.guid, GUID_SIZE);
349
350 ctx->readableSectorTags = (bool *)malloc(sizeof(bool) * MaxSectorTag);
351
352 if(ctx->readableSectorTags == NULL)
353 {
354 errno = AARUF_ERROR_NOT_ENOUGH_MEMORY;
355
356 TRACE("Exiting aaruf_create() = NULL");
357 cleanup_failed_create(ctx);
358 return NULL;
359 }
360
361 memset(ctx->readableSectorTags, 0, sizeof(bool) * MaxSectorTag);
362
363 // Initialize image info
364 TRACE("Initializing image info");
365
366 // Copy application name (UTF-8) to image_info
367 memset(ctx->image_info.Application, 0, 64);
368 size_t copy_len = application_name_length < 63 ? application_name_length : 63;
369 memcpy(ctx->image_info.Application, application_name, copy_len);
370 ctx->image_info.Application[63] = '\0';
371
372 // Set application version string directly in the fixed-size array
373 memset(ctx->image_info.ApplicationVersion, 0, 32);
374 sprintf(ctx->image_info.ApplicationVersion, "%d.%d", ctx->header.applicationMajorVersion,
375 ctx->header.applicationMinorVersion);
376
377 // Set image version string directly in the fixed-size array
378 memset(ctx->image_info.Version, 0, 32);
379 sprintf(ctx->image_info.Version, "%d.%d", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion);
380
381 ctx->image_info.MediaType = ctx->header.mediaType;
382 ctx->image_info.ImageSize = 0;
383 ctx->image_info.CreationTime = ctx->header.creationTime;
384 ctx->image_info.LastModificationTime = ctx->header.lastWrittenTime;
385 ctx->image_info.MetadataMediaType = aaruf_get_xml_mediatype(ctx->header.mediaType);
386 ctx->image_info.SectorSize = sector_size;
387 ctx->image_info.Sectors = user_sectors;
388
389 // Initialize caches
390 TRACE("Initializing caches");
391 ctx->block_header_cache.cache = NULL;
392 const uint64_t cache_divisor = (uint64_t)ctx->image_info.SectorSize * (1ULL << ctx->shift);
393 ctx->block_header_cache.max_items = cache_divisor == 0 ? 0 : MAX_CACHE_SIZE / cache_divisor;
394 ctx->block_cache.cache = NULL;
395 ctx->block_cache.max_items = ctx->block_header_cache.max_items;
396
397 // TODO: Cache tracks and sessions?
398
399 // Initialize ECC for Compact Disc
400 TRACE("Initializing Compact Disc ECC");
401 ctx->ecc_cd_context = (CdEccContext *)aaruf_ecc_cd_init();
402
403 ctx->magic = AARU_MAGIC;
404 ctx->library_major_version = LIBAARUFORMAT_MAJOR_VERSION;
405 ctx->library_minor_version = LIBAARUFORMAT_MINOR_VERSION;
406
407 if(!is_tape)
408 { // Initialize DDT2
409 TRACE("Initializing DDT2");
410 ctx->in_memory_ddt = true;
411 ctx->user_data_ddt_header.identifier = DeDuplicationTable2;
412 ctx->user_data_ddt_header.type = UserData;
413 ctx->user_data_ddt_header.compression = None;
414 ctx->user_data_ddt_header.tableLevel = 0;
415 ctx->user_data_ddt_header.previousLevelOffset = 0;
416 ctx->user_data_ddt_header.negative = negative_sectors;
417 ctx->user_data_ddt_header.blocks = user_sectors + overflow_sectors + negative_sectors;
418 ctx->user_data_ddt_header.overflow = overflow_sectors;
419 ctx->user_data_ddt_header.start = 0;
420 ctx->user_data_ddt_header.blockAlignmentShift = parsed_options.block_alignment;
421 ctx->user_data_ddt_header.dataShift = parsed_options.data_shift;
422
423 if(parsed_options.table_shift == -1)
424 {
425 const uint64_t total_sectors = user_sectors + overflow_sectors + negative_sectors;
426
427 if(total_sectors < 0x8388608ULL)
428 ctx->user_data_ddt_header.tableShift = 0;
429 else
430 ctx->user_data_ddt_header.tableShift = 22;
431 }
432 else
433 ctx->user_data_ddt_header.tableShift =
434 parsed_options.table_shift > 0 ? (uint8_t)parsed_options.table_shift : 0;
435
436 ctx->user_data_ddt_header.levels = ctx->user_data_ddt_header.tableShift > 0 ? 2 : 1;
437
438 uint8_t effective_table_shift = ctx->user_data_ddt_header.tableShift;
439 if(effective_table_shift >= 63)
440 {
441 TRACE("Clamping table shift from %u to 62 to avoid overflow", effective_table_shift);
442 effective_table_shift = 62;
443 ctx->user_data_ddt_header.tableShift = effective_table_shift;
444 }
445
446 const uint64_t sectors_per_entry = 1ULL << effective_table_shift;
447 ctx->user_data_ddt_header.entries = ctx->user_data_ddt_header.blocks / sectors_per_entry;
448 if(ctx->user_data_ddt_header.blocks % sectors_per_entry != 0 || ctx->user_data_ddt_header.entries == 0)
449 ctx->user_data_ddt_header.entries++;
450
451 TRACE("Initializing primary/single DDT");
452 ctx->user_data_ddt2 =
453 (uint64_t *)calloc(ctx->user_data_ddt_header.entries, sizeof(uint64_t)); // All entries to zero
454 if(ctx->user_data_ddt2 == NULL)
455 {
456 FATAL("Not enough memory to allocate primary DDT (big)");
457 errno = AARUF_ERROR_NOT_ENOUGH_MEMORY;
458 TRACE("Exiting aaruf_create() = NULL");
459 cleanup_failed_create(ctx);
460 return NULL;
461 }
462
463 // Set the primary DDT offset (just after the header, block aligned)
464 ctx->primary_ddt_offset = sizeof(AaruHeaderV2); // Start just after the header
465 const uint64_t alignment_mask = (1ULL << ctx->user_data_ddt_header.blockAlignmentShift) - 1;
466 ctx->primary_ddt_offset = ctx->primary_ddt_offset + alignment_mask & ~alignment_mask;
467
468 TRACE("Primary DDT will be placed at offset %" PRIu64, ctx->primary_ddt_offset);
469
470 // Calculate size of primary DDT table
471 const uint64_t primary_table_size = ctx->user_data_ddt_header.entries * sizeof(uint64_t);
472
473 // Calculate where data blocks can start (after primary DDT + header)
474 if(ctx->user_data_ddt_header.tableShift > 0)
475 {
476 const uint64_t data_start_position = ctx->primary_ddt_offset + sizeof(DdtHeader2) + primary_table_size;
477 ctx->next_block_position = data_start_position + alignment_mask & ~alignment_mask;
478 }
479 else
480 ctx->next_block_position = ctx->primary_ddt_offset; // Single-level DDT can start anywhere
481 }
482 else
483 {
484 // Fill needed values
485 ctx->user_data_ddt_header.blockAlignmentShift = parsed_options.block_alignment;
486 ctx->user_data_ddt_header.dataShift = parsed_options.data_shift;
487
488 // Calculate aligned next block position
489 const uint64_t alignment_mask = (1ULL << parsed_options.block_alignment) - 1;
490 ctx->next_block_position = sizeof(AaruHeaderV2); // Start just after the header
491 ctx->next_block_position = ctx->next_block_position + alignment_mask & ~alignment_mask;
492 ctx->is_tape = 1;
493 ctx->tape_ddt = NULL;
494 }
495
496 TRACE("Data blocks will start at position %" PRIu64, ctx->next_block_position);
497
498 // Position file pointer at the data start position
499 if(fseek(ctx->imageStream, ctx->next_block_position, SEEK_SET) != 0)
500 {
501 FATAL("Could not seek to data start position");
502 errno = AARUF_ERROR_CANNOT_CREATE_FILE;
503 TRACE("Exiting aaruf_create() = NULL");
504 cleanup_failed_create(ctx);
505 return NULL;
506 }
507
508 // Initialize index entries array
509 TRACE("Initializing index entries array");
510 const UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
511 utarray_new(ctx->index_entries, &index_entry_icd);
512
513 if(ctx->index_entries == NULL)
514 {
515 FATAL("Not enough memory to create index entries array");
516 errno = AARUF_ERROR_NOT_ENOUGH_MEMORY;
517
518 TRACE("Exiting aaruf_create() = NULL");
519 cleanup_failed_create(ctx);
520 return NULL;
521 }
522
523 ctx->compression_enabled = parsed_options.compress;
524 ctx->lzma_dict_size = parsed_options.dictionary;
525 ctx->deduplicate = parsed_options.deduplicate;
526 if(ctx->deduplicate)
527 ctx->sector_hash_map = create_map(ctx->user_data_ddt_header.blocks * 25 / 100); // 25% of total sectors
528
529 ctx->rewinded = false;
530 ctx->last_written_block = 0;
531
532 if(parsed_options.md5)
533 {
534 ctx->calculating_md5 = true;
535 aaruf_md5_init(&ctx->md5_context);
536 }
537 if(parsed_options.sha1)
538 {
539 ctx->calculating_sha1 = true;
540 aaruf_sha1_init(&ctx->sha1_context);
541 }
542 if(parsed_options.sha256)
543 {
544 ctx->calculating_sha256 = true;
545 aaruf_sha256_init(&ctx->sha256_context);
546 }
547 if(parsed_options.spamsum)
548 {
549 ctx->calculating_spamsum = true;
550 ctx->spamsum_context = aaruf_spamsum_init();
551 }
552 if(parsed_options.blake3)
553 {
554 ctx->blake3_context = calloc(1, sizeof(blake3_hasher));
555 if(ctx->blake3_context != NULL)
556 {
557 ctx->calculating_blake3 = true;
558 blake3_hasher_init(ctx->blake3_context);
559 }
560 }
561
562 // Is writing
563 ctx->is_writing = true;
564
565 TRACE("Exiting aaruf_create() = %p", ctx);
566 // Return context
567 return ctx;
568}
aaruformat.h
LIBAARUFORMAT_MAJOR_VERSION
#define LIBAARUFORMAT_MAJOR_VERSION
Definition aaruformat.h:22
LIBAARUFORMAT_MINOR_VERSION
#define LIBAARUFORMAT_MINOR_VERSION
Definition aaruformat.h:23
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_create
void * aaruf_create(const char *filepath, const uint32_t media_type, const uint32_t sector_size, const uint64_t user_sectors, const uint64_t negative_sectors, const uint64_t overflow_sectors, const char *options, const uint8_t *application_name, const uint8_t application_name_length, const uint8_t application_major_version, const uint8_t application_minor_version, const bool is_tape)
Creates a new AaruFormat image file.
Definition create.c:279
cleanup_failed_create
static void cleanup_failed_create(aaruformat_context *ctx)
Definition create.c:30
AARU_CALL
#define AARU_CALL
Definition decls.h:45
aaruf_sha256_init
void aaruf_sha256_init(sha256_ctx *ctx)
Definition sha256.c:76
aaruf_md5_init
void aaruf_md5_init(md5_ctx *ctx)
Definition md5.c:436
aaruf_spamsum_free
void aaruf_spamsum_free(spamsum_ctx *ctx)
Frees a spamsum (fuzzy hash) context.
Definition spamsum.c:75
aaruf_spamsum_init
spamsum_ctx * aaruf_spamsum_init(void)
Definition spamsum.c:37
AARU_EXPORT
#define AARU_EXPORT
Definition decls.h:54
aaruf_sha1_init
void aaruf_sha1_init(sha1_ctx *ctx)
Definition sha1.c:34
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
enums.h
DeDuplicationTable2
@ DeDuplicationTable2
Block containing a deduplication table v2.
Definition enums.h:143
UserData
@ UserData
User (main) data.
Definition enums.h:46
None
@ None
Not compressed.
Definition enums.h:33
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_ERROR_INVALID_APP_NAME_LENGTH
#define AARUF_ERROR_INVALID_APP_NAME_LENGTH
Application name field length invalid (sanity limit).
Definition errors.h:59
AARUF_ERROR_NOT_ENOUGH_MEMORY
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
Definition errors.h:48
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
free_map
void free_map(hash_map_t *map)
Frees all memory associated with a hash map.
Definition hash_map.c:73
GUID_SIZE
#define GUID_SIZE
Size in bytes of GUID / UUID-like binary identifier.
Definition header.h:60
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
get_filetime_uint64
uint64_t get_filetime_uint64()
Gets the current time as a 64-bit FILETIME value.
Definition time.c:45
generate_random_bytes
void generate_random_bytes(uint8_t *buffer, size_t length)
Generates cryptographically strong random bytes.
Definition helpers.c:480
parse_options
aaru_options parse_options(const char *options)
Parses the options string for AaruFormat image creation/opening.
Definition options.c:38
log.h
FATAL
#define FATAL(fmt,...)
Definition log.h:40
TRACE
#define TRACE(fmt,...)
Definition log.h:25
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::guid
uint8_t guid[16]
128-bit image GUID (binary, not text); stable across children.
Definition header.h:118
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
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
Header preceding a version 2 hierarchical deduplication table.
Definition ddt.h:142
DdtHeader2::type
uint16_t type
Data classification (DataType) for sectors referenced by this table.
Definition ddt.h:144
DdtHeader2::start
uint64_t start
Base internal index covered by this table (used for secondary tables; currently informational).
Definition ddt.h:153
DdtHeader2::overflow
uint16_t overflow
Trailing dumped sectors beyond user area (overflow range), still mapped with entries.
Definition ddt.h:151
DdtHeader2::entries
uint64_t entries
Number of entries contained in (uncompressed) table payload.
Definition ddt.h:158
DdtHeader2::levels
uint8_t levels
Total number of hierarchy levels (root depth); > 0.
Definition ddt.h:146
DdtHeader2::identifier
uint32_t identifier
Block identifier, must be BlockType::DeDuplicationTable2.
Definition ddt.h:143
DdtHeader2::tableShift
uint8_t tableShift
2^tableShift = number of logical sectors per primary entry (multi-level only; 0 for single-level or s...
Definition ddt.h:156
DdtHeader2::blocks
uint64_t blocks
Total internal span (negative + usable + overflow) in logical sectors.
Definition ddt.h:150
DdtHeader2::negative
uint16_t negative
Leading negative LBA count; added to external L to build internal index.
Definition ddt.h:149
DdtHeader2::blockAlignmentShift
uint8_t blockAlignmentShift
2^blockAlignmentShift = block alignment boundary in bytes.
Definition ddt.h:154
DdtHeader2::tableLevel
uint8_t tableLevel
Zero-based level index of this table (0 = root, increases downward).
Definition ddt.h:147
DdtHeader2::compression
uint16_t compression
Compression algorithm for this table body (CompressionType).
Definition ddt.h:145
DdtHeader2::dataShift
uint8_t dataShift
2^dataShift = sectors represented per increment in blockIndex field.
Definition ddt.h:155
DdtHeader2::previousLevelOffset
uint64_t previousLevelOffset
Absolute byte offset of the parent (previous) level table; 0 if root.
Definition ddt.h:148
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
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::data_shift
uint8_t data_shift
Global data shift: low bits encode sector offset inside a block (2^data_shift span).
Definition options.h:223
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
aaru_options::sha256
bool sha256
Generate SHA-256 checksum (ChecksumAlgorithm::Sha256) when finalizing image.
Definition options.h:227
aaru_options::spamsum
bool spamsum
Generate SpamSum fuzzy hash (ChecksumAlgorithm::SpamSum) if enabled.
Definition options.h:229
aaru_options::table_shift
int8_t table_shift
DDT table shift (multi-level fan-out exponent). Default: heuristically calculated.
Definition options.h:222
aaru_options::md5
bool md5
Generate MD5 checksum (ChecksumAlgorithm::Md5) when finalizing image.
Definition options.h:225
aaru_options::blake3
bool blake3
Generate BLAKE3 checksum if supported (not stored if algorithm unavailable).
Definition options.h:228
aaru_options::sha1
bool sha1
Generate SHA-1 checksum (ChecksumAlgorithm::Sha1) when finalizing image.
Definition options.h:226
aaru_options::block_alignment
uint8_t block_alignment
log2 underlying block alignment (2^n bytes). Default: 9 (512 bytes).
Definition options.h:224
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:298
aaruformat_context::compression_enabled
bool compression_enabled
True if block compression enabled (writing path).
Definition context.h:299
aaruformat_context::last_written_block
uint64_t last_written_block
Last written block number (write path).
Definition context.h:283
aaruformat_context::sector_hash_map
hash_map_t * sector_hash_map
Deduplication hash map (fingerprint->entry mapping).
Definition context.h:253
aaruformat_context::sha256_context
sha256_ctx sha256_context
Opaque SHA-256 context for streaming updates.
Definition context.h:272
aaruformat_context::calculating_sha256
bool calculating_sha256
True if whole-image SHA-256 being calculated on-the-fly.
Definition context.h:275
aaruformat_context::block_header_cache
struct CacheHeader block_header_cache
LRU/Cache header for block headers.
Definition context.h:256
aaruformat_context::md5_context
md5_ctx md5_context
Opaque MD5 context for streaming updates.
Definition context.h:270
aaruformat_context::user_data_ddt2
uint64_t * user_data_ddt2
DDT entries (big variant) primary/secondary current.
Definition context.h:187
aaruformat_context::shift
uint8_t shift
Legacy overall shift (deprecated by data_shift/table_shift).
Definition context.h:195
aaruformat_context::is_tape
bool is_tape
True if the image is a tape image.
Definition context.h:304
aaruformat_context::calculating_sha1
bool calculating_sha1
True if whole-image SHA-1 being calculated on-the-fly.
Definition context.h:274
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::in_memory_ddt
bool in_memory_ddt
True if primary (and possibly secondary) DDT loaded.
Definition context.h:196
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::tape_ddt
TapeDdtHashEntry * tape_ddt
Hash table root for tape DDT entries.
Definition context.h:182
aaruformat_context::spamsum_context
spamsum_ctx * spamsum_context
Opaque SpamSum context for streaming updates.
Definition context.h:267
aaruformat_context::magic
uint64_t magic
File magic (AARU_MAGIC) post-open.
Definition context.h:174
aaruformat_context::calculating_spamsum
bool calculating_spamsum
True if whole-image SpamSum being calculated on-the-fly.
Definition context.h:276
aaruformat_context::primary_ddt_offset
uint64_t primary_ddt_offset
File offset of the primary DDT v2 table.
Definition context.h:192
aaruformat_context::blake3_context
blake3_hasher * blake3_context
Opaque BLAKE3 context for streaming updates.
Definition context.h:268
aaruformat_context::calculating_blake3
bool calculating_blake3
True if whole-image BLAKE3 being calculated on-the-fly.
Definition context.h:277
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::calculating_md5
bool calculating_md5
True if whole-image MD5 being calculated on-the-fly.
Definition context.h:273
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::sha1_context
sha1_ctx sha1_context
Opaque SHA-1 context for streaming updates.
Definition context.h:271
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:297