libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
data.c File Reference
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "aaruformat.h"
#include "log.h"
#include "uthash.h"

Go to the source code of this file.

Functions

int32_t process_data_block (aaruformat_context *ctx, IndexEntry *entry)
 Processes a data block from the image stream.

Function Documentation

◆ process_data_block()

int32_t process_data_block ( aaruformat_context * ctx,
IndexEntry * entry )

Processes a data block from the image stream.

Reads a data block from the image, decompresses if needed, and updates the context with its contents. This function handles various types of data blocks including compressed (LZMA) and uncompressed data, performs CRC validation, and stores the processed data in the appropriate context fields.

Parameters
ctxPointer to the aaruformat context.
entryPointer to the index entry describing the data block.
Returns
Returns one of the following status codes:
Return values
AARUF_STATUS_OK(0) Successfully processed the data block. This is returned when:
  • The block is processed successfully and all validations pass
  • A NoData block type is encountered (these are skipped)
  • A UserData block type is encountered (these update sector size but are otherwise skipped)
  • Block validation fails but processing continues (non-fatal errors like CRC mismatches)
  • Memory allocation failures occur (processing continues with other blocks)
  • Block reading failures occur (processing continues with other blocks)
  • Unknown compression types are encountered (block is skipped)
AARUF_ERROR_NOT_AARUFORMAT(-1) The context or image stream is invalid (NULL pointers).
AARUF_ERROR_CANNOT_READ_BLOCK(-7) Failed to seek to the block position in the image stream. This occurs when fseek() fails or the file position doesn't match the expected offset.
AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK(-17) LZMA decompression failed. This can happen when:
  • The LZMA decoder returns an error code
  • The decompressed data size doesn't match the expected block length
Note
Most validation and reading errors are treated as non-fatal and result in AARUF_STATUS_OK being returned while the problematic block is skipped. This allows processing to continue with other blocks in the image.
The function performs the following validations:
  • Block identifier matches the expected block type
  • Block data type matches the expected data type
  • CRC64 checksum validation (with version-specific byte order handling)
  • Proper decompression for LZMA-compressed blocks
Warning
Memory allocated for block data is stored in the context and should be freed when the context is destroyed. The function may replace existing data in the context.

Definition at line 71 of file data.c.

References aaruf_crc64_data(), aaruf_cst_untransform(), AARUF_ERROR_CANNOT_DECOMPRESS_BLOCK, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_NOT_AARUFORMAT, aaruf_get_media_tag_type_for_datatype(), aaruf_lzma_decode_buffer(), AARUF_STATUS_OK, AARUF_VERSION_V1, AppleProfileTag, AppleProfileTagAaru, AppleSonyTag, AppleSonyTagAaru, IndexEntry::blockType, bswap_64, CdSectorEcc, CdSectorEccP, CdSectorEccQ, CdSectorEdc, CdSectorHeader, CdSectorPrefix, CdSectorPrefixCorrected, CdSectorSubchannel, CdSectorSubchannelAaru, CdSectorSubHeader, CdSectorSuffix, CdSectorSuffixCorrected, CdSectorSync, BlockHeader::cmpLength, CompactDiscMode2Subheader, BlockHeader::compression, BlockHeader::crc64, mediaTagEntry::data, IndexEntry::dataType, DvdCmi, DvdSectorCprMai, DvdSectorEdc, DvdSectorEdcAaru, DvdSectorId, DvdSectorIed, DvdSectorIedAaru, DvdSectorInformation, DvdSectorNumber, DvdSectorTitleKeyDecrypted, DvdTitleKeyDecrypted, FATAL, aaruformat_context::header, BlockHeader::identifier, aaruformat_context::image_info, AaruHeaderV2::imageMajorVersion, ImageInfo::ImageSize, aaruformat_context::imageStream, BlockHeader::length, mediaTagEntry::length, Lzma, LZMA_PROPERTIES_LENGTH, LzmaClauniaSubchannelTransform, aaruformat_context::mediaTags, aaruformat_context::mode2_subheaders, NoData, None, IndexEntry::offset, PriamDataTowerTag, PriamDataTowerTagAaru, aaruformat_context::readableSectorTags, 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_prefix, aaruformat_context::sector_prefix_corrected, aaruformat_context::sector_subchannel, aaruformat_context::sector_suffix, aaruformat_context::sector_suffix_corrected, ImageInfo::SectorSize, BlockHeader::sectorSize, TRACE, BlockHeader::type, mediaTagEntry::type, and UserData.

Referenced by aaruf_open().