mirror of
https://github.com/holub/mame
synced 2025-10-06 09:00:04 +03:00
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:
parent
c11ba8606d
commit
33ebcc9120
1
src/regtests/chdman/input/createhd_4/in.params
Normal file
1
src/regtests/chdman/input/createhd_4/in.params
Normal file
@ -0,0 +1 @@
|
||||
-s 1073741824
|
1
src/regtests/chdman/input/createhd_5/in.params
Normal file
1
src/regtests/chdman/input/createhd_5/in.params
Normal file
@ -0,0 +1 @@
|
||||
-s 1073741824 -ss 1024
|
BIN
src/regtests/chdman/output/createhd_4/out.chd
Normal file
BIN
src/regtests/chdman/output/createhd_4/out.chd
Normal file
Binary file not shown.
BIN
src/regtests/chdman/output/createhd_5/out.chd
Normal file
BIN
src/regtests/chdman/output/createhd_5/out.chd
Normal file
Binary file not shown.
@ -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,11 +1685,24 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
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];
|
||||
memcpy(compression, s_default_hd_compression, sizeof(compression));
|
||||
@ -1746,13 +1757,17 @@ static void do_create_hd(parameters_t ¶ms)
|
||||
if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, §ors, §or_size) != 4)
|
||||
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 ¶ms)
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user