- added initial 'virtual VFAT' image support (shadows a local directory)

* ported the read part of the Qemu vvfat block driver
  * added win32 specific directory functions (required for MSVC)
  * TODO: write support, FAT32 support, read MBR and boot sector from file
This commit is contained in:
Volker Ruppert 2010-12-23 16:17:12 +00:00
parent 709059ddcc
commit 341c764e1f
6 changed files with 1327 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.216 2010-12-10 17:02:18 vruppert Exp $
// $Id: siminterface.cc,v 1.217 2010-12-23 16:16:17 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 The Bochs Project
@ -482,6 +482,7 @@ const char *hdimage_mode_names[] = {
"volatile",
"z-undoable",
"z-volatile",
"vvfat",
NULL
};

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.256 2010-12-10 17:02:18 vruppert Exp $
// $Id: siminterface.h,v 1.257 2010-12-23 16:16:17 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 The Bochs Project
@ -522,7 +522,8 @@ enum {
#define BX_HDIMAGE_MODE_VOLATILE 9
#define BX_HDIMAGE_MODE_Z_UNDOABLE 10
#define BX_HDIMAGE_MODE_Z_VOLATILE 11
#define BX_HDIMAGE_MODE_LAST 11
#define BX_HDIMAGE_MODE_VVFAT 12
#define BX_HDIMAGE_MODE_LAST 12
#define BX_CLOCK_SYNC_NONE 0
#define BX_CLOCK_SYNC_REALTIME 1

View File

@ -98,6 +98,7 @@ OBJS_THAT_SUPPORT_OTHER_PLUGINS = \
hdimage.o \
vmware3.o \
vmware4.o \
vvfat.o \
$(CDROM_OBJS) \
$(SOUNDLOW_OBJS) \
$(NETLOW_OBJS) \
@ -135,8 +136,8 @@ libbx_%.la: %.lo
$(LIBTOOL) --mode=link $(CXX) -module $< -o $@ -rpath $(PLUGIN_PATH)
# special link rules for plugins that require more than one object file
libbx_harddrv.la: harddrv.lo hdimage.lo vmware3.lo vmware4.lo $(CDROM_OBJS:.o=.lo)
$(LIBTOOL) --mode=link $(CXX) -module harddrv.lo hdimage.lo vmware3.lo vmware4.lo $(CDROM_OBJS:.o=.lo) -o libbx_harddrv.la -rpath $(PLUGIN_PATH)
libbx_harddrv.la: harddrv.lo hdimage.lo vmware3.lo vmware4.lo vvfat.lo $(CDROM_OBJS:.o=.lo)
$(LIBTOOL) --mode=link $(CXX) -module harddrv.lo hdimage.lo vmware3.lo vmware4.lo vvfat.lo $(CDROM_OBJS:.o=.lo) -o libbx_harddrv.la -rpath $(PLUGIN_PATH)
libbx_keyboard.la: keyboard.lo scancodes.lo
$(LIBTOOL) --mode=link $(CXX) -module keyboard.lo scancodes.lo -o libbx_keyboard.la -rpath $(PLUGIN_PATH)
@ -159,16 +160,16 @@ libbx_serial.la: serial.lo serial_raw.lo
libbx_vga.la: vga.lo svga_cirrus.lo
$(LIBTOOL) --mode=link $(CXX) -module vga.lo svga_cirrus.lo -o libbx_vga.la -rpath $(PLUGIN_PATH)
libbx_usb_common.la: usb_common.lo $(USBDEV_OBJS:.o=.lo) scsi_device.lo hdimage.lo vmware3.lo vmware4.lo $(CDROM_OBJS:.o=.lo)
$(LIBTOOL) --mode=link $(CXX) -module usb_common.lo $(USBDEV_OBJS:.o=.lo) scsi_device.lo hdimage.lo vmware3.lo vmware4.lo $(CDROM_OBJS:.o=.lo) -o libbx_usb_common.la -rpath $(PLUGIN_PATH)
libbx_usb_common.la: usb_common.lo $(USBDEV_OBJS:.o=.lo) scsi_device.lo hdimage.lo vmware3.lo vmware4.lo vvfat.lo $(CDROM_OBJS:.o=.lo)
$(LIBTOOL) --mode=link $(CXX) -module usb_common.lo $(USBDEV_OBJS:.o=.lo) scsi_device.lo hdimage.lo vmware3.lo vmware4.lo vvfat.lo $(CDROM_OBJS:.o=.lo) -o libbx_usb_common.la -rpath $(PLUGIN_PATH)
#### building DLLs for win32 (tested on cygwin only)
bx_%.dll: %.o
$(CXX) $(CXXFLAGS) -shared -o $@ $< $(WIN32_DLL_IMPORT_LIBRARY)
# special link rules for plugins that require more than one object file
bx_harddrv.dll: harddrv.o hdimage.o vmware3.o vmware4.o $(CDROM_OBJS)
$(CXX) $(CXXFLAGS) -shared -o bx_harddrv.dll harddrv.o hdimage.o vmware3.o vmware4.o $(CDROM_OBJS) $(WIN32_DLL_IMPORT_LIBRARY)
bx_harddrv.dll: harddrv.o hdimage.o vmware3.o vmware4.o vvfat.o $(CDROM_OBJS)
$(CXX) $(CXXFLAGS) -shared -o bx_harddrv.dll harddrv.o hdimage.o vmware3.o vmware4.o vvfat.o $(CDROM_OBJS) $(WIN32_DLL_IMPORT_LIBRARY)
bx_keyboard.dll: keyboard.o scancodes.o
$(CXX) $(CXXFLAGS) -shared -o bx_keyboard.dll keyboard.o scancodes.o $(WIN32_DLL_IMPORT_LIBRARY)
@ -194,8 +195,8 @@ bx_serial.dll: serial.o serial_raw.o
bx_vga.dll: vga.o svga_cirrus.o
$(CXX) $(CXXFLAGS) -shared -o bx_vga.dll vga.o svga_cirrus.o $(WIN32_DLL_IMPORT_LIBRARY)
bx_usb_common.dll: usb_common.o $(USBDEV_OBJS) scsi_device.o hdimage.o vmware3.o vmware4.o $(CDROM_OBJS)
$(CXX) $(CXXFLAGS) -shared -o bx_usb_common.dll usb_common.o $(USBDEV_OBJS) scsi_device.o hdimage.o vmware3.o vmware4.o $(CDROM_OBJS) $(WIN32_DLL_IMPORT_LIBRARY)
bx_usb_common.dll: usb_common.o $(USBDEV_OBJS) scsi_device.o hdimage.o vmware3.o vmware4.o vvfat.o $(CDROM_OBJS)
$(CXX) $(CXXFLAGS) -shared -o bx_usb_common.dll usb_common.o $(USBDEV_OBJS) scsi_device.o hdimage.o vmware3.o vmware4.o vvfat.o $(CDROM_OBJS) $(WIN32_DLL_IMPORT_LIBRARY)
##### end DLL section

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: hdimage.cc,v 1.23 2010-12-21 21:47:41 vruppert Exp $
// $Id: hdimage.cc,v 1.24 2010-12-23 16:16:17 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2009 The Bochs Project
@ -29,6 +29,7 @@
#include "hdimage.h"
#include "vmware3.h"
#include "vmware4.h"
#include "vvfat.h"
#if BX_HAVE_SYS_MMAN_H
#include <sys/mman.h>
@ -1817,6 +1818,10 @@ device_image_t *hdimage_init_image(Bit8u image_mode, Bit64u disk_size, const cha
break;
#endif //BX_COMPRESSED_HD_SUPPORT
case BX_HDIMAGE_MODE_VVFAT:
hdimage = new vvfat_image_t();
break;
default:
BX_PANIC(("unsupported HD mode : '%s'", hdimage_mode_names[image_mode]));
break;

1142
bochs/iodev/vvfat.cc Normal file

File diff suppressed because it is too large Load Diff

165
bochs/iodev/vvfat.h Normal file
View File

@ -0,0 +1,165 @@
/////////////////////////////////////////////////////////////////////////
// $Id: vvfat.h,v 1.1 2010-12-23 16:17:12 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2010 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/////////////////////////////////////////////////////////////////////////
#ifndef BX_VVFAT_H
#define BX_VVFAT_H
typedef struct array_t {
char *pointer;
unsigned int size, next, item_size;
} array_t;
typedef struct {
Bit8u head;
Bit8u sector;
Bit8u cylinder;
} mbr_chs_t;
#if defined(_MSC_VER) && (_MSC_VER<1300)
#pragma pack(push, 1)
#elif defined(__MWERKS__) && defined(macintosh)
#pragma options align=packed
#endif
typedef
#if defined(_MSC_VER) && (_MSC_VER>=1300)
__declspec(align(1))
#endif
struct direntry_t {
Bit8u name[8];
Bit8u extension[3];
Bit8u attributes;
Bit8u reserved[2];
Bit16u ctime;
Bit16u cdate;
Bit16u adate;
Bit16u begin_hi;
Bit16u mtime;
Bit16u mdate;
Bit16u begin;
Bit32u size;
}
#if !defined(_MSC_VER)
GCC_ATTRIBUTE((packed))
#endif
direntry_t;
#if defined(_MSC_VER) && (_MSC_VER<1300)
#pragma pack(pop)
#elif defined(__MWERKS__) && defined(macintosh)
#pragma options align=reset
#endif
// this structure are used to transparently access the files
enum {
MODE_UNDEFINED = 0, MODE_NORMAL = 1, MODE_MODIFIED = 2,
MODE_DIRECTORY = 4, MODE_FAKED = 8,
MODE_DELETED = 16, MODE_RENAMED = 32
};
typedef struct mapping_t {
// begin is the first cluster, end is the last+1
Bit32u begin, end;
// as s->directory is growable, no pointer may be used here
unsigned int dir_index;
// the clusters of a file may be in any order; this points to the first
int first_mapping_index;
union {
/* offset is
* - the offset in the file (in clusters) for a file, or
* - the next cluster of the directory for a directory, and
* - the address of the buffer for a faked entry
*/
struct {
Bit32u offset;
} file;
struct {
int parent_mapping_index;
int first_dir_index;
} dir;
} info;
// path contains the full path, i.e. it always starts with s->path
char *path;
Bit8u mode;
int read_only;
} mapping_t;
class vvfat_image_t : public device_image_t
{
public:
vvfat_image_t();
virtual ~vvfat_image_t();
int open(const char* dirname);
void close();
Bit64s lseek(Bit64s offset, int whence);
ssize_t read(void* buf, size_t count);
ssize_t write(const void* buf, size_t count);
Bit32u get_capabilities();
private:
bx_bool sector2CHS(Bit32u spos, mbr_chs_t *chs);
void init_mbr();
direntry_t* create_long_filename(const char* filename);
void fat_set(unsigned int cluster, Bit32u value);
void init_fat();
direntry_t* create_short_and_long_name(unsigned int directory_start,
const char* filename, int is_dot);
int read_directory(int mapping_index);
Bit32u sector2cluster(off_t sector_num);
int init_directories(const char* dirname);
void close_current_file(void);
int open_file(mapping_t* mapping);
int find_mapping_for_cluster_aux(int cluster_num, int index1, int index2);
mapping_t* find_mapping_for_cluster(int cluster_num);
int read_cluster(int cluster_num);
Bit32u n_first_sectors;
Bit8u *first_sectors;
Bit8u fat_type;
array_t fat, directory, mapping;
Bit16u cluster_size;
Bit8u sectors_per_cluster;
Bit8u sectors_per_fat;
Bit16u sectors_of_root_directory;
Bit32u last_cluster_of_root_directory;
Bit16u faked_sectors; // how many sectors are faked before file data
Bit32u sector_count;
Bit32u cluster_count; // total number of clusters of this partition
Bit32u max_fat_value;
int current_fd;
mapping_t* current_mapping;
Bit8u *cluster; // points to current cluster
Bit8u *cluster_buffer; // points to a buffer to hold temp data
Bit16u current_cluster;
const char *path;
Bit32u sector_num;
};
#endif