trunk/src/tools/chdman.c
| r242926 | r242927 | |
| 87 | 87 | #define OPTION_VERBOSE "verbose" |
| 88 | 88 | #define OPTION_FIX "fix" |
| 89 | 89 | #define OPTION_NUMPROCESSORS "numprocessors" |
| 90 | | #define OPTION_SIZE "size" |
| 91 | 90 | |
| 92 | 91 | |
| 93 | 92 | //************************************************************************** |
| r242926 | r242927 | |
| 529 | 528 | { OPTION_NO_CHECKSUM, "nocs", false, ": do not include this metadata information in the overall SHA-1" }, |
| 530 | 529 | { OPTION_FIX, "f", false, ": fix the SHA-1 if it is incorrect" }, |
| 531 | 530 | { OPTION_VERBOSE, "v", false, ": output additional information" }, |
| 532 | | { OPTION_SIZE, "s", true, ": <bytes>: size of the output file" }, |
| 533 | 531 | }; |
| 534 | 532 | |
| 535 | 533 | |
| r242926 | r242927 | |
| 581 | 579 | OPTION_COMPRESSION, |
| 582 | 580 | OPTION_IDENT, |
| 583 | 581 | OPTION_CHS, |
| 584 | | OPTION_SIZE, |
| 585 | 582 | OPTION_SECTOR_SIZE, |
| 586 | 583 | OPTION_NUMPROCESSORS |
| 587 | 584 | } |
| r242926 | r242927 | |
| 904 | 901 | if (filesize == 0) |
| 905 | 902 | report_error(1, "Can't guess CHS values because there is no input file"); |
| 906 | 903 | |
| 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 | |
| 907 | 909 | // now find a valid value |
| 908 | 910 | for (UINT32 totalsectors = filesize / sectorsize; ; totalsectors++) |
| 909 | 911 | for (UINT32 cursectors = 63; cursectors > 1; cursectors--) |
| r242926 | r242927 | |
| 1685 | 1687 | parse_hunk_size(params, sector_size, hunk_size); |
| 1686 | 1688 | |
| 1687 | 1689 | // process input start/end (needs to know hunk_size) |
| 1688 | | UINT64 filesize = 0; |
| 1689 | 1690 | UINT64 input_start = 0; |
| 1690 | 1691 | UINT64 input_end = 0; |
| 1691 | 1692 | if (input_file != NULL) |
| 1692 | | { |
| 1693 | 1693 | parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end); |
| 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, "%"I64FMT"d", &filesize) != 1) |
| 1702 | | report_error(1, "Invalid size string"); |
| 1703 | | } |
| 1704 | | } |
| 1705 | | |
| 1694 | |
| 1706 | 1695 | // process compression |
| 1707 | 1696 | chd_codec_type compression[4]; |
| 1708 | 1697 | memcpy(compression, s_default_hd_compression, sizeof(compression)); |
| r242926 | r242927 | |
| 1757 | 1746 | if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, §ors, §or_size) != 4) |
| 1758 | 1747 | report_error(1, "Error parsing hard disk metadata in parent CHD"); |
| 1759 | 1748 | } |
| 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); |
| 1764 | 1749 | |
| 1765 | 1750 | // if no CHS values, try to guess them |
| 1766 | 1751 | if (cylinders == 0) |
| 1767 | 1752 | { |
| 1768 | | if (input_file == NULL && filesize == 0) |
| 1753 | if (input_file == NULL && input_end - input_start == 0) |
| 1769 | 1754 | report_error(1, "Blank hard drives must specify either a length or a set of CHS values"); |
| 1770 | | guess_chs(input_file_str, filesize, sector_size, cylinders, heads, sectors, sector_size); |
| 1755 | guess_chs(input_file_str, input_end - input_start, sector_size, cylinders, heads, sectors, sector_size); |
| 1771 | 1756 | } |
| 1772 | 1757 | UINT32 totalsectors = cylinders * heads * sectors; |
| 1773 | 1758 | |
| r242926 | r242927 | |
| 1782 | 1767 | if (input_start != 0 || input_end != core_fsize(input_file)) |
| 1783 | 1768 | { |
| 1784 | 1769 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| 1785 | | printf("Input length: %s\n", big_int_string(tempstr, filesize)); |
| 1770 | printf("Input length: %s\n", big_int_string(tempstr, input_end - input_start)); |
| 1786 | 1771 | } |
| 1787 | 1772 | } |
| 1788 | 1773 | printf("Compression: %s\n", compression_string(tempstr, compression)); |