Files
libaaruformat/docs/html/identify_8c.html

306 lines
16 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/identify.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('identify_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">identify.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;errno.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;<a class="el" href="aaruformat_8h_source.html">aaruformat.h</a>&gt;</code><br />
</div>
<p><a href="identify_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:a74c444fbd394f58aefd2fabff221231b" id="r_a74c444fbd394f58aefd2fabff221231b"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a74c444fbd394f58aefd2fabff221231b">aaruf_identify</a> (const char *filename)</td></tr>
<tr class="memdesc:a74c444fbd394f58aefd2fabff221231b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Identifies a file as an AaruFormat image using a file path. <br /></td></tr>
<tr class="memitem:a6f30353aff3ece1e889542c26f7146e2" id="r_a6f30353aff3ece1e889542c26f7146e2"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a6f30353aff3ece1e889542c26f7146e2">aaruf_identify_stream</a> (FILE *image_stream)</td></tr>
<tr class="memdesc:a6f30353aff3ece1e889542c26f7146e2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Identifies a file as an AaruFormat image using an open 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="a74c444fbd394f58aefd2fabff221231b" name="a74c444fbd394f58aefd2fabff221231b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a74c444fbd394f58aefd2fabff221231b">&#9670;&#160;</a></span>aaruf_identify()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int aaruf_identify </td>
<td>(</td>
<td class="paramtype">const char *</td> <td class="paramname"><span class="paramname"><em>filename</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Identifies a file as an AaruFormat image using a file path. </p>
<p>Opens the file at the given path and determines if it is an AaruFormat image by examining the file header for valid AaruFormat signatures and version information. This function provides a simple file-based interface that handles file opening, identification, and cleanup automatically. It delegates the actual identification logic to <a class="el" href="#a6f30353aff3ece1e889542c26f7146e2" title="Identifies a file as an AaruFormat image using an open stream.">aaruf_identify_stream()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">filename</td><td>Path to the file to identify (must be accessible and readable).</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">100</td><td>Maximum confidence - Definitive AaruFormat image. This is returned when:<ul>
<li>The file header contains a valid AaruFormat signature (DIC_MAGIC or AARU_MAGIC)</li>
<li>The image major version is less than or equal to the supported version (AARUF_VERSION)</li>
<li>The file structure passes all header validation checks</li>
<li>This indicates the file is definitely a supported AaruFormat image</li>
</ul>
</td></tr>
<tr><td class="paramname">0</td><td>Not recognized - File is not an AaruFormat image. This is returned when:<ul>
<li>The file header doesn't contain a recognized AaruFormat signature</li>
<li>The image major version exceeds the maximum supported version</li>
<li>The file header cannot be read completely (file too small or corrupted)</li>
<li>The file format doesn't match AaruFormat specifications</li>
</ul>
</td></tr>
<tr><td class="paramname">Positive</td><td>errno values - File access errors from system calls. Common values include:<ul>
<li>ENOENT (2) - File not found or path doesn't exist</li>
<li>EACCES (13) - Permission denied, file not readable</li>
<li>EISDIR (21) - Path refers to a directory, not a file</li>
<li>EMFILE (24) - Too many open files (process limit reached)</li>
<li>ENFILE (23) - System limit on open files reached</li>
<li>ENOMEM (12) - Insufficient memory to open file</li>
<li>EIO (5) - I/O error occurred during file access</li>
<li>Other platform-specific errno values from fopen()</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Identification Process:<ul>
<li>Opens the file in binary read mode ("rb")</li>
<li>Delegates identification to <a class="el" href="#a6f30353aff3ece1e889542c26f7146e2" title="Identifies a file as an AaruFormat image using an open stream.">aaruf_identify_stream()</a> for actual header analysis</li>
<li>Automatically closes the file stream regardless of identification result</li>
<li>Returns system errno values directly if file opening fails</li>
</ul>
</dd>
<dd>
Confidence Scoring:<ul>
<li>Uses binary scoring: 100 (definitive match) or 0 (no match)</li>
<li>No intermediate confidence levels are returned</li>
<li>Designed for simple yes/no identification rather than probabilistic matching</li>
</ul>
</dd>
<dd>
Version Compatibility:<ul>
<li>Only recognizes AaruFormat versions up to AARUF_VERSION</li>
<li>Future versions beyond library support are treated as unrecognized</li>
<li>Backwards compatible with older DIC_MAGIC identifiers</li>
</ul>
</dd></dl>
<dl class="section warning"><dt>Warning</dt><dd>The function opens and closes the file for each identification. For repeated operations on the same file, consider using <a class="el" href="#a6f30353aff3ece1e889542c26f7146e2" title="Identifies a file as an AaruFormat image using an open stream.">aaruf_identify_stream()</a> with a pre-opened stream for better performance.</dd>
<dd>
File access permissions and availability are checked at runtime. Network files or files on removable media may cause variable access times.</dd>
<dd>
The function performs minimal file content validation. A positive result indicates the file appears to be AaruFormat but doesn't guarantee the entire file is valid or uncorrupted. </dd></dl>
<p class="definition">Definition at line <a class="el" href="identify_8c_source.html#l00084">84</a> of file <a class="el" href="identify_8c_source.html">identify.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>, and <a class="el" href="identify_8c_source.html#l00163">aaruf_identify_stream()</a>.</p>
2025-10-11 01:35:43 +01:00
</div>
</div>
<a id="a6f30353aff3ece1e889542c26f7146e2" name="a6f30353aff3ece1e889542c26f7146e2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6f30353aff3ece1e889542c26f7146e2">&#9670;&#160;</a></span>aaruf_identify_stream()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int aaruf_identify_stream </td>
<td>(</td>
<td class="paramtype">FILE *</td> <td class="paramname"><span class="paramname"><em>image_stream</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Identifies a file as an AaruFormat image using an open stream. </p>
<p>Determines if the provided stream is an AaruFormat image by reading and validating the file header at the beginning of the stream. This function performs the core identification logic by checking for valid AaruFormat signatures and version compatibility. It's designed to work with any FILE stream, making it suitable for integration with existing file handling code.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">image_stream</td><td>Open FILE stream positioned at any location (will be repositioned to start).</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">100</td><td>Maximum confidence - Definitive AaruFormat image. This is returned when:<ul>
<li>The stream is successfully repositioned to the beginning</li>
<li>The AaruFormat header is successfully read (<a class="el" href="structAaruHeader.html" title="Version 1 container header placed at offset 0 for legacy / initial format.">AaruHeader</a> structure)</li>
<li>The header identifier matches either DIC_MAGIC or AARU_MAGIC (valid signatures)</li>
<li>The image major version is less than or equal to AARUF_VERSION (supported version)</li>
<li>All validation checks pass indicating a compatible AaruFormat image</li>
</ul>
</td></tr>
<tr><td class="paramname">0</td><td>Not recognized - Stream is not an AaruFormat image. This is returned when:<ul>
<li>The stream parameter is NULL</li>
<li>Cannot read a complete <a class="el" href="structAaruHeader.html" title="Version 1 container header placed at offset 0 for legacy / initial format.">AaruHeader</a> structure from the stream (file too small)</li>
<li>The header identifier doesn't match DIC_MAGIC or AARU_MAGIC (wrong format)</li>
<li>The image major version exceeds AARUF_VERSION (unsupported future version)</li>
<li>Any validation check fails indicating the stream is not a valid AaruFormat image</li>
</ul>
</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Stream Handling:<ul>
<li>Always seeks to position 0 at the beginning of the function</li>
<li>Reads exactly one <a class="el" href="structAaruHeader.html" title="Version 1 container header placed at offset 0 for legacy / initial format.">AaruHeader</a> structure (size depends on format version)</li>
<li>Does not restore the original stream position after identification</li>
<li>Stream remains open and positioned after the header on function return</li>
</ul>
</dd>
<dd>
Signature Recognition:<ul>
<li>DIC_MAGIC: Legacy identifier from original DiscImageChef format</li>
<li>AARU_MAGIC: Current AaruFormat identifier</li>
<li>Both signatures are accepted for backwards compatibility</li>
<li>Signature validation is performed using exact byte matching</li>
</ul>
</dd>
<dd>
Version Validation:<ul>
<li>Only checks the major version number for compatibility</li>
<li>Minor version differences are ignored (assumed backwards compatible)</li>
<li>Future major versions are rejected to prevent compatibility issues</li>
<li>Version check prevents attempting to read unsupported format variants</li>
</ul>
</dd>
<dd>
Confidence Scoring:<ul>
<li>Binary result: 100 (definitive) or 0 (not recognized)</li>
<li>No probabilistic or partial matching</li>
<li>Designed for definitive identification rather than format detection</li>
</ul>
</dd></dl>
<dl class="section warning"><dt>Warning</dt><dd>The function modifies the stream position by seeking to the beginning and reading the header. The stream position is not restored.</dd>
<dd>
This function performs only header-level validation. A positive result indicates the file appears to have a valid AaruFormat header but doesn't guarantee the entire image structure is valid or uncorrupted.</dd>
<dd>
The stream must support seeking operations. Non-seekable streams (like pipes or network streams) may cause undefined behavior.</dd>
<dd>
No error codes are returned for I/O failures during header reading. Such failures result in a return value of 0 (not recognized). </dd></dl>
<p class="definition">Definition at line <a class="el" href="identify_8c_source.html#l00163">163</a> of file <a class="el" href="identify_8c_source.html">identify.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="consts_8h_source.html#l00064">AARU_MAGIC</a>, <a class="el" href="consts_8h_source.html#l00068">AARUF_VERSION</a>, <a class="el" href="consts_8h_source.html#l00061">DIC_MAGIC</a>, <a class="el" href="header_8h_source.html#l00078">AaruHeader::identifier</a>, and <a class="el" href="header_8h_source.html#l00080">AaruHeader::imageMajorVersion</a>.</p>
2025-10-11 01:35:43 +01:00
<p class="reference">Referenced by <a class="el" href="identify_8c_source.html#l00084">aaruf_identify()</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="identify_8c.html">identify.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>