From: Jack Lange Date: Wed, 6 Oct 2010 17:36:15 +0000 (-0500) Subject: Functional file backend X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=0e29a343765b225251f5634fb34aa6a60085a0bd;p=palacios.git Functional file backend Conflicts: palacios/src/devices/filedisk.c --- diff --git a/palacios/src/devices/filedisk.c b/palacios/src/devices/filedisk.c index 6e9e5d7..278b234 100644 --- a/palacios/src/devices/filedisk.c +++ b/palacios/src/devices/filedisk.c @@ -34,14 +34,52 @@ struct disk_state { }; + +static int write_all(int fd, char * buf, int offset, int length) { + int bytes_written = 0; + + PrintDebug("Writing %d bytes\n", length - bytes_written); + while (bytes_written < length) { + int tmp_bytes = V3_FileWrite(fd, offset+bytes_written, buf + bytes_written, length - bytes_written); + PrintDebug("Wrote %d bytes\n", tmp_bytes); + + if (tmp_bytes <= 0 ) { + PrintError("Write failed\n"); + return -1; + } + + bytes_written += tmp_bytes; + } + + return 0; +} + + +static int read_all(int fd, char * buf, int offset, int length) { + int bytes_read = 0; + + PrintDebug("Reading %d bytes\n", length - bytes_read); + while (bytes_read < length) { + int tmp_bytes = V3_FileRead(fd, offset+bytes_read, buf + bytes_read, length - bytes_read); + PrintDebug("Read %d bytes\n", tmp_bytes); + + if (tmp_bytes <= 0) { + PrintError("Read failed\n"); + return -1; + } + + bytes_read += tmp_bytes; + } + + return 0; +} + static int read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data) { struct disk_state * disk = (struct disk_state *)private_data; PrintDebug("Reading %d bytes from %p to %p\n", (uint32_t)num_bytes, (uint8_t *)(disk->disk_image + lba), buf); - V3_FileRead(disk->fd, lba, buf, num_bytes); - - return 0; + return read_all(disk->fd, buf, lba, num_bytes); } @@ -50,9 +88,7 @@ static int write(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private PrintDebug("Writing %d bytes from %p to %p\n", (uint32_t)num_bytes, buf, (uint8_t *)(disk->disk_image + lba)); - V3_FileWrite(disk->fd, lba, buf, num_bytes); - - return 0; + return write_all(disk->fd, buf, lba, num_bytes); } @@ -102,6 +138,7 @@ static int disk_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { if (!path) { + PrintError("Missing path (%s) for %s\n", path, dev_id); return -1; } @@ -109,8 +146,8 @@ static int disk_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { disk->fd = V3_FileOpen(path, 0); disk->capacity = V3_FileSize(disk->fd); - PrintDebug("Registering RAMDISK at %p (size=%d)\n", - (void *)file->data, (uint32_t)file->size); + PrintDebug("Registering FILEDISK %s (path=%s, fd=%lu, size=%lu)\n", + name, path, file->fd, file->capacity); struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, disk);