From 33ebcc91208f51520368e4933f19d29d36f50ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 16 Jan 2015 12:56:37 +0100 Subject: [PATCH] =?UTF-8?q?chdman:=20added=20-s/--size=20parameter=20for?= =?UTF-8?q?=20"createhd"=20to=20create=20blank=20harddisk=20based=20on=20s?= =?UTF-8?q?ize=20and=20sector=20size=20[Oliver=20St=C3=B6neberg]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also added unit tests for the new option / moved filesize validation out of guess_chd() --- .../chdman/input/createhd_4/in.params | 1 + .../chdman/input/createhd_5/in.params | 1 + src/regtests/chdman/output/createhd_4/out.chd | Bin 0 -> 1048751 bytes src/regtests/chdman/output/createhd_5/out.chd | Bin 0 -> 1048752 bytes src/tools/chdman.c | 33 +++++++++++++----- 5 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/regtests/chdman/input/createhd_4/in.params create mode 100644 src/regtests/chdman/input/createhd_5/in.params create mode 100644 src/regtests/chdman/output/createhd_4/out.chd create mode 100644 src/regtests/chdman/output/createhd_5/out.chd diff --git a/src/regtests/chdman/input/createhd_4/in.params b/src/regtests/chdman/input/createhd_4/in.params new file mode 100644 index 00000000000..61dfdd4701b --- /dev/null +++ b/src/regtests/chdman/input/createhd_4/in.params @@ -0,0 +1 @@ +-s 1073741824 \ No newline at end of file diff --git a/src/regtests/chdman/input/createhd_5/in.params b/src/regtests/chdman/input/createhd_5/in.params new file mode 100644 index 00000000000..614d2b26384 --- /dev/null +++ b/src/regtests/chdman/input/createhd_5/in.params @@ -0,0 +1 @@ +-s 1073741824 -ss 1024 \ No newline at end of file diff --git a/src/regtests/chdman/output/createhd_4/out.chd b/src/regtests/chdman/output/createhd_4/out.chd new file mode 100644 index 0000000000000000000000000000000000000000..8e565b3799372e20d44f7fb3f87536ab297f5584 GIT binary patch literal 1048751 zcmeIuF$%&^3;@ut;NCm9cCb|o{z>gGc2E%hfFCWK: 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));