33 if(ctx == NULL)
return;
228 size_t read_bytes = 0;
231 uint32_t signature = 0;
232 UT_array *index_entries = NULL;
237 slog_init(
"aaruformat.log", SLOG_FLAGS_ALL, 0);
240 TRACE(
"Logging initialized");
242 TRACE(
"Entering aaruf_open(%s)", filepath);
244 TRACE(
"Allocating memory for context");
249 FATAL(
"Not enough memory to create context");
252 TRACE(
"Exiting aaruf_open() = NULL");
258 TRACE(
"Opening file %s", filepath);
266 FATAL(
"Error %d opening file %s for reading", errno, filepath);
271 TRACE(
"Exiting aaruf_open() = NULL");
275 TRACE(
"Reading header at position 0");
281 FATAL(
"Could not read header");
285 TRACE(
"Exiting aaruf_open() = NULL");
295 TRACE(
"Exiting aaruf_open() = NULL");
301 TRACE(
"Cannot write to old images");
304 TRACE(
"Exiting aaruf_open() = NULL");
311 TRACE(
"Reading new header version at position 0");
331 TRACE(
"Exiting aaruf_open() = NULL");
337 TRACE(
"Allocating memory for readable sector tags bitmap");
342 FATAL(
"Could not allocate memory for readable sector tags bitmap");
346 TRACE(
"Exiting aaruf_open() = NULL");
352 TRACE(
"Setting up image info");
360 TRACE(
"Converting application name (v2+): UTF-8 direct copy");
368 TRACE(
"Converting application name (v1): UTF-16LE to ASCII");
411 read_bytes = fread(&signature, 1,
sizeof(uint32_t), ctx->
imageStream);
413 if(read_bytes !=
sizeof(uint32_t) ||
416 FATAL(
"Could not read index header or incorrect identifier %4.4s", (
char *)&signature);
420 TRACE(
"Exiting aaruf_open() = NULL");
431 if(index_entries == NULL)
433 FATAL(
"Could not process index.");
434 utarray_free(index_entries);
438 TRACE(
"Exiting aaruf_open() = NULL");
444 for(i = 0; i < utarray_len(index_entries); i++)
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,
451 bool found_user_data_ddt =
false;
453 for(i = 0; i < utarray_len(index_entries); i++)
455 IndexEntry *entry = utarray_eltptr(index_entries, i);
460 TRACE(
"Could not seek to %" PRIu64
" as indicated by index entry %d, continuing...", entry->
offset, i);
465 TRACE(
"Processing block type %4.4s with data type %d at position %" PRIu64
"", (
char *)&entry->
blockType,
474 utarray_free(index_entries);
488 utarray_free(index_entries);
501 utarray_free(index_entries);
547 TRACE(
"Unhandled block type %4.4s with data type %d is indexed to be at %" PRIu64
"",
555 if(!found_user_data_ddt)
557 FATAL(
"Could not find user data deduplication table, aborting...");
560 TRACE(
"Exiting aaruf_open() = NULL");
576 TRACE(
"Initializing caches");
581 if(cache_divisor == 0)
595 TRACE(
"Initializing ECC for Compact Disc");
604 TRACE(
"Exiting aaruf_open() = %p", ctx);
609 TRACE(
"Parsing options");
626 FATAL(
"Could not seek to data start position");
628 TRACE(
"Exiting aaruf_open() = NULL");
646 TRACE(
"Exiting aaruf_open() = %p", ctx);
#define DIC_MAGIC
Magic identifier for legacy DiscImageChef container (ASCII "DICMFRMT").
#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).
#define AARUF_VERSION
Current image format major version (incompatible changes bump this).
int aaruf_close(void *context)
Close an Aaru image context, flushing pending data structures and releasing resources.
void * aaruf_ecc_cd_init()
Initializes a Compact Disc ECC context.
int32_t aaruf_get_xml_mediatype(int32_t type)
@ IndexBlock3
Block containing the index v3.
@ ChecksumBlock
Block containing contents checksums.
@ DataBlock
Block containing data.
@ TapePartitionBlock
Block containing list of partitions for a tape image.
@ IndexBlock2
Block containing the index v2.
@ GeometryBlock
Block containing logical geometry.
@ AaruMetadataJsonBlock
Block containing JSON version of Aaru Metadata.
@ CicmBlock
Block containing CICM XML metadata.
@ IndexBlock
Block containing the index (v1).
@ DeDuplicationTable2
Block containing a deduplication table v2.
@ TapeFileBlock
Block containing list of files for a tape image.
@ DeDuplicationTable
Block containing a deduplication table (v1).
@ DumpHardwareBlock
Block containing an array of hardware used to create the image.
@ MetadataBlock
Block containing metadata.
@ TracksBlock
Block containing optical disc tracks.
@ BlockMedia
Media that is physically block-based or abstracted like that.
#define AARUF_ERROR_CANNOT_CREATE_FILE
Output file could not be created / opened for write.
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
#define AARUF_ERROR_INCOMPATIBLE_VERSION
Image uses a newer incompatible on-disk version.
#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.
#define AARUF_ERROR_FILE_TOO_SMALL
File size insufficient for mandatory header / structures.
hash_map_t * create_map(size_t size)
Creates a new hash map with the specified initial size.
void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a dump hardware block from the image stream.
UT_array * process_index_v2(aaruformat_context *ctx)
Processes an index block (version 2) from the image stream.
int32_t process_ddt_v2(aaruformat_context *ctx, IndexEntry *entry, bool *found_user_data_ddt)
Processes a DDT v2 block from the image stream.
int32_t process_data_block(aaruformat_context *ctx, IndexEntry *entry)
Processes a data block from the image stream.
uint64_t get_filetime_uint64()
Gets the current time as a 64-bit FILETIME value.
void process_tracks_block(aaruformat_context *ctx, const IndexEntry *entry)
Parse and integrate a Tracks block from the image stream into the context.
void process_metadata_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a metadata block from the image stream.
void process_checksum_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a checksum block from the image stream.
UT_array * process_index_v1(aaruformat_context *ctx)
Processes an index block (version 1) from the image stream.
void process_cicm_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a CICM XML metadata block from the image stream.
void process_geometry_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a logical geometry block from the image stream.
void process_tape_files_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a tape file metadata block from the image stream.
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.
void process_tape_partitions_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a tape partition metadata block from the image stream.
aaru_options parse_options(const char *options)
Parses the options string for AaruFormat image creation/opening.
int32_t process_ddt_v1(aaruformat_context *ctx, IndexEntry *entry, bool *found_user_data_ddt)
Processes a DDT v1 block from the image stream.
UT_array * process_index_v3(aaruformat_context *ctx)
Processes an index block (version 3) from the image stream.
static void cleanup_open_failure(aaruformat_context *ctx)
void * aaruf_open(const char *filepath, const bool resume_mode, const char *options)
Opens an existing AaruFormat image file.
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.
uint32_t blockType
Block identifier of the referenced block (value from BlockType).
uint64_t offset
Absolute byte offset in the image where the referenced block header begins.
uint16_t dataType
Data classification (value from DataType) or unused for untyped blocks.
Parsed user-specified tunables controlling compression, deduplication, hashing and DDT geometry.
bool deduplicate
Storage dedup flag (DDT always exists).
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.
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).
hash_map_t * sector_hash_map
Deduplication hash map (fingerprint->entry mapping).
uint32_t cylinders
Cylinders of the media represented by the image.
struct CacheHeader block_header_cache
LRU/Cache header for block headers.
uint8_t shift
Legacy overall shift (deprecated by data_shift/table_shift).
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.
AaruHeaderV2 header
Parsed container header (v2).
bool is_writing
True if context opened/created for writing.
uint64_t magic
File magic (AARU_MAGIC) post-open.
uint8_t library_minor_version
Linked library minor version;.
uint64_t next_block_position
Absolute file offset where next block will be written.
GeometryBlockHeader geometry_block
Logical geometry block (if present).
uint32_t sectors_per_track
Sectors per track of the media represented by the image (for variable image, the smallest)
uint32_t heads
Heads of the media represented by the image.
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.
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
uint32_t lzma_dict_size
LZMA dictionary size (writing path).