Files
libaaruformat/docs/html/index__v2_8c.html

327 lines
20 KiB
HTML
Raw Normal View History

2025-10-11 01:35:43 +01:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libaaruformat: src/index/index_v2.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">libaaruformat<span id="projectnumber">&#160;1.0</span>
</div>
<div id="projectbrief">Aaru Data Preservation Suite - Format Library</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(function(){initNavTree('index__v2_8c.html','',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">index_v2.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;limits.h&gt;</code><br />
<code>#include &lt;stdint.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &quot;<a class="el" href="aaruformat_8h_source.html">aaruformat.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="log_8h_source.html">log.h</a>&quot;</code><br />
<code>#include &quot;utarray.h&quot;</code><br />
</div>
<p><a href="index__v2_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 id="header-func-members" class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a1baad6508d1cde5a712794e956fb3d3c" id="r_a1baad6508d1cde5a712794e956fb3d3c"><td class="memItemLeft" align="right" valign="top">UT_array *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a1baad6508d1cde5a712794e956fb3d3c">process_index_v2</a> (<a class="el" href="structaaruformat__context.html">aaruformat_context</a> *ctx)</td></tr>
<tr class="memdesc:a1baad6508d1cde5a712794e956fb3d3c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Processes an index block (version 2) from the image stream. <br /></td></tr>
<tr class="memitem:ae234e22b16b085d18614110630034db5" id="r_ae234e22b16b085d18614110630034db5"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae234e22b16b085d18614110630034db5">verify_index_v2</a> (<a class="el" href="structaaruformat__context.html">aaruformat_context</a> *ctx)</td></tr>
<tr class="memdesc:ae234e22b16b085d18614110630034db5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Verifies the integrity of an index block (version 2) in the image stream. <br /></td></tr>
</table>
<a name="doc-func-members" id="doc-func-members"></a><h2 id="header-doc-func-members" class="groupheader">Function Documentation</h2>
<a id="a1baad6508d1cde5a712794e956fb3d3c" name="a1baad6508d1cde5a712794e956fb3d3c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a1baad6508d1cde5a712794e956fb3d3c">&#9670;&#160;</a></span>process_index_v2()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">UT_array * process_index_v2 </td>
<td>(</td>
<td class="paramtype"><a class="el" href="structaaruformat__context.html">aaruformat_context</a> *</td> <td class="paramname"><span class="paramname"><em>ctx</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<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 <a class="el" href="structIndexHeader2.html" title="Index header (version 2) with 64bit entry counter (identifier == IndexBlock2).">IndexHeader2</a> structure followed by a sequential list of <a class="el" href="structIndexEntry.html" title="Single index entry describing a block&#39;s type, (optional) data classification, and file offset.">IndexEntry</a> structures, validating the index identifier for format correctness.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">ctx</td><td>Pointer to the aaruformat context containing the image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns one of the following values: </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="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-&gt;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><td class="paramname">NULL</td><td>Index processing failed. This occurs when:<ul>
<li>The context parameter is NULL</li>
<li>The image stream (ctx-&gt;imageStream) is NULL or invalid</li>
<li>Cannot read the <a class="el" href="structIndexHeader2.html" title="Index header (version 2) with 64bit 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>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Index Structure (Version 2):<ul>
<li><a class="el" href="structIndexHeader2.html" title="Index header (version 2) with 64bit entry counter (identifier == IndexBlock2).">IndexHeader2</a>: Contains identifier (IndexBlock2), entry count, and enhanced metadata</li>
<li><a class="el" href="structIndexEntry.html" title="Single index entry describing a block&#39;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 <a class="el" href="structIndexEntry.html" title="Single index entry describing a block&#39;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>
<dl class="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 <a class="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-&gt;header.indexOffset points to a valid index block. Invalid offsets may cause file access errors or reading incorrect data. </dd></dl>
<p class="definition">Definition at line <a class="el" href="index__v2_8c_source.html#l00081">81</a> of file <a class="el" href="index__v2_8c_source.html">index_v2.c</a>.</p>
<p class="reference">References <a class="el" href="index_8h_source.html#l00081">IndexHeader2::entries</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="context_8h_source.html#l00175">aaruformat_context::header</a>, <a class="el" href="index_8h_source.html#l00080">IndexHeader2::identifier</a>, <a class="el" href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <a class="el" href="enums_8h_source.html#l00146">IndexBlock2</a>, <a class="el" href="header_8h_source.html#l00115">AaruHeaderV2::indexOffset</a>, and <a class="el" href="log_8h_source.html#l00025">TRACE</a>.</p>
<p class="reference">Referenced by <a class="el" href="open_8c_source.html#l00125">aaruf_open()</a>, and <a class="el" href="verify_8c_source.html#l00130">aaruf_verify_image()</a>.</p>
</div>
</div>
<a id="ae234e22b16b085d18614110630034db5" name="ae234e22b16b085d18614110630034db5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae234e22b16b085d18614110630034db5">&#9670;&#160;</a></span>verify_index_v2()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t verify_index_v2 </td>
<td>(</td>
<td class="paramtype"><a class="el" href="structaaruformat__context.html">aaruformat_context</a> *</td> <td class="paramname"><span class="paramname"><em>ctx</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<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>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">ctx</td><td>Pointer to the aaruformat context containing image stream and header information.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns one of the following status codes: </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="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-&gt;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><td class="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-&gt;imageStream) is NULL or invalid</li>
</ul>
</td></tr>
<tr><td class="paramname">AARUF_ERROR_CANNOT_READ_HEADER</td><td>(-6) Index header reading failed. This occurs when:<ul>
<li>Cannot read the complete <a class="el" href="structIndexHeader2.html" title="Index header (version 2) with 64bit entry counter (identifier == IndexBlock2).">IndexHeader2</a> structure from the image stream</li>
<li>File I/O errors prevent accessing the header at ctx-&gt;header.indexOffset</li>
<li>Insufficient data available at the specified index offset</li>
</ul>
</td></tr>
<tr><td class="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><td class="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><td class="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>Index data corruption is detected</li>
<li>Data integrity verification fails indicating potential file damage</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>CRC64 Validation Process:<ul>
<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 &lt;= AARUF_VERSION_V1: Uses <a class="el" href="endian_8h.html#a0c0b427a2547aa727e2c5262a174e26b">bswap_64()</a> for byte order correction</li>
<li>Compares calculated CRC64 with the value stored in the <a class="el" href="structIndexHeader2.html" title="Index header (version 2) with 64bit entry counter (identifier == IndexBlock2).">IndexHeader2</a></li>
</ul>
</dd>
<dd>
Version 2 Enhancements:<ul>
<li>Uses <a class="el" href="structIndexHeader2.html" title="Index header (version 2) with 64bit 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>
<dl class="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-&gt;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>
<p class="definition">Definition at line <a class="el" href="index__v2_8c_source.html#l00227">227</a> of file <a class="el" href="index__v2_8c_source.html">index_v2.c</a>.</p>
<p class="reference">References <a class="el" href="crc64_8c_source.html#l00141">aaruf_crc64_final()</a>, <a class="el" href="crc64_8c_source.html#l00155">aaruf_crc64_free()</a>, <a class="el" href="crc64_8c_source.html#l00032">aaruf_crc64_init()</a>, <a class="el" href="crc64_8c_source.html#l00055">aaruf_crc64_update()</a>, <a class="el" href="errors_8h_source.html#l00045">AARUF_ERROR_CANNOT_READ_HEADER</a>, <a class="el" href="errors_8h_source.html#l00043">AARUF_ERROR_CANNOT_READ_INDEX</a>, <a class="el" href="errors_8h_source.html#l00057">AARUF_ERROR_INVALID_BLOCK_CRC</a>, <a class="el" href="errors_8h_source.html#l00040">AARUF_ERROR_NOT_AARUFORMAT</a>, <a class="el" href="errors_8h_source.html#l00048">AARUF_ERROR_NOT_ENOUGH_MEMORY</a>, <a class="el" href="errors_8h_source.html#l00075">AARUF_STATUS_OK</a>, <a class="el" href="consts_8h_source.html#l00071">AARUF_VERSION_V1</a>, <a class="el" href="endian_8h_source.html#l00081">bswap_64</a>, <a class="el" href="index_8h_source.html#l00082">IndexHeader2::crc64</a>, <a class="el" href="index_8h_source.html#l00081">IndexHeader2::entries</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="context_8h_source.html#l00175">aaruformat_context::header</a>, <a class="el" href="index_8h_source.html#l00080">IndexHeader2::identifier</a>, <a class="el" href="header_8h_source.html#l00110">AaruHeaderV2::imageMajorVersion</a>, <a class="el" href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <a class="el" href="enums_8h_source.html#l00146">IndexBlock2</a>, <a class="el" href="header_8h_source.html#l00115">AaruHeaderV2::indexOffset</a>, and <a class="el" href="log_8h_source.html#l00025">TRACE</a>.</p>
<p class="reference">Referenced by <a class="el" href="verify_8c_source.html#l00130">aaruf_verify_image()</a>.</p>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<div id="page-nav" class="page-nav-panel">
<div id="page-nav-resize-handle"></div>
<div id="page-nav-tree">
<div id="page-nav-contents">
</div><!-- page-nav-contents -->
</div><!-- page-nav-tree -->
</div><!-- page-nav -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a href="dir_19ac67bde96fa7098d9c89fb8e36db69.html">index</a></li><li class="navelem"><a href="index__v2_8c.html">index_v2.c</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
</ul>
</div>
</body>
</html>