mirror of https://github.com/bochs-emu/Bochs
Some work on the bximage utility.
- The selected / detected disk image mode is now stored as a string constant to simplify code (same as Bochs core). - Changed command line option to select operation mode to "-func=X" to avoid confusion with disk image mode. - Documentation updates.
This commit is contained in:
parent
afcda20b83
commit
38a04afe8e
|
@ -9051,14 +9051,9 @@ If unspecified, the default "mode" is flat.
|
|||
mappable to contained partitions
|
||||
</entry>
|
||||
</row>
|
||||
<row> <entry> external </entry> <entry> accessed through an external C++ class </entry>
|
||||
<entry>
|
||||
developer specific, needs a C++ class at compile time
|
||||
</entry>
|
||||
</row>
|
||||
<row> <entry> dll </entry> <entry> accessed through a DLL </entry>
|
||||
<entry>
|
||||
developer specific, windows only
|
||||
developer specific, win32 / win64 only
|
||||
</entry>
|
||||
</row>
|
||||
<row> <entry> sparse </entry> <entry> up to 10 layers stackable files </entry>
|
||||
|
@ -9201,13 +9196,13 @@ On some host OSes, there is a limit of 2GiB per file.
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section><title>external/dll</title>
|
||||
<section><title>dll</title>
|
||||
<para>
|
||||
</para>
|
||||
<section><title>description</title>
|
||||
<para>
|
||||
This mode is only useful for developers and needs an additional C++ class
|
||||
compiled in, or an additional DLL linked to Bochs.
|
||||
This mode is only useful for developers and needs an additional win32 / win64
|
||||
DLL loaded by Bochs at runtime.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
@ -9253,7 +9248,8 @@ substracting 1 from the last character (must be a digit)
|
|||
</section>
|
||||
<section><title>external tools</title>
|
||||
<para>
|
||||
No external tool support Sparse disk images yet.
|
||||
The bximage utility (see <xref linkend="using-bximage"> provides convert and
|
||||
resize support for "sparse" mode images.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>typical use</title>
|
||||
|
@ -9445,9 +9441,9 @@ Only vmware versions 3 and 4 disk image files are supported.
|
|||
</section>
|
||||
<section><title>image creation</title>
|
||||
<para>
|
||||
The flat / sparse / growing disk images must be created with the bximage utility
|
||||
(see <xref linkend="using-bximage"> for more information).
|
||||
The growing redolog is created automatically if needed.
|
||||
The base disk images must be created with the bximage utility
|
||||
(see <xref linkend="using-bximage"> for more information).
|
||||
The redolog file is created automatically if it doesn't exist.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>path</title>
|
||||
|
@ -9460,7 +9456,7 @@ The growing redolog is created automatically if needed.
|
|||
</section>
|
||||
<section><title>external tools</title>
|
||||
<para>
|
||||
To access the flat disk image content,
|
||||
To access the 'flat' mode base disk image content,
|
||||
see <xref linkend="harddisk-mode-flat-tools"> for available tools.
|
||||
</para>
|
||||
<note>
|
||||
|
@ -9538,14 +9534,16 @@ Be sure to enter "growing" when selecting the image type.
|
|||
</section>
|
||||
<section><title>external tools</title>
|
||||
<para>
|
||||
No external tool support Growing disk images yet.
|
||||
The bximage utility (see <xref linkend="using-bximage"> provides convert
|
||||
and resize support for "growing" mode images.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>typical use</title>
|
||||
<para>
|
||||
Growing disk images can be used whenever you want to maximize disk space.
|
||||
However, please note that Bochs will not check if enough disk space is available
|
||||
before writing new data. If no disk space is available, a panic will occur.
|
||||
Growing disk images can be used whenever you want to maximize disk space.
|
||||
However, please note that Bochs will not check if enough disk space is
|
||||
available before writing new data. If no disk space is available, a panic
|
||||
will occur.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>limitations</title>
|
||||
|
@ -9565,8 +9563,8 @@ before writing new data. If no disk space is available, a panic will occur.
|
|||
An volatile disk is based on a read-only image, associated with
|
||||
a growing redolog, that contains all changes (writes)
|
||||
made to the base image content. Currently, base images of
|
||||
types 'flat', 'sparse', 'growing', 'vmware3', 'vmware4' and
|
||||
'vpc' are supported.
|
||||
types 'flat', 'sparse', 'growing', 'vmware3', 'vmware4', 'vpc' and
|
||||
'vbox' are supported.
|
||||
</para>
|
||||
<para>
|
||||
The redolog is dynamically created at runtime, when
|
||||
|
@ -9596,9 +9594,9 @@ before writing new data. If no disk space is available, a panic will occur.
|
|||
</section>
|
||||
<section><title>image creation</title>
|
||||
<para>
|
||||
The flat / sparse / growing disk images must be created with the bximage utility
|
||||
(see <xref linkend="using-bximage"> for more information).
|
||||
The growing redolog is created automatically.
|
||||
The base disk images must be created with the bximage utility
|
||||
(see <xref linkend="using-bximage"> for more information).
|
||||
The temporary redolog file is created automatically.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>path</title>
|
||||
|
@ -9613,8 +9611,8 @@ The growing redolog is created automatically.
|
|||
</section>
|
||||
<section><title>external tools</title>
|
||||
<para>
|
||||
See <xref linkend="harddisk-mode-flat-tools"> for tools
|
||||
to access the flat disk image content.
|
||||
To access 'flat' mode base disk image content,
|
||||
see <xref linkend="harddisk-mode-flat-tools"> for available tools.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>typical use</title>
|
||||
|
@ -9654,7 +9652,9 @@ The growing redolog is created automatically.
|
|||
</section>
|
||||
<section><title>image creation</title>
|
||||
<para>
|
||||
Create such disk image with Microsoft VirtualPC (tm) or Qemu's disk image utility (qemu-img).
|
||||
Create such disk image with Microsoft VirtualPC (tm), Qemu's disk image
|
||||
utility (qemu-img) or bximage utility
|
||||
(see <xref linkend="using-bximage"> for more information).
|
||||
</para>
|
||||
</section>
|
||||
<section><title>path</title>
|
||||
|
@ -9680,6 +9680,43 @@ The growing redolog is created automatically.
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section><title>vbox</title>
|
||||
<para>
|
||||
</para>
|
||||
<section><title>description</title>
|
||||
<para>
|
||||
The "vbox" disk image mode for VirtualBox disk images (VDI version 1.1)
|
||||
has been written by Benjamin D. Lunt.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>image creation</title>
|
||||
<para>
|
||||
Create such disk image with Qemu's disk image utility (qemu-img).
|
||||
</para>
|
||||
</section>
|
||||
<section><title>path</title>
|
||||
<para>
|
||||
The "path" option of the ataX-xxx directive in the configuration file
|
||||
must point to the VirtualBox disk image.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>external tools</title>
|
||||
<para>
|
||||
Use VirtualBox tools to manipulate these disk images.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>typical use</title>
|
||||
<para>
|
||||
Share disk images with VirtualBox.
|
||||
</para>
|
||||
</section>
|
||||
<section><title>limitations</title>
|
||||
<para>
|
||||
&FIXME; to be completed
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section><title>vvfat</title>
|
||||
<para>
|
||||
</para>
|
||||
|
@ -9810,7 +9847,7 @@ interactive mode and ask for all required parameters to manipulate an image.
|
|||
Usage: bximage [options] [filename1] [filename2]
|
||||
|
||||
Supported options:
|
||||
-mode=... operation mode (create, convert, resize, commit, info)
|
||||
-func=... operation to perform (create, convert, resize, commit, info)
|
||||
-fd=... create: floppy image with size code
|
||||
-hd=... create/resize: hard disk image with size in megabytes (M)
|
||||
or gigabytes (G)
|
||||
|
@ -9877,6 +9914,11 @@ Other arguments:
|
|||
<entry>Yes</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>vbox</entry>
|
||||
<entry>No</entry>
|
||||
<entry>Yes</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
|
@ -9927,7 +9969,7 @@ suffix ".orig".
|
|||
<para>
|
||||
This function can be used to determine the disk image format, geometry
|
||||
and size. Note that Bochs can only detect the formats growing, sparse,
|
||||
vmware3, vmware4 and vpc correctly. Other images with a file size
|
||||
vmware3, vmware4, vpc and vbox correctly. Other images with a file size
|
||||
multiple of 512 are treated as flat ones. If the image doesn't support
|
||||
returning the geometry, the cylinders are calculated based on 16 heads
|
||||
and 63 sectors per track.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.\"Document Author: Timothy R. Butler - tbutler@uninetsolutions.com"
|
||||
.TH bximage 1 "19 Jun 2014" "bximage" "The Bochs Project"
|
||||
.TH bximage 1 "9 Jan 2021" "bximage" "The Bochs Project"
|
||||
.\"SKIP_SECTION"
|
||||
.SH NAME
|
||||
bximage \- Interactive Disk Image Creation, Conversion, Resize and
|
||||
|
@ -27,8 +27,8 @@ When you run bximage without one of the following options,
|
|||
it will appear in interactive mode and ask for all
|
||||
required parameters to manipulate an image.
|
||||
.TP
|
||||
.BI \-mode=...
|
||||
Operation mode (create, convert, resize, commit, info)
|
||||
.BI \-func=...
|
||||
Operation to perform (create, convert, resize, commit, info)
|
||||
.TP
|
||||
.BI \-fd=...
|
||||
Create: floppy image with size code (e.g. 360k, 720k, 1.44M)
|
||||
|
|
|
@ -65,9 +65,9 @@ extern int bx_interactive;
|
|||
class device_image_t;
|
||||
|
||||
void myexit(int code);
|
||||
device_image_t* init_image_2(const char *image_mode);
|
||||
device_image_t* init_image(const char *image_mode);
|
||||
|
||||
#define DEV_hdimage_init_image(a,b,c) init_image_2(a)
|
||||
#define DEV_hdimage_init_image(a,b,c) init_image(a)
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -77,49 +77,18 @@
|
|||
#include "iodev/hdimage/vpc.h"
|
||||
#include "iodev/hdimage/vbox.h"
|
||||
|
||||
#define BXIMAGE_MODE_NULL 0
|
||||
#define BXIMAGE_MODE_CREATE_IMAGE 1
|
||||
#define BXIMAGE_MODE_CONVERT_IMAGE 2
|
||||
#define BXIMAGE_MODE_RESIZE_IMAGE 3
|
||||
#define BXIMAGE_MODE_COMMIT_UNDOABLE 4
|
||||
#define BXIMAGE_MODE_IMAGE_INFO 5
|
||||
#define BXIMAGE_FUNC_NULL 0
|
||||
#define BXIMAGE_FUNC_CREATE_IMAGE 1
|
||||
#define BXIMAGE_FUNC_CONVERT_IMAGE 2
|
||||
#define BXIMAGE_FUNC_RESIZE_IMAGE 3
|
||||
#define BXIMAGE_FUNC_COMMIT_UNDOABLE 4
|
||||
#define BXIMAGE_FUNC_IMAGE_INFO 5
|
||||
|
||||
#define BX_MAX_CYL_BITS 24 // 8 TB
|
||||
|
||||
const int bx_max_hd_megs = (int)(((1 << BX_MAX_CYL_BITS) - 1) * 16.0 * 63.0 / 2048.0);
|
||||
|
||||
enum {
|
||||
BX_HDIMAGE_MODE_FLAT,
|
||||
BX_HDIMAGE_MODE_CONCAT,
|
||||
BX_HDIMAGE_MODE_DLL_HD,
|
||||
BX_HDIMAGE_MODE_SPARSE,
|
||||
BX_HDIMAGE_MODE_VMWARE3,
|
||||
BX_HDIMAGE_MODE_VMWARE4,
|
||||
BX_HDIMAGE_MODE_UNDOABLE,
|
||||
BX_HDIMAGE_MODE_GROWING,
|
||||
BX_HDIMAGE_MODE_VOLATILE,
|
||||
BX_HDIMAGE_MODE_VVFAT,
|
||||
BX_HDIMAGE_MODE_VPC,
|
||||
BX_HDIMAGE_MODE_VBOX
|
||||
};
|
||||
|
||||
const char *hdimage_mode_names[] = {
|
||||
"flat",
|
||||
"concat",
|
||||
"dll",
|
||||
"sparse",
|
||||
"vmware3",
|
||||
"vmware4",
|
||||
"undoable",
|
||||
"growing",
|
||||
"volatile",
|
||||
"vvfat",
|
||||
"vpc",
|
||||
"vbox",
|
||||
NULL
|
||||
};
|
||||
|
||||
int bximage_mode;
|
||||
int bximage_func;
|
||||
int bx_hdimage;
|
||||
int bx_fdsize_idx;
|
||||
int bx_min_hd_megs = 10;
|
||||
|
@ -161,9 +130,6 @@ int fdsize_n_choices = 10;
|
|||
// menu data for choosing disk mode
|
||||
const char *hdmode_menu = "\nWhat kind of image should I create?\nPlease type flat, sparse, growing, vpc or vmware4. ";
|
||||
const char *hdmode_choices[] = {"flat", "sparse", "growing", "vpc", "vmware4" };
|
||||
const int hdmode_choice_id[] = {BX_HDIMAGE_MODE_FLAT, BX_HDIMAGE_MODE_SPARSE,
|
||||
BX_HDIMAGE_MODE_GROWING, BX_HDIMAGE_MODE_VPC,
|
||||
BX_HDIMAGE_MODE_VMWARE4};
|
||||
int hdmode_n_choices = 5;
|
||||
|
||||
// menu data for choosing hard disk sector size
|
||||
|
@ -171,17 +137,6 @@ const char *sectsize_menu = "\nChoose the size of hard disk sectors.\nPlease typ
|
|||
const char *sectsize_choices[] = { "512","1024","4096" };
|
||||
int sectsize_n_choices = 3;
|
||||
|
||||
int hdimage_get_mode_id(const char *mode)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (hdimage_mode_names[i] != NULL) {
|
||||
if (!strcmp(mode, hdimage_mode_names[i])) return i;
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if !BX_HAVE_SNPRINTF
|
||||
#include <stdarg.h>
|
||||
/* XXX use real snprintf */
|
||||
|
@ -382,63 +337,37 @@ int ask_string(const char *prompt, char *the_default, char *out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
device_image_t* init_image(int image_mode)
|
||||
device_image_t* init_image(const char *imgmode)
|
||||
{
|
||||
device_image_t *hdimage = NULL;
|
||||
|
||||
// instantiate the right class
|
||||
switch (image_mode) {
|
||||
|
||||
case BX_HDIMAGE_MODE_FLAT:
|
||||
hdimage = new flat_image_t();
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_CONCAT:
|
||||
hdimage = new concat_image_t();
|
||||
break;
|
||||
|
||||
if (!strcmp(imgmode, "flat")) {
|
||||
hdimage = new flat_image_t();
|
||||
} else if (!strcmp(imgmode, "concat")) {
|
||||
hdimage = new concat_image_t();
|
||||
#ifdef WIN32
|
||||
case BX_HDIMAGE_MODE_DLL_HD:
|
||||
hdimage = new dll_image_t();
|
||||
break;
|
||||
} else if (!strcmp(imgmode, "dll")) {
|
||||
hdimage = new dll_image_t();
|
||||
#endif
|
||||
|
||||
case BX_HDIMAGE_MODE_SPARSE:
|
||||
hdimage = new sparse_image_t();
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_VMWARE3:
|
||||
hdimage = new vmware3_image_t();
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_VMWARE4:
|
||||
hdimage = new vmware4_image_t();
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_GROWING:
|
||||
hdimage = new growing_image_t();
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_VPC:
|
||||
hdimage = new vpc_image_t();
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_VBOX:
|
||||
hdimage = new vbox_image_t();
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("unsupported disk image mode");
|
||||
break;
|
||||
} else if (!strcmp(imgmode, "sparse")) {
|
||||
hdimage = new sparse_image_t();
|
||||
} else if (!strcmp(imgmode, "vmware3")) {
|
||||
hdimage = new vmware3_image_t();
|
||||
} else if (!strcmp(imgmode, "vmware4")) {
|
||||
hdimage = new vmware4_image_t();
|
||||
} else if (!strcmp(imgmode, "growing")) {
|
||||
hdimage = new growing_image_t();
|
||||
} else if (!strcmp(imgmode, "vpc")) {
|
||||
hdimage = new vpc_image_t();
|
||||
} else if (!strcmp(imgmode, "vbox")) {
|
||||
hdimage = new vbox_image_t();
|
||||
} else {
|
||||
fatal("unsupported disk image mode");
|
||||
}
|
||||
return hdimage;
|
||||
}
|
||||
|
||||
device_image_t* init_image_2(const char *image_mode)
|
||||
{
|
||||
return init_image(hdimage_get_mode_id(image_mode));
|
||||
}
|
||||
|
||||
int create_image_file(const char *filename)
|
||||
{
|
||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC
|
||||
|
@ -763,56 +692,44 @@ void create_vmware4_image(const char *filename, Bit64u size)
|
|||
close(fd);
|
||||
}
|
||||
|
||||
void create_hard_disk_image(const char *filename, int imgmode, Bit64u size)
|
||||
void create_hard_disk_image(const char *filename, const char *imgmode, Bit64u size)
|
||||
{
|
||||
switch (imgmode) {
|
||||
case BX_HDIMAGE_MODE_FLAT:
|
||||
if(!strcmp(imgmode, "flat")) {
|
||||
#ifndef WIN32
|
||||
create_flat_image(filename, size);
|
||||
create_flat_image(filename, size);
|
||||
#else
|
||||
create_flat_image_win32(filename, size);
|
||||
create_flat_image_win32(filename, size);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_GROWING:
|
||||
create_growing_image(filename, size);
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_SPARSE:
|
||||
create_sparse_image(filename, size);
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_VPC:
|
||||
create_vpc_image(filename, size);
|
||||
break;
|
||||
|
||||
case BX_HDIMAGE_MODE_VMWARE4:
|
||||
create_vmware4_image(filename, size);
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("image mode not implemented yet");
|
||||
} else if(!strcmp(imgmode, "growing")) {
|
||||
create_growing_image(filename, size);
|
||||
} else if(!strcmp(imgmode, "sparse")) {
|
||||
create_sparse_image(filename, size);
|
||||
} else if(!strcmp(imgmode, "vpc")) {
|
||||
create_vpc_image(filename, size);
|
||||
} else if(!strcmp(imgmode, "vmware4")) {
|
||||
create_vmware4_image(filename, size);
|
||||
} else {
|
||||
fatal("image mode not implemented yet");
|
||||
}
|
||||
}
|
||||
|
||||
void convert_image(int newimgmode, Bit64u newsize)
|
||||
void convert_image(const char *newimgmode, Bit64u newsize)
|
||||
{
|
||||
device_image_t *source_image, *dest_image;
|
||||
int mode = -1;
|
||||
Bit64u i, sc, s;
|
||||
char buffer[512], null_sector[512];
|
||||
const char *image_mode = NULL;
|
||||
const char *imgmode = NULL;
|
||||
bx_bool error = 0;
|
||||
|
||||
printf("\n");
|
||||
memset(null_sector, 0, 512);
|
||||
if (newsize == 0) {
|
||||
if (!strncmp(bx_filename_1, "concat:", 7)) {
|
||||
image_mode = "concat";
|
||||
imgmode = "concat";
|
||||
strcpy(bx_filename_1, &bx_filename_1[7]);
|
||||
#ifdef WIN32
|
||||
} else if (!strncmp(bx_filename_1, "dll:", 4)) {
|
||||
image_mode = "dll";
|
||||
imgmode = "dll";
|
||||
strcpy(bx_filename_1, &bx_filename_1[4]);
|
||||
#endif
|
||||
}
|
||||
|
@ -820,18 +737,16 @@ void convert_image(int newimgmode, Bit64u newsize)
|
|||
if (access(bx_filename_1, F_OK) < 0) {
|
||||
fatal("source disk image doesn't exist");
|
||||
}
|
||||
if (image_mode == NULL) {
|
||||
if (hdimage_detect_image_mode(bx_filename_1, &image_mode)) {
|
||||
mode = hdimage_get_mode_id(image_mode);
|
||||
}
|
||||
if (imgmode == NULL) {
|
||||
hdimage_detect_image_mode(bx_filename_1, &imgmode);
|
||||
}
|
||||
if (mode == -1) {
|
||||
if (imgmode == NULL) {
|
||||
fatal("source disk image mode not detected");
|
||||
} else {
|
||||
printf("source image mode = '%s'\n", hdimage_mode_names[mode]);
|
||||
printf("source image mode = '%s'\n", imgmode);
|
||||
}
|
||||
|
||||
source_image = init_image(mode);
|
||||
source_image = init_image(imgmode);
|
||||
if (source_image->open(bx_filename_1, O_RDONLY) < 0)
|
||||
fatal("cannot open source disk image");
|
||||
|
||||
|
@ -885,20 +800,17 @@ void commit_redolog()
|
|||
{
|
||||
device_image_t *base_image;
|
||||
redolog_t *redolog;
|
||||
int mode = -1, ret;
|
||||
const char *image_mode = NULL;
|
||||
int ret;
|
||||
const char *imgmode = NULL;
|
||||
|
||||
printf("\n");
|
||||
if (access(bx_filename_1, F_OK) < 0) {
|
||||
fatal("base disk image doesn't exist");
|
||||
}
|
||||
if (hdimage_detect_image_mode(bx_filename_1, &image_mode)) {
|
||||
mode = hdimage_get_mode_id(image_mode);
|
||||
}
|
||||
if (mode == -1)
|
||||
if (!hdimage_detect_image_mode(bx_filename_1, &imgmode))
|
||||
fatal("base disk image mode not detected");
|
||||
|
||||
base_image = init_image(mode);
|
||||
base_image = init_image(imgmode);
|
||||
if (base_image->open(bx_filename_1) < 0)
|
||||
fatal("cannot open base disk image");
|
||||
|
||||
|
@ -927,7 +839,7 @@ void print_usage()
|
|||
fprintf(stderr,
|
||||
"Usage: bximage [options] [filename1] [filename2]\n\n"
|
||||
"Supported options:\n"
|
||||
" -mode=... operation mode (create, convert, resize, commit, info)\n"
|
||||
" -func=... operation to perform (create, convert, resize, commit, info)\n"
|
||||
" -fd=... create: floppy image with size code\n"
|
||||
" -hd=... create/resize: hard disk image with size in megabytes (M)\n"
|
||||
" or gigabytes (G)\n"
|
||||
|
@ -947,7 +859,7 @@ void print_usage()
|
|||
|
||||
void set_default_values()
|
||||
{
|
||||
if (bximage_mode == BXIMAGE_MODE_CREATE_IMAGE) {
|
||||
if (bximage_func == BXIMAGE_FUNC_CREATE_IMAGE) {
|
||||
if (bx_hdimage == -1) {
|
||||
bx_hdimage = 1;
|
||||
bx_fdsize_idx = 6;
|
||||
|
@ -968,12 +880,12 @@ void set_default_values()
|
|||
bx_interactive = 1;
|
||||
}
|
||||
}
|
||||
} else if (bximage_mode == BXIMAGE_MODE_CONVERT_IMAGE) {
|
||||
} else if (bximage_func == BXIMAGE_FUNC_CONVERT_IMAGE) {
|
||||
if (bx_imagemode == -1) {
|
||||
bx_imagemode = 0;
|
||||
bx_interactive = 1;
|
||||
}
|
||||
} else if (bximage_mode == BXIMAGE_MODE_RESIZE_IMAGE) {
|
||||
} else if (bximage_func == BXIMAGE_FUNC_RESIZE_IMAGE) {
|
||||
if (bx_hdsize == 0) {
|
||||
bx_interactive = 1;
|
||||
}
|
||||
|
@ -987,7 +899,7 @@ int parse_cmdline(int argc, char *argv[])
|
|||
int fnargs = 0;
|
||||
char *suffix;
|
||||
|
||||
bximage_mode = BXIMAGE_MODE_NULL;
|
||||
bximage_func = BXIMAGE_FUNC_NULL;
|
||||
bx_hdimage = -1;
|
||||
bx_fdsize_idx = -1;
|
||||
bx_hdsize = 0;
|
||||
|
@ -1004,20 +916,20 @@ int parse_cmdline(int argc, char *argv[])
|
|||
print_usage();
|
||||
ret = 0;
|
||||
}
|
||||
else if (!strncmp("-mode=", argv[arg], 6)) {
|
||||
if (bximage_mode != BXIMAGE_MODE_NULL) {
|
||||
else if (!strncmp("-func=", argv[arg], 6)) {
|
||||
if (bximage_func != BXIMAGE_FUNC_NULL) {
|
||||
printf("bximage mode already defined\n\n");
|
||||
ret = 0;
|
||||
} else if (!strcmp(&argv[arg][6], "create")) {
|
||||
bximage_mode = BXIMAGE_MODE_CREATE_IMAGE;
|
||||
bximage_func = BXIMAGE_FUNC_CREATE_IMAGE;
|
||||
} else if (!strcmp(&argv[arg][6], "convert")) {
|
||||
bximage_mode = BXIMAGE_MODE_CONVERT_IMAGE;
|
||||
bximage_func = BXIMAGE_FUNC_CONVERT_IMAGE;
|
||||
} else if (!strcmp(&argv[arg][6], "resize")) {
|
||||
bximage_mode = BXIMAGE_MODE_RESIZE_IMAGE;
|
||||
bximage_func = BXIMAGE_FUNC_RESIZE_IMAGE;
|
||||
} else if (!strcmp(&argv[arg][6], "commit")) {
|
||||
bximage_mode = BXIMAGE_MODE_COMMIT_UNDOABLE;
|
||||
bximage_func = BXIMAGE_FUNC_COMMIT_UNDOABLE;
|
||||
} else if (!strcmp(&argv[arg][6], "info")) {
|
||||
bximage_mode = BXIMAGE_MODE_IMAGE_INFO;
|
||||
bximage_func = BXIMAGE_FUNC_IMAGE_INFO;
|
||||
} else {
|
||||
printf("Unknown bximage mode '%s'\n\n", &argv[arg][6]);
|
||||
ret = 0;
|
||||
|
@ -1086,14 +998,14 @@ int parse_cmdline(int argc, char *argv[])
|
|||
}
|
||||
arg++;
|
||||
}
|
||||
if (bximage_mode == BXIMAGE_MODE_NULL) {
|
||||
if (bximage_func == BXIMAGE_FUNC_NULL) {
|
||||
bx_interactive = 1;
|
||||
} else {
|
||||
set_default_values();
|
||||
if (fnargs < 1) {
|
||||
bx_interactive = 1;
|
||||
}
|
||||
if ((bximage_mode == BXIMAGE_MODE_COMMIT_UNDOABLE) && (fnargs == 1)) {
|
||||
if ((bximage_func == BXIMAGE_FUNC_COMMIT_UNDOABLE) && (fnargs == 1)) {
|
||||
snprintf(bx_filename_2, 520, "%s%s", bx_filename_1, UNDOABLE_REDOLOG_EXTENSION);
|
||||
}
|
||||
}
|
||||
|
@ -1132,31 +1044,26 @@ void check_image_names()
|
|||
}
|
||||
}
|
||||
|
||||
int get_image_mode_and_hdsize(const char *filename, int *hdsize_megs)
|
||||
int get_image_mode_and_hdsize(const char *filename, const char **image_mode)
|
||||
{
|
||||
device_image_t *source_image;
|
||||
int mode = -1;
|
||||
const char *image_mode = NULL;
|
||||
int hdsize_megs = 0;
|
||||
|
||||
if (hdimage_detect_image_mode(bx_filename_1, &image_mode)) {
|
||||
mode = hdimage_get_mode_id(image_mode);
|
||||
}
|
||||
if (mode == -1)
|
||||
if (!hdimage_detect_image_mode(bx_filename_1, image_mode))
|
||||
fatal("source disk image mode not detected");
|
||||
source_image = init_image(mode);
|
||||
source_image = init_image(*image_mode);
|
||||
if (source_image->open(bx_filename_1, O_RDONLY) < 0) {
|
||||
fatal("cannot open source disk image");
|
||||
} else {
|
||||
*hdsize_megs = (int)(source_image->hd_size >> 20);
|
||||
hdsize_megs = (int)(source_image->hd_size >> 20);
|
||||
source_image->close();
|
||||
}
|
||||
return mode;
|
||||
return hdsize_megs;
|
||||
}
|
||||
|
||||
int CDECL main(int argc, char *argv[])
|
||||
{
|
||||
char bochsrc_line[1024], prompt[80], tmpfname[528];
|
||||
int imgmode = 0;
|
||||
Bit64u hdsize = 0;
|
||||
device_image_t *hdimage;
|
||||
const char *image_mode = NULL;
|
||||
|
@ -1167,16 +1074,16 @@ int CDECL main(int argc, char *argv[])
|
|||
print_banner();
|
||||
|
||||
if (bx_interactive) {
|
||||
if (ask_int(main_menu_prompt, 0, 5, bximage_mode, &bximage_mode) < 0)
|
||||
if (ask_int(main_menu_prompt, 0, 5, bximage_func, &bximage_func) < 0)
|
||||
fatal(EOF_ERR);
|
||||
|
||||
set_default_values();
|
||||
switch (bximage_mode) {
|
||||
case BXIMAGE_MODE_NULL:
|
||||
switch (bximage_func) {
|
||||
case BXIMAGE_FUNC_NULL:
|
||||
myexit(0);
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_CREATE_IMAGE:
|
||||
case BXIMAGE_FUNC_CREATE_IMAGE:
|
||||
printf("\nCreate image\n");
|
||||
if (ask_menu(fdhd_menu, fdhd_n_choices, fdhd_choices, bx_hdimage, &bx_hdimage) < 0)
|
||||
fatal(EOF_ERR);
|
||||
|
@ -1191,10 +1098,10 @@ int CDECL main(int argc, char *argv[])
|
|||
} else { // hard disk
|
||||
if (ask_menu(hdmode_menu, hdmode_n_choices, hdmode_choices, bx_imagemode, &bx_imagemode) < 0)
|
||||
fatal(EOF_ERR);
|
||||
imgmode = hdmode_choice_id[bx_imagemode];
|
||||
if ((imgmode == BX_HDIMAGE_MODE_FLAT) ||
|
||||
(imgmode == BX_HDIMAGE_MODE_SPARSE) ||
|
||||
(imgmode == BX_HDIMAGE_MODE_GROWING)) {
|
||||
image_mode = hdmode_choices[bx_imagemode];
|
||||
if (!strcmp(image_mode, "flat") ||
|
||||
!strcmp(image_mode, "sparse") ||
|
||||
!strcmp(image_mode, "growing")) {
|
||||
if (ask_menu(sectsize_menu, sectsize_n_choices, sectsize_choices, bx_sectsize_idx, &bx_sectsize_idx) < 0)
|
||||
fatal(EOF_ERR);
|
||||
bx_sectsize_val = atoi(sectsize_choices[bx_sectsize_idx]);
|
||||
|
@ -1213,7 +1120,7 @@ int CDECL main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_CONVERT_IMAGE:
|
||||
case BXIMAGE_FUNC_CONVERT_IMAGE:
|
||||
printf("\nConvert image\n");
|
||||
if (!strlen(bx_filename_1)) {
|
||||
strcpy(bx_filename_1, "c.img");
|
||||
|
@ -1235,7 +1142,7 @@ int CDECL main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_RESIZE_IMAGE:
|
||||
case BXIMAGE_FUNC_RESIZE_IMAGE:
|
||||
printf("\nResize image\n");
|
||||
if (!strlen(bx_filename_1)) {
|
||||
strcpy(bx_filename_1, "c.img");
|
||||
|
@ -1249,7 +1156,7 @@ int CDECL main(int argc, char *argv[])
|
|||
}
|
||||
if (ask_string("\nWhat should be the name of the new image?\n", tmpfname, bx_filename_2) < 0)
|
||||
fatal(EOF_ERR);
|
||||
imgmode = get_image_mode_and_hdsize(bx_filename_1, &bx_min_hd_megs);
|
||||
bx_min_hd_megs = get_image_mode_and_hdsize(bx_filename_1, &image_mode);
|
||||
sprintf(prompt, "\nEnter the new hard disk size in megabytes, between %d and %d\n",
|
||||
bx_min_hd_megs, bx_max_hd_megs);
|
||||
if (bx_hdsize < bx_min_hd_megs) bx_hdsize = bx_min_hd_megs;
|
||||
|
@ -1261,7 +1168,7 @@ int CDECL main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_COMMIT_UNDOABLE:
|
||||
case BXIMAGE_FUNC_COMMIT_UNDOABLE:
|
||||
printf("\nCommit redolog\n");
|
||||
if (!strlen(bx_filename_1)) {
|
||||
strcpy(bx_filename_1, "c.img");
|
||||
|
@ -1279,7 +1186,7 @@ int CDECL main(int argc, char *argv[])
|
|||
fatal(EOF_ERR);
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_IMAGE_INFO:
|
||||
case BXIMAGE_FUNC_IMAGE_INFO:
|
||||
printf("\nDisk image info\n");
|
||||
if (!strlen(bx_filename_1)) {
|
||||
strcpy(bx_filename_1, "c.img");
|
||||
|
@ -1292,8 +1199,8 @@ int CDECL main(int argc, char *argv[])
|
|||
fatal("\nbximage: unknown mode");
|
||||
}
|
||||
}
|
||||
switch (bximage_mode) {
|
||||
case BXIMAGE_MODE_CREATE_IMAGE:
|
||||
switch (bximage_func) {
|
||||
case BXIMAGE_FUNC_CREATE_IMAGE:
|
||||
image_overwrite_check(bx_filename_1);
|
||||
if (bx_hdimage == 0) {
|
||||
sprintf(bochsrc_line, "floppya: image=\"%s\", status=inserted", bx_filename_1);
|
||||
|
@ -1309,7 +1216,7 @@ int CDECL main(int argc, char *argv[])
|
|||
sprintf(bochsrc_line, "ata0-master: type=disk, path=\"%s\", mode=%s, sect_size=%d",
|
||||
bx_filename_1, hdmode_choices[bx_imagemode], bx_sectsize_val);
|
||||
}
|
||||
imgmode = hdmode_choice_id[bx_imagemode];
|
||||
image_mode = hdmode_choices[bx_imagemode];
|
||||
hdsize = ((Bit64u)bx_hdsize) << 20;
|
||||
Bit64u cyl = (Bit64u)(hdsize/16.0/63.0/bx_sectsize_val);
|
||||
if (cyl >= (1 << BX_MAX_CYL_BITS))
|
||||
|
@ -1317,7 +1224,7 @@ int CDECL main(int argc, char *argv[])
|
|||
printf("\nCreating hard disk image '%s' with CHS=" FMT_LL "d/%d/%d (sector size = %d)\n",
|
||||
bx_filename_1, cyl, heads, spt, bx_sectsize_val);
|
||||
hdsize = cyl * heads * spt * bx_sectsize_val;
|
||||
create_hard_disk_image(bx_filename_1, imgmode, hdsize);
|
||||
create_hard_disk_image(bx_filename_1, image_mode, hdsize);
|
||||
}
|
||||
printf("\nThe following line should appear in your bochsrc:\n");
|
||||
printf(" %s\n", bochsrc_line);
|
||||
|
@ -1335,22 +1242,22 @@ int CDECL main(int argc, char *argv[])
|
|||
#endif
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_CONVERT_IMAGE:
|
||||
case BXIMAGE_FUNC_CONVERT_IMAGE:
|
||||
check_image_names();
|
||||
imgmode = hdmode_choice_id[bx_imagemode];
|
||||
convert_image(imgmode, 0);
|
||||
image_mode = hdmode_choices[bx_imagemode];
|
||||
convert_image(image_mode, 0);
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_RESIZE_IMAGE:
|
||||
imgmode = get_image_mode_and_hdsize(bx_filename_1, &bx_min_hd_megs);
|
||||
case BXIMAGE_FUNC_RESIZE_IMAGE:
|
||||
bx_min_hd_megs = get_image_mode_and_hdsize(bx_filename_1, &image_mode);
|
||||
if (bx_hdsize < bx_min_hd_megs)
|
||||
fatal("invalid image size");
|
||||
hdsize = ((Bit64u)bx_hdsize) << 20;
|
||||
check_image_names();
|
||||
convert_image(imgmode, hdsize);
|
||||
convert_image(image_mode, hdsize);
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_COMMIT_UNDOABLE:
|
||||
case BXIMAGE_FUNC_COMMIT_UNDOABLE:
|
||||
if (bx_backup) {
|
||||
snprintf(tmpfname, 517, "%s%s", bx_filename_1, ".orig");
|
||||
if (hdimage_copy_file(bx_filename_1, tmpfname) != 1)
|
||||
|
@ -1367,17 +1274,13 @@ int CDECL main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
|
||||
case BXIMAGE_MODE_IMAGE_INFO:
|
||||
imgmode = -1;
|
||||
if (hdimage_detect_image_mode(bx_filename_1, &image_mode)) {
|
||||
imgmode = hdimage_get_mode_id(image_mode);
|
||||
}
|
||||
if (imgmode == -1) {
|
||||
case BXIMAGE_FUNC_IMAGE_INFO:
|
||||
if (!hdimage_detect_image_mode(bx_filename_1, &image_mode)) {
|
||||
fatal("disk image mode not detected");
|
||||
} else {
|
||||
printf("\ndisk image mode = '%s'\n", hdimage_mode_names[imgmode]);
|
||||
printf("\ndisk image mode = '%s'\n", image_mode);
|
||||
}
|
||||
hdimage = init_image(imgmode);
|
||||
hdimage = init_image(image_mode);
|
||||
if (hdimage->open(bx_filename_1, O_RDONLY) < 0) {
|
||||
fatal("cannot open source disk image");
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue