Add long sector read support to cli_compare command

This commit is contained in:
2025-10-10 22:06:00 +01:00
parent 258d132fbf
commit c4e5b51e6a
4 changed files with 29 additions and 11 deletions

View File

@@ -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_

View File

@@ -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;

View File

@@ -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, "<filename1>", "First image to compare");
struct arg_str *filename2 = arg_str1(NULL, NULL, "<filename2>", "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;
}

View File

@@ -117,11 +117,13 @@ void usage_compare()
void usage_cli_compare()
{
printf("\nUsage:\n");
printf(" aaruformattool cli-compare <filename1> <filename2>\n\n");
printf(" aaruformattool cli-compare [-l] <filename1> <filename2>\n\n");
printf("Compares two AaruFormat images sector by sector and lists all different sectors.\n");
printf("Arguments:\n");
printf(" <filename1> Path to first image file.\n");
printf(" <filename2> Path to second image file.\n");
printf("Options:\n");
printf(" -l Use long sector read (includes tags and metadata).\n");
}
void usage_convert()