Previous 199869 Revisions Next

r34413 Friday 16th January, 2015 at 11:56:37 UTC by Oliver Stöneberg
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()
[src/regtests/chdman/input/createhd_4]in.params*
[src/regtests/chdman/input/createhd_5]in.params*
[src/regtests/chdman/output/createhd_4]out.chd*
[src/regtests/chdman/output/createhd_5]out.chd*
[src/tools]chdman.c

trunk/src/regtests/chdman/input/createhd_4/in.params
r0r242925
1-s 1073741824
No newline at end of file
trunk/src/regtests/chdman/input/createhd_5/in.params
r0r242925
1-s 1073741824 -ss 1024
No newline at end of file
trunk/src/regtests/chdman/output/createhd_4/out.chd
r0r242925
1MComprHD|@||GDDD#CYLS:4096,HEADS:16,SECS:32,BPS:512
No newline at end of file
trunk/src/regtests/chdman/output/createhd_5/out.chd
r0r242925
1MComprHD|@||GDDD$CYLS:2048,HEADS:16,SECS:32,BPS:1024
No newline at end of file
trunk/src/tools/chdman.c
r242924r242925
8787#define OPTION_VERBOSE "verbose"
8888#define OPTION_FIX "fix"
8989#define OPTION_NUMPROCESSORS "numprocessors"
90#define OPTION_SIZE "size"
9091
9192
9293//**************************************************************************
r242924r242925
528529   { OPTION_NO_CHECKSUM,           "nocs", false, ": do not include this metadata information in the overall SHA-1" },
529530   { OPTION_FIX,                   "f",    false, ": fix the SHA-1 if it is incorrect" },
530531   { OPTION_VERBOSE,               "v",    false, ": output additional information" },
532   { OPTION_SIZE,                  "s",    true, ": <bytes>: size of the output file" },
531533};
532534
533535
r242924r242925
579581         OPTION_COMPRESSION,
580582         OPTION_IDENT,
581583         OPTION_CHS,
584         OPTION_SIZE,
582585         OPTION_SECTOR_SIZE,
583586         OPTION_NUMPROCESSORS
584587      }
r242924r242925
901904   if (filesize == 0)
902905      report_error(1, "Can't guess CHS values because there is no input file");
903906
904   // validate the size
905   if (filesize % sectorsize != 0)
906      report_error(1, "Can't guess CHS values because data size is not divisible by %d", sectorsize);
907   ;
908
909907   // now find a valid value
910908   for (UINT32 totalsectors = filesize / sectorsize; ; totalsectors++)
911909      for (UINT32 cursectors = 63; cursectors > 1; cursectors--)
r242924r242925
16871685   parse_hunk_size(params, sector_size, hunk_size);
16881686
16891687   // process input start/end (needs to know hunk_size)
1688   UINT64 filesize = 0;
16901689   UINT64 input_start = 0;
16911690   UINT64 input_end = 0;
16921691   if (input_file != NULL)
1692   {
16931693      parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
1694
1694      filesize = input_end - input_start;
1695   }
1696   else
1697   {
1698      astring *size_str = params.find(OPTION_SIZE);
1699      if (size_str != NULL)
1700      {
1701         if (sscanf(*size_str, "%d", &filesize) != 1)
1702            report_error(1, "Invalid size string");
1703      }
1704   }
1705   
16951706   // process compression
16961707   chd_codec_type compression[4];
16971708   memcpy(compression, s_default_hd_compression, sizeof(compression));
r242924r242925
17461757      if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, &sectors, &sector_size) != 4)
17471758         report_error(1, "Error parsing hard disk metadata in parent CHD");
17481759   }
1760     
1761   // validate the size
1762   if (filesize % sector_size != 0)
1763      report_error(1, "Data size is not divisible by sector size %d", sector_size);
17491764
17501765   // if no CHS values, try to guess them
17511766   if (cylinders == 0)
17521767   {
1753      if (input_file == NULL && input_end - input_start == 0)
1768      if (input_file == NULL && filesize == 0)
17541769         report_error(1, "Blank hard drives must specify either a length or a set of CHS values");
1755      guess_chs(input_file_str, input_end - input_start, sector_size, cylinders, heads, sectors, sector_size);
1770      guess_chs(input_file_str, filesize, sector_size, cylinders, heads, sectors, sector_size);
17561771   }
17571772   UINT32 totalsectors = cylinders * heads * sectors;
17581773
r242924r242925
17671782      if (input_start != 0 || input_end != core_fsize(input_file))
17681783      {
17691784         printf("Input start:  %s\n", big_int_string(tempstr, input_start));
1770         printf("Input length: %s\n", big_int_string(tempstr, input_end - input_start));
1785         printf("Input length: %s\n", big_int_string(tempstr, filesize));
17711786      }
17721787   }
17731788   printf("Compression:  %s\n", compression_string(tempstr, compression));


Previous 199869 Revisions Next


© 1997-2024 The MAME Team