Files
libaaruformat/docs/html/optical_8c.html

422 lines
32 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/blocks/optical.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('optical_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">optical.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;inttypes.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 &lt;string.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 />
</div>
<p><a href="optical_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:a375a516fdf6f81e997365d93b21f6708" id="r_a375a516fdf6f81e997365d93b21f6708"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a375a516fdf6f81e997365d93b21f6708">process_tracks_block</a> (<a class="el" href="structaaruformat__context.html">aaruformat_context</a> *ctx, const <a class="el" href="structIndexEntry.html">IndexEntry</a> *entry)</td></tr>
<tr class="memdesc:a375a516fdf6f81e997365d93b21f6708"><td class="mdescLeft">&#160;</td><td class="mdescRight">Parse and integrate a Tracks block from the image stream into the context. <br /></td></tr>
<tr class="memitem:a2ce65757ca5209f17d467c51ba7d445d" id="r_a2ce65757ca5209f17d467c51ba7d445d"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a2ce65757ca5209f17d467c51ba7d445d">aaruf_get_tracks</a> (const void *context, uint8_t *buffer, size_t *length)</td></tr>
<tr class="memdesc:a2ce65757ca5209f17d467c51ba7d445d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Retrieve the array of track descriptors contained in an opened AaruFormat image. <br /></td></tr>
<tr class="memitem:a518d8d68debf1b9a24af3eb6bc2f9e49" id="r_a518d8d68debf1b9a24af3eb6bc2f9e49"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a518d8d68debf1b9a24af3eb6bc2f9e49">aaruf_set_tracks</a> (void *context, <a class="el" href="structTrackEntry.html">TrackEntry</a> *tracks, const int count)</td></tr>
<tr class="memdesc:a518d8d68debf1b9a24af3eb6bc2f9e49"><td class="mdescLeft">&#160;</td><td class="mdescRight">Replace (or clear) the in-memory track table for an AaruFormat image context. <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="a2ce65757ca5209f17d467c51ba7d445d" name="a2ce65757ca5209f17d467c51ba7d445d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2ce65757ca5209f17d467c51ba7d445d">&#9670;&#160;</a></span>aaruf_get_tracks()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t aaruf_get_tracks </td>
<td>(</td>
<td class="paramtype">const void *</td> <td class="paramname"><span class="paramname"><em>context</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t *</td> <td class="paramname"><span class="paramname"><em>buffer</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *</td> <td class="paramname"><span class="paramname"><em>length</em></span>&#160;)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Retrieve the array of track descriptors contained in an opened AaruFormat image. </p>
<p>Provides the caller with a contiguous array of all track entries found in the image. The function follows a two-step usage pattern allowing callers to query the required buffer size before performing the actual copy.</p>
<p>Usage pattern:</p><ul>
<li>First call with buffer == NULL (or *length smaller than required). The function sets *length to the required size and returns AARUF_ERROR_BUFFER_TOO_SMALL.</li>
<li>Allocate a buffer of at least *length bytes and call again. On success, the function copies all <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures and returns AARUF_STATUS_OK with *length set to the bytes copied.</li>
</ul>
<p>The returned data is a raw copy of internal <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures (host endianness). The caller does not assume ownership of internal memory; only the caller-provided buffer should be freed by the caller.</p>
<p>Preconditions (</p><dl class="section pre"><dt>Precondition</dt><dd>):<ul>
<li></li>
</ul>
</dd>
<dd>
context is a valid pointer to an aaruformatContext previously returned by an open function.<ul>
<li></li>
</ul>
</dd>
<dd>
context-&gt;magic == AARU_MAGIC.<ul>
<li></li>
</ul>
</dd>
<dd>
<a class="el" href="#a375a516fdf6f81e997365d93b21f6708" title="Parse and integrate a Tracks block from the image stream into the context.">process_tracks_block()</a> has run (implicitly done during image open) populating trackEntries.</dd></dl>
<p>Thread safety:</p><ul>
<li>Read-only access; safe for concurrent calls on different contexts.</li>
<li>Concurrent calls on the same context are safe only if no other thread is modifying/destroying it.</li>
</ul>
<p>Buffer sizing logic:</p><ul>
<li>required_length = ctx-&gt;tracksHeader.entries * sizeof(TrackEntry)</li>
<li>If buffer == NULL OR *length &lt; required_length =&gt; *length updated, return AARUF_ERROR_BUFFER_TOO_SMALL.</li>
<li>On success *length == required_length.</li>
</ul>
<p>Error strategy:</p><ul>
<li>Validation failures: return specific error codes and log through <a class="el" href="log_8h.html#a053d6037d543b84ce59308ce71d15cd1">FATAL()</a>/TRACE().</li>
<li>No partial copies are performed.</li>
</ul>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">context</td><td>Opaque pointer that MUST point to a valid aaruformatContext. </td></tr>
<tr><td class="paramname">buffer</td><td>Destination buffer for a copy of all <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures, or NULL to query size. </td></tr>
<tr><td class="paramname">length</td><td>In/Out: On entry capacity of buffer (ignored if buffer == NULL). On return required or copied size in bytes. Must not be NULL.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>int32_t API status code. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname">AARUF_STATUS_OK</td><td>Success; buffer filled. </td></tr>
<tr><td class="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td>context is NULL or not a valid libaaruformat context. </td></tr>
<tr><td class="paramname">AARUF_ERROR_TRACK_NOT_FOUND</td><td>No tracks present (entries == 0 or internal array NULL). </td></tr>
<tr><td class="paramname">AARUF_ERROR_BUFFER_TOO_SMALL</td><td>Sizing query / provided buffer insufficient; *length updated.</td></tr>
</table>
</dd>
</dl>
<dl class="section warning"><dt>Warning</dt><dd>Passing an invalid context yields an error; no data is written to buffer. </dd>
<dd>
The function never performs partial copies.</dd></dl>
<dl class="section note"><dt>Note</dt><dd>Order of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> elements matches on-disk order. </dd>
<dd>
Caller may further filter (e.g., data vs audio) after retrieval.</dd></dl>
<dl class="section since"><dt>Since</dt><dd>1.0</dd></dl>
<p>Usage example (conceptual):</p><ol type="1">
<li>Open an image obtaining a valid aaruformatContext pointer.</li>
<li>Invoke aaruf_get_tracks(ctx, NULL, &amp;size) to query required buffer size (expect AARUF_ERROR_BUFFER_TOO_SMALL).</li>
<li>Allocate a buffer of "size" bytes.</li>
<li>Invoke aaruf_get_tracks(ctx, buffer, &amp;size) again; on AARUF_STATUS_OK iterate over (size / sizeof(TrackEntry)) entries.</li>
<li>Free the buffer and close the image when done. </li>
</ol>
<p class="definition">Definition at line <a class="el" href="optical_8c_source.html#l00281">281</a> of file <a class="el" href="optical_8c_source.html">optical.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="errors_8h_source.html#l00049">AARUF_ERROR_BUFFER_TOO_SMALL</a>, <a class="el" href="errors_8h_source.html#l00040">AARUF_ERROR_NOT_AARUFORMAT</a>, <a class="el" href="errors_8h_source.html#l00052">AARUF_ERROR_TRACK_NOT_FOUND</a>, <a class="el" href="errors_8h_source.html#l00075">AARUF_STATUS_OK</a>, <a class="el" href="optical_8h_source.html#l00064">TracksHeader::entries</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="context_8h_source.html#l00174">aaruformat_context::magic</a>, <a class="el" href="log_8h_source.html#l00025">TRACE</a>, <a class="el" href="context_8h_source.html#l00242">aaruformat_context::track_entries</a>, and <a class="el" href="context_8h_source.html#l00244">aaruformat_context::tracks_header</a>.</p>
2025-10-11 01:35:43 +01:00
</div>
</div>
<a id="a518d8d68debf1b9a24af3eb6bc2f9e49" name="a518d8d68debf1b9a24af3eb6bc2f9e49"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a518d8d68debf1b9a24af3eb6bc2f9e49">&#9670;&#160;</a></span>aaruf_set_tracks()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t aaruf_set_tracks </td>
<td>(</td>
<td class="paramtype">void *</td> <td class="paramname"><span class="paramname"><em>context</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="structTrackEntry.html">TrackEntry</a> *</td> <td class="paramname"><span class="paramname"><em>tracks</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const int</td> <td class="paramname"><span class="paramname"><em>count</em></span>&#160;)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Replace (or clear) the in-memory track table for an AaruFormat image context. </p>
<p>Copies an array of caller-provided <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures into the internal context, replacing any previously stored track metadata. A CRC64 is recomputed over the new table and stored in the associated <a class="el" href="structTracksHeader.html" title="Header for an optical tracks block listing track entries.">TracksHeader</a>. Passing a count of 0 clears existing track information.</p>
<p>Typical usage:</p><ul>
<li>Prepare an array of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures describing each track (filled by the caller).</li>
<li>Call <a class="el" href="#a518d8d68debf1b9a24af3eb6bc2f9e49" title="Replace (or clear) the in-memory track table for an AaruFormat image context.">aaruf_set_tracks()</a> with the array and the track count to load them into the context.</li>
<li>Subsequently the table can be retrieved with <a class="el" href="#a2ce65757ca5209f17d467c51ba7d445d" title="Retrieve the array of track descriptors contained in an opened AaruFormat image.">aaruf_get_tracks()</a>.</li>
</ul>
<p>Memory ownership:</p><ul>
<li>The function allocates (or frees when clearing) internal storage sized to (count * sizeof(TrackEntry)).</li>
<li>The caller retains ownership of the input array (if any) and may free or reuse it after the call.</li>
</ul>
<p>Validation performed:</p><ul>
<li><code class="param">context</code> must be non-NULL and reference aaruformatContext with magic == AARU_MAGIC.</li>
<li><code class="param">tracks</code> must be non-NULL when <code class="param">count</code> &gt; 0.</li>
<li><code class="param">count</code> must be &gt;= 0. (Negative values produce AARUF_ERROR_INVALID_TRACK_FORMAT.)</li>
<li>(Implementation detail) count is truncated to uint16_t for header storage; values &gt; UINT16_MAX will silently wrap. Callers should ensure count &lt;= 65535. This behavior may change in a future version.</li>
</ul>
<p>Concurrency &amp; thread-safety:</p><ul>
<li>Not thread-safe. Mutates shared context state. External synchronization is required if multiple threads access the same context.</li>
</ul>
<p>Side effects:</p><ul>
<li>Frees any existing internal track table before allocating the new one.</li>
<li>Updates ctx-&gt;tracksHeader.identifier, entries, crc64.</li>
<li>When clearing (count == 0) sets header to zero and frees internal table.</li>
</ul>
<p>Error handling &amp; atomicity:</p><ul>
<li>On allocation failure the previous track table is already freed (non-atomic replace) and the header is zeroed (no partial new state left). Caller must repopulate.</li>
<li>No partial copies: either all tracks are stored or none.</li>
</ul>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">context</td><td>Opaque pointer that MUST point to a valid aaruformatContext returned by an open/create call. </td></tr>
<tr><td class="paramname">tracks</td><td>Pointer to an array of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures to copy. Must not be NULL if count &gt; 0. Ignored (may be NULL) when count == 0. </td></tr>
<tr><td class="paramname">count</td><td>Number of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> elements in <code class="param">tracks</code>. If 0, existing tracks are cleared. Must be &gt;= 0 and (recommended) &lt;= UINT16_MAX.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>int32_t API status code indicating success or the nature of the failure. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
<table class="retval">
<tr><td class="paramname">AARUF_STATUS_OK</td><td>Success (tracks replaced or cleared). </td></tr>
<tr><td class="paramname">AARUF_ERROR_NOT_AARUFORMAT</td><td><code class="param">context</code> is NULL or not a recognized libaaruformat context. </td></tr>
<tr><td class="paramname">AARUF_ERROR_INVALID_TRACK_FORMAT</td><td>Invalid input (tracks NULL with count &gt; 0, or count &lt; 0). </td></tr>
<tr><td class="paramname">AARUF_ERROR_NOT_ENOUGH_MEMORY</td><td>Memory allocation failed while copying tracks.</td></tr>
</table>
</dd>
</dl>
<dl class="section warning"><dt>Warning</dt><dd>Not thread-safe. Do not invoke concurrently with readers/writers of the same context. </dd></dl>
<dl class="section note"><dt>Note</dt><dd>After success, <a class="el" href="#a2ce65757ca5209f17d467c51ba7d445d" title="Retrieve the array of track descriptors contained in an opened AaruFormat image.">aaruf_get_tracks()</a> can be used to read back the stored table. </dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a2ce65757ca5209f17d467c51ba7d445d" title="Retrieve the array of track descriptors contained in an opened AaruFormat image.">aaruf_get_tracks()</a></dd></dl>
<dl class="section since"><dt>Since</dt><dd>1.0</dd></dl>
<p>Usage example (conceptual):</p><ol type="1">
<li>Prepare an array of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> structures (N elements) and fill the fields.</li>
<li>Call aaruf_set_tracks(ctx, array, N) to store them; check for AARUF_STATUS_OK.</li>
<li>To clear all tracks later call aaruf_set_tracks(ctx, NULL, 0).</li>
<li>Use <a class="el" href="#a2ce65757ca5209f17d467c51ba7d445d" title="Retrieve the array of track descriptors contained in an opened AaruFormat image.">aaruf_get_tracks()</a> afterwards to retrieve them if needed. </li>
</ol>
<p class="definition">Definition at line <a class="el" href="optical_8c_source.html#l00392">392</a> of file <a class="el" href="optical_8c_source.html">optical.c</a>.</p>
2025-12-12 12:25:02 +00: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="crc64_8c_source.html#l00160">aaruf_crc64_data()</a>, <a class="el" href="errors_8h_source.html#l00054">AARUF_ERROR_INVALID_TRACK_FORMAT</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="optical_8h_source.html#l00065">TracksHeader::crc64</a>, <a class="el" href="context_8h_source.html#l00243">aaruformat_context::data_tracks</a>, <a class="el" href="context_8h_source.html#l00312">aaruformat_context::dirty_tracks_block</a>, <a class="el" href="optical_8h_source.html#l00064">TracksHeader::entries</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="aaru_8h_source.html#l00923">ImageInfo::HasPartitions</a>, <a class="el" href="aaru_8h_source.html#l00924">ImageInfo::HasSessions</a>, <a class="el" href="optical_8h_source.html#l00063">TracksHeader::identifier</a>, <a class="el" href="context_8h_source.html#l00260">aaruformat_context::image_info</a>, <a class="el" href="context_8h_source.html#l00174">aaruformat_context::magic</a>, <a class="el" href="context_8h_source.html#l00245">aaruformat_context::number_of_data_tracks</a>, <a class="el" href="optical_8h_source.html#l00073">TrackEntry::sequence</a>, <a class="el" href="log_8h_source.html#l00025">TRACE</a>, <a class="el" href="context_8h_source.html#l00242">aaruformat_context::track_entries</a>, <a class="el" href="context_8h_source.html#l00244">aaruformat_context::tracks_header</a>, and <a class="el" href="enums_8h_source.html#l00150">TracksBlock</a>.</p>
2025-10-11 01:35:43 +01:00
</div>
</div>
<a id="a375a516fdf6f81e997365d93b21f6708" name="a375a516fdf6f81e997365d93b21f6708"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a375a516fdf6f81e997365d93b21f6708">&#9670;&#160;</a></span>process_tracks_block()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void process_tracks_block </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 <a class="el" href="structIndexEntry.html">IndexEntry</a> *</td> <td class="paramname"><span class="paramname"><em>entry</em></span>&#160;)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Parse and integrate a Tracks block from the image stream into the context. </p>
<p>This function seeks to the byte offset specified by the supplied <code class="param">entry</code>, reads a <a class="el" href="structTracksHeader.html" title="Header for an optical tracks block listing track entries.">TracksHeader</a> followed by the declared number of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> records, validates the block through its CRC64, and populates multiple fields in the provided <code class="param">ctx:</code> </p>
<ul>
<li>ctx-&gt;tracksHeader (identifier, entries, crc64)</li>
<li>ctx-&gt;trackEntries (raw array with ALL tracks in on-disk order)</li>
<li>ctx-&gt;dataTracks (array filtered to data track sequences in [1..99])</li>
<li>ctx-&gt;numberOfDataTracks</li>
<li>ctx-&gt;imageInfo.ImageSize (incremented by sizeof(TrackEntry) * entries)</li>
<li>ctx-&gt;imageInfo.HasPartitions / HasSessions (both set true unconditionally on success path before filtering)</li>
</ul>
<p>It also performs a legacy endian correction of the computed CRC for images whose major version is &lt;= AARUF_VERSION_V1 (historical writer quirk).</p>
<p>The function is intended for internal library use during image opening / indexing and is NOT part of the stable public API (no versioning guarantees). Callers outside the library should use the higher-level image open helpers that trigger this parsing implicitly.</p>
<p>Error &amp; early-return behavior (no exception mechanism, all via logging + early return):</p><ul>
<li>NULL <code class="param">ctx</code> or NULL ctx-&gt;imageStream: Logs FATAL and returns immediately; context left untouched.</li>
<li>Seek failure: FATAL + return; context left untouched.</li>
<li><a class="el" href="structTracksHeader.html" title="Header for an optical tracks block listing track entries.">TracksHeader</a> read short: tracksHeader zeroed, TRACE logged, return.</li>
<li>Identifier mismatch: tracksHeader zeroed, TRACE logged, return.</li>
<li>Allocation failure for trackEntries: tracksHeader zeroed, FATAL logged, return.</li>
<li>Short read of <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> array: tracksHeader zeroed, allocated trackEntries freed, FATAL logged, return.</li>
<li>CRC mismatch: TRACE logged and return; (NOTE: at this point trackEntries remain allocated and tracksHeader retains the just-read values, but caller receives no explicit status.)</li>
</ul>
<p>Memory management:</p><ul>
<li>Allocates ctx-&gt;trackEntries with malloc() sized to entries * sizeof(TrackEntry).</li>
<li>Allocates ctx-&gt;dataTracks only if at least one filtered data track is found; otherwise sets it to NULL.</li>
<li>On certain failure paths (short reads) allocated memory is freed; on CRC mismatch memory is kept.</li>
<li>Pre-existing ctx-&gt;trackEntries or ctx-&gt;dataTracks are NOT freed before overwriting pointers, so repeated calls without prior cleanup will leak memory. The function is therefore expected to be called exactly once per context lifetime. This constraint should be observed by library code.</li>
</ul>
<p>Filtering rule for ctx-&gt;dataTracks:</p><ul>
<li>Any <a class="el" href="structTrackEntry.html" title="Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).">TrackEntry</a> with sequence in inclusive range [1, 99] is considered a data track (historical convention in format) and copied into ctx-&gt;dataTracks preserving original order.</li>
</ul>
<p>Thread safety:</p><ul>
<li>Not thread-safe: mutates shared state in <code class="param">ctx</code> without synchronization.</li>
<li>Must not be called concurrently with readers/writers referencing the same context.</li>
</ul>
<p>Preconditions (</p><dl class="section pre"><dt>Precondition</dt><dd>):<ul>
<li><code class="param">ctx</code> != NULL</li>
<li><code class="param">ctx-&gt;imageStream</code> is a valid FILE* opened for reading at least up to the block region.</li>
<li><code class="param">entry</code> != NULL and entry-&gt;offset points to the start of a well-formed Tracks block.</li>
</ul>
</dd></dl>
<p>Postconditions (</p><dl class="section post"><dt>Postcondition</dt><dd>) on success (CRC valid):<ul>
<li>ctx-&gt;tracksHeader.identifier == TracksBlock</li>
<li>ctx-&gt;tracksHeader.entries &gt; 0 implies ctx-&gt;trackEntries != NULL</li>
<li>ctx-&gt;dataTracks != NULL iff numberOfDataTracks &gt; 0</li>
<li>numberOfDataTracks &lt;= tracksHeader.entries</li>
<li>imageInfo flags (HasPartitions, HasSessions) set true</li>
</ul>
</dd></dl>
<p>Limitations / Caveats:</p><ul>
<li>No explicit status code: callers infer success by inspecting ctx-&gt;tracksHeader.entries and presence of ctx-&gt;trackEntries after invocation.</li>
<li>In case of CRC mismatch trackEntries are retained though not guaranteed trustworthy; caller may wish to discard them or trigger re-read.</li>
<li>Potential memory leak if invoked multiple times without freeing previous arrays.</li>
</ul>
<p>Logging strategy:</p><ul>
<li>FATAL used for unrecoverable structural or resource errors.</li>
<li>TRACE used for informational / soft failures (e.g., CRC mismatch, identifier mismatch, short read).</li>
</ul>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">ctx</td><td>Mutable pointer to an aaruformatContext receiving parsed track metadata. </td></tr>
<tr><td class="paramname">entry</td><td>Pointer to the index entry describing this Tracks block (offset required; size not strictly used beyond informational logging and sequential reading).</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void This function does not return a status code; errors are reported via logging side effects.</dd></dl>
<dl class="section warning"><dt>Warning</dt><dd>Not idempotent and not leak-safe if called more than once for a context. </dd>
<dd>
Absence of a returned status requires defensive post-call validation by the caller. </dd>
<dd>
CRC mismatch leaves possibly invalid data in ctx-&gt;trackEntries.</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a2ce65757ca5209f17d467c51ba7d445d" title="Retrieve the array of track descriptors contained in an opened AaruFormat image.">aaruf_get_tracks()</a> </dd>
<dd>
<a class="el" href="#a518d8d68debf1b9a24af3eb6bc2f9e49" title="Replace (or clear) the in-memory track table for an AaruFormat image context.">aaruf_set_tracks()</a> </dd></dl>
<p class="definition">Definition at line <a class="el" href="optical_8c_source.html#l00111">111</a> of file <a class="el" href="optical_8c_source.html">optical.c</a>.</p>
2025-12-12 12:25:02 +00:00
<p class="reference">References <a class="el" href="crc64_8c_source.html#l00160">aaruf_crc64_data()</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="optical_8h_source.html#l00065">TracksHeader::crc64</a>, <a class="el" href="context_8h_source.html#l00243">aaruformat_context::data_tracks</a>, <a class="el" href="optical_8h_source.html#l00064">TracksHeader::entries</a>, <a class="el" href="log_8h_source.html#l00040">FATAL</a>, <a class="el" href="aaru_8h_source.html#l00923">ImageInfo::HasPartitions</a>, <a class="el" href="aaru_8h_source.html#l00924">ImageInfo::HasSessions</a>, <a class="el" href="context_8h_source.html#l00175">aaruformat_context::header</a>, <a class="el" href="optical_8h_source.html#l00063">TracksHeader::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="aaru_8h_source.html#l00925">ImageInfo::ImageSize</a>, <a class="el" href="context_8h_source.html#l00176">aaruformat_context::imageStream</a>, <a class="el" href="context_8h_source.html#l00245">aaruformat_context::number_of_data_tracks</a>, <a class="el" href="index_8h_source.html#l00112">IndexEntry::offset</a>, <a class="el" href="optical_8h_source.html#l00073">TrackEntry::sequence</a>, <a class="el" href="log_8h_source.html#l00025">TRACE</a>, <a class="el" href="context_8h_source.html#l00242">aaruformat_context::track_entries</a>, <a class="el" href="context_8h_source.html#l00244">aaruformat_context::tracks_header</a>, and <a class="el" href="enums_8h_source.html#l00150">TracksBlock</a>.</p>
2025-10-11 01:35:43 +01:00
2025-10-21 14:23:35 +01:00
<p class="reference">Referenced by <a class="el" href="open_8c_source.html#l00223">aaruf_open()</a>.</p>
2025-10-11 01:35:43 +01:00
</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_b2e0cd1ddd0a904cb261e9b68779deb4.html">blocks</a></li><li class="navelem"><a href="optical_8c.html">optical.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>