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);
213 if(old_entry != NULL)
215 TRACE(
"Replaced existing tape file entry for partition %u, file %u", entries[i].Partition, entries[i].File);
219 TRACE(
"Added new tape file entry for partition %u, file %u", entries[i].Partition, entries[i].File);
349 size_t read_bytes = 0;
355 FATAL(
"Invalid context or image stream.");
363 FATAL(
"Could not seek to %" PRIu64
" as indicated by index entry...", entry->
offset);
373 TRACE(
"Could not read tape partitions header, continuing...");
379 TRACE(
"Incorrect identifier for data block at position %" PRIu64
"\n", entry->
offset);
388 FATAL(
"Could not allocate memory for tape partitions block, continuing...");
392 if(read_bytes != tape_partition_header.
entries)
395 FATAL(
"Could not read tape partitions block, continuing...");
401 if(crc64 != tape_partition_header.
crc64)
403 TRACE(
"Incorrect CRC found: 0x%" PRIx64
" found, expected 0x%" PRIx64
", continuing...", crc64,
404 tape_partition_header.
crc64);
412 for(uint32_t i = 0; i < tape_partition_header.
entries; i++)
416 if(hash_entry == NULL)
418 FATAL(
"Could not allocate memory for tape partition hash entry");
430 HASH_REPLACE(hh, ctx->
tape_partitions, key,
sizeof(uint8_t), hash_entry, old_entry);
433 if(old_entry != NULL)
435 TRACE(
"Replaced existing tape partition entry for partition %u", entries[i].Number);
439 TRACE(
"Added new tape partition entry for partition %u", entries[i].Number);
569int32_t
aaruf_get_tape_file(
const void *context,
const uint8_t partition,
const uint32_t file, uint64_t *starting_block,
570 uint64_t *ending_block)
572 TRACE(
"Entering aaruf_get_tape_file(%p, %d, %d, %llu, %llu)", context, partition, file, *starting_block,
579 FATAL(
"Invalid context");
581 TRACE(
"Exiting aaruf_get_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
590 FATAL(
"Invalid context");
592 TRACE(
"Exiting aaruf_get_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
596 uint64_t key = (uint64_t)partition << 32 | file;
598 HASH_FIND(hh, ctx->
tape_files, &key,
sizeof(uint64_t), entry);
602 TRACE(
"Tape file not found");
609 TRACE(
"Exiting aaruf_get_tape_file(%p, %d, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, file,
610 *starting_block, *ending_block);
770int32_t
aaruf_set_tape_file(
void *context,
const uint8_t partition,
const uint32_t file,
const uint64_t starting_block,
771 const uint64_t ending_block)
773 TRACE(
"Entering aaruf_set_tape_file(%p, %d, %d, %llu, %llu)", context, partition, file, starting_block,
780 FATAL(
"Invalid context");
782 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
791 FATAL(
"Invalid context");
793 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_ERROR_NOT_AARUFORMAT");
800 FATAL(
"Trying to write a read-only image");
802 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_READ_ONLY");
808 if(hash_entry == NULL)
810 FATAL(
"Could not allocate memory for tape file hash entry");
812 TRACE(
"Exiting aaruf_set_tape_file() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
817 hash_entry->
key = (uint64_t)partition << 32 | file;
827 HASH_REPLACE(hh, ctx->
tape_files, key,
sizeof(uint64_t), hash_entry, old_entry);
830 if(old_entry != NULL)
832 TRACE(
"Replaced existing tape file entry for partition %u, file %u", partition, file);
836 TRACE(
"Added new tape file entry for partition %u, file %u", partition, file);
838 TRACE(
"Exiting aaruf_set_tape_file(%p, %d, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, file,
839 starting_block, ending_block);
983 uint64_t *ending_block)
985 TRACE(
"Entering aaruf_get_tape_partition(%p, %d, %llu, %llu)", context, partition, *starting_block, *ending_block);
991 FATAL(
"Invalid context");
993 TRACE(
"Exiting aaruf_get_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1002 FATAL(
"Invalid context");
1004 TRACE(
"Exiting aaruf_get_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1008 uint8_t key = partition;
1014 TRACE(
"Tape partition not found");
1021 TRACE(
"Exiting aaruf_get_tape_partition(%p, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, *starting_block,
1197 const uint64_t ending_block)
1199 TRACE(
"Entering aaruf_set_tape_partition(%p, %d, %llu, %llu)", context, partition, starting_block, ending_block);
1205 FATAL(
"Invalid context");
1207 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1216 FATAL(
"Invalid context");
1218 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_ERROR_NOT_AARUFORMAT");
1225 FATAL(
"Trying to write a read-only image");
1227 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_READ_ONLY");
1233 if(hash_entry == NULL)
1235 FATAL(
"Could not allocate memory for tape partition hash entry");
1237 TRACE(
"Exiting aaruf_set_tape_partition() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1242 hash_entry->
key = partition;
1251 HASH_REPLACE(hh, ctx->
tape_partitions, key,
sizeof(uint8_t), hash_entry, old_entry);
1254 if(old_entry != NULL)
1256 TRACE(
"Replaced existing tape partition entry for partition %u", partition);
1260 TRACE(
"Added new tape partition entry for partition %u", partition);
1262 TRACE(
"Exiting aaruf_set_tape_partition(%p, %d, %llu, %llu) = AARUF_STATUS_OK", context, partition, starting_block,
#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.
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 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).
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_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.