libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
context.h
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#ifndef LIBAARUFORMAT_CONTEXT_H
20#define LIBAARUFORMAT_CONTEXT_H
21
22#include "blake3.h"
23#include "crc64.h"
24#include "hash_map.h"
25#include "lru.h"
26#include "md5.h"
27#include "sha1.h"
28#include "sha256.h"
29#include "spamsum.h"
30#include "structs.h"
31#include "utarray.h"
32
67
68#ifndef MD5_DIGEST_LENGTH
69#define MD5_DIGEST_LENGTH 16
70#endif
71
72#ifndef SHA1_DIGEST_LENGTH
73#define SHA1_DIGEST_LENGTH 20
74#endif
75
76#ifndef SHA256_DIGEST_LENGTH
77#define SHA256_DIGEST_LENGTH 32
78#endif
79
85typedef struct CdEccContext
86{
88 uint8_t *ecc_b_table;
89 uint8_t *ecc_f_table;
90 uint32_t *edc_table;
92
99typedef struct Checksums
100{
101 bool hasMd5;
102 bool hasSha1;
109 uint8_t blake3[BLAKE3_OUT_LEN];
110 uint8_t *spamsum;
112
118typedef struct mediaTagEntry
119{
120 uint8_t *data;
121 int32_t type;
122 uint32_t length;
123 UT_hash_handle hh;
125
126typedef struct TapeFileHashEntry
127{
128 uint64_t key;
130 UT_hash_handle hh;
132
139
140typedef struct TapeDdtHashEntry
141{
142 uint64_t key;
143 uint64_t value;
144 UT_hash_handle hh;
146
171typedef struct aaruformat_context
172{
173 /* Core & header */
174 uint64_t magic;
179
180 /* Deduplication tables (DDT) */
181 uint64_t *user_data_ddt;
187 uint64_t *user_data_ddt2;
195 uint8_t shift;
197
198 /* Optical auxiliary buffers (NULL if not present) */
199 uint8_t *sector_prefix;
201 uint8_t *sector_suffix;
205 uint8_t *sector_id;
206 uint8_t *sector_ied;
207 uint8_t *sector_cpr_mai;
208 uint8_t *sector_edc;
210
211 /* Metadata & geometry */
213 uint8_t *metadata_block;
214 uint8_t *cicm_block;
215 uint8_t *json_block;
216 uint8_t *creator;
217 uint8_t *media_title;
218 uint8_t *comments;
220 uint8_t *media_model;
222 uint8_t *media_barcode;
225 uint8_t *drive_model;
227 uint8_t
234 uint32_t cylinders;
235 uint32_t heads;
240
241 /* Optical information */
246
247 /* Integrity & ECC */
250
251 /* Index & deduplication lookup */
252 UT_array *index_entries;
254
255 /* Caches */
258
259 /* High-level summary */
261
262 /* Tags */
265
266 /* Checksums */
268 blake3_hasher *blake3_context;
278
279 /* Write path */
280 uint8_t *writing_buffer;
293 bool rewinded;
295
296 /* Options */
297 uint32_t lzma_dict_size;
300
301 /* Tape-specific structures */
304 bool is_tape;
306
326
327#pragma pack(push, 1)
328
332typedef struct DumpExtent
333{
334 uint64_t start;
335 uint64_t end;
337
338#pragma pack(pop)
339
340#endif // LIBAARUFORMAT_CONTEXT_H
#define MD5_DIGEST_LENGTH
Definition context.h:69
struct TapeFileHashEntry tapeFileHashEntry
CRC64 (ECMA-182) core context and precomputed slicing-by-4 tables.
#define SHA1_DIGEST_LENGTH
Definition sha1.h:39
#define SHA256_DIGEST_LENGTH
Definition sha256.h:38
Version 2 container header with GUID, alignment shifts, and feature negotiation bitmaps.
Definition header.h:107
Header for an Aaru metadata JSON block (identifier == BlockType::AaruMetadataJsonBlock).
Definition metadata.h:120
Header preceding the compressed data payload of a data block (BlockType::DataBlock).
Definition data.h:71
Cache top-level descriptor encapsulating the hash table root and capacity limit.
Definition lru.h:46
Lookup tables and state for Compact Disc EDC/ECC (P/Q) regeneration / verification.
Definition context.h:86
uint8_t * ecc_f_table
Forward (F) ECC table.
Definition context.h:89
bool inited_edc
True once EDC/ECC tables have been initialized.
Definition context.h:87
uint32_t * edc_table
EDC (CRC) lookup table.
Definition context.h:90
uint8_t * ecc_b_table
Backward (B) ECC table (allocated, size implementation-defined).
Definition context.h:88
Collected whole‑image checksums / hashes present in a checksum block.
Definition context.h:100
uint8_t * spamsum
SpamSum fuzzy hash (ASCII), allocated length+1 with trailing 0.
Definition context.h:110
bool hasSha256
True if sha256[] buffer populated.
Definition context.h:103
uint8_t sha1[20]
SHA-1 digest (20 bytes).
Definition context.h:107
uint8_t sha256[32]
SHA-256 digest (32 bytes).
Definition context.h:108
uint8_t md5[16]
MD5 digest (16 bytes).
Definition context.h:106
bool hasSpamSum
True if spamsum pointer allocated and signature read.
Definition context.h:105
bool hasSha1
True if sha1[] buffer populated.
Definition context.h:102
uint8_t blake3[BLAKE3_OUT_LEN]
BLAKE3 digest (32 bytes).
Definition context.h:109
bool hasMd5
True if md5[] buffer populated.
Definition context.h:101
bool hasBlake3
True if blake3[] buffer populated.
Definition context.h:104
Header for a CICM XML metadata block (identifier == BlockType::CicmBlock).
Definition metadata.h:108
Header preceding a version 2 hierarchical deduplication table.
Definition ddt.h:142
Inclusive [start,end] logical sector range contributed by a single hardware environment.
Definition context.h:333
uint64_t end
Ending LBA (inclusive); >= start.
Definition context.h:335
uint64_t start
Starting LBA (inclusive).
Definition context.h:334
In-memory representation of a dump hardware entry plus decoded variable-length fields & extents.
Definition context.h:314
uint8_t * firmware
Firmware version string or NULL.
Definition context.h:320
uint8_t * revision
Hardware revision string or NULL.
Definition context.h:319
uint8_t * model
Model string or NULL.
Definition context.h:318
uint8_t * softwareName
Dump software name or NULL.
Definition context.h:322
struct DumpExtent * extents
Array of extents (entry.extents elements) or NULL.
Definition context.h:316
uint8_t * manufacturer
Manufacturer string (UTF-8) or NULL.
Definition context.h:317
uint8_t * softwareVersion
Dump software version or NULL.
Definition context.h:323
uint8_t * serial
Serial number string or NULL.
Definition context.h:321
DumpHardwareEntry entry
Fixed-size header with lengths & counts.
Definition context.h:315
uint8_t * softwareOperatingSystem
Host operating system string or NULL.
Definition context.h:324
Per-environment length table describing subsequent UTF-8 strings and optional extent array.
Definition dump.h:113
Header that precedes a sequence of dump hardware entries and their variable-length payload.
Definition dump.h:91
Legacy CHS style logical geometry metadata (BlockType::GeometryBlock).
Definition data.h:91
High-level summary of an opened Aaru image containing metadata and media characteristics.
Definition aaru.h:870
Header for a metadata block containing offsets and lengths to UTF-16LE descriptive strings.
Definition metadata.h:69
UT_hash_handle hh
UTHASH handle.
Definition context.h:144
uint64_t key
Key: sector address.
Definition context.h:142
uint64_t value
Value: DDT entry.
Definition context.h:143
Describes a single logical file on a tape medium.
Definition tape.h:134
UT_hash_handle hh
UTHASH handle.
Definition context.h:130
uint64_t key
Composite key: partition << 32 | file.
Definition context.h:128
TapeFileEntry fileEntry
The actual tape file data.
Definition context.h:129
Describes a single physical partition on a tape medium.
Definition tape.h:320
UT_hash_handle hh
UTHASH handle.
Definition context.h:137
uint8_t key
Key: partition.
Definition context.h:135
TapePartitionEntry partitionEntry
The actual tape partition data.
Definition context.h:136
Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).
Definition optical.h:72
Header for an optical tracks block listing track entries.
Definition optical.h:62
Master context representing an open or in‑creation Aaru image.
Definition context.h:172
uint8_t * media_barcode
Barcode of the media represented by the image.
Definition context.h:222
DdtHeader2 user_data_ddt_header
Active user data DDT v2 header (primary table meta).
Definition context.h:189
Checksums checksums
Whole-image checksums discovered.
Definition context.h:269
uint8_t library_major_version
Linked library major version.
Definition context.h:177
uint8_t * creator
Who (person) created the image?
Definition context.h:216
bool deduplicate
Storage deduplication active (duplicates coalesce).
Definition context.h:298
size_t sector_suffix_length
Length of sector_suffix.
Definition context.h:285
bool compression_enabled
True if block compression enabled (writing path).
Definition context.h:299
uint64_t last_written_block
Last written block number (write path).
Definition context.h:283
uint8_t * cicm_block
CICM XML payload.
Definition context.h:214
uint8_t * sector_cpr_mai
DVD sector CPR_MAI (6 bytes) if present.
Definition context.h:207
hash_map_t * sector_hash_map
Deduplication hash map (fingerprint->entry mapping).
Definition context.h:253
uint8_t * sector_prefix_corrected
Corrected variant (post error correction) if stored.
Definition context.h:200
uint64_t * user_data_ddt
Legacy flat DDT pointer (NULL when using v2 mini/big arrays).
Definition context.h:181
sha256_ctx sha256_context
Opaque SHA-256 context for streaming updates.
Definition context.h:272
TrackEntry * data_tracks
Filtered list of data tracks (subset of trackEntries).
Definition context.h:243
uint32_t cylinders
Cylinders of the media represented by the image.
Definition context.h:234
bool calculating_sha256
True if whole-image SHA-256 being calculated on-the-fly.
Definition context.h:275
uint8_t * drive_firmware_revision
Firmware revision of the drive used to read the media represented by the image.
Definition context.h:228
uint8_t * media_serial_number
Serial number of the media represented by the image.
Definition context.h:221
struct CacheHeader block_header_cache
LRU/Cache header for block headers.
Definition context.h:256
uint8_t * sector_ied
DVD sector IED (2 bytes) if present.
Definition context.h:206
md5_ctx md5_context
Opaque MD5 context for streaming updates.
Definition context.h:270
uint64_t * user_data_ddt2
DDT entries (big variant) primary/secondary current.
Definition context.h:187
MetadataBlockHeader metadata_block_header
Metadata block header.
Definition context.h:230
int32_t media_sequence
Number in sequence for the media represented by the image.
Definition context.h:238
uint8_t shift
Legacy overall shift (deprecated by data_shift/table_shift).
Definition context.h:195
uint8_t * sector_prefix
Raw per-sector prefix (e.g., sync+header) uncorrected.
Definition context.h:199
uint64_t * sector_suffix_ddt2
CD sector suffix DDT V2.
Definition context.h:186
tapeFileHashEntry * tape_files
Hash table root for tape files.
Definition context.h:302
uint64_t cached_ddt_offset
File offset of currently cached secondary DDT (0=none).
Definition context.h:190
bool is_tape
True if the image is a tape image.
Definition context.h:304
uint8_t * sector_edc
DVD sector EDC (4 bytes) if present.
Definition context.h:208
bool calculating_sha1
True if whole-image SHA-1 being calculated on-the-fly.
Definition context.h:274
uint8_t * media_model
Model of the media represented by the image.
Definition context.h:220
uint8_t * drive_serial_number
Serial number of the drive used to read the media represented by the image.
Definition context.h:226
CdEccContext * ecc_cd_context
CD ECC/EDC helper tables (allocated on demand).
Definition context.h:248
bool rewinded
True if stream has been rewound after open (write path).
Definition context.h:293
struct CacheHeader block_cache
LRU/Cache header for block payloads.
Definition context.h:257
uint32_t * sector_suffix_ddt
Legacy CD sector suffix DDT.
Definition context.h:184
uint8_t * drive_manufacturer
Manufacturer of the drive used to read the media represented by the image.
Definition context.h:224
bool in_memory_ddt
True if primary (and possibly secondary) DDT loaded.
Definition context.h:196
uint8_t * sector_suffix
Raw per-sector suffix (EDC/ECC) uncorrected.
Definition context.h:201
AaruHeaderV2 header
Parsed container header (v2).
Definition context.h:175
int current_block_offset
Logical offset inside block (units: bytes or sectors depending on path).
Definition context.h:288
bool is_writing
True if context opened/created for writing.
Definition context.h:292
TapeDdtHashEntry * tape_ddt
Hash table root for tape DDT entries.
Definition context.h:182
spamsum_ctx * spamsum_context
Opaque SpamSum context for streaming updates.
Definition context.h:267
CicmMetadataBlock cicm_block_header
CICM metadata header (if present).
Definition context.h:231
size_t sector_prefix_offset
Current position in sector_prefix.
Definition context.h:286
uint8_t * drive_model
Model of the drive used to read the media represented by the image.
Definition context.h:225
BlockHeader current_block_header
Header for block currently being assembled (write path).
Definition context.h:281
int ddt_version
DDT version in use (1=legacy, 2=v2 hierarchical).
Definition context.h:194
uint64_t magic
File magic (AARU_MAGIC) post-open.
Definition context.h:174
uint8_t * writing_buffer
Accumulation buffer for current block data.
Definition context.h:280
uint64_t * sector_prefix_ddt2
CD sector prefix DDT V2.
Definition context.h:185
bool calculating_spamsum
True if whole-image SpamSum being calculated on-the-fly.
Definition context.h:276
uint64_t primary_ddt_offset
File offset of the primary DDT v2 table.
Definition context.h:192
size_t sector_prefix_length
Length of sector_prefix.
Definition context.h:284
mediaTagEntry * mediaTags
Hash table of extra media tags (uthash root).
Definition context.h:264
blake3_hasher * blake3_context
Opaque BLAKE3 context for streaming updates.
Definition context.h:268
bool calculating_blake3
True if whole-image BLAKE3 being calculated on-the-fly.
Definition context.h:277
uint8_t library_minor_version
Linked library minor version;.
Definition context.h:178
struct DumpHardwareEntriesWithData * dump_hardware_entries_with_data
Array of dump hardware entries + strings.
Definition context.h:212
uint64_t next_block_position
Absolute file offset where next block will be written.
Definition context.h:282
bool calculating_md5
True if whole-image MD5 being calculated on-the-fly.
Definition context.h:273
GeometryBlockHeader geometry_block
Logical geometry block (if present).
Definition context.h:229
size_t sector_suffix_offset
Current position in sector_suffix.
Definition context.h:287
uint64_t * cached_secondary_ddt2
Cached secondary table (big entries) or NULL.
Definition context.h:188
uint8_t * json_block
JSON metadata block payload (UTF-8).
Definition context.h:215
uint8_t * media_part_number
Part number of the media represented by the image.
Definition context.h:223
uint8_t * sector_decrypted_title_key
DVD decrypted title key (5 bytes) if present.
Definition context.h:209
AaruMetadataJsonBlockHeader json_block_header
JSON metadata block header (if present).
Definition context.h:233
int writing_buffer_position
Current size / position within writingBuffer.
Definition context.h:289
crc64_ctx * crc64_context
Opaque CRC64 context for streaming updates.
Definition context.h:249
uint32_t sectors_per_track
Sectors per track of the media represented by the image (for variable image, the smallest)
Definition context.h:236
uint8_t * sector_subchannel
Raw 96-byte subchannel (if captured).
Definition context.h:203
uint8_t * comments
Image comments.
Definition context.h:218
uint32_t heads
Heads of the media represented by the image.
Definition context.h:235
FILE * imageStream
Underlying FILE* stream (binary mode).
Definition context.h:176
UT_array * index_entries
Flattened index entries (UT_array of IndexEntry).
Definition context.h:252
uint8_t * mode2_subheaders
MODE2 Form1/Form2 8-byte subheaders (concatenated).
Definition context.h:204
ImageInfo image_info
Exposed high-level image info summary.
Definition context.h:260
uint8_t * sector_id
DVD sector ID (4 bytes) if present.
Definition context.h:205
DumpHardwareHeader dump_hardware_header
Dump hardware header.
Definition context.h:232
sha1_ctx sha1_context
Opaque SHA-1 context for streaming updates.
Definition context.h:271
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
Definition context.h:263
TapePartitionHashEntry * tape_partitions
Hash table root for tape partitions.
Definition context.h:303
uint32_t * sector_prefix_ddt
Legacy CD sector prefix DDT (deprecated by *2).
Definition context.h:183
uint32_t lzma_dict_size
LZMA dictionary size (writing path).
Definition context.h:297
TrackEntry * track_entries
Full track list (tracksHeader.entries elements).
Definition context.h:242
uint8_t number_of_data_tracks
Count of tracks considered "data" (sequence 1..99 heuristics).
Definition context.h:245
uint8_t * sector_suffix_corrected
Corrected suffix if stored separately.
Definition context.h:202
uint8_t * metadata_block
Raw metadata UTF-16LE concatenated strings.
Definition context.h:213
uint64_t cached_ddt_position
Position index of cached secondary DDT.
Definition context.h:191
uint8_t current_track_type
Current track type (when writing optical images with tracks, needed for block compression type).
Definition context.h:290
bool writing_long
True if writing long sectors.
Definition context.h:294
uint8_t * media_title
Title of the media represented by the image.
Definition context.h:217
int32_t last_media_sequence
Last media of the sequence the media represented by the image corresponds to.
Definition context.h:239
size_t mapped_memory_ddt_size
Length of mmapped DDT if userDataDdt is mmapped.
Definition context.h:193
uint8_t * media_manufacturer
Manufacturer of the media represented by the image.
Definition context.h:219
TracksHeader tracks_header
Tracks header (optical) if present.
Definition context.h:244
Minimal ECMA-182 CRC64 incremental state container (running value only).
Definition crc64.h:56
Minimal open-addressing hash map for 64-bit key/value pairs used in deduplication lookup.
Definition hash_map.h:50
Definition md5.h:32
Hash table entry for an arbitrary media tag (e.g., proprietary drive/medium descriptor).
Definition context.h:119
uint8_t * data
Tag data blob (opaque to library core); length bytes long.
Definition context.h:120
int32_t type
Numeric type identifier.
Definition context.h:121
uint32_t length
Length in bytes of data.
Definition context.h:122
UT_hash_handle hh
uthash linkage.
Definition context.h:123