24 Commits

Author SHA1 Message Date
963174ce20 Bump version to 1.0.0-alpha.16 in nuspec file 2025-12-10 01:15:59 +00:00
c5e3878174 Fix the size of the metadata block in memory buffer. 2025-12-10 01:15:27 +00:00
afa1c94aac Bump version to 1.0.0-alpha.15 in nuspec file 2025-12-10 00:32:00 +00:00
12418518c2 Fixed metadata block not being read correctly. 2025-12-10 00:31:37 +00:00
5bf7981133 Fixed metadata block not being printed correctly in aaruformattool. 2025-12-10 00:31:24 +00:00
dc221d91ee Fixed missing comma in media types. 2025-12-10 00:30:37 +00:00
d0859665d9 Bump version to 1.0.0-alpha.14 in nuspec file 2025-12-09 19:39:13 +00:00
0d4d01fa8f Fix metadata block header not being written to image. 2025-12-09 19:38:40 +00:00
bd8c00e758 Synced media types with Aaru. 2025-12-01 12:55:48 +00:00
e28b1209c8 Bump version to 1.0.0-alpha.13 in nuspec file 2025-11-26 03:21:45 +00:00
0e51337e30 In info tool correct print application from image information. 2025-11-26 03:21:24 +00:00
56bb631872 Read uncompressed DDT v1 into memory. 2025-11-26 03:20:58 +00:00
58788beed1 Bump version to 1.0.0-alpha.12 in nuspec file 2025-11-24 00:05:53 +00:00
176cab648b Fix bounds with negative sectors. 2025-11-23 23:53:25 +00:00
fb88d4d04b Bump version to 1.0.0-alpha.11 in nuspec file 2025-11-23 20:56:36 +00:00
2b98fb44d0 Skip LZMA properties when verifying compressed blocks. 2025-11-23 20:55:57 +00:00
90f0eba315 Bump version to 1.0.0-alpha.10 in nuspec file 2025-11-22 17:44:51 +00:00
dc613fef8e Override sector status when setting DDT entry as it can be different than cached deduplicated entries. 2025-11-22 17:44:28 +00:00
8022e32415 Fix incorrect media type references in read.c 2025-11-22 17:43:51 +00:00
515db911d7 Fix linking of slog library in CMakeLists.txt 2025-11-22 17:43:19 +00:00
be0f95482d Bump version to 1.0.0-alpha.9 in nuspec file 2025-11-22 13:51:36 +00:00
bb6c427378 Fix calculation of negative sectors offset in DDT tables. 2025-11-22 13:51:10 +00:00
649ac6003d Pass parameter instead of hardcoded value in set_ddt_entry_v2. 2025-11-22 13:50:52 +00:00
25bad474ec Add test for negative sectors. 2025-11-22 13:50:10 +00:00
15 changed files with 743 additions and 445 deletions

View File

@@ -277,7 +277,7 @@ if(USE_SLOG)
target_compile_definitions(aaruformat PRIVATE ENABLE_TRACE ENABLE_FATAL USE_SLOG)
# Link slog
target_link_libraries(aaruformat PRIVATE slog)
target_link_libraries(aaruformat slog)
message(STATUS "slog logging enabled")
else()

View File

@@ -544,6 +544,7 @@ For the most accurate and up-to-date list, refer to the `libaaruformat` source.
|ISO_14517|802|5.25", M.O., 1273011 sectors, 1024 bytes/sector, ISO 14517, 2.6Gb/cart
|ISO_14517_512|803|5.25", M.O., 2244958 sectors, 512 bytes/sector, ISO 14517, 2.3Gb/cart
|ISO_15041_512|804|3.5", M.O., 1041500 sectors, 512 bytes/sector, ISO 15041, 540Mb/cart
|HSM650|805|3,5", M.O., ??????? sectors, proprietary, 650Mb/cart, Sony HyperStorage
|MetaFloppy_Mod_I|820|5.25", SS, DD, 35 tracks, 16 spt, 256 bytes/sector, MFM, 48 tpi, ???rpm
|AtariLynxCard|821|
|AtariJaguarCartridge|822|

View File

@@ -770,8 +770,60 @@ typedef enum
// VideoNow, types 740 to 749
VideoNow = 740, ///< Hasbro VideoNow 85 mm proprietary video disc
VideoNowColor = 741, ///< Hasbro VideoNow Color disc
VideoNowXp = 742 ///< Hasbro VideoNow XP higher capacity disc
//
VideoNowXp = 742, ///< Hasbro VideoNow XP higher capacity disc
// VideoNow, types 740 to 749
// Iomega, types 750 to 759
Bernoulli10 = 750, ///< 8"x11" Bernoulli Box disk with 10Mb capacity
///< 8"x11" Bernoulli Box disk with 20Mb capacity
Bernoulli20 = 751,
///< 5⅓" Bernoulli Box II disk with 20Mb capacity
BernoulliBox2_20 = 752,
// Iomega, types 750 to 759
// Kodak, types 760 to 769
KodakVerbatim3 = 760, ///< Kodak/Verbatim (3Mb)
KodakVerbatim6 = 761, ///< Kodak/Verbatim (6Mb)
KodakVerbatim12 = 762, ///< Kodak/Verbatim (12Mb)
// Kodak, types 760 to 769
// Sony and Panasonic Blu-ray derived, types 770 to 799
ProfessionalDisc = 770, ///< Professional Disc for video, single layer, rewritable, 23Gb
ProfessionalDiscDual = 771, ///< Professional Disc for video, dual layer, rewritable, 50Gb
ProfessionalDiscTriple = 772, ///< Professional Disc for video, triple layer, rewritable, 100Gb
ProfessionalDiscQuad = 773, ///< Professional Disc for video, quad layer, write once, 128Gb
PDD = 774, ///< Professional Disc for DATA, single layer, rewritable, 23Gb
PDD_WORM = 775, ///< Professional Disc for DATA, single layer, write once, 23Gb
ArchivalDisc = 776, ///< Archival Disc, 1st gen., 300Gb
ArchivalDisc2 = 777, ///< Archival Disc, 2nd gen., 500Gb
ArchivalDisc3 = 778, ///< Archival Disc, 3rd gen., 1Tb
ODC300R = 779, ///< Optical Disc archive, 1st gen., write once, 300Gb
ODC300RE = 780, ///< Optical Disc archive, 1st gen., rewritable, 300Gb
ODC600R = 781, ///< Optical Disc archive, 2nd gen., write once, 600Gb
ODC600RE = 782, ///< Optical Disc archive, 2nd gen., rewritable, 600Gb
ODC1200RE = 783, ///< Optical Disc archive, 3rd gen., rewritable, 1200Gb
ODC1500R = 784, ///< Optical Disc archive, 3rd gen., write once, 1500Gb
ODC3300R = 785, ///< Optical Disc archive, 4th gen., write once, 3300Gb
ODC5500R = 786, ///< Optical Disc archive, 5th gen., write once, 5500Gb
// Sony and Panasonic Blu-ray derived, types 770 to 799
// Magneto-optical, types 800 to 819
ECMA_322_1k = 800, ///< 5,25", M.O., 4383356 sectors, 1024 bytes/sector, ECMA-322, ISO 22092, 9.1Gb/cart
ECMA_322_512 = 801, ///< 5,25", M.O., ??????? sectors, 512 bytes/sector, ECMA-322, ISO 22092, 9.1Gb/cart
ISO_14517 = 802, ///< 5,25", M.O., 1273011 sectors, 1024 bytes/sector, ISO 14517, 2.6Gb/cart
ISO_14517_512 = 803, ///< 5,25", M.O., 2244958 sectors, 512 bytes/sector, ISO 14517, 2.3Gb/cart
ISO_15041_512 = 804, ///< 3,5", M.O., 1041500 sectors, 512 bytes/sector, ISO 15041, 540Mb/cart
HSM650 = 805, ///< 3,5", M.O., ??????? sectors, proprietary, 650Mb/cart, Sony HyperStorage
// Magneto-optical, types 800 to 819
// More floppy formats, types 820 to deprecated
MetaFloppy_Mod_I = 820, ///< 5.25", SS, DD, 35 tracks, 16 spt, 256 bytes/sector, MFM, 48 tpi, ???rpm
HF12 = 823, ///< HyperFlex (12Mb), 5.25", DS, 301 tracks, 78 spt, 256 bytes/sector, MFM, 333 tpi, 600rpm
HF24 = 824, ///< HyperFlex (24Mb), 5.25", DS, 506 tracks, 78 spt, 256 bytes/sector, MFM, 666 tpi, 720rpm
// More floppy formats, types 820 to deprecated
AtariLynxCard = 821, ///< Atari Lynx card
AtariJaguarCartridge = 822 ///< Atari Jaguar cartridge
} MediaType;
/** @} */ /* end of MediaTypes group */
@@ -1008,7 +1060,7 @@ typedef enum
MiniDiscUTOC = 71, ///< User TOC, contains fragments, track names, and can be from 1 to 3 sectors of 2336 bytes
MiniDiscDTOC = 72, ///< Not entirely clear kind of TOC that only appears on MD-DATA discs
DVD_DiscKey_Decrypted = 73, ///< Decrypted DVD disc key,
MaxMediaTag = DVD_DiscKey_Decrypted
MaxMediaTag = DVD_DiscKey_Decrypted
} MediaTagType;
/** @} */ /* end of MediaTags group */

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>libaaruformat</id>
<version>1.0.0-alpha.8</version>
<version>1.0.0-alpha.16</version>
<description>Library for management of AaruFormat images.</description>
<authors>claunia</authors>
<projectUrl>https://github.com/aaru-dps/libaaruformat</projectUrl>

View File

@@ -81,7 +81,7 @@ void process_metadata_block(aaruformat_context *ctx, const IndexEntry *entry)
ctx->image_info.ImageSize += ctx->metadata_block_header.blockSize;
ctx->metadata_block = (uint8_t *)malloc(ctx->metadata_block_header.blockSize);
ctx->metadata_block = (uint8_t *)malloc(ctx->metadata_block_header.blockSize + sizeof(MetadataBlockHeader));
if(ctx->metadata_block == NULL)
{
@@ -92,15 +92,20 @@ void process_metadata_block(aaruformat_context *ctx, const IndexEntry *entry)
return;
}
TRACE("Reading metadata block of size %u at position %" PRIu64, ctx->metadata_block_header.blockSize,
entry->offset + sizeof(MetadataBlockHeader));
read_bytes = fread(ctx->metadata_block, 1, ctx->metadata_block_header.blockSize, ctx->imageStream);
TRACE("Reading metadata block of size %u at position %" PRIu64,
ctx->metadata_block_header.blockSize + sizeof(MetadataBlockHeader), entry->offset);
if(read_bytes != ctx->metadata_block_header.blockSize)
fseek(ctx->imageStream, entry->offset, SEEK_SET);
read_bytes = fread(ctx->metadata_block, 1, ctx->metadata_block_header.blockSize + sizeof(MetadataBlockHeader),
ctx->imageStream);
if(read_bytes != ctx->metadata_block_header.blockSize + sizeof(MetadataBlockHeader))
{
memset(&ctx->metadata_block_header, 0, sizeof(MetadataBlockHeader));
free(ctx->metadata_block);
FATAL("Could not read metadata block, continuing...");
return;
}
if(ctx->metadata_block_header.mediaSequence > 0 && ctx->metadata_block_header.lastMediaSequence > 0)

View File

@@ -3304,6 +3304,8 @@ static void write_metadata_block(aaruformat_context *ctx)
block_position = aligned_position;
}
memcpy(buffer, &ctx->metadata_block_header, sizeof(MetadataBlockHeader));
TRACE("Writing metadata block at position %ld", block_position);
if(fwrite(buffer, ctx->metadata_block_header.blockSize, 1, ctx->imageStream) == 1)

View File

@@ -217,26 +217,26 @@ int32_t process_ddt_v1(aaruformat_context *ctx, IndexEntry *entry, bool *found_u
break;
// TODO: Check CRC
case None:
#ifdef __linux__
TRACE("Memory mapping deduplication table at position %" PRIu64, entry->offset + sizeof(ddt_header));
ctx->mapped_memory_ddt_size = sizeof(uint64_t) * ddt_header.entries;
ctx->user_data_ddt = mmap(NULL, ctx->mapped_memory_ddt_size, PROT_READ, MAP_SHARED,
fileno(ctx->imageStream), entry->offset + sizeof(ddt_header));
if(ctx->user_data_ddt == MAP_FAILED)
ctx->user_data_ddt = (uint64_t *)malloc(ddt_header.length);
if(ctx->user_data_ddt == NULL)
{
*found_user_data_ddt = false;
FATAL("Could not read map deduplication table.");
TRACE("Cannot allocate memory for DDT, continuing...");
break;
}
ctx->in_memory_ddt = false;
read_bytes = fread(ctx->user_data_ddt, 1, ddt_header.entries * sizeof(uint64_t), ctx->imageStream);
if(read_bytes != ddt_header.entries * sizeof(uint64_t))
{
free(ctx->user_data_ddt);
TRACE("Could not read deduplication table, continuing...");
break;
}
ctx->in_memory_ddt = true;
*found_user_data_ddt = true;
break;
#else // TODO: Implement
TRACE("Uncompressed DDT not yet implemented...");
*found_user_data_ddt = false;
break;
#endif
default:
TRACE("Found unknown compression type %d, continuing...", ddt_header.compression);
*found_user_data_ddt = false;

View File

@@ -605,7 +605,7 @@ int32_t decode_ddt_single_level_v2(aaruformat_context *ctx, uint64_t sector_addr
// Calculate positive or negative sector
if(negative)
sector_address -= ctx->user_data_ddt_header.negative;
sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
sector_address += ctx->user_data_ddt_header.negative;
@@ -757,7 +757,7 @@ int32_t decode_ddt_multi_level_v2(aaruformat_context *ctx, uint64_t sector_addre
// Calculate positive or negative sector
if(negative)
sector_address -= ctx->user_data_ddt_header.negative;
sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
sector_address += ctx->user_data_ddt_header.negative;
@@ -985,7 +985,7 @@ int32_t decode_ddt_multi_level_v2(aaruformat_context *ctx, uint64_t sector_addre
* @return Returns one of the following status codes:
* @retval true if the entry was set successfully, false otherwise.
*/
bool set_ddt_entry_v2(aaruformat_context *ctx, const uint64_t sector_address, bool negative, const uint64_t offset,
bool set_ddt_entry_v2(aaruformat_context *ctx, const uint64_t sector_address, const bool negative, const uint64_t offset,
const uint64_t block_offset, const uint8_t sector_status, uint64_t *ddt_entry)
{
TRACE("Entering set_ddt_entry_v2(%p, %" PRIu64 ", %d, %llu, %llu, %d)", ctx, sector_address, negative, offset,
@@ -999,9 +999,9 @@ bool set_ddt_entry_v2(aaruformat_context *ctx, const uint64_t sector_address, bo
}
if(ctx->user_data_ddt_header.tableShift > 0)
return set_ddt_multi_level_v2(ctx, sector_address, false, offset, block_offset, sector_status, ddt_entry);
return set_ddt_multi_level_v2(ctx, sector_address, negative, offset, block_offset, sector_status, ddt_entry);
return set_ddt_single_level_v2(ctx, sector_address, false, offset, block_offset, sector_status, ddt_entry);
return set_ddt_single_level_v2(ctx, sector_address, negative, offset, block_offset, sector_status, ddt_entry);
}
/**
@@ -1045,7 +1045,7 @@ bool set_ddt_single_level_v2(aaruformat_context *ctx, uint64_t sector_address, c
// Calculate positive or negative sector
if(negative)
sector_address -= ctx->user_data_ddt_header.negative;
sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
sector_address += ctx->user_data_ddt_header.negative;
@@ -1062,10 +1062,12 @@ bool set_ddt_single_level_v2(aaruformat_context *ctx, uint64_t sector_address, c
TRACE("Exiting set_ddt_single_level_v2() = false");
return false;
}
*ddt_entry |= (uint64_t)sector_status << 60;
}
// Sector status can be different from previous deduplicated sector
*ddt_entry &= 0x0FFFFFFFFFFFFFFF;
*ddt_entry |= (uint64_t)sector_status << 60;
TRACE("Setting big single-level DDT entry %d to %ull", sector_address, (uint64_t)*ddt_entry);
ctx->user_data_ddt2[sector_address] = *ddt_entry;
@@ -1125,7 +1127,7 @@ bool set_ddt_multi_level_v2(aaruformat_context *ctx, uint64_t sector_address, bo
// Calculate positive or negative sector
if(negative)
sector_address -= ctx->user_data_ddt_header.negative;
sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
sector_address += ctx->user_data_ddt_header.negative;
@@ -1154,10 +1156,12 @@ bool set_ddt_multi_level_v2(aaruformat_context *ctx, uint64_t sector_address, bo
TRACE("Exiting set_ddt_multi_level_v2() = false");
return false;
}
*ddt_entry |= (uint64_t)sector_status << 60;
}
// Sector status can be different from previous deduplicated sector
*ddt_entry &= 0x0FFFFFFFFFFFFFFF;
*ddt_entry |= (uint64_t)sector_status << 60;
TRACE("Setting small secondary DDT entry %d to %ull", sector_address % items_per_ddt_entry,
(uint64_t)*ddt_entry);
ctx->cached_secondary_ddt2[sector_address % items_per_ddt_entry] = *ddt_entry;
@@ -1637,10 +1641,12 @@ bool set_ddt_multi_level_v2(aaruformat_context *ctx, uint64_t sector_address, bo
TRACE("Exiting set_ddt_multi_level_v2() = false");
return false;
}
*ddt_entry |= (uint64_t)sector_status << 60;
}
// Sector status can be different from previous deduplicated sector
*ddt_entry &= 0x0FFFFFFFFFFFFFFF;
*ddt_entry |= (uint64_t)sector_status << 60;
TRACE("Setting big secondary DDT entry %d to %ull", sector_address % items_per_ddt_entry, (uint64_t)*ddt_entry);
ctx->cached_secondary_ddt2[sector_address % items_per_ddt_entry] = *ddt_entry;

View File

@@ -297,7 +297,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void *context, const uint64_t se
return AARUF_ERROR_NOT_AARUFORMAT;
}
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1)
if(negative && sector_address > ctx->user_data_ddt_header.negative)
{
FATAL("Sector address out of bounds");
@@ -704,7 +704,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_track_sector(void *context, uint8_t *da
if(ctx->image_info.MetadataMediaType != OpticalDisc)
{
FATAL("Incorrect media type %d, expected OpticalDisc", ctx->imageInfo.XmlMediaType);
FATAL("Incorrect media type %d, expected OpticalDisc", ctx->image_info.MetadataMediaType);
TRACE("Exiting aaruf_read_track_sector() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
@@ -868,7 +868,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64
return AARUF_ERROR_NOT_AARUFORMAT;
}
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1)
if(negative && sector_address > ctx->user_data_ddt_header.negative)
{
FATAL("Sector address out of bounds");
@@ -888,7 +888,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64
// Calculate positive or negative sector
if(negative)
corrected_sector_address -= ctx->user_data_ddt_header.negative;
corrected_sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
corrected_sector_address += ctx->user_data_ddt_header.negative;
@@ -1282,7 +1282,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64
tag_length = 24;
break;
default:
FATAL("Unsupported media type %d", ctx->imageInfo.MediaType);
FATAL("Unsupported media type %d", ctx->image_info.MediaType);
TRACE("Exiting aaruf_read_sector_long() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
@@ -1339,13 +1339,13 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64
TRACE("Exiting aaruf_read_sector_long() = AARUF_STATUS_OK");
return AARUF_STATUS_OK;
default:
FATAL("Incorrect media type %d for long sector reading", ctx->imageInfo.MediaType);
FATAL("Incorrect media type %d for long sector reading", ctx->image_info.MediaType);
TRACE("Exiting aaruf_read_sector_long() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
}
default:
FATAL("Incorrect media type %d for long sector reading", ctx->imageInfo.MediaType);
FATAL("Incorrect media type %d for long sector reading", ctx->image_info.MediaType);
TRACE("Exiting aaruf_read_sector_long() = AARUF_ERROR_INCORRECT_MEDIA_TYPE");
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
@@ -1509,7 +1509,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_tag(const void *context, const u
return AARUF_ERROR_NOT_AARUFORMAT;
}
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1)
if(negative && sector_address > ctx->user_data_ddt_header.negative)
{
FATAL("Sector address out of bounds");
@@ -1529,7 +1529,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_tag(const void *context, const u
// Calculate positive or negative sector
if(negative)
corrected_sector_address -= ctx->user_data_ddt_header.negative;
corrected_sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
corrected_sector_address += ctx->user_data_ddt_header.negative;

View File

@@ -225,195 +225,242 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup;
}
uint64_t crc_length;
const unsigned int entry_count = utarray_len(index_entries);
for(unsigned int i = 0; i < entry_count; i++)
{
const unsigned int entry_count = utarray_len(index_entries);
IndexEntry *entry = utarray_eltptr(index_entries, i);
TRACE("Checking block with type %4.4s at position %" PRIu64, (char *)&entry->blockType, entry->offset);
for(unsigned int i = 0; i < entry_count; i++)
if(fseek(ctx->imageStream, entry->offset, SEEK_SET) != 0)
{
IndexEntry *entry = utarray_eltptr(index_entries, i);
TRACE("Checking block with type %4.4s at position %" PRIu64, (char *)&entry->blockType, entry->offset);
FATAL("Could not seek to block at offset %" PRIu64, entry->offset);
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(fseek(ctx->imageStream, entry->offset, SEEK_SET) != 0)
{
FATAL("Could not seek to block at offset %" PRIu64, entry->offset);
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
switch(entry->blockType)
{
case DataBlock:
read_bytes = fread(&block_header, 1, sizeof(BlockHeader), ctx->imageStream);
if(read_bytes != sizeof(BlockHeader))
{
FATAL("Could not read block header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, block_header.cmpLength, buffer, VERIFY_SIZE,
crc64_context, "data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for data block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != block_header.cmpCrc64)
{
FATAL("Expected block CRC 0x%16llX but got 0x%16llX", block_header.cmpCrc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
case DeDuplicationTable:
read_bytes = fread(&ddt_header, 1, sizeof(DdtHeader), ctx->imageStream);
if(read_bytes != sizeof(DdtHeader))
{
FATAL("Could not read DDT header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, ddt_header.cmpLength, buffer, VERIFY_SIZE,
crc64_context, "DDT block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for DDT block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != ddt_header.cmpCrc64)
{
FATAL("Expected DDT CRC 0x%16llX but got 0x%16llX", ddt_header.cmpCrc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
case DeDuplicationTable2:
read_bytes = fread(&ddt2_header, 1, sizeof(DdtHeader2), ctx->imageStream);
if(read_bytes != sizeof(DdtHeader2))
{
FATAL("Could not read DDT2 header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, ddt2_header.cmpLength, buffer, VERIFY_SIZE,
crc64_context, "DDT2 block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for DDT2 block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(crc64 != ddt2_header.cmpCrc64)
{
FATAL("Expected DDT2 CRC 0x%16llX but got 0x%16llX", ddt2_header.cmpCrc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
case TracksBlock:
switch(entry->blockType)
{
case DataBlock:
read_bytes = fread(&block_header, 1, sizeof(BlockHeader), ctx->imageStream);
if(read_bytes != sizeof(BlockHeader))
{
read_bytes = fread(&tracks_header, 1, sizeof(TracksHeader), ctx->imageStream);
if(read_bytes != sizeof(TracksHeader))
{
FATAL("Could not read tracks header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
const uint64_t tracks_bytes = (uint64_t)tracks_header.entries * sizeof(TrackEntry);
if(tracks_header.entries != 0 && tracks_bytes / sizeof(TrackEntry) != tracks_header.entries)
{
FATAL("Tracks header length overflow (entries=%u)", tracks_header.entries);
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, tracks_bytes, buffer, VERIFY_SIZE,
crc64_context, "tracks block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for tracks block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != tracks_header.crc64)
{
FATAL("Expected tracks CRC 0x%16llX but got 0x%16llX", tracks_header.crc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
FATAL("Could not read block header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
default:
TRACE("Ignoring block type %4.4s", (char *)&entry->blockType);
break;
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
// For LZMA compression, skip the 5-byte properties header
crc_length = block_header.cmpLength;
if(block_header.compression == Lzma || block_header.compression == LzmaClauniaSubchannelTransform)
{
// Skip LZMA properties
uint8_t props[LZMA_PROPERTIES_LENGTH];
size_t read_props = fread(props, 1, LZMA_PROPERTIES_LENGTH, ctx->imageStream);
if(read_props != LZMA_PROPERTIES_LENGTH)
{
FATAL("Could not read LZMA properties");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc_length -= LZMA_PROPERTIES_LENGTH;
}
status = update_crc64_from_stream(ctx->imageStream, crc_length, buffer, VERIFY_SIZE, crc64_context,
"data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for data block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != block_header.cmpCrc64)
{
FATAL("Expected block CRC 0x%16llX but got 0x%16llX", block_header.cmpCrc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
case DeDuplicationTable:
read_bytes = fread(&ddt_header, 1, sizeof(DdtHeader), ctx->imageStream);
if(read_bytes != sizeof(DdtHeader))
{
FATAL("Could not read DDT header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
// For LZMA compression, skip the 5-byte properties header
crc_length = ddt_header.cmpLength;
if(ddt_header.compression == Lzma || ddt_header.compression == LzmaClauniaSubchannelTransform)
{
// Skip LZMA properties
uint8_t props[LZMA_PROPERTIES_LENGTH];
size_t read_props = fread(props, 1, LZMA_PROPERTIES_LENGTH, ctx->imageStream);
if(read_props != LZMA_PROPERTIES_LENGTH)
{
FATAL("Could not read LZMA properties");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc_length -= LZMA_PROPERTIES_LENGTH;
}
status = update_crc64_from_stream(ctx->imageStream, crc_length, buffer, VERIFY_SIZE, crc64_context,
"data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for DDT block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != ddt_header.cmpCrc64)
{
FATAL("Expected DDT CRC 0x%16llX but got 0x%16llX", ddt_header.cmpCrc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
case DeDuplicationTable2:
read_bytes = fread(&ddt2_header, 1, sizeof(DdtHeader2), ctx->imageStream);
if(read_bytes != sizeof(DdtHeader2))
{
FATAL("Could not read DDT2 header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
// For LZMA compression, skip the 5-byte properties header
crc_length = ddt2_header.cmpLength;
if(ddt2_header.compression == Lzma || ddt2_header.compression == LzmaClauniaSubchannelTransform)
{
// Skip LZMA properties
uint8_t props[LZMA_PROPERTIES_LENGTH];
size_t read_props = fread(props, 1, LZMA_PROPERTIES_LENGTH, ctx->imageStream);
if(read_props != LZMA_PROPERTIES_LENGTH)
{
FATAL("Could not read LZMA properties");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc_length -= LZMA_PROPERTIES_LENGTH;
}
status = update_crc64_from_stream(ctx->imageStream, crc_length, buffer, VERIFY_SIZE, crc64_context,
"data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for DDT2 block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(crc64 != ddt2_header.cmpCrc64)
{
FATAL("Expected DDT2 CRC 0x%16llX but got 0x%16llX", ddt2_header.cmpCrc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
case TracksBlock:
{
read_bytes = fread(&tracks_header, 1, sizeof(TracksHeader), ctx->imageStream);
if(read_bytes != sizeof(TracksHeader))
{
FATAL("Could not read tracks header");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
const uint64_t tracks_bytes = (uint64_t)tracks_header.entries * sizeof(TrackEntry);
if(tracks_header.entries != 0 && tracks_bytes / sizeof(TrackEntry) != tracks_header.entries)
{
FATAL("Tracks header length overflow (entries=%u)", tracks_header.entries);
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc64_context = aaruf_crc64_init();
if(crc64_context == NULL)
{
FATAL("Could not initialize CRC64 context");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, tracks_bytes, buffer, VERIFY_SIZE, crc64_context,
"tracks block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
{
FATAL("Could not finalize CRC64 for tracks block");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != tracks_header.crc64)
{
FATAL("Expected tracks CRC 0x%16llX but got 0x%16llX", tracks_header.crc64, crc64);
status = AARUF_ERROR_INVALID_BLOCK_CRC;
goto cleanup;
}
aaruf_crc64_free(crc64_context);
crc64_context = NULL;
break;
}
default:
TRACE("Ignoring block type %4.4s", (char *)&entry->blockType);
break;
}
}

View File

@@ -130,7 +130,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_
return AARUF_READ_ONLY;
}
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1)
if(negative && sector_address > ctx->user_data_ddt_header.negative)
{
FATAL("Sector address out of bounds");
@@ -569,7 +569,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_long(void *context, uint64_t se
return AARUF_READ_ONLY;
}
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1)
if(negative && sector_address > ctx->user_data_ddt_header.negative)
{
FATAL("Sector address out of bounds");
@@ -604,7 +604,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_long(void *context, uint64_t se
// Calculate positive or negative sector
if(negative)
corrected_sector_address -= ctx->user_data_ddt_header.negative;
corrected_sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
corrected_sector_address += ctx->user_data_ddt_header.negative;
@@ -2101,7 +2101,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_tag(void *context, const uint64
return AARUF_READ_ONLY;
}
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1)
if(negative && sector_address > ctx->user_data_ddt_header.negative)
{
FATAL("Sector address out of bounds");
@@ -2127,7 +2127,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_tag(void *context, const uint64
// Calculate positive or negative sector
if(negative)
corrected_sector_address -= ctx->user_data_ddt_header.negative;
corrected_sector_address = ctx->user_data_ddt_header.negative - sector_address;
else
corrected_sector_address += ctx->user_data_ddt_header.negative;

View File

@@ -576,7 +576,18 @@ enum MediaType : u32
ODC1200RE = 783,
ODC1500R = 784,
ODC3300R = 785,
ODC5500R = 786
ODC5500R = 786,
ECMA_322_1k = 800,
ECMA_322_512 = 801,
ISO_14517 = 802,
ISO_14517_512 = 803,
ISO_15041_512 = 804,
HSM650 = 805,
MetaFloppy_Mod_I = 820,
HF12 = 823,
HF24 = 824,
};
enum CompressionType : u16

View File

@@ -738,3 +738,120 @@ TEST_F(CreateImageFixture, create_audio_image)
close_result = aaruf_close(context);
EXPECT_EQ(close_result, AARUF_STATUS_OK) << "Failed to close image";
}
TEST_F(CreateImageFixture, create_image_negative_sectors)
{
char path[PATH_MAX];
char filename[PATH_MAX];
getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/random", path);
// Open random file
FILE *f = fopen(filename, "rb");
ASSERT_NE(f, nullptr) << "Failed to open random data file";
uint8_t *buffer = static_cast<uint8_t *>(malloc(1048576));
fread(buffer, 1, 1048576, f);
fclose(f);
constexpr size_t total_sectors = 128 * 1024 * 1024 / 512; // 128 MiB / 512 bytes
// Create image
void *context = aaruf_create("test.aif", 1, 512, total_sectors, 300, 0, "deduplicate=true;compress=true",
reinterpret_cast<const uint8_t *>("gtest"), 10, 0, 0, false);
// Verify that the file was successfully opened
ASSERT_NE(context, nullptr) << "Failed to create test.aif";
crc64_ctx *ctx = aaruf_crc64_init();
uint64_t generated_crc = 0;
// Write data in sectors of 512 bytes
for(size_t sector = 1; sector <= 150; ++sector)
{
const size_t buffer_offset = sector * 512 % 1048576; // Roll back to start when reaching end
const int32_t write_result =
aaruf_write_sector(context, sector, true, buffer + buffer_offset, SectorStatusDumped, 512);
ASSERT_EQ(write_result, AARUF_STATUS_OK) << "Failed to write negative sector " << sector;
aaruf_crc64_update(ctx, buffer + buffer_offset, 512);
}
// Write data in sectors of 512 bytes
for(size_t sector = 0; sector < total_sectors; ++sector)
{
const size_t buffer_offset = sector * 512 % 1048576; // Roll back to start when reaching end
const int32_t write_result =
aaruf_write_sector(context, sector, false, buffer + buffer_offset, SectorStatusDumped, 512);
ASSERT_EQ(write_result, AARUF_STATUS_OK) << "Failed to write sector " << sector;
aaruf_crc64_update(ctx, buffer + buffer_offset, 512);
}
aaruf_crc64_final(ctx, &generated_crc);
aaruf_crc64_free(ctx);
// Close the image
int32_t close_result = aaruf_close(context);
ASSERT_EQ(close_result, AARUF_STATUS_OK) << "Failed to close image";
free(buffer);
// Reopen the image
context = aaruf_open("test.aif", false, NULL);
ASSERT_NE(context, nullptr) << "Failed to open test.aif";
// Get image info to verify it's a valid image
ImageInfo image_info;
const int32_t result = aaruf_get_image_info(context, &image_info);
ASSERT_EQ(result, AARUF_STATUS_OK) << "Failed to get image info";
// Basic sanity checks on the image info
ASSERT_EQ(image_info.HasPartitions, false) << "Image should not have partitions";
ASSERT_EQ(image_info.HasSessions, false) << "Image should not have sessions";
ASSERT_EQ(image_info.Sectors, total_sectors) << "Unexpected number of sectors";
ASSERT_EQ(image_info.SectorSize, 512) << "Unexpected sector size";
ASSERT_STREQ(image_info.Version, "2.0") << "Unexpected image version";
ASSERT_STREQ(image_info.Application, "gtest") << "Unexpected application name";
ASSERT_STREQ(image_info.ApplicationVersion, "0.0") << "Unexpected application version";
ASSERT_EQ(image_info.MediaType, 1) << "Unexpected media type";
ASSERT_EQ(image_info.MetadataMediaType, 1) << "Unexpected metadata media type";
ctx = aaruf_crc64_init();
uint64_t crc = 0;
for(int i = 1; i <= 150; i++)
{
uint8_t sector_buffer[512];
uint32_t length = sizeof(sector_buffer);
uint8_t sector_status = 0;
const int32_t read_result = aaruf_read_sector(context, i, true, sector_buffer, &length, &sector_status);
EXPECT_EQ(read_result, AARUF_STATUS_OK) << "Failed to read negative sector " << i;
EXPECT_EQ(length, 512U) << "Unexpected length for negative sector " << i;
aaruf_crc64_update(ctx, sector_buffer, 512);
}
for(int i = 0; i < total_sectors; i++)
{
uint8_t sector_buffer[512];
uint32_t length = sizeof(sector_buffer);
uint8_t sector_status = 0;
const int32_t read_result = aaruf_read_sector(context, i, false, sector_buffer, &length, &sector_status);
EXPECT_EQ(read_result, AARUF_STATUS_OK) << "Failed to read sector " << i;
EXPECT_EQ(length, 512U) << "Unexpected length for sector " << i;
aaruf_crc64_update(ctx, sector_buffer, 512);
}
aaruf_crc64_final(ctx, &crc);
aaruf_crc64_free(ctx);
ASSERT_EQ(crc, generated_crc) << "Unexpected CRC64 for image data";
// Close the image
close_result = aaruf_close(context);
EXPECT_EQ(close_result, AARUF_STATUS_OK) << "Failed to close image";
}

View File

@@ -24,14 +24,14 @@
char *byte_array_to_hex_string(const unsigned char *array, int array_size)
{
char *hex_string = NULL;
int j = 0;
int j = 0;
hex_string = malloc(array_size * 2 + 1);
if(hex_string == NULL) return NULL;
j = 0;
for (int i = 0; i < array_size; i++)
for(int i = 0; i < array_size; i++)
{
hex_string[j] = (array[i] >> 4) + '0';
if(hex_string[j] > '9') hex_string[j] += 0x7;
@@ -1109,6 +1109,84 @@ const char *media_type_to_string(MediaType type)
case VideoNowXp:
return "VideoNow XP";
// Iomega, types 750 to 759
case Bernoulli10:
return "Bernoulli Box (10Mb)";
case Bernoulli20:
return "Bernoulli Box (20Mb)";
case BernoulliBox2_20:
return "Bernoulli Box II (20Mb)";
// Kodak, types 760 to 769
case KodakVerbatim3:
return "Kodak/Verbatim (3Mb)";
case KodakVerbatim6:
return "Kodak/Verbatim (6Mb)";
case KodakVerbatim12:
return "Kodak/Verbatim (12Mb)";
// Sony and Panasonic Blu-ray derived, types 770 to 799
case ProfessionalDisc:
return "Professional Disc for video";
case ProfessionalDiscDual:
return "Professional Disc for video";
case ProfessionalDiscTriple:
return "Professional Disc for video";
case ProfessionalDiscQuad:
return "Professional Disc for video";
case PDD:
return "Professional Disc for DATA";
case PDD_WORM:
return "Professional Disc for DATA";
case ArchivalDisc:
return "Archival Disc";
case ArchivalDisc2:
return "Archival Disc";
case ArchivalDisc3:
return "Archival Disc";
case ODC300R:
return "Optical Disc archive";
case ODC300RE:
return "Optical Disc archive";
case ODC600R:
return "Optical Disc archive";
case ODC600RE:
return "Optical Disc archive";
case ODC1200RE:
return "Optical Disc archive";
case ODC1500R:
return "Optical Disc archive";
case ODC3300R:
return "Optical Disc archive";
case ODC5500R:
return "Optical Disc archive";
// Magneto-optical, types 800 to 819
case ECMA_322_1k:
return "5,25\", M.O., 4383356 sectors, 1024 bytes/sector, ECMA-322, ISO 22092, 9.1Gb/cart";
case ECMA_322_512:
return "5,25\", M.O., ??????? sectors, 512 bytes/sector, ECMA-322, ISO 22092, 9.1Gb/cart";
case ISO_14517:
return "5,25\", M.O., 1273011 sectors, 1024 bytes/sector, ISO 14517, 2.6Gb/cart";
case ISO_14517_512:
return "5,25\", M.O., 2244958 sectors, 512 bytes/sector, ISO 14517, 2.3Gb/cart";
case ISO_15041_512:
return "3,5\", M.O., 1041500 sectors, 512 bytes/sector, ISO 15041, 540Mb/cart";
case HSM650:
return "Sony HyperStorage";
// More floppy formats, types 820 to deprecated
case MetaFloppy_Mod_I:
return "5.25\", SS, DD, 35 tracks, 16 spt, 256 bytes/sector, MFM, 48 tpi, ???rpm";
case HF12:
return "HyperFlex (12Mb)";
case HF24:
return "HyperFlex (24Mb)";
case AtariLynxCard:
return "Atari Lynx card";
case AtariJaguarCartridge:
return "Atari Jaguar cartridge";
default:
return "Unknown Media Type";
}

View File

@@ -48,7 +48,10 @@ static const char *format_filetime(uint64_t filetime)
snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute,
st.wSecond);
}
else { snprintf(buf, sizeof(buf), "%llu", filetime); }
else
{
snprintf(buf, sizeof(buf), "%llu", filetime);
}
return buf;
#else
time_t t;
@@ -132,285 +135,272 @@ int info(const char *path)
int32_t sequence = 0;
int32_t lastSequence = 0;
printf("Metadata block:\n");
if(aaruf_get_media_sequence(ctx, &sequence, &lastSequence) == AARUF_STATUS_OK && sequence > 0)
{
printf("Metadata block:\n");
printf("\tMedia is no. %d in a set of %d media\n", sequence, lastSequence);
int32_t length = 0;
if(aaruf_get_creator(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
}
int32_t length = 0;
if(aaruf_get_creator(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_creator(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_creator(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tCreator: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tCreator: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_comments(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_comments(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_comments(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_comments(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tComments: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tComments: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_media_title(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_media_title(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_media_title(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_media_title(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia title: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia title: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_media_manufacturer(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_media_manufacturer(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_media_manufacturer(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_media_manufacturer(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia manufacturer: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia manufacturer: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_media_model(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_media_model(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_media_model(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_media_model(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia model: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia model: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_media_serial_number(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_media_serial_number(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_media_serial_number(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_media_serial_number(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia serial number: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia serial number: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_media_barcode(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_media_barcode(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_media_barcode(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_media_barcode(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia barcode: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia barcode: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_media_part_number(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_media_part_number(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_media_part_number(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_media_part_number(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia part number: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tMedia part number: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_drive_manufacturer(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_drive_manufacturer(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_drive_manufacturer(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_drive_manufacturer(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive manufacturer: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive manufacturer: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_drive_model(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_drive_model(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_drive_model(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_drive_model(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive model: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive model: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_drive_serial_number(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_drive_serial_number(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_drive_serial_number(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_drive_serial_number(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive serial number: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive serial number: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
length = 0;
if(aaruf_get_drive_firmware_revision(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
length = 0;
if(aaruf_get_drive_firmware_revision(ctx, NULL, &length) == AARUF_ERROR_BUFFER_TOO_SMALL && length > 0)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
{
uint8_t *utf16Buffer = malloc(length);
if(utf16Buffer != NULL)
if(aaruf_get_drive_firmware_revision(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
{
if(aaruf_get_drive_firmware_revision(ctx, utf16Buffer, &length) == AARUF_STATUS_OK)
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
strBuffer = malloc(length + 1);
if(strBuffer != NULL)
{
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length,
&u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive firmware revision: %s\n", strBuffer);
free(strBuffer);
}
memset(strBuffer, 0, length + 1);
u_error_code = U_ZERO_ERROR;
ucnv_convert(NULL, "UTF-16LE", strBuffer, length, (const char *)utf16Buffer, length, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tDrive firmware revision: %s\n", strBuffer);
free(strBuffer);
}
free(utf16Buffer);
}
free(utf16Buffer);
}
}
@@ -576,16 +566,7 @@ int info(const char *path)
printf("\tImage contains %llu sectors\n", ctx->image_info.Sectors);
printf("\tBiggest sector is %d bytes\n", ctx->image_info.SectorSize);
printf("\tImage version: %s\n", ctx->image_info.Version);
if(ctx->image_info.Application != NULL)
{
strBuffer = malloc(65);
memset(strBuffer, 0, 65);
ucnv_convert(NULL, "UTF-16LE", strBuffer, 64, (const char *)ctx->image_info.Application, 64, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tApplication: %s\n", strBuffer);
free(strBuffer);
}
if(ctx->image_info.Application != NULL) printf("\tApplication: %s\n", ctx->image_info.Application);
if(ctx->image_info.ApplicationVersion != NULL)
printf("\tApplication version: %s\n", ctx->image_info.ApplicationVersion);
printf("\tCreation time: %s\n", format_filetime(ctx->image_info.CreationTime));
@@ -620,9 +601,7 @@ int info(const char *path)
{
printf("Media tags:\n");
HASH_ITER(hh, ctx->mediaTags, mediaTag, tmpMediaTag)
{
printf("\tType %d is %d bytes long.\n", mediaTag->type, mediaTag->length);
}
{ printf("\tType %d is %d bytes long.\n", mediaTag->type, mediaTag->length); }
}
aaruf_close(ctx);