|
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 "erasure_internal.h"#include "internal.h"#include "log.h"Go to the source code of this file.
Functions | |
| uint64_t | dpm_payload_length (const DpmHeader *header) |
| Computes the payload length a Data Position Measurement header describes. | |
| int32_t | validate_dpm_block (const uint8_t *data, size_t length) |
| Validates a serialized Data Position Measurement block. | |
| int32_t | recover_dpm_block (aaruformat_context *ctx) |
| Recovers a damaged Data Position Measurement block with erasure coding. | |
| void | process_dpm_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a Data Position Measurement block from the image stream. | |
| uint64_t dpm_payload_length | ( | const DpmHeader * | header | ) |
Computes the payload length a Data Position Measurement header describes.
| header | DPM block header. |
Definition at line 36 of file dpm.c.
References DpmHeader::calibrations, dpm_payload_length(), DpmHeader::entries, and DpmHeader::layerEnds.
Referenced by aaruf_verify_image(), dpm_payload_length(), process_dpm_block(), and validate_dpm_block().
| void process_dpm_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a Data Position Measurement block from the image stream.
Reads the block pointed to by the index entry, validates it and keeps it, header included, in the context so aaruf_get_dpm() can return it. The block is optional: if it cannot be read or is invalid it is ignored and the image opens without it.
On images opened for resume, the loaded block is not marked dirty, so its index entry is kept untouched on close unless aaruf_set_dpm() or aaruf_clear_dpm() are called.
| ctx | Pointer to the aaruformat context. |
| entry | Index entry pointing to the block. |
Definition at line 148 of file dpm.c.
References aaruf_fseek(), aaruf_ftell(), AARUF_STATUS_OK, DataPositionMeasurementBlock, aaruformat_context::dpm_block, aaruformat_context::dpm_block_length, aaruformat_context::dpm_damaged_offset, dpm_payload_length(), DpmHeader::entries, FATAL, DpmHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, DpmHeader::length, IndexEntry::offset, process_dpm_block(), recover_dpm_block(), TRACE, and validate_dpm_block().
Referenced by aaruf_open(), and process_dpm_block().
| int32_t recover_dpm_block | ( | aaruformat_context * | ctx | ) |
Recovers a damaged Data Position Measurement block with erasure coding.
The DPM block is part of the erasure coding metadata group. When it fails to load, its offset is remembered in ctx->dpm_damaged_offset, and this rebuilds it from the parity, trims the alignment padding the recovered bytes carry, validates it and keeps it in the context. aaruf_open() loads the erasure coding map before processing the indexed blocks, so this works while opening.
| ctx | Pointer to the aaruformat context. |
Definition at line 83 of file dpm.c.
References AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_STATUS_OK, aaruformat_context::dpm_block, aaruformat_context::dpm_block_length, aaruformat_context::dpm_damaged_offset, ec_recover_meta_block(), DpmHeader::length, recover_dpm_block(), TRACE, and validate_dpm_block().
Referenced by process_dpm_block(), and recover_dpm_block().
| int32_t validate_dpm_block | ( | const uint8_t * | data, |
| size_t | length ) |
Validates a serialized Data Position Measurement block.
Checks that the buffer holds a DpmHeader with the correct identifier, that the payload length matches both the header length field and the counts of layer ends, entries and calibrations, and that the payload CRC64 matches.
| data | Serialized block, header followed by its payload. |
| length | Length of data in bytes. |
Definition at line 53 of file dpm.c.
References aaruf_crc64_data(), AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_STATUS_OK, DpmHeader::crc64, DataPositionMeasurementBlock, dpm_payload_length(), DpmHeader::identifier, DpmHeader::length, and validate_dpm_block().
Referenced by aaruf_set_dpm(), process_dpm_block(), recover_dpm_block(), and validate_dpm_block().