|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include "utarray.h"Go to the source code of this file.
Functions | |
| UT_array * | process_index_v1 (aaruformat_context *ctx) |
| Processes an index block (version 1) from the image stream. | |
| int32_t | verify_index_v1 (aaruformat_context *ctx) |
| Verifies the integrity of an index block (version 1) in the image stream. | |
| UT_array * | process_index_v2 (aaruformat_context *ctx) |
| Processes an index block (version 2) from the image stream. | |
| int32_t | verify_index_v2 (aaruformat_context *ctx) |
| Verifies the integrity of an index block (version 2) in the image stream. | |
| UT_array * | process_index_v3 (aaruformat_context *ctx) |
| Processes an index block (version 3) from the image stream. | |
| int32_t | verify_index_v3 (aaruformat_context *ctx) |
| Verifies the integrity of an index block (version 3) in the image stream. | |
| int32_t | process_data_block (aaruformat_context *ctx, IndexEntry *entry) |
| Processes a data 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. | |
| int32_t | process_ddt_v2 (aaruformat_context *ctx, IndexEntry *entry, bool *found_user_data_ddt) |
| Processes a DDT v2 block from the image stream. | |
| void | process_metadata_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a 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_tracks_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Parse and integrate a Tracks block from the image stream into the context. | |
| void | process_cicm_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a CICM XML 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_dumphw_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a dump hardware block from the image stream. | |
| void | process_checksum_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a checksum 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_tape_partitions_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a tape partition metadata block from the image stream. | |
| int32_t | decode_ddt_entry_v1 (aaruformat_context *ctx, uint64_t sector_address, uint64_t *offset, uint64_t *block_offset, uint8_t *sector_status) |
| Decodes a DDT v1 entry for a given sector address. | |
| int32_t | decode_ddt_entry_v2 (aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t *offset, uint64_t *block_offset, uint8_t *sector_status) |
| Decodes a DDT v2 entry for a given sector address. | |
| int32_t | decode_ddt_single_level_v2 (aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t *offset, uint64_t *block_offset, uint8_t *sector_status) |
| Decodes a single-level DDT v2 entry for a given sector address. | |
| int32_t | decode_ddt_multi_level_v2 (aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t *offset, uint64_t *block_offset, uint8_t *sector_status) |
| Decodes a multi-level DDT v2 entry for a given sector address. | |
| bool | set_ddt_entry_v2 (aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t offset, uint64_t block_offset, uint8_t sector_status, uint64_t *ddt_entry) |
| Sets a DDT v2 entry for a given sector address. | |
| bool | set_ddt_single_level_v2 (aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t offset, uint64_t block_offset, uint8_t sector_status, uint64_t *ddt_entry) |
| Sets a single-level DDT v2 entry for a given sector address. | |
| bool | set_ddt_multi_level_v2 (aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t offset, uint64_t block_offset, uint8_t sector_status, uint64_t *ddt_entry) |
| Sets a multi-level DDT v2 entry for a given sector address. | |
| bool | set_ddt_tape (aaruformat_context *ctx, uint64_t sector_address, uint64_t offset, uint64_t block_offset, uint8_t sector_status, uint64_t *ddt_entry) |
| Sets a DDT entry for tape media using a hash-based lookup table. | |
| aaru_options | parse_options (const char *options) |
| Parses the options string for AaruFormat image creation/opening. | |
| uint64_t | get_filetime_uint64 () |
| Gets the current time as a 64-bit FILETIME value. | |
| int32_t | aaruf_close_current_block (aaruformat_context *ctx) |
| Finalizes and writes the current data block to the AaruFormat image file. | |
| int | compare_extents (const void *a, const void *b) |
| Comparison function for sorting DumpExtent arrays by start sector. | |
| void | generate_random_bytes (uint8_t *buffer, size_t length) |
| Generates cryptographically strong random bytes. | |
| int32_t aaruf_close_current_block | ( | aaruformat_context * | ctx | ) |
Finalizes and writes the current data block to the AaruFormat image file.
This function completes the current writing block by computing checksums, optionally compressing the buffered sector data, writing the block header and data to the image file, updating the index, and cleaning up resources. It is called automatically when a block is full (reaches maximum size determined by dataShift), when sector size changes, or when image finalization begins. The function supports multiple compression algorithms (FLAC for audio, LZMA for data) with automatic fallback to uncompressed storage if compression is ineffective.
Block Finalization Sequence:
Compression Handling:
Index Entry Creation:
Each closed block is registered in the index with:
This enables efficient block lookup during image reading via binary search on index entries.
File Layout:
Written to ctx->imageStream at ctx->nextBlockPosition:
Next Block Position Calculation:
After writing, nextBlockPosition is updated to the next aligned boundary:
This ensures all blocks begin on properly aligned file offsets for efficient I/O.
Resource Cleanup:
Before returning, the function:
This prepares the context for the next block or signals that no block is currently open.
| ctx | Pointer to an initialized aaruformatContext in write mode. |
| AARUF_STATUS_OK | (0) Successfully finalized and wrote the block. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_READ_ONLY | (-22) Attempting to finalize block on read-only image. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. This occurs when:
|
| AARUF_ERROR_CANNOT_WRITE_BLOCK_HEADER | (-23) Failed to write block header. This occurs when:
|
| AARUF_ERROR_CANNOT_WRITE_BLOCK_DATA | (-24) Failed to write block data. This occurs when:
|
Definition at line 1427 of file write.c.
References AARU_MAGIC, aaruf_crc64_data(), aaruf_crc64_final(), aaruf_crc64_free(), aaruf_crc64_init(), aaruf_crc64_update(), AARUF_ERROR_CANNOT_WRITE_BLOCK_DATA, AARUF_ERROR_CANNOT_WRITE_BLOCK_HEADER, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, aaruf_flac_encode_redbook_buffer(), aaruf_lzma_encode_buffer(), AARUF_READ_ONLY, AARUF_STATUS_OK, DdtHeader2::blockAlignmentShift, IndexEntry::blockType, BlockHeader::cmpCrc64, BlockHeader::cmpLength, BlockHeader::compression, BlockHeader::crc64, aaruformat_context::crc64_context, aaruformat_context::current_block_header, aaruformat_context::current_block_offset, DataBlock, IndexEntry::dataType, aaruformat_context::dirty_index_block, FATAL, Flac, aaruformat_context::imageStream, aaruformat_context::index_entries, aaruformat_context::is_writing, BlockHeader::length, Lzma, aaruformat_context::lzma_dict_size, LZMA_PROPERTIES_LENGTH, aaruformat_context::magic, MAX_FLAKE_BLOCK, MIN_FLAKE_BLOCK, aaruformat_context::next_block_position, None, IndexEntry::offset, SAMPLES_PER_SECTOR, BlockHeader::sectorSize, TRACE, aaruformat_context::user_data_ddt_header, UserData, aaruformat_context::writing_buffer, and aaruformat_context::writing_buffer_position.
Referenced by aaruf_close(), aaruf_write_sector(), and set_ddt_multi_level_v2().
| int compare_extents | ( | const void * | a, |
| const void * | b ) |
Comparison function for sorting DumpExtent arrays by start sector.
This function is used by qsort() to order dump extents in ascending order based on their start sector values. Extents with lower start sectors will appear first in the sorted array. This ordering is important for efficient extent lookup and validation during image operations.
| a | Pointer to the first DumpExtent to compare. |
| b | Pointer to the second DumpExtent to compare. |
Definition at line 459 of file helpers.c.
References DumpExtent::start.
Referenced by aaruf_set_dumphw(), and process_dumphw_block().
| int32_t decode_ddt_entry_v1 | ( | aaruformat_context * | ctx, |
| const uint64_t | sector_address, | ||
| uint64_t * | offset, | ||
| uint64_t * | block_offset, | ||
| uint8_t * | sector_status ) |
Decodes a DDT v1 entry for a given sector address.
Determines the offset and block offset for a sector using the DDT v1 table. This function performs bit manipulation on the DDT entry to extract the sector offset within a block and the block offset, and determines whether the sector was dumped or not based on the DDT entry value.
| ctx | Pointer to the aaruformat context containing the loaded DDT table. |
| sector_address | Logical sector address to decode (must be within valid range). |
| offset | Pointer to store the resulting sector offset within the block. |
| block_offset | Pointer to store the resulting block offset in the image. |
| sector_status | Pointer to store the sector status (dumped or not dumped). |
| AARUF_STATUS_OK | (0) Successfully decoded the DDT entry. This is always returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). This is the only error condition that can occur in this function. |
Definition at line 405 of file ddt_v1.c.
References AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, aaruformat_context::imageStream, SectorStatusDumped, SectorStatusNotDumped, aaruformat_context::shift, TRACE, and aaruformat_context::user_data_ddt.
Referenced by aaruf_read_sector().
| int32_t decode_ddt_entry_v2 | ( | aaruformat_context * | ctx, |
| const uint64_t | sector_address, | ||
| bool | negative, | ||
| uint64_t * | offset, | ||
| uint64_t * | block_offset, | ||
| uint8_t * | sector_status ) |
Decodes a DDT v2 entry for a given sector address.
Determines the offset and block offset for a sector using the DDT v2 table(s). This function acts as a dispatcher that automatically selects between single-level and multi-level DDT decoding based on the tableShift parameter in the DDT header. It provides a unified interface for DDT v2 entry decoding regardless of the underlying table structure complexity.
| ctx | Pointer to the aaruformat context containing the loaded DDT structures. |
| sector_address | Logical sector address to decode (will be adjusted for negative sectors). |
| negative | Indicates if the sector address is negative. |
| offset | Pointer to store the resulting sector offset within the block. |
| block_offset | Pointer to store the resulting block offset in the image. |
| sector_status | Pointer to store the sector status (dumped, not dumped, etc.). |
| AARUF_STATUS_OK | (0) Successfully decoded the DDT entry. This is always returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). This is the only error condition that can occur at this dispatcher level. |
| Other | error codes may be returned by the underlying decoding functions:
|
Definition at line 507 of file ddt_v2.c.
References AARUF_ERROR_NOT_AARUFORMAT, decode_ddt_multi_level_v2(), decode_ddt_single_level_v2(), FATAL, aaruformat_context::imageStream, DdtHeader2::tableShift, TRACE, and aaruformat_context::user_data_ddt_header.
Referenced by aaruf_read_sector().
| int32_t decode_ddt_multi_level_v2 | ( | aaruformat_context * | ctx, |
| uint64_t | sector_address, | ||
| bool | negative, | ||
| uint64_t * | offset, | ||
| uint64_t * | block_offset, | ||
| uint8_t * | sector_status ) |
Decodes a multi-level DDT v2 entry for a given sector address.
Used when the DDT table uses multi-level indirection (tableShift > 0). This function handles the complex process of navigating a hierarchical DDT structure where the primary table points to secondary tables that contain the actual sector mappings. It includes caching mechanisms for secondary tables, supports both compressed and uncompressed secondary tables, and performs comprehensive validation including CRC verification.
| ctx | Pointer to the aaruformat context containing the loaded primary DDT table. |
| sector_address | Logical sector address to decode (adjusted for negative sectors). |
| negative | Indicates if the sector address is negative. |
| offset | Pointer to store the resulting sector offset within the block. |
| block_offset | Pointer to store the resulting block offset in the image. |
| sector_status | Pointer to store the sector status (dumped, not dumped, etc.). |
| AARUF_STATUS_OK | (0) Successfully decoded the DDT entry. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). |
| AARUF_ERROR_CANNOT_READ_BLOCK | (-7) Configuration, validation, or file access errors. This occurs when:
|
| AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK | (-17) LZMA decompression failed for secondary DDT. This occurs when:
|
| AARUF_ERROR_INVALID_BLOCK_CRC | (-18) CRC64 validation failed for secondary DDT. This occurs when:
|
Definition at line 724 of file ddt_v2.c.
References aaruf_crc64_final(), aaruf_crc64_init(), aaruf_crc64_update(), AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_ERROR_NOT_AARUFORMAT, aaruf_lzma_decode_buffer(), AARUF_STATUS_OK, DdtHeader2::blockAlignmentShift, aaruformat_context::cached_ddt_offset, aaruformat_context::cached_secondary_ddt2, DdtHeader2::cmpLength, DdtHeader2::compression, DdtHeader2::crc64, DdtHeader2::dataShift, DeDuplicationTableSecondary, FATAL, DdtHeader2::identifier, aaruformat_context::imageStream, DdtHeader2::length, Lzma, LZMA_PROPERTIES_LENGTH, DdtHeader2::negative, None, SectorStatusNotDumped, DdtHeader2::tableShift, TRACE, DdtHeader2::type, aaruformat_context::user_data_ddt2, aaruformat_context::user_data_ddt_header, and UserData.
Referenced by decode_ddt_entry_v2().
| int32_t decode_ddt_single_level_v2 | ( | aaruformat_context * | ctx, |
| uint64_t | sector_address, | ||
| bool | negative, | ||
| uint64_t * | offset, | ||
| uint64_t * | block_offset, | ||
| uint8_t * | sector_status ) |
Decodes a single-level DDT v2 entry for a given sector address.
Used when the DDT table does not use multi-level indirection (tableShift = 0). This function performs direct lookup in the primary DDT table to extract sector offset, block offset, and sector status information. It performs bit manipulation to decode the packed DDT entry values.
| ctx | Pointer to the aaruformat context containing the loaded DDT table. |
| sector_address | Logical sector address to decode (adjusted for negative sectors). |
| negative | Indicates if the sector address is negative. |
| offset | Pointer to store the resulting sector offset within the block. |
| block_offset | Pointer to store the resulting block offset in the image. |
| sector_status | Pointer to store the sector status (dumped, not dumped, etc.). |
| AARUF_STATUS_OK | (0) Successfully decoded the DDT entry. This is always returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). |
| AARUF_ERROR_CANNOT_READ_BLOCK | (-7) Configuration or validation errors. This occurs when:
|
Definition at line 581 of file ddt_v2.c.
References AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, DdtHeader2::blockAlignmentShift, DdtHeader2::dataShift, FATAL, aaruformat_context::imageStream, DdtHeader2::negative, SectorStatusNotDumped, DdtHeader2::tableShift, TRACE, aaruformat_context::user_data_ddt2, and aaruformat_context::user_data_ddt_header.
Referenced by decode_ddt_entry_v2().
| void generate_random_bytes | ( | uint8_t * | buffer, |
| size_t | length ) |
Generates cryptographically strong random bytes.
This function fills the provided buffer with random bytes using platform-appropriate cryptographic random number generators. On Unix-like systems (including macOS and Linux), it reads from /dev/urandom. On Windows, it uses CryptGenRandom. If the platform-specific methods fail, it falls back to a time-seeded pseudo-random generator.
| buffer | Pointer to the buffer to fill with random bytes. |
| length | Number of random bytes to generate. |
Definition at line 480 of file helpers.c.
Referenced by aaruf_create().
| uint64_t get_filetime_uint64 | ( | ) |
Gets the current time as a 64-bit FILETIME value.
Returns the current system time as a 64-bit value compatible with Windows FILETIME (number of 100-nanosecond intervals since January 1, 1601 UTC).
Definition at line 45 of file time.c.
Referenced by aaruf_create(), and aaruf_open().
| aaru_options parse_options | ( | const char * | options | ) |
Parses the options string for AaruFormat image creation/opening.
Parses the options string and returns a struct with the parsed options for image creation or opening.
| options | String with options to parse (may be NULL). |
Definition at line 38 of file options.c.
References aaru_options::blake3, aaru_options::block_alignment, aaru_options::compress, aaru_options::data_shift, aaru_options::deduplicate, aaru_options::dictionary, aaru_options::md5, aaru_options::sha1, aaru_options::sha256, aaru_options::spamsum, aaru_options::table_shift, and TRACE.
Referenced by aaruf_create(), and aaruf_open().
| 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.
Reads an Aaru metadata JSON block from the image file and loads its contents into the context for subsequent retrieval. The Aaru metadata JSON format is a structured representation of comprehensive image metadata including media information, imaging session details, hardware configuration, optical disc tracks and sessions, checksums, and preservation metadata. The JSON payload is stored in its original form without parsing or interpretation by this function, allowing higher-level code to process the structured data as needed.
This function is called during the image opening process (aaruf_open) when an index entry indicates the presence of an AaruMetadataJsonBlock. The function is non-critical; if reading fails or memory allocation fails, the error is logged but the image opening continues. This allows images without JSON metadata or with corrupted JSON blocks to still be opened for data access.
Processing sequence:
Memory allocation: The function allocates memory (via malloc) sized to hold the entire JSON payload as specified by ctx->jsonBlockHeader.length. This memory remains allocated for the lifetime of the context and is freed during aaruf_close(). If allocation fails, the function returns gracefully without the JSON metadata, allowing the image to still be opened.
Image size tracking: The function increments ctx->imageInfo.ImageSize by the length of the JSON payload to track the total size of metadata and structural blocks in the image.
Error handling: All errors are non-fatal and handled gracefully:
In all error cases, the ctx->jsonBlockHeader is zeroed (memset to 0) to indicate that no valid JSON metadata is available, and any allocated memory is properly freed.
| ctx | Pointer to an initialized aaruformatContext being populated during image opening. Must not be NULL. ctx->imageStream must be open and readable. On success, ctx->jsonBlockHeader will contain the block header and ctx->jsonBlock will point to the allocated JSON data. |
| entry | Pointer to the IndexEntry that specifies the file offset where the AaruMetadataJsonBlock begins. Must not be NULL. entry->offset indicates the position of the block header in the file. |
Definition at line 475 of file metadata.c.
References AaruMetadataJsonBlock, FATAL, AaruMetadataJsonBlockHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::json_block, aaruformat_context::json_block_header, AaruMetadataJsonBlockHeader::length, IndexEntry::offset, and TRACE.
Referenced by aaruf_open().
| void process_checksum_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a checksum block from the image stream.
Reads a checksum block, parses its entries, and stores the checksums (MD5, SHA1, SHA256, SpamSum) in the context.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the checksum block. |
Definition at line 39 of file checksum.c.
References ChecksumBlock, aaruformat_context::checksums, ChecksumHeader::entries, FATAL, Checksums::hasMd5, Checksums::hasSha1, Checksums::hasSha256, Checksums::hasSpamSum, ChecksumHeader::identifier, aaruformat_context::imageStream, ChecksumEntry::length, ChecksumHeader::length, Md5, Checksums::md5, MD5_DIGEST_LENGTH, IndexEntry::offset, Sha1, Checksums::sha1, SHA1_DIGEST_LENGTH, Sha256, Checksums::sha256, SHA256_DIGEST_LENGTH, SpamSum, Checksums::spamsum, TRACE, and ChecksumEntry::type.
Referenced by aaruf_open().
| void process_cicm_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a CICM XML metadata block from the image stream.
Reads a CICM XML metadata block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the CICM block. |
Definition at line 311 of file metadata.c.
References aaruformat_context::cicm_block, aaruformat_context::cicm_block_header, CicmBlock, FATAL, CicmMetadataBlock::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, CicmMetadataBlock::length, IndexEntry::offset, and TRACE.
Referenced by aaruf_open().
| int32_t process_data_block | ( | aaruformat_context * | ctx, |
| IndexEntry * | entry ) |
Processes a data block from the image stream.
Reads a data block from the image, decompresses if needed, and updates the context with its contents. This function handles various types of data blocks including compressed (LZMA) and uncompressed data, performs CRC validation, and stores the processed data in the appropriate context fields.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the data block. |
| AARUF_STATUS_OK | (0) Successfully processed the data block. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). |
| AARUF_ERROR_CANNOT_READ_BLOCK | (-7) Failed to seek to the block position in the image stream. This occurs when fseek() fails or the file position doesn't match the expected offset. |
| AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK | (-17) LZMA decompression failed. This can happen when:
|
Definition at line 71 of file data.c.
References aaruf_crc64_data(), aaruf_cst_untransform(), AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, aaruf_get_media_tag_type_for_datatype(), aaruf_lzma_decode_buffer(), AARUF_STATUS_OK, AARUF_VERSION_V1, AppleProfileTag, AppleProfileTagAaru, AppleSonyTag, AppleSonyTagAaru, IndexEntry::blockType, bswap_64, CdSectorEcc, CdSectorEccP, CdSectorEccQ, CdSectorEdc, CdSectorHeader, CdSectorPrefix, CdSectorPrefixCorrected, CdSectorSubchannel, CdSectorSubchannelAaru, CdSectorSubHeader, CdSectorSuffix, CdSectorSuffixCorrected, CdSectorSync, BlockHeader::cmpLength, CompactDiscMode2Subheader, BlockHeader::compression, BlockHeader::crc64, mediaTagEntry::data, IndexEntry::dataType, DvdCmi, DvdSectorCprMai, DvdSectorEdc, DvdSectorEdcAaru, DvdSectorId, DvdSectorIed, DvdSectorIedAaru, DvdSectorInformation, DvdSectorNumber, DvdSectorTitleKeyDecrypted, DvdTitleKeyDecrypted, FATAL, aaruformat_context::header, BlockHeader::identifier, aaruformat_context::image_info, AaruHeaderV2::imageMajorVersion, ImageInfo::ImageSize, aaruformat_context::imageStream, BlockHeader::length, mediaTagEntry::length, Lzma, LZMA_PROPERTIES_LENGTH, LzmaClauniaSubchannelTransform, aaruformat_context::mediaTags, aaruformat_context::mode2_subheaders, NoData, None, IndexEntry::offset, PriamDataTowerTag, PriamDataTowerTagAaru, aaruformat_context::readableSectorTags, aaruformat_context::sector_cpr_mai, aaruformat_context::sector_decrypted_title_key, aaruformat_context::sector_edc, aaruformat_context::sector_id, aaruformat_context::sector_ied, aaruformat_context::sector_prefix, aaruformat_context::sector_prefix_corrected, aaruformat_context::sector_subchannel, aaruformat_context::sector_suffix, aaruformat_context::sector_suffix_corrected, ImageInfo::SectorSize, BlockHeader::sectorSize, TRACE, BlockHeader::type, mediaTagEntry::type, and UserData.
Referenced by aaruf_open().
| int32_t process_ddt_v1 | ( | aaruformat_context * | ctx, |
| IndexEntry * | entry, | ||
| bool * | found_user_data_ddt ) |
Processes a DDT v1 block from the image stream.
Reads and decompresses (if needed) a DDT v1 block, verifies its integrity, and loads it into memory or maps it. This function handles both user data DDT blocks and CD sector prefix/suffix corrected DDT blocks, supporting both LZMA compression and uncompressed formats. On Linux, uncompressed blocks can be memory-mapped for improved performance.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the DDT block. |
| found_user_data_ddt | Pointer to a boolean that will be set to true if a user data DDT was found and loaded. |
| AARUF_STATUS_OK | (0) Successfully processed the DDT block. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). |
| AARUF_ERROR_CANNOT_READ_BLOCK | (-7) Failed to access the DDT block in the image stream. This occurs when:
|
| AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK | (-17) LZMA decompression failed. This can happen when:
|
Definition at line 85 of file ddt_v1.c.
References AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, aaruf_lzma_decode_buffer(), AARUF_STATUS_OK, CdSectorPrefixCorrected, CdSectorSuffixCorrected, DdtHeader::cmpLength, DdtHeader::compression, IndexEntry::dataType, aaruformat_context::ddt_version, DdtHeader::entries, FATAL, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::in_memory_ddt, DdtHeader::length, Lzma, LZMA_PROPERTIES_LENGTH, None, IndexEntry::offset, aaruformat_context::sector_prefix_ddt, aaruformat_context::sector_suffix_ddt, ImageInfo::Sectors, aaruformat_context::shift, DdtHeader::shift, TRACE, aaruformat_context::user_data_ddt, and UserData.
Referenced by aaruf_open().
| int32_t process_ddt_v2 | ( | aaruformat_context * | ctx, |
| IndexEntry * | entry, | ||
| bool * | found_user_data_ddt ) |
Processes a DDT v2 block from the image stream.
Reads and decompresses (if needed) a DDT v2 block, verifies its CRC, and loads it into memory. This function handles both user data DDT blocks and CD sector prefix/suffix corrected DDT blocks, supporting both LZMA compression and uncompressed formats. It performs CRC64 validation and stores the processed DDT data in the appropriate context fields based on size type (small/big).
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the DDT block. |
| found_user_data_ddt | Pointer to a boolean that will be set to true if a user data DDT was found and loaded. |
| AARUF_STATUS_OK | (0) Successfully processed the DDT block. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context or image stream is invalid (NULL pointers). |
| AARUF_ERROR_CANNOT_READ_BLOCK | (-7) Failed to access the DDT block in the image stream. This occurs when:
|
| AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK | (-17) LZMA decompression failed. This can happen when:
|
| AARUF_ERROR_INVALID_BLOCK_CRC | (-18) CRC64 validation failed. This occurs when:
|
Definition at line 96 of file ddt_v2.c.
References aaruf_crc64_final(), aaruf_crc64_init(), aaruf_crc64_update(), AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_ERROR_NOT_AARUFORMAT, aaruf_lzma_decode_buffer(), AARUF_STATUS_OK, DdtHeader2::blocks, CdSectorPrefix, CdSectorSuffix, DdtHeader2::cmpLength, DdtHeader2::compression, DdtHeader2::crc64, IndexEntry::dataType, aaruformat_context::ddt_version, FATAL, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::in_memory_ddt, DdtHeader2::length, Lzma, LZMA_PROPERTIES_LENGTH, DdtHeader2::negative, None, IndexEntry::offset, DdtHeader2::overflow, aaruformat_context::primary_ddt_offset, aaruformat_context::sector_prefix_ddt2, aaruformat_context::sector_suffix_ddt2, ImageInfo::Sectors, TRACE, aaruformat_context::user_data_ddt2, aaruformat_context::user_data_ddt_header, and UserData.
Referenced by aaruf_open().
| void process_dumphw_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a dump hardware block from the image stream.
Reads a dump hardware block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the dump hardware block. |
Definition at line 107 of file dump.c.
References aaruf_crc64_data(), AARUF_VERSION_V1, IndexEntry::blockType, bswap_64, compare_extents(), DumpHardwareHeader::crc64, aaruformat_context::dump_hardware_entries_with_data, aaruformat_context::dump_hardware_header, DumpHardwareBlock, DumpHardwareHeader::entries, DumpHardwareEntriesWithData::entry, DumpHardwareEntriesWithData::extents, DumpHardwareEntry::extents, FATAL, DumpHardwareEntriesWithData::firmware, DumpHardwareEntry::firmwareLength, free_dump_hardware_entries_array(), aaruformat_context::header, DumpHardwareHeader::identifier, AaruHeaderV2::imageMajorVersion, aaruformat_context::imageStream, DumpHardwareHeader::length, DumpHardwareEntriesWithData::manufacturer, DumpHardwareEntry::manufacturerLength, DumpHardwareEntriesWithData::model, DumpHardwareEntry::modelLength, IndexEntry::offset, read_dump_string(), reset_dump_hardware_context(), DumpHardwareEntriesWithData::revision, DumpHardwareEntry::revisionLength, DumpHardwareEntriesWithData::serial, DumpHardwareEntry::serialLength, DumpHardwareEntriesWithData::softwareName, DumpHardwareEntry::softwareNameLength, DumpHardwareEntriesWithData::softwareOperatingSystem, DumpHardwareEntry::softwareOperatingSystemLength, DumpHardwareEntriesWithData::softwareVersion, DumpHardwareEntry::softwareVersionLength, and TRACE.
Referenced by aaruf_open().
| void process_geometry_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a logical geometry block from the image stream.
Reads a logical geometry block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the geometry block. |
Definition at line 251 of file metadata.c.
References aaruformat_context::cylinders, GeometryBlockHeader::cylinders, FATAL, aaruformat_context::geometry_block, GeometryBlock, aaruformat_context::heads, GeometryBlockHeader::heads, GeometryBlockHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, IndexEntry::offset, aaruformat_context::sectors_per_track, GeometryBlockHeader::sectorsPerTrack, and TRACE.
Referenced by aaruf_open().
| UT_array * process_index_v1 | ( | aaruformat_context * | ctx | ) |
Processes an index block (version 1) from the image stream.
Reads and parses an index block (version 1) from the image, returning an array of index entries. This function handles the legacy index format used in early AaruFormat versions, providing compatibility with older image files. It reads the IndexHeader structure followed by a sequential list of IndexEntry structures, validating the index identifier for format correctness.
| ctx | Pointer to the aaruformat context containing the image stream and header information. |
| UT_array* | Successfully processed the index block. This is returned when:
|
| NULL | Index processing failed. This occurs when:
|
Definition at line 79 of file index_v1.c.
References IndexHeader::entries, FATAL, aaruformat_context::header, IndexHeader::identifier, aaruformat_context::imageStream, IndexBlock, AaruHeaderV2::indexOffset, and TRACE.
Referenced by aaruf_open(), and aaruf_verify_image().
| UT_array * process_index_v2 | ( | aaruformat_context * | ctx | ) |
Processes an index block (version 2) from the image stream.
Reads and parses an index block (version 2) from the image, returning an array of index entries. This function handles the intermediate index format used in mid-generation AaruFormat versions, providing compatibility with version 2 image files. It reads the IndexHeader2 structure followed by a sequential list of IndexEntry structures, validating the index identifier for format correctness.
| ctx | Pointer to the aaruformat context containing the image stream and header information. |
| UT_array* | Successfully processed the index block. This is returned when:
|
| NULL | Index processing failed. This occurs when:
|
Definition at line 81 of file index_v2.c.
References IndexHeader2::entries, FATAL, aaruformat_context::header, IndexHeader2::identifier, aaruformat_context::imageStream, IndexBlock2, AaruHeaderV2::indexOffset, and TRACE.
Referenced by aaruf_open(), and aaruf_verify_image().
| UT_array * process_index_v3 | ( | aaruformat_context * | ctx | ) |
Processes an index block (version 3) from the image stream.
Reads and parses an index block (version 3) from the image, returning an array of index entries. This function handles the advanced index format used in current AaruFormat versions, supporting hierarchical subindex structures for improved scalability. It reads the IndexHeader3 structure followed by index entries, recursively processing any subindex blocks encountered to create a flattened array of all index entries.
| ctx | Pointer to the aaruformat context containing the image stream and header information. |
| UT_array* | Successfully processed the index block and all subindexes. This is returned when:
|
| NULL | Index processing failed. This occurs when:
|
Definition at line 98 of file index_v3.c.
References add_subindex_entries(), IndexEntry::blockType, IndexHeader3::entries, FATAL, aaruformat_context::header, IndexHeader3::identifier, aaruformat_context::imageStream, IndexBlock3, AaruHeaderV2::indexOffset, and TRACE.
Referenced by aaruf_open(), and aaruf_verify_image().
| void process_metadata_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a metadata block from the image stream.
Reads a metadata block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the metadata block. |
Definition at line 35 of file metadata.c.
References MetadataBlockHeader::blockSize, IndexEntry::blockType, aaruformat_context::comments, MetadataBlockHeader::commentsLength, MetadataBlockHeader::commentsOffset, aaruformat_context::creator, MetadataBlockHeader::creatorLength, MetadataBlockHeader::creatorOffset, aaruformat_context::drive_firmware_revision, aaruformat_context::drive_manufacturer, aaruformat_context::drive_model, aaruformat_context::drive_serial_number, MetadataBlockHeader::driveFirmwareRevisionLength, MetadataBlockHeader::driveFirmwareRevisionOffset, MetadataBlockHeader::driveManufacturerLength, MetadataBlockHeader::driveManufacturerOffset, MetadataBlockHeader::driveModelLength, MetadataBlockHeader::driveModelOffset, MetadataBlockHeader::driveSerialNumberLength, MetadataBlockHeader::driveSerialNumberOffset, FATAL, MetadataBlockHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::last_media_sequence, MetadataBlockHeader::lastMediaSequence, aaruformat_context::media_barcode, aaruformat_context::media_manufacturer, aaruformat_context::media_model, aaruformat_context::media_part_number, aaruformat_context::media_sequence, aaruformat_context::media_serial_number, aaruformat_context::media_title, MetadataBlockHeader::mediaBarcodeLength, MetadataBlockHeader::mediaBarcodeOffset, MetadataBlockHeader::mediaManufacturerLength, MetadataBlockHeader::mediaManufacturerOffset, MetadataBlockHeader::mediaModelLength, MetadataBlockHeader::mediaModelOffset, MetadataBlockHeader::mediaPartNumberLength, MetadataBlockHeader::mediaPartNumberOffset, MetadataBlockHeader::mediaSequence, MetadataBlockHeader::mediaSerialNumberLength, MetadataBlockHeader::mediaSerialNumberOffset, MetadataBlockHeader::mediaTitleLength, MetadataBlockHeader::mediaTitleOffset, aaruformat_context::metadata_block, aaruformat_context::metadata_block_header, IndexEntry::offset, and TRACE.
Referenced by aaruf_open().
| void process_tape_files_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a tape file metadata block from the image stream.
Reads and parses a TapeFileBlock from the Aaru image, validates its integrity, and populates the context's tape file hash table with file layout information. Each tape file entry defines a logical file on the tape medium by specifying its partition, file number, and block range (FirstBlock to LastBlock inclusive).
The function performs the following operations:
Composite Key Construction: Each tape file is uniquely identified by a 64-bit composite key: key = (partition << 32) | file_number This allows files with the same file number in different partitions to coexist in the hash table without conflicts.
Hash Table Management: The function uses HASH_REPLACE to insert entries, which automatically:
Error Handling: The function treats most errors as non-fatal and continues processing:
Block Structure: The tape file block consists of:
CRC64 Validation: The CRC64 checksum in the header is computed over the entire array of TapeFileEntry structures (excluding the header itself). This provides integrity verification to detect corruption in the file table.
Memory Management:
| ctx | Pointer to the aaruformat context. Must not be NULL. The context must have a valid imageStream open for reading. The ctx->tapeFiles hash table will be populated with file entries. The ctx->imageInfo.ImageSize will be updated with the block size. |
| entry | Pointer to the index entry describing the tape file block. Must not be NULL. The entry->offset field indicates the file position where the TapeFileHeader begins. |
Definition at line 126 of file tape.c.
References aaruf_crc64_data(), TapeFileHeader::crc64, aaruformat_context::dirty_tape_file_block, TapeFileHeader::entries, FATAL, TapeFileHashEntry::fileEntry, TapeFileHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, TapeFileHashEntry::key, IndexEntry::offset, aaruformat_context::tape_files, TapeFileBlock, and TRACE.
Referenced by aaruf_open().
| void process_tape_partitions_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a tape partition metadata block from the image stream.
Reads and parses a TapePartitionBlock from the Aaru image, validates its integrity, and populates the context's tape partition hash table with partition layout information. Each tape partition entry defines a physical division of the tape medium by specifying its partition number and block range (FirstBlock to LastBlock inclusive).
The function performs the following operations:
Partition Identification: Each tape partition is uniquely identified by its partition number (0-255). This number serves as the hash table key for fast lookup operations. Most tapes have a single partition (partition 0), but multi-partition formats like LTO, DLT, and AIT support multiple partitions with independent block address spaces.
Hash Table Management: The function uses HASH_REPLACE to insert entries, which automatically:
Error Handling: The function treats most errors as non-fatal and continues processing:
Block Structure: The tape partition block consists of:
CRC64 Validation: The CRC64 checksum in the header is computed over the entire array of TapePartitionEntry structures (excluding the header itself). This provides integrity verification to detect corruption in the partition table.
Partition Block Ranges: Each partition defines a block address space:
Block addresses are local to each partition. Different partitions may have overlapping logical block numbers (e.g., both partition 0 and partition 1 can have blocks numbered 0-1000).
Memory Management:
| ctx | Pointer to the aaruformat context. Must not be NULL. The context must have a valid imageStream open for reading. The ctx->tapePartitions hash table will be populated with partition entries. The ctx->imageInfo.ImageSize will be updated with the block size. |
| entry | Pointer to the index entry describing the tape partition block. Must not be NULL. The entry->offset field indicates the file position where the TapePartitionHeader begins. |
Definition at line 347 of file tape.c.
References aaruf_crc64_data(), TapePartitionHeader::crc64, aaruformat_context::dirty_tape_partition_block, TapePartitionHeader::entries, FATAL, TapePartitionHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, TapePartitionHashEntry::key, TapePartitionEntry::Number, IndexEntry::offset, TapePartitionHashEntry::partitionEntry, aaruformat_context::tape_partitions, TapePartitionBlock, and TRACE.
Referenced by aaruf_open().
| void process_tracks_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Parse and integrate a Tracks block from the image stream into the context.
This function seeks to the byte offset specified by the supplied entry, reads a TracksHeader followed by the declared number of TrackEntry records, validates the block through its CRC64, and populates multiple fields in the provided ctx:
It also performs a legacy endian correction of the computed CRC for images whose major version is <= AARUF_VERSION_V1 (historical writer quirk).
The function is intended for internal library use during image opening / indexing and is NOT part of the stable public API (no versioning guarantees). Callers outside the library should use the higher-level image open helpers that trigger this parsing implicitly.
Error & early-return behavior (no exception mechanism, all via logging + early return):
ctx or NULL ctx->imageStream: Logs FATAL and returns immediately; context left untouched.Memory management:
Filtering rule for ctx->dataTracks:
Thread safety:
ctx without synchronization.Preconditions (
ctx != NULLctx->imageStream is a valid FILE* opened for reading at least up to the block region.entry != NULL and entry->offset points to the start of a well-formed Tracks block.Postconditions (
Limitations / Caveats:
Logging strategy:
| ctx | Mutable pointer to an aaruformatContext receiving parsed track metadata. |
| entry | Pointer to the index entry describing this Tracks block (offset required; size not strictly used beyond informational logging and sequential reading). |
Definition at line 111 of file optical.c.
References aaruf_crc64_data(), AARUF_VERSION_V1, bswap_64, TracksHeader::crc64, aaruformat_context::data_tracks, TracksHeader::entries, FATAL, ImageInfo::HasPartitions, ImageInfo::HasSessions, aaruformat_context::header, TracksHeader::identifier, aaruformat_context::image_info, AaruHeaderV2::imageMajorVersion, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::number_of_data_tracks, IndexEntry::offset, TrackEntry::sequence, TRACE, aaruformat_context::track_entries, aaruformat_context::tracks_header, and TracksBlock.
Referenced by aaruf_open().
| bool set_ddt_entry_v2 | ( | aaruformat_context * | ctx, |
| const uint64_t | sector_address, | ||
| const bool | negative, | ||
| const uint64_t | offset, | ||
| const uint64_t | block_offset, | ||
| const uint8_t | sector_status, | ||
| uint64_t * | ddt_entry ) |
Sets a DDT v2 entry for a given sector address.
Updates the DDT v2 table(s) with the specified offset, block offset, and sector status for a sector.
| ctx | Pointer to the aaruformat context. |
| sector_address | Logical sector address to set. |
| negative | Indicates if the sector address is negative. |
| offset | Offset to set for the sector. |
| block_offset | Block offset to set for the sector. |
| sector_status | Status to set for the sector. |
| ddt_entry | Existing DDT entry or 0 to create a new one. If 0, a new entry is returned. |
| true | if the entry was set successfully, false otherwise. |
Definition at line 988 of file ddt_v2.c.
References FATAL, aaruformat_context::imageStream, set_ddt_multi_level_v2(), set_ddt_single_level_v2(), DdtHeader2::tableShift, TRACE, and aaruformat_context::user_data_ddt_header.
Referenced by aaruf_write_sector().
| bool set_ddt_multi_level_v2 | ( | aaruformat_context * | ctx, |
| uint64_t | sector_address, | ||
| bool | negative, | ||
| uint64_t | offset, | ||
| uint64_t | block_offset, | ||
| uint8_t | sector_status, | ||
| uint64_t * | ddt_entry ) |
Sets a multi-level DDT v2 entry for a given sector address.
Used when the DDT table uses multi-level indirection (tableShift > 0).
| ctx | Pointer to the aaruformat context. |
| sector_address | Logical sector address to set. |
| negative | Indicates if the sector address is negative. |
| offset | Offset to set for the sector. |
| block_offset | Block offset to set for the sector. |
| sector_status | Status to set for the sector. |
| ddt_entry | Existing DDT entry or 0 to create a new one. If 0, a new entry is returned. |
| true | if the entry was set successfully, false otherwise. |
Definition at line 1096 of file ddt_v2.c.
References aaruf_close_current_block(), aaruf_crc64_data(), aaruf_crc64_final(), aaruf_crc64_init(), aaruf_crc64_update(), AARUF_ERROR_NOT_ENOUGH_MEMORY, aaruf_lzma_encode_buffer(), DdtHeader2::blockAlignmentShift, DdtHeader2::blocks, IndexEntry::blockType, aaruformat_context::cached_ddt_offset, aaruformat_context::cached_ddt_position, aaruformat_context::cached_secondary_ddt2, DdtHeader2::cmpCrc64, DdtHeader2::cmpLength, DdtHeader2::compression, aaruformat_context::compression_enabled, DdtHeader2::crc64, DdtHeader2::dataShift, IndexEntry::dataType, DeDuplicationTable2, DeDuplicationTableSecondary, aaruformat_context::dirty_index_block, aaruformat_context::dirty_primary_ddt, aaruformat_context::dirty_secondary_ddt, DdtHeader2::entries, FATAL, DdtHeader2::identifier, aaruformat_context::imageStream, aaruformat_context::index_entries, DdtHeader2::length, DdtHeader2::levels, Lzma, aaruformat_context::lzma_dict_size, LZMA_PROPERTIES_LENGTH, DdtHeader2::negative, aaruformat_context::next_block_position, None, IndexEntry::offset, DdtHeader2::overflow, DdtHeader2::previousLevelOffset, aaruformat_context::primary_ddt_offset, DdtHeader2::start, DdtHeader2::tableLevel, DdtHeader2::tableShift, TRACE, DdtHeader2::type, aaruformat_context::user_data_ddt2, aaruformat_context::user_data_ddt_header, UserData, and aaruformat_context::writing_buffer.
Referenced by set_ddt_entry_v2().
| bool set_ddt_single_level_v2 | ( | aaruformat_context * | ctx, |
| uint64_t | sector_address, | ||
| const bool | negative, | ||
| const uint64_t | offset, | ||
| const uint64_t | block_offset, | ||
| const uint8_t | sector_status, | ||
| uint64_t * | ddt_entry ) |
Sets a single-level DDT v2 entry for a given sector address.
Used when the DDT table does not use multi-level indirection.
| ctx | Pointer to the aaruformat context. |
| sector_address | Logical sector address to set. |
| negative | Indicates if the sector address is negative. |
| offset | Offset to set for the sector. |
| block_offset | Block offset to set for the sector. |
| sector_status | Status to set for the sector. |
| ddt_entry | Existing DDT entry or 0 to create a new one. If 0, a new entry is returned. |
| true | if the entry was set successfully, false otherwise. |
Definition at line 1024 of file ddt_v2.c.
References DdtHeader2::blockAlignmentShift, DdtHeader2::dataShift, aaruformat_context::dirty_single_level_ddt, FATAL, aaruformat_context::imageStream, DdtHeader2::negative, DdtHeader2::tableShift, TRACE, aaruformat_context::user_data_ddt2, and aaruformat_context::user_data_ddt_header.
Referenced by set_ddt_entry_v2().
| bool set_ddt_tape | ( | aaruformat_context * | ctx, |
| uint64_t | sector_address, | ||
| const uint64_t | offset, | ||
| const uint64_t | block_offset, | ||
| const uint8_t | sector_status, | ||
| uint64_t * | ddt_entry ) |
Sets a DDT entry for tape media using a hash-based lookup table.
This function is specifically designed for tape media images where sectors are accessed non-sequentially and the traditional DDT array structure is inefficient. Instead of using a large contiguous array, it uses a hash table (UTHASH) to store only the sectors that have been written, providing sparse storage for tape media.
The function performs the following operations:
DDT Entry Format: The DDT entry is a 64-bit value with the following bit layout:
Hash Table Management: Uses HASH_REPLACE macro from UTHASH library which:
Overflow Detection: The function checks if the constructed DDT entry exceeds 28 bits (0xFFFFFFF). This limit ensures the sector status can fit in the upper 4 bits while leaving room for future extensions in the upper 32 bits.
| ctx | Pointer to the aaruformat context. Must not be NULL. The context must have a valid imageStream and is_tape must be true. The ctx->tapeDdt hash table will be updated with the new entry. The ctx->userDataDdtHeader contains alignment and shift parameters. |
| sector_address | Logical sector address on the tape to set. This serves as the unique key in the hash table. Multiple calls with the same sector_address will replace the previous entry. |
| offset | Byte offset within the aligned block where the sector data begins. This value is masked by (1 << dataShift) - 1 to extract only the lower bits representing the offset within the block. |
| block_offset | Absolute byte offset in the image file where the data block starts. This is right-shifted by blockAlignmentShift to get the block index, which is stored in the DDT entry's middle bits. |
| sector_status | Status flags for the sector (4 bits). Common values include:
|
| ddt_entry | Pointer to a 64-bit value that will receive the constructed DDT entry.
|
| true | Successfully created and inserted the DDT entry. This occurs when:
|
| false | Failed to set the DDT entry. This can happen when:
|
Definition at line 1782 of file ddt_v2.c.
References DdtHeader2::blockAlignmentShift, DdtHeader2::dataShift, aaruformat_context::dirty_tape_ddt, FATAL, aaruformat_context::imageStream, aaruformat_context::is_tape, TapeDdtHashEntry::key, aaruformat_context::tape_ddt, TRACE, aaruformat_context::user_data_ddt_header, and TapeDdtHashEntry::value.
| int32_t verify_index_v1 | ( | aaruformat_context * | ctx | ) |
Verifies the integrity of an index block (version 1) in the image stream.
Checks the CRC64 of the index block without decompressing it. This function performs comprehensive validation of the index structure including header validation, data integrity verification, and version-specific CRC calculation. It ensures the index block is valid and uncorrupted before the image can be safely used for data access.
| ctx | Pointer to the aaruformat context containing image stream and header information. |
| AARUF_STATUS_OK | (0) Successfully verified index integrity. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or stream. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_HEADER | (-6) Index header reading failed. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_INDEX | (-19) Index format or data access errors. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. This occurs when:
|
| AARUF_ERROR_INVALID_BLOCK_CRC | (-18) CRC64 validation failed. This occurs when:
|
Definition at line 225 of file index_v1.c.
References aaruf_crc64_data(), AARUF_ERROR_CANNOT_READ_HEADER, AARUF_ERROR_CANNOT_READ_INDEX, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_STATUS_OK, AARUF_VERSION_V1, bswap_64, IndexHeader::crc64, IndexHeader::entries, FATAL, aaruformat_context::header, IndexHeader::identifier, AaruHeaderV2::imageMajorVersion, aaruformat_context::imageStream, IndexBlock, AaruHeaderV2::indexOffset, and TRACE.
Referenced by aaruf_verify_image().
| int32_t verify_index_v2 | ( | aaruformat_context * | ctx | ) |
Verifies the integrity of an index block (version 2) in the image stream.
Checks the CRC64 of the index block without decompressing it. This function performs comprehensive validation of the version 2 index structure including header validation, data integrity verification, and version-specific CRC calculation. It ensures the index block is valid and uncorrupted before the image can be safely used for data access.
| ctx | Pointer to the aaruformat context containing image stream and header information. |
| AARUF_STATUS_OK | (0) Successfully verified index integrity. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or stream. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_HEADER | (-6) Index header reading failed. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_INDEX | (-19) Index format or data access errors. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. This occurs when:
|
| AARUF_ERROR_INVALID_BLOCK_CRC | (-18) CRC64 validation failed. This occurs when:
|
Definition at line 227 of file index_v2.c.
References aaruf_crc64_final(), aaruf_crc64_free(), aaruf_crc64_init(), aaruf_crc64_update(), AARUF_ERROR_CANNOT_READ_HEADER, AARUF_ERROR_CANNOT_READ_INDEX, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_STATUS_OK, AARUF_VERSION_V1, bswap_64, IndexHeader2::crc64, IndexHeader2::entries, FATAL, aaruformat_context::header, IndexHeader2::identifier, AaruHeaderV2::imageMajorVersion, aaruformat_context::imageStream, IndexBlock2, AaruHeaderV2::indexOffset, and TRACE.
Referenced by aaruf_verify_image().
| int32_t verify_index_v3 | ( | aaruformat_context * | ctx | ) |
Verifies the integrity of an index block (version 3) in the image stream.
Checks the CRC64 of the index block and all subindexes without decompressing them. This function performs comprehensive validation of the advanced version 3 index structure including header validation, data integrity verification, and version-specific CRC calculation. Note that this function validates only the main index block's CRC and does not recursively validate subindex CRCs, focusing on the primary index structure integrity.
| ctx | Pointer to the aaruformat context containing image stream and header information. |
| AARUF_STATUS_OK | (0) Successfully verified index integrity. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or stream. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_HEADER | (-6) Index header reading failed. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_INDEX | (-19) Index format or data access errors. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. This occurs when:
|
| AARUF_ERROR_INVALID_BLOCK_CRC | (-18) CRC64 validation failed. This occurs when:
|
Definition at line 408 of file index_v3.c.
References aaruf_crc64_final(), aaruf_crc64_free(), aaruf_crc64_init(), aaruf_crc64_update(), AARUF_ERROR_CANNOT_READ_HEADER, AARUF_ERROR_CANNOT_READ_INDEX, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_STATUS_OK, AARUF_VERSION_V1, bswap_64, IndexHeader3::crc64, IndexHeader3::entries, FATAL, aaruformat_context::header, IndexHeader3::identifier, AaruHeaderV2::imageMajorVersion, aaruformat_context::imageStream, IndexBlock3, AaruHeaderV2::indexOffset, and TRACE.
Referenced by aaruf_verify_image().