|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <stdint.h>#include <stdlib.h>#include "aaruformat.h"#include "internal.h"#include "log.h"Go to the source code of this file.
Macros | |
| #define | COPY_STRING_FIELD(field) |
Functions | |
| static void | free_dump_hardware_entries (DumpHardwareEntriesWithData *entries, uint32_t count) |
| int32_t | aaruf_get_dumphw (void *context, uint8_t *buffer, size_t *length) |
| Retrieves the dump hardware block containing acquisition environment information. | |
| int32_t | aaruf_set_dumphw (void *context, uint8_t *data, size_t length) |
| Sets the dump hardware block for the image during creation. | |
| #define COPY_STRING_FIELD | ( | field | ) |
Referenced by aaruf_set_dumphw().
| int32_t aaruf_get_dumphw | ( | void * | context, |
| uint8_t * | buffer, | ||
| size_t * | length ) |
Retrieves the dump hardware block containing acquisition environment information.
Extracts the complete DumpHardwareBlock from the image, which documents the hardware and software environments used to create the image. A dump hardware block records one or more "dump environments" – typically combinations of physical devices (drives, controllers, adapters) and the software stacks that performed the read operations. This metadata is essential for understanding the imaging context, validating acquisition integrity, reproducing imaging conditions, and supporting forensic or archival documentation requirements.
Each environment entry includes hardware identification (manufacturer, model, revision, firmware, serial number), software identification (name, version, operating system), and optional extent ranges that specify which logical sectors or units were contributed by that particular environment. This structure supports complex imaging scenarios where multiple devices or software configurations were used to create a composite image.
The function reconstructs the complete on-disk binary representation of the dump hardware block, including the DumpHardwareHeader followed by all entries with their variable-length UTF-8 strings and extent arrays. The reconstructed block includes a calculated CRC64 checksum over the payload data for integrity verification.
This function supports a two-call pattern for buffer size determination:
Alternatively, if the caller already knows the buffer is large enough, a single call will succeed and populate the buffer with the complete dump hardware block.
| context | Pointer to the aaruformat context (must be a valid, opened image context). |
| buffer | Pointer to a buffer that will receive the dump hardware block data. Must be large enough to hold the complete block (at least *length bytes on input). May be NULL to query the required buffer size. The buffer will contain the DumpHardwareHeader followed by serialized entries, strings, and extent arrays on success. |
| length | Pointer to a size_t that serves dual purpose:
|
| AARUF_STATUS_OK | (0) Successfully retrieved dump hardware block. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_BLOCK | (-6) The dump hardware block is not present. This occurs when:
|
| AARUF_ERROR_BUFFER_TOO_SMALL | (-12) The provided buffer is insufficient. This occurs when:
|
Definition at line 186 of file dump.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, aaruf_crc64_data(), AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_NOT_AARUFORMAT, AARUF_STATUS_OK, DumpHardwareHeader::crc64, aaruformat_context::dump_hardware_entries_with_data, aaruformat_context::dump_hardware_header, DumpHardwareBlock, DumpHardwareHeader::entries, DumpHardwareEntriesWithData::entry, DumpHardwareEntriesWithData::extents, DumpHardwareEntry::extents, FATAL, DumpHardwareEntriesWithData::firmware, DumpHardwareEntry::firmwareLength, DumpHardwareHeader::identifier, DumpHardwareHeader::length, aaruformat_context::magic, DumpHardwareEntriesWithData::manufacturer, DumpHardwareEntry::manufacturerLength, DumpHardwareEntriesWithData::model, DumpHardwareEntry::modelLength, DumpHardwareEntriesWithData::revision, DumpHardwareEntry::revisionLength, DumpHardwareEntriesWithData::serial, DumpHardwareEntry::serialLength, DumpHardwareEntriesWithData::softwareName, DumpHardwareEntry::softwareNameLength, DumpHardwareEntriesWithData::softwareOperatingSystem, DumpHardwareEntry::softwareOperatingSystemLength, DumpHardwareEntriesWithData::softwareVersion, DumpHardwareEntry::softwareVersionLength, and TRACE.
| int32_t aaruf_set_dumphw | ( | void * | context, |
| uint8_t * | data, | ||
| size_t | length ) |
Sets the dump hardware block for the image during creation.
Embeds dump hardware information into the image being created. The dump hardware block documents the hardware and software environments used to create the image, recording one or more "dump environments" – typically combinations of physical devices (drives, controllers, adapters) and the software stacks that performed the read operations. This metadata is essential for understanding the imaging context, validating acquisition integrity, reproducing imaging conditions, and supporting forensic or archival documentation requirements.
Each environment entry includes hardware identification (manufacturer, model, revision, firmware, serial number), software identification (name, version, operating system), and optional extent ranges that specify which logical sectors or units were contributed by that particular environment. This structure supports complex imaging scenarios where multiple devices or software configurations were used to create a composite image.
The function accepts a complete, pre-serialized DumpHardwareBlock in the on-disk binary format (as returned by aaruf_get_dumphw() or manually constructed). The block is validated for correct identifier, length consistency, and CRC64 integrity before being parsed and stored in the context. The function deserializes the binary block, extracts all entries with their variable-length UTF-8 strings and extent arrays, and creates null-terminated in-memory copies for internal use.
Validation performed:
Parsing process:
Memory management: If any memory allocation fails during parsing, all previously allocated memory for the new data is freed via the free_copy_and_error label, and AARUF_ERROR_NOT_ENOUGH_MEMORY is returned. Any existing dump hardware data in the context is freed before storing new data, ensuring no memory leaks when replacing dump hardware information.
| context | Pointer to the aaruformat context (must be a valid, write-enabled image context). |
| data | Pointer to the dump hardware block data in on-disk binary format. Must contain a complete DumpHardwareBlock starting with DumpHardwareHeader followed by all entries, strings, and extent arrays. Must not be NULL. |
| length | Length of the dump hardware block data in bytes. Must equal sizeof(DumpHardwareHeader) + header.length for validation to succeed. |
| AARUF_STATUS_OK | (0) Successfully set dump hardware block. This is returned when:
|
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. This occurs when:
|
| AARUF_READ_ONLY | (-13) The context is not opened for writing. This occurs when:
|
| AARUF_ERROR_CANNOT_READ_BLOCK | (-6) Invalid block identifier. This occurs when:
|
| AARUF_ERROR_INCORRECT_DATA_SIZE | (-11) Invalid data or length. This occurs when:
|
| AARUF_ERROR_INVALID_BLOCK_CRC | (-10) CRC64 checksum mismatch. This occurs when:
|
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-8) Memory allocation failed. This occurs when:
|
Definition at line 531 of file dump.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, aaruf_crc64_data(), AARUF_ERROR_CANNOT_READ_BLOCK, AARUF_ERROR_INCORRECT_DATA_SIZE, AARUF_ERROR_INVALID_BLOCK_CRC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_READ_ONLY, AARUF_STATUS_OK, compare_extents(), COPY_STRING_FIELD, DumpHardwareHeader::crc64, aaruformat_context::dirty_dumphw_block, aaruformat_context::dump_hardware_entries_with_data, aaruformat_context::dump_hardware_header, DumpHardwareBlock, DumpHardwareHeader::entries, DumpHardwareEntriesWithData::entry, DumpHardwareEntriesWithData::extents, DumpHardwareEntry::extents, FATAL, free_dump_hardware_entries(), DumpHardwareHeader::identifier, aaruformat_context::is_writing, DumpHardwareHeader::length, aaruformat_context::magic, and TRACE.
|
static |
Definition at line 26 of file dump.c.
Referenced by aaruf_set_dumphw().