From c4e5b51e6a1a4a0502bc8fb101cea248d1971fd0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 10 Oct 2025 22:06:00 +0100 Subject: [PATCH] Add long sector read support to cli_compare command --- tool/aaruformattool.h | 2 +- tool/cli_compare.c | 29 ++++++++++++++++++++++------- tool/commands.c | 5 +++-- tool/usage.c | 4 +++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/tool/aaruformattool.h b/tool/aaruformattool.h index fdeccf5..f9c4fe4 100644 --- a/tool/aaruformattool.h +++ b/tool/aaruformattool.h @@ -36,7 +36,7 @@ bool check_cd_sector_channel(CdEccContext *context, const uint8_t *sector bool *edc_correct, bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct); int compare(const char *path1, const char *path2); -int cli_compare(const char *path1, const char *path2); +int cli_compare(const char *path1, const char *path2, bool use_long); int convert(const char *input_path, const char *output_path, bool use_long); #endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_ diff --git a/tool/cli_compare.c b/tool/cli_compare.c index 9caf343..346226f 100644 --- a/tool/cli_compare.c +++ b/tool/cli_compare.c @@ -26,7 +26,7 @@ #include "aaruformattool.h" -int cli_compare(const char *path1, const char *path2) +int cli_compare(const char *path1, const char *path2, bool use_long) { aaruformat_context *ctx1 = NULL; aaruformat_context *ctx2 = NULL; @@ -65,6 +65,11 @@ int cli_compare(const char *path1, const char *path2) printf("Image 2: %llu sectors, %u bytes per sector\n", (unsigned long long)ctx2->image_info.Sectors, ctx2->image_info.SectorSize); + if(use_long) + printf("Mode: Long sector read (including tags and metadata)\n"); + else + printf("Mode: Normal sector read\n"); + if(ctx1->image_info.Sectors != ctx2->image_info.Sectors) { fprintf(stderr, "Warning: Images have different number of sectors\n"); @@ -84,8 +89,10 @@ int cli_compare(const char *path1, const char *path2) } // Allocate buffers for sector data - buffer1 = malloc(ctx1->image_info.SectorSize); - buffer2 = malloc(ctx2->image_info.SectorSize); + // For long mode, we need larger buffers to accommodate tags and metadata + uint32_t buffer_size = use_long ? ctx1->image_info.SectorSize * 2 : ctx1->image_info.SectorSize; + buffer1 = malloc(buffer_size); + buffer2 = malloc(buffer_size); if(buffer1 == NULL || buffer2 == NULL) { fprintf(stderr, "Error: Could not allocate memory for sector buffers\n"); @@ -103,11 +110,19 @@ int cli_compare(const char *path1, const char *path2) // Compare sectors for(uint64_t sector = 0; sector < total_sectors; sector++) { - buffer1_length = ctx1->image_info.SectorSize; - buffer2_length = ctx2->image_info.SectorSize; + buffer1_length = buffer_size; + buffer2_length = buffer_size; - read_result1 = aaruf_read_sector(ctx1, sector, false, buffer1, &buffer1_length); - read_result2 = aaruf_read_sector(ctx2, sector, false, buffer2, &buffer2_length); + if(use_long) + { + read_result1 = aaruf_read_sector_long(ctx1, sector, false, buffer1, &buffer1_length); + read_result2 = aaruf_read_sector_long(ctx2, sector, false, buffer2, &buffer2_length); + } + else + { + read_result1 = aaruf_read_sector(ctx1, sector, false, buffer1, &buffer1_length); + read_result2 = aaruf_read_sector(ctx2, sector, false, buffer2, &buffer2_length); + } // Handle read errors or missing sectors const bool sector1_available = read_result1 == AARUF_STATUS_OK; diff --git a/tool/commands.c b/tool/commands.c index da2b4f3..3d950c1 100644 --- a/tool/commands.c +++ b/tool/commands.c @@ -85,10 +85,11 @@ int cmd_compare(int argc, char *argv[]) int cmd_cli_compare(int argc, char *argv[]) { + struct arg_lit *use_long = arg_lit0("l", NULL, "Use long sector read/write (includes tags and metadata)"); struct arg_str *filename1 = arg_str1(NULL, NULL, "", "First image to compare"); struct arg_str *filename2 = arg_str1(NULL, NULL, "", "Second image to compare"); struct arg_end *end = arg_end(10); - void *argtable[] = {filename1, filename2, end}; + void *argtable[] = {use_long, filename1, filename2, end}; if(arg_parse(argc, argv, argtable) > 0) { @@ -98,7 +99,7 @@ int cmd_cli_compare(int argc, char *argv[]) return -1; } - const int result = cli_compare(filename1->sval[0], filename2->sval[0]); + const int result = cli_compare(filename1->sval[0], filename2->sval[0], use_long->count > 0); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return result; } diff --git a/tool/usage.c b/tool/usage.c index 7c94e6b..0c8a839 100644 --- a/tool/usage.c +++ b/tool/usage.c @@ -117,11 +117,13 @@ void usage_compare() void usage_cli_compare() { printf("\nUsage:\n"); - printf(" aaruformattool cli-compare \n\n"); + printf(" aaruformattool cli-compare [-l] \n\n"); printf("Compares two AaruFormat images sector by sector and lists all different sectors.\n"); printf("Arguments:\n"); printf(" Path to first image file.\n"); printf(" Path to second image file.\n"); + printf("Options:\n"); + printf(" -l Use long sector read (includes tags and metadata).\n"); } void usage_convert()