libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
dpm.c File Reference
#include <stdint.h>
#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_get_dpm (const void *context, uint8_t *buffer, size_t *length)
 Retrieves the Data Position Measurement block.
int32_t aaruf_set_dpm (void *context, const uint8_t *data, size_t length)
 Sets the Data Position Measurement block.
int32_t aaruf_clear_dpm (void *context)
 Removes the Data Position Measurement block.

Function Documentation

◆ aaruf_clear_dpm()

int32_t aaruf_clear_dpm ( void * context)

Removes the Data Position Measurement block.

Discards the DPM kept in the context. When the image is closed, the DPM block is removed from the index, so a resumed image loses the DPM it had.

Parameters
contextPointer to the aaruformat context, opened for writing.
Returns
AARUF_STATUS_OK on success, AARUF_ERROR_NOT_AARUFORMAT if the context is invalid, AARUF_READ_ONLY if the image is not being written.

Definition at line 172 of file dpm.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, aaruf_clear_dpm(), AARUF_ERROR_NOT_AARUFORMAT, AARUF_READ_ONLY, AARUF_STATUS_OK, aaruformat_context::dirty_dpm_block, aaruformat_context::dpm_block, aaruformat_context::dpm_block_length, FATAL, aaruformat_context::is_writing, aaruformat_context::magic, and TRACE.

Referenced by aaruf_clear_dpm().

◆ aaruf_get_dpm()

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

Retrieves the Data Position Measurement block.

Copies the serialized block, a DpmHeader followed by its payload exactly as stored in the image, to buffer. When buffer is NULL or too small, length is set to the required size and AARUF_ERROR_BUFFER_TOO_SMALL is returned, so the caller can allocate and call again.

Works on images opened for reading and on images being created or resumed.

Parameters
contextPointer to the aaruformat context.
bufferBuffer that receives the block, may be NULL to query the size.
lengthOn input the size of buffer, on output the size of the block.
Returns
AARUF_STATUS_OK on success, AARUF_ERROR_NOT_AARUFORMAT if the context is invalid, AARUF_ERROR_METADATA_NOT_PRESENT if the image has no DPM, AARUF_ERROR_BUFFER_TOO_SMALL if buffer is too small.

Definition at line 43 of file dpm.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_METADATA_NOT_PRESENT, AARUF_ERROR_NOT_AARUFORMAT, aaruf_get_dpm(), AARUF_STATUS_OK, aaruformat_context::dpm_block, aaruformat_context::dpm_block_length, FATAL, aaruformat_context::magic, and TRACE.

Referenced by aaruf_get_dpm().

◆ aaruf_set_dpm()

int32_t aaruf_set_dpm ( void * context,
const uint8_t * data,
size_t length )

Sets the Data Position Measurement block.

Takes the serialized block, a DpmHeader followed by its payload, validates its identifier, sizes and CRC64, and keeps a copy that is written when the image is closed, replacing any DPM the image already had.

Parameters
contextPointer to the aaruformat context, opened for writing.
dataSerialized block.
lengthLength of data in bytes.
Returns
AARUF_STATUS_OK on success, AARUF_ERROR_NOT_AARUFORMAT if the context is invalid, AARUF_READ_ONLY if the image is not being written, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_CANNOT_READ_BLOCK or AARUF_ERROR_INVALID_BLOCK_CRC if the block is invalid, AARUF_ERROR_NOT_ENOUGH_MEMORY.

Definition at line 102 of file dpm.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_READ_ONLY, aaruf_set_dpm(), AARUF_STATUS_OK, aaruformat_context::dirty_dpm_block, aaruformat_context::dpm_block, aaruformat_context::dpm_block_length, FATAL, aaruformat_context::is_writing, aaruformat_context::magic, TRACE, and validate_dpm_block().

Referenced by aaruf_set_dpm().