mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
314 lines
20 KiB
HTML
314 lines
20 KiB
HTML
<!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/ddt/ddt_v1.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"> 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('ddt__v1_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">ddt_v1.c File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="textblock"><code>#include <inttypes.h></code><br />
|
|
<code>#include <stdint.h></code><br />
|
|
<code>#include <stdio.h></code><br />
|
|
<code>#include <stdlib.h></code><br />
|
|
<code>#include "<a class="el" href="errors_8h_source.html">errors.h</a>"</code><br />
|
|
<code>#include "<a class="el" href="aaruformat_8h_source.html">aaruformat.h</a>"</code><br />
|
|
<code>#include "<a class="el" href="log_8h_source.html">log.h</a>"</code><br />
|
|
</div>
|
|
<p><a href="ddt__v1_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:abaf38090f967423898b99e0455751c07" id="r_abaf38090f967423898b99e0455751c07"><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="#abaf38090f967423898b99e0455751c07">process_ddt_v1</a> (<a class="el" href="structaaruformat__context.html">aaruformat_context</a> *ctx, <a class="el" href="structIndexEntry.html">IndexEntry</a> *entry, bool *found_user_data_ddt)</td></tr>
|
|
<tr class="memdesc:abaf38090f967423898b99e0455751c07"><td class="mdescLeft"> </td><td class="mdescRight">Processes a DDT v1 block from the image stream. <br /></td></tr>
|
|
<tr class="memitem:aabd621530978c71e2abb20d78098453e" id="r_aabd621530978c71e2abb20d78098453e"><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="#aabd621530978c71e2abb20d78098453e">decode_ddt_entry_v1</a> (<a class="el" href="structaaruformat__context.html">aaruformat_context</a> *ctx, const uint64_t sector_address, uint64_t *offset, uint64_t *block_offset, uint8_t *sector_status)</td></tr>
|
|
<tr class="memdesc:aabd621530978c71e2abb20d78098453e"><td class="mdescLeft"> </td><td class="mdescRight">Decodes a DDT v1 entry for a given sector address. <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="aabd621530978c71e2abb20d78098453e" name="aabd621530978c71e2abb20d78098453e"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aabd621530978c71e2abb20d78098453e">◆ </a></span>decode_ddt_entry_v1()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int32_t decode_ddt_entry_v1 </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>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const uint64_t</td> <td class="paramname"><span class="paramname"><em>sector_address</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">uint64_t *</td> <td class="paramname"><span class="paramname"><em>offset</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">uint64_t *</td> <td class="paramname"><span class="paramname"><em>block_offset</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">uint8_t *</td> <td class="paramname"><span class="paramname"><em>sector_status</em></span> )</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<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>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">ctx</td><td>Pointer to the aaruformat context containing the loaded DDT table. </td></tr>
|
|
<tr><td class="paramname">sector_address</td><td>Logical sector address to decode (must be within valid range). </td></tr>
|
|
<tr><td class="paramname">offset</td><td>Pointer to store the resulting sector offset within the block. </td></tr>
|
|
<tr><td class="paramname">block_offset</td><td>Pointer to store the resulting block offset in the image. </td></tr>
|
|
<tr><td class="paramname">sector_status</td><td>Pointer to store the sector status (dumped or not dumped).</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 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><td class="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>
|
|
<dl class="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>
|
|
<dl class="section warning"><dt>Warning</dt><dd>The function assumes:<ul>
|
|
<li>The DDT table (ctx->userDataDdt) has been properly loaded by <a class="el" href="#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>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="ddt__v1_8c_source.html#l00405">405</a> of file <a class="el" href="ddt__v1_8c_source.html">ddt_v1.c</a>.</p>
|
|
|
|
<p class="reference">References <a class="el" href="errors_8h_source.html#l00065">AARUF_ERROR_INCORRECT_DATA_SIZE</a>, <a class="el" href="errors_8h_source.html#l00040">AARUF_ERROR_NOT_AARUFORMAT</a>, <a class="el" href="errors_8h_source.html#l00075">AARUF_STATUS_OK</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <a class="el" href="enums_8h_source.html#l00231">SectorStatusDumped</a>, <a class="el" href="enums_8h_source.html#l00230">SectorStatusNotDumped</a>, <a class="el" href="context_8h_source.html#l00195">aaruformat_context::shift</a>, <a class="el" href="log_8h_source.html#l00025">TRACE</a>, and <a class="el" href="context_8h_source.html#l00181">aaruformat_context::user_data_ddt</a>.</p>
|
|
|
|
<p class="reference">Referenced by <a class="el" href="read_8c_source.html#l00253">aaruf_read_sector()</a>.</p>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="abaf38090f967423898b99e0455751c07" name="abaf38090f967423898b99e0455751c07"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#abaf38090f967423898b99e0455751c07">◆ </a></span>process_ddt_v1()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int32_t process_ddt_v1 </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>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype"><a class="el" href="structIndexEntry.html">IndexEntry</a> *</td> <td class="paramname"><span class="paramname"><em>entry</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">bool *</td> <td class="paramname"><span class="paramname"><em>found_user_data_ddt</em></span> )</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<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>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">ctx</td><td>Pointer to the aaruformat context. </td></tr>
|
|
<tr><td class="paramname">entry</td><td>Pointer to the index entry describing the DDT block. </td></tr>
|
|
<tr><td class="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>
|
|
<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 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><td class="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>(-1) The context or image stream is invalid (NULL pointers).</td></tr>
|
|
<tr><td class="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><td class="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>
|
|
<dl class="section note"><dt>Note</dt><dd>The function exhibits different error handling strategies depending on the operation:<ul>
|
|
<li>Critical errors (seek failures, header read failures, decompression failures) cause immediate return</li>
|
|
<li>Non-critical errors (memory allocation failures, unknown compression types) allow processing to continue</li>
|
|
<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>
|
|
<dl class="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>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="ddt__v1_8c_source.html#l00085">85</a> of file <a class="el" href="ddt__v1_8c_source.html">ddt_v1.c</a>.</p>
|
|
|
|
<p class="reference">References <a class="el" href="errors_8h_source.html#l00056">AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK</a>, <a class="el" href="errors_8h_source.html#l00046">AARUF_ERROR_CANNOT_READ_BLOCK</a>, <a class="el" href="errors_8h_source.html#l00040">AARUF_ERROR_NOT_AARUFORMAT</a>, <a class="el" href="lzma_8c_source.html#l00039">aaruf_lzma_decode_buffer()</a>, <a class="el" href="errors_8h_source.html#l00075">AARUF_STATUS_OK</a>, <a class="el" href="enums_8h_source.html#l00121">CdSectorPrefixCorrected</a>, <a class="el" href="enums_8h_source.html#l00122">CdSectorSuffixCorrected</a>, <a class="el" href="ddt_8h_source.html#l00072">DdtHeader::cmpLength</a>, <a class="el" href="ddt_8h_source.html#l00069">DdtHeader::compression</a>, <a class="el" href="index_8h_source.html#l00111">IndexEntry::dataType</a>, <a class="el" href="context_8h_source.html#l00194">aaruformat_context::ddt_version</a>, <a class="el" href="ddt_8h_source.html#l00071">DdtHeader::entries</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="context_8h_source.html#l00260">aaruformat_context::image_info</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="context_8h_source.html#l00196">aaruformat_context::in_memory_ddt</a>, <a class="el" href="ddt_8h_source.html#l00073">DdtHeader::length</a>, <a class="el" href="enums_8h_source.html#l00034">Lzma</a>, <a class="el" href="consts_8h_source.html#l00082">LZMA_PROPERTIES_LENGTH</a>, <a class="el" href="context_8h_source.html#l00193">aaruformat_context::mapped_memory_ddt_size</a>, <a class="el" href="enums_8h_source.html#l00033">None</a>, <a class="el" href="index_8h_source.html#l00112">IndexEntry::offset</a>, <a class="el" href="context_8h_source.html#l00183">aaruformat_context::sector_prefix_ddt</a>, <a class="el" href="context_8h_source.html#l00184">aaruformat_context::sector_suffix_ddt</a>, <a class="el" href="aaru_8h_source.html#l00874">ImageInfo::Sectors</a>, <a class="el" href="context_8h_source.html#l00195">aaruformat_context::shift</a>, <a class="el" href="ddt_8h_source.html#l00070">DdtHeader::shift</a>, <a class="el" href="log_8h_source.html#l00025">TRACE</a>, <a class="el" href="context_8h_source.html#l00181">aaruformat_context::user_data_ddt</a>, and <a class="el" href="enums_8h_source.html#l00046">UserData</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="dir_a6e99c46e07b25cfb1b3942f86972439.html">ddt</a></li><li class="navelem"><a href="ddt__v1_8c.html">ddt_v1.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>
|