chdman: added -s/--size parameter for "createhd" to create blank harddisk based on size and sector size [Oliver Stöneberg]

also added unit tests for the new option / moved filesize validation out
of guess_chd()
This commit is contained in:
Oliver Stöneberg 2015-01-16 12:56:37 +01:00
parent c11ba8606d
commit 33ebcc9120
5 changed files with 26 additions and 9 deletions

View File

@ -0,0 +1 @@
-s 1073741824

View File

@ -0,0 +1 @@
-s 1073741824 -ss 1024

Binary file not shown.

Binary file not shown.

View File

@ -87,6 +87,7 @@ const int MODE_GDI = 2;
#define OPTION_VERBOSE "verbose"
#define OPTION_FIX "fix"
#define OPTION_NUMPROCESSORS "numprocessors"
#define OPTION_SIZE "size"
//**************************************************************************
@ -528,6 +529,7 @@ static const option_description s_options[] =
{ OPTION_NO_CHECKSUM, "nocs", false, ": do not include this metadata information in the overall SHA-1" },
{ OPTION_FIX, "f", false, ": fix the SHA-1 if it is incorrect" },
{ OPTION_VERBOSE, "v", false, ": output additional information" },
{ OPTION_SIZE, "s", true, ": <bytes>: size of the output file" },
};
@ -579,6 +581,7 @@ static const command_description s_commands[] =
OPTION_COMPRESSION,
OPTION_IDENT,
OPTION_CHS,
OPTION_SIZE,
OPTION_SECTOR_SIZE,
OPTION_NUMPROCESSORS
}
@ -901,11 +904,6 @@ static void guess_chs(astring *filename, UINT64 filesize, int sectorsize, UINT32
if (filesize == 0)
report_error(1, "Can't guess CHS values because there is no input file");
// validate the size
if (filesize % sectorsize != 0)
report_error(1, "Can't guess CHS values because data size is not divisible by %d", sectorsize);
;
// now find a valid value
for (UINT32 totalsectors = filesize / sectorsize; ; totalsectors++)
for (UINT32 cursectors = 63; cursectors > 1; cursectors--)
@ -1687,10 +1685,23 @@ static void do_create_hd(parameters_t &params)
parse_hunk_size(params, sector_size, hunk_size);
// process input start/end (needs to know hunk_size)
UINT64 filesize = 0;
UINT64 input_start = 0;
UINT64 input_end = 0;
if (input_file != NULL)
{
parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
filesize = input_end - input_start;
}
else
{
astring *size_str = params.find(OPTION_SIZE);
if (size_str != NULL)
{
if (sscanf(*size_str, "%d", &filesize) != 1)
report_error(1, "Invalid size string");
}
}
// process compression
chd_codec_type compression[4];
@ -1747,12 +1758,16 @@ static void do_create_hd(parameters_t &params)
report_error(1, "Error parsing hard disk metadata in parent CHD");
}
// validate the size
if (filesize % sector_size != 0)
report_error(1, "Data size is not divisible by sector size %d", sector_size);
// if no CHS values, try to guess them
if (cylinders == 0)
{
if (input_file == NULL && input_end - input_start == 0)
if (input_file == NULL && filesize == 0)
report_error(1, "Blank hard drives must specify either a length or a set of CHS values");
guess_chs(input_file_str, input_end - input_start, sector_size, cylinders, heads, sectors, sector_size);
guess_chs(input_file_str, filesize, sector_size, cylinders, heads, sectors, sector_size);
}
UINT32 totalsectors = cylinders * heads * sectors;
@ -1767,7 +1782,7 @@ static void do_create_hd(parameters_t &params)
if (input_start != 0 || input_end != core_fsize(input_file))
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
printf("Input length: %s\n", big_int_string(tempstr, input_end - input_start));
printf("Input length: %s\n", big_int_string(tempstr, filesize));
}
}
printf("Compression: %s\n", compression_string(tempstr, compression));