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