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);
54 if (!guest_img.guest_data) {
55 printf("ERROR: Could not allocate memory for guest image\n");
59 read_file(guest_fd, guest_img.size, guest_img.guest_data);
63 printf("Loaded guest image. Launching to V3Vee\n");
65 strncpy(guest_img.name, name, 127);
68 v3_fd = open(v3_dev, O_RDONLY);
71 printf("Error opening V3Vee control device\n");
75 ioctl(v3_fd, V3_START_GUEST, &guest_img);
79 /* Close the file descriptor. */
89 int read_file(int fd, int size, unsigned char * buf) {
90 int left_to_read = size;
93 while (left_to_read != 0) {
94 int bytes_read = read(fd, buf + have_read, left_to_read);
96 if (bytes_read <= 0) {
100 have_read += bytes_read;
101 left_to_read -= bytes_read;
104 if (left_to_read != 0) {
105 printf("Error could not finish reading file\n");