32 if(ctx == NULL)
return;
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)
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);
292 TRACE(
"Parsing options");
296 TRACE(
"Allocating memory for context");
300 FATAL(
"Not enough memory to create context");
303 TRACE(
"Exiting aaruf_create() = NULL");
310 TRACE(
"Creating image file %s", filepath);
314 FATAL(
"Error %d opening file %s for writing", errno, filepath);
317 TRACE(
"Exiting aaruf_create() = NULL");
324 FATAL(
"Application name too long (%u bytes, maximum %u bytes)", application_name_length,
328 TRACE(
"Exiting aaruf_create() = NULL");
334 TRACE(
"Initializing header");
352 TRACE(
"Exiting aaruf_create() = NULL");
360 TRACE(
"Initializing image info");
364 size_t copy_len = application_name_length < 63 ? application_name_length : 63;
386 TRACE(
"Initializing caches");
396 TRACE(
"Initializing Compact Disc ECC");
405 TRACE(
"Initializing DDT2");
421 const uint64_t total_sectors = user_sectors + overflow_sectors + negative_sectors;
423 if(total_sectors < 0x8388608ULL)
435 if(effective_table_shift >= 63)
437 TRACE(
"Clamping table shift from %u to 62 to avoid overflow", effective_table_shift);
438 effective_table_shift = 62;
442 const uint64_t sectors_per_entry = 1ULL << effective_table_shift;
447 TRACE(
"Initializing primary/single DDT");
452 FATAL(
"Not enough memory to allocate primary DDT (big)");
454 TRACE(
"Exiting aaruf_create() = NULL");
485 const uint64_t alignment_mask = (1ULL << parsed_options.
block_alignment) - 1;
497 FATAL(
"Could not seek to data start position");
499 TRACE(
"Exiting aaruf_create() = NULL");
505 TRACE(
"Initializing index entries array");
506 const UT_icd index_entry_icd = {
sizeof(
IndexEntry), NULL, NULL, NULL};
511 FATAL(
"Not enough memory to create index entries array");
514 TRACE(
"Exiting aaruf_create() = NULL");
528 if(parsed_options.
md5)
533 if(parsed_options.
sha1)
561 TRACE(
"Exiting aaruf_create() = %p", ctx);
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
#define MAX_CACHE_SIZE
Maximum read cache size (bytes).
#define AARUF_VERSION_V2
Second on‑disk version (C implementation).
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.
static void cleanup_failed_create(aaruformat_context *ctx)
void aaruf_sha256_init(sha256_ctx *ctx)
void aaruf_md5_init(md5_ctx *ctx)
void aaruf_spamsum_free(spamsum_ctx *ctx)
Frees a spamsum (fuzzy hash) context.
spamsum_ctx * aaruf_spamsum_init(void)
void aaruf_sha1_init(sha1_ctx *ctx)
void * aaruf_ecc_cd_init()
Initializes a Compact Disc ECC context.
int32_t aaruf_get_xml_mediatype(int32_t type)
@ DeDuplicationTable2
Block containing a deduplication table v2.
@ UserData
User (main) data.
#define AARUF_ERROR_CANNOT_CREATE_FILE
Output file could not be created / opened for write.
#define AARUF_ERROR_INVALID_APP_NAME_LENGTH
Application name field length invalid (sanity limit).
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
hash_map_t * create_map(size_t size)
Creates a new hash map with the specified initial size.
void free_map(hash_map_t *map)
Frees all memory associated with a hash map.
uint64_t get_filetime_uint64()
Gets the current time as a 64-bit FILETIME value.
aaru_options parse_options(const char *options)
Parses the options string for AaruFormat image creation/opening.
Lookup tables and state for Compact Disc EDC/ECC (P/Q) regeneration / verification.
uint32_t MediaType
Media type identifier (see MediaType enum; 0=Unknown)
uint8_t MetadataMediaType
Media type for sidecar generation (internal archival use)
uint32_t SectorSize
Size of each logical sector in bytes (512, 2048, 2352, 4096, etc.)
char Application[64]
Name of application that created the image (NUL-terminated)
uint64_t ImageSize
Size of the image payload in bytes (excludes headers/metadata)
int64_t CreationTime
Image creation timestamp (Windows FILETIME: 100ns since 1601-01-01 UTC)
int64_t LastModificationTime
Last modification timestamp (Windows FILETIME format)
char Version[32]
Image format version string (NUL-terminated, e.g., "6.0")
uint64_t Sectors
Total count of addressable logical sectors/blocks.
char ApplicationVersion[32]
Version of the creating application (NUL-terminated)
Single index entry describing a block's type, (optional) data classification, and file offset.
Parsed user-specified tunables controlling compression, deduplication, hashing and DDT geometry.
bool deduplicate
Storage dedup flag (DDT always exists).
uint8_t data_shift
Global data shift: low bits encode sector offset inside a block (2^data_shift span).
uint32_t dictionary
LZMA dictionary size in bytes (>= 4096 recommended). Default: 33554432 (32 MiB).
bool compress
Enable adaptive compression (LZMA for data blocks, FLAC for audio). Default: true.
bool sha256
Generate SHA-256 checksum (ChecksumAlgorithm::Sha256) when finalizing image.
bool spamsum
Generate SpamSum fuzzy hash (ChecksumAlgorithm::SpamSum) if enabled.
int8_t table_shift
DDT table shift (multi-level fan-out exponent). Default: heuristically calculated.
bool md5
Generate MD5 checksum (ChecksumAlgorithm::Md5) when finalizing image.
bool blake3
Generate BLAKE3 checksum if supported (not stored if algorithm unavailable).
bool sha1
Generate SHA-1 checksum (ChecksumAlgorithm::Sha1) when finalizing image.
uint8_t block_alignment
log2 underlying block alignment (2^n bytes). Default: 9 (512 bytes).
Master context representing an open or in‑creation Aaru image.
DdtHeader2 user_data_ddt_header
Active user data DDT v2 header (primary table meta).
uint8_t library_major_version
Linked library major version.
bool deduplicate
Storage deduplication active (duplicates coalesce).
bool compression_enabled
True if block compression enabled (writing path).
uint64_t last_written_block
Last written block number (write path).
hash_map_t * sector_hash_map
Deduplication hash map (fingerprint->entry mapping).
sha256_ctx sha256_context
Opaque SHA-256 context for streaming updates.
bool calculating_sha256
True if whole-image SHA-256 being calculated on-the-fly.
struct CacheHeader block_header_cache
LRU/Cache header for block headers.
md5_ctx md5_context
Opaque MD5 context for streaming updates.
uint64_t * user_data_ddt2
DDT entries (big variant) primary/secondary current.
uint8_t shift
Legacy overall shift (deprecated by data_shift/table_shift).
bool is_tape
True if the image is a tape image.
bool calculating_sha1
True if whole-image SHA-1 being calculated on-the-fly.
CdEccContext * ecc_cd_context
CD ECC/EDC helper tables (allocated on demand).
bool rewinded
True if stream has been rewound after open (write path).
struct CacheHeader block_cache
LRU/Cache header for block payloads.
bool in_memory_ddt
True if primary (and possibly secondary) DDT loaded.
AaruHeaderV2 header
Parsed container header (v2).
bool is_writing
True if context opened/created for writing.
TapeDdtHashEntry * tape_ddt
Hash table root for tape DDT entries.
spamsum_ctx * spamsum_context
Opaque SpamSum context for streaming updates.
uint64_t magic
File magic (AARU_MAGIC) post-open.
bool calculating_spamsum
True if whole-image SpamSum being calculated on-the-fly.
uint64_t primary_ddt_offset
File offset of the primary DDT v2 table.
blake3_hasher * blake3_context
Opaque BLAKE3 context for streaming updates.
bool calculating_blake3
True if whole-image BLAKE3 being calculated on-the-fly.
uint8_t library_minor_version
Linked library minor version;.
uint64_t next_block_position
Absolute file offset where next block will be written.
bool calculating_md5
True if whole-image MD5 being calculated on-the-fly.
FILE * imageStream
Underlying FILE* stream (binary mode).
UT_array * index_entries
Flattened index entries (UT_array of IndexEntry).
ImageInfo image_info
Exposed high-level image info summary.
sha1_ctx sha1_context
Opaque SHA-1 context for streaming updates.
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
uint32_t lzma_dict_size
LZMA dictionary size (writing path).