};
+
+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);
}
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);
}
if (!path) {
+
PrintError("Missing path (%s) for %s\n", path, dev_id);
return -1;
}
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);