99 const uint8_t *data, uint8_t sector_status, uint32_t length)
101 TRACE(
"Entering aaruf_write_sector(%p, %" PRIu64
", %d, %p, %u, %u)", context, sector_address, negative, data,
102 sector_status, length);
107 FATAL(
"Invalid context");
109 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_AARUFORMAT");
118 FATAL(
"Invalid context");
120 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_AARUFORMAT");
127 FATAL(
"Trying to write a read-only image");
129 TRACE(
"Exiting aaruf_write_sector() = AARUF_READ_ONLY");
135 FATAL(
"Sector address out of bounds");
137 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_SECTOR_OUT_OF_BOUNDS");
143 FATAL(
"Sector address out of bounds");
145 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_SECTOR_OUT_OF_BOUNDS");
151 if(sector_address <= ctx->last_written_block)
195 !negative && sector_address <= ctx->image_info.Sectors && !ctx->
writing_long)
204 TRACE(
"Closing current block before writing new data");
209 FATAL(
"Error closing current block: %d", error);
211 TRACE(
"Exiting aaruf_write_sector() = %d", error);
216 uint64_t ddt_entry = 0;
222 TRACE(
"Hashing sector data for deduplication");
223 uint64_t hash = XXH3_64bits(data, length);
227 TRACE(
"Block does %s exist in deduplication map", existing ?
"already" :
"not yet");
230 sector_status, &ddt_entry);
233 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_CANNOT_SET_DDT_ENTRY");
239 TRACE(
"Sector exists, so not writing to image");
240 TRACE(
"Exiting aaruf_write_sector() = AARUF_STATUS_OK");
244 TRACE(
"Inserting sector hash into deduplication map, proceeding to write into image as normal");
249 sector_status, &ddt_entry);
253 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_CANNOT_SET_DDT_ENTRY");
260 TRACE(
"Creating new writing block");
270 if(sector_address >= ctx->
track_entries[i].
start && sector_address <= ctx->track_entries[i].end)
312 uint32_t max_buffer_size =
314 TRACE(
"Setting max buffer size to %u bytes", max_buffer_size);
316 TRACE(
"Allocating memory for writing buffer");
320 FATAL(
"Could not allocate memory");
322 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
334 TRACE(
"Exiting aaruf_write_sector() = AARUF_STATUS_OK");
545 const uint8_t *data, uint8_t sector_status, uint32_t length)
547 TRACE(
"Entering aaruf_write_sector_long(%p, %" PRIu64
", %d, %p, %u, %u)", context, sector_address, negative, data,
548 sector_status, length);
553 FATAL(
"Invalid context");
555 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_AARUFORMAT");
564 FATAL(
"Invalid context");
566 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_AARUFORMAT");
573 FATAL(
"Trying to write a read-only image");
575 TRACE(
"Exiting aaruf_write_sector() = AARUF_READ_ONLY");
581 FATAL(
"Sector address out of bounds");
583 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_SECTOR_OUT_OF_BOUNDS");
589 FATAL(
"Sector address out of bounds");
591 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_SECTOR_OUT_OF_BOUNDS");
602 if(sector_address >= ctx->
track_entries[i].
start && sector_address <= ctx->track_entries[i].end)
610 uint64_t corrected_sector_address = sector_address;
618 uint64_t total_sectors =
636 memcpy(ctx->
sector_id + corrected_sector_address * 4, data, 4);
637 memcpy(ctx->
sector_ied + corrected_sector_address * 2, data + 4, 2);
638 memcpy(ctx->
sector_cpr_mai + corrected_sector_address * 6, data + 6, 6);
639 memcpy(ctx->
sector_edc + corrected_sector_address * 4, data + 2060, 4);
641 return aaruf_write_sector(context, sector_address, negative, data + 12, sector_status, 2048);
646 FATAL(
"Incorrect sector size");
647 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_INCORRECT_DATA_SIZE");
655 if(sector_address <= ctx->last_written_block)
681 if(ctx->
calculating_md5 && !negative && sector_address <= ctx->image_info.Sectors)
684 if(ctx->
calculating_sha1 && !negative && sector_address <= ctx->image_info.Sectors)
703 return aaruf_write_sector(context, sector_address, negative, data, sector_status, length);
715 FATAL(
"Could not allocate memory for CD sector prefix DDT");
717 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
731 FATAL(
"Could not allocate memory for CD sector prefix DDT");
733 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
746 FATAL(
"Could not allocate memory for CD sector prefix buffer");
748 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
762 FATAL(
"Could not allocate memory for CD sector suffix buffer");
764 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
771 for(
int i = 0; i < length; i++)
788 prefix_correct =
true;
790 if(data[0x00] != 0x00 || data[0x01] != 0xFF || data[0x02] != 0xFF || data[0x03] != 0xFF ||
791 data[0x04] != 0xFF || data[0x05] != 0xFF || data[0x06] != 0xFF || data[0x07] != 0xFF ||
792 data[0x08] != 0xFF || data[0x09] != 0xFF || data[0x0A] != 0xFF || data[0x0B] != 0x00 ||
794 prefix_correct =
false;
798 const int minute = (data[0x0C] >> 4) * 10 + (data[0x0C] & 0x0F);
799 const int second = (data[0x0D] >> 4) * 10 + (data[0x0D] & 0x0F);
800 const int frame = (data[0x0E] >> 4) * 10 + (data[0x0E] & 0x0F);
801 const int stored_lba = minute * 60 * 75 + second * 75 + frame - 150;
802 prefix_correct = stored_lba == sector_address;
824 FATAL(
"Could not allocate memory for CD sector prefix buffer");
826 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
854 FATAL(
"Could not allocate memory for CD sector suffix buffer");
856 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
877 FATAL(
"Could not allocate memory for CD sector prefix DDT");
879 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
893 FATAL(
"Could not allocate memory for CD sector prefix DDT");
895 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
908 FATAL(
"Could not allocate memory for CD sector prefix buffer");
910 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
924 FATAL(
"Could not allocate memory for CD sector suffix buffer");
926 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
933 for(
int i = 0; i < length; i++)
948 const bool form2 = (data[18] & 0x20) == 0x20 || (data[22] & 0x20) == 0x20;
950 prefix_correct =
true;
952 if(data[0x00] != 0x00 || data[0x01] != 0xFF || data[0x02] != 0xFF || data[0x03] != 0xFF ||
953 data[0x04] != 0xFF || data[0x05] != 0xFF || data[0x06] != 0xFF || data[0x07] != 0xFF ||
954 data[0x08] != 0xFF || data[0x09] != 0xFF || data[0x0A] != 0xFF || data[0x0B] != 0x00 ||
956 prefix_correct =
false;
960 const int minute = (data[0x0C] >> 4) * 10 + (data[0x0C] & 0x0F);
961 const int second = (data[0x0D] >> 4) * 10 + (data[0x0D] & 0x0F);
962 const int frame = (data[0x0E] >> 4) * 10 + (data[0x0E] & 0x0F);
963 const int stored_lba = minute * 60 * 75 + second * 75 + frame - 150;
964 prefix_correct = stored_lba == sector_address;
987 FATAL(
"Could not allocate memory for CD sector prefix buffer");
989 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1004 FATAL(
"Could not allocate memory for CD mode 2 subheader buffer");
1006 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1015 memcpy(&edc, data + 0x92C,
sizeof(edc));
1016 const bool correct_edc = computed_edc == edc;
1042 FATAL(
"Could not allocate memory for CD sector suffix buffer");
1044 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1051 memcpy(ctx->
mode2_subheaders + corrected_sector_address * 8, data + 0x10, 8);
1065 memcpy(&edc, data + 0x818,
sizeof(edc));
1066 const bool correct_edc = computed_edc == edc;
1068 if(correct_ecc && correct_edc)
1087 FATAL(
"Could not allocate memory for CD sector suffix buffer");
1089 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1096 memcpy(ctx->
mode2_subheaders + corrected_sector_address * 8, data + 0x10, 8);
1101 context, sector_address, negative, data + 24,
1120 switch(length - 512)
1142 newTag = malloc(12);
1143 memcpy(newTag, data + 512, 12);
1155 newTag = malloc(20);
1156 memcpy(newTag, data + 512, 20);
1186 newTag = malloc(24);
1187 memcpy(newTag, data + 512, 24);
1203 FATAL(
"Incorrect sector size");
1204 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_INCORRECT_DATA_SIZE");
1209 return aaruf_write_sector(context, sector_address, negative, data, sector_status, 512);
1218 FATAL(
"Could not allocate memory for sector subchannel DDT");
1222 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
1227 memcpy(ctx->
sector_subchannel + sector_address * newTagSize, newTag, newTagSize);
1231 return aaruf_write_sector(context, sector_address, negative, data, sector_status, 512);
1237 TRACE(
"Exiting aaruf_write_sector() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
1437 TRACE(
"Initializing CRC64 context");
1439 TRACE(
"Updating CRC64");
1444 uint8_t *cmp_buffer = NULL;
1452 if(cmp_buffer == NULL)
1454 FATAL(
"Could not allocate buffer for compressed data");
1463 const long remaining = current_samples % flac_block_size;
1471 flac_block_size,
true,
false,
"hamming", 12, 15,
true,
false, 0, 8,
"Aaru", 4);
1482 if(cmp_buffer == NULL)
1484 FATAL(
"Could not allocate buffer for compressed data");
1491 lzma_properties, &props_size, 9, ctx->
lzma_dict_size, 4, 0, 2, 273, 8);
1503 FATAL(
"Invalid compression type");
1518 TRACE(
"Adding block to index");
1526 TRACE(
"Block added to index at offset %" PRIu64, index_entry.
offset);
1826 const uint32_t length)
1828 TRACE(
"Entering aaruf_write_media_tag(%p, %p, %d, %d)", context, data, type, length);
1833 FATAL(
"Invalid context");
1835 TRACE(
"Exiting aaruf_write_media_tag() = AARUF_ERROR_NOT_AARUFORMAT");
1844 FATAL(
"Invalid context");
1846 TRACE(
"Exiting aaruf_write_media_tag() = AARUF_ERROR_NOT_AARUFORMAT");
1853 FATAL(
"Trying to write a read-only image");
1855 TRACE(
"Exiting aaruf_write_media_tag() = AARUF_READ_ONLY");
1859 if(data == NULL || length == 0)
1861 FATAL(
"Invalid data or length");
1865 uint8_t *new_data = malloc(length);
1867 if(new_data == NULL)
1869 FATAL(
"Could not allocate memory for media tag");
1872 memcpy(new_data, data, length);
1877 if(media_tag == NULL)
1879 TRACE(
"Cannot allocate memory for media tag entry.");
1886 media_tag->
type = type;
1887 media_tag->
data = new_data;
1888 media_tag->
length = length;
1890 HASH_REPLACE_INT(ctx->
mediaTags, type, media_tag, old_media_tag);
1892 if(old_media_tag != NULL)
1894 TRACE(
"Replaced media tag with type %d", old_media_tag->
type);
1895 free(old_media_tag->
data);
1896 free(old_media_tag);
1897 old_media_tag = NULL;
1901 TRACE(
"Exiting aaruf_write_media_tag() = AARUF_STATUS_OK");
2096 const uint8_t *data,
const size_t length,
const int32_t tag)
2098 TRACE(
"Entering aaruf_write_sector_tag(%p, %" PRIu64
", %d, %p, %zu, %d)", context, sector_address, negative, data,
2104 FATAL(
"Invalid context");
2106 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_AARUFORMAT");
2115 FATAL(
"Invalid context");
2117 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_AARUFORMAT");
2124 FATAL(
"Trying to write a read-only image");
2126 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_READ_ONLY");
2132 FATAL(
"Sector address out of bounds");
2134 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_SECTOR_OUT_OF_BOUNDS");
2140 FATAL(
"Sector address out of bounds");
2142 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_SECTOR_OUT_OF_BOUNDS");
2146 if(data == NULL || length == 0)
2148 FATAL(
"Invalid data or length");
2152 uint64_t corrected_sector_address = sector_address;
2160 const uint64_t total_sectors =
2168 FATAL(
"Invalid media type for tag");
2169 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2175 FATAL(
"Incorrect tag size");
2176 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2181 if(sector_address >= ctx->
track_entries[i].
start && sector_address <= ctx->track_entries[i].end)
2185 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2189 FATAL(
"Track not found");
2194 FATAL(
"Invalid media type for tag");
2195 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2201 FATAL(
"Incorrect tag size");
2202 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2207 if(sector_address >= ctx->
track_entries[i].
start && sector_address <= ctx->track_entries[i].end)
2211 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2215 FATAL(
"Track not found");
2220 FATAL(
"Invalid media type for tag");
2221 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2227 FATAL(
"Incorrect tag size");
2228 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2236 FATAL(
"Could not allocate memory for sector subchannel");
2238 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2244 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2249 FATAL(
"Invalid media type for tag");
2250 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2256 FATAL(
"Incorrect tag size");
2257 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2265 FATAL(
"Could not allocate memory for sector CPR/MAI");
2267 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2271 memcpy(ctx->
sector_cpr_mai + corrected_sector_address * 6, data, 1);
2273 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2278 FATAL(
"Invalid media type for tag");
2279 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2285 FATAL(
"Incorrect tag size");
2286 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2294 FATAL(
"Could not allocate memory for sector ID");
2296 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2300 memcpy(ctx->
sector_id + corrected_sector_address * 4, data, 1);
2301 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2306 FATAL(
"Invalid media type for tag");
2307 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2313 FATAL(
"Incorrect tag size");
2314 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2322 FATAL(
"Could not allocate memory for sector ID");
2324 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2328 memcpy(ctx->
sector_id + corrected_sector_address * 4 + 1, data, 3);
2330 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2335 FATAL(
"Invalid media type for tag");
2336 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2342 FATAL(
"Incorrect tag size");
2343 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2351 FATAL(
"Could not allocate memory for sector IED");
2353 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2357 memcpy(ctx->
sector_ied + corrected_sector_address * 2, data, 2);
2359 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2364 FATAL(
"Invalid media type for tag");
2365 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2371 FATAL(
"Incorrect tag size");
2372 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2380 FATAL(
"Could not allocate memory for sector EDC");
2382 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2386 memcpy(ctx->
sector_edc + corrected_sector_address * 4, data, 4);
2388 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2393 FATAL(
"Invalid media type for tag");
2394 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2400 FATAL(
"Incorrect tag size");
2401 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2409 FATAL(
"Could not allocate memory for sector decrypted title key");
2411 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2417 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2422 FATAL(
"Invalid media type for tag");
2423 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2429 FATAL(
"Incorrect tag size");
2430 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2438 FATAL(
"Could not allocate memory for Apple Sony tag");
2440 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2446 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2451 FATAL(
"Invalid media type for tag");
2452 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2458 FATAL(
"Incorrect tag size");
2459 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2467 FATAL(
"Could not allocate memory for Apple Profile tag");
2469 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2475 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2480 FATAL(
"Invalid media type for tag");
2481 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
2487 FATAL(
"Incorrect tag size");
2488 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_INCORRECT_DATA_SIZE");
2496 FATAL(
"Could not allocate memory for Priam Data Tower tag");
2498 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_ERROR_NOT_ENOUGH_MEMORY");
2504 TRACE(
"Exiting aaruf_write_sector_tag() = AARUF_STATUS_OK");
2507 TRACE(
"Do not know how to write sector tag %d", tag);
#define MAX_FLAKE_BLOCK
FLAC maximum block size used for encoding audio sectors.
#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 MIN_FLAKE_BLOCK
FLAC minimum block size.
#define SAMPLES_PER_SECTOR
Red Book (CD‑DA) PCM samples per 2352‑byte sector: 44,100 Hz / 75 sectors per second = 588 samples.
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)
size_t aaruf_flac_encode_redbook_buffer(uint8_t *dst_buffer, size_t dst_size, const uint8_t *src_buffer, size_t src_size, uint32_t blocksize, int32_t do_mid_side_stereo, int32_t loose_mid_side_stereo, const char *apodization, uint32_t max_lpc_order, uint32_t qlp_coeff_precision, int32_t do_qlp_coeff_prec_search, int32_t do_exhaustive_model_search, uint32_t min_residual_partition_order, uint32_t max_residual_partition_order, const char *application_id, uint32_t application_id_len)
Encodes a Red Book audio buffer to FLAC format.
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.
int aaruf_spamsum_update(spamsum_ctx *ctx, const uint8_t *data, uint32_t len)
Updates the spamsum context with new data.
crc64_ctx * aaruf_crc64_init()
Initializes a CRC64 context.
uint32_t aaruf_edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int size, int pos)
Computes the EDC (Error Detection Code) for a CD sector.
void aaruf_md5_update(md5_ctx *ctx, const void *data, unsigned long size)
void aaruf_sha256_update(sha256_ctx *ctx, const void *data, unsigned long size)
bool aaruf_ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector)
Checks if the suffix (EDC/ECC) of a CD sector is correct (Mode 2).
void aaruf_sha1_update(sha1_ctx *ctx, const void *data, unsigned long size)
int aaruf_crc64_final(crc64_ctx *ctx, uint64_t *crc)
Computes the final CRC64 value from the context.
bool aaruf_ecc_cd_is_suffix_correct(void *context, const uint8_t *sector)
Checks if the suffix (EDC/ECC) of a CD sector is correct (Mode 1).
@ DataBlock
Block containing data.
@ SectorStatusNotDumped
Sector(s) not yet acquired during image dumping.
@ SectorStatusMode2Form2NoCrc
Suffix matches MODE 2 Form 2 but CRC empty/missing.
@ SectorStatusMode1Correct
Valid MODE 1 data with regenerable suffix/prefix.
@ SectorStatusMode2Form2Ok
Suffix matches MODE 2 Form 2 with valid CRC.
@ SectorStatusErrored
Error during dumping; data may be incomplete or corrupt.
@ SectorStatusMode2Form1Ok
Suffix verified/regenerable for MODE 2 Form 1.
@ OpticalDisc
Purely optical discs.
@ BlockMedia
Media that is physically block-based or abstracted like that.
@ CdMode1
Compact Disc Mode 1 data track.
@ Data
Generic data track (not further specified).
@ CdMode2Form2
Compact Disc Mode 2 Form 2 data track.
@ CdMode2Form1
Compact Disc Mode 2 Form 1 data track.
@ CdMode2Formless
Compact Disc Mode 2 (formless) data track.
@ UserData
User (main) 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_READ_ONLY
Operation requires write mode but context is read-only.
#define AARUF_ERROR_INCORRECT_MEDIA_TYPE
Operation incompatible with image media type.
#define AARUF_ERROR_TRACK_NOT_FOUND
Referenced track number not present.
#define AARUF_ERROR_NOT_ENOUGH_MEMORY
Memory allocation failure (critical).
#define AARUF_ERROR_SECTOR_OUT_OF_BOUNDS
Requested logical sector outside media bounds.
#define AARUF_ERROR_INCORRECT_DATA_SIZE
Data size does not match expected size.
#define AARUF_ERROR_CANNOT_SET_DDT_ENTRY
Failed to encode/store a DDT entry (overflow or IO).
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
#define AARUF_ERROR_INVALID_TAG
Invalid or unsupported media or sector tag format.
#define AARUF_ERROR_CANNOT_WRITE_BLOCK_HEADER
Failure writing block header.
bool lookup_map(const hash_map_t *map, uint64_t key, uint64_t *out_value)
Looks up a value by key in the hash map.
bool insert_map(hash_map_t *map, uint64_t key, uint64_t value)
Inserts a key-value pair into the hash map.
bool set_ddt_entry_v2(aaruformat_context *ctx, uint64_t sector_address, bool negative, uint64_t offset, uint64_t block_offset, uint8_t sector_status, uint64_t *ddt_entry)
Sets a DDT v2 entry for a given sector address.
Structure definitions and conversion/serialization function declarations for Lisa family disk tags.
uint8_t * priam_tag_to_bytes(priam_tag tag)
Serialize a priam_tag into a newly allocated 24-byte big-endian on-disk representation.
priam_tag bytes_to_priam_tag(const uint8_t *bytes)
Parse a 24-byte Priam tag record into a priam_tag structure.
sony_tag profile_tag_to_sony(profile_tag tag)
Convert a profile_tag to a sony_tag.
uint8_t * sony_tag_to_bytes(sony_tag tag)
Serialize a sony_tag into a newly allocated 12-byte big-endian on-disk representation.
profile_tag priam_tag_to_profile(priam_tag tag)
Convert a priam_tag to a profile_tag.
uint8_t * profile_tag_to_bytes(profile_tag tag)
Serialize a profile_tag into a newly allocated 20-byte big-endian on-disk representation.
profile_tag sony_tag_to_profile(sony_tag tag)
Convert a sony_tag to a profile_tag representation.
sony_tag bytes_to_sony_tag(const uint8_t *bytes)
Parse a 12-byte Sony tag record into a sony_tag structure.
profile_tag bytes_to_profile_tag(const uint8_t *bytes)
Parse a 20-byte Profile tag record into a profile_tag structure.
priam_tag sony_tag_to_priam(sony_tag tag)
Convert a sony_tag to a priam_tag representation.
priam_tag profile_tag_to_priam(profile_tag tag)
Convert a profile_tag to a priam_tag.
sony_tag priam_tag_to_sony(priam_tag tag)
Convert a priam_tag to a sony_tag.
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.
Single optical disc track descriptor (sequence, type, LBAs, session, ISRC, flags).
uint8_t session
Session number (1-based). 1 for single-session discs.
uint8_t flags
Control / attribute bitfield (see file documentation for suggested bit mapping).
int64_t end
Inclusive ending LBA of the track.
uint8_t sequence
Track number (1..99 typical for CD audio/data). 0 may indicate placeholder/non-standard.
int64_t start
Inclusive starting LBA of the track.
uint8_t type
Track type (value from TrackType).
uint8_t isrc[13]
ISRC raw 13-byte code (no null terminator). All zeros if not present.
Master context representing an open or in‑creation Aaru image.
DdtHeader2 user_data_ddt_header
Active user data DDT v2 header (primary table meta).
bool dirty_checksum_block
True if checksum block should be written during close.
bool deduplicate
Storage deduplication active (duplicates coalesce).
size_t sector_suffix_length
Length of sector_suffix.
bool compression_enabled
True if block compression enabled (writing path).
uint64_t last_written_block
Last written block number (write path).
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).
sha256_ctx sha256_context
Opaque SHA-256 context for streaming updates.
bool calculating_sha256
True if whole-image SHA-256 being calculated on-the-fly.
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.
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.
bool dirty_mode2_subheaders_block
True if MODE2 subheader block should be written during close.
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.
bool dirty_tracks_block
True if tracks block should be written during close.
CdEccContext * ecc_cd_context
CD ECC/EDC helper tables (allocated on demand).
bool rewinded
True if stream has been rewound after open (write path).
bool dirty_sector_prefix_block
True if sector prefix block should be written during close.
bool dirty_index_block
True if index block should be written during close.
uint8_t * sector_suffix
Raw per-sector suffix (EDC/ECC) uncorrected.
int current_block_offset
Logical offset inside block (units: bytes or sectors depending on path).
bool is_writing
True if context opened/created for writing.
spamsum_ctx * spamsum_context
Opaque SpamSum context for streaming updates.
size_t sector_prefix_offset
Current position in sector_prefix.
BlockHeader current_block_header
Header for block currently being assembled (write path).
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.
size_t sector_prefix_length
Length of sector_prefix.
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.
uint64_t next_block_position
Absolute file offset where next block will be written.
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.
size_t sector_suffix_offset
Current position in sector_suffix.
uint8_t * sector_decrypted_title_key
DVD decrypted title key (5 bytes) if present.
int writing_buffer_position
Current size / position within writingBuffer.
bool block_zero_written
True if block zero has been written (writing path).
crc64_ctx * crc64_context
Opaque CRC64 context for streaming updates.
uint8_t * sector_subchannel
Raw 96-byte subchannel (if captured).
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).
uint8_t * mode2_subheaders
MODE2 Form1/Form2 8-byte subheaders (concatenated).
ImageInfo image_info
Exposed high-level image info summary.
uint8_t * sector_id
DVD sector ID (4 bytes) if present.
sha1_ctx sha1_context
Opaque SHA-1 context for streaming updates.
uint32_t lzma_dict_size
LZMA dictionary size (writing path).
TrackEntry * track_entries
Full track list (tracksHeader.entries elements).
uint8_t current_track_type
Current track type (when writing optical images with tracks, needed for block compression type).
bool writing_long
True if writing long sectors.
TracksHeader tracks_header
Tracks header (optical) if present.
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.
int32_t aaruf_close_current_block(aaruformat_context *ctx)
Finalizes and writes the current data block to the AaruFormat image file.
int32_t aaruf_write_sector_tag(void *context, const uint64_t sector_address, const bool negative, const uint8_t *data, const size_t length, const int32_t tag)
Writes per-sector tag data (auxiliary metadata) for a specific sector.
int32_t aaruf_write_media_tag(void *context, const uint8_t *data, const int32_t type, const uint32_t length)
Writes a media tag to the AaruFormat image, storing medium-specific metadata and descriptors.
int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative, const uint8_t *data, uint8_t sector_status, uint32_t length)
Writes a sector to the AaruFormat image.
int32_t aaruf_write_sector_long(void *context, uint64_t sector_address, bool negative, const uint8_t *data, uint8_t sector_status, uint32_t length)
Writes a full ("long") raw sector from optical or block media, parsing structure and validating conte...