mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 11:14:39 +00:00
Add support for long sector read/write in convert command
This commit is contained in:
@@ -37,6 +37,6 @@ bool check_cd_sector_channel(CdEccContext *context, const uint8_t *sector
|
||||
bool *ecc_q_correct);
|
||||
int compare(const char *path1, const char *path2);
|
||||
int cli_compare(const char *path1, const char *path2);
|
||||
int convert(const char *input_path, const char *output_path);
|
||||
int convert(const char *input_path, const char *output_path, bool use_long);
|
||||
|
||||
#endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
||||
|
||||
@@ -155,10 +155,11 @@ int cmd_verify_sectors(int argc, char *argv[]) { return cmd_verify_common(argc,
|
||||
|
||||
int cmd_convert(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 *input_filename = arg_str1(NULL, NULL, "<input>", "Input image file");
|
||||
struct arg_str *output_filename = arg_str1(NULL, NULL, "<output>", "Output image file");
|
||||
struct arg_end *end = arg_end(10);
|
||||
void *argtable[] = {input_filename, output_filename, end};
|
||||
void *argtable[] = {use_long, input_filename, output_filename, end};
|
||||
|
||||
if(arg_parse(argc, argv, argtable) > 0)
|
||||
{
|
||||
@@ -168,7 +169,7 @@ int cmd_convert(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int result = convert(input_filename->sval[0], output_filename->sval[0]);
|
||||
const int result = convert(input_filename->sval[0], output_filename->sval[0], use_long->count > 0);
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "aaruformattool.h"
|
||||
|
||||
int convert(const char *input_path, const char *output_path)
|
||||
int convert(const char *input_path, const char *output_path, bool use_long)
|
||||
{
|
||||
aaruformat_context *input_ctx = NULL;
|
||||
aaruformat_context *output_ctx = NULL;
|
||||
@@ -37,7 +37,7 @@ int convert(const char *input_path, const char *output_path)
|
||||
uint64_t total_sectors = 0;
|
||||
uint8_t *sector_data = NULL;
|
||||
|
||||
printf("Converting image from %s to %s...\n", input_path, output_path);
|
||||
printf("Converting image from %s to %s%s...\n", input_path, output_path, use_long ? " (long mode)" : "");
|
||||
|
||||
// Open input image
|
||||
input_ctx = aaruf_open(input_path);
|
||||
@@ -170,7 +170,7 @@ int convert(const char *input_path, const char *output_path)
|
||||
// Copy sectors from input to output
|
||||
for(uint64_t sector = 0; sector < total_sectors; sector++)
|
||||
{
|
||||
uint32_t read_length = sector_size;
|
||||
uint32_t read_length = 0;
|
||||
|
||||
// Show progress every 1000 sectors
|
||||
if(sector % 1000 == 0 || sector == total_sectors - 1)
|
||||
@@ -180,8 +180,38 @@ int convert(const char *input_path, const char *output_path)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// Check sector size
|
||||
if(use_long)
|
||||
res = aaruf_read_sector_long(input_ctx, sector, false, sector_data, &read_length);
|
||||
else
|
||||
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length);
|
||||
|
||||
if(res != AARUF_ERROR_BUFFER_TOO_SMALL)
|
||||
{
|
||||
printf("\nError %d when reading sector %llu from input image.\n", res, (unsigned long long)sector);
|
||||
break;
|
||||
}
|
||||
|
||||
if(sector_size < read_length)
|
||||
{
|
||||
free(sector_data);
|
||||
sector_size = read_length;
|
||||
sector_data = malloc(sector_size);
|
||||
if(sector_data == NULL)
|
||||
{
|
||||
printf("Error allocating memory for sector buffer.\n");
|
||||
aaruf_close(input_ctx);
|
||||
aaruf_close(output_ctx);
|
||||
return AARUF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// Read sector from input
|
||||
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length);
|
||||
if(use_long)
|
||||
res = aaruf_read_sector_long(input_ctx, sector, false, sector_data, &read_length);
|
||||
else
|
||||
res = aaruf_read_sector(input_ctx, sector, false, sector_data, &read_length);
|
||||
|
||||
if(res != AARUF_STATUS_OK)
|
||||
{
|
||||
printf("\nError %d when reading sector %llu from input image.\n", res, (unsigned long long)sector);
|
||||
@@ -189,7 +219,11 @@ int convert(const char *input_path, const char *output_path)
|
||||
}
|
||||
|
||||
// Write sector to output
|
||||
res = aaruf_write_sector(output_ctx, sector, false, sector_data, SectorStatusDumped, read_length);
|
||||
if(use_long)
|
||||
res = aaruf_write_sector_long(output_ctx, sector, false, sector_data, SectorStatusDumped, read_length);
|
||||
else
|
||||
res = aaruf_write_sector(output_ctx, sector, false, sector_data, SectorStatusDumped, read_length);
|
||||
|
||||
if(res != AARUF_STATUS_OK)
|
||||
{
|
||||
printf("\nError %d when writing sector %llu to output image.\n", res, (unsigned long long)sector);
|
||||
|
||||
@@ -127,9 +127,11 @@ void usage_cli_compare()
|
||||
void usage_convert()
|
||||
{
|
||||
printf("\nUsage:\n");
|
||||
printf(" aaruformattool convert <input> <output>\n\n");
|
||||
printf(" aaruformattool convert [-l] <input> <output>\n\n");
|
||||
printf("Converts an AaruFormat image by reading all sectors from input and writing them to output.\n");
|
||||
printf("Arguments:\n");
|
||||
printf(" <input> Path to input image file.\n");
|
||||
printf(" <output> Path to output image file.\n");
|
||||
printf("Options:\n");
|
||||
printf(" -l Use long sector read/write (includes tags and metadata).\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user