mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-02-16 14:30:34 +00:00
Generify vhd, too
This commit is contained in:
parent
5c7af60f16
commit
17aabc4c40
@ -36,5 +36,6 @@ struct disk_generic {
|
||||
typedef disk_generic *(disk_factory)(const char *path, bool read_only);
|
||||
|
||||
extern disk_factory disk_sparsebundle_factory;
|
||||
extern disk_factory disk_vhd_factory;
|
||||
|
||||
#endif
|
||||
|
@ -62,9 +62,6 @@
|
||||
#include "bincue_unix.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
#include "vhd_unix.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define DEBUG 0
|
||||
@ -72,6 +69,9 @@
|
||||
|
||||
static disk_factory *disk_factories[] = {
|
||||
disk_sparsebundle_factory,
|
||||
#if defined(HAVE_LIBVHD)
|
||||
disk_vhd_factory,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -104,11 +104,6 @@ struct mac_file_handle {
|
||||
bool is_bincue; // Flag: BIN CUE file
|
||||
void *bincue_fd;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
bool is_vhd; // Flag: VHD file
|
||||
void *vhd_fd;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Open file handles
|
||||
@ -608,22 +603,6 @@ void *Sys_open(const char *name, bool read_only)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
int vhdsize;
|
||||
void *vhdfd = vhd_unix_open(name, &vhdsize, read_only);
|
||||
if (vhdfd) {
|
||||
mac_file_handle *fh = open_filehandle(name);
|
||||
D(bug("opening %s as vnd\n", name));
|
||||
fh->is_vhd = true;
|
||||
fh->vhd_fd = vhdfd;
|
||||
fh->read_only = read_only;
|
||||
fh->file_size = vhdsize;
|
||||
fh->is_media_present = true;
|
||||
sys_add_mac_file_handle(fh);
|
||||
return fh;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (disk_factory **f = disk_factories; *f; ++f) {
|
||||
disk_generic *generic = (*f)(name, read_only);
|
||||
if (generic) {
|
||||
@ -739,11 +718,6 @@ void Sys_close(void *arg)
|
||||
|
||||
sys_remove_mac_file_handle(fh);
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
if (fh->is_vhd)
|
||||
vhd_unix_close(fh->vhd_fd);
|
||||
#endif
|
||||
|
||||
#if defined(BINCUE)
|
||||
if (fh->is_bincue)
|
||||
close_bincue(fh->bincue_fd);
|
||||
@ -777,11 +751,6 @@ size_t Sys_read(void *arg, void *buffer, loff_t offset, size_t length)
|
||||
return read_bincue(fh->bincue_fd, buffer, offset, length);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
if (fh->is_vhd)
|
||||
return vhd_unix_read(fh->vhd_fd, buffer, offset, length);
|
||||
#endif
|
||||
|
||||
if (fh->generic_disk)
|
||||
return fh->generic_disk->read(buffer, offset, length);
|
||||
|
||||
@ -805,11 +774,6 @@ size_t Sys_write(void *arg, void *buffer, loff_t offset, size_t length)
|
||||
if (!fh)
|
||||
return 0;
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
if (fh->is_vhd)
|
||||
return vhd_unix_write(fh->vhd_fd, buffer, offset, length);
|
||||
#endif
|
||||
|
||||
if (fh->generic_disk)
|
||||
return fh->generic_disk->write(buffer, offset, length);
|
||||
|
||||
@ -837,11 +801,6 @@ loff_t SysGetFileSize(void *arg)
|
||||
return size_bincue(fh->bincue_fd);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
if (fh->is_vhd)
|
||||
return fh->file_size;
|
||||
#endif
|
||||
|
||||
if (fh->generic_disk)
|
||||
return fh->file_size;
|
||||
|
||||
@ -978,11 +937,6 @@ bool SysIsFixedDisk(void *arg)
|
||||
if (!fh)
|
||||
return true;
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
if (fh->is_vhd)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if (fh->generic_disk)
|
||||
return true;
|
||||
|
||||
@ -1005,11 +959,6 @@ bool SysIsDiskInserted(void *arg)
|
||||
if (!fh)
|
||||
return false;
|
||||
|
||||
#if defined(HAVE_LIBVHD)
|
||||
if (fh->is_vhd)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if (fh->generic_disk)
|
||||
return true;
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "sysdeps.h"
|
||||
#include "vhd_unix.h"
|
||||
#include "disk_unix.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -32,7 +32,7 @@ extern "C" {
|
||||
#define DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
void *vhd_unix_open(const char *name, int *size, bool read_only)
|
||||
static void *vhd_unix_open(const char *name, int *size, bool read_only)
|
||||
{
|
||||
int amode = read_only ? R_OK : (R_OK | W_OK);
|
||||
int fid;
|
||||
@ -79,9 +79,9 @@ void *vhd_unix_open(const char *name, int *size, bool read_only)
|
||||
}
|
||||
}
|
||||
|
||||
int vhd_unix_read(void *arg, void *buffer, loff_t offset, size_t length)
|
||||
static int vhd_unix_read(vhd_context_t *ctx, void *buffer, loff_t offset,
|
||||
size_t length)
|
||||
{
|
||||
vhd_context_t *ctx = (vhd_context_t *) arg;
|
||||
int err;
|
||||
if ((offset % VHD_SECTOR_SIZE) || (length % VHD_SECTOR_SIZE)) {
|
||||
printf("vhd read only supported on sector boundaries (%d)\n",
|
||||
@ -97,10 +97,10 @@ int vhd_unix_read(void *arg, void *buffer, loff_t offset, size_t length)
|
||||
return length;
|
||||
}
|
||||
|
||||
int vhd_unix_write(void *arg, void *buffer, loff_t offset, size_t length)
|
||||
static int vhd_unix_write(vhd_context_t *ctx, void *buffer, loff_t offset,
|
||||
size_t length)
|
||||
{
|
||||
int err;
|
||||
vhd_context_t *ctx = (vhd_context_t *) arg;
|
||||
|
||||
if ((offset % VHD_SECTOR_SIZE) || (length % VHD_SECTOR_SIZE)) {
|
||||
printf("vhd write only supported on sector boundaries (%d)\n",
|
||||
@ -116,9 +116,41 @@ int vhd_unix_write(void *arg, void *buffer, loff_t offset, size_t length)
|
||||
return length;
|
||||
}
|
||||
|
||||
void vhd_unix_close(void *arg)
|
||||
|
||||
static void vhd_unix_close(vhd_context_t *ctx)
|
||||
{
|
||||
D(bug("vhd close\n"));
|
||||
vhd_close((vhd_context_t *) arg);
|
||||
free(arg);
|
||||
vhd_close(ctx);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
||||
struct disk_vhd : disk_generic {
|
||||
disk_vhd(vhd_context_t *ctx, bool read_only, loff_t size)
|
||||
: ctx(ctx), read_only(read_only), file_size(size) { }
|
||||
|
||||
virtual ~disk_vhd() { vhd_unix_close(ctx); }
|
||||
virtual bool is_read_only() { return read_only; }
|
||||
virtual loff_t size() { return file_size; }
|
||||
|
||||
virtual size_t read(void *buf, loff_t offset, size_t length) {
|
||||
return vhd_unix_read(ctx, buf, offset, length);
|
||||
}
|
||||
|
||||
virtual size_t write(void *buf, loff_t offset, size_t length) {
|
||||
return vhd_unix_write(ctx, buf, offset, length);
|
||||
}
|
||||
|
||||
protected:
|
||||
vhd_context_t *ctx;
|
||||
bool read_only;
|
||||
loff_t file_size;
|
||||
};
|
||||
|
||||
disk_generic *disk_vhd_factory(const char *path, bool read_only) {
|
||||
int size;
|
||||
vhd_context_t *ctx = (vhd_context_t*)vhd_unix_open(path, &size, read_only);
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
return new disk_vhd(ctx, read_only, size);
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* vhd_unix.h -- support for disk images in vhd format
|
||||
*
|
||||
* (C) 2010 Geoffrey Brown
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef VHD_H
|
||||
#define VHD_H
|
||||
|
||||
void *vhd_unix_open(const char *name, int *size, bool read_only);
|
||||
int vhd_unix_read(void *arg, void *buffer, loff_t offset, size_t length);
|
||||
int vhd_unix_write(void *arg, void *buffer, loff_t offset, size_t length);
|
||||
void vhd_unix_close(void *arg);
|
||||
|
||||
#endif
|
@ -61,7 +61,7 @@ links:
|
||||
BeOS/serial_beos.cpp BeOS/sys_beos.cpp BeOS/timer_beos.cpp \
|
||||
BeOS/xpram_beos.cpp BeOS/SheepDriver BeOS/SheepNet \
|
||||
Unix/audio_oss_esd.cpp Unix/bincue_unix.cpp Unix/bincue_unix.h \
|
||||
Unix/vhd_unix.cpp Unix/vhd_unix.h \
|
||||
Unix/vhd_unix.cpp \
|
||||
Unix/extfs_unix.cpp Unix/serial_unix.cpp \
|
||||
Unix/sshpty.h Unix/sshpty.c Unix/strlcpy.h Unix/strlcpy.c \
|
||||
Unix/sys_unix.cpp Unix/timer_unix.cpp Unix/xpram_unix.cpp \
|
||||
|
@ -1 +0,0 @@
|
||||
../../../BasiliskII/src/Unix/vhd_unix.h
|
Loading…
x
Reference in New Issue
Block a user