Add sector status parameter to read sector functions

This commit is contained in:
2025-10-11 12:42:32 +01:00
parent e78ecff7fa
commit dde81f6773
7 changed files with 75 additions and 51 deletions

View File

@@ -40,6 +40,8 @@ int cli_compare(const char *path1, const char *path2, bool use_long)
int result = 0;
int32_t read_result1 = 0;
int32_t read_result2 = 0;
uint8_t sector_status1 = 0;
uint8_t sector_status2 = 0;
printf("Opening first image: %s\n", path1);
ctx1 = aaruf_open(path1);
@@ -115,13 +117,13 @@ int cli_compare(const char *path1, const char *path2, bool use_long)
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);
read_result1 = aaruf_read_sector_long(ctx1, sector, false, buffer1, &buffer1_length, &sector_status1);
read_result2 = aaruf_read_sector_long(ctx2, sector, false, buffer2, &buffer2_length, &sector_status2);
}
else
{
read_result1 = aaruf_read_sector(ctx1, sector, false, buffer1, &buffer1_length);
read_result2 = aaruf_read_sector(ctx2, sector, false, buffer2, &buffer2_length);
read_result1 = aaruf_read_sector(ctx1, sector, false, buffer1, &buffer1_length, &sector_status1);
read_result2 = aaruf_read_sector(ctx2, sector, false, buffer2, &buffer2_length, &sector_status2);
}
// Handle read errors or missing sectors
@@ -139,6 +141,11 @@ int cli_compare(const char *path1, const char *path2, bool use_long)
// One sector is available, the other is not - they're different
sectors_different = true;
}
else if(sector_status1 != sector_status2)
{
// Both sectors are available but have different status codes
sectors_different = true;
}
else if(sector1_available && sector2_available &&
(buffer1_length != buffer2_length || memcmp(buffer1, buffer2, buffer1_length) != 0))
{

View File

@@ -62,6 +62,8 @@ int compare(const char *path1, const char *path2)
uintattr_t sectorsColor = TB_WHITE;
uintattr_t sectorSizeColor = TB_WHITE;
uintattr_t versionColor = TB_WHITE;
uint8_t sector_status1 = 0;
uint8_t sector_status2 = 0;
// Initialize termbox2
if(tb_init() != 0) return 1;
@@ -489,7 +491,7 @@ int compare(const char *path1, const char *path2)
tb_printf(2, height - 5, TB_WHITE | TB_BOLD, TB_BLUE, "Comparing sector %llu of %llu", i + 1, sectors);
draw_progress_bar(height - 4, i * 100 / sectors);
errno = aaruf_read_sector(ctx1, i, false, buffer1, &sectorSize);
errno = aaruf_read_sector(ctx1, i, false, buffer1, &sectorSize, &sector_status1);
if(errno != AARUF_STATUS_OK && errno != AARUF_STATUS_SECTOR_NOT_DUMPED)
{
tb_printf(2, lr++, TB_RED | TB_BOLD, TB_BLUE, "Error reading sector %llu: %s", i, errno);
@@ -497,7 +499,7 @@ int compare(const char *path1, const char *path2)
continue;
}
errno = aaruf_read_sector(ctx2, i, false, buffer2, &sectorSize);
errno = aaruf_read_sector(ctx2, i, false, buffer2, &sectorSize, &sector_status2);
if(errno != AARUF_STATUS_OK && errno != AARUF_STATUS_SECTOR_NOT_DUMPED)
{
tb_printf(2, rr++, TB_RED | TB_BOLD, TB_BLUE, "Error reading sector %llu: %s", i, errno);

View File

@@ -36,6 +36,7 @@ int convert(const char *input_path, const char *output_path, bool use_long)
uint32_t sector_size = 0;
uint64_t total_sectors = 0;
uint8_t *sector_data = NULL;
uint8_t sector_status = 0;
printf("Converting image from %s to %s%s...\n", input_path, output_path, use_long ? " (long mode)" : "");
@@ -182,9 +183,9 @@ int convert(const char *input_path, const char *output_path, bool use_long)
// Check sector size
if(use_long)
res = aaruf_read_sector_long(input_ctx, sector, false, sector_data, &read_length);
res = aaruf_read_sector_long(input_ctx, sector, false, sector_data, &read_length, &sector_status);
else
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length);
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length, &sector_status);
if(res != AARUF_ERROR_BUFFER_TOO_SMALL)
{
@@ -208,9 +209,9 @@ int convert(const char *input_path, const char *output_path, bool use_long)
// Read sector from input
if(use_long)
res = aaruf_read_sector_long(input_ctx, sector, false, sector_data, &read_length);
res = aaruf_read_sector_long(input_ctx, sector, false, sector_data, &read_length, &sector_status);
else
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length);
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length, &sector_status);
if(res != AARUF_STATUS_OK)
{
@@ -220,9 +221,9 @@ int convert(const char *input_path, const char *output_path, bool use_long)
// Write sector to output
if(use_long)
res = aaruf_write_sector_long(output_ctx, sector, false, sector_data, SectorStatusDumped, read_length);
res = aaruf_write_sector_long(output_ctx, sector, false, sector_data, sector_status, read_length);
else
res = aaruf_write_sector(output_ctx, sector, false, sector_data, SectorStatusDumped, read_length);
res = aaruf_write_sector(output_ctx, sector, false, sector_data, sector_status, read_length);
if(res != AARUF_STATUS_OK)
{

View File

@@ -26,10 +26,11 @@
int read(const unsigned long long sector_no, const char *path)
{
aaruformat_context *ctx = NULL;
int32_t res = 0;
uint32_t length = 0;
uint8_t *data = NULL;
aaruformat_context *ctx = NULL;
int32_t res = 0;
uint32_t length = 0;
uint8_t *data = NULL;
uint8_t sector_status = 0;
ctx = aaruf_open(path);
@@ -39,7 +40,7 @@ int read(const unsigned long long sector_no, const char *path)
return errno;
}
res = aaruf_read_sector(ctx, sector_no, false, NULL, &length);
res = aaruf_read_sector(ctx, sector_no, false, NULL, &length, &sector_status);
if(res != AARUF_STATUS_OK && res != AARUF_ERROR_BUFFER_TOO_SMALL)
{
@@ -58,7 +59,7 @@ int read(const unsigned long long sector_no, const char *path)
return AARUF_ERROR_NOT_ENOUGH_MEMORY;
}
res = aaruf_read_sector(ctx, sector_no, false, data, &length);
res = aaruf_read_sector(ctx, sector_no, false, data, &length, &sector_status);
if(res != AARUF_STATUS_OK)
{
@@ -78,10 +79,11 @@ int read(const unsigned long long sector_no, const char *path)
int read_long(const unsigned long long sector_no, const char *path)
{
aaruformat_context *ctx = NULL;
int32_t res = 0;
uint32_t length = 0;
uint8_t *data = NULL;
aaruformat_context *ctx = NULL;
int32_t res = 0;
uint32_t length = 0;
uint8_t *data = NULL;
uint8_t sector_status = 0;
ctx = aaruf_open(path);
@@ -91,7 +93,7 @@ int read_long(const unsigned long long sector_no, const char *path)
return errno;
}
res = aaruf_read_sector_long(ctx, sector_no, false, NULL, &length);
res = aaruf_read_sector_long(ctx, sector_no, false, NULL, &length, &sector_status);
if(res != AARUF_STATUS_OK && res != AARUF_ERROR_BUFFER_TOO_SMALL)
{
@@ -110,7 +112,7 @@ int read_long(const unsigned long long sector_no, const char *path)
return AARUF_ERROR_NOT_ENOUGH_MEMORY;
}
res = aaruf_read_sector_long(ctx, sector_no, false, data, &length);
res = aaruf_read_sector_long(ctx, sector_no, false, data, &length, &sector_status);
if(res != AARUF_STATUS_OK)
{

View File

@@ -20,6 +20,7 @@
#include <errno.h>
#include <aaruformat.h>
#include <sys/types.h>
#include "aaruformattool.h"
@@ -61,7 +62,8 @@ int verify_sectors(const char *path)
bool edc_correct = false;
bool unknown = false;
uint64_t errors = 0, unknowns = 0;
bool any_error = false;
bool any_error = false;
uint8_t sector_status = 0;
if(ctx == NULL)
{
@@ -83,7 +85,7 @@ int verify_sectors(const char *path)
for(uint64_t s = 0; s < ctx->image_info.Sectors; s++)
{
printf("\rVerifying sector %llu...", s);
res = aaruf_read_sector_long(ctx, s, buffer, false, &buffer_len);
res = aaruf_read_sector_long(ctx, s, buffer, false, &buffer_len, &sector_status);
if(res != AARUF_STATUS_OK)
{