libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
metadata.c File Reference

Read-only metadata accessors for libaaruformat. More...

#include <stddef.h>
#include <stdint.h>
#include "aaruformat.h"
#include "log.h"

Go to the source code of this file.

Functions

int32_t aaruf_get_geometry (const void *context, uint32_t *cylinders, uint32_t *heads, uint32_t *sectors_per_track)
 Retrieves the logical CHS geometry from the AaruFormat image.
int32_t aaruf_get_cicm_metadata (const void *context, uint8_t *buffer, size_t *length)
 Retrieves the embedded CICM XML metadata sidecar from the image.
int32_t aaruf_get_aaru_json_metadata (const void *context, uint8_t *buffer, size_t *length)
 Retrieves the embedded Aaru metadata JSON from the image.
int32_t aaruf_get_media_sequence (const void *context, int32_t *sequence, int32_t *last_sequence)
 Retrieves the media sequence metadata for multi-volume image sets.
int32_t aaruf_get_creator (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the recorded creator (operator) name from the MetadataBlock.
int32_t aaruf_get_comments (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the user comments or notes stored in the MetadataBlock.
int32_t aaruf_get_media_title (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the media title or label captured during image creation.
int32_t aaruf_get_media_manufacturer (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the recorded media manufacturer name.
int32_t aaruf_get_media_model (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the media model or product designation metadata.
int32_t aaruf_get_media_serial_number (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the media serial number recorded in the image metadata.
int32_t aaruf_get_media_barcode (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the barcode assigned to the physical media or its packaging.
int32_t aaruf_get_media_part_number (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the media part number recorded in the MetadataBlock.
int32_t aaruf_get_drive_manufacturer (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the drive manufacturer metadata captured during imaging.
int32_t aaruf_get_drive_model (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the device model information for the imaging drive.
int32_t aaruf_get_drive_serial_number (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the imaging drive's serial number metadata.
int32_t aaruf_get_drive_firmware_revision (const void *context, uint8_t *buffer, int32_t *length)
 Retrieves the firmware revision metadata for the imaging drive.
int32_t aaruf_get_user_sectors (const void *context, uint64_t *sectors)
 Retrieves the total number of user-accessible sectors in the AaruFormat image.
int32_t aaruf_get_negative_sectors (const void *context, uint32_t *sectors)
 Retrieves the number of negative (pre-gap) sectors in the AaruFormat image.
int32_t aaruf_get_overflow_sectors (const void *context, uint32_t *sectors)
 Retrieves the number of overflow (post-gap) sectors in the AaruFormat image.
int32_t aaruf_get_image_info (const void *context, ImageInfo *image_info)
 Retrieves a deep copy of the ImageInfo structure from the AaruFormat image.

Detailed Description

Read-only metadata accessors for libaaruformat.

Contains all aaruf_get_* functions that retrieve metadata from an opened AaruFormat image context. Writer-side functions (aaruf_set_*, aaruf_clear_*) are in metadata_write.c.

See also
metadata_write.c

Definition in file metadata.c.

Function Documentation

◆ aaruf_get_aaru_json_metadata()

int32_t aaruf_get_aaru_json_metadata ( const void * context,
uint8_t * buffer,
size_t * length )

Retrieves the embedded Aaru metadata JSON from the image.

Aaru metadata JSON is a structured metadata format that provides machine-readable, comprehensive information about the image, media, imaging session details, hardware configuration, optical disc tracks and sessions, checksums, and preservation metadata. This function extracts the raw JSON payload that was embedded in the AaruFormat image during creation. The JSON data is preserved in its original form without parsing or interpretation by the library, allowing callers to process the structured metadata using standard JSON parsing libraries.

This function supports a two-call pattern for buffer size determination:

  1. First call with a buffer that may be too small returns AARUF_ERROR_BUFFER_TOO_SMALL and sets *length to the required size
  2. Second call with a properly sized buffer retrieves the actual data

Alternatively, if the caller already knows the buffer is large enough, a single call will succeed and populate the buffer with the Aaru JSON data.

Parameters
contextPointer to the aaruformat context (must be a valid, opened image context).
bufferPointer to a buffer that will receive the Aaru metadata JSON. Must be large enough to hold the entire JSON payload (at least *length bytes on input). The buffer will contain raw UTF-8 encoded JSON data on success.
lengthPointer to a size_t that serves dual purpose:
  • On input: size of the provided buffer in bytes
  • On output: actual size of the Aaru metadata JSON in bytes If the function returns AARUF_ERROR_BUFFER_TOO_SMALL, this will be updated to contain the required buffer size for a subsequent successful call.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully retrieved Aaru metadata JSON. This is returned when:
  • The context is valid and properly initialized
  • The Aaru JSON block is present in the image (identifier == AaruMetadataJsonBlock)
  • The provided buffer is large enough (>= required length)
  • The Aaru JSON data is successfully copied to the buffer
  • The *length parameter is set to the actual size of the JSON data
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC (invalid context type)
  • The context was not properly initialized by aaruf_open() or aaruf_create()
AARUF_ERROR_CANNOT_READ_BLOCK(-7) The Aaru JSON block is not present. This occurs when:
  • The image was created without Aaru metadata JSON
  • ctx->jsonBlock is NULL (no data loaded)
  • ctx->jsonBlockHeader.length is 0 (empty metadata)
  • ctx->jsonBlockHeader.identifier doesn't equal AaruMetadataJsonBlock
  • The Aaru JSON block was not found during image opening
  • The *length output parameter is set to 0 to indicate no data available
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer is insufficient. This occurs when:
  • The input *length is less than ctx->jsonBlockHeader.length
  • The *length parameter is updated to contain the required buffer size
  • No data is copied to the buffer
  • The caller should allocate a larger buffer and call again
Note
Aaru JSON Format and Encoding:
  • The JSON payload is stored in UTF-8 encoding
  • The payload may or may not be null-terminated
  • The library treats the JSON as opaque binary data
  • No JSON parsing, interpretation, or validation is performed by libaaruformat
  • JSON schema validation and parsing are the caller's responsibility
Aaru Metadata JSON Purpose:
  • Provides machine-readable structured metadata using modern JSON format
  • Includes comprehensive information about media, sessions, tracks, and checksums
  • Enables programmatic access to metadata without XML parsing overhead
  • Documents imaging session details, hardware configuration, and preservation data
  • Used by Aaru and compatible tools for metadata exchange and analysis
  • Complements or serves as alternative to CICM XML metadata
Buffer Size Handling:
  • First call with insufficient buffer returns required size in *length
  • Caller allocates properly sized buffer based on returned length
  • Second call with adequate buffer retrieves the actual JSON data
  • Single call succeeds if buffer is already large enough
Data Availability:
  • Aaru JSON blocks are optional in AaruFormat images
  • Not all images will contain Aaru metadata JSON
  • The presence of JSON data depends on how the image was created
  • Check return value to handle missing metadata gracefully
  • Images may contain CICM XML, Aaru JSON, both, or neither
Distinction from CICM XML:
  • CICM XML follows the Canary Islands Computer Museum schema (older format)
  • Aaru JSON follows the Aaru-specific metadata schema (newer format)
  • Both can coexist in the same image file
  • Aaru JSON may provide more detailed or different metadata than CICM XML
  • Different tools and workflows may prefer one format over the other
Warning
This function reads from the in-memory Aaru JSON block loaded during aaruf_open(). It does not perform file I/O operations. The entire JSON is kept in memory for the lifetime of the context.
The buffer parameter must be valid and large enough to hold the JSON data. Passing a buffer smaller than the required size will result in AARUF_ERROR_BUFFER_TOO_SMALL with no partial data copied.
This function does not validate JSON syntax or schema. Corrupted JSON data will be retrieved successfully and errors will only be detected when attempting to parse.
See also
AaruMetadataJsonBlockHeader for the on-disk structure definition.
aaruf_get_cicm_metadata() for retrieving CICM XML metadata.
process_aaru_metadata_json_block() for the loading process during image opening.

Definition at line 399 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, AaruMetadataJsonBlock, FATAL, AaruMetadataJsonBlockHeader::identifier, aaruformat_context::json_block, aaruformat_context::json_block_header, AaruMetadataJsonBlockHeader::length, aaruformat_context::magic, and TRACE.

◆ aaruf_get_cicm_metadata()

int32_t aaruf_get_cicm_metadata ( const void * context,
uint8_t * buffer,
size_t * length )

Retrieves the embedded CICM XML metadata sidecar from the image.

CICM (Canary Islands Computer Museum) XML is a standardized metadata format used for documenting preservation and archival information about media and disk images. This function extracts the raw CICM XML payload that was embedded in the AaruFormat image during creation. The XML data is preserved in its original form without parsing, interpretation, or validation by the library. The metadata typically includes detailed information about the physical media, imaging process, checksums, device information, and preservation metadata following the CICM schema.

This function supports a two-call pattern for buffer size determination:

  1. First call with a buffer that may be too small returns AARUF_ERROR_BUFFER_TOO_SMALL and sets *length to the required size
  2. Second call with a properly sized buffer retrieves the actual data

Alternatively, if the caller already knows the buffer is large enough, a single call will succeed and populate the buffer with the CICM XML data.

Parameters
contextPointer to the aaruformat context (must be a valid, opened image context).
bufferPointer to a buffer that will receive the CICM XML metadata. Must be large enough to hold the entire XML payload (at least *length bytes on input). The buffer will contain raw UTF-8 encoded XML data on success.
lengthPointer to a size_t that serves dual purpose:
  • On input: size of the provided buffer in bytes
  • On output: actual size of the CICM XML metadata in bytes If the function returns AARUF_ERROR_BUFFER_TOO_SMALL, this will be updated to contain the required buffer size for a subsequent successful call.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully retrieved CICM XML metadata. This is returned when:
  • The context is valid and properly initialized
  • The CICM block is present in the image (identifier == CicmBlock)
  • The provided buffer is large enough (>= required length)
  • The CICM XML data is successfully copied to the buffer
  • The *length parameter is set to the actual size of the XML data
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC (invalid context type)
  • The context was not properly initialized by aaruf_open() or aaruf_create()
AARUF_ERROR_CANNOT_READ_BLOCK(-7) The CICM block is not present. This occurs when:
  • The image was created without CICM XML metadata
  • ctx->cicmBlock is NULL (no data loaded)
  • ctx->cicmBlockHeader.length is 0 (empty metadata)
  • ctx->cicmBlockHeader.identifier doesn't equal CicmBlock
  • The CICM block was not found during image opening
  • The *length output parameter is set to 0 to indicate no data available
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer is insufficient. This occurs when:
  • The input *length is less than ctx->cicmBlockHeader.length
  • The *length parameter is updated to contain the required buffer size
  • No data is copied to the buffer
  • The caller should allocate a larger buffer and call again
Note
CICM XML Format:
  • The XML is stored in UTF-8 encoding
  • The payload may or may not be null-terminated
  • The library treats the XML as opaque binary data
  • No XML parsing, interpretation, or validation is performed by libaaruformat
  • Schema validation and XML processing are the caller's responsibility
CICM Metadata Purpose:
  • Developed by the Canary Islands Computer Museum for digital preservation
  • Documents comprehensive preservation metadata
  • Includes checksums for data integrity verification
  • Records detailed device and media information
  • Supports archival and long-term preservation requirements
  • Provides standardized metadata for digital preservation workflows
  • Used by cultural heritage institutions and archives
Buffer Size Handling:
  • First call with insufficient buffer returns required size in *length
  • Caller allocates properly sized buffer based on returned length
  • Second call with adequate buffer retrieves the actual XML data
  • Single call succeeds if buffer is already large enough
Data Availability:
  • CICM blocks are optional in AaruFormat images
  • Not all images will contain CICM metadata
  • The presence of CICM data depends on how the image was created
  • Check return value to handle missing metadata gracefully
Warning
The XML data may contain sensitive information about the imaging environment, personnel, locations, or media content. Handle appropriately for your use case.
This function reads from the in-memory CICM block loaded during aaruf_open(). It does not perform file I/O operations. The entire CICM XML is kept in memory for the lifetime of the context.
The buffer parameter must be valid and large enough to hold the XML data. Passing a buffer smaller than the required size will result in AARUF_ERROR_BUFFER_TOO_SMALL with no partial data copied.
See also
CicmMetadataBlock for the on-disk structure definition.
aaruf_set_cicm_metadata() for embedding CICM XML during image creation.

Definition at line 244 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, aaruformat_context::cicm_block, aaruformat_context::cicm_block_header, CicmBlock, FATAL, CicmMetadataBlock::identifier, CicmMetadataBlock::length, aaruformat_context::magic, and TRACE.

◆ aaruf_get_comments()

int32_t aaruf_get_comments ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the user comments or notes stored in the MetadataBlock.

Provides access to the UTF-16LE encoded comments associated with the image. Comments are often used for provenance notes, imaging details, or curator remarks. The function follows the same two-call buffer sizing pattern used by other metadata retrieval APIs: the caller may probe the required size before allocating memory.

Parameters
contextPointer to a valid aaruformat context opened with aaruf_open() or aaruf_create().
bufferDestination buffer that receives the comments data. May be NULL when probing size.
lengthPointer to an int32_t. On input it contains the size of buffer in bytes; on output it is updated with the actual comments length.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Comments were available and copied successfully.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid or not a libaaruformat context.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No comments metadata exists in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The supplied buffer was too small. *length is updated with the required size and no data is copied.
Note
Comments are stored exactly as provided during image creation and may include multi-line text or other control characters. No validation or normalization is applied by the library.

Definition at line 616 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, aaruformat_context::comments, MetadataBlockHeader::commentsLength, FATAL, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_creator()

int32_t aaruf_get_creator ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the recorded creator (operator) name from the MetadataBlock.

Copies the UTF-16LE encoded creator string that identifies the person or operator who created the image. The function supports the common two-call pattern: the caller first determines the required buffer size by passing a buffer that may be NULL or too small, then allocates sufficient memory and calls again to obtain the actual data. On success the buffer contains an opaque UTF-16LE string of length *length bytes (not null-terminated).

Parameters
contextPointer to a valid aaruformat context opened for reading or writing.
bufferPointer to the destination buffer that will receive the creator string. May be NULL to query the required size.
lengthPointer to an int32_t that on input specifies the size of buffer in bytes and on output receives the actual length of the creator metadata.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) The creator string was copied successfully.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is NULL or not an aaruformat context.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) Creator metadata has not been recorded in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer was insufficient; *length contains the required size and no data was copied.
Note
The returned data is UTF-16LE encoded and may contain embedded null characters. Callers should treat it as an opaque byte array unless they explicitly handle UTF-16LE strings.
The function does not allocate memory. Callers are responsible for ensuring buffer is large enough before requesting the data.

Definition at line 544 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, aaruformat_context::creator, MetadataBlockHeader::creatorLength, FATAL, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_drive_firmware_revision()

int32_t aaruf_get_drive_firmware_revision ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the firmware revision metadata for the imaging drive.

Returns the UTF-16LE encoded firmware revision string that was captured when the image was created. Firmware information is critical for reproducing imaging environments and diagnosing drive-specific behavior or bugs.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the firmware revision string. May be NULL when probing size.
lengthPointer to an int32_t that specifies the buffer capacity in bytes on input and is updated with the actual metadata length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Firmware revision metadata was present and copied successfully.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No firmware metadata exists in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The supplied buffer was too small; *length is updated.
Note
Firmware revision formats vary between manufacturers (e.g., numeric, alphanumeric, dot-separated). The library stores the data verbatim without attempting normalization.

Definition at line 1318 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, aaruformat_context::drive_firmware_revision, MetadataBlockHeader::driveFirmwareRevisionLength, FATAL, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_drive_manufacturer()

int32_t aaruf_get_drive_manufacturer ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the drive manufacturer metadata captured during imaging.

Copies the UTF-16LE encoded manufacturer name of the device used to read or write the medium. This information documents the hardware involved in the imaging process, which is crucial for forensic reporting and reproducibility studies.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the manufacturer string. May be NULL when querying required length.
lengthPointer to an int32_t specifying the buffer size on input and receiving the actual metadata length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Drive manufacturer metadata was copied successfully.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) The image lacks drive manufacturer metadata.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer is too small; *length holds the required size for a subsequent call.
Note
The returned manufacturer string corresponds to the value recorded by aaruf_set_drive_manufacturer() and may include branding or OEM designations.

Definition at line 1108 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, aaruformat_context::drive_manufacturer, MetadataBlockHeader::driveManufacturerLength, FATAL, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_drive_model()

int32_t aaruf_get_drive_model ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the device model information for the imaging drive.

Returns the UTF-16LE encoded model identifier for the drive used during acquisition. The model metadata provides finer granularity than the manufacturer name, enabling detailed documentation of imaging hardware capabilities and behavior.

Parameters
contextPointer to a valid aaruformat context.
bufferBuffer that receives the model string; may be NULL while probing required capacity.
lengthPointer to an int32_t indicating buffer size on input and receiving the metadata length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Drive model metadata was available and copied.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No drive model metadata exists in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The supplied buffer was insufficient; *length is updated.
Note
Model strings can include firmware suffixes, interface hints, or OEM variations. Consume the data verbatim to maintain accurate provenance records.

Definition at line 1178 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, aaruformat_context::drive_model, MetadataBlockHeader::driveModelLength, FATAL, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_drive_serial_number()

int32_t aaruf_get_drive_serial_number ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the imaging drive's serial number metadata.

Copies the UTF-16LE encoded serial number reported for the drive used during the imaging session. This metadata enables correlation between images and specific hardware units for forensic chain of custody or quality assurance workflows.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the serial number; may be NULL when querying size.
lengthPointer to an int32_t carrying the buffer size on input and receiving the actual serial number length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Drive serial number metadata was copied to buffer.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No drive serial number metadata is available.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer was insufficient.
Note
Serial numbers are stored exactly as returned by the imaging hardware and may include leading zeros or spacing that should be preserved.

Definition at line 1248 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, aaruformat_context::drive_serial_number, MetadataBlockHeader::driveSerialNumberLength, FATAL, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_geometry()

int32_t aaruf_get_geometry ( const void * context,
uint32_t * cylinders,
uint32_t * heads,
uint32_t * sectors_per_track )

Retrieves the logical CHS geometry from the AaruFormat image.

Reads the Cylinder-Head-Sector (CHS) geometry information from the image's geometry block and returns the values through output parameters. The geometry block contains legacy-style logical addressing parameters that describe how the storage medium was originally organized in terms of cylinders, heads (tracks per cylinder), and sectors per track. This information is essential for software that requires CHS addressing or for accurately representing the original medium's logical structure.

Parameters
contextPointer to the aaruformat context (must be a valid, opened image context).
cylindersPointer to store the number of cylinders. Updated on success.
headsPointer to store the number of heads (tracks per cylinder). Updated on success.
sectors_per_trackPointer to store the number of sectors per track. Updated on success.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully retrieved geometry information. This is returned when:
  • The context is valid and properly initialized
  • The geometry block is present in the image (identifier == GeometryBlock)
  • All three output parameters are successfully populated with geometry values
  • The cylinders parameter contains the total number of cylinders
  • The heads parameter contains the number of heads per cylinder
  • The sectors_per_track parameter contains the number of sectors per track
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC (invalid context type)
  • The context was not properly initialized by aaruf_open() or aaruf_create()
AARUF_ERROR_CANNOT_READ_BLOCK(-7) The geometry block is not present. This occurs when:
  • The image was created without geometry information
  • The geometryBlock.identifier field doesn't equal GeometryBlock
  • The geometry block was not found during image opening
  • The image format doesn't support or require CHS geometry
Note
Geometry Interpretation:
  • Total logical sectors = cylinders × heads × sectors_per_track
  • Sector size is not included in the geometry block and must be obtained separately (typically 512 bytes for most block devices, but can vary)
  • The geometry represents logical addressing, not necessarily physical medium geometry
  • Modern storage devices often report translated or synthetic geometry values
CHS Addressing Context:
  • CHS addressing was historically used for hard disk drives and floppy disks
  • Legacy BIOS and older operating systems relied on CHS parameters
  • LBA (Logical Block Addressing) has largely replaced CHS for modern devices
  • Some disk image formats and emulators still require CHS information
Geometry Block Availability:
  • Not all image types contain geometry blocks
  • Optical media (CDs, DVDs) typically don't have CHS geometry
  • Modern large-capacity drives may not have meaningful CHS values
  • Check the return value to determine if geometry is available
Parameter Validation:
  • All output parameters must be non-NULL valid pointers
  • The function does not validate the geometry values themselves
  • Geometry values of zero or unusually large values may indicate issues
Warning
The output parameters are only modified on success (AARUF_STATUS_OK). On error, their values remain unchanged. Initialize them before calling if default values are needed on failure.
This function reads from the in-memory geometry block loaded during aaruf_open(). It does not perform file I/O operations.
Geometry values may not accurately represent physical device geometry, especially for modern drives with zone-based recording or flash storage.

Definition at line 104 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, GeometryBlockHeader::cylinders, FATAL, aaruformat_context::geometry_block, GeometryBlock, GeometryBlockHeader::heads, GeometryBlockHeader::identifier, aaruformat_context::magic, GeometryBlockHeader::sectorsPerTrack, and TRACE.

◆ aaruf_get_image_info()

int32_t aaruf_get_image_info ( const void * context,
ImageInfo * image_info )

Retrieves a deep copy of the ImageInfo structure from the AaruFormat image.

Returns a complete copy of the high-level image information summary containing metadata such as image size, sector count, sector size, version information, creation timestamps, and media type. This function performs a deep copy of all fields including string buffers, ensuring the caller receives a complete, independent copy of the image information.

Parameters
contextPointer to the aaruformat context (must be a valid, opened image context).
image_infoPointer to an ImageInfo structure to receive the copied data. Must be a valid pointer to allocated memory.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully copied image info. The image_info parameter contains a complete copy of all fields including:
  • HasPartitions: Whether image contains partitions/tracks
  • HasSessions: Whether image contains multiple sessions
  • ImageSize: Size of image payload in bytes
  • Sectors: Total count of addressable sectors/blocks
  • SectorSize: Size of each logical sector in bytes
  • Version: Image format version string (NUL-terminated)
  • Application: Creating application name (NUL-terminated)
  • ApplicationVersion: Application version string (NUL-terminated)
  • CreationTime: Image creation timestamp (Windows FILETIME)
  • LastModificationTime: Last modification timestamp (Windows FILETIME)
  • MediaType: Media type identifier
  • MetadataMediaType: Media type for sidecar generation
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC
  • The context was not properly initialized
Note
The ImageInfo structure contains fixed-size character arrays that are properly NUL-terminated, making it safe to use as C strings.
This function performs a complete deep copy using memcpy, copying all fields including strings, integers, and timestamps.
The caller is responsible for allocating the ImageInfo structure before calling this function. The structure is not dynamically allocated by this function.
Warning
The image_info parameter must point to valid, allocated memory of at least sizeof(ImageInfo) bytes. Passing NULL or invalid pointers will result in undefined behavior.
This function reads from the in-memory image_info loaded during aaruf_open() or populated during aaruf_create(). It does not perform file I/O operations.

Definition at line 1774 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, aaruformat_context::image_info, aaruformat_context::magic, and TRACE.

◆ aaruf_get_media_barcode()

int32_t aaruf_get_media_barcode ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the barcode assigned to the physical media or its packaging.

Returns the UTF-16LE encoded barcode string that was captured when the image was created. Barcodes are commonly used in institutional workflows for inventory tracking and automated retrieval.

Parameters
contextPointer to a valid aaruformat context.
bufferBuffer that receives the barcode string; may be NULL when probing size requirements.
lengthPointer to an int32_t specifying the buffer size on input and receiving the actual barcode length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Barcode metadata was present and copied successfully.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No barcode metadata exists in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The supplied buffer was too small.
Note
Barcode values can be strict alphanumeric codes (e.g., LTO cartridge IDs) or full strings from custom labeling systems. Preserve the returned string exactly for catalog interoperability.

Definition at line 965 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, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::media_barcode, MetadataBlockHeader::mediaBarcodeLength, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_media_manufacturer()

int32_t aaruf_get_media_manufacturer ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the recorded media manufacturer name.

Provides access to the UTF-16LE encoded manufacturer metadata that identifies the company which produced the physical medium. This information is taken from the MetadataBlock and mirrors the value previously stored via aaruf_set_media_manufacturer().

Parameters
contextPointer to a valid aaruformat context.
bufferBuffer that receives the manufacturer string. May be NULL when probing size.
lengthPointer to an int32_t specifying the buffer size on input and receiving the actual manufacturer string length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Manufacturer metadata was available and copied.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) The image lacks manufacturer metadata.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer was too small; *length indicates size.
Note
Values may include trailing spaces or vendor-specific capitalization. Treat the returned data as authoritative and avoid trimming unless required by the consuming application.

Definition at line 756 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, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::media_manufacturer, MetadataBlockHeader::mediaManufacturerLength, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_media_model()

int32_t aaruf_get_media_model ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the media model or product designation metadata.

Returns the UTF-16LE encoded model name that specifies the exact product variant of the physical medium. The function mirrors the set counterpart and is useful for accurately documenting media specifications during preservation workflows.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the model string; may be NULL when querying required size.
lengthPointer to an int32_t that on input contains the buffer capacity in bytes and on output is updated with the actual metadata length.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Model metadata was successfully copied.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No media model metadata is present in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The caller-provided buffer is too small.
Note
Model strings often contain performance ratings (e.g., "16x", "LTO-7"). The data is opaque and should be handled without modification unless necessary.

Definition at line 826 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, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::media_model, MetadataBlockHeader::mediaModelLength, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_media_part_number()

int32_t aaruf_get_media_part_number ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the media part number recorded in the MetadataBlock.

Provides access to the UTF-16LE encoded part number identifying the precise catalog or ordering code for the physical medium. Part numbers help archivists procure exact replacements and document specific media variants used during acquisition.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the part number string. May be NULL while querying size.
lengthPointer to an int32_t that supplies the buffer size on input and is updated with the actual part number length on output.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Part number metadata was returned successfully.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No part number metadata exists.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer was insufficient; *length contains the required size.
Note
Part numbers may include manufacturer-specific formatting such as hyphens or suffix letters. The library stores and returns the data verbatim.

Definition at line 1036 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, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::media_part_number, MetadataBlockHeader::mediaPartNumberLength, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_media_sequence()

int32_t aaruf_get_media_sequence ( const void * context,
int32_t * sequence,
int32_t * last_sequence )

Retrieves the media sequence metadata for multi-volume image sets.

Reads the media sequence fields stored in the MetadataBlock header and returns the current media number together with the final media number for the complete set. This information indicates the position of the imaged medium within a multi-volume collection (for example, "disc 2 of 5"). The function operates entirely on in-memory structures populated during aaruf_open(); no additional disk I/O is performed.

Parameters
contextPointer to an initialized aaruformat context opened for reading or writing.
sequencePointer that receives the current media sequence number (typically 1-based).
last_sequencePointer that receives the total number of media in the set.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Metadata was present and the output parameters were populated.
AARUF_ERROR_NOT_AARUFORMAT(-1) The provided context pointer is NULL or not an aaruformat context (magic mismatch).
AARUF_ERROR_METADATA_NOT_PRESENT(-30) The MetadataBlock was not present in the image, making sequence data unavailable.
Note
For standalone media, both sequence and last_sequence are commonly set to 1. Some creators may also set them to 0 to indicate the absence of sequence semantics; callers should handle either pattern gracefully.
The function does not validate logical consistency (e.g., whether sequence <= last_sequence); it simply returns the values stored in the image header.

Definition at line 477 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_METADATA_NOT_PRESENT, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, MetadataBlockHeader::identifier, MetadataBlockHeader::lastMediaSequence, aaruformat_context::magic, MetadataBlockHeader::mediaSequence, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_media_serial_number()

int32_t aaruf_get_media_serial_number ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the media serial number recorded in the image metadata.

Copies the UTF-16LE encoded serial number identifying the specific physical medium. Serial numbers are particularly important for forensic tracking and archival provenance, enabling correlation between the physical item and its digital representation.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the serial number. May be NULL to determine required size.
lengthPointer to an int32_t that on input holds the buffer size and on output receives the actual serial number length.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Serial number metadata was copied into buffer.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No serial number metadata was stored in the image.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The provided buffer was too small.
Note
Serial numbers may contain spaces, hyphens, or alphanumeric characters. The library does not normalize or validate these strings.

Definition at line 896 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, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::media_serial_number, MetadataBlockHeader::mediaSerialNumberLength, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_media_title()

int32_t aaruf_get_media_title ( const void * context,
uint8_t * buffer,
int32_t * length )

Retrieves the media title or label captured during image creation.

Returns the UTF-16LE encoded media title string, representing markings or labels present on the original physical media. This function allows applications to present or archive the media title alongside the image, preserving contextual information from the physical artifact.

Parameters
contextPointer to a valid aaruformat context.
bufferDestination buffer for the UTF-16LE title string. May be NULL when querying size.
lengthPointer to an int32_t that on input holds the buffer capacity in bytes and on output receives the actual title length.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) The media title was available and copied to buffer.
AARUF_ERROR_NOT_AARUFORMAT(-1) The context pointer is invalid.
AARUF_ERROR_METADATA_NOT_PRESENT(-30) No media title metadata exists.
AARUF_ERROR_BUFFER_TOO_SMALL(-10) The supplied buffer was insufficient.
Note
Titles may contain international characters, control codes, or mixed casing. The library does not attempt to sanitize or interpret the string.

Definition at line 686 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, MetadataBlockHeader::identifier, aaruformat_context::magic, aaruformat_context::media_title, MetadataBlockHeader::mediaTitleLength, aaruformat_context::metadata_block_header, MetadataBlock, and TRACE.

◆ aaruf_get_negative_sectors()

int32_t aaruf_get_negative_sectors ( const void * context,
uint32_t * sectors )

Retrieves the number of negative (pre-gap) sectors in the AaruFormat image.

Returns the count of negative sectors that precede the standard user data area. Negative sectors are used to capture pre-gap data, lead-in areas, and other metadata that exists before the main user-accessible storage region. This is particularly important for optical media (CD, DVD, BD) where the lead-in contains the Table of Contents (TOC) and other essential disc structures, and for audio CDs where pre-gap sectors contain silence or hidden tracks. For most hard disk and floppy disk images, this value is typically zero.

Parameters
contextPointer to a valid aaruformat context (must be properly initialized).
sectorsPointer to a uint16_t that receives the negative sector count on success.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully retrieved the negative sector count. This is returned when:
  • The context is valid and properly initialized
  • The context magic number matches AARU_MAGIC
  • The sectors parameter is successfully populated with the negative sector count
  • The value is taken from ctx->user_data_ddt_header.negative
  • For optical media with lead-in data: sectors may be non-zero
  • For standard hard disk/floppy images: sectors is typically 0
  • Maximum value is 65,535 (uint16_t limit)
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC (invalid context type)
  • The context was not properly initialized by aaruf_open() or aaruf_create()
Note
Negative Sector Addressing:
  • Negative sectors are addressed with the 'negative' flag set to true
  • Sector addresses range from 0 to (negative_sectors - 1)
  • When calling aaruf_read_sector() or aaruf_write_sector():
    • Use negative=true
    • Use sector_address in range [0, negative_sectors - 1]
    • The actual logical position is before the user data area
Optical Media Context:
  • CD-ROM/CD-DA: Negative sectors contain lead-in area with TOC (Table of Contents). The lead-in typically spans LBA -450000 to -1, though only a portion may be captured. Pre-gap sectors (usually 150 sectors/2 seconds before each track) may also be stored as negative sectors for the first track.
  • DVD: May contain lead-in with disc structure information, copyright data, and region codes. The lead-in area varies by format (DVD-ROM, DVD-R, DVD+R, etc.).
  • Blu-ray: Lead-in contains disc information, burst cutting area (BCA), and other metadata. The structure differs between BD-ROM, BD-R, and BD-RE.
Hard Disk and Floppy Context:
  • Hard disk drives: Negative sectors are typically zero unless capturing special manufacturer reserved areas (HPA, DCO) that precede the standard user area.
  • Floppy disks: Negative sectors are typically zero as floppies have a simple linear sector layout without lead-in areas.
Audio CD Hidden Tracks:
  • Some audio CDs contain hidden tracks in the pre-gap of the first track
  • These pre-gap sectors can extend up to several minutes before track 1
  • Negative sectors can capture this "hidden" audio data
  • The pre-gap for track 1 typically starts at LBA -150 (2 seconds)
DDT Header Source:
  • The value is retrieved from ctx->user_data_ddt_header.negative
  • The DDT (Deduplication and Data Table) header tracks all sector allocation
  • This field is populated during image creation with aaruf_create()
  • The value is fixed for read-only images opened with aaruf_open()
  • Maximum representable value is 65,535 (uint16_t)
Total Addressable Space:
  • Total sectors = negative_sectors + user_sectors + overflow_sectors
  • The negative region comes first in logical order
  • Followed by the user region [0, user_sectors - 1]
  • Followed by the overflow region if present
Relationship to Image Creation:
  • The negative_sectors value is specified when calling aaruf_create()
  • It should be set based on the medium type and imaging requirements:
    • Optical discs: Set to the number of lead-in sectors captured
    • Hard disks: Typically 0, unless capturing HPA/DCO areas
    • Floppy disks: Typically 0
    • Audio CDs: May be non-zero to capture pre-gap hidden tracks
Warning
The sectors parameter is only modified on success (AARUF_STATUS_OK). On error, its value remains unchanged. Initialize it before calling if a default value is needed on failure.
This function reads from the in-memory DDT header loaded during aaruf_open() or set during aaruf_create(). It does not perform file I/O operations and executes quickly.
The maximum negative sector count is 65,535 due to the uint16_t storage type. If imaging optical media with larger lead-in areas, some data may not be representable. This limit is generally sufficient for most practical cases.
Negative sector data may contain copy-protected or encrypted content (e.g., CSS on DVDs, AACS on Blu-rays). Handle this data according to applicable laws and licensing agreements.

Definition at line 1557 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, aaruformat_context::magic, DdtHeader2::negative, TRACE, and aaruformat_context::user_data_ddt_header.

◆ aaruf_get_overflow_sectors()

int32_t aaruf_get_overflow_sectors ( const void * context,
uint32_t * sectors )

Retrieves the number of overflow (post-gap) sectors in the AaruFormat image.

Returns the count of overflow sectors that follow the standard user data area. Overflow sectors are used to capture post-gap data, lead-out areas, and other metadata that exists after the main user-accessible storage region. This is particularly important for optical media (CD, DVD, BD) where the lead-out marks the physical end of the recorded data and contains disc finalization information, and for multi-session discs where gaps between sessions need to be preserved. For most hard disk and floppy disk images, this value is typically zero.

Parameters
contextPointer to a valid aaruformat context (must be properly initialized).
sectorsPointer to a uint16_t that receives the overflow sector count on success.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully retrieved the overflow sector count. This is returned when:
  • The context is valid and properly initialized
  • The context magic number matches AARU_MAGIC
  • The sectors parameter is successfully populated with the overflow sector count
  • The value is taken from ctx->user_data_ddt_header.overflow
  • For optical media with lead-out data: sectors may be non-zero
  • For standard hard disk/floppy images: sectors is typically 0
  • Maximum value is 65,535 (uint16_t limit)
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC (invalid context type)
  • The context was not properly initialized by aaruf_open() or aaruf_create()
Note
Overflow Sector Addressing:
  • Overflow sectors are addressed with the 'negative' flag set to false
  • Sector addresses range from user_sectors to (user_sectors + overflow_sectors - 1)
  • When calling aaruf_read_sector() or aaruf_write_sector():
    • Use negative=false
    • Use sector_address in range [user_sectors, user_sectors + overflow_sectors - 1]
    • The actual logical position is after the user data area
Optical Media Context:
  • CD-ROM/CD-DA: Overflow sectors contain the lead-out area, which marks the physical end of the disc's recorded data. The lead-out consists of unreadable sectors filled with specific patterns.
  • DVD: May contain lead-out with disc finalization data, middle area (for dual-layer), and outer zone. DVD+R/RW discs may have substantial lead-out areas.
  • Blu-ray: Lead-out contains disc finalization markers and padding. For multi-layer discs, may include middle zones and outer areas.
Multi-Session and Track Context:
  • Multi-session optical discs have gaps between sessions
  • Audio CDs with post-gap after the last track may use overflow sectors
  • Track post-gaps (silence after audio tracks) typically 2 seconds/150 sectors
Hard Disk and Floppy Context:
  • Hard disk drives: Overflow sectors are typically zero unless capturing special manufacturer reserved areas (like DCO or HPA) that follow the standard user area.
  • Floppy disks: Overflow sectors are typically zero as floppies have a simple linear sector layout without lead-out areas. They may contain mastering information.
  • Some proprietary copy protection schemes may place data beyond the normal capacity, which could be captured as overflow sectors.
DDT Header Source:
  • The value is retrieved from ctx->user_data_ddt_header.overflow
  • The DDT (Deduplication and Data Table) header tracks all sector allocation
  • This field is populated during image creation with aaruf_create()
  • The value is fixed for read-only images opened with aaruf_open()
  • Maximum representable value is 65,535 (uint16_t)
Total Addressable Space:
  • Total sectors = negative_sectors + user_sectors + overflow_sectors
  • The negative region comes first in logical order
  • Followed by the user region [0, user_sectors - 1]
  • Followed by the overflow region at the end
  • Overflow represents the final addressable range in the image
Relationship to Image Creation:
  • The overflow_sectors value is specified when calling aaruf_create()
  • It should be set based on the medium type and imaging requirements:
    • Optical discs: Set to the number of lead-out sectors captured
    • Multi-session discs: May include inter-session gaps
    • Hard disks: Typically 0, unless capturing post-user reserved areas
    • Floppy disks: Typically 0
    • Copy-protected media: May be non-zero to capture protection schemes
Forensic Imaging Considerations:
  • Some copy protection schemes intentionally place data in overflow regions
  • These "overburn" areas extend beyond the disc's rated capacity
  • Overflow sectors ensure complete forensic capture of all readable data
  • Important for authenticity verification and copy protection analysis
Warning
The sectors parameter is only modified on success (AARUF_STATUS_OK). On error, its value remains unchanged. Initialize it before calling if a default value is needed on failure.
This function reads from the in-memory DDT header loaded during aaruf_open() or set during aaruf_create(). It does not perform file I/O operations and executes quickly.
The maximum overflow sector count is 65,535 due to the uint16_t storage type. If imaging optical media with larger lead-out areas or extensive overburn regions, some data may not be representable. This limit is generally sufficient for most practical cases.
Overflow sector data may be difficult or impossible to read on some drives, as it often resides in lead-out areas or beyond rated capacity. The presence of overflow sectors in an image indicates the imaging drive was capable of reading these extended areas, but other drives may not be able to access them.

Definition at line 1692 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, FATAL, aaruformat_context::magic, DdtHeader2::overflow, TRACE, and aaruformat_context::user_data_ddt_header.

◆ aaruf_get_user_sectors()

int32_t aaruf_get_user_sectors ( const void * context,
uint64_t * sectors )

Retrieves the total number of user-accessible sectors in the AaruFormat image.

Returns the count of standard user data sectors in the image, excluding any negative (pre-gap) or overflow (post-gap) sectors. This represents the primary addressable sector range that contains the main user data, typically corresponding to the logical capacity of the storage medium as it would be seen by an operating system or file system. For optical media, this excludes lead-in and lead-out areas. For hard disks, this represents the standard LBA-addressable range.

Parameters
contextPointer to a valid aaruformat context (must be properly initialized).
sectorsPointer to a uint64_t that receives the total user sector count on success.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully retrieved the user sector count. This is returned when:
  • The context is valid and properly initialized
  • The context magic number matches AARU_MAGIC
  • The sectors parameter is successfully populated with the user sector count
  • The value is taken from ctx->user_data_ddt_header.blocks
  • For block devices: sectors typically equals the total capacity in sectors
  • For optical media: sectors represents the user data area excluding lead-in/lead-out
  • For tape media: sectors may represent the total block count across all files
AARUF_ERROR_NOT_AARUFORMAT(-1) The context is invalid. This occurs when:
  • The context parameter is NULL
  • The context magic number doesn't match AARU_MAGIC (invalid context type)
  • The context was not properly initialized by aaruf_open() or aaruf_create()
Note
Sector Range Context:
  • User sectors represent the standard addressable range: 0 to (user_sectors - 1)
  • Total addressable sectors = negative_sectors + user_sectors + overflow_sectors
  • Negative sectors precede user sectors (pre-gap, lead-in)
  • Overflow sectors follow user sectors (post-gap, lead-out)
  • Use aaruf_get_negative_sectors() to get the negative sector count
  • Use aaruf_get_overflow_sectors() to get the overflow sector count
Media Type Considerations:
  • Optical Media (CD/DVD/BD): User sectors exclude lead-in and lead-out areas. Negative sectors may contain TOC and pre-gap data. Overflow sectors may contain post-gap and lead-out data.
  • Hard Disk Drives: User sectors represent the full LBA range. Negative and overflow sectors are typically zero unless capturing special areas.
  • Floppy Disks: User sectors represent the standard formatted capacity.
  • Tape Media: User sectors may represent the total block count. Negative and overflow sectors are typically not used for tape.
DDT Header Source:
  • The value is retrieved from ctx->user_data_ddt_header.blocks
  • The DDT (Deduplication and Data Table) header tracks sector allocation
  • This field is populated during image creation with aaruf_create()
  • The value is fixed for read-only images opened with aaruf_open()
  • For write-enabled images, this represents the allocated capacity
Addressing and I/O Operations:
  • When reading/writing sectors with aaruf_read_sector() or aaruf_write_sector():
    • Set negative=false and use sector_address in range [0, user_sectors - 1]
    • For negative sectors: set negative=true, sector_address in [0, negative_sectors - 1]
    • For overflow sectors: set negative=false, sector_address in [user_sectors, user_sectors + overflow_sectors
  • 1]
Note
Relationship to Image Creation:
  • The user_sectors value is specified when calling aaruf_create()
  • It should match the logical capacity of the medium being imaged
  • For forensic images, ensure it matches the source medium exactly
  • For virtual disks, set it to the desired capacity

Definition at line 1432 of file metadata.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, DdtHeader2::blocks, FATAL, aaruformat_context::magic, TRACE, and aaruformat_context::user_data_ddt_header.