33 if(ctx == NULL)
return;
129 size_t read_bytes = 0;
132 uint32_t signature = 0;
133 UT_array *index_entries = NULL;
138 slog_init(
"aaruformat.log", SLOG_FLAGS_ALL, 0);
141 TRACE(
"Logging initialized");
143 TRACE(
"Entering aaruf_open(%s)", filepath);
145 TRACE(
"Allocating memory for context");
150 FATAL(
"Not enough memory to create context");
153 TRACE(
"Exiting aaruf_open() = NULL");
159 TRACE(
"Opening file %s", filepath);
164 FATAL(
"Error %d opening file %s for reading", errno, filepath);
169 TRACE(
"Exiting aaruf_open() = NULL");
173 TRACE(
"Reading header at position 0");
179 FATAL(
"Could not read header");
183 TRACE(
"Exiting aaruf_open() = NULL");
193 TRACE(
"Exiting aaruf_open() = NULL");
200 TRACE(
"Reading new header version at position 0");
220 TRACE(
"Exiting aaruf_open() = NULL");
226 TRACE(
"Allocating memory for readable sector tags bitmap");
231 FATAL(
"Could not allocate memory for readable sector tags bitmap");
235 TRACE(
"Exiting aaruf_open() = NULL");
241 TRACE(
"Setting up image info");
249 TRACE(
"Converting application name (v2+): UTF-8 direct copy");
257 TRACE(
"Converting application name (v1): UTF-16LE to ASCII");
300 read_bytes = fread(&signature, 1,
sizeof(uint32_t), ctx->
imageStream);
302 if(read_bytes !=
sizeof(uint32_t) ||
305 FATAL(
"Could not read index header or incorrect identifier %4.4s", (
char *)&signature);
309 TRACE(
"Exiting aaruf_open() = NULL");
320 if(index_entries == NULL)
322 FATAL(
"Could not process index.");
323 utarray_free(index_entries);
327 TRACE(
"Exiting aaruf_open() = NULL");
333 for(i = 0; i < utarray_len(index_entries); i++)
335 IndexEntry *entry = utarray_eltptr(index_entries, i);
336 TRACE(
"Block type %4.4s with data type %d is indexed to be at %" PRIu64
"", (
char *)&entry->
blockType,
340 bool found_user_data_ddt =
false;
342 for(i = 0; i < utarray_len(index_entries); i++)
344 IndexEntry *entry = utarray_eltptr(index_entries, i);
349 TRACE(
"Could not seek to %" PRIu64
" as indicated by index entry %d, continuing...", entry->
offset, i);
354 TRACE(
"Processing block type %4.4s with data type %d at position %" PRIu64
"", (
char *)&entry->
blockType,
363 utarray_free(index_entries);
377 utarray_free(index_entries);
390 utarray_free(index_entries);
436 TRACE(
"Unhandled block type %4.4s with data type %d is indexed to be at %" PRIu64
"",
442 utarray_free(index_entries);
444 if(!found_user_data_ddt)
446 FATAL(
"Could not find user data deduplication table, aborting...");
449 TRACE(
"Exiting aaruf_open() = NULL");
465 TRACE(
"Initializing caches");
470 if(cache_divisor == 0)
484 TRACE(
"Initializing ECC for Compact Disc");
491 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_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.
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.
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.
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)
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.
Master context representing an open or in‑creation Aaru image.
uint8_t library_major_version
Linked library major version.
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).
struct CacheHeader block_cache
LRU/Cache header for block payloads.
AaruHeaderV2 header
Parsed container header (v2).
uint64_t magic
File magic (AARU_MAGIC) post-open.
uint8_t library_minor_version
Linked library minor version;.
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).
ImageInfo image_info
Exposed high-level image info summary.
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).