|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <inttypes.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include "aaruformat.h"#include "log.h"Go to the source code of this file.
Functions | |
| void | process_metadata_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a metadata block from the image stream. | |
| void | process_geometry_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a logical geometry block from the image stream. | |
| void | process_cicm_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a CICM XML metadata block from the image stream. | |
| void | process_aaru_metadata_json_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes an Aaru metadata JSON block from the image stream during image opening. | |
| int32_t | aaruf_get_readable_sector_tags (const void *context, uint8_t *buffer, size_t *length) |
| Retrieves which sector tags are readable in the AaruFormat image. | |
| int32_t | aaruf_get_readable_media_tags (const void *context, uint8_t *buffer, size_t *length) |
| Retrieves which media tags are present in the AaruFormat image. | |
| int32_t aaruf_get_readable_media_tags | ( | const void * | context, |
| uint8_t * | buffer, | ||
| size_t * | length ) |
Retrieves which media tags are present in the AaruFormat image.
Returns an array of booleans indicating the presence of each MediaTagType in the image. The array is indexed by MediaTagType enum values (0 to MaxMediaTag), where each boolean is true if the corresponding media tag exists in the image's mediaTags hash table.
| context | Pointer to the aaruformat context (must be a valid, opened image context). |
| buffer | Pointer to a buffer to store the boolean array. Can be NULL to query required length. |
| length | Pointer to the buffer length. On input, contains buffer size; on output, contains required size. |
| AARUF_STATUS_OK | (0) Successfully retrieved readable media tags. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_BUFFER_TOO_SMALL | (-10) The buffer is too small. This occurs when:
|
Definition at line 711 of file metadata.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, aaruformat_context::magic, MaxMediaTag, aaruformat_context::mediaTags, and TRACE.
| int32_t aaruf_get_readable_sector_tags | ( | const void * | context, |
| uint8_t * | buffer, | ||
| size_t * | length ) |
Retrieves which sector tags are readable in the AaruFormat image.
Returns an array of booleans indicating whether each SectorTagType was successfully read from the image. The array is indexed by SectorTagType enum values (0 to MaxSectorTag), where each boolean is true if the corresponding sector tag data is present and readable in the image. Sector tags contain per-sector metadata such as sync headers, ECC/EDC codes, subchannels, and other sector-level information essential for exact media reconstruction.
| context | Pointer to the aaruformat context (must be a valid, opened image context). |
| buffer | Pointer to a buffer to store the boolean array. Can be NULL to query required length. |
| length | Pointer to the buffer length. On input, contains buffer size; on output, contains required size. |
| AARUF_STATUS_OK | (0) Successfully retrieved readable sector tags. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_METADATA_NOT_PRESENT | (-30) The sector tags array is not available. This occurs when:
|
| AARUF_ERROR_BUFFER_TOO_SMALL | (-10) The buffer is too small. This occurs when:
|
Definition at line 623 of file metadata.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_METADATA_NOT_PRESENT, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, aaruformat_context::magic, MaxSectorTag, aaruformat_context::readableSectorTags, and TRACE.
| void process_aaru_metadata_json_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes an Aaru metadata JSON block from the image stream during image opening.
Reads an Aaru metadata JSON block from the image file and loads its contents into the context for subsequent retrieval. The Aaru metadata JSON format is a structured representation of comprehensive image metadata including media information, imaging session details, hardware configuration, optical disc tracks and sessions, checksums, and preservation metadata. The JSON payload is stored in its original form without parsing or interpretation by this function, allowing higher-level code to process the structured data as needed.
This function is called during the image opening process (aaruf_open) when an index entry indicates the presence of an AaruMetadataJsonBlock. The function is non-critical; if reading fails or memory allocation fails, the error is logged but the image opening continues. This allows images without JSON metadata or with corrupted JSON blocks to still be opened for data access.
Processing sequence:
Memory allocation: The function allocates memory (via malloc) sized to hold the entire JSON payload as specified by ctx->jsonBlockHeader.length. This memory remains allocated for the lifetime of the context and is freed during aaruf_close(). If allocation fails, the function returns gracefully without the JSON metadata, allowing the image to still be opened.
Image size tracking: The function increments ctx->imageInfo.ImageSize by the length of the JSON payload to track the total size of metadata and structural blocks in the image.
Error handling: All errors are non-fatal and handled gracefully:
In all error cases, the ctx->jsonBlockHeader is zeroed (memset to 0) to indicate that no valid JSON metadata is available, and any allocated memory is properly freed.
| ctx | Pointer to an initialized aaruformatContext being populated during image opening. Must not be NULL. ctx->imageStream must be open and readable. On success, ctx->jsonBlockHeader will contain the block header and ctx->jsonBlock will point to the allocated JSON data. |
| entry | Pointer to the IndexEntry that specifies the file offset where the AaruMetadataJsonBlock begins. Must not be NULL. entry->offset indicates the position of the block header in the file. |
Definition at line 475 of file metadata.c.
References AaruMetadataJsonBlock, FATAL, AaruMetadataJsonBlockHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::json_block, aaruformat_context::json_block_header, AaruMetadataJsonBlockHeader::length, IndexEntry::offset, and TRACE.
Referenced by aaruf_open().
| void process_cicm_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a CICM XML metadata block from the image stream.
Reads a CICM XML metadata block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the CICM block. |
Definition at line 311 of file metadata.c.
References aaruformat_context::cicm_block, aaruformat_context::cicm_block_header, CicmBlock, FATAL, CicmMetadataBlock::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, CicmMetadataBlock::length, IndexEntry::offset, and TRACE.
Referenced by aaruf_open().
| void process_geometry_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a logical geometry block from the image stream.
Reads a logical geometry block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the geometry block. |
Definition at line 251 of file metadata.c.
References aaruformat_context::cylinders, GeometryBlockHeader::cylinders, FATAL, aaruformat_context::geometry_block, GeometryBlock, aaruformat_context::heads, GeometryBlockHeader::heads, GeometryBlockHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, IndexEntry::offset, aaruformat_context::sectors_per_track, GeometryBlockHeader::sectorsPerTrack, and TRACE.
Referenced by aaruf_open().
| void process_metadata_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a metadata block from the image stream.
Reads a metadata block from the image and updates the context with its contents.
| ctx | Pointer to the aaruformat context. |
| entry | Pointer to the index entry describing the metadata block. |
Definition at line 35 of file metadata.c.
References MetadataBlockHeader::blockSize, IndexEntry::blockType, aaruformat_context::comments, MetadataBlockHeader::commentsLength, MetadataBlockHeader::commentsOffset, aaruformat_context::creator, MetadataBlockHeader::creatorLength, MetadataBlockHeader::creatorOffset, aaruformat_context::drive_firmware_revision, aaruformat_context::drive_manufacturer, aaruformat_context::drive_model, aaruformat_context::drive_serial_number, MetadataBlockHeader::driveFirmwareRevisionLength, MetadataBlockHeader::driveFirmwareRevisionOffset, MetadataBlockHeader::driveManufacturerLength, MetadataBlockHeader::driveManufacturerOffset, MetadataBlockHeader::driveModelLength, MetadataBlockHeader::driveModelOffset, MetadataBlockHeader::driveSerialNumberLength, MetadataBlockHeader::driveSerialNumberOffset, FATAL, MetadataBlockHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, aaruformat_context::last_media_sequence, MetadataBlockHeader::lastMediaSequence, aaruformat_context::media_barcode, aaruformat_context::media_manufacturer, aaruformat_context::media_model, aaruformat_context::media_part_number, aaruformat_context::media_sequence, aaruformat_context::media_serial_number, aaruformat_context::media_title, MetadataBlockHeader::mediaBarcodeLength, MetadataBlockHeader::mediaBarcodeOffset, MetadataBlockHeader::mediaManufacturerLength, MetadataBlockHeader::mediaManufacturerOffset, MetadataBlockHeader::mediaModelLength, MetadataBlockHeader::mediaModelOffset, MetadataBlockHeader::mediaPartNumberLength, MetadataBlockHeader::mediaPartNumberOffset, MetadataBlockHeader::mediaSequence, MetadataBlockHeader::mediaSerialNumberLength, MetadataBlockHeader::mediaSerialNumberOffset, MetadataBlockHeader::mediaTitleLength, MetadataBlockHeader::mediaTitleOffset, aaruformat_context::metadata_block, aaruformat_context::metadata_block_header, IndexEntry::offset, and TRACE.
Referenced by aaruf_open().