Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of newskysaw.cs.northwestern.edu:/home/palacios/palacios into...
[palacios.git] / linux_usr / v3_ctrl.c
1 /* 
2  * V3 Control utility
3  * (c) Jack lange, 2010
4  */
5
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h> 
10 #include <sys/ioctl.h> 
11 #include <sys/stat.h> 
12 #include <sys/types.h> 
13 #include <unistd.h> 
14 #include <string.h>
15  
16 #include "v3_ctrl.h"
17
18 int read_file(int fd, int size, unsigned char * buf);
19
20 int main(int argc, char* argv[]) {
21     char * filename = argv[1];
22     char * name = argv[2];
23     int guest_fd = 0;
24     int v3_fd = 0;
25     struct v3_guest_img guest_img;
26     struct stat guest_stats;
27  
28     memset(&guest_img, 0, sizeof(struct v3_guest_img));
29
30     if (argc <= 2) {
31         printf("Usage: ./v3_ctrl <guest_img> <vm name>\n");
32         return -1;
33     }
34
35     printf("Launching guest: %s\n", filename);
36
37     guest_fd = open(filename, O_RDONLY); 
38
39     if (guest_fd == -1) {
40         printf("Error Opening guest image: %s\n", filename);
41         return -1;
42     }
43
44     if (fstat(guest_fd, &guest_stats) == -1) {
45         printf("ERROR: Could not stat guest image file -- %s\n", filename);
46         return -1;
47     }
48
49     
50     guest_img.size = guest_stats.st_size;
51     
52     // load guest image into user memory
53     guest_img.guest_data = malloc(guest_img.size);
54
55     read_file(guest_fd, guest_img.size, guest_img.guest_data);
56     
57     close(guest_fd);
58
59     printf("Loaded guest image. Launching to V3Vee\n");
60     
61     strncpy(guest_img.name, name, 127);
62
63
64     v3_fd = open(v3_dev, O_RDONLY);
65
66     if (v3_fd == -1) {
67         printf("Error opening V3Vee control device\n");
68         return -1;
69     }
70
71     ioctl(v3_fd, V3_START_GUEST, &guest_img); 
72
73
74
75     /* Close the file descriptor.  */ 
76     close(v3_fd); 
77  
78
79
80     return 0; 
81
82
83
84
85 int read_file(int fd, int size, unsigned char * buf) {
86     int left_to_read = size;
87     int have_read = 0;
88
89     while (left_to_read != 0) {
90         int bytes_read = read(fd, buf + have_read, left_to_read);
91
92         if (bytes_read <= 0) {
93             break;
94         }
95
96         have_read += bytes_read;
97         left_to_read -= bytes_read;
98     }
99
100     if (left_to_read != 0) {
101         printf("Error could not finish reading file\n");
102         return -1;
103     }
104     
105     return 0;
106 }