81 bool has_cached_secondary_ddt =
86 TRACE(
"Writing cached secondary DDT table to file");
93 if(end_of_file & alignment_mask)
96 uint64_t aligned_position = end_of_file + alignment_mask & ~alignment_mask;
99 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
100 end_of_file = aligned_position;
102 TRACE(
"Aligned DDT write position from %ld to %" PRIu64
" (alignment shift: %d)",
103 ftell(ctx->
imageStream) - (aligned_position - end_of_file), aligned_position,
122 ddt_header.
blocks = items_per_ddt_entry;
123 ddt_header.
entries = items_per_ddt_entry;
127 ddt_header.
length = items_per_ddt_entry *
sizeof(uint64_t);
131 if(crc64_context != NULL)
137 ddt_header.
crc64 = crc64;
143 uint8_t *buffer = NULL;
153 buffer = malloc((
size_t)ddt_header.
length * 2);
156 TRACE(
"Failed to allocate memory for secondary DDT v2 compression");
160 size_t dst_size = (size_t)ddt_header.
length * 2 * 2;
167 ddt_header.
cmpLength = (uint32_t)dst_size;
196 const uint64_t new_secondary_table_block_offset =
202 TRACE(
"Updating index for cached secondary DDT");
211 for(
unsigned int k = 0; k < utarray_len(ctx->
index_entries); k++)
218 TRACE(
"Found old DDT index entry at position %u, removing", k);
229 new_ddt_entry.
offset = end_of_file;
233 TRACE(
"Added new DDT index entry at offset %" PRIu64, end_of_file);
241 size_t primary_written_bytes = 0;
244 if(primary_written_bytes != 1)
246 TRACE(
"Could not flush primary DDT table to file.");
253 TRACE(
"Failed to write cached secondary DDT data");
256 TRACE(
"Failed to write cached secondary DDT header");
293 TRACE(
"Writing cached primary DDT table back to file");
297 if(crc64_context != NULL)
317 TRACE(
"Calculated CRC64 for primary DDT: 0x%16lX", crc64);
327 if(headerWritten != 1)
329 TRACE(
"Failed to write primary DDT header to file");
337 size_t written_bytes = 0;
340 if(written_bytes == 1)
342 TRACE(
"Successfully wrote primary DDT header and table to file (%" PRIu64
" entries, %zu bytes)",
346 TRACE(
"Removing any previously existing primary DDT index entries");
347 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
352 TRACE(
"Found existing primary DDT index entry at position %d, removing", k);
358 TRACE(
"Adding primary DDT to index");
369 TRACE(
"Failed to write primary DDT table to file");
395 TRACE(
"Writing single-level DDT table to file");
416 uint8_t *cmp_buffer = NULL;
428 if(cmp_buffer == NULL)
430 TRACE(
"Failed to allocate memory for secondary DDT v2 compression");
467 if(ddt_position & alignment_mask)
469 const uint64_t aligned_position = ddt_position + alignment_mask & ~alignment_mask;
470 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
471 ddt_position = aligned_position;
475 if(header_written != 1)
477 TRACE(
"Failed to write single-level DDT header to file");
482 size_t written_bytes = 0;
488 if(written_bytes == 1)
490 TRACE(
"Successfully wrote single-level DDT header and table to file (%" PRIu64
491 " entries, %zu bytes, %zu compressed bytes)",
495 TRACE(
"Removing any previously existing single-level DDT index entries");
496 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
501 TRACE(
"Found existing single-level DDT index entry at position %d, removing", k);
507 TRACE(
"Adding single-level DDT to index");
511 single_ddt_entry.
offset = ddt_position;
515 TRACE(
"Added single-level DDT index entry at offset %" PRIu64, ddt_position);
518 TRACE(
"Failed to write single-level DDT table data to file");
638 uint64_t max_key = 0;
640 HASH_ITER(hh, ctx->
tape_ddt, entry, tmp)
641 if(entry->
key > max_key) max_key = entry->
key;
663 TRACE(
"Failed to allocate memory for tape DDT table");
668 HASH_ITER(hh, ctx->
tape_ddt, entry, tmp)
693 uint64_t alignment_mask;
694 uint64_t aligned_position;
730 if(!has_checksums)
return;
739 if(checksum_position & alignment_mask)
741 aligned_position = checksum_position + alignment_mask & ~alignment_mask;
742 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
743 checksum_position = aligned_position;
747 fseek(ctx->
imageStream,
sizeof(checksum_header), SEEK_CUR);
751 TRACE(
"Writing MD5 checksum entry");
763 TRACE(
"Writing SHA1 checksum entry");
775 TRACE(
"Writing SHA256 checksum entry");
787 TRACE(
"Writing SpamSum checksum entry");
799 TRACE(
"Writing BLAKE3 checksum entry");
801 blake3_entry.
length = BLAKE3_OUT_LEN;
810 fseek(ctx->
imageStream, checksum_position, SEEK_SET);
811 TRACE(
"Writing checksum header");
815 TRACE(
"Removing any previously existing checksum block index entries");
816 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
821 TRACE(
"Found existing checksum block index entry at position %d, removing", k);
827 TRACE(
"Adding checksum block to index");
831 checksum_index_entry.
offset = checksum_position;
833 utarray_push_back(ctx->
index_entries, &checksum_index_entry);
835 TRACE(
"Added checksum block index entry at offset %" PRIu64, checksum_position);
857 if(tracks_position & alignment_mask)
859 uint64_t aligned_position = tracks_position + alignment_mask & ~alignment_mask;
860 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
861 tracks_position = aligned_position;
864 TRACE(
"Writing tracks block at position %ld", tracks_position);
869 size_t written_entries =
877 TRACE(
"Removing any previously existing tracks block index entries");
878 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
883 TRACE(
"Found existing tracks block index entry at position %d, removing", k);
889 TRACE(
"Adding tracks block to index");
894 tracks_index_entry.
offset = tracks_position;
897 TRACE(
"Added tracks block index entry at offset %" PRIu64, tracks_position);
920 long mode2_subheaders_position = ftell(ctx->
imageStream);
923 if(mode2_subheaders_position & alignment_mask)
925 uint64_t aligned_position = mode2_subheaders_position + alignment_mask & ~alignment_mask;
926 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
927 mode2_subheaders_position = aligned_position;
930 TRACE(
"Writing MODE 2 subheaders block at position %ld", mode2_subheaders_position);
942 uint8_t *buffer = NULL;
952 buffer = malloc((
size_t)subheaders_block.
length * 2);
955 TRACE(
"Failed to allocate memory for MODE 2 subheaders compression");
959 size_t dst_size = (size_t)subheaders_block.
length * 2 * 2;
964 subheaders_block.
cmpLength = (uint32_t)dst_size;
982 const size_t length_to_write = subheaders_block.
cmpLength;
991 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
992 if(written_bytes == 1)
994 TRACE(
"Successfully wrote MODE 2 subheaders block (%" PRIu64
" bytes)", subheaders_block.
cmpLength);
997 TRACE(
"Removing any previously existing MODE 2 subheaders block index entries");
998 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
1003 TRACE(
"Found existing MODE 2 subheaders block index entry at position %d, removing", k);
1009 TRACE(
"Adding MODE 2 subheaders block to index");
1013 mode2_subheaders_index_entry.
offset = mode2_subheaders_position;
1014 utarray_push_back(ctx->
index_entries, &mode2_subheaders_index_entry);
1016 TRACE(
"Added MODE 2 subheaders block index entry at offset %" PRIu64, mode2_subheaders_position);
1053 if(prefix_position & alignment_mask)
1055 uint64_t aligned_position = prefix_position + alignment_mask & ~alignment_mask;
1056 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
1057 prefix_position = aligned_position;
1060 TRACE(
"Writing sector prefix block at position %ld", prefix_position);
1070 uint8_t *buffer = NULL;
1080 buffer = malloc((
size_t)prefix_block.
length * 2);
1083 TRACE(
"Failed to allocate memory for CD sector prefix compression");
1087 size_t dst_size = (size_t)prefix_block.
length * 2 * 2;
1092 prefix_block.
cmpLength = (uint32_t)dst_size;
1110 const size_t length_to_write = prefix_block.
cmpLength;
1119 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
1120 if(written_bytes == 1)
1122 TRACE(
"Successfully wrote CD sector prefix block (%" PRIu64
" bytes)", prefix_block.
cmpLength);
1125 TRACE(
"Removing any previously existing CD sector prefix block index entries");
1126 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
1131 TRACE(
"Found existing CD sector prefix block index entry at position %d, removing", k);
1137 TRACE(
"Adding CD sector prefix block to index");
1141 prefix_index_entry.
offset = prefix_position;
1144 TRACE(
"Added CD sector prefix block index entry at offset %" PRIu64, prefix_position);
1190 if(suffix_position & alignment_mask)
1192 const uint64_t aligned_position = suffix_position + alignment_mask & ~alignment_mask;
1193 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
1194 suffix_position = aligned_position;
1197 TRACE(
"Writing sector suffix block at position %ld", suffix_position);
1207 uint8_t *buffer = NULL;
1217 buffer = malloc((
size_t)suffix_block.
length * 2);
1220 TRACE(
"Failed to allocate memory for CD sector suffix compression");
1224 size_t dst_size = (size_t)suffix_block.
length * 2 * 2;
1229 suffix_block.
cmpLength = (uint32_t)dst_size;
1247 const size_t length_to_write = suffix_block.
cmpLength;
1256 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
1257 if(written_bytes == 1)
1259 TRACE(
"Successfully wrote CD sector suffix block (%" PRIu64
" bytes)", suffix_block.
cmpLength);
1262 TRACE(
"Removing any previously existing CD sector suffix block index entries");
1263 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
1268 TRACE(
"Found existing CD sector suffix block index entry at position %d, removing", k);
1274 TRACE(
"Adding CD sector suffix block to index");
1278 suffix_index_entry.
offset = suffix_position;
1281 TRACE(
"Added CD sector suffix block index entry at offset %" PRIu64, suffix_position);
1320 long prefix_ddt_position = ftell(ctx->
imageStream);
1323 if(prefix_ddt_position & alignment_mask)
1325 const uint64_t aligned_position = prefix_ddt_position + alignment_mask & ~alignment_mask;
1326 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
1327 prefix_ddt_position = aligned_position;
1330 TRACE(
"Writing sector prefix DDT v2 at position %ld", prefix_ddt_position);
1345 ddt_header2.
start = 0;
1346 ddt_header2.
length = ddt_header2.
entries *
sizeof(uint64_t);
1350 uint8_t *buffer = NULL;
1360 buffer = malloc((
size_t)ddt_header2.
length * 2);
1363 TRACE(
"Failed to allocate memory for sector prefix DDT v2 compression");
1367 size_t dst_size = (size_t)ddt_header2.
length * 2 * 2;
1370 lzma_properties, &props_size, 9, ctx->
lzma_dict_size, 4, 0, 2, 273, 8);
1372 ddt_header2.
cmpLength = (uint32_t)dst_size;
1390 const size_t length_to_write = ddt_header2.
cmpLength;
1399 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
1400 if(written_bytes == 1)
1402 TRACE(
"Successfully wrote sector prefix DDT v2 (%" PRIu64
" bytes)", ddt_header2.
cmpLength);
1405 TRACE(
"Removing any previously existing sector prefix DDT v2 index entries");
1406 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
1411 TRACE(
"Found existing sector prefix DDT v2 index entry at position %d, removing", k);
1417 TRACE(
"Adding sector prefix DDT v2 to index");
1421 prefix_ddt_index_entry.
offset = prefix_ddt_position;
1422 utarray_push_back(ctx->
index_entries, &prefix_ddt_index_entry);
1424 TRACE(
"Added sector prefix DDT v2 index entry at offset %" PRIu64, prefix_ddt_position);
1479 long suffix_ddt_position = ftell(ctx->
imageStream);
1482 if(suffix_ddt_position & alignment_mask)
1484 const uint64_t aligned_position = suffix_ddt_position + alignment_mask & ~alignment_mask;
1485 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
1486 suffix_ddt_position = aligned_position;
1489 TRACE(
"Writing sector suffix DDT v2 at position %ld", suffix_ddt_position);
1504 ddt_header2.
start = 0;
1505 ddt_header2.
length = ddt_header2.
entries *
sizeof(uint64_t);
1509 uint8_t *buffer = NULL;
1519 buffer = malloc((
size_t)ddt_header2.
length * 2);
1522 TRACE(
"Failed to allocate memory for sector suffix DDT v2 compression");
1526 size_t dst_size = (size_t)ddt_header2.
length * 2 * 2;
1529 lzma_properties, &props_size, 9, ctx->
lzma_dict_size, 4, 0, 2, 273, 8);
1531 ddt_header2.
cmpLength = (uint32_t)dst_size;
1549 const size_t length_to_write = ddt_header2.
cmpLength;
1558 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
1559 if(written_bytes == 1)
1561 TRACE(
"Successfully wrote sector suffix DDT v2 (%" PRIu64
" bytes)", ddt_header2.
cmpLength);
1564 TRACE(
"Removing any previously existing sector suffix DDT v2 block index entries");
1565 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
1570 TRACE(
"Found existing sector suffix DDT v2 index entry at position %d, removing", k);
1576 TRACE(
"Adding sector suffix DDT v2 to index");
1580 suffix_ddt_index_entry.
offset = suffix_ddt_position;
1581 utarray_push_back(ctx->
index_entries, &suffix_ddt_index_entry);
1583 TRACE(
"Added sector suffix DDT v2 index entry at offset %" PRIu64, suffix_ddt_position);
1655 if(block_position & alignment_mask)
1657 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
1658 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
1659 block_position = aligned_position;
1662 TRACE(
"Writing sector subchannel block at position %ld", block_position);
1668 bool owns_buffer =
false;
1681 uint8_t *cst_buffer = malloc(subchannel_block.
length);
1683 if(cst_buffer == NULL)
1685 TRACE(
"Failed to allocate memory for Claunia Subchannel Transform output");
1689 uint8_t *dst_buffer = malloc(subchannel_block.
length);
1691 if(dst_buffer == NULL)
1693 TRACE(
"Failed to allocate memory for LZMA output");
1699 size_t dst_size = subchannel_block.
length;
1707 if(dst_size < subchannel_block.
length)
1710 subchannel_block.
cmpLength = (uint32_t)dst_size;
1711 buffer = dst_buffer;
1741 TRACE(
"Incorrect media type, not writing sector subchannel block");
1747 uint8_t *dst_buffer = malloc(subchannel_block.
length);
1749 if(dst_buffer == NULL)
1751 TRACE(
"Failed to allocate memory for LZMA output");
1755 size_t dst_size = subchannel_block.
length;
1759 lzma_properties, &props_size, 9, ctx->
lzma_dict_size, 4, 0, 2, 273, 8);
1761 if(dst_size < subchannel_block.
length)
1763 subchannel_block.
cmpLength = (uint32_t)dst_size;
1764 buffer = dst_buffer;
1776 TRACE(
"Incorrect media type, not writing sector subchannel block");
1787 const size_t length_to_write = subchannel_block.
cmpLength;
1796 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
1797 if(written_bytes == 1)
1799 TRACE(
"Successfully wrote sector subchannel block (%" PRIu64
" bytes)", subchannel_block.
cmpLength);
1802 TRACE(
"Removing any previously existing subchannel block index entries");
1803 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
1808 TRACE(
"Found existing subchannel block index entry at position %d, removing", k);
1814 TRACE(
"Adding sector subchannel block to index");
1817 subchannel_index_entry.
dataType = subchannel_block.
type;
1818 subchannel_index_entry.
offset = block_position;
1819 utarray_push_back(ctx->
index_entries, &subchannel_index_entry);
1821 TRACE(
"Added sector subchannel block index entry at offset %" PRIu64, block_position);
1825 if(owns_buffer) free(buffer);
1969 uint64_t total_sectors =
1976 if(id_position & alignment_mask)
1978 const uint64_t aligned_position = id_position + alignment_mask & ~alignment_mask;
1979 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
1980 id_position = aligned_position;
1982 TRACE(
"Writing DVD sector ID block at position %ld", id_position);
1987 id_block.
length = (uint32_t)total_sectors * 4;
1992 uint8_t *buffer = NULL;
2002 buffer = malloc((
size_t)id_block.
length * 2);
2005 TRACE(
"Failed to allocate memory for DVD sector ID compression");
2009 size_t dst_size = (size_t)id_block.
length * 2 * 2;
2014 id_block.
cmpLength = (uint32_t)dst_size;
2032 size_t length_to_write = id_block.
cmpLength;
2041 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
2042 if(written_bytes == 1)
2044 TRACE(
"Successfully wrote DVD sector ID block (%" PRIu64
" bytes)", id_block.
cmpLength);
2047 TRACE(
"Removing any previously existing DVD sector ID block index entries");
2048 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2053 TRACE(
"Found existing DVD sector ID block index entry at position %d, removing", k);
2059 TRACE(
"Adding DVD sector ID block to index");
2063 id_index_entry.
offset = id_position;
2066 TRACE(
"Added DVD sector ID block index entry at offset %" PRIu64, id_position);
2075 if(ied_position & alignment_mask)
2077 const uint64_t aligned_position = ied_position + alignment_mask & ~alignment_mask;
2078 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
2079 ied_position = aligned_position;
2081 TRACE(
"Writing DVD sector IED block at position %ld", ied_position);
2086 ied_block.
length = (uint32_t)total_sectors * 2;
2099 buffer = malloc((
size_t)ied_block.
length * 2);
2102 TRACE(
"Failed to allocate memory for DVD sector IED compression");
2106 size_t dst_size = (size_t)ied_block.
length * 2 * 2;
2111 ied_block.
cmpLength = (uint32_t)dst_size;
2138 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
2139 if(written_bytes == 1)
2141 TRACE(
"Successfully wrote DVD sector IED block (%" PRIu64
" bytes)", ied_block.
cmpLength);
2144 TRACE(
"Removing any previously existing DVD sector IED block index entries");
2145 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2150 TRACE(
"Found existing DVD sector IED block index entry at position %d, removing", k);
2156 TRACE(
"Adding DVD sector IED block to index");
2160 ied_index_entry.
offset = ied_position;
2163 TRACE(
"Added DVD sector IED block index entry at offset %" PRIu64, ied_position);
2172 if(cpr_mai_position & alignment_mask)
2174 const uint64_t aligned_position = cpr_mai_position + alignment_mask & ~alignment_mask;
2175 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
2176 cpr_mai_position = aligned_position;
2178 TRACE(
"Writing DVD sector CPR/MAI block at position %ld", cpr_mai_position);
2183 cpr_mai_block.
length = (uint32_t)total_sectors * 6;
2196 buffer = malloc((
size_t)cpr_mai_block.
length * 2);
2199 TRACE(
"Failed to allocate memory for DVD sector CPR/MAI compression");
2203 size_t dst_size = (size_t)cpr_mai_block.
length * 2 * 2;
2208 cpr_mai_block.
cmpLength = (uint32_t)dst_size;
2226 length_to_write = cpr_mai_block.
cmpLength;
2235 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
2236 if(written_bytes == 1)
2238 TRACE(
"Successfully wrote DVD sector CPR/MAI block (%" PRIu64
" bytes)", cpr_mai_block.
cmpLength);
2241 TRACE(
"Removing any previously existing DVD sector CPR/MAI block index entries");
2242 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2247 TRACE(
"Found existing DVD sector CPR/MAI block index entry at position %d, removing", k);
2253 TRACE(
"Adding DVD sector CPR/MAI block to index");
2257 cpr_mai_index_entry.
offset = cpr_mai_position;
2258 utarray_push_back(ctx->
index_entries, &cpr_mai_index_entry);
2260 TRACE(
"Added DVD sector CPR/MAI block index entry at offset %" PRIu64, cpr_mai_position);
2269 if(edc_position & alignment_mask)
2271 const uint64_t aligned_position = edc_position + alignment_mask & ~alignment_mask;
2272 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
2273 edc_position = aligned_position;
2275 TRACE(
"Writing DVD sector EDC block at position %ld", edc_position);
2280 edc_block.
length = (uint32_t)total_sectors * 4;
2293 buffer = malloc((
size_t)edc_block.
length * 2);
2296 TRACE(
"Failed to allocate memory for DVD sector EDC compression");
2300 size_t dst_size = (size_t)edc_block.
length * 2 * 2;
2305 edc_block.
cmpLength = (uint32_t)dst_size;
2332 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
2333 if(written_bytes == 1)
2335 TRACE(
"Successfully wrote DVD sector EDC block (%" PRIu64
" bytes)", edc_block.
cmpLength);
2338 TRACE(
"Removing any previously existing DVD sector EDC block index entries");
2339 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2344 TRACE(
"Found existing DVD sector EDC block index entry at position %d, removing", k);
2350 TRACE(
"Adding DVD sector EDC block to index");
2354 edc_index_entry.
offset = edc_position;
2357 TRACE(
"Added DVD sector EDC block index entry at offset %" PRIu64, edc_position);
2468 if(block_position & alignment_mask)
2470 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
2471 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
2472 block_position = aligned_position;
2474 TRACE(
"Writing DVD decrypted title key block at position %ld", block_position);
2479 decrypted_title_key_block.
length =
2483 decrypted_title_key_block.
crc64 =
2486 uint8_t *buffer = NULL;
2492 decrypted_title_key_block.
cmpCrc64 = decrypted_title_key_block.
crc64;
2496 buffer = malloc((
size_t)decrypted_title_key_block.
length * 2);
2499 TRACE(
"Failed to allocate memory for DVD decrypted title key compression");
2503 size_t dst_size = (size_t)decrypted_title_key_block.
length * 2 * 2;
2506 lzma_properties, &props_size, 9, ctx->
lzma_dict_size, 4, 0, 2, 273, 8);
2508 decrypted_title_key_block.
cmpLength = (uint32_t)dst_size;
2510 if(decrypted_title_key_block.
cmpLength >= decrypted_title_key_block.
length)
2520 decrypted_title_key_block.
cmpLength = decrypted_title_key_block.
length;
2521 decrypted_title_key_block.
cmpCrc64 = decrypted_title_key_block.
crc64;
2526 const size_t length_to_write = decrypted_title_key_block.
cmpLength;
2536 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
2537 if(written_bytes == 1)
2539 TRACE(
"Successfully wrote DVD decrypted title key block (%" PRIu64
" bytes)",
2543 TRACE(
"Removing any previously existing DVD decrypted title key block index entries");
2544 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2549 TRACE(
"Found existing DVD decrypted title key block index entry at position %d, removing", k);
2555 TRACE(
"Adding DVD decrypted title key block to index");
2559 decrypted_title_key_index_entry.
offset = block_position;
2560 utarray_push_back(ctx->
index_entries, &decrypted_title_key_index_entry);
2562 TRACE(
"Added DVD decrypted title key block index entry at offset %" PRIu64, block_position);
2647 HASH_ITER(hh, ctx->
mediaTags, media_tag, tmp_media_tag)
2652 if(tag_position & alignment_mask)
2654 const uint64_t aligned_position = tag_position + alignment_mask & ~alignment_mask;
2655 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
2656 tag_position = aligned_position;
2670 uint8_t *buffer = NULL;
2675 buffer = media_tag->
data;
2680 buffer = malloc((
size_t)tag_block.
length * 2);
2683 TRACE(
"Failed to allocate memory for media tag compression");
2687 size_t dst_size = (size_t)tag_block.
length * 2 * 2;
2692 tag_block.
cmpLength = (uint32_t)dst_size;
2698 buffer = media_tag->
data;
2710 const size_t length_to_write = tag_block.
cmpLength;
2719 const size_t written_bytes = fwrite(buffer, length_to_write, 1, ctx->
imageStream);
2720 if(written_bytes == 1)
2722 TRACE(
"Successfully wrote media tag block type %d (%" PRIu64
" bytes)", tag_block.
type,
2726 TRACE(
"Removing any previously existing media tag type %d block index entries", tag_block.
type);
2727 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2732 TRACE(
"Found existing media tag type %d block index entry at position %d, removing",
2739 TRACE(
"Adding media tag type %d block to index", tag_block.
type);
2743 tag_index_entry.
offset = tag_position;
2746 TRACE(
"Added media tag block type %d index entry at offset %" PRIu64, tag_block.
type, tag_position);
2923 size_t tape_file_count = 0;
2924 HASH_ITER(hh, ctx->
tape_files, tape_file, tmp_tape_file) tape_file_count++;
2927 const size_t buffer_size = tape_file_count *
sizeof(
TapeFileEntry);
2931 TRACE(
"Failed to allocate memory for tape file entries");
2934 memset(buffer, 0, buffer_size);
2936 HASH_ITER(hh, ctx->
tape_files, tape_file, tmp_tape_file)
2938 if(index >= tape_file_count)
break;
2946 tape_file_block.
length = (uint32_t)buffer_size;
2953 if(block_position & alignment_mask)
2955 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
2956 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
2957 block_position = aligned_position;
2959 TRACE(
"Writing tape file block at position %ld", block_position);
2962 const size_t written_bytes = fwrite(buffer, tape_file_block.
length, 1, ctx->
imageStream);
2963 if(written_bytes == 1)
2965 TRACE(
"Successfully wrote tape file block (%" PRIu64
" bytes)", tape_file_block.
length);
2968 TRACE(
"Removing any previously existing tape file block index entries");
2969 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
2974 TRACE(
"Found existing tape file block index entry at position %d, removing", k);
2980 TRACE(
"Adding tape file block to index");
2984 index_entry.
offset = block_position;
2987 TRACE(
"Added tape file block index entry at offset %" PRIu64, block_position);
3169 size_t tape_partition_count = 0;
3170 HASH_ITER(hh, ctx->
tape_partitions, tape_partition, tmp_tape_partition) tape_partition_count++;
3177 TRACE(
"Failed to allocate memory for tape partition entries");
3180 memset(buffer, 0, buffer_size);
3182 HASH_ITER(hh, ctx->
tape_partitions, tape_partition, tmp_tape_partition)
3184 if(index >= tape_partition_count)
break;
3192 tape_partition_block.
length = (uint32_t)buffer_size;
3199 if(block_position & alignment_mask)
3201 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
3202 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
3203 block_position = aligned_position;
3205 TRACE(
"Writing tape partition block at position %ld", block_position);
3208 const size_t written_bytes = fwrite(buffer, tape_partition_block.
length, 1, ctx->
imageStream);
3209 if(written_bytes == 1)
3211 TRACE(
"Successfully wrote tape partition block (%" PRIu64
" bytes)", tape_partition_block.
length);
3214 TRACE(
"Removing any previously existing tape partition block index entries");
3215 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
3220 TRACE(
"Found existing tape partition block index entry at position %d, removing", k);
3226 TRACE(
"Adding tape partition block to index");
3230 index_entry.
offset = block_position;
3233 TRACE(
"Added tape partition block index entry at offset %" PRIu64, block_position);
3308 if(block_position & alignment_mask)
3310 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
3311 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
3312 block_position = aligned_position;
3315 TRACE(
"Writing geometry block at position %ld", block_position);
3320 TRACE(
"Successfully wrote geometry block");
3323 TRACE(
"Removing any previously existing geometry block index entries");
3324 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
3329 TRACE(
"Found existing geometry block index entry at position %d, removing", k);
3335 TRACE(
"Adding geometry block to index");
3339 index_entry.
offset = block_position;
3342 TRACE(
"Added geometry block index entry at offset %" PRIu64, block_position);
3474 if(buffer == NULL)
return;
3562 if(block_position & alignment_mask)
3564 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
3565 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
3566 block_position = aligned_position;
3571 TRACE(
"Writing metadata block at position %ld", block_position);
3575 TRACE(
"Successfully wrote metadata block");
3578 TRACE(
"Removing any previously existing metadata block index entries");
3579 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
3584 TRACE(
"Found existing metadata block index entry at position %d, removing", k);
3590 TRACE(
"Adding metadata block to index");
3594 index_entry.
offset = block_position;
3597 TRACE(
"Added metadata block index entry at offset %" PRIu64, block_position);
3757 uint8_t *buffer = calloc(1, required_length);
3759 if(buffer == NULL)
return;
3776 if(offset + entry_size > required_length)
3778 FATAL(
"Calculated size exceeds provided buffer length");
3860 if(block_position & alignment_mask)
3862 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
3863 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
3864 block_position = aligned_position;
3866 TRACE(
"Writing dump hardware block at position %ld", block_position);
3867 if(fwrite(buffer, required_length, 1, ctx->
imageStream) == 1)
3869 TRACE(
"Successfully wrote dump hardware block");
3872 TRACE(
"Removing any previously existing dump hardware block index entries");
3873 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
3878 TRACE(
"Found existing dump hardware block index entry at position %d, removing", k);
3884 TRACE(
"Adding dump hardware block to index");
3888 index_entry.
offset = block_position;
3891 TRACE(
"Added dump hardware block index entry at offset %" PRIu64, block_position);
4000 if(block_position & alignment_mask)
4002 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
4003 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
4004 block_position = aligned_position;
4007 TRACE(
"Writing CICM XML block at position %ld", block_position);
4011 TRACE(
"Successfully wrote CICM XML block");
4014 TRACE(
"Removing any previously existing CICM XML block index entries");
4015 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
4020 TRACE(
"Found existing CICM XML block index entry at position %d, removing", k);
4026 TRACE(
"Adding CICM XML block to index");
4030 index_entry.
offset = block_position;
4033 TRACE(
"Added CICM XML block index entry at offset %" PRIu64, block_position);
4151 if(block_position & alignment_mask)
4153 const uint64_t aligned_position = block_position + alignment_mask & ~alignment_mask;
4154 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
4155 block_position = aligned_position;
4158 TRACE(
"Writing Aaru metadata JSON block at position %ld", block_position);
4162 TRACE(
"Successfully wrote Aaru metadata JSON block");
4165 TRACE(
"Removing any previously existing Aaru metadata JSON block index entries");
4166 for(
int k = utarray_len(ctx->
index_entries) - 1; k >= 0; k--)
4171 TRACE(
"Found existing Aaru metadata JSON block index entry at position %d, removing", k);
4177 TRACE(
"Adding Aaru metadata JSON block to index");
4181 index_entry.
offset = block_position;
4184 TRACE(
"Added Aaru metadata JSON block index entry at offset %" PRIu64, block_position);
4375 uint64_t raw_length = data_length + index_length;
4377 if(raw_length > UINT32_MAX)
4379 FATAL(
"Flux capture raw length exceeds 32-bit limit (%" PRIu64
")", raw_length);
4383 uint8_t *raw_buffer = NULL;
4386 raw_buffer = malloc(raw_length);
4387 if(raw_buffer == NULL)
4389 FATAL(
"Could not allocate %" PRIu64
" bytes for flux serialization", raw_length);
4393 if(data_length != 0 && record->
data_buffer != NULL) memcpy(raw_buffer, record->
data_buffer, data_length);
4395 memcpy(raw_buffer + data_length, record->
index_buffer, index_length);
4398 uint64_t raw_crc = raw_length != 0 && raw_buffer != NULL ?
aaruf_crc64_data(raw_buffer, raw_length) : 0;
4402 uint8_t *compressed_buffer = NULL;
4403 uint32_t cmp_length = 0;
4404 uint64_t cmp_crc = 0;
4406 if(compression ==
Lzma)
4411 uint8_t *cmp_stream = malloc(cmp_capacity);
4412 if(cmp_stream == NULL)
4415 FATAL(
"Could not allocate %zu bytes for LZMA flux compression", cmp_capacity);
4419 size_t dst_size = cmp_capacity;
4427 TRACE(
"Flux capture compression fell back to uncompressed (err=%d, dst=%zu, raw=%" PRIu64
")", error_no,
4428 dst_size, raw_length);
4435 compressed_buffer = malloc(cmp_length);
4436 if(compressed_buffer == NULL)
4440 FATAL(
"Could not allocate %u bytes for flux compressed payload", cmp_length);
4453 if(compression ==
None)
4455 cmp_length = (uint32_t)raw_length;
4457 compressed_buffer = raw_buffer;
4465 if(payload_position & alignment_mask)
4467 const uint64_t aligned_position = payload_position + alignment_mask & ~alignment_mask;
4468 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
4469 payload_position = aligned_position;
4475 payload_header.
compression = (uint16_t)compression;
4477 payload_header.
length = (uint32_t)raw_length;
4479 payload_header.
crc64 = raw_crc;
4483 free(compressed_buffer);
4485 FATAL(
"Could not write flux payload header");
4489 if(cmp_length != 0 && compressed_buffer != NULL &&
4490 fwrite(compressed_buffer, cmp_length, 1, ctx->
imageStream) != 1)
4492 free(compressed_buffer);
4494 FATAL(
"Could not write flux payload data");
4501 payload_entry.
offset = payload_position;
4513 record->
entry = *entry;
4515 free(compressed_buffer);
4756 TRACE(
"Entering write_flux_blocks(%p)", ctx);
4760 FATAL(
"Invalid context when writing flux blocks");
4766 TRACE(
"No flux captures enqueued, skipping flux block serialization");
4771 if(capture_count > UINT16_MAX)
4773 FATAL(
"Flux capture count exceeds header capacity (%zu > %u)", capture_count, UINT16_MAX);
4784 FATAL(
"Could not allocate %zu bytes for flux entries", capture_count *
sizeof(
FluxEntry));
4803 header.
entries = (uint16_t)capture_count;
4812 if(metadata_position & alignment_mask)
4814 const uint64_t aligned_position = metadata_position + alignment_mask & ~alignment_mask;
4815 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
4816 metadata_position = aligned_position;
4823 FATAL(
"Could not write flux metadata header");
4827 if(capture_count != 0)
4830 if(written_entries != capture_count)
4834 FATAL(
"Could not write %zu flux entries (wrote %zu)", capture_count, written_entries);
4842 metadata_entry.
offset = metadata_position;
4845 if(previous_entries != NULL) free(previous_entries);
4855 TRACE(
"Wrote %zu flux captures", capture_count);
4878 TRACE(
"Writing index at the end of the file");
4884 if(index_position & alignment_mask)
4886 uint64_t aligned_position = index_position + alignment_mask & ~alignment_mask;
4887 fseek(ctx->
imageStream, aligned_position, SEEK_SET);
4888 index_position = aligned_position;
4889 TRACE(
"Aligned index position to %" PRIu64, aligned_position);
4898 TRACE(
"Writing index with %" PRIu64
" entries at position %ld", index_header.
entries, index_position);
4902 if(index_crc64_context != NULL && index_header.
entries > 0)
4907 TRACE(
"Calculated index CRC64: 0x%16lX", index_header.
crc64);
4910 index_header.
crc64 = 0;
4918 TRACE(
"Successfully wrote index header");
4923 size_t entries_written = 0;
4931 TRACE(
"Wrote index entry: blockType=0x%08X dataType=%u offset=%" PRIu64, entry->
blockType,
4936 TRACE(
"Failed to write index entry %zu", entries_written);
4940 if(entries_written == index_header.
entries)
4942 TRACE(
"Successfully wrote all %zu index entries", entries_written);
4951 TRACE(
"Successfully updated header with index offset");
4954 TRACE(
"Failed to update header with index offset");
4960 TRACE(
"Failed to write all index entries (wrote %zu of %" PRIu64
")", entries_written,
4968 TRACE(
"Failed to write index header");
5013 TRACE(
"Entering aaruf_close(%p)", context);
5020 FATAL(
"Invalid context");
5030 FATAL(
"Invalid context");
5037 TRACE(
"File is writing");
5039 TRACE(
"Seeking to start of image");
5043 TRACE(
"Writing header at position 0");
5053 TRACE(
"Closing current block if any");
5164 TRACE(
"Clearing sector hash map");
5171 TRACE(
"Freeing memory pointers");
5199 TRACE(
"Freeing media tags");
5203 free(media_tag->
data);
5208 TRACE(
"Unmapping user data DDT if it is not in memory");
5286 TRACE(
"Exiting aaruf_close() = 0");
static int32_t write_flux_capture_payload(aaruformat_context *ctx, FluxCaptureRecord *record, FluxEntry *entry)
Serialize a single flux capture payload block to the image file.
void write_dvd_long_sector_blocks(aaruformat_context *ctx)
Serialize DVD long sector auxiliary data blocks to the image file.
static int32_t write_primary_ddt(aaruformat_context *ctx)
Write (flush) the multi-level primary DDT table header and data back to its file offset.
static void write_cicm_block(aaruformat_context *ctx)
Serialize the CICM XML metadata block to the image file.
static void write_sector_subchannel(aaruformat_context *ctx)
Serialize the per-sector subchannel or tag data block.
static int32_t write_index_block(aaruformat_context *ctx)
Serialize the accumulated index entries at the end of the image and back-patch the header.
static void write_media_tags(aaruformat_context *ctx)
Serialize all accumulated media tags to the image file.
static void write_dvd_title_key_decrypted_block(aaruformat_context *ctx)
Serialize the DVD decrypted title key data block to the image file.
int aaruf_close(void *context)
Close an Aaru image context, flushing pending data structures and releasing resources.
static int32_t write_single_level_ddt(aaruformat_context *ctx)
Serialize a single-level DDT (tableShift == 0) directly after its header.
static void write_tape_file_block(aaruformat_context *ctx)
Serialize the tape file metadata block to the image file.
static void write_dumphw_block(aaruformat_context *ctx)
Serialize the dump hardware block containing acquisition environment information.
static void write_checksum_block(aaruformat_context *ctx)
Finalize any active checksum calculations and append a checksum block.
static void write_sector_suffix(aaruformat_context *ctx)
Serialize the optional CD sector suffix block (EDC/ECC region capture).
static void write_sector_suffix_ddt(aaruformat_context *ctx)
Serialize the per-sector CD suffix status / index DeDuplication Table (DDT v2, suffix variant).
static void write_tracks_block(aaruformat_context *ctx)
Serialize the tracks metadata block and add it to the index.
static void write_aaru_json_block(aaruformat_context *ctx)
Serialize the Aaru metadata JSON block to the image file.
static void write_geometry_block(aaruformat_context *ctx)
Serialize the geometry metadata block to the image file.
static void write_mode2_subheaders_block(aaruformat_context *ctx)
Serialize a MODE 2 (XA) subheaders data block.
static void write_tape_partition_block(aaruformat_context *ctx)
Serialize the tape partition metadata block to the image file.
static void write_sector_prefix_ddt(aaruformat_context *ctx)
Serialize the per-sector CD prefix status / index DeDuplication Table (DDT v2, prefix variant).
static int32_t write_tape_ddt(aaruformat_context *ctx)
Converts tape DDT hash table to array format and writes it as a single-level DDT.
static int32_t write_cached_secondary_ddt(aaruformat_context *ctx)
Flush a cached secondary (child) DeDuplication Table (DDT) to the image.
static void write_metadata_block(aaruformat_context *ctx)
Serialize the metadata block containing image and media descriptive information.
static void write_sector_prefix(aaruformat_context *ctx)
Serialize the optional CD sector prefix block.
static int32_t write_flux_blocks(aaruformat_context *ctx)
Serialize all accumulated flux capture blocks to the image file.
#define LZMA_PROPERTIES_LENGTH
Size in bytes of the fixed LZMA properties header (lc/lp/pb + dictionary size).
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
#define MD5_DIGEST_LENGTH
struct TapeFileHashEntry tapeFileHashEntry
void aaruf_sha1_final(sha1_ctx *ctx, unsigned char *result)
int32_t aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length)
Transforms interleaved subchannel data to sequential format.
int32_t aaruf_lzma_encode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer, size_t src_size, uint8_t *out_props, size_t *out_props_size, int32_t level, uint32_t dict_size, int32_t lc, int32_t lp, int32_t pb, int32_t fb, int32_t num_threads)
Encodes a buffer using LZMA compression.
uint64_t aaruf_crc64_data(const uint8_t *data, uint32_t len)
int aaruf_crc64_update(crc64_ctx *ctx, const uint8_t *data, uint32_t len)
Updates the CRC64 context with new data.
void aaruf_crc64_free(crc64_ctx *ctx)
Frees a CRC64 context.
void aaruf_sha256_final(sha256_ctx *ctx, unsigned char *result)
crc64_ctx * aaruf_crc64_init()
Initializes a CRC64 context.
void aaruf_md5_final(md5_ctx *ctx, unsigned char *result)
void aaruf_spamsum_free(spamsum_ctx *ctx)
Frees a spamsum (fuzzy hash) context.
int32_t aaruf_get_datatype_for_media_tag_type(int32_t tag_type)
Converts an Aaru media tag type to an image data type.
int aaruf_spamsum_final(spamsum_ctx *ctx, uint8_t *result)
void aaruf_ecc_cd_free(void *context)
Frees a Compact Disc ECC context and its internal tables.
int aaruf_crc64_final(crc64_ctx *ctx, uint64_t *crc)
Computes the final CRC64 value from the context.
@ IndexBlock3
Block containing the index v3.
@ ChecksumBlock
Block containing contents checksums.
@ DataBlock
Block containing data.
@ TapePartitionBlock
Block containing list of partitions for a tape image.
@ GeometryBlock
Block containing logical geometry.
@ DeDuplicationTableSecondary
Block containing a secondary deduplication table (v2).
@ AaruMetadataJsonBlock
Block containing JSON version of Aaru Metadata.
@ CicmBlock
Block containing CICM XML metadata.
@ DeDuplicationTable2
Block containing a deduplication table v2.
@ TapeFileBlock
Block containing list of files for a tape image.
@ DeDuplicationTableSAlpha
Block containing a secondary deduplication table (v2) (mistake).
@ DumpHardwareBlock
Block containing an array of hardware used to create the image.
@ MetadataBlock
Block containing metadata.
@ TracksBlock
Block containing optical disc tracks.
@ FluxDataBlock
Block containing flux data metadata.
@ DataStreamPayloadBlock
Block containing compressed data stream payload (e.g., flux data, bitstreams).
@ OpticalDisc
Purely optical discs.
@ BlockMedia
Media that is physically block-based or abstracted like that.
@ SpamSum
SpamSum (context-triggered piecewise hash).
@ CdSectorSubchannel
Compact Disc subchannel data.
@ AppleProfileTag
Apple Profile (20‑byte) tag.
@ DvdSectorIed
DVD ID Error Detection Code (IED).
@ DvdSectorCprMai
DVD Copyright Management Information (CPR_MAI).
@ AppleSonyTag
Apple Sony (12‑byte) tag.
@ CdSectorPrefix
Compact Disc sector prefix (sync, header).
@ PriamDataTowerTag
Priam Data Tower (24‑byte) tag.
@ UserData
User (main) data.
@ DvdSectorEdc
DVD Error Detection Code (EDC).
@ DvdSectorTitleKeyDecrypted
Decrypted DVD Title Key.
@ DvdSectorId
DVD Identification Data (ID).
@ CdSectorSuffix
Compact Disc sector suffix (EDC, ECC P, ECC Q).
@ CompactDiscMode2Subheader
Compact Disc MODE 2 subheader.
@ AARU_FEATURE_RW_BLAKE3
BLAKE3 checksum is present (read/write support for BLAKE3 hashes).
@ AARUF_STATUS_INVALID_CONTEXT
Provided context/handle is invalid.
CompressionType
List of known compression types.
@ LzmaClauniaSubchannelTransform
LZMA applied to Claunia Subchannel Transform processed data.
#define AARUF_ERROR_CANNOT_WRITE_BLOCK_DATA
Failure writing block payload.
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
#define AARUF_ERROR_INCORRECT_DATA_SIZE
Data size does not match expected size.
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
#define AARUF_ERROR_CANNOT_WRITE_HEADER
Failure writing container header.
#define AARUF_ERROR_CANNOT_WRITE_BLOCK_HEADER
Failure writing block header.
void free_map(hash_map_t *map)
Frees all memory associated with a hash map.
int32_t aaruf_close_current_block(aaruformat_context *ctx)
Finalizes and writes the current data block to the AaruFormat image file.
int32_t flux_map_rebuild_from_entries(aaruformat_context *ctx)
Rebuild the flux capture lookup map from the flux_entries array.
void free_cache(struct CacheHeader *cache)
Frees all entries in the cache and clears it.
#define SHA1_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
Per-checksum metadata immediately followed by the digest / signature bytes.
uint32_t length
Length in bytes of the digest that immediately follows this structure.
uint8_t type
Algorithm used (value from ChecksumAlgorithm).
uint8_t * spamsum
SpamSum fuzzy hash (ASCII), allocated length+1 with trailing 0.
bool hasSha256
True if sha256[] buffer populated.
uint8_t sha1[20]
SHA-1 digest (20 bytes).
uint8_t sha256[32]
SHA-256 digest (32 bytes).
uint8_t md5[16]
MD5 digest (16 bytes).
bool hasSpamSum
True if spamsum pointer allocated and signature read.
bool hasSha1
True if sha1[] buffer populated.
uint8_t blake3[BLAKE3_OUT_LEN]
BLAKE3 digest (32 bytes).
bool hasMd5
True if md5[] buffer populated.
bool hasBlake3
True if blake3[] buffer populated.
Inclusive [start,end] logical sector range contributed by a single hardware environment.
uint8_t * firmware
Firmware version string or NULL.
uint8_t * revision
Hardware revision string or NULL.
uint8_t * model
Model string or NULL.
uint8_t * softwareName
Dump software name or NULL.
struct DumpExtent * extents
Array of extents (entry.extents elements) or NULL.
uint8_t * manufacturer
Manufacturer string (UTF-8) or NULL.
uint8_t * softwareVersion
Dump software version or NULL.
uint8_t * serial
Serial number string or NULL.
DumpHardwareEntry entry
Fixed-size header with lengths & counts.
uint8_t * softwareOperatingSystem
Host operating system string or NULL.
Per-environment length table describing subsequent UTF-8 strings and optional extent array.
uint32_t softwareNameLength
Length in bytes of dumping software name string.
uint32_t manufacturerLength
Length in bytes of manufacturer UTF-8 string.
uint32_t softwareVersionLength
Length in bytes of dumping software version string.
uint32_t firmwareLength
Length in bytes of firmware version string.
uint32_t extents
Number of DumpExtent records following the strings (0 = none).
uint32_t modelLength
Length in bytes of model UTF-8 string.
uint32_t serialLength
Length in bytes of device serial number string.
uint32_t revisionLength
Length in bytes of revision / hardware revision string.
uint32_t softwareOperatingSystemLength
Length in bytes of host operating system string.
Internal structure for storing flux capture data during write mode.
FluxEntry entry
Flux entry metadata describing this capture.
uint32_t data_length
Length of the data buffer in bytes.
uint32_t index_length
Length of the index buffer in bytes.
uint8_t * index_buffer
Pointer to the flux index buffer. Owned by the utarray, freed automatically.
uint8_t * data_buffer
Pointer to the flux data buffer. Owned by the utarray, freed automatically.
Metadata entry describing a single flux capture in the FluxDataBlock.
uint64_t indexResolution
Resolution in picoseconds at which the index stream was sampled.
uint64_t dataResolution
Resolution in picoseconds at which the data stream was sampled.
uint32_t head
Head number the flux capture corresponds to. Typically 0 or 1 for double-sided media.
uint64_t payloadOffset
Block-aligned file offset where the DataStreamPayloadBlock containing this capture's data is stored,...
uint16_t track
Track number the flux capture corresponds to. Track numbering is format-dependent.
uint64_t indexOffset
Byte offset within the payload where the index buffer starts (equals data_length).
uint8_t subtrack
Subtrack number, allowing sub-stepping within a track. Used for fine positioning.
uint32_t captureIndex
Capture index, allowing multiple captures for the same location (e.g., multiple revolutions).
uint32_t MediaType
Media type identifier (see MediaType enum; 0=Unknown).
uint8_t MetadataMediaType
Media type for sidecar generation (internal archival use).
uint64_t Sectors
Total count of addressable logical sectors/blocks.
Single index entry describing a block's type, (optional) data classification, and file offset.
uint32_t blockType
Block identifier of the referenced block (value from BlockType).
uint64_t offset
Absolute byte offset in the image where the referenced block header begins.
uint16_t dataType
Data classification (value from DataType) or unused for untyped blocks.
uint64_t key
Key: sector address.
uint64_t value
Value: DDT entry.
Describes a single logical file on a tape medium.
TapeFileEntry fileEntry
The actual tape file data.
Describes a single physical partition on a tape medium.
TapePartitionEntry partitionEntry
The actual tape partition data.
Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).
Master context representing an open or in‑creation Aaru image.
uint8_t * media_barcode
Barcode of the media represented by the image.
DdtHeader2 user_data_ddt_header
Active user data DDT v2 header (primary table meta).
Checksums checksums
Whole-image checksums discovered.
uint8_t * creator
Who (person) created the image?
bool dirty_checksum_block
True if checksum block should be written during close.
bool deduplicate
Storage deduplication active (duplicates coalesce).
bool compression_enabled
True if block compression enabled (writing path).
uint8_t * cicm_block
CICM XML payload.
uint8_t * sector_cpr_mai
DVD sector CPR_MAI (6 bytes) if present.
bool dirty_media_tags
True if media tags should be written during close.
hash_map_t * sector_hash_map
Deduplication hash map (fingerprint->entry mapping).
FluxHeader flux_data_header
Flux data header (if present).
uint8_t * sector_prefix_corrected
Corrected variant (post error correction) if stored.
uint64_t * user_data_ddt
Legacy flat DDT pointer (NULL when using v2 mini/big arrays).
UT_array * flux_captures
Pending flux capture payloads (write path).
sha256_ctx sha256_context
Opaque SHA-256 context for streaming updates.
TrackEntry * data_tracks
Filtered list of data tracks (subset of trackEntries).
bool calculating_sha256
True if whole-image SHA-256 being calculated on-the-fly.
bool dirty_primary_ddt
True if primary DDT table should be written during close.
uint8_t * drive_firmware_revision
Firmware revision of the drive used to read the media represented by the image.
uint8_t * media_serial_number
Serial number of the media represented by the image.
struct CacheHeader block_header_cache
LRU/Cache header for block headers.
uint8_t * sector_ied
DVD sector IED (2 bytes) if present.
md5_ctx md5_context
Opaque MD5 context for streaming updates.
bool dirty_sector_suffix_block
True if sector suffix block should be written during close.
uint64_t * user_data_ddt2
DDT entries (big variant) primary/secondary current.
MetadataBlockHeader metadata_block_header
Metadata block header.
uint8_t * sector_prefix
Raw per-sector prefix (e.g., sync+header) uncorrected.
bool dirty_dvd_title_key_decrypted_block
True if decrypted title key block should be written during close.
uint64_t * sector_suffix_ddt2
CD sector suffix DDT V2.
tapeFileHashEntry * tape_files
Hash table root for tape files.
bool dirty_mode2_subheaders_block
True if MODE2 subheader block should be written during close.
bool dirty_tape_partition_block
True if tape partition block should be written during close.
uint64_t cached_ddt_offset
File offset of currently cached secondary DDT (0=none).
bool dirty_cicm_block
True if CICM metadata block should be written during close.
bool is_tape
True if the image is a tape image.
uint8_t * sector_edc
DVD sector EDC (4 bytes) if present.
bool calculating_sha1
True if whole-image SHA-1 being calculated on-the-fly.
uint8_t * media_model
Model of the media represented by the image.
bool dirty_tracks_block
True if tracks block should be written during close.
uint8_t * drive_serial_number
Serial number of the drive used to read the media represented by the image.
CdEccContext * ecc_cd_context
CD ECC/EDC helper tables (allocated on demand).
struct CacheHeader block_cache
LRU/Cache header for block payloads.
uint32_t * sector_suffix_ddt
Legacy CD sector suffix DDT.
bool dirty_sector_prefix_block
True if sector prefix block should be written during close.
uint8_t * drive_manufacturer
Manufacturer of the drive used to read the media represented by the image.
bool in_memory_ddt
True if primary (and possibly secondary) DDT loaded.
bool dirty_index_block
True if index block should be written during close.
uint8_t * sector_suffix
Raw per-sector suffix (EDC/ECC) uncorrected.
AaruHeaderV2 header
Parsed container header (v2).
FluxEntry * flux_entries
Array of flux entries (flux_data_header.entries elements).
bool dirty_json_block
True if JSON metadata block should be written during close.
bool is_writing
True if context opened/created for writing.
TapeDdtHashEntry * tape_ddt
Hash table root for tape DDT entries.
spamsum_ctx * spamsum_context
Opaque SpamSum context for streaming updates.
CicmMetadataBlock cicm_block_header
CICM metadata header (if present).
size_t sector_prefix_offset
Current position in sector_prefix.
uint8_t * drive_model
Model of the drive used to read the media represented by the image.
bool dirty_single_level_ddt
True if single-level DDT should be written during close.
uint64_t magic
File magic (AARU_MAGIC) post-open.
uint8_t * writing_buffer
Accumulation buffer for current block data.
uint64_t * sector_prefix_ddt2
CD sector prefix DDT V2.
bool calculating_spamsum
True if whole-image SpamSum being calculated on-the-fly.
uint64_t primary_ddt_offset
File offset of the primary DDT v2 table.
mediaTagEntry * mediaTags
Hash table of extra media tags (uthash root).
blake3_hasher * blake3_context
Opaque BLAKE3 context for streaming updates.
bool calculating_blake3
True if whole-image BLAKE3 being calculated on-the-fly.
struct DumpHardwareEntriesWithData * dump_hardware_entries_with_data
Array of dump hardware entries + strings.
bool calculating_md5
True if whole-image MD5 being calculated on-the-fly.
bool dirty_sector_suffix_ddt
True if sector suffix DDT should be written during close.
GeometryBlockHeader geometry_block
Logical geometry block (if present).
size_t sector_suffix_offset
Current position in sector_suffix.
uint64_t * cached_secondary_ddt2
Cached secondary table (big entries) or NULL.
uint8_t * json_block
JSON metadata block payload (UTF-8).
uint8_t * media_part_number
Part number of the media represented by the image.
uint8_t * sector_decrypted_title_key
DVD decrypted title key (5 bytes) if present.
bool dirty_dumphw_block
True if dump hardware block should be written during close.
AaruMetadataJsonBlockHeader json_block_header
JSON metadata block header (if present).
bool dirty_metadata_block
True if metadata block should be written during close.
uint8_t * sector_subchannel
Raw 96-byte subchannel (if captured).
uint8_t * comments
Image comments.
bool dirty_sector_subchannel_block
True if subchannel block should be written during close.
FILE * imageStream
Underlying FILE* stream (binary mode).
bool dirty_dvd_long_sector_blocks
True if DVD long sector blocks should be written during close.
bool dirty_sector_prefix_ddt
True if sector prefix DDT should be written during close.
UT_array * index_entries
Flattened index entries (UT_array of IndexEntry).
bool dirty_tape_file_block
True if tape file block should be written during close.
uint8_t * mode2_subheaders
MODE2 Form1/Form2 8-byte subheaders (concatenated).
ImageInfo image_info
Exposed high-level image info summary.
bool dirty_flux_block
True if flux block should be written during close.
uint8_t * sector_id
DVD sector ID (4 bytes) if present.
DumpHardwareHeader dump_hardware_header
Dump hardware header.
sha1_ctx sha1_context
Opaque SHA-1 context for streaming updates.
bool dirty_secondary_ddt
True if secondary DDT tables should be written during close.
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
bool dirty_tape_ddt
True if tape DDT should be written during close.
TapePartitionHashEntry * tape_partitions
Hash table root for tape partitions.
uint32_t * sector_prefix_ddt
Legacy CD sector prefix DDT (deprecated by *2).
uint32_t lzma_dict_size
LZMA dictionary size (writing path).
TrackEntry * track_entries
Full track list (tracksHeader.entries elements).
uint8_t * sector_suffix_corrected
Corrected suffix if stored separately.
uint8_t * metadata_block
Raw metadata UTF-16LE concatenated strings.
uint64_t cached_ddt_position
Position index of cached secondary DDT.
uint8_t * media_title
Title of the media represented by the image.
bool dirty_geometry_block
True if geometry block should be written during close.
size_t mapped_memory_ddt_size
Length of mmapped DDT if userDataDdt is mmapped.
uint8_t * media_manufacturer
Manufacturer of the media represented by the image.
TracksHeader tracks_header
Tracks header (optical) if present.
Minimal ECMA-182 CRC64 incremental state container (running value only).
Hash table entry for an arbitrary media tag (e.g., proprietary drive/medium descriptor).
uint8_t * data
Tag data blob (opaque to library core); length bytes long.
int32_t type
Numeric type identifier.
uint32_t length
Length in bytes of data.