<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>
<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="#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>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>
<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>