<trclass="memdesc:a5d3b1092abc36a27a441a01a8a0b3b48"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes an index block (version 1) from the image stream. <br/></td></tr>
<trclass="memdesc:a89ed93d216c4dce0ae5e2acccf8cc2b4"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Verifies the integrity of an index block (version 1) in the image stream. <br/></td></tr>
<trclass="memdesc:a1baad6508d1cde5a712794e956fb3d3c"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes an index block (version 2) from the image stream. <br/></td></tr>
<trclass="memdesc:ae234e22b16b085d18614110630034db5"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Verifies the integrity of an index block (version 2) in the image stream. <br/></td></tr>
<trclass="memdesc:aff88fae9938d5f56318bfd7a455d5e94"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes an index block (version 3) from the image stream. <br/></td></tr>
<trclass="memdesc:ad7ed9250463c320c7bc8d83689bcfefb"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Verifies the integrity of an index block (version 3) in the image stream. <br/></td></tr>
<trclass="memdesc:a28d844a06cecbbf436d825a3c99ff0eb"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a data block from the image stream. <br/></td></tr>
<trclass="memdesc:abaf38090f967423898b99e0455751c07"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a DDT v1 block from the image stream. <br/></td></tr>
<trclass="memdesc:a1caeae710ee5e1dd356e43b3b659e9c0"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a DDT v2 block from the image stream. <br/></td></tr>
<trclass="memdesc:a43974d4c183240be30d49ff09ef7b8c2"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a metadata block from the image stream. <br/></td></tr>
<trclass="memdesc:a81d410de6727d95a85b827067e1a8bc6"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a logical geometry block from the image stream. <br/></td></tr>
<trclass="memdesc:a375a516fdf6f81e997365d93b21f6708"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Parse and integrate a Tracks block from the image stream into the context. <br/></td></tr>
<trclass="memdesc:a5e0397faed8aea27c5a6a3881875de54"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a CICM XML metadata block from the image stream. <br/></td></tr>
<trclass="memdesc:a84003ec881425a7b28ec24cb48d19f02"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes an Aaru metadata JSON block from the image stream during image opening. <br/></td></tr>
<trclass="memdesc:a0e2cfc858c0551bc9bef11d5bdb85aac"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a dump hardware block from the image stream. <br/></td></tr>
<trclass="memdesc:a565eace88f86c500249be1f2a89a1c60"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a checksum block from the image stream. <br/></td></tr>
<trclass="memdesc:a829bbac3c17b60efd8f93188a8de8278"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a tape file metadata block from the image stream. <br/></td></tr>
<trclass="memdesc:aa76718b0402b1a28be3d563d5e62028e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Processes a tape partition metadata block from the image stream. <br/></td></tr>
<trclass="memdesc:a26e5fd58cdfd39948f1b724fafffcdc2"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes a DDT v1 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a805d607b45bb8ad8a3e6b0bcfabe3265"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes a DDT v2 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a40c571bc4778040f22ac211cea670db1"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes a single-level DDT v2 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a83aff4d408ab17f8f350cb03b0e12ef6"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Decodes a multi-level DDT v2 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a1906cbcaef9f44b8ac4360beb70a0120"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets a DDT v2 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a7471ae33a70bae7e3aa93a52f8e519ca"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets a single-level DDT v2 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a69ff2e68fe4d92a2d2d469ac69f41d82"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets a multi-level DDT v2 entry for a given sector address. <br/></td></tr>
<trclass="memdesc:a8241636367dc185ee88d1dc5af9caf59"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets a DDT entry for tape media using a hash-based lookup table. <br/></td></tr>
<trclass="memdesc:aaae42bff244df727b6c029f58d4957df"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Parses the options string for AaruFormat image creation/opening. <br/></td></tr>
<trclass="memdesc:a36c1cca0e4cea9c2e0dffb582b836f6f"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Gets the current time as a 64-bit FILETIME value. <br/></td></tr>
<trclass="memdesc:a2402812f5e04ba16765208c0b70fa6c5"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Finalizes and writes the current data block to the AaruFormat image file. <br/></td></tr>
<trclass="memdesc:ac93ebc6d918745be56b680e19bf7e8d5"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Comparison function for sorting <aclass="el"href="structDumpExtent.html"title="Inclusive [start,end] logical sector range contributed by a single hardware environment.">DumpExtent</a> arrays by start sector. <br/></td></tr>
<p>Finalizes and writes the current data block to the AaruFormat image file. </p>
<p>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.</p>
<p><b>Block Finalization Sequence:</b></p>
<oltype="1">
<li><b>Context Validation</b>: Verify context is valid and opened for writing</li>
<li><b>Length Calculation</b>: Set block length = currentBlockOffset × sectorSize</li>
<li><b>CRC64 Computation</b>: Calculate checksum of uncompressed block data</li>
<li>FLAC: For audio tracks, compress using Red Book audio encoding with configurable block size</li>
<li>LZMA: For data tracks, compress using LZMA algorithm with dictionary size optimization</li>
<li>Fallback: If compressed size ≥ uncompressed size, use uncompressed storage</li>
</ul>
</li>
<li><b>Compressed CRC64</b>: Calculate checksum of compressed data (if compression was applied)</li>
<li><b>Index Registration</b>: Add <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> to ctx->indexEntries for block lookup</li>
<li><b>File Writing</b>: Write <aclass="el"href="structBlockHeader.html"title="Header preceding the compressed data payload of a data block (BlockType::DataBlock).">BlockHeader</a>, optional LZMA properties, and block data to image stream</li>
<li><b>Position Update</b>: Calculate next block position with alignment boundary adjustment</li>
<li><b>None (<aclass="el"href="enums_8h.html#affec749ed88365143745313ae9168263"title="List of known compression types.">CompressionType</a> = 0)</b>: No compression applied<ul>
<li>cmpLength = length (uncompressed size)</li>
<li>cmpCrc64 = crc64 (same checksum)</li>
<li>Direct write of ctx->writingBuffer to file</li>
</ul>
</li>
<li><b>FLAC (<aclass="el"href="enums_8h.html#affec749ed88365143745313ae9168263"title="List of known compression types.">CompressionType</a> = 2)</b>: For CD audio tracks (Red Book format)<ul>
<li>Allocates 2× length buffer for compressed data</li>
<li>Calculates optimal FLAC block size (MIN_FLAKE_BLOCK to MAX_FLAKE_BLOCK range)</li>
<li>Pads incomplete blocks with zeros to meet FLAC block size requirements</li>
<li>Encoding parameters: mid-side stereo, Hamming apodization, 12 max LPC order</li>
<li>Falls back to None if compression ineffective (compressed ≥ uncompressed)</li>
</ul>
</li>
<li><b>LZMA (<aclass="el"href="enums_8h.html#affec749ed88365143745313ae9168263"title="List of known compression types.">CompressionType</a> = 1)</b>: For data tracks and non-audio content<ul>
<li>Allocates 2× length buffer for compressed data</li>
<li>LZMA properties: level 9, dictionary size from ctx->lzma_dict_size</li>
<li>Properties stored as 5-byte header: lc=4, lp=0, pb=2, fb=273, threads=8</li>
<li>Falls back to None if compression ineffective (compressed ≥ uncompressed)</li>
<li>Compressed length includes LZMA_PROPERTIES_LENGTH (5 bytes) overhead</li>
</ul>
</li>
</ul>
<p><b>Index Entry Creation:</b></p>
<p>Each closed block is registered in the index with:</p><ul>
<li>blockType = DataBlock (0x4B4C4244)</li>
<li>dataType = UserData (1)</li>
<li>offset = ctx->nextBlockPosition (file position where block was written)</li>
</ul>
<p>This enables efficient block lookup during image reading via binary search on index entries.</p>
<p><b>File Layout:</b></p>
<p>Written to ctx->imageStream at ctx->nextBlockPosition:</p><oltype="1">
<li><aclass="el"href="structBlockHeader.html"title="Header preceding the compressed data payload of a data block (BlockType::DataBlock).">BlockHeader</a> (sizeof(BlockHeader) bytes)</li>
<li>LZMA properties (5 bytes, only if compression = Lzma)</li>
<li>Block data (cmpLength bytes - compressed or uncompressed depending on compression type)</li>
</ol>
<p><b>Next Block Position Calculation:</b></p>
<p>After writing, nextBlockPosition is updated to the next aligned boundary:</p><ul>
<tr><tdclass="paramname">AARUF_ERROR_NOT_ENOUGH_MEMORY</td><td>(-9) Memory allocation failed. This occurs when:<ul>
<li>Cannot allocate compression buffer (2× block length) for FLAC compression</li>
<li>Cannot allocate compression buffer (2× block length) for LZMA compression</li>
<li>System is out of memory or memory is severely fragmented</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_WRITE_BLOCK_HEADER</td><td>(-23) Failed to write block header. This occurs when:<ul>
<li>fwrite() for <aclass="el"href="structBlockHeader.html"title="Header preceding the compressed data payload of a data block (BlockType::DataBlock).">BlockHeader</a> returns != 1 (incomplete write or I/O error)</li>
<li>Disk space is insufficient for header</li>
<li>File system errors or permissions prevent writing</li>
<li>Media errors on the destination storage device</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_WRITE_BLOCK_DATA</td><td>(-24) Failed to write block data. This occurs when:<ul>
<li>Compression type is determined when block is created in <aclass="el"href="write_8c.html#a4b8cd2bb5fd9e2c670a0a13695c6f9e3"title="Writes a sector to the AaruFormat image.">aaruf_write_sector()</a></li>
<li>Audio tracks (<aclass="el"href="enums_8h.html#ad80740dd555f7d3688d2c4d9f44d3b04"title="Track (partitioning element) types for optical media.">TrackType</a> = Audio) use FLAC compression if enabled</li>
<li>Data tracks use LZMA compression if enabled</li>
<li>Special cases (JaguarCD data in audio, VideoNow) force LZMA even for audio tracks</li>
<li>Compression can be disabled entirely via ctx->compression_enabled flag</li>
</ul>
</dd>
<dd>
Compression Fallback Logic:<ul>
<li>If compressed size ≥ uncompressed size, compression is abandoned</li>
<li>Compression buffer is freed and compression type set to None</li>
<li>This prevents storage expansion from ineffective compression</li>
<li>Fallback is transparent to caller; function still returns success</li>
</ul>
</dd>
<dd>
FLAC Encoding Parameters:<ul>
<li>Encoding for Red Book audio (44.1kHz, 16-bit stereo)</li>
<li>Block size: auto-selected between MIN_FLAKE_BLOCK and MAX_FLAKE_BLOCK samples</li>
<li>Mid-side stereo enabled for better compression on correlated channels</li>
<li>Hamming window apodization for LPC analysis</li>
<li>Every closed block gets an index entry for efficient lookup</li>
<li>Index entries are stored in ctx->indexEntries (dynamic array)</li>
<li>Final index is serialized during <aclass="el"href="decls_8h.html#a6823e139f81a9dfd08efcb0e9b213a49"title="Close an Aaru image context, flushing pending data structures and releasing resources.">aaruf_close()</a> for image finalization</li>
<li>Index enables O(log n) block lookup during image reading</li>
</ul>
</dd>
<dd>
Alignment Requirements:<ul>
<li>Blocks must start on aligned boundaries per blockAlignmentShift</li>
<li>Typical alignment: 512 bytes (shift=9) or 4096 bytes (shift=12)</li>
<li>Alignment ensures efficient sector-aligned I/O on modern storage</li>
<li>Gap between blocks is implicit; no padding data is written</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>This function assumes ctx->writingBuffer contains valid data for ctx->currentBlockOffset sectors of ctx->currentBlockHeader.sectorSize bytes each.</dd>
<dd>
Do not call this function when no block is open (ctx->writingBuffer == NULL). This will result in undefined behavior or segmentation fault.</dd>
<dd>
The function modifies ctx->nextBlockPosition, which affects where subsequent blocks are written. Ensure file positioning is properly managed.</dd>
<dd>
Memory allocated for compression buffers is freed before returning. Do not retain pointers to compressed data after function completion.</dd>
<dd>
CRC64 context (ctx->crc64Context) is freed during cleanup. Do not access this pointer after calling this function. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="write_8c_source.html#l01403">1403</a> of file <aclass="el"href="write_8c_source.html">write.c</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="close_8c_source.html#l03997">aaruf_close()</a>, <aclass="el"href="write_8c_source.html#l00098">aaruf_write_sector()</a>, and <aclass="el"href="ddt__v2_8c_source.html#l01092">set_ddt_multi_level_v2()</a>.</p>
<p>Comparison function for sorting <aclass="el"href="structDumpExtent.html"title="Inclusive [start,end] logical sector range contributed by a single hardware environment.">DumpExtent</a> arrays by start sector. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">a</td><td>Pointer to the first <aclass="el"href="structDumpExtent.html"title="Inclusive [start,end] logical sector range contributed by a single hardware environment.">DumpExtent</a> to compare. </td></tr>
<tr><tdclass="paramname">b</td><td>Pointer to the second <aclass="el"href="structDumpExtent.html"title="Inclusive [start,end] logical sector range contributed by a single hardware environment.">DumpExtent</a> to compare. </td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Negative value if a->start < b->start, zero if equal, positive if a->start > b->start. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="helpers_8c_source.html#l00459">459</a> of file <aclass="el"href="helpers_8c_source.html">helpers.c</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="dump_8c_source.html#l00531">aaruf_set_dumphw()</a>, and <aclass="el"href="blocks_2dump_8c_source.html#l00107">process_dumphw_block()</a>.</p>
<p>Decodes a DDT v1 entry for a given sector address. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the loaded DDT table. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to decode (must be within valid range). </td></tr>
<tr><tdclass="paramname">offset</td><td>Pointer to store the resulting sector offset within the block. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Pointer to store the resulting block offset in the image. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Pointer to store the sector status (dumped or not dumped).</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully decoded the DDT entry. This is always returned when:<ul>
<li>The context and image stream are valid</li>
<li>The DDT entry is successfully extracted and decoded</li>
<li>The offset, block_offset, and sector_status are successfully populated</li>
<li>A zero DDT entry is encountered (indicates sector not dumped)</li>
<li>A non-zero DDT entry is encountered (indicates sector was dumped)</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers). This is the only error condition that can occur in this function.</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>This is a lightweight function that performs only basic validation and bit manipulation. It does not perform bounds checking on the sector_address parameter.</dd>
<dd>
DDT Entry Decoding:<ul>
<li>Uses a bit mask derived from ctx->shift to extract the offset within block</li>
<li>Right-shifts the DDT entry by ctx->shift bits to get the block offset</li>
<li>A zero DDT entry indicates the sector was not dumped (SectorStatusNotDumped)</li>
<li>A non-zero DDT entry indicates the sector was dumped (SectorStatusDumped)</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The function assumes:<ul>
<li>The DDT table (ctx->userDataDdt) has been properly loaded by <aclass="el"href="ddt__v1_8c.html#abaf38090f967423898b99e0455751c07"title="Processes a DDT v1 block from the image stream.">process_ddt_v1()</a></li>
<li>The sector_address is within the valid range of the DDT table</li>
<li>The shift value (ctx->shift) has been properly initialized</li>
<li>All output parameters (offset, block_offset, sector_status) are valid pointers</li>
</ul>
</dd>
<dd>
No bounds checking is performed on sector_address. Accessing beyond the DDT table boundaries will result in undefined behavior. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v1_8c_source.html#l00405">405</a> of file <aclass="el"href="ddt__v1_8c_source.html">ddt_v1.c</a>.</p>
<p>Decodes a DDT v2 entry for a given sector address. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the loaded DDT structures. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to decode (will be adjusted for negative sectors). </td></tr>
<tr><tdclass="paramname">negative</td><td>Indicates if the sector address is negative. </td></tr>
<tr><tdclass="paramname">offset</td><td>Pointer to store the resulting sector offset within the block. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Pointer to store the resulting block offset in the image. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Pointer to store the sector status (dumped, not dumped, etc.).</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully decoded the DDT entry. This is always returned when:<ul>
<li>The context and image stream are valid</li>
<li>The appropriate decoding function (single-level or multi-level) completes successfully</li>
<li>All output parameters are properly populated with decoded values</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers). This is the only error condition that can occur at this dispatcher level.</td></tr>
<tr><tdclass="paramname">Other</td><td>error codes may be returned by the underlying decoding functions:<ul>
<li>From <aclass="el"href="ddt__v2_8c.html#a40c571bc4778040f22ac211cea670db1"title="Decodes a single-level DDT v2 entry for a given sector address.">decode_ddt_single_level_v2()</a>: AARUF_ERROR_CANNOT_READ_BLOCK (-7)</li>
<li>From <aclass="el"href="ddt__v2_8c.html#a83aff4d408ab17f8f350cb03b0e12ef6"title="Decodes a multi-level DDT v2 entry for a given sector address.">decode_ddt_multi_level_v2()</a>: AARUF_ERROR_CANNOT_READ_BLOCK (-7), AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK (-17), AARUF_ERROR_INVALID_BLOCK_CRC (-18)</li>
<li>The tableShift parameter is read from ctx->userDataDdtHeader.tableShift</li>
</ul>
</dd>
<dd>
This function performs minimal validation and primarily acts as a dispatcher. Most error conditions and complex logic are handled by the underlying functions.</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The function assumes the DDT has been properly loaded by <aclass="el"href="ddt__v2_8c.html#a1caeae710ee5e1dd356e43b3b659e9c0"title="Processes a DDT v2 block from the image stream.">process_ddt_v2()</a>. Calling this function with an uninitialized or corrupted DDT will result in undefined behavior from the underlying decoding functions.</dd>
<dd>
All output parameters must be valid pointers. No bounds checking is performed on the sector_address parameter at this level. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l00507">507</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<pclass="reference">References <aclass="el"href="errors_8h_source.html#l00040">AARUF_ERROR_NOT_AARUFORMAT</a>, <aclass="el"href="ddt__v2_8c_source.html#l00724">decode_ddt_multi_level_v2()</a>, <aclass="el"href="ddt__v2_8c_source.html#l00581">decode_ddt_single_level_v2()</a>, <aclass="el"href="log_8h_source.html#l00040">FATAL</a>, <aclass="el"href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <aclass="el"href="ddt_8h_source.html#l00156">DdtHeader2::tableShift</a>, <aclass="el"href="log_8h_source.html#l00025">TRACE</a>, and <aclass="el"href="context_8h_source.html#l00189">aaruformat_context::user_data_ddt_header</a>.</p>
<p>Decodes a multi-level DDT v2 entry for a given sector address. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the loaded primary DDT table. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to decode (adjusted for negative sectors). </td></tr>
<tr><tdclass="paramname">negative</td><td>Indicates if the sector address is negative. </td></tr>
<tr><tdclass="paramname">offset</td><td>Pointer to store the resulting sector offset within the block. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Pointer to store the resulting block offset in the image. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Pointer to store the sector status (dumped, not dumped, etc.).</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully decoded the DDT entry. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The tableShift validation passes (must be > 0)</li>
<li>The DDT size type is recognized (SmallDdtSizeType or BigDdtSizeType)</li>
<li>Secondary DDT table is successfully loaded (from cache or file)</li>
<li>Uses tableShift to calculate items per DDT entry (2^tableShift)</li>
<li>Calculates DDT position by dividing sector address by items per entry</li>
<li>Retrieves secondary DDT offset from primary table at calculated position</li>
<li>Converts block offset to file offset using blockAlignmentShift</li>
</ul>
</dd>
<dd>
Secondary DDT Caching:<ul>
<li>Maintains a single cached secondary DDT in memory (ctx->cachedSecondaryDdtSmall/Big)</li>
<li>Compares requested offset with cached offset (ctx->cachedDdtOffset)</li>
<li>Only loads from disk if the requested secondary DDT is not currently cached</li>
<li>Caching improves performance for sequential sector access patterns</li>
</ul>
</dd>
<dd>
Secondary DDT Processing:<ul>
<li>Supports both LZMA compression and uncompressed formats</li>
<li>Performs full CRC64 validation of secondary DDT data</li>
<li>Same bit manipulation as single-level DDT for final entry decoding</li>
</ul>
</dd>
<dd>
Error Handling Strategy:<ul>
<li>Memory allocation failures for secondary DDT loading are treated as critical errors</li>
<li>File I/O errors and validation failures cause immediate function termination</li>
<li>Unknown compression types are treated as errors (unlike the processing functions)</li>
<li>All allocated memory is cleaned up on error conditions</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>This function should only be called when tableShift > 0. Calling it with tableShift = 0 will result in AARUF_ERROR_CANNOT_READ_BLOCK.</dd>
<dd>
The function assumes the primary DDT table has been properly loaded and is accessible via ctx->userDataDdtMini or ctx->userDataDdtBig depending on size type.</dd>
<dd>
Secondary DDT caching means that memory usage can increase during operation. The cached secondary DDT is replaced when a different secondary table is needed.</dd>
<dd>
No bounds checking is performed on sector_address or calculated DDT positions. Accessing beyond table boundaries will result in undefined behavior. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l00724">724</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<p>Decodes a single-level DDT v2 entry for a given sector address. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the loaded DDT table. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to decode (adjusted for negative sectors). </td></tr>
<tr><tdclass="paramname">negative</td><td>Indicates if the sector address is negative. </td></tr>
<tr><tdclass="paramname">offset</td><td>Pointer to store the resulting sector offset within the block. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Pointer to store the resulting block offset in the image. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Pointer to store the sector status (dumped, not dumped, etc.).</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully decoded the DDT entry. This is always returned when:<ul>
<li>The context and image stream are valid</li>
<li>The tableShift validation passes (must be 0)</li>
<li>The DDT size type is recognized (SmallDdtSizeType or BigDdtSizeType)</li>
<li>The DDT entry is successfully extracted and decoded</li>
<li>All output parameters are properly populated with decoded values</li>
<li>Zero DDT entries are handled (indicates sector not dumped)</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers).</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_BLOCK</td><td>(-7) Configuration or validation errors. This occurs when:<ul>
<li>The tableShift is not zero (should use multi-level decoding instead)</li>
<li>The DDT size type is unknown/unsupported (not SmallDdtSizeType or BigDdtSizeType)</li>
<li>Bits 60-0: Combined offset and block index (60 bits)</li>
<li>Offset mask: Derived from dataShift parameter</li>
<li>Block offset: Calculated using blockAlignmentShift parameter</li>
</ul>
</dd>
<dd>
Negative Sector Handling:<ul>
<li>Sector address is automatically adjusted by adding ctx->userDataDdtHeader.negative</li>
<li>This allows proper indexing into the DDT table for negative sector addresses</li>
</ul>
</dd>
<dd>
Zero Entry Handling:<ul>
<li>A zero DDT entry indicates the sector was not dumped</li>
<li>Sets sector_status to SectorStatusNotDumped and zeros offset/block_offset</li>
<li>This is a normal condition and not an error</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The function assumes the DDT table has been properly loaded and is accessible via ctx->userDataDdtMini or ctx->userDataDdtBig depending on size type.</dd>
<dd>
No bounds checking is performed on sector_address. Accessing beyond the DDT table boundaries will result in undefined behavior.</dd>
<dd>
This function should only be called when tableShift is 0. Calling it with tableShift > 0 will result in AARUF_ERROR_CANNOT_READ_BLOCK. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l00581">581</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<p>Generates cryptographically strong random bytes. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">buffer</td><td>Pointer to the buffer to fill with random bytes. </td></tr>
<tr><tdclass="paramname">length</td><td>Number of random bytes to generate. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="helpers_8c_source.html#l00480">480</a> of file <aclass="el"href="helpers_8c_source.html">helpers.c</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="create_8c_source.html#l00279">aaruf_create()</a>.</p>
<p>Gets the current time as a 64-bit FILETIME value. </p>
<p>Returns the current system time as a 64-bit value compatible with Windows FILETIME (number of 100-nanosecond intervals since January 1, 1601 UTC).</p>
<dlclass="section return"><dt>Returns</dt><dd>The current time as a 64-bit FILETIME value. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="time_8c_source.html#l00045">45</a> of file <aclass="el"href="time_8c_source.html">time.c</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="create_8c_source.html#l00279">aaruf_create()</a>, and <aclass="el"href="open_8c_source.html#l00223">aaruf_open()</a>.</p>
<p>Parses the options string for AaruFormat image creation/opening. </p>
<p>Parses the options string and returns a struct with the parsed options for image creation or opening.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">options</td><td>String with options to parse (may be NULL). </td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Parsed options as an <aclass="el"href="structaaru__options.html"title="Parsed user-specified tunables controlling compression, deduplication, hashing and DDT geometry.">aaru_options</a> struct. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="options_8c_source.html#l00038">38</a> of file <aclass="el"href="options_8c_source.html">options.c</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="create_8c_source.html#l00279">aaruf_create()</a>, and <aclass="el"href="open_8c_source.html#l00223">aaruf_open()</a>.</p>
<p>Processes an Aaru metadata JSON block from the image stream during image opening. </p>
<p>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.</p>
<p>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.</p>
<p><b>Processing sequence:</b></p><oltype="1">
<li>Validate context and image stream</li>
<li>Seek to the block offset specified by the index entry</li>
<li>Read the <aclass="el"href="structAaruMetadataJsonBlockHeader.html"title="Header for an Aaru metadata JSON block (identifier == BlockType::AaruMetadataJsonBlock).">AaruMetadataJsonBlockHeader</a> (8 bytes: identifier + length)</li>
<li>Validate the block identifier matches AaruMetadataJsonBlock</li>
<li>Allocate memory for the JSON payload</li>
<li>Read the JSON data from the file stream</li>
<li>Store header and data pointer in the context for later retrieval</li>
</ol>
<p><b>Memory allocation:</b> 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 <aclass="el"href="decls_8h.html#a6823e139f81a9dfd08efcb0e9b213a49"title="Close an Aaru image context, flushing pending data structures and releasing resources.">aaruf_close()</a>. If allocation fails, the function returns gracefully without the JSON metadata, allowing the image to still be opened.</p>
<p><b>Image size tracking:</b> 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.</p>
<p><b>Error handling:</b> All errors are non-fatal and handled gracefully:</p><ul>
<li>Seek failures: logged and function returns early</li>
<li>Header read failures: header zeroed, function returns</li>
<li>Identifier mismatches: header zeroed, processing continues but data is not loaded</li>
<li>Memory allocation failures: header zeroed, function returns</li>
<li>Data read failures: header zeroed, allocated memory freed, function returns</li>
</ul>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>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. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> 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.</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>JSON Format and Encoding:<ul>
<li>The JSON payload is stored in UTF-8 encoding</li>
<li>The payload may or may not be null-terminated</li>
<li>This function treats the JSON as opaque binary data</li>
<li>No JSON parsing, interpretation, or validation is performed during loading</li>
<li>JSON schema validation is the responsibility of code that retrieves the metadata</li>
</ul>
</dd>
<dd>
Aaru Metadata JSON Purpose:<ul>
<li>Provides machine-readable structured metadata about the image</li>
<li>Includes comprehensive information about media, sessions, tracks, and checksums</li>
<li>Enables programmatic access to metadata without XML parsing overhead</li>
<li>Complements CICM XML with a more modern, structured format</li>
<li>Used by Aaru and compatible tools for metadata exchange</li>
</ul>
</dd>
<dd>
Non-Critical Nature:<ul>
<li>JSON metadata is optional and supplementary to core image data</li>
<li>Failures reading this block do not prevent image opening</li>
<li>The image remains fully functional for sector data access without JSON metadata</li>
<li>Higher-level code should check if ctx->jsonBlock is non-NULL before use</li>
</ul>
</dd>
<dd>
Distinction from CICM XML:<ul>
<li>Both CICM and Aaru JSON blocks can coexist in the same image</li>
<li>CICM XML follows the Canary Islands Computer Museum schema</li>
<li>Aaru JSON follows the Aaru-specific metadata schema</li>
<li>Different tools may prefer one format over the other</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>Memory allocated for ctx->jsonBlock persists for the context lifetime and must be freed during context cleanup (aaruf_close).</dd>
<dd>
This function does not validate JSON syntax or schema. Corrupted JSON data will be loaded successfully and errors will only be detected when attempting to parse.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="structAaruMetadataJsonBlockHeader.html"title="Header for an Aaru metadata JSON block (identifier == BlockType::AaruMetadataJsonBlock).">AaruMetadataJsonBlockHeader</a> for the on-disk structure definition. </dd>
<dd>
<aclass="el"href="blocks_2metadata_8c.html#a5e0397faed8aea27c5a6a3881875de54"title="Processes a CICM XML metadata block from the image stream.">process_cicm_block()</a> for processing CICM XML metadata blocks. </dd>
<pclass="definition">Definition at line <aclass="el"href="blocks_2metadata_8c_source.html#l00470">470</a> of file <aclass="el"href="blocks_2metadata_8c_source.html">metadata.c</a>.</p>
<p>Processes a checksum block from the image stream. </p>
<p>Reads a checksum block, parses its entries, and stores the checksums (MD5, SHA1, SHA256, SpamSum) in the context.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the checksum block. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="checksum_8c_source.html#l00039">39</a> of file <aclass="el"href="checksum_8c_source.html">checksum.c</a>.</p>
<p>Processes a CICM XML metadata block from the image stream. </p>
<p>Reads a CICM XML metadata block from the image and updates the context with its contents.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the CICM block. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="blocks_2metadata_8c_source.html#l00306">306</a> of file <aclass="el"href="blocks_2metadata_8c_source.html">metadata.c</a>.</p>
<p>Processes a data block from the image stream. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the data block.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully processed the data block. This is returned when:<ul>
<li>The block is processed successfully and all validations pass</li>
<li>A NoData block type is encountered (these are skipped)</li>
<li>A UserData block type is encountered (these update sector size but are otherwise skipped)</li>
<li>Block validation fails but processing continues (non-fatal errors like CRC mismatches)</li>
<li>Memory allocation failures occur (processing continues with other blocks)</li>
<li>Block reading failures occur (processing continues with other blocks)</li>
<li>Unknown compression types are encountered (block is skipped)</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers).</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_BLOCK</td><td>(-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.</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK</td><td>(-17) LZMA decompression failed. This can happen when:<ul>
<li>The LZMA decoder returns an error code</li>
<li>The decompressed data size doesn't match the expected block length</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>Most validation and reading errors are treated as non-fatal and result in AARUF_STATUS_OK being returned while the problematic block is skipped. This allows processing to continue with other blocks in the image.</dd>
<dd>
The function performs the following validations:<ul>
<li>Block identifier matches the expected block type</li>
<li>Block data type matches the expected data type</li>
<li>CRC64 checksum validation (with version-specific byte order handling)</li>
<li>Proper decompression for LZMA-compressed blocks</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>Memory allocated for block data is stored in the context and should be freed when the context is destroyed. The function may replace existing data in the context. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="data_8c_source.html#l00071">71</a> of file <aclass="el"href="data_8c_source.html">data.c</a>.</p>
<p>Processes a DDT v1 block from the image stream. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the DDT block. </td></tr>
<tr><tdclass="paramname">found_user_data_ddt</td><td>Pointer to a boolean that will be set to true if a user data DDT was found and loaded.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully processed the DDT block. This is returned when:<ul>
<li>The DDT block is successfully read, decompressed (if needed), and loaded into memory</li>
<li>Memory mapping of uncompressed DDT succeeds on Linux systems</li>
<li>CD sector prefix/suffix corrected DDT blocks are processed successfully</li>
<li>Memory allocation failures occur for non-critical operations (processing continues)</li>
<li>File reading errors occur for compressed data or LZMA properties (processing continues)</li>
<li>Unknown compression types are encountered (block is skipped)</li>
<li>Memory mapping fails on Linux (sets found_user_data_ddt to false but continues)</li>
<li>Uncompressed DDT is encountered on non-Linux systems (not yet implemented, continues)</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers).</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_BLOCK</td><td>(-7) Failed to access the DDT block in the image stream. This occurs when:<ul>
<li>fseek() fails to position at the DDT block offset</li>
<li>The file position doesn't match the expected offset after seeking</li>
<li>Failed to read the DDT header from the image stream</li>
<li>The number of bytes read for the DDT header is insufficient</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK</td><td>(-17) LZMA decompression failed. This can happen when:<ul>
<li>The LZMA decoder returns a non-zero error code during decompression</li>
<li>The decompressed data size doesn't match the expected DDT block length</li>
<li>This error causes immediate function termination and memory cleanup</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>The function exhibits different error handling strategies depending on the operation:<ul>
<li>The found_user_data_ddt flag is updated to reflect the success of user data DDT loading</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Allocated DDT data is stored in the context (ctx->userDataDdt, ctx->sectorPrefixDdt, ctx->sectorSuffixDdt)</li>
<li>On Linux, uncompressed DDTs may be memory-mapped instead of allocated</li>
<li>Memory is automatically cleaned up on decompression errors</li>
</ul>
</dd>
<dd>
Platform-specific behavior:<ul>
<li>Linux: Supports memory mapping of uncompressed DDT blocks for better performance</li>
<li>Non-Linux: Uncompressed DDT processing is not yet implemented</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The function modifies context state including sector count, shift value, and DDT version. Ensure proper context cleanup when the function completes. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v1_8c_source.html#l00085">85</a> of file <aclass="el"href="ddt__v1_8c_source.html">ddt_v1.c</a>.</p>
<p>Processes a DDT v2 block from the image stream. </p>
<p>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).</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the DDT block. </td></tr>
<tr><tdclass="paramname">found_user_data_ddt</td><td>Pointer to a boolean that will be set to true if a user data DDT was found and loaded.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully processed the DDT block. This is returned when:<ul>
<li>The DDT block is successfully read, decompressed (if needed), and loaded into memory</li>
<li>CRC64 validation passes for the DDT data</li>
<li>User data DDT blocks are processed and context is properly updated</li>
<li>CD sector prefix/suffix corrected DDT blocks are processed successfully</li>
<li>Memory allocation failures occur for non-critical operations (processing continues)</li>
<li>File reading errors occur for compressed data or LZMA properties (processing continues)</li>
<li>Unknown compression types are encountered (block is skipped)</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers).</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_BLOCK</td><td>(-7) Failed to access the DDT block in the image stream. This occurs when:<ul>
<li>fseek() fails to position at the DDT block offset</li>
<li>The file position doesn't match the expected offset after seeking</li>
<li>Failed to read the DDT header from the image stream</li>
<li>The number of bytes read for the DDT header is insufficient</li>
<li>The found_user_data_ddt flag is updated to reflect the success of user data DDT loading</li>
</ul>
</dd>
<dd>
DDT v2 Features:<ul>
<li>Handles multi-level DDT hierarchies with tableShift parameter</li>
<li>Updates context with sector counts, DDT version, and primary DDT offset</li>
<li>Stores DDT data in size-appropriate context fields (userDataDdtMini/Big, sectorPrefixDdt, etc.)</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Allocated DDT data is stored in the context and becomes part of the context lifecycle</li>
<li>Memory is automatically cleaned up on decompression or CRC validation errors</li>
<li>Buffer memory is reused for the final DDT data storage (no double allocation)</li>
</ul>
</dd>
<dd>
CRC Validation:<ul>
<li>All DDT blocks undergo CRC64 validation regardless of compression type</li>
<li>CRC is calculated on the final decompressed data</li>
<li>Uses standard CRC64 calculation (no version-specific endianness conversion like v1)</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The function modifies context state including sector count, DDT version, and primary DDT offset. Ensure proper context cleanup when the function completes.</dd>
<dd>
Memory allocated for DDT data becomes part of the context and should not be freed separately. The context cleanup functions will handle DDT memory deallocation. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l00096">96</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="blocks_2dump_8c_source.html#l00107">107</a> of file <aclass="el"href="blocks_2dump_8c_source.html">dump.c</a>.</p>
<p>Processes a logical geometry block from the image stream. </p>
<p>Reads a logical geometry block from the image and updates the context with its contents.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the geometry block. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="blocks_2metadata_8c_source.html#l00246">246</a> of file <aclass="el"href="blocks_2metadata_8c_source.html">metadata.c</a>.</p>
<p>Processes an index block (version 1) from the image stream. </p>
<p>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 <aclass="el"href="structIndexHeader.html"title="Index header (version 1) for legacy images (identifier == IndexBlock).">IndexHeader</a> structure followed by a sequential list of <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> structures, validating the index identifier for format correctness.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following values: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">UT_array*</td><td>Successfully processed the index block. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The index header is successfully read from the position specified in ctx->header.indexOffset</li>
<li>The index identifier matches IndexBlock (legacy format identifier)</li>
<li>All index entries are successfully read and stored in the UT_array</li>
<li>Memory allocation for the index entries array succeeds</li>
<li>The returned array contains all index entries from the version 1 index block</li>
</ul>
</td></tr>
<tr><tdclass="paramname">NULL</td><td>Index processing failed. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx->imageStream) is NULL or invalid</li>
<li>Cannot read the <aclass="el"href="structIndexHeader.html"title="Index header (version 1) for legacy images (identifier == IndexBlock).">IndexHeader</a> structure from the image stream</li>
<li>The index identifier doesn't match IndexBlock (incorrect format or corruption)</li>
<li>Memory allocation fails for the UT_array structure</li>
<li>File I/O errors occur while reading index entries</li>
<li><aclass="el"href="structIndexHeader.html"title="Index header (version 1) for legacy images (identifier == IndexBlock).">IndexHeader</a>: Contains identifier (IndexBlock), entry count, and metadata</li>
<li><aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> array: Sequential list of entries describing block locations and types</li>
<li>No CRC validation is performed during processing (use verify_index_v1 for validation)</li>
<li>No compression support in version 1 index format</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Returns a newly allocated UT_array that must be freed by the caller using utarray_free()</li>
<li>On error, any partially allocated memory is cleaned up before returning NULL</li>
<li>Each <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> is copied into the array (no reference to original stream data)</li>
</ul>
</dd>
<dd>
Version Compatibility:<ul>
<li>Supports only legacy IndexBlock format (not IndexBlock2 or IndexBlock3)</li>
<li>Compatible with early AaruFormat and DiscImageChef image files</li>
<li>Does not handle subindex or hierarchical index structures</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The caller is responsible for freeing the returned UT_array using utarray_free(). Failure to free the array will result in memory leaks.</dd>
<dd>
This function does not validate the CRC integrity of the index data. Use <aclass="el"href="index__v1_8c.html#a89ed93d216c4dce0ae5e2acccf8cc2b4"title="Verifies the integrity of an index block (version 1) in the image stream.">verify_index_v1()</a> to ensure index integrity before processing.</dd>
<dd>
The function assumes ctx->header.indexOffset points to a valid index block. Invalid offsets may cause file access errors or reading incorrect data. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="index__v1_8c_source.html#l00079">79</a> of file <aclass="el"href="index__v1_8c_source.html">index_v1.c</a>.</p>
<pclass="reference">References <aclass="el"href="index_8h_source.html#l00069">IndexHeader::entries</a>, <aclass="el"href="log_8h_source.html#l00040">FATAL</a>, <aclass="el"href="context_8h_source.html#l00175">aaruformat_context::header</a>, <aclass="el"href="index_8h_source.html#l00068">IndexHeader::identifier</a>, <aclass="el"href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <aclass="el"href="enums_8h_source.html#l00145">IndexBlock</a>, <aclass="el"href="header_8h_source.html#l00115">AaruHeaderV2::indexOffset</a>, and <aclass="el"href="log_8h_source.html#l00025">TRACE</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="open_8c_source.html#l00223">aaruf_open()</a>, and <aclass="el"href="verify_8c_source.html#l00130">aaruf_verify_image()</a>.</p>
<p>Processes an index block (version 2) from the image stream. </p>
<p>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 <aclass="el"href="structIndexHeader2.html"title="Index header (version 2) with 64‑bit entry counter (identifier == IndexBlock2).">IndexHeader2</a> structure followed by a sequential list of <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> structures, validating the index identifier for format correctness.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following values: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">UT_array*</td><td>Successfully processed the index block. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The index header is successfully read from the position specified in ctx->header.indexOffset</li>
<li>The index identifier matches IndexBlock2 (version 2 format identifier)</li>
<li>All index entries are successfully read and stored in the UT_array</li>
<li>Memory allocation for the index entries array succeeds</li>
<li>The returned array contains all index entries from the version 2 index block</li>
</ul>
</td></tr>
<tr><tdclass="paramname">NULL</td><td>Index processing failed. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx->imageStream) is NULL or invalid</li>
<li>Cannot read the <aclass="el"href="structIndexHeader2.html"title="Index header (version 2) with 64‑bit entry counter (identifier == IndexBlock2).">IndexHeader2</a> structure from the image stream</li>
<li>The index identifier doesn't match IndexBlock2 (incorrect format or corruption)</li>
<li>Memory allocation fails for the UT_array structure</li>
<li>File I/O errors occur while reading index entries</li>
<li><aclass="el"href="structIndexHeader2.html"title="Index header (version 2) with 64‑bit entry counter (identifier == IndexBlock2).">IndexHeader2</a>: Contains identifier (IndexBlock2), entry count, and enhanced metadata</li>
<li><aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> array: Sequential list of entries describing block locations and types</li>
<li>No CRC validation is performed during processing (use verify_index_v2 for validation)</li>
<li>No compression support in version 2 index format</li>
<li>Compatible with mid-generation AaruFormat improvements</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Returns a newly allocated UT_array that must be freed by the caller using utarray_free()</li>
<li>On error, any partially allocated memory is cleaned up before returning NULL</li>
<li>Each <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> is copied into the array (no reference to original stream data)</li>
</ul>
</dd>
<dd>
Version Compatibility:<ul>
<li>Supports only IndexBlock2 format (not IndexBlock or IndexBlock3)</li>
<li>Compatible with intermediate AaruFormat image files</li>
<li>Does not handle subindex or hierarchical index structures (introduced in v3)</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The caller is responsible for freeing the returned UT_array using utarray_free(). Failure to free the array will result in memory leaks.</dd>
<dd>
This function does not validate the CRC integrity of the index data. Use <aclass="el"href="index__v2_8c.html#ae234e22b16b085d18614110630034db5"title="Verifies the integrity of an index block (version 2) in the image stream.">verify_index_v2()</a> to ensure index integrity before processing.</dd>
<dd>
The function assumes ctx->header.indexOffset points to a valid index block. Invalid offsets may cause file access errors or reading incorrect data. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="index__v2_8c_source.html#l00081">81</a> of file <aclass="el"href="index__v2_8c_source.html">index_v2.c</a>.</p>
<pclass="reference">References <aclass="el"href="index_8h_source.html#l00081">IndexHeader2::entries</a>, <aclass="el"href="log_8h_source.html#l00040">FATAL</a>, <aclass="el"href="context_8h_source.html#l00175">aaruformat_context::header</a>, <aclass="el"href="index_8h_source.html#l00080">IndexHeader2::identifier</a>, <aclass="el"href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <aclass="el"href="enums_8h_source.html#l00146">IndexBlock2</a>, <aclass="el"href="header_8h_source.html#l00115">AaruHeaderV2::indexOffset</a>, and <aclass="el"href="log_8h_source.html#l00025">TRACE</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="open_8c_source.html#l00223">aaruf_open()</a>, and <aclass="el"href="verify_8c_source.html#l00130">aaruf_verify_image()</a>.</p>
<p>Processes an index block (version 3) from the image stream. </p>
<p>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 <aclass="el"href="structIndexHeader3.html"title="Index header (version 3) adding hierarchical chaining (identifier == IndexBlock3).">IndexHeader3</a> structure followed by index entries, recursively processing any subindex blocks encountered to create a flattened array of all index entries.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing the image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following values: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">UT_array*</td><td>Successfully processed the index block and all subindexes. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The index header is successfully read from the position specified in ctx->header.indexOffset</li>
<li>The index identifier matches IndexBlock3 (version 3 format identifier)</li>
<li>All index entries are successfully read and stored in the UT_array</li>
<li>Any subindex blocks (IndexBlock3 entries) are recursively processed via <aclass="el"href="index__v3_8c.html#ac85ad03ba0f06b8799d7fe056b87a18e"title="Adds entries from a subindex block (version 3) to the main index entries array.">add_subindex_entries()</a></li>
<li>Memory allocation for the index entries array succeeds</li>
<li>The returned array contains all index entries from the main index and all subindexes</li>
</ul>
</td></tr>
<tr><tdclass="paramname">NULL</td><td>Index processing failed. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx->imageStream) is NULL or invalid</li>
<li>Cannot read the <aclass="el"href="structIndexHeader3.html"title="Index header (version 3) adding hierarchical chaining (identifier == IndexBlock3).">IndexHeader3</a> structure from the image stream</li>
<li>The index identifier doesn't match IndexBlock3 (incorrect format or corruption)</li>
<li>Memory allocation fails for the UT_array structure</li>
<li>File I/O errors occur while reading index entries</li>
<li>Recursive subindex processing fails (errors in <aclass="el"href="index__v3_8c.html#ac85ad03ba0f06b8799d7fe056b87a18e"title="Adds entries from a subindex block (version 3) to the main index entries array.">add_subindex_entries()</a>)</li>
<li><aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> array: May contain regular entries and subindex references (IndexBlock3 type)</li>
<li>Hierarchical support: Subindex entries are recursively processed to flatten the structure</li>
<li>No CRC validation is performed during processing (use verify_index_v3 for validation)</li>
<li>Supports scalable index organization for large image files</li>
</ul>
</dd>
<dd>
Subindex Processing:<ul>
<li>When an <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> has blockType == IndexBlock3, it references a subindex</li>
<li>Subindexes are recursively processed using <aclass="el"href="index__v3_8c.html#ac85ad03ba0f06b8799d7fe056b87a18e"title="Adds entries from a subindex block (version 3) to the main index entries array.">add_subindex_entries()</a></li>
<li>All entries from subindexes are flattened into the main index entries array</li>
<li>Supports arbitrary nesting depth of subindexes</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Returns a newly allocated UT_array that must be freed by the caller using utarray_free()</li>
<li>On error, any partially allocated memory is cleaned up before returning NULL</li>
<li>Each <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> is copied into the array (no reference to original stream data)</li>
<li>Memory usage scales with total entries across all subindexes</li>
</ul>
</dd>
<dd>
Version Compatibility:<ul>
<li>Supports only IndexBlock3 format (not IndexBlock or IndexBlock2)</li>
<li>Compatible with current generation AaruFormat image files</li>
<li>Backward compatible with images that don't use subindexes</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The caller is responsible for freeing the returned UT_array using utarray_free(). Failure to free the array will result in memory leaks.</dd>
<dd>
This function does not validate the CRC integrity of the index data. Use <aclass="el"href="index__v3_8c.html#ad7ed9250463c320c7bc8d83689bcfefb"title="Verifies the integrity of an index block (version 3) in the image stream.">verify_index_v3()</a> to ensure index integrity before processing.</dd>
<dd>
Recursive subindex processing may cause significant memory usage and processing time for images with deeply nested or numerous subindexes.</dd>
<dd>
The function assumes ctx->header.indexOffset points to a valid index block. Invalid offsets may cause file access errors or reading incorrect data. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="index__v3_8c_source.html#l00098">98</a> of file <aclass="el"href="index__v3_8c_source.html">index_v3.c</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="open_8c_source.html#l00223">aaruf_open()</a>, and <aclass="el"href="verify_8c_source.html#l00130">aaruf_verify_image()</a>.</p>
<p>Processes a metadata block from the image stream. </p>
<p>Reads a metadata block from the image and updates the context with its contents.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the metadata block. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="blocks_2metadata_8c_source.html#l00035">35</a> of file <aclass="el"href="blocks_2metadata_8c_source.html">metadata.c</a>.</p>
<p>Processes a tape file metadata block from the image stream. </p>
<p>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).</p>
<p>The function performs the following operations:</p><oltype="1">
<li>Seeks to the block position indicated by the index entry</li>
<li>Reads and validates the <aclass="el"href="structTapeFileHeader.html"title="Header for a tape file metadata block containing file layout information.">TapeFileHeader</a> structure</li>
<li>Allocates and reads the array of <aclass="el"href="structTapeFileEntry.html"title="Describes a single logical file on a tape medium.">TapeFileEntry</a> structures</li>
<li>Validates data integrity using CRC64-ECMA checksum</li>
<li>Inserts each file entry into the context's UTHASH table with a composite key</li>
<li>Updates image size statistics</li>
</ol>
<p><b>Composite Key Construction:</b> 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.</p>
<p><b>Hash Table Management:</b> The function uses HASH_REPLACE to insert entries, which automatically:</p><ul>
<li>Adds new entries if the key doesn't exist</li>
<li>Replaces existing entries if the key is found (freeing the old entry) This ensures that duplicate entries (same partition/file combination) are properly handled by keeping only the most recent definition.</li>
</ul>
<p><b>Error Handling:</b> The function treats most errors as non-fatal and continues processing:</p><ul>
<li>Invalid context or stream: Returns immediately (FATAL log)</li>
<divclass="ttc"id="astructTapeFileEntry_html"><divclass="ttname"><ahref="structTapeFileEntry.html">TapeFileEntry</a></div><divclass="ttdoc">Describes a single logical file on a tape medium.</div><divclass="ttdef"><b>Definition</b><ahref="tape_8h_source.html#l00133">tape.h:134</a></div></div>
</div><!-- fragment --><p><b>CRC64 Validation:</b> The CRC64 checksum in the header is computed over the entire array of <aclass="el"href="structTapeFileEntry.html"title="Describes a single logical file on a tape medium.">TapeFileEntry</a> structures (excluding the header itself). This provides integrity verification to detect corruption in the file table.</p>
<p><b>Memory Management:</b></p><ul>
<li>Allocates a temporary buffer to read all file entries</li>
<li>Allocates individual hash table entries for each file</li>
<li>Frees the temporary buffer before returning</li>
<li>Hash table entries remain in context until cleanup</li>
</ul>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>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.</td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the tape file block. Must not be NULL. The entry->offset field indicates the file position where the <aclass="el"href="structTapeFileHeader.html"title="Header for a tape file metadata block containing file layout information.">TapeFileHeader</a> begins.</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>This function does not return a status code. All errors are handled internally with appropriate logging and the function returns early on fatal errors.</dd>
<dd>
The tape file hash table (ctx->tapeFiles) must be initialized to NULL before the first call to this function. UTHASH will manage the table automatically as entries are added.</dd>
<dd>
Files are ordered in the hash table by their composite key value, not by insertion order. To iterate files in partition/file number order, use HASH_SORT with an appropriate comparison function.</dd>
<dd>
The function updates ctx->imageInfo.ImageSize by adding the size of all file entries (entries × sizeof(TapeFileEntry)). This contributes to the total reported image size but does not include the header size.</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The context and imageStream must be valid. Passing NULL pointers will result in immediate return with a FATAL log message.</dd>
<dd>
If the CRC64 checksum validation fails, all entries in the block are discarded. The function does not attempt partial recovery.</dd>
<dd>
If memory allocation fails for a hash entry, that specific file entry is skipped but processing continues with remaining entries.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="structTapeFileHeader.html"title="Header for a tape file metadata block containing file layout information.">TapeFileHeader</a> for the block header structure </dd>
<dd>
<aclass="el"href="structTapeFileEntry.html"title="Describes a single logical file on a tape medium.">TapeFileEntry</a> for individual file entry structure </dd>
<dd>
<aclass="el"href="context_8h.html#a5ba965cb003bc2d68a9f9e1c11225494">tapeFileHashEntry</a> for the hash table entry structure </dd>
<dd>
process_tape_partition_block() for partition metadata processing </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="tape_8c_source.html#l00126">126</a> of file <aclass="el"href="tape_8c_source.html">tape.c</a>.</p>
<p>Processes a tape partition metadata block from the image stream. </p>
<p>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).</p>
<p>The function performs the following operations:</p><oltype="1">
<li>Seeks to the block position indicated by the index entry</li>
<li>Reads and validates the <aclass="el"href="structTapePartitionHeader.html"title="Header for a tape partition metadata block containing partition layout information.">TapePartitionHeader</a> structure</li>
<li>Allocates and reads the array of <aclass="el"href="structTapePartitionEntry.html"title="Describes a single physical partition on a tape medium.">TapePartitionEntry</a> structures</li>
<li>Validates data integrity using CRC64-ECMA checksum</li>
<li>Inserts each partition entry into the context's UTHASH table with partition number as key</li>
<li>Updates image size statistics</li>
</ol>
<p><b>Partition Identification:</b> 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.</p>
<p><b>Hash Table Management:</b> The function uses HASH_REPLACE to insert entries, which automatically:</p><ul>
<li>Adds new entries if the partition number doesn't exist</li>
<li>Replaces existing entries if the partition number is found (freeing the old entry) This ensures that duplicate partition definitions are properly handled by keeping only the most recent definition.</li>
</ul>
<p><b>Error Handling:</b> The function treats most errors as non-fatal and continues processing:</p><ul>
<li>Invalid context or stream: Returns immediately (FATAL log)</li>
<divclass="ttc"id="astructTapePartitionEntry_html"><divclass="ttname"><ahref="structTapePartitionEntry.html">TapePartitionEntry</a></div><divclass="ttdoc">Describes a single physical partition on a tape medium.</div><divclass="ttdef"><b>Definition</b><ahref="tape_8h_source.html#l00319">tape.h:320</a></div></div>
</div><!-- fragment --><p><b>CRC64 Validation:</b> The CRC64 checksum in the header is computed over the entire array of <aclass="el"href="structTapePartitionEntry.html"title="Describes a single physical partition on a tape medium.">TapePartitionEntry</a> structures (excluding the header itself). This provides integrity verification to detect corruption in the partition table.</p>
<p><b>Partition Block Ranges:</b> Each partition defines a block address space:</p><ul>
<li>FirstBlock: Starting block address (often 0, but format-dependent)</li>
<p>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).</p>
<p><b>Memory Management:</b></p><ul>
<li>Allocates a temporary buffer to read all partition entries</li>
<li>Allocates individual hash table entries for each partition</li>
<li>Frees the temporary buffer before returning</li>
<li>Hash table entries remain in context until cleanup</li>
</ul>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>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.</td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing the tape partition block. Must not be NULL. The entry->offset field indicates the file position where the <aclass="el"href="structTapePartitionHeader.html"title="Header for a tape partition metadata block containing partition layout information.">TapePartitionHeader</a> begins.</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>This function does not return a status code. All errors are handled internally with appropriate logging and the function returns early on fatal errors.</dd>
<dd>
The tape partition hash table (ctx->tapePartitions) must be initialized to NULL before the first call to this function. UTHASH will manage the table automatically as entries are added.</dd>
<dd>
Partitions are ordered in the hash table by their partition number, not by insertion order. To iterate partitions in numerical order, use HASH_SORT with an appropriate comparison function.</dd>
<dd>
The function updates ctx->imageInfo.ImageSize by adding the size of all partition entries (entries × sizeof(TapePartitionEntry)). This contributes to the total reported image size but does not include the header size.</dd>
<dd>
The partition metadata is essential for correctly interpreting tape file locations, as files reference partition numbers in their definitions. Without partition metadata, tape file block ranges may be ambiguous.</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The context and imageStream must be valid. Passing NULL pointers will result in immediate return with a FATAL log message.</dd>
<dd>
If the CRC64 checksum validation fails, all entries in the block are discarded. The function does not attempt partial recovery.</dd>
<dd>
If memory allocation fails for a hash entry, that specific partition entry is skipped but processing continues with remaining entries.</dd>
<dd>
If multiple partition entries have the same Number field, only the last occurrence is retained. This should not occur in valid images.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="structTapePartitionHeader.html"title="Header for a tape partition metadata block containing partition layout information.">TapePartitionHeader</a> for the block header structure </dd>
<dd>
<aclass="el"href="structTapePartitionEntry.html"title="Describes a single physical partition on a tape medium.">TapePartitionEntry</a> for individual partition entry structure </dd>
<dd>
<aclass="el"href="structTapePartitionHashEntry.html">TapePartitionHashEntry</a> for the hash table entry structure </dd>
<dd>
<aclass="el"href="tape_8c.html#a829bbac3c17b60efd8f93188a8de8278"title="Processes a tape file metadata block from the image stream.">process_tape_files_block()</a> for tape file metadata processing </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="tape_8c_source.html#l00346">346</a> of file <aclass="el"href="tape_8c_source.html">tape.c</a>.</p>
<p>Parse and integrate a Tracks block from the image stream into the context. </p>
<p>This function seeks to the byte offset specified by the supplied <codeclass="param">entry</code>, reads a <aclass="el"href="structTracksHeader.html"title="Header for an optical tracks block listing track entries.">TracksHeader</a> followed by the declared number of <aclass="el"href="structTrackEntry.html"title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> records, validates the block through its CRC64, and populates multiple fields in the provided <codeclass="param">ctx:</code></p>
<li>ctx->trackEntries (raw array with ALL tracks in on-disk order)</li>
<li>ctx->dataTracks (array filtered to data track sequences in [1..99])</li>
<li>ctx->numberOfDataTracks</li>
<li>ctx->imageInfo.ImageSize (incremented by sizeof(TrackEntry) * entries)</li>
<li>ctx->imageInfo.HasPartitions / HasSessions (both set true unconditionally on success path before filtering)</li>
</ul>
<p>It also performs a legacy endian correction of the computed CRC for images whose major version is <= AARUF_VERSION_V1 (historical writer quirk).</p>
<p>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.</p>
<p>Error & early-return behavior (no exception mechanism, all via logging + early return):</p><ul>
<li>NULL <codeclass="param">ctx</code> or NULL ctx->imageStream: Logs FATAL and returns immediately; context left untouched.</li>
<li>Seek failure: FATAL + return; context left untouched.</li>
<li><aclass="el"href="structTracksHeader.html"title="Header for an optical tracks block listing track entries.">TracksHeader</a> read short: tracksHeader zeroed, TRACE logged, return.</li>
<li>CRC mismatch: TRACE logged and return; (NOTE: at this point trackEntries remain allocated and tracksHeader retains the just-read values, but caller receives no explicit status.)</li>
</ul>
<p>Memory management:</p><ul>
<li>Allocates ctx->trackEntries with malloc() sized to entries * sizeof(TrackEntry).</li>
<li>Allocates ctx->dataTracks only if at least one filtered data track is found; otherwise sets it to NULL.</li>
<li>On certain failure paths (short reads) allocated memory is freed; on CRC mismatch memory is kept.</li>
<li>Pre-existing ctx->trackEntries or ctx->dataTracks are NOT freed before overwriting pointers, so repeated calls without prior cleanup will leak memory. The function is therefore expected to be called exactly once per context lifetime. This constraint should be observed by library code.</li>
</ul>
<p>Filtering rule for ctx->dataTracks:</p><ul>
<li>Any <aclass="el"href="structTrackEntry.html"title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> with sequence in inclusive range [1, 99] is considered a data track (historical convention in format) and copied into ctx->dataTracks preserving original order.</li>
</ul>
<p>Thread safety:</p><ul>
<li>Not thread-safe: mutates shared state in <codeclass="param">ctx</code> without synchronization.</li>
<li>Must not be called concurrently with readers/writers referencing the same context.</li>
<li>imageInfo flags (HasPartitions, HasSessions) set true</li>
</ul>
</dd></dl>
<p>Limitations / Caveats:</p><ul>
<li>No explicit status code: callers infer success by inspecting ctx->tracksHeader.entries and presence of ctx->trackEntries after invocation.</li>
<li>In case of CRC mismatch trackEntries are retained though not guaranteed trustworthy; caller may wish to discard them or trigger re-read.</li>
<li>Potential memory leak if invoked multiple times without freeing previous arrays.</li>
</ul>
<p>Logging strategy:</p><ul>
<li>FATAL used for unrecoverable structural or resource errors.</li>
<li>TRACE used for informational / soft failures (e.g., CRC mismatch, identifier mismatch, short read).</li>
</ul>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Mutable pointer to an aaruformatContext receiving parsed track metadata. </td></tr>
<tr><tdclass="paramname">entry</td><td>Pointer to the index entry describing this Tracks block (offset required; size not strictly used beyond informational logging and sequential reading).</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>void This function does not return a status code; errors are reported via logging side effects.</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>Not idempotent and not leak-safe if called more than once for a context. </dd>
<dd>
Absence of a returned status requires defensive post-call validation by the caller. </dd>
<dd>
CRC mismatch leaves possibly invalid data in ctx->trackEntries.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="optical_8c.html#a2ce65757ca5209f17d467c51ba7d445d"title="Retrieve the array of track descriptors contained in an opened AaruFormat image.">aaruf_get_tracks()</a></dd>
<dd>
<aclass="el"href="optical_8c.html#a518d8d68debf1b9a24af3eb6bc2f9e49"title="Replace (or clear) the in-memory track table for an AaruFormat image context.">aaruf_set_tracks()</a></dd></dl>
<pclass="definition">Definition at line <aclass="el"href="optical_8c_source.html#l00111">111</a> of file <aclass="el"href="optical_8c_source.html">optical.c</a>.</p>
<p>Sets a DDT v2 entry for a given sector address. </p>
<p>Updates the DDT v2 table(s) with the specified offset, block offset, and sector status for a sector.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to set. </td></tr>
<tr><tdclass="paramname">negative</td><td>Indicates if the sector address is negative. </td></tr>
<tr><tdclass="paramname">offset</td><td>Offset to set for the sector. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Block offset to set for the sector. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Status to set for the sector. </td></tr>
<tr><tdclass="paramname">ddt_entry</td><td>Existing DDT entry or 0 to create a new one. If 0, a new entry is returned.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">true</td><td>if the entry was set successfully, false otherwise. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l00988">988</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<pclass="reference">References <aclass="el"href="log_8h_source.html#l00040">FATAL</a>, <aclass="el"href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <aclass="el"href="ddt__v2_8c_source.html#l01092">set_ddt_multi_level_v2()</a>, <aclass="el"href="ddt__v2_8c_source.html#l01023">set_ddt_single_level_v2()</a>, <aclass="el"href="ddt_8h_source.html#l00156">DdtHeader2::tableShift</a>, <aclass="el"href="log_8h_source.html#l00025">TRACE</a>, and <aclass="el"href="context_8h_source.html#l00189">aaruformat_context::user_data_ddt_header</a>.</p>
<pclass="reference">Referenced by <aclass="el"href="write_8c_source.html#l00098">aaruf_write_sector()</a>.</p>
<p>Sets a multi-level DDT v2 entry for a given sector address. </p>
<p>Used when the DDT table uses multi-level indirection (tableShift > 0).</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to set. </td></tr>
<tr><tdclass="paramname">negative</td><td>Indicates if the sector address is negative. </td></tr>
<tr><tdclass="paramname">offset</td><td>Offset to set for the sector. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Block offset to set for the sector. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Status to set for the sector. </td></tr>
<tr><tdclass="paramname">ddt_entry</td><td>Existing DDT entry or 0 to create a new one. If 0, a new entry is returned.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">true</td><td>if the entry was set successfully, false otherwise. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l01092">1092</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<p>Sets a single-level DDT v2 entry for a given sector address. </p>
<p>Used when the DDT table does not use multi-level indirection.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
<tr><tdclass="paramname">sector_address</td><td>Logical sector address to set. </td></tr>
<tr><tdclass="paramname">negative</td><td>Indicates if the sector address is negative. </td></tr>
<tr><tdclass="paramname">offset</td><td>Offset to set for the sector. </td></tr>
<tr><tdclass="paramname">block_offset</td><td>Block offset to set for the sector. </td></tr>
<tr><tdclass="paramname">sector_status</td><td>Status to set for the sector. </td></tr>
<tr><tdclass="paramname">ddt_entry</td><td>Existing DDT entry or 0 to create a new one. If 0, a new entry is returned.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">true</td><td>if the entry was set successfully, false otherwise. </td></tr>
</table>
</dd>
</dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l01023">1023</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<p>Sets a DDT entry for tape media using a hash-based lookup table. </p>
<p>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.</p>
<p>The function performs the following operations:</p><oltype="1">
<li>Validates the context and verifies it's a tape image</li>
<li>Constructs a DDT entry encoding offset, block alignment, and sector status</li>
<li>Creates a hash table entry with the sector address as the key</li>
<li>Inserts or replaces the entry in the tape DDT hash table</li>
</ol>
<p><b>DDT Entry Format:</b> The DDT entry is a 64-bit value with the following bit layout: </p><divclass="fragment"><divclass="line">Bits 0-(dataShift-1): Sector offset within block (masked by dataShift)</div>
<divclass="line">Bits dataShift-27: Block index (block_offset >> blockAlignmentShift)</div>
<divclass="line">Bits 28-31: Sector status (4 bits for status flags)</div>
<divclass="line">Bits 32-63: Unused (reserved for future use)</div>
</div><!-- fragment --><p><b>Hash Table Management:</b> Uses HASH_REPLACE macro from UTHASH library which:</p><ul>
<li>Adds new entries if the key (sector_address) doesn't exist</li>
<li>Replaces existing entries if the key is found (automatically frees old entry)</li>
<li>Maintains O(1) average lookup time for sector address resolution</li>
</ul>
<p><b>Overflow Detection:</b> 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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>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.</td></tr>
<tr><tdclass="paramname">sector_address</td><td>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.</td></tr>
<tr><tdclass="paramname">offset</td><td>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.</td></tr>
<tr><tdclass="paramname">block_offset</td><td>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.</td></tr>
<tr><tdclass="paramname">sector_status</td><td>Status flags for the sector (4 bits). Common values include:<ul>
<li>0x0 (SectorStatusNotDumped): Sector not yet acquired during image dumping</li>
<li>0x1 (SectorStatusDumped): Sector successfully dumped without error</li>
<li>0x2 (SectorStatusErrored): Error during dumping; data may be incomplete or corrupt</li>
<li>0x3 (SectorStatusMode1Correct): Valid MODE 1 data with regenerable suffix/prefix</li>
<li>0x4 (SectorStatusMode2Form1Ok): Suffix verified/regenerable for MODE 2 Form 1</li>
<li>0x5 (SectorStatusMode2Form2Ok): Suffix matches MODE 2 Form 2 with valid CRC</li>
<li>0x6 (SectorStatusMode2Form2NoCrc): Suffix matches MODE 2 Form 2 but CRC empty/missing</li>
<li>0x7 (SectorStatusTwin): Pointer references a twin sector table</li>
<li>0x9 (SectorStatusEncrypted): Content encrypted and stored encrypted in image</li>
<li>0xA (SectorStatusUnencrypted): Content originally encrypted but stored decrypted in image See <aclass="el"href="enums_8h.html#a74e216af87b18a5fbf0204a52dd1bba0"title="Acquisition / content status for one or more sectors.">SectorStatus</a> enum for complete list of defined values</li>
</ul>
</td></tr>
<tr><tdclass="paramname">ddt_entry</td><td>Pointer to a 64-bit value that will receive the constructed DDT entry.<ul>
<li>If *ddt_entry is 0: A new entry is constructed from the provided parameters</li>
<li>If *ddt_entry is non-zero: The existing value is used directly The constructed or provided value is stored in the hash table.</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">true</td><td>Successfully created and inserted the DDT entry. This occurs when:<ul>
<li>The context and image stream are valid</li>
<li>The image is confirmed to be a tape image (is_tape == true)</li>
<li>The DDT entry fits within the 28-bit limit (< 0xFFFFFFF)</li>
<li>Memory allocation for the hash entry succeeds</li>
<li>The entry is successfully inserted or replaced in the hash table</li>
</ul>
</td></tr>
<tr><tdclass="paramname">false</td><td>Failed to set the DDT entry. This can happen when:<ul>
<li>ctx is NULL or ctx->imageStream is NULL (invalid context)</li>
<li>ctx->is_tape is false (wrong function called for non-tape media)</li>
<li>The DDT entry exceeds 0xFFFFFFF (media too large for big DDT)</li>
<li>Memory allocation fails for the new hash table entry (out of memory)</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dlclass="section note"><dt>Note</dt><dd>This function is only for tape images. For disk images, use <aclass="el"href="ddt__v2_8c.html#a9583b5975c5c0b81902681c07d6f737f"title="Sets a single-level DDT v2 entry for a given sector address.">set_ddt_single_level_v2()</a> or <aclass="el"href="ddt__v2_8c.html#a69ff2e68fe4d92a2d2d469ac69f41d82"title="Sets a multi-level DDT v2 entry for a given sector address.">set_ddt_multi_level_v2()</a> instead, which use array-based DDT structures.</dd>
<dd>
Memory Management:<ul>
<li>Allocates a new <aclass="el"href="structTapeDdtHashEntry.html">TapeDdtHashEntry</a> for each sector</li>
<li>All hash entries remain in context until cleanup</li>
<li>The tapeDdt hash table must be freed during context destruction</li>
</ul>
</dd>
<dd>
Tape Media Characteristics:<ul>
<li>Tape sectors are typically accessed sequentially during streaming</li>
<li>File marks and partition boundaries create sparse address spaces</li>
<li>Hash table provides efficient storage for sparse sector maps</li>
<li>Supports variable block sizes common in tape formats</li>
</ul>
</dd>
<dd>
Error Handling:<ul>
<li>All errors are logged with FATAL level messages</li>
<li>Function returns false immediately on any error condition</li>
<li>TRACE logging marks entry/exit points for debugging</li>
<li>No partial state changes occur on failure</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>The DDT entry overflow check at 0xFFFFFFF (28 bits) is critical. Exceeding this limit indicates the media is too large to fit in the current DDT format, and continuing would cause data corruption.</dd>
<dd>
This function modifies the shared tapeDdt hash table. In multi-threaded environments, external synchronization is required to prevent race conditions.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="structTapeDdtHashEntry.html">TapeDdtHashEntry</a> for the hash table entry structure </dd>
<dd>
<aclass="el"href="ddt__v2_8c.html#aa36e08ed9b99bf6e6e022e810c1a3ad1"title="Sets a DDT v2 entry for a given sector address.">set_ddt_entry_v2()</a> for the main DDT entry point that dispatches to this function </dd>
<dd>
get_ddt_tape() for retrieving tape DDT entries from the hash table </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="ddt__v2_8c_source.html#l01768">1768</a> of file <aclass="el"href="ddt__v2_8c_source.html">ddt_v2.c</a>.</p>
<p>Verifies the integrity of an index block (version 1) in the image stream. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully verified index integrity. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The index header is successfully read from ctx->header.indexOffset</li>
<li>The index identifier matches IndexBlock (version 1 format)</li>
<li>Memory allocation for index entries succeeds</li>
<li>All index entries are successfully read from the image stream</li>
<li>CRC64 calculation completes successfully with version-specific endianness handling</li>
<li>The calculated CRC64 matches the expected CRC64 in the index header</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) Invalid context or stream. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx->imageStream) is NULL or invalid</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_HEADER</td><td>(-6) Index header reading failed. This occurs when:<ul>
<li>Cannot read the complete <aclass="el"href="structIndexHeader.html"title="Index header (version 1) for legacy images (identifier == IndexBlock).">IndexHeader</a> structure from the image stream</li>
<li>File I/O errors prevent accessing the header at ctx->header.indexOffset</li>
<li>Insufficient data available at the specified index offset</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_INDEX</td><td>(-19) Index format or data access errors. This occurs when:<ul>
<li>The index identifier doesn't match IndexBlock (wrong format or corruption)</li>
<li>Cannot read all index entries from the image stream</li>
<li>File I/O errors during index entry reading</li>
<li>Index structure is corrupted or truncated</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_ENOUGH_MEMORY</td><td>(-9) Memory allocation failed. This occurs when:<ul>
<li>Cannot allocate memory for the index entries array</li>
<li>System memory exhaustion prevents loading index data for verification</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_INVALID_BLOCK_CRC</td><td>(-18) CRC64 validation failed. This occurs when:<ul>
<li>The calculated CRC64 doesn't match the expected CRC64 in the index header</li>
<li>Reads all index entries into memory for CRC calculation</li>
<li>Calculates CRC64 over the complete index entries array</li>
<li>Applies version-specific endianness conversion for compatibility</li>
<li>For imageMajorVersion <= AARUF_VERSION_V1: Uses <aclass="el"href="endian_8h.html#a0c0b427a2547aa727e2c5262a174e26b">bswap_64()</a> for byte order correction</li>
<li>Compares calculated CRC64 with the value stored in the index header</li>
</ul>
</dd>
<dd>
Version Compatibility:<ul>
<li>Handles legacy byte order differences from original C# implementation</li>
<li>Supports IndexBlock format (version 1 only)</li>
<li>Does not support IndexBlock2 or IndexBlock3 formats</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Allocates temporary memory for index entries during verification</li>
<li>Automatically frees allocated memory on both success and error conditions</li>
<li>Memory usage is proportional to the number of index entries</li>
</ul>
</dd>
<dd>
Verification Scope:<ul>
<li>Validates index header structure and identifier</li>
<li>Verifies data integrity through CRC64 calculation</li>
<li>Does not validate individual index entry contents or block references</li>
<li>Does not check for logical consistency of referenced blocks</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>This function reads the entire index into memory for CRC calculation. Large indexes may require significant memory allocation.</dd>
<dd>
The function assumes ctx->header.indexOffset points to a valid index location. Invalid offsets will cause file access errors or incorrect validation.</dd>
<dd>
CRC validation failure indicates potential data corruption and may suggest the image file is damaged or has been modified outside of library control. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="index__v1_8c_source.html#l00225">225</a> of file <aclass="el"href="index__v1_8c_source.html">index_v1.c</a>.</p>
<p>Verifies the integrity of an index block (version 2) in the image stream. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully verified index integrity. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The index header is successfully read from ctx->header.indexOffset</li>
<li>The index identifier matches IndexBlock2 (version 2 format)</li>
<li>Memory allocation for index entries succeeds</li>
<li>All index entries are successfully read from the image stream</li>
<li>CRC64 calculation completes successfully with version-specific endianness handling</li>
<li>The calculated CRC64 matches the expected CRC64 in the index header</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) Invalid context or stream. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx->imageStream) is NULL or invalid</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_HEADER</td><td>(-6) Index header reading failed. This occurs when:<ul>
<li>Cannot read the complete <aclass="el"href="structIndexHeader2.html"title="Index header (version 2) with 64‑bit entry counter (identifier == IndexBlock2).">IndexHeader2</a> structure from the image stream</li>
<li>File I/O errors prevent accessing the header at ctx->header.indexOffset</li>
<li>Insufficient data available at the specified index offset</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_INDEX</td><td>(-19) Index format or data access errors. This occurs when:<ul>
<li>The index identifier doesn't match IndexBlock2 (wrong format or corruption)</li>
<li>Cannot read all index entries from the image stream</li>
<li>File I/O errors during index entry reading</li>
<li>Index structure is corrupted or truncated</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_ENOUGH_MEMORY</td><td>(-9) Memory allocation failed. This occurs when:<ul>
<li>Cannot allocate memory for the index entries array</li>
<li>System memory exhaustion prevents loading index data for verification</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_INVALID_BLOCK_CRC</td><td>(-18) CRC64 validation failed. This occurs when:<ul>
<li>The calculated CRC64 doesn't match the expected CRC64 in the index header</li>
<li>Reads all index entries into memory for CRC calculation</li>
<li>Calculates CRC64 over the complete index entries array</li>
<li>Applies version-specific endianness conversion for compatibility</li>
<li>For imageMajorVersion <= AARUF_VERSION_V1: Uses <aclass="el"href="endian_8h.html#a0c0b427a2547aa727e2c5262a174e26b">bswap_64()</a> for byte order correction</li>
<li>Compares calculated CRC64 with the value stored in the <aclass="el"href="structIndexHeader2.html"title="Index header (version 2) with 64‑bit entry counter (identifier == IndexBlock2).">IndexHeader2</a></li>
</ul>
</dd>
<dd>
Version 2 Enhancements:<ul>
<li>Uses <aclass="el"href="structIndexHeader2.html"title="Index header (version 2) with 64‑bit entry counter (identifier == IndexBlock2).">IndexHeader2</a> structure with enhanced metadata support</li>
<li>Maintains compatibility with legacy endianness handling</li>
<li>Supports improved index entry organization compared to version 1</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Allocates temporary memory for index entries during verification</li>
<li>Automatically frees allocated memory on both success and error conditions</li>
<li>Memory usage is proportional to the number of index entries</li>
</ul>
</dd>
<dd>
Verification Scope:<ul>
<li>Validates index header structure and identifier</li>
<li>Verifies data integrity through CRC64 calculation</li>
<li>Does not validate individual index entry contents or block references</li>
<li>Does not check for logical consistency of referenced blocks</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>This function reads the entire index into memory for CRC calculation. Large indexes may require significant memory allocation.</dd>
<dd>
The function assumes ctx->header.indexOffset points to a valid index location. Invalid offsets will cause file access errors or incorrect validation.</dd>
<dd>
CRC validation failure indicates potential data corruption and may suggest the image file is damaged or has been modified outside of library control. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="index__v2_8c_source.html#l00227">227</a> of file <aclass="el"href="index__v2_8c_source.html">index_v2.c</a>.</p>
<p>Verifies the integrity of an index block (version 3) in the image stream. </p>
<p>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.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">ctx</td><td>Pointer to the aaruformat context containing image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dlclass="retval"><dt>Return values</dt><dd>
<tableclass="retval">
<tr><tdclass="paramname">AARUF_STATUS_OK</td><td>(0) Successfully verified index integrity. This is returned when:<ul>
<li>The context and image stream are valid</li>
<li>The index header is successfully read from ctx->header.indexOffset</li>
<li>The index identifier matches IndexBlock3 (version 3 format)</li>
<li>Memory allocation for index entries succeeds</li>
<li>All index entries are successfully read from the image stream</li>
<li>CRC64 calculation completes successfully with version-specific endianness handling</li>
<li>The calculated CRC64 matches the expected CRC64 in the index header</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) Invalid context or stream. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx->imageStream) is NULL or invalid</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_HEADER</td><td>(-6) Index header reading failed. This occurs when:<ul>
<li>Cannot read the complete <aclass="el"href="structIndexHeader3.html"title="Index header (version 3) adding hierarchical chaining (identifier == IndexBlock3).">IndexHeader3</a> structure from the image stream</li>
<li>File I/O errors prevent accessing the header at ctx->header.indexOffset</li>
<li>Insufficient data available at the specified index offset</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_CANNOT_READ_INDEX</td><td>(-19) Index format or data access errors. This occurs when:<ul>
<li>The index identifier doesn't match IndexBlock3 (wrong format or corruption)</li>
<li>Cannot read all index entries from the image stream</li>
<li>File I/O errors during index entry reading</li>
<li>Index structure is corrupted or truncated</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_NOT_ENOUGH_MEMORY</td><td>(-9) Memory allocation failed. This occurs when:<ul>
<li>Cannot allocate memory for the index entries array</li>
<li>System memory exhaustion prevents loading index data for verification</li>
</ul>
</td></tr>
<tr><tdclass="paramname">AARUF_ERROR_INVALID_BLOCK_CRC</td><td>(-18) CRC64 validation failed. This occurs when:<ul>
<li>The calculated CRC64 doesn't match the expected CRC64 in the index header</li>
<li>Reads all main index entries into memory for CRC calculation</li>
<li>Calculates CRC64 over the complete main index entries array</li>
<li>Applies version-specific endianness conversion for compatibility</li>
<li>For imageMajorVersion <= AARUF_VERSION_V1: Uses <aclass="el"href="endian_8h.html#a0c0b427a2547aa727e2c5262a174e26b">bswap_64()</a> for byte order correction</li>
<li>Compares calculated CRC64 with the value stored in the <aclass="el"href="structIndexHeader3.html"title="Index header (version 3) adding hierarchical chaining (identifier == IndexBlock3).">IndexHeader3</a></li>
<li>Maintains compatibility with legacy endianness handling</li>
<li>Supports advanced index entry organization with subindex references</li>
<li>Only validates the main index block CRC - subindex CRCs are not recursively checked</li>
</ul>
</dd>
<dd>
Validation Scope:<ul>
<li>Validates main index header structure and identifier</li>
<li>Verifies data integrity of the primary index entries through CRC64 calculation</li>
<li>Does not validate individual <aclass="el"href="structIndexEntry.html"title="Single index entry describing a block's type, (optional) data classification, and file offset.">IndexEntry</a> contents or block references</li>
<li>Does not check for logical consistency of referenced blocks</li>
<li>Does not recursively validate subindex blocks (unlike hierarchical processing)</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Allocates temporary memory for index entries during verification</li>
<li>Automatically frees allocated memory on both success and error conditions</li>
<li>Memory usage is proportional to the number of entries in the main index only</li>
</ul>
</dd>
<dd>
Subindex Validation Limitation:<ul>
<li>This function does not recursively validate subindex CRCs</li>
<li>Each subindex block contains its own CRC that would need separate validation</li>
<li>For complete integrity verification, subindex blocks should be validated individually</li>
<li>The main index CRC only covers the primary index entries, not the subindex content</li>
</ul>
</dd></dl>
<dlclass="section warning"><dt>Warning</dt><dd>This function reads only the main index into memory for CRC calculation. Subindex blocks are not loaded or validated by this function.</dd>
<dd>
The function assumes ctx->header.indexOffset points to a valid index location. Invalid offsets will cause file access errors or incorrect validation.</dd>
<dd>
CRC validation failure indicates potential data corruption in the main index and may suggest the image file is damaged or has been modified outside of library control.</dd>
<dd>
For complete integrity verification of hierarchical indexes, additional validation of subindex blocks may be required beyond this function's scope. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="index__v3_8c_source.html#l00408">408</a> of file <aclass="el"href="index__v3_8c_source.html">index_v3.c</a>.</p>
<liclass="footer">Generated by <ahref="https://www.doxygen.org/index.html"><imgclass="footer"src="doxygen.svg"width="104"height="31"alt="doxygen"/></a> 1.14.0 </li>