mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Implement image verification.
This commit is contained in:
@@ -4,5 +4,5 @@ find_package(ICU COMPONENTS uc REQUIRED)
|
||||
|
||||
include_directories(${ICU_INCLUDE_DIRS})
|
||||
|
||||
add_executable(aaruformattool main.c main.h aaruformattool.h identify.c info.c helpers.c read.c printhex.c)
|
||||
add_executable(aaruformattool main.c main.h aaruformattool.h identify.c info.c helpers.c read.c printhex.c verify.c)
|
||||
target_link_libraries(aaruformattool "aaruformat" ICU::uc)
|
||||
|
||||
@@ -27,5 +27,6 @@ char* byte_array_to_hex_string(const unsigned char* array, int array_size);
|
||||
int read(unsigned long long sector_no, char* path);
|
||||
int printhex(unsigned char* array, unsigned int length, int width, bool color);
|
||||
int read_long(unsigned long long sector_no, char* path);
|
||||
int verify(char* path);
|
||||
|
||||
#endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
||||
|
||||
30
tool/main.c
30
tool/main.c
@@ -37,6 +37,7 @@ void usage()
|
||||
printf("\tinfo\tPrints information about a given AaruFormat image.\n");
|
||||
printf("\tread\tReads a sector and prints it out on screen.\n");
|
||||
printf("\tread_long\tReads a sector with all its prefixes and suffixes and prints it out on screen.\n");
|
||||
printf("\tverify\tVerifies the integrity of all blocks in a AaruFormat image.\n");
|
||||
printf("\n");
|
||||
printf("For help on the verb invoke the tool with the verb and no arguments.\n");
|
||||
}
|
||||
@@ -87,6 +88,17 @@ void usage_read_long()
|
||||
printf("\t<filename>\tPath to AaruFormat image to print information from.\n");
|
||||
}
|
||||
|
||||
void usage_verify()
|
||||
{
|
||||
printf("\n");
|
||||
printf("Usage:\n");
|
||||
printf("aaruformattool verify <filename>\n");
|
||||
printf("Verifies the integrity of all blocks in a AaruFormat image.\n");
|
||||
printf("\n");
|
||||
printf("Arguments:\n");
|
||||
printf("\t<filename>\tPath to AaruFormat image to verify.\n");
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
uint64_t sector_no = 0;
|
||||
@@ -195,5 +207,23 @@ int main(int argc, char* argv[])
|
||||
return read(sector_no, argv[3]);
|
||||
}
|
||||
|
||||
if(strncmp(argv[1], "verify", strlen("verify")) == 0)
|
||||
{
|
||||
if(argc == 2)
|
||||
{
|
||||
usage_verify();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(argc > 3)
|
||||
{
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
usage_verify();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return verify(argv[2]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
46
tool/verify.c
Normal file
46
tool/verify.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of the Aaru Data Preservation Suite.
|
||||
* Copyright (c) 2019-2022 Natalia Portillo.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
int verify(char* path)
|
||||
{
|
||||
aaruformatContext* ctx;
|
||||
uint32_t res;
|
||||
|
||||
ctx = aaruf_open(path);
|
||||
|
||||
if(ctx == NULL)
|
||||
{
|
||||
printf("Error %d when opening AaruFormat image.\n", errno);
|
||||
return errno;
|
||||
}
|
||||
|
||||
res = aaruf_verify_image(ctx);
|
||||
|
||||
if(res == AARUF_STATUS_OK) printf("Image blocks contain no errors.\n");
|
||||
else if(res == AARUF_ERROR_INVALID_BLOCK_CRC)
|
||||
printf("A block contains an invalid CRC value.\n");
|
||||
else
|
||||
printf("Error %d verifying image.\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user