Some work on the hdimage mode detection code.

- In plugin mode make sure all hdimage plugins are loaded for mode detection.
- Implemented image mode detection via hdimage_locator_c.
- TODO: use the new code for bximage, too.
This commit is contained in:
Volker Ruppert 2021-01-08 21:17:47 +00:00
parent 04c767d240
commit afcda20b83
7 changed files with 35 additions and 5 deletions

View File

@ -33,7 +33,7 @@
#include "cdrom_win32.h" #include "cdrom_win32.h"
#endif #endif
#include "hdimage.h" #include "hdimage.h"
#if !BX_PLUGINS || defined(BXIMAGE) #ifdef BXIMAGE
#include "vbox.h" #include "vbox.h"
#include "vmware3.h" #include "vmware3.h"
#include "vmware4.h" #include "vmware4.h"
@ -292,6 +292,20 @@ hdimage_locator_c::create(const char *mode, Bit64u disk_size, const char *journa
return NULL; return NULL;
} }
bool hdimage_locator_c::detect_image_mode(int fd, Bit64u disk_size,
const char **image_mode)
{
hdimage_locator_c *ptr = 0;
for (ptr = all; ptr != NULL; ptr = ptr->next) {
if (ptr->check_format(fd, disk_size) == HDIMAGE_FORMAT_OK) {
*image_mode = ptr->mode;
return 1;
}
}
return 0;
}
#endif // ifndef BXIMAGE #endif // ifndef BXIMAGE
// helper functions // helper functions
@ -440,7 +454,7 @@ bool hdimage_detect_image_mode(const char *pathname, const char **image_mode)
} else if (growing_image_t::check_format(fd, image_size) == HDIMAGE_FORMAT_OK) { } else if (growing_image_t::check_format(fd, image_size) == HDIMAGE_FORMAT_OK) {
*image_mode = "growing"; *image_mode = "growing";
result = true; result = true;
#if !BX_PLUGINS || defined(BXIMAGE) #ifdef BXIMAGE
} else if (vbox_image_t::check_format(fd, image_size) >= HDIMAGE_FORMAT_OK) { } else if (vbox_image_t::check_format(fd, image_size) >= HDIMAGE_FORMAT_OK) {
*image_mode = "vbox"; *image_mode = "vbox";
result = true; result = true;
@ -453,6 +467,9 @@ bool hdimage_detect_image_mode(const char *pathname, const char **image_mode)
} else if (vpc_image_t::check_format(fd, image_size) >= HDIMAGE_FORMAT_OK) { } else if (vpc_image_t::check_format(fd, image_size) >= HDIMAGE_FORMAT_OK) {
*image_mode = "vpc"; *image_mode = "vpc";
result = true; result = true;
#else
} else if (hdimage_locator_c::detect_image_mode(fd, image_size, image_mode)) {
result = true;
#endif #endif
} else if (flat_image_t::check_format(fd, image_size) == HDIMAGE_FORMAT_OK) { } else if (flat_image_t::check_format(fd, image_size) == HDIMAGE_FORMAT_OK) {
*image_mode = "flat"; *image_mode = "flat";

View File

@ -628,10 +628,12 @@ public:
static const char* get_module_name(Bit8u index); static const char* get_module_name(Bit8u index);
static void cleanup(void); static void cleanup(void);
static device_image_t *create(const char *mode, Bit64u disk_size, const char *journal); static device_image_t *create(const char *mode, Bit64u disk_size, const char *journal);
static bool detect_image_mode(int fd, Bit64u disk_size, const char **image_mode);
protected: protected:
hdimage_locator_c(const char *mode); hdimage_locator_c(const char *mode);
virtual ~hdimage_locator_c(); virtual ~hdimage_locator_c();
virtual device_image_t *allocate(Bit64u disk_size, const char *journal) = 0; virtual device_image_t *allocate(Bit64u disk_size, const char *journal) = 0;
virtual int check_format(int fd, Bit64u disk_size) {return -1;}
private: private:
static Bit8u count; static Bit8u count;
static hdimage_locator_c *all; static hdimage_locator_c *all;

View File

@ -80,6 +80,9 @@ protected:
device_image_t *allocate(Bit64u disk_size, const char *journal) { device_image_t *allocate(Bit64u disk_size, const char *journal) {
return (new vbox_image_t()); return (new vbox_image_t());
} }
int check_format(int fd, Bit64u disk_size) {
return (vbox_image_t::check_format(fd, disk_size));
}
} bx_vbox_match; } bx_vbox_match;
#endif #endif

View File

@ -75,6 +75,9 @@ protected:
device_image_t *allocate(Bit64u disk_size, const char *journal) { device_image_t *allocate(Bit64u disk_size, const char *journal) {
return (new vmware3_image_t()); return (new vmware3_image_t());
} }
int check_format(int fd, Bit64u disk_size) {
return (vmware3_image_t::check_format(fd, disk_size));
}
} bx_vmware3_match; } bx_vmware3_match;
#endif #endif

View File

@ -73,6 +73,9 @@ protected:
device_image_t *allocate(Bit64u disk_size, const char *journal) { device_image_t *allocate(Bit64u disk_size, const char *journal) {
return (new vmware4_image_t()); return (new vmware4_image_t());
} }
int check_format(int fd, Bit64u disk_size) {
return (vmware4_image_t::check_format(fd, disk_size));
}
} bx_vmware4_match; } bx_vmware4_match;
#endif #endif

View File

@ -71,6 +71,9 @@ protected:
device_image_t *allocate(Bit64u disk_size, const char *journal) { device_image_t *allocate(Bit64u disk_size, const char *journal) {
return (new vpc_image_t()); return (new vpc_image_t());
} }
int check_format(int fd, Bit64u disk_size) {
return (vpc_image_t::check_format(fd, disk_size));
}
} bx_vpc_match; } bx_vpc_match;
#endif #endif

View File

@ -751,9 +751,8 @@ int bx_load_plugin(const char *name, plugintype_t type)
if (!strcmp(name, "*")) { if (!strcmp(name, "*")) {
for (plugin = plugins; plugin; plugin = plugin->next) { for (plugin = plugins; plugin; plugin = plugin->next) {
if (!strcmp(plugin->name, name) && (type == plugin->type) && if ((type == plugin->type) && !plugin->loaded) {
!plugin->loaded) { plugin_load(plugin->name, type);
plugin_load(name, type);
} }
} }
} else { } else {