10 #include <sys/ioctl.h>
12 #include <sys/types.h>
18 int read_file(int fd, int size, unsigned char * buf);
20 int main(int argc, char* argv[]) {
21 char * filename = argv[1];
22 char * name = argv[2];
25 struct v3_guest_img guest_img;
26 struct stat guest_stats;
29 memset(&guest_img, 0, sizeof(struct v3_guest_img));
32 printf("Usage: ./v3_ctrl <guest_img> <vm name>\n");
36 printf("Launching guest: %s\n", filename);
38 guest_fd = open(filename, O_RDONLY);
41 printf("Error Opening guest image: %s\n", filename);
45 if (fstat(guest_fd, &guest_stats) == -1) {
46 printf("ERROR: Could not stat guest image file -- %s\n", filename);
51 guest_img.size = guest_stats.st_size;
53 // load guest image into user memory
54 guest_img.guest_data = malloc(guest_img.size);
56 read_file(guest_fd, guest_img.size, guest_img.guest_data);
60 printf("Loaded guest image. Launching to V3Vee\n");
62 strncpy(guest_img.name, name, 127);
65 v3_fd = open(v3_dev, O_RDONLY);
68 printf("Error opening V3Vee control device\n");
72 dev_idx = ioctl(v3_fd, V3_CREATE_GUEST, &guest_img);
76 printf("Error (%d) creating VM\n", dev_idx);
80 printf("VM (%s) created at /dev/v3-vm%d\n", name, dev_idx);
82 /* Close the file descriptor. */
92 int read_file(int fd, int size, unsigned char * buf) {
93 int left_to_read = size;
96 while (left_to_read != 0) {
97 int bytes_read = read(fd, buf + have_read, left_to_read);
99 if (bytes_read <= 0) {
103 have_read += bytes_read;
104 left_to_read -= bytes_read;
107 if (left_to_read != 0) {
108 printf("Error could not finish reading file\n");