From 5731492874513cfcd204aae6735cf70db4d6b6e0 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 10 Feb 2024 06:10:19 +1100 Subject: [PATCH] tools/chdman.cpp: Fixed numerous issues, including: Support input start/size options for createdvd. Fixed not reporting an error on unrecognised command line options. Fixed --fix/-f option for verify command not working. Report an error when conflicting options are supplied (e.g. hard disk template and C/H/S geometry, or input start offset in both bytes and hunks). Previously the results would be unpredictable. Detect more invalid combinations of options, and detect when output unit size or hunk size doesn't match parent. Changed order of processing options for createhd so using a template cannot not inadvertently result in an invalid combination of sector size and hunk size. Don't require an explicit unit size for createraw if an output parent CHD file is supplied. Fixed an object leak in createcd. --- docs/source/tools/chdman.rst | 109 +++- src/lib/util/chd.cpp | 32 +- src/lib/util/chd.h | 8 +- src/tools/chdman.cpp | 1032 +++++++++++++++++----------------- 4 files changed, 609 insertions(+), 572 deletions(-) diff --git a/docs/source/tools/chdman.rst b/docs/source/tools/chdman.rst index f23a21cddf5e9..0461264276426 100644 --- a/docs/source/tools/chdman.rst +++ b/docs/source/tools/chdman.rst @@ -27,6 +27,25 @@ used by multiple commands: most commands that operate on CHD format input files. This option must be used if the input file is a *delta CHD*, storing only the hunks that differ from its parent CHD, +--inputstartbyte / -isb + Specify the offset to the data in the input file in bytes. This is useful + for creating CHD format files from input files that contain a header before + the start of the data, or for extracting partial content from a CHD format + file. May not be specified in combination with the + ``--inputstarthunk``/``-ish`` option. +--inputstarthunk / -ish + Specify the offset to the data in the input file in hunks. May not be + specified in combination with the ``--inputstartbyte``/``-isb`` option. +--inputbytes / -ib + Specify the amount of input data to use in bytes, starting from the offset + to the data in the input file. This is useful for creating CHD format files + from input files that contain additional content after the data, or for + extracting partial content from a CHD format file. May not be specified in + combination with the ``--inputhunks``/``-ih`` option. +--inputhunks / -ih + Specify the amount of input data to use in hunks, starting from the offset + to the data in the input file. May not be specified in combination with the + ``--inputbytes``/``-ib`` option. --output / -o Specify the output file name. This option is required for commands that produce output files. The output file formats supported depend on the @@ -86,13 +105,19 @@ verify ~~~~~~ Verify the integrity of a CHD format file. The input file must be a read-only -CHD format file (the integrity of writable CHD files cannot be verified). +CHD format file (the integrity of writable CHD files cannot be verified). Note +that this command modifies its input file if the ``--fix``/``-f`` option is +specified. Common options supported: * ``--input `` / ``-i `` (required) * ``--inputparent `` / ``-ip `` +Additional options: + +* ``--fix`` / ``-f`` + createraw ~~~~~~~~~ @@ -101,20 +126,34 @@ Create a CHD format file from a raw media image. Common options supported: * ``--input `` / ``-i `` (required) +* ``--inputstartbyte `` / ``-isb `` +* ``--inputstarthunk `` / ``-ish `` +* ``--inputbytes `` / ``-ib `` +* ``--inputhunks `` / ``-ih `` * ``--output `` / ``-o `` (required) * ``--outputparent `` / ``-op `` * ``--compression none|[,]...`` / ``-c none|[,]...`` -* ``--hunksize `` / ``-hs `` (required) +* ``--hunksize `` / ``-hs `` * ``--force`` / ``-f`` * ``--numprocessors `` / ``-np `` Additional options: -* ``--unitsize `` / ``-us `` (required) -* ``--inputstartbyte `` / ``-isb `` -* ``--inputstarthunk `` / ``-ish `` -* ``--inputbytes `` / ``-ib `` -* ``--inputhunks `` / ``-ih `` +--unitsize / -us (required) + The unit size for the output CHD file in bytes. This is the smallest unit + of data that can be addressed within the CHD file. It should match the + sector size or page size of the source media. The hunk size must be a whole + multiple of the unit size. The unit size must be specified if no parent CHD + file for the output is supplied. If a parent CHD file for the output is + supplied, the unit size must match the unit size of the parent CHD file. + +If the ``--hunksize`` or ``-hs`` option is not supplied, the default will be: + +* The hunk size of the parent CHD file if a parent CHD file for the output is + supplied. +* The smallest whole multiple of the unit size not larger than 4 KiB if the unit + size is not larger than 4 KiB (4096 bytes). +* The unit size if it is larger than 4 KiB (4096 bytes). If the ``--compression`` or ``-c`` option is not supplied, it defaults to ``lzma,zlib,huff,flac``. @@ -126,7 +165,11 @@ Create a CHD format hard disk image file. Common options supported: -* ``--input `` / ``-i `` (required) +* ``--input `` / ``-i `` +* ``--inputstartbyte `` / ``-isb `` +* ``--inputstarthunk `` / ``-ish `` +* ``--inputbytes `` / ``-ib `` +* ``--inputhunks `` / ``-ih `` * ``--output `` / ``-o `` (required) * ``--outputparent `` / ``-op `` * ``--compression none|[,]...`` / ``-c none|[,]...`` @@ -140,13 +183,23 @@ Additional options: * ``--size `` / ``-s `` * ``--chs ,,`` / ``-chs ,,`` * ``--template