129 size_t read_bytes = 0;
135 FATAL(
"Invalid context or image stream.");
143 FATAL(
"Could not seek to %" PRIu64
" as indicated by index entry...", entry->
offset);
153 TRACE(
"Could not read tape files header, continuing...");
159 TRACE(
"Incorrect identifier for data block at position %" PRIu64
"\n", entry->
offset);
168 FATAL(
"Could not allocate memory for tape files block, continuing...");
172 if(read_bytes != tape_file_header.
entries)
175 FATAL(
"Could not read tape files block, continuing...");
181 if(crc64 != tape_file_header.
crc64)
183 TRACE(
"Incorrect CRC found: 0x%" PRIx64
" found, expected 0x%" PRIx64
", continuing...", crc64,
184 tape_file_header.
crc64);
192 for(uint32_t i = 0; i < tape_file_header.
entries; i++)
196 if(hash_entry == NULL)
198 FATAL(
"Could not allocate memory for tape file hash entry");
203 hash_entry->
key = (uint64_t)entries[i].Partition << 32 | entries[i].File;
210 HASH_REPLACE(hh, ctx->
tape_files, key,
sizeof(uint64_t), hash_entry, old_entry);
214 if(old_entry != NULL)
216 TRACE(
"Replaced existing tape file entry for partition %u, file %u", entries[i].Partition, entries[i].File);
220 TRACE(
"Added new tape file entry for partition %u, file %u", entries[i].Partition, entries[i].File);
350 size_t read_bytes = 0;
356 FATAL(
"Invalid context or image stream.");
364 FATAL(
"Could not seek to %" PRIu64
" as indicated by index entry...", entry->
offset);
374 TRACE(
"Could not read tape partitions header, continuing...");
380 TRACE(
"Incorrect identifier for data block at position %" PRIu64
"\n", entry->
offset);
389 FATAL(
"Could not allocate memory for tape partitions block, continuing...");
393 if(read_bytes != tape_partition_header.
entries)
396 FATAL(
"Could not read tape partitions block, continuing...");
402 if(crc64 != tape_partition_header.
crc64)
404 TRACE(
"Incorrect CRC found: 0x%" PRIx64
" found, expected 0x%" PRIx64
", continuing...", crc64,
405 tape_partition_header.
crc64);
413 for(uint32_t i = 0; i < tape_partition_header.
entries; i++)
417 if(hash_entry == NULL)
419 FATAL(
"Could not allocate memory for tape partition hash entry");
431 HASH_REPLACE(hh, ctx->
tape_partitions, key,
sizeof(uint8_t), hash_entry, old_entry);
435 if(old_entry != NULL)
437 TRACE(
"Replaced existing tape partition entry for partition %u", entries[i].Number);
441 TRACE(
"Added new tape partition entry for partition %u", entries[i].Number);
572 uint64_t *starting_block, uint64_t *ending_block)
574 TRACE(
"Entering aaruf_get_tape_file(%p, %d, %d, %llu, %llu)", context, partition, file, *starting_block,
581 FATAL(
"Invalid context");
583 TRACE(
"Exiting aaruf_get_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
592 FATAL(
"Invalid context");
594 TRACE(
"Exiting aaruf_get_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
598 uint64_t key = (uint64_t)partition << 32 | file;
600 HASH_FIND(hh, ctx->
tape_files, &key,
sizeof(uint64_t), entry);
604 TRACE(
"Tape file not found");
611 TRACE(
"Exiting aaruf_get_tape_file(%p, %d, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, file,
612 *starting_block, *ending_block);
773 const uint64_t starting_block,
const uint64_t ending_block)
775 TRACE(
"Entering aaruf_set_tape_file(%p, %d, %d, %llu, %llu)", context, partition, file, starting_block,
782 FATAL(
"Invalid context");
784 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
793 FATAL(
"Invalid context");
795 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
802 FATAL(
"Trying to write a read-only image");
804 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_READ_ONLY");
810 if(hash_entry == NULL)
812 FATAL(
"Could not allocate memory for tape file hash entry");
814 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
819 hash_entry->
key = (uint64_t)partition << 32 | file;
829 HASH_REPLACE(hh, ctx->
tape_files, key,
sizeof(uint64_t), hash_entry, old_entry);
833 if(old_entry != NULL)
835 TRACE(
"Replaced existing tape file entry for partition %u, file %u", partition, file);
839 TRACE(
"Added new tape file entry for partition %u, file %u", partition, file);
841 TRACE(
"Exiting aaruf_set_tape_file(%p, %d, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, file,
842 starting_block, ending_block);
986 uint64_t *starting_block, uint64_t *ending_block)
988 TRACE(
"Entering aaruf_get_tape_partition(%p, %d, %llu, %llu)", context, partition, *starting_block, *ending_block);
994 FATAL(
"Invalid context");
996 TRACE(
"Exiting aaruf_get_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1005 FATAL(
"Invalid context");
1007 TRACE(
"Exiting aaruf_get_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1011 uint8_t key = partition;
1017 TRACE(
"Tape partition not found");
1024 TRACE(
"Exiting aaruf_get_tape_partition(%p, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, *starting_block,
1200 const uint64_t starting_block,
const uint64_t ending_block)
1202 TRACE(
"Entering aaruf_set_tape_partition(%p, %d, %llu, %llu)", context, partition, starting_block, ending_block);
1208 FATAL(
"Invalid context");
1210 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1219 FATAL(
"Invalid context");
1221 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1228 FATAL(
"Trying to write a read-only image");
1230 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_READ_ONLY");
1236 if(hash_entry == NULL)
1238 FATAL(
"Could not allocate memory for tape partition hash entry");
1240 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1245 hash_entry->
key = partition;
1254 HASH_REPLACE(hh, ctx->
tape_partitions, key,
sizeof(uint8_t), hash_entry, old_entry);
1258 if(old_entry != NULL)
1260 TRACE(
"Replaced existing tape partition entry for partition %u", partition);
1264 TRACE(
"Added new tape partition entry for partition %u", partition);
1266 TRACE(
"Exiting aaruf_set_tape_partition(%p, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, starting_block,
1320 TRACE(
"Entering aaruf_get_all_tape_files(%p, %p, %zu)", context, buffer, (length ? *length : 0));
1325 FATAL(
"Invalid context");
1326 TRACE(
"Exiting aaruf_get_all_tape_files() = AARUF_ERROR_NOT_AARUFORMAT");
1335 FATAL(
"Invalid context");
1336 TRACE(
"Exiting aaruf_get_all_tape_files() = AARUF_ERROR_NOT_AARUFORMAT");
1342 FATAL(
"Image contains no tape files");
1343 TRACE(
"Exiting aaruf_get_all_tape_files() = AARUF_ERROR_TAPE_FILE_NOT_FOUND");
1348 const size_t count = HASH_COUNT(ctx->
tape_files);
1351 if(buffer == NULL || length == NULL || *length < required_size)
1353 if(length) *length = required_size;
1354 TRACE(
"Buffer too small for tape files, required %zu bytes", required_size);
1355 TRACE(
"Exiting aaruf_get_all_tape_files() = AARUF_ERROR_BUFFER_TOO_SMALL");
1370 *length = required_size;
1372 TRACE(
"Exiting aaruf_get_all_tape_files(%p, %p, %zu) = AARUF_STATUS_OK", context, buffer, *length);
1422 TRACE(
"Entering aaruf_get_all_tape_partitions(%p, %p, %zu)", context, buffer, (length ? *length : 0));
1427 FATAL(
"Invalid context");
1428 TRACE(
"Exiting aaruf_get_all_tape_partitions() = AARUF_ERROR_NOT_AARUFORMAT");
1437 FATAL(
"Invalid context");
1438 TRACE(
"Exiting aaruf_get_all_tape_partitions() = AARUF_ERROR_NOT_AARUFORMAT");
1444 FATAL(
"Image contains no tape partitions");
1445 TRACE(
"Exiting aaruf_get_all_tape_partitions() = AARUF_ERROR_TAPE_PARTITION_NOT_FOUND");
1453 if(buffer == NULL || length == NULL || *length < required_size)
1455 if(length) *length = required_size;
1456 TRACE(
"Buffer too small for tape partitions, required %zu bytes", required_size);
1457 TRACE(
"Exiting aaruf_get_all_tape_partitions() = AARUF_ERROR_BUFFER_TOO_SMALL");
1472 *length = required_size;
1474 TRACE(
"Exiting aaruf_get_all_tape_partitions(%p, %p, %zu) = AARUF_STATUS_OK", context, buffer, *length);
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
struct TapeFileHashEntry tapeFileHashEntry
uint64_t aaruf_crc64_data(const uint8_t *data, uint32_t len)
@ TapePartitionBlock
Block containing list of partitions for a tape image.
@ TapeFileBlock
Block containing list of files for a tape image.
#define AARUF_ERROR_TAPE_PARTITION_NOT_FOUND
Requested tape partition not present in image.
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
#define AARUF_READ_ONLY
Operation requires write mode but context is read-only.
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
#define AARUF_ERROR_TAPE_FILE_NOT_FOUND
Requested tape file number not present in image.
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
#define AARUF_ERROR_BUFFER_TOO_SMALL
Caller-supplied buffer insufficient for data.
uint64_t ImageSize
Size of the image payload in bytes (excludes headers/metadata)
Single index entry describing a block's type, (optional) data classification, and file offset.
uint64_t offset
Absolute byte offset in the image where the referenced block header begins.
Describes a single logical file on a tape medium.
uint32_t File
File number (unique within the partition).
uint64_t LastBlock
Last block of the file (inclusive).
uint64_t FirstBlock
First block of the file (inclusive).
uint8_t Partition
Partition number containing this file.
uint64_t key
Composite key: partition << 32 | file.
TapeFileEntry fileEntry
The actual tape file data.
Describes a single physical partition on a tape medium.
uint64_t LastBlock
Last block in the partition (inclusive).
uint64_t FirstBlock
First block in the partition (inclusive).
uint8_t Number
Partition number (unique identifier for this partition).
uint8_t key
Key: partition.
TapePartitionEntry partitionEntry
The actual tape partition data.
Master context representing an open or in‑creation Aaru image.
tapeFileHashEntry * tape_files
Hash table root for tape files.
bool dirty_tape_partition_block
True if tape partition block should be written during close.
bool is_writing
True if context opened/created for writing.
uint64_t magic
File magic (AARU_MAGIC) post-open.
FILE * imageStream
Underlying FILE* stream (binary mode).
bool dirty_tape_file_block
True if tape file block should be written during close.
ImageInfo image_info
Exposed high-level image info summary.
TapePartitionHashEntry * tape_partitions
Hash table root for tape partitions.
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_all_tape_partitions(const void *context, uint8_t *buffer, size_t *length)
Retrieves all tape partition entries from the image.
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.
void process_tape_files_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a tape file metadata block from the image stream.
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.
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_all_tape_files(const void *context, uint8_t *buffer, size_t *length)
Retrieves all tape file entries from the image.