Files
libaaruformat/docs/html/open_8c.html

285 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/open.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('open_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">open.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;errno.h&gt;</code><br />
<code>#include &lt;inttypes.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;<a class="el" href="aaruformat_8h_source.html">aaruformat.h</a>&gt;</code><br />
<code>#include &quot;<a class="el" href="internal_8h_source.html">internal.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="open_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:a356a7467b41a2929a27a6639cd3a2b50" id="r_a356a7467b41a2929a27a6639cd3a2b50"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a356a7467b41a2929a27a6639cd3a2b50">cleanup_open_failure</a> (<a class="el" href="structaaruformat__context.html">aaruformat_context</a> *ctx)</td></tr>
<tr class="memitem:afc4932cdc795ffb2ef3a33d5b8c57656" id="r_afc4932cdc795ffb2ef3a33d5b8c57656"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#afc4932cdc795ffb2ef3a33d5b8c57656">aaruf_open</a> (const char *filepath)</td></tr>
<tr class="memdesc:afc4932cdc795ffb2ef3a33d5b8c57656"><td class="mdescLeft">&#160;</td><td class="mdescRight">Opens an existing AaruFormat image file. <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="afc4932cdc795ffb2ef3a33d5b8c57656" name="afc4932cdc795ffb2ef3a33d5b8c57656"></a>
<h2 class="memtitle"><span class="permalink"><a href="#afc4932cdc795ffb2ef3a33d5b8c57656">&#9670;&#160;</a></span>aaruf_open()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void * aaruf_open </td>
<td>(</td>
<td class="paramtype">const char *</td> <td class="paramname"><span class="paramname"><em>filepath</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Opens an existing AaruFormat image file. </p>
<p>Opens the specified image file and returns a pointer to the initialized aaruformat context. This function performs comprehensive validation of the image file format, reads and processes all index entries, initializes data structures for reading operations, and sets up caches for optimal performance. It supports multiple AaruFormat versions and handles various block types including data blocks, deduplication tables, metadata, and checksums.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">filepath</td><td>Path to the image file to open.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns one of the following: </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname">aaruformatContext*</td><td>Successfully opened and initialized context. The returned pointer contains:<ul>
<li>Validated AaruFormat headers and metadata</li>
<li>Processed index entries with all discoverable blocks</li>
<li>Loaded deduplication tables (DDT) for efficient sector access</li>
<li>Initialized block and header caches for performance</li>
<li>Open file stream ready for reading operations</li>
<li>Populated image information and geometry data</li>
<li>ECC context initialized for error correction support</li>
</ul>
</td></tr>
<tr><td class="paramname">NULL</td><td>Opening failed. The specific error can be determined by checking errno, which will be set to:<ul>
<li>AARUF_ERROR_NOT_ENOUGH_MEMORY (-9) when memory allocation fails for:<ul>
<li>Context allocation</li>
<li>Readable sector tags bitmap allocation</li>
<li>Application version string allocation</li>
<li>Image version string allocation</li>
</ul>
</li>
<li>AARUF_ERROR_FILE_TOO_SMALL (-2) when file reading fails:<ul>
<li>Cannot read the AaruFormat header (file too small or corrupted)</li>
<li>Cannot read the extended header for version 2+ formats</li>
</ul>
</li>
<li>AARUF_ERROR_NOT_AARUFORMAT (-1) when format validation fails:<ul>
<li>File identifier doesn't match DIC_MAGIC or AARU_MAGIC</li>
<li>File is not a valid AaruFormat image</li>
</ul>
</li>
<li>AARUF_ERROR_INCOMPATIBLE_VERSION (-3) when:<ul>
<li>Image major version exceeds the maximum supported version</li>
<li>Future format versions that cannot be read by this library</li>
</ul>
</li>
<li>AARUF_ERROR_CANNOT_READ_INDEX (-4) when index processing fails:<ul>
<li>Cannot seek to the index offset specified in the header</li>
<li>Cannot read the index signature</li>
<li>Index signature is not a recognized index block type</li>
<li>Index processing functions return NULL (corrupted index)</li>
</ul>
</li>
<li>Other error codes may be propagated from block processing functions:<ul>
<li>Data block processing errors</li>
<li>DDT processing errors</li>
<li>Metadata processing errors</li>
</ul>
</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Format Support:<ul>
<li>Supports AaruFormat versions 1.x and 2.x</li>
<li>Automatically detects and handles different index formats (v1, v2, v3)</li>
<li>Backwards compatible with older DIC format identifiers</li>
<li>Handles both small and large deduplication tables</li>
</ul>
</dd>
<dd>
Block Processing:<ul>
<li>Processes all indexed blocks including data, DDT, geometry, metadata, tracks, CICM, dump hardware, and checksums</li>
<li>Non-critical block processing errors are logged but don't prevent opening</li>
<li>Critical errors (DDT processing failures) cause opening to fail</li>
<li>Unknown block types are logged but ignored</li>
</ul>
</dd>
<dd>
Memory Management:<ul>
<li>Allocates memory for various context structures and caches</li>
<li>On failure, all previously allocated memory is properly cleaned up</li>
<li>The returned context must be freed using <a class="el" href="decls_8h.html#a6823e139f81a9dfd08efcb0e9b213a49" title="Close an Aaru image context, flushing pending data structures and releasing resources.">aaruf_close()</a></li>
</ul>
</dd>
<dd>
Performance Optimization:<ul>
<li>Initializes block and header caches based on sector size and available memory</li>
<li>Cache sizes are calculated to optimize memory usage and access patterns</li>
<li>ECC context is pre-initialized for Compact Disc support</li>
</ul>
</dd></dl>
<dl class="section warning"><dt>Warning</dt><dd>The function requires a valid user data deduplication table to be present. Images without a DDT will fail to open even if otherwise valid.</dd>
<dd>
File access is performed in binary read mode. The file must be accessible and not locked by other processes.</dd>
<dd>
Some memory allocations (version strings) are optional and failure doesn't prevent opening, but may affect functionality that depends on version information. </dd></dl>
<p>&lt; Size in bytes (UTF-16LE) of application name field (32 UTF-16 code units).</p>
<p>&lt; Size in bytes (UTF-16LE) of application name field (32 UTF-16 code units).</p>
<p>&lt; Size in bytes (UTF-16LE) of application name field (32 UTF-16 code units).</p>
<p class="definition">Definition at line <a class="el" href="open_8c_source.html#l00125">125</a> of file <a class="el" href="open_8c_source.html">open.c</a>.</p>
2025-10-11 12:43:39 +01:00
<p class="reference">References <a class="el" href="decls_8h_source.html#l00045">AARU_CALL</a>, <a class="el" href="decls_8h_source.html#l00054">AARU_EXPORT</a>, <a class="el" href="header_8h_source.html#l00059">AARU_HEADER_APP_NAME_LEN</a>, <a class="el" href="consts_8h_source.html#l00064">AARU_MAGIC</a>, <a class="el" href="close_8c_source.html#l03995">aaruf_close()</a>, <a class="el" href="ecc__cd_8c_source.html#l00035">aaruf_ecc_cd_init()</a>, <a class="el" href="errors_8h_source.html#l00043">AARUF_ERROR_CANNOT_READ_INDEX</a>, <a class="el" href="errors_8h_source.html#l00041">AARUF_ERROR_FILE_TOO_SMALL</a>, <a class="el" href="errors_8h_source.html#l00042">AARUF_ERROR_INCOMPATIBLE_VERSION</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="helpers_8c_source.html#l00339">aaruf_get_xml_mediatype()</a>, <a class="el" href="errors_8h_source.html#l00075">AARUF_STATUS_OK</a>, <a class="el" href="consts_8h_source.html#l00068">AARUF_VERSION</a>, <a class="el" href="consts_8h_source.html#l00075">AARUF_VERSION_V2</a>, <a class="el" href="enums_8h_source.html#l00159">AaruMetadataJsonBlock</a>, <a class="el" href="aaru_8h_source.html#l00877">ImageInfo::Application</a>, <a class="el" href="header_8h_source.html#l00109">AaruHeaderV2::application</a>, <a class="el" href="header_8h_source.html#l00112">AaruHeaderV2::applicationMajorVersion</a>, <a class="el" href="header_8h_source.html#l00113">AaruHeaderV2::applicationMinorVersion</a>, <a class="el" href="aaru_8h_source.html#l00878">ImageInfo::ApplicationVersion</a>, <a class="el" href="context_8h_source.html#l00257">aaruformat_context::block_cache</a>, <a class="el" href="context_8h_source.html#l00256">aaruformat_context::block_header_cache</a>, <a class="el" href="enums_8h_source.html#l00219">BlockMedia</a>, <a class="el" href="index_8h_source.html#l00110">IndexEntry::blockType</a>, <a class="el" href="lru_8h_source.html#l00048">CacheHeader::cache</a>, <a class="el" href="enums_8h_source.html#l00152">ChecksumBlock</a>, <a class="el" href="enums_8h_source.html#l00151">CicmBlock</a>, <a class="el" href="open_8c_source.html#l00031">cleanup_open_failure()</a>, <a class="el" href="aaru_8h_source.html#l00879">ImageInfo::CreationTime</a>, <a class="el" href="header_8h_source.html#l00116">AaruHeaderV2::creationTime</a>, <a class="el" href="context_8h_source.html#l00234">aaruformat_context::cylinders</a>, <a class="el" href="enums_8h_source.html#l00141">DataBlock</a>, <a class="el" href="index_8h_source.html#l00111">IndexEntry::dataType</a>, <a class="el" href="enums_8h_source.html#l00142">DeDuplicationTable</a>, <a class="el" href="enums_8h_source.html#l00143">DeDuplicationTable2</a>, <a class="el" href="consts_8h_source.html#l00061">DIC_MAGIC</a>, <a class="el" href="enums_8h_source.html#l00156">DumpHardwareBlock</a>, <a class="el" href="context_8h_source.html#l00248">aaruformat_context::ecc_cd_context</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="context_8h_source.html#l00229">aaruformat_context::geometry_block</a>, <a class="el" href="enums_8h_source.html#l00148">GeometryBlock</a>, <a class="el" href="context_8h_source.html#l00175">aaruformat_context::header</a>, <a class="el" href="context_8h_source.html#l00235">aaruformat_context::heads</a>, <a class="el" href="header_8h_source.html#l00108">AaruHeaderV2::identifier</a>, <a class="el" href="data_8h_source.html#l00092">GeometryBlockHeader::identifier</a>, <a class="el" href="context_8h_source.html#l00260">aaruformat_context::image_info</a>, <a class="el" href="header_8h_source.html#l00110">AaruHeaderV2::imageMajorVersion</a>, <a class="el" href="header_8h_source.html#l00111">AaruHeaderV2::imageMinorVersion</a>, <a class="el" href="aaru_8h_source.html#l00873">ImageInfo::ImageSize</a>, <a class="el" href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <a class="el" href="enums_8h_source.html#l00145">IndexBlock</a>, <a class="el" href="enums_8h
2025-10-11 01:35:43 +01:00
</div>
</div>
<a id="a356a7467b41a2929a27a6639cd3a2b50" name="a356a7467b41a2929a27a6639cd3a2b50"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a356a7467b41a2929a27a6639cd3a2b50">&#9670;&#160;</a></span>cleanup_open_failure()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void cleanup_open_failure </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>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p class="definition">Definition at line <a class="el" href="open_8c_source.html#l00031">31</a> of file <a class="el" href="open_8c_source.html">open.c</a>.</p>
<p class="reference">References <a class="el" href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, and <a class="el" href="context_8h_source.html#l00263">aaruformat_context::readableSectorTags</a>.</p>
<p class="reference">Referenced by <a class="el" href="open_8c_source.html#l00125">aaruf_open()</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="open_8c.html">open.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>