|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <inttypes.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "aaruformat.h"#include "log.h"Go to the source code of this file.
Functions | |
| void | process_tracks_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Parse and integrate a Tracks block from the image stream into the context. | |
| int32_t | aaruf_get_tracks (const void *context, uint8_t *buffer, size_t *length) |
| Retrieve the array of track descriptors contained in an opened AaruFormat image. | |
| int32_t | aaruf_set_tracks (void *context, TrackEntry *tracks, const int count) |
| Replace (or clear) the in-memory track table for an AaruFormat image context. | |
| int32_t aaruf_get_tracks | ( | const void * | context, |
| uint8_t * | buffer, | ||
| size_t * | length ) |
Retrieve the array of track descriptors contained in an opened AaruFormat image.
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.
Usage pattern:
The returned data is a raw copy of internal TrackEntry structures (host endianness). The caller does not assume ownership of internal memory; only the caller-provided buffer should be freed by the caller.
Preconditions (
Thread safety:
Buffer sizing logic:
Error strategy:
| context | Opaque pointer that MUST point to a valid aaruformatContext. |
| buffer | Destination buffer for a copy of all TrackEntry structures, or NULL to query size. |
| length | In/Out: On entry capacity of buffer (ignored if buffer == NULL). On return required or copied size in bytes. Must not be NULL. |
| AARUF_STATUS_OK | Success; buffer filled. |
| AARUF_ERROR_NOT_AARUFORMAT | context is NULL or not a valid libaaruformat context. |
| AARUF_ERROR_TRACK_NOT_FOUND | No tracks present (entries == 0 or internal array NULL). |
| AARUF_ERROR_BUFFER_TOO_SMALL | Sizing query / provided buffer insufficient; *length updated. |
Usage example (conceptual):
Definition at line 281 of file optical.c.
References AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_TRACK_NOT_FOUND, AARUF_STATUS_OK, TracksHeader::entries, FATAL, aaruformat_context::magic, TRACE, aaruformat_context::track_entries, and aaruformat_context::tracks_header.
| int32_t aaruf_set_tracks | ( | void * | context, |
| TrackEntry * | tracks, | ||
| const int | count ) |
Replace (or clear) the in-memory track table for an AaruFormat image context.
Copies an array of caller-provided TrackEntry structures into the internal context, replacing any previously stored track metadata. A CRC64 is recomputed over the new table and stored in the associated TracksHeader. Passing a count of 0 clears existing track information.
Typical usage:
Memory ownership:
Validation performed:
context must be non-NULL and reference aaruformatContext with magic == AARU_MAGIC.tracks must be non-NULL when count > 0.count must be >= 0. (Negative values produce AARUF_ERROR_INVALID_TRACK_FORMAT.)Concurrency & thread-safety:
Side effects:
Error handling & atomicity:
| context | Opaque pointer that MUST point to a valid aaruformatContext returned by an open/create call. |
| tracks | Pointer to an array of TrackEntry structures to copy. Must not be NULL if count > 0. Ignored (may be NULL) when count == 0. |
| count | Number of TrackEntry elements in tracks. If 0, existing tracks are cleared. Must be >= 0 and (recommended) <= UINT16_MAX. |
| AARUF_STATUS_OK | Success (tracks replaced or cleared). |
| AARUF_ERROR_NOT_AARUFORMAT | context is NULL or not a recognized libaaruformat context. |
| AARUF_ERROR_INVALID_TRACK_FORMAT | Invalid input (tracks NULL with count > 0, or count < 0). |
| AARUF_ERROR_NOT_ENOUGH_MEMORY | Memory allocation failed while copying tracks. |
Usage example (conceptual):
Definition at line 392 of file optical.c.
References AARU_MAGIC, aaruf_crc64_data(), AARUF_ERROR_INVALID_TRACK_FORMAT, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_STATUS_OK, TracksHeader::crc64, aaruformat_context::data_tracks, TracksHeader::entries, FATAL, ImageInfo::HasPartitions, ImageInfo::HasSessions, TracksHeader::identifier, aaruformat_context::image_info, aaruformat_context::magic, aaruformat_context::number_of_data_tracks, TrackEntry::sequence, TRACE, aaruformat_context::track_entries, aaruformat_context::tracks_header, and TracksBlock.
| void process_tracks_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Parse and integrate a Tracks block from the image stream into the context.
This function seeks to the byte offset specified by the supplied entry, reads a TracksHeader followed by the declared number of TrackEntry records, validates the block through its CRC64, and populates multiple fields in the provided ctx:
It also performs a legacy endian correction of the computed CRC for images whose major version is <= AARUF_VERSION_V1 (historical writer quirk).
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.
Error & early-return behavior (no exception mechanism, all via logging + early return):
ctx or NULL ctx->imageStream: Logs FATAL and returns immediately; context left untouched.Memory management:
Filtering rule for ctx->dataTracks:
Thread safety:
ctx without synchronization.Preconditions (
ctx != NULLctx->imageStream is a valid FILE* opened for reading at least up to the block region.entry != NULL and entry->offset points to the start of a well-formed Tracks block.Postconditions (
Limitations / Caveats:
Logging strategy:
| ctx | Mutable pointer to an aaruformatContext receiving parsed track metadata. |
| entry | Pointer to the index entry describing this Tracks block (offset required; size not strictly used beyond informational logging and sequential reading). |
Definition at line 111 of file optical.c.
References aaruf_crc64_data(), AARUF_VERSION_V1, bswap_64, TracksHeader::crc64, aaruformat_context::data_tracks, TracksHeader::entries, FATAL, ImageInfo::HasPartitions, ImageInfo::HasSessions, aaruformat_context::header, TracksHeader::identifier, aaruformat_context::image_info, AaruHeaderV2::imageMajorVersion, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::number_of_data_tracks, IndexEntry::offset, TrackEntry::sequence, TRACE, aaruformat_context::track_entries, aaruformat_context::tracks_header, and TracksBlock.
Referenced by aaruf_open().