mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Implement sector verification in tool.
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
#include "aaruformattool.h"
|
||||
|
||||
int verify(char* path)
|
||||
{
|
||||
aaruformatContext* ctx;
|
||||
@@ -43,4 +45,87 @@ int verify(char* path)
|
||||
printf("Error %d verifying image.\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int verify_sectors(char* path)
|
||||
{
|
||||
aaruformatContext* ctx;
|
||||
uint64_t s;
|
||||
uint8_t* buffer;
|
||||
uint32_t buffer_len = 2352;
|
||||
int32_t res;
|
||||
CdEccContext* cd_ecc_context;
|
||||
ctx = aaruf_open(path);
|
||||
bool verify_result;
|
||||
bool unknown, has_edc, edc_correct, has_ecc_p, ecc_p_correct, has_ecc_q, ecc_q_correct;
|
||||
uint64_t errors, unknowns;
|
||||
bool any_error;
|
||||
|
||||
if(ctx == NULL)
|
||||
{
|
||||
printf("Error %d when opening AaruFormat image.\n", errno);
|
||||
return errno;
|
||||
}
|
||||
|
||||
if(ctx->imageInfo.XmlMediaType != OpticalDisc)
|
||||
{
|
||||
printf("Image sectors do not contain checksums, cannot verify.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cd_ecc_context = aaruf_ecc_cd_init();
|
||||
errors = 0;
|
||||
unknown = 0;
|
||||
any_error = false;
|
||||
|
||||
for(s = 0; s < ctx->imageInfo.Sectors; s++)
|
||||
{
|
||||
printf("\rVerifying sector %lu...", s);
|
||||
res = aaruf_read_sector_long(ctx, s, buffer, &buffer_len);
|
||||
|
||||
if(res != AARUF_STATUS_OK)
|
||||
{
|
||||
fprintf(stderr, "\rError %d reading sector %lu\n.", res, s);
|
||||
continue;
|
||||
}
|
||||
|
||||
verify_result = check_cd_sector_channel(cd_ecc_context,
|
||||
buffer,
|
||||
&unknown,
|
||||
&has_edc,
|
||||
&edc_correct,
|
||||
&has_ecc_p,
|
||||
&ecc_p_correct,
|
||||
&has_ecc_q,
|
||||
&ecc_q_correct);
|
||||
|
||||
if(verify_result) continue;
|
||||
|
||||
if(unknown)
|
||||
{
|
||||
unknowns++;
|
||||
printf("\rSector %lu cannot be verified.\n", s);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(has_edc && !edc_correct) printf("\rSector %lu has an incorrect EDC value.\n", s);
|
||||
|
||||
if(has_ecc_p && !ecc_p_correct) printf("\rSector %lu has an incorrect EDC value.\n", s);
|
||||
|
||||
if(has_ecc_q && !ecc_q_correct) printf("\rSector %lu has an incorrect EDC value.\n", s);
|
||||
|
||||
errors++;
|
||||
any_error = true;
|
||||
}
|
||||
|
||||
if(any_error) printf("\rSome sectors had incorrect checksums.\n");
|
||||
else
|
||||
printf("\rAll sector checksums are correct.\n");
|
||||
|
||||
printf("Total sectors........... %lu\n", ctx->imageInfo.Sectors);
|
||||
printf("Total errors............ %lu\n", errors);
|
||||
printf("Total unknowns.......... %lu\n", unknowns);
|
||||
printf("Total errors+unknowns... %lu\n", errors + unknowns);
|
||||
|
||||
return AARUF_STATUS_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user