|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <stdlib.h>#include <string.h>#include <aaruformat.h>#include "internal.h"#include "log.h"Go to the source code of this file.
Functions | |
| int32_t | aaruf_read_media_tag (void *context, uint8_t *data, const int32_t tag, uint32_t *length) |
| Reads a media tag from the AaruFormat image. | |
| int32_t | aaruf_read_sector (void *context, const uint64_t sector_address, bool negative, uint8_t *data, uint32_t *length) |
| Reads a sector from the AaruFormat image. | |
| int32_t | aaruf_read_track_sector (void *context, uint8_t *data, const uint64_t sector_address, uint32_t *length, const uint8_t track) |
| Reads a sector from a specific track in the AaruFormat image. | |
| int32_t | aaruf_read_sector_long (void *context, const uint64_t sector_address, bool negative, uint8_t *data, uint32_t *length) |
| Reads a complete sector with all metadata from the AaruFormat image. | |
| int32_t | aaruf_read_sector_tag (const void *context, const uint64_t sector_address, const bool negative, uint8_t *buffer, uint32_t *length, const int32_t tag) |
| Reads a specific sector tag from the AaruFormat image. | |
| int32_t aaruf_read_media_tag | ( | void * | context, |
| uint8_t * | data, | ||
| const int32_t | tag, | ||
| uint32_t * | length ) |
Reads a media tag from the AaruFormat image.
Reads the specified media tag from the image and stores it in the provided buffer. Media tags contain metadata information about the storage medium such as disc information, lead-in/lead-out data, manufacturer-specific information, or other medium-specific metadata. This function uses a hash table lookup for efficient tag retrieval and supports buffer size querying when data pointer is NULL.
| context | Pointer to the aaruformat context. |
| data | Pointer to the buffer to store the tag data. Can be NULL to query tag length. |
| tag | Tag identifier to read (specific to media type and format). |
| length | Pointer to the length of the buffer on input; updated with actual tag length on output. |
| AARUF_STATUS_OK | (0) Successfully read the media tag. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_MEDIA_TAG_NOT_PRESENT | (-11) The requested media tag does not exist. This occurs when:
|
| AARUF_ERROR_BUFFER_TOO_SMALL | (-10) The provided buffer is insufficient. This occurs when:
|
Definition at line 85 of file read.c.
References AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_MEDIA_TAG_NOT_PRESENT, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, mediaTagEntry::data, FATAL, mediaTagEntry::length, aaruformat_context::magic, aaruformat_context::mediaTags, and TRACE.
| int32_t aaruf_read_sector | ( | void * | context, |
| const uint64_t | sector_address, | ||
| bool | negative, | ||
| uint8_t * | data, | ||
| uint32_t * | length ) |
Reads a sector from the AaruFormat image.
Reads user data from the specified sector address in the image. This function reads only the user data portion of the sector, without any additional metadata or ECC/EDC information. It handles block-based deduplication, compression (LZMA/FLAC), and caching for optimal performance. The function supports both DDT v1 and v2 formats for sector-to-block mapping.
| context | Pointer to the aaruformat context. |
| sector_address | The logical sector address to read from. |
| negative | Indicates if the sector address is negative. |
| data | Pointer to buffer where sector data will be stored. Can be NULL to query length. |
| length | Pointer to variable containing buffer size on input, actual data length on output. |
| AARUF_STATUS_OK | (0) Successfully read the sector data. This is returned when:
|
| AARUF_STATUS_SECTOR_NOT_DUMPED | (1) The sector was not dumped during imaging. This occurs when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_SECTOR_OUT_OF_BOUNDS | (-8) The sector address exceeds image bounds. This occurs when:
|
| AARUF_ERROR_BUFFER_TOO_SMALL | (-10) The provided buffer is insufficient. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_HEADER | (-6) Block header reading failed. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_BLOCK | (-7) Block data reading failed. This occurs when:
|
| AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK | (-17) Decompression failed. This occurs when:
|
| AARUF_ERROR_UNSUPPORTED_COMPRESSION | (-13) Unsupported compression algorithm. This occurs when:
|
| Other | error codes may be propagated from DDT decoding functions:
|
Definition at line 250 of file read.c.
References AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_CANNOT_READ_HEADER, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_ERROR_SECTOR_OUT_OF_BOUNDS, AARUF_ERROR_UNSUPPORTED_COMPRESSION, aaruf_flac_decode_redbook_buffer(), aaruf_lzma_decode_buffer(), AARUF_STATUS_OK, AARUF_STATUS_SECTOR_NOT_DUMPED, add_to_cache_uint64(), aaruformat_context::block_cache, aaruformat_context::block_header_cache, BlockHeader::cmpLength, BlockHeader::compression, aaruformat_context::ddt_version, decode_ddt_entry_v1(), decode_ddt_entry_v2(), FATAL, find_in_cache_uint64(), Flac, aaruformat_context::image_info, aaruformat_context::imageStream, BlockHeader::length, Lzma, LZMA_PROPERTIES_LENGTH, aaruformat_context::magic, DdtHeader2::negative, None, DdtHeader2::overflow, ImageInfo::Sectors, ImageInfo::SectorSize, BlockHeader::sectorSize, SectorStatusNotDumped, TRACE, and aaruformat_context::user_data_ddt_header.
Referenced by aaruf_read_sector_long(), and aaruf_read_track_sector().
| int32_t aaruf_read_sector_long | ( | void * | context, |
| const uint64_t | sector_address, | ||
| bool | negative, | ||
| uint8_t * | data, | ||
| uint32_t * | length ) |
Reads a complete sector with all metadata from the AaruFormat image.
Reads the complete sector data including user data, ECC/EDC, subchannel data, and other metadata depending on the media type. For optical discs, this returns a full 2352-byte sector with sync, header, user data, and ECC/EDC. For block media with tags, this includes both the user data and tag information. The function handles complex sector reconstruction including ECC correction and format-specific metadata assembly.
| context | Pointer to the aaruformat context. |
| sector_address | The logical sector address to read from. |
| negative | Indicates if the sector address is negative. |
| data | Pointer to buffer where complete sector data will be stored. Can be NULL to query length. |
| length | Pointer to variable containing buffer size on input, actual data length on output. |
| AARUF_STATUS_OK | (0) Successfully read the complete sector with metadata. This is returned when:
|
| AARUF_STATUS_SECTOR_NOT_DUMPED | (1) The sector or metadata was not dumped. This can occur when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_INCORRECT_MEDIA_TYPE | (-5) The media type doesn't support long sector reading. This occurs when:
|
| AARUF_ERROR_BUFFER_TOO_SMALL | (-10) The buffer is insufficient for complete sector data. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. This occurs when:
|
| AARUF_ERROR_TRACK_NOT_FOUND | (-12) Cannot locate the sector's track. This occurs when:
|
| AARUF_ERROR_INVALID_TRACK_FORMAT | (-14) The track has an unsupported format. This occurs when:
|
| AARUF_ERROR_REACHED_UNREACHABLE_CODE | (-15) Internal logic error. This occurs when:
|
| All | error codes from aaruf_read_sector() may be propagated:
|
Definition at line 815 of file read.c.
References AARU_MAGIC, aaruf_ecc_cd_reconstruct(), aaruf_ecc_cd_reconstruct_prefix(), AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_INCORRECT_MEDIA_TYPE, AARUF_ERROR_INVALID_TRACK_FORMAT, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_ERROR_REACHED_UNREACHABLE_CODE, AARUF_ERROR_SECTOR_OUT_OF_BOUNDS, AARUF_ERROR_TRACK_NOT_FOUND, aaruf_read_sector(), AARUF_STATUS_OK, AARUF_STATUS_SECTOR_NOT_DUMPED, AppleFileWare, AppleProfile, AppleSonyDS, AppleSonySS, AppleWidget, Audio, BlockMedia, CD_DFIX_MASK, CD_XFIX_MASK, CdMode1, CdMode2Form1, CdMode2Form2, CdMode2Formless, Correct, Data, aaruformat_context::data_tracks, DVDDownload, DVDPR, DVDPRDL, DVDPRW, DVDPRWDL, DVDR, DVDRAM, DVDRDL, DVDROM, DVDRW, DVDRWDL, aaruformat_context::ecc_cd_context, FATAL, aaruformat_context::image_info, aaruformat_context::magic, ImageInfo::MediaType, ImageInfo::MetadataMediaType, aaruformat_context::mode2_subheaders, Mode2Form1Ok, Mode2Form2NoCrc, Mode2Form2Ok, DdtHeader2::negative, NotDumped, aaruformat_context::number_of_data_tracks, Nuon, OpticalDisc, DdtHeader2::overflow, PriamDataTower, PS2DVD, PS3DVD, SACD, aaruformat_context::sector_cpr_mai, aaruformat_context::sector_edc, aaruformat_context::sector_id, aaruformat_context::sector_ied, aaruformat_context::sector_prefix, aaruformat_context::sector_prefix_corrected, aaruformat_context::sector_prefix_ddt, aaruformat_context::sector_prefix_ddt2, aaruformat_context::sector_subchannel, aaruformat_context::sector_suffix, aaruformat_context::sector_suffix_corrected, aaruformat_context::sector_suffix_ddt, aaruformat_context::sector_suffix_ddt2, ImageInfo::Sectors, SectorStatusMode1Correct, SectorStatusMode2Form1Ok, SectorStatusMode2Form2NoCrc, SectorStatusMode2Form2Ok, SectorStatusNotDumped, TrackEntry::start, TRACE, TrackEntry::type, and aaruformat_context::user_data_ddt_header.
| int32_t aaruf_read_sector_tag | ( | const void * | context, |
| const uint64_t | sector_address, | ||
| const bool | negative, | ||
| uint8_t * | buffer, | ||
| uint32_t * | length, | ||
| const int32_t | tag ) |
Reads a specific sector tag from the AaruFormat image.
Reads sector-level metadata tags such as subchannel data, track information, DVD sector metadata, or Apple/Priam proprietary tags from the specified sector. Sector tags are ancillary data stored separately from the main user data and provide format-specific metadata like track flags, ISRC codes, DVD encryption information, or ECC/EDC data. This function validates tag type against media type and ensures the tag data is present in the image before returning it.
| context | Pointer to the aaruformat context. |
| sector_address | The logical sector address to read the tag from. |
| negative | Indicates if the sector address is negative (pre-track area). |
| buffer | Pointer to buffer where tag data will be stored. Can be NULL to query tag length. |
| length | Pointer to variable containing buffer size on input, actual tag length on output. |
| tag | Tag identifier specifying which sector tag to read (see SectorTagType enum). |
| AARUF_STATUS_OK | (0) Successfully read the sector tag. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_SECTOR_OUT_OF_BOUNDS | (-5) The sector address exceeds image bounds. This occurs when:
|
| AARUF_ERROR_INCORRECT_MEDIA_TYPE | (-12) Tag type incompatible with media type. This occurs when:
|
| AARUF_ERROR_INCORRECT_DATA_SIZE | (-26) The provided buffer has incorrect size. This occurs when:
|
| AARUF_ERROR_SECTOR_TAG_NOT_PRESENT | (-16) The requested tag is not stored in the image. This occurs when:
|
| AARUF_ERROR_TRACK_NOT_FOUND | (-13) Track information not found for the sector. This occurs when:
|
| AARUF_ERROR_INVALID_TAG | (-27) The tag identifier is not recognized or supported. This occurs when:
|
Block Media Tags (BlockMedia only):
Definition at line 1463 of file read.c.
References AARU_MAGIC, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_INCORRECT_MEDIA_TYPE, AARUF_ERROR_INVALID_TAG, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_SECTOR_OUT_OF_BOUNDS, AARUF_ERROR_SECTOR_TAG_NOT_PRESENT, AARUF_ERROR_TRACK_NOT_FOUND, AARUF_STATUS_OK, AppleProfileTag, AppleSonyTag, BlockMedia, CdSectorSubchannel, CdTrackFlags, CdTrackIsrc, DvdCmi, DvdSectorEdc, DvdSectorIed, DvdSectorInformation, DvdSectorNumber, DvdTitleKeyDecrypted, TracksHeader::entries, FATAL, TrackEntry::flags, aaruformat_context::image_info, TrackEntry::isrc, aaruformat_context::magic, ImageInfo::MetadataMediaType, DdtHeader2::negative, OpticalDisc, DdtHeader2::overflow, PriamDataTowerTag, aaruformat_context::sector_cpr_mai, aaruformat_context::sector_decrypted_title_key, aaruformat_context::sector_edc, aaruformat_context::sector_id, aaruformat_context::sector_ied, aaruformat_context::sector_subchannel, ImageInfo::Sectors, TrackEntry::start, TRACE, aaruformat_context::track_entries, aaruformat_context::tracks_header, and aaruformat_context::user_data_ddt_header.
| int32_t aaruf_read_track_sector | ( | void * | context, |
| uint8_t * | data, | ||
| const uint64_t | sector_address, | ||
| uint32_t * | length, | ||
| const uint8_t | track ) |
Reads a sector from a specific track in the AaruFormat image.
Reads user data from the specified sector address within a particular track. This function is specifically designed for optical disc images where sectors are organized by tracks. The sector address is relative to the start of the track. It validates the media type, locates the specified track by sequence number, calculates the absolute sector address, and delegates to aaruf_read_sector().
| context | Pointer to the aaruformat context. |
| data | Pointer to buffer where sector data will be stored. |
| sector_address | The sector address relative to the track start. |
| length | Pointer to variable containing buffer size on input, actual data length on output. |
| track | The track sequence number to read from. |
| AARUF_STATUS_OK | (0) Successfully read the sector data from the specified track. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_INCORRECT_MEDIA_TYPE | (-5) The media is not an optical disc. This occurs when:
|
| AARUF_ERROR_TRACK_NOT_FOUND | (-12) The specified track does not exist. This occurs when:
|
| All | other error codes from aaruf_read_sector() may be returned:
|
Definition at line 663 of file read.c.
References AARU_MAGIC, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_INCORRECT_MEDIA_TYPE, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_TRACK_NOT_FOUND, aaruf_read_sector(), aaruformat_context::data_tracks, FATAL, aaruformat_context::image_info, aaruformat_context::magic, ImageInfo::MetadataMediaType, aaruformat_context::number_of_data_tracks, OpticalDisc, TrackEntry::sequence, TrackEntry::start, and TRACE.