|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
Go to the source code of this file.
Functions | |
| void | process_tape_files_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a tape file metadata block from the image stream. | |
| void | process_tape_partitions_block (aaruformat_context *ctx, const IndexEntry *entry) |
| Processes a tape partition metadata block from the image stream. | |
| int32_t | aaruf_get_tape_file (const void *context, const uint8_t partition, const uint32_t file, uint64_t *starting_block, uint64_t *ending_block) |
| Retrieves the block range for a specific tape file from an Aaru tape image. | |
| int32_t | aaruf_set_tape_file (void *context, const uint8_t partition, const uint32_t file, const uint64_t starting_block, const uint64_t ending_block) |
| Sets or updates the block range for a specific tape file in an Aaru tape image. | |
| int32_t | aaruf_get_tape_partition (const void *context, const uint8_t partition, uint64_t *starting_block, uint64_t *ending_block) |
| Retrieves the block range for a specific tape partition from an Aaru tape image. | |
| int32_t | aaruf_set_tape_partition (void *context, const uint8_t partition, const uint64_t starting_block, const uint64_t ending_block) |
| Sets or updates the block range for a specific tape partition in an Aaru tape image. | |
| int32_t | aaruf_get_all_tape_files (const void *context, uint8_t *buffer, size_t *length) |
| Retrieves all tape file entries from the image. | |
| int32_t | aaruf_get_all_tape_partitions (const void *context, uint8_t *buffer, size_t *length) |
| Retrieves all tape partition entries from the image. | |
| int32_t aaruf_get_all_tape_files | ( | const void * | context, |
| uint8_t * | buffer, | ||
| size_t * | length ) |
Retrieves all tape file entries from the image.
Extracts the complete set of tape file metadata entries from an Aaru tape image, returning an array of TapeFileEntry structures. Tape files represent logical file divisions on sequential access media (magnetic tapes) where data is organized into numbered files within numbered partitions. Each file entry defines a contiguous range of tape blocks (FirstBlock to LastBlock inclusive) that comprise one logical file unit on the tape medium.
Tape file organization is hierarchical:
This function is essential for applications that need to:
The function supports a two-call pattern for buffer size determination:
Alternatively, if the caller knows or pre-allocates sufficient buffer space, a single call will succeed and populate the buffer with all tape file entries.
| context | Pointer to the aaruformat context (must be a valid, opened tape image context). |
| buffer | Pointer to a buffer that will receive the array of TapeFileEntry structures. May be NULL to query the required buffer size without retrieving data. |
| length | Pointer to a size_t that serves dual purpose:
|
| AARUF_STATUS_OK | (0) Successfully retrieved all tape file entries. |
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. |
| AARUF_ERROR_TAPE_FILE_NOT_FOUND | (-19) No tape file metadata exists. |
| AARUF_ERROR_BUFFER_TOO_SMALL | (-12) The provided buffer is insufficient. |
Definition at line 1314 of file tape.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_TAPE_FILE_NOT_FOUND, AARUF_STATUS_OK, FATAL, TapeFileHashEntry::fileEntry, aaruformat_context::magic, aaruformat_context::tape_files, and TRACE.
| int32_t aaruf_get_all_tape_partitions | ( | const void * | context, |
| uint8_t * | buffer, | ||
| size_t * | length ) |
Retrieves all tape partition entries from the image.
Extracts the complete set of tape partition metadata entries from an Aaru tape image, returning an array of TapePartitionEntry structures. Tape partitions represent physical or logical divisions of sequential access media (magnetic tapes) that segment the tape into independent data regions. Each partition entry defines a contiguous range of tape blocks (FirstBlock to LastBlock inclusive) that comprise one partition on the tape medium.
Tape partitions enable:
This function is essential for applications that need to:
The function supports a two-call pattern for buffer size determination:
| context | Pointer to the aaruformat context (must be a valid, opened tape image context). |
| buffer | Pointer to a buffer that will receive the array of TapePartitionEntry structures. May be NULL to query the required buffer size without retrieving data. |
| length | Pointer to a size_t that serves dual purpose:
|
| AARUF_STATUS_OK | (0) Successfully retrieved all tape partition entries. |
| AARUF_ERROR_NOT_AARUFORMAT | (-1) The context is invalid. |
| AARUF_ERROR_TAPE_PARTITION_NOT_FOUND | (-20) No tape partition metadata exists. |
| AARUF_ERROR_BUFFER_TOO_SMALL | (-12) The provided buffer is insufficient. |
Definition at line 1416 of file tape.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_BUFFER_TOO_SMALL, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_TAPE_PARTITION_NOT_FOUND, AARUF_STATUS_OK, FATAL, aaruformat_context::magic, TapePartitionHashEntry::partitionEntry, aaruformat_context::tape_partitions, and TRACE.
| int32_t aaruf_get_tape_file | ( | const void * | context, |
| const uint8_t | partition, | ||
| const uint32_t | file, | ||
| uint64_t * | starting_block, | ||
| uint64_t * | ending_block ) |
Retrieves the block range for a specific tape file from an Aaru tape image.
Queries the tape file hash table to locate a file by its partition and file number, returning the first and last block addresses that define the file's extent on the tape medium. This function provides the core lookup mechanism for accessing logical files stored in tape images.
Tape File Identification: Each tape file is uniquely identified by a combination of:
These two values are combined into a 64-bit composite key: key = (partition << 32) | file_number
This composite key is used to perform a hash table lookup in the context's tapeFiles table, which was previously populated by process_tape_files_block() during image initialization.
Block Range Semantics: The returned block range [FirstBlock, LastBlock] is inclusive on both ends:
Block addresses are absolute positions within the tape image's logical block space, not relative to the partition or file.
Typical Usage Flow:
Error Handling: The function performs validation in the following order:
If any validation fails, an appropriate error code is returned and the output parameters (starting_block, ending_block) are left unmodified.
Thread Safety: This function performs read-only operations on the context and is safe to call from multiple threads concurrently, provided the context is not being modified by other operations (e.g., during image opening/closing).
Performance Characteristics:
| context | Pointer to an initialized aaruformat context. Must not be NULL. The context must have been successfully opened with aaruf_open() and contain a valid tape file hash table. The context is treated as const and is not modified by this operation. | |
| partition | The partition number (0-255) containing the requested file. For single-partition tapes, this is typically 0. Multi-partition tapes may have files in different partitions with potentially overlapping file numbers. | |
| file | The file number within the specified partition. File numbers are typically sequential starting from 0 or 1, but gaps may exist if files were deleted or the tape was written non-sequentially. | |
| [out] | starting_block | Pointer to receive the first block address of the file. Must not be NULL. Only modified on success. The value written represents the inclusive start of the file's block range. |
| [out] | ending_block | Pointer to receive the last block address of the file. Must not be NULL. Only modified on success. The value written represents the inclusive end of the file's block range. |
| AARUF_STATUS_OK | (0) Successfully retrieved tape file information. Both output parameters have been populated with valid block addresses. The requested partition/file combination exists in the image's file table. |
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or context validation failed. This is returned when:
|
| AARUF_ERROR_TAPE_FILE_NOT_FOUND | (-28) The requested partition/file combination does not exist in the image's tape file table. This is returned when:
|
Definition at line 569 of file tape.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_TAPE_FILE_NOT_FOUND, AARUF_STATUS_OK, FATAL, TapeFileHashEntry::fileEntry, TapeFileEntry::FirstBlock, TapeFileEntry::LastBlock, aaruformat_context::magic, aaruformat_context::tape_files, and TRACE.
| int32_t aaruf_get_tape_partition | ( | const void * | context, |
| const uint8_t | partition, | ||
| uint64_t * | starting_block, | ||
| uint64_t * | ending_block ) |
Retrieves the block range for a specific tape partition from an Aaru tape image.
Queries the tape partition hash table to locate a partition by its partition number, returning the first and last block addresses that define the partition's extent on the tape medium. This function provides the core lookup mechanism for accessing partition layout information in tape images.
Tape Partition Identification: Each tape partition is uniquely identified by its partition number (0-255). Most tapes have a single partition (partition 0), but multi-partition formats like LTO, DLT, and AIT support multiple partitions with independent block address spaces.
The partition number is used as the hash table key to perform a lookup in the context's tapePartitions table, which was previously populated by process_tape_partitions_block() during image initialization.
Block Range Semantics: The returned block range [FirstBlock, LastBlock] is inclusive on both ends:
Block addresses are local to each partition. Different partitions may have overlapping logical block numbers (e.g., both partition 0 and partition 1 can have blocks 0-1000). When accessing blocks, both the partition number and block number are required for unique identification.
Typical Usage Flow:
Error Handling: The function performs validation in the following order:
If any validation fails, an appropriate error code is returned and the output parameters (starting_block, ending_block) are left unmodified.
Thread Safety: This function performs read-only operations on the context and is safe to call from multiple threads concurrently, provided the context is not being modified by other operations (e.g., during image opening/closing).
Performance Characteristics:
Partition Layout Information: The partition metadata is essential for:
| context | Pointer to an initialized aaruformat context. Must not be NULL. The context must have been successfully opened with aaruf_open() and contain a valid tape partition hash table. The context is treated as const and is not modified by this operation. | |
| partition | The partition number (0-255) to query. For single-partition tapes, this is typically 0. Multi-partition tapes may have multiple partitions numbered sequentially from 0. | |
| [out] | starting_block | Pointer to receive the first block address of the partition. Must not be NULL. Only modified on success. The value written represents the inclusive start of the partition's block range (often 0, but format-dependent). |
| [out] | ending_block | Pointer to receive the last block address of the partition. Must not be NULL. Only modified on success. The value written represents the inclusive end of the partition's block range. |
| AARUF_STATUS_OK | (0) Successfully retrieved tape partition information. Both output parameters have been populated with valid block addresses. The requested partition exists in the image's partition table. |
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or context validation failed. This is returned when:
|
| AARUF_ERROR_TAPE_PARTITION_NOT_FOUND | (-29) The requested partition number does not exist in the image's tape partition table. This is returned when:
|
Definition at line 982 of file tape.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_TAPE_PARTITION_NOT_FOUND, AARUF_STATUS_OK, FATAL, TapePartitionEntry::FirstBlock, TapePartitionEntry::LastBlock, aaruformat_context::magic, TapePartitionHashEntry::partitionEntry, aaruformat_context::tape_partitions, and TRACE.
| int32_t aaruf_set_tape_file | ( | void * | context, |
| const uint8_t | partition, | ||
| const uint32_t | file, | ||
| const uint64_t | starting_block, | ||
| const uint64_t | ending_block ) |
Sets or updates the block range for a specific tape file in an Aaru tape image.
Creates or modifies a tape file entry in the context's hash table, defining the logical file's extent on the tape medium by its partition number, file number, and block range. This function is the write-mode counterpart to aaruf_get_tape_file() and is used when creating or modifying tape images to establish the file structure metadata.
Tape File Registration: When writing a tape image, this function should be called for each logical file to register its location. Each file is uniquely identified by:
These values are combined into a 64-bit composite key: key = (partition << 32) | file_number
The file entry (including the block range) is then stored in the context's tapeFiles hash table and will be written to the image's TapeFileBlock during finalization.
Block Range Definition: The block range [starting_block, ending_block] defines the file's extent:
Block addresses must be absolute positions within the tape image's logical block space. The caller is responsible for ensuring:
Typical Usage Flow:
Update/Replace Behavior: If a file entry with the same partition/file combination already exists:
This allows updating file metadata or correcting errors without manual deletion.
Error Handling: The function performs validation in the following order:
If any validation fails, an appropriate error code is returned and no modifications are made to the context's tape file table.
Thread Safety: This function modifies the shared context's hash table and is NOT thread-safe. Concurrent calls to aaruf_set_tape_file() or other functions that modify ctx->tapeFiles may result in data corruption or memory leaks. The caller must ensure exclusive access through external synchronization if needed.
Memory Management:
Performance Characteristics:
| context | Pointer to an initialized aaruformat context. Must not be NULL. The context must have been opened with write access (isWriting=true). The context's tapeFiles hash table will be updated with the new entry. |
| partition | The partition number (0-255) where the file is located. For single-partition tapes, this is typically 0. Multi-partition tapes can have files in different partitions with potentially overlapping file numbers. |
| file | The file number within the specified partition. File numbers are typically sequential (0, 1, 2, ...) but gaps are allowed. The same file number can exist in different partitions without conflict. |
| starting_block | The first block address of the file (inclusive). This should be the absolute block number in the image where the file's first byte begins. Must be <= ending_block (not validated). |
| ending_block | The last block address of the file (inclusive). This should be the absolute block number in the image where the file's last byte ends. Must be >= starting_block (not validated). |
| AARUF_STATUS_OK | (0) Successfully set tape file information. The hash table has been updated with the file entry. If an entry with the same partition/file combination existed, it has been replaced. The metadata will be written to the TapeFileBlock when the image is closed. |
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or context validation failed. This is returned when:
|
| AARUF_READ_ONLY | (-22) The context is not opened for writing. This is returned when ctx->isWriting is false, indicating the image was opened in read-only mode. Tape file metadata cannot be modified in read-only mode. No modifications are made to the context. |
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. The system could not allocate memory for the hash table entry (tapeFileHashEntry). This is a critical error indicating low memory conditions. No modifications are made to the context. |
Definition at line 770 of file tape.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_READ_ONLY, AARUF_STATUS_OK, FATAL, TapeFileEntry::File, TapeFileHashEntry::fileEntry, TapeFileEntry::FirstBlock, aaruformat_context::is_writing, TapeFileHashEntry::key, TapeFileEntry::LastBlock, aaruformat_context::magic, TapeFileEntry::Partition, aaruformat_context::tape_files, and TRACE.
| int32_t aaruf_set_tape_partition | ( | void * | context, |
| const uint8_t | partition, | ||
| const uint64_t | starting_block, | ||
| const uint64_t | ending_block ) |
Sets or updates the block range for a specific tape partition in an Aaru tape image.
Creates or modifies a tape partition entry in the context's hash table, defining the physical partition's extent on the tape medium by its partition number and block range. This function is the write-mode counterpart to aaruf_get_tape_partition() and is used when creating or modifying tape images to establish the partition structure metadata.
Tape Partition Registration: When writing a tape image, this function should be called for each physical partition to register its block range. Each partition is uniquely identified by its partition number (0-255), and most tapes have a single partition (partition 0), though formats like LTO, DLT, and AIT support multiple partitions.
The partition entry (including the block range) is stored in the context's tapePartitions hash table and will be written to the image's TapePartitionBlock during finalization.
Block Range Definition: The block range [starting_block, ending_block] defines the partition's extent:
Block addresses are local to each partition. The caller is responsible for ensuring:
Typical Usage Flow:
Update/Replace Behavior: If a partition entry with the same partition number already exists:
This allows updating partition metadata or correcting errors without manual deletion.
Error Handling: The function performs validation in the following order:
If any validation fails, an appropriate error code is returned and no modifications are made to the context's tape partition table.
Thread Safety: This function modifies the shared context's hash table and is NOT thread-safe. Concurrent calls to aaruf_set_tape_partition() or other functions that modify ctx->tapePartitions may result in data corruption or memory leaks. The caller must ensure exclusive access through external synchronization if needed.
Memory Management:
Performance Characteristics:
Partition Organization: Proper partition metadata is essential for:
| context | Pointer to an initialized aaruformat context. Must not be NULL. The context must have been opened with write access (isWriting=true). The context's tapePartitions hash table will be updated with the new entry. |
| partition | The partition number (0-255) to set. For single-partition tapes, this is typically 0. Multi-partition tapes use sequential numbers (0, 1, 2, ...) though the numbering scheme is format-specific. |
| starting_block | The first block address of the partition (inclusive). This defines where the partition begins in the tape's block address space. Often 0 for the first partition, but format-dependent. Must be <= ending_block (not validated). |
| ending_block | The last block address of the partition (inclusive). This defines where the partition ends in the tape's block address space. Must be >= starting_block (not validated). |
| AARUF_STATUS_OK | (0) Successfully set tape partition information. The hash table has been updated with the partition entry. If an entry with the same partition number existed, it has been replaced. The metadata will be written to the TapePartitionBlock when the image is closed. |
| AARUF_ERROR_NOT_AARUFORMAT | (-1) Invalid context or context validation failed. This is returned when:
|
| AARUF_READ_ONLY | (-22) The context is not opened for writing. This is returned when ctx->isWriting is false, indicating the image was opened in read-only mode. Tape partition metadata cannot be modified in read-only mode. No modifications are made to the context. |
| AARUF_ERROR_NOT_ENOUGH_MEMORY | (-9) Memory allocation failed. The system could not allocate memory for the hash table entry (TapePartitionHashEntry). This is a critical error indicating low memory conditions. No modifications are made to the context. |
Definition at line 1196 of file tape.c.
References AARU_CALL, AARU_EXPORT, AARU_MAGIC, AARUF_ERROR_NOT_AARUFORMAT, AARUF_ERROR_NOT_ENOUGH_MEMORY, AARUF_READ_ONLY, AARUF_STATUS_OK, FATAL, TapePartitionEntry::FirstBlock, aaruformat_context::is_writing, TapePartitionHashEntry::key, TapePartitionEntry::LastBlock, aaruformat_context::magic, TapePartitionEntry::Number, TapePartitionHashEntry::partitionEntry, aaruformat_context::tape_partitions, and TRACE.
| void process_tape_files_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a tape file metadata block from the image stream.
Reads and parses a TapeFileBlock from the Aaru image, validates its integrity, and populates the context's tape file hash table with file layout information. Each tape file entry defines a logical file on the tape medium by specifying its partition, file number, and block range (FirstBlock to LastBlock inclusive).
The function performs the following operations:
Composite Key Construction: Each tape file is uniquely identified by a 64-bit composite key: key = (partition << 32) | file_number This allows files with the same file number in different partitions to coexist in the hash table without conflicts.
Hash Table Management: The function uses HASH_REPLACE to insert entries, which automatically:
Error Handling: The function treats most errors as non-fatal and continues processing:
Block Structure: The tape file block consists of:
CRC64 Validation: The CRC64 checksum in the header is computed over the entire array of TapeFileEntry structures (excluding the header itself). This provides integrity verification to detect corruption in the file table.
Memory Management:
| ctx | Pointer to the aaruformat context. Must not be NULL. The context must have a valid imageStream open for reading. The ctx->tapeFiles hash table will be populated with file entries. The ctx->imageInfo.ImageSize will be updated with the block size. |
| entry | Pointer to the index entry describing the tape file block. Must not be NULL. The entry->offset field indicates the file position where the TapeFileHeader begins. |
Definition at line 126 of file tape.c.
References aaruf_crc64_data(), TapeFileHeader::crc64, TapeFileHeader::entries, FATAL, TapeFileHashEntry::fileEntry, TapeFileHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, TapeFileHashEntry::key, IndexEntry::offset, aaruformat_context::tape_files, TapeFileBlock, and TRACE.
Referenced by aaruf_open().
| void process_tape_partitions_block | ( | aaruformat_context * | ctx, |
| const IndexEntry * | entry ) |
Processes a tape partition metadata block from the image stream.
Reads and parses a TapePartitionBlock from the Aaru image, validates its integrity, and populates the context's tape partition hash table with partition layout information. Each tape partition entry defines a physical division of the tape medium by specifying its partition number and block range (FirstBlock to LastBlock inclusive).
The function performs the following operations:
Partition Identification: Each tape partition is uniquely identified by its partition number (0-255). This number serves as the hash table key for fast lookup operations. Most tapes have a single partition (partition 0), but multi-partition formats like LTO, DLT, and AIT support multiple partitions with independent block address spaces.
Hash Table Management: The function uses HASH_REPLACE to insert entries, which automatically:
Error Handling: The function treats most errors as non-fatal and continues processing:
Block Structure: The tape partition block consists of:
CRC64 Validation: The CRC64 checksum in the header is computed over the entire array of TapePartitionEntry structures (excluding the header itself). This provides integrity verification to detect corruption in the partition table.
Partition Block Ranges: Each partition defines a block address space:
Block addresses are local to each partition. Different partitions may have overlapping logical block numbers (e.g., both partition 0 and partition 1 can have blocks numbered 0-1000).
Memory Management:
| ctx | Pointer to the aaruformat context. Must not be NULL. The context must have a valid imageStream open for reading. The ctx->tapePartitions hash table will be populated with partition entries. The ctx->imageInfo.ImageSize will be updated with the block size. |
| entry | Pointer to the index entry describing the tape partition block. Must not be NULL. The entry->offset field indicates the file position where the TapePartitionHeader begins. |
Definition at line 346 of file tape.c.
References aaruf_crc64_data(), TapePartitionHeader::crc64, TapePartitionHeader::entries, FATAL, TapePartitionHeader::identifier, aaruformat_context::image_info, ImageInfo::ImageSize, aaruformat_context::imageStream, TapePartitionHashEntry::key, TapePartitionEntry::Number, IndexEntry::offset, TapePartitionHashEntry::partitionEntry, aaruformat_context::tape_partitions, TapePartitionBlock, and TRACE.
Referenced by aaruf_open().