#ifdef __V3VEE__
-#define V3_FileOpen(path, mode) \
+#define V3_FileOpen(path, mode, host_data) \
({ \
+ void * fd = NULL; \
extern struct v3_file_hooks * file_hooks; \
- ((file_hooks) && (file_hooks)->file_open) ? \
- (file_hooks)->file_open((path), (mode)) : -1; \
+ if ((file_hooks) && (file_hooks)->file_open) { \
+ fd = (file_hooks)->file_open((path), (mode), (host_data)); \
+ } \
+ fd; \
})
#define V3_FileClose(fd) \
({ \
+ int ret = 0; \
extern struct v3_file_hooks * file_hooks; \
- ((file_hooks) && (file_hooks)->file_close) ? \
- (file_hooks)->file_close((fd)) : -1; \
+ if ((file_hooks) && (file_hooks)->file_close) { \
+ ret = (file_hooks)->file_close((fd)); \
+ } \
+ ret; \
})
#define V3_FileSize(fd) \
({ \
+ long long size = -1; \
extern struct v3_file_hooks * file_hooks; \
- ((file_hooks) && (file_hooks)->file_size) ? \
- (file_hooks)->file_size((fd)) : -1; \
+ if ((file_hooks) && (file_hooks)->file_size) { \
+ size = (file_hooks)->file_size((fd)); \
+ } \
+ size; \
})
#define V3_FileRead(fd, start, buf, len) \
({ \
+ long long ret = -1; \
extern struct v3_file_hooks * file_hooks; \
- ((file_hooks) && (file_hooks)->file_read) ? \
- (file_hooks)->file_read((fd), (buf), (len), (start)) : -1; \
+ if ((file_hooks) && (file_hooks)->file_read) { \
+ ret = (file_hooks)->file_read((fd), (buf), (len), (start)); \
+ } \
+ ret; \
})
#define V3_FileWrite(fd,start,buf,len) \
({ \
+ long long ret = -1; \
extern struct v3_file_hooks * file_hooks; \
- ((file_hooks) && (file_hooks)->file_write) ? \
- (file_hooks)->file_write((fd), (buf), (len), (start)) : -1; \
+ if ((file_hooks) && (file_hooks)->file_write) { \
+ ret = (file_hooks)->file_write((fd), (buf), (len), (start)); \
+ } \
+ ret; \
})
struct v3_file_hooks {
- void (*file_open)(const char * path, int mode, void * host_data);
+ void * (*file_open)(const char * path, int mode, void * host_data);
int (*file_close)(void * fd);
long long (*file_size)(void * fd);
#include <palacios/vmm_dev_mgr.h>
#include <palacios/vmm_file.h>
+#include <palacios/vm_guest.h>
#ifndef CONFIG_DEBUG_FILEDISK
#undef PrintDebug
struct disk_state {
uint64_t capacity; // in bytes
- int fd;
+ void * fd;
};
-static int write_all(int fd, char * buf, int offset, int length) {
+static int write_all(void * fd, char * buf, int offset, int length) {
int bytes_written = 0;
PrintDebug("Writing %d bytes\n", length - bytes_written);
}
-static int read_all(int fd, char * buf, int offset, int length) {
+static int read_all(void * fd, char * buf, int offset, int length) {
int bytes_read = 0;
PrintDebug("Reading %d bytes\n", length - bytes_read);
static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
struct disk_state * disk = NULL;
char * path = v3_cfg_val(cfg, "path");
-
char * dev_id = v3_cfg_val(cfg, "ID");
-
-
char * writable = v3_cfg_val(cfg, "writable");
char * readable = v3_cfg_val(cfg, "readable");
memset(disk, 0, sizeof(struct disk_state));
- if (!path) {
-
-
+ if (path == NULL) {
PrintError("Missing path (%s) for %s\n", path, dev_id);
return -1;
}
- if ( allowRead && allowWrite ) {
- disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE );
- } else if ( allowRead && !allowWrite ) {
- disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ );
- } else if ( !allowRead && allowWrite ) {
- disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_WRITE );
+ if ( (allowRead == 1) && (allowWrite == 1) ) {
+ disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE, vm->host_priv_data );
+ } else if ( (allowRead == 1) && (allowWrite == 0) ) {
+ disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ, vm->host_priv_data );
+ } else if ( (allowRead == 0) && (allowWrite == 1) ) {
+ disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_WRITE, vm->host_priv_data );
} else {
PrintError("Error on %s: No file mode specified\n", dev_id );
return -1;