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;
28 memset(&guest_img, 0, sizeof(struct v3_guest_img));
31 printf("Usage: ./v3_ctrl <guest_img> <vm name>\n");
35 printf("Launching guest: %s\n", filename);
37 guest_fd = open(filename, O_RDONLY);
40 printf("Error Opening guest image: %s\n", filename);
44 if (fstat(guest_fd, &guest_stats) == -1) {
45 printf("ERROR: Could not stat guest image file -- %s\n", filename);
50 guest_img.size = guest_stats.st_size;
52 // load guest image into user memory
53 guest_img.guest_data = malloc(guest_img.size);
55 read_file(guest_fd, guest_img.size, guest_img.guest_data);
59 printf("Loaded guest image. Launching to V3Vee\n");
61 strncpy(guest_img.name, name, 127);
64 v3_fd = open(v3_dev, O_RDONLY);
67 printf("Error opening V3Vee control device\n");
71 ioctl(v3_fd, V3_START_GUEST, &guest_img);
75 /* Close the file descriptor. */
85 int read_file(int fd, int size, unsigned char * buf) {
86 int left_to_read = size;
89 while (left_to_read != 0) {
90 int bytes_read = read(fd, buf + have_read, left_to_read);
92 if (bytes_read <= 0) {
96 have_read += bytes_read;
97 left_to_read -= bytes_read;
100 if (left_to_read != 0) {
101 printf("Error could not finish reading file\n");