summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Oliver Stöneberg <oliverst@online.de>2015-01-16 12:56:37 +0100
committer Oliver Stöneberg <oliverst@online.de>2015-01-16 12:56:37 +0100
commit33ebcc91208f51520368e4933f19d29d36f50ad3 (patch)
treed962c991f48b4968f2792eb34f96e5a4f6504dac
parentc11ba8606d1083aefd5f0ebe7a4a0a4ac691ecc0 (diff)
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()
-rw-r--r--src/regtests/chdman/input/createhd_4/in.params1
-rw-r--r--src/regtests/chdman/input/createhd_5/in.params1
-rw-r--r--src/regtests/chdman/output/createhd_4/out.chdbin0 -> 1048751 bytes
-rw-r--r--src/regtests/chdman/output/createhd_5/out.chdbin0 -> 1048752 bytes
-rw-r--r--src/tools/chdman.c33
5 files changed, 26 insertions, 9 deletions
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 00000000000..8e565b37993
--- /dev/null
+++ b/src/regtests/chdman/output/createhd_4/out.chd
Binary files differ
diff --git a/src/regtests/chdman/output/createhd_5/out.chd b/src/regtests/chdman/output/createhd_5/out.chd
new file mode 100644
index 00000000000..825a3493d0b
--- /dev/null
+++ b/src/regtests/chdman/output/createhd_5/out.chd
Binary files differ
diff --git a/src/tools/chdman.c b/src/tools/chdman.c
index a491226452b..621c55580ae 100644
--- a/src/tools/chdman.c
+++ b/src/tools/chdman.c
@@ -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 &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];
memcpy(compression, s_default_hd_compression, sizeof(compression));
@@ -1746,13 +1757,17 @@ static void do_create_hd(parameters_t &params)
if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, &sectors, &sector_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 &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));