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.


Small fixes in v3_free.c
[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     if (!guest_img.guest_data) {
55         printf("ERROR: Could not allocate memory for guest image\n");
56         return -1;
57     }
58
59     read_file(guest_fd, guest_img.size, guest_img.guest_data);
60     
61     close(guest_fd);
62
63     printf("Loaded guest image. Launching to V3Vee\n");
64     
65     strncpy(guest_img.name, name, 127);
66
67
68     v3_fd = open(v3_dev, O_RDONLY);
69
70     if (v3_fd == -1) {
71         printf("Error opening V3Vee control device\n");
72         return -1;
73     }
74
75     ioctl(v3_fd, V3_START_GUEST, &guest_img); 
76
77
78
79     /* Close the file descriptor.  */ 
80     close(v3_fd); 
81  
82
83
84     return 0; 
85
86
87
88
89 int read_file(int fd, int size, unsigned char * buf) {
90     int left_to_read = size;
91     int have_read = 0;
92
93     while (left_to_read != 0) {
94         int bytes_read = read(fd, buf + have_read, left_to_read);
95
96         if (bytes_read <= 0) {
97             break;
98         }
99
100         have_read += bytes_read;
101         left_to_read -= bytes_read;
102     }
103
104     if (left_to_read != 0) {
105         printf("Error could not finish reading file\n");
106         return -1;
107     }
108     
109     return 0;
110 }