Commit 00af2b26809d9cfb20af348ea7df255780348dd2

Authored by bellard
1 parent a735aa31

added cow.h


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@653 c046a42c-6fe2-441c-8c8c-71466251a162
@@ -45,6 +45,8 @@ @@ -45,6 +45,8 @@
45 #define NO_THUNK_TYPE_SIZE 45 #define NO_THUNK_TYPE_SIZE
46 #include "thunk.h" 46 #include "thunk.h"
47 47
  48 +#include "cow.h"
  49 +
48 struct BlockDriverState { 50 struct BlockDriverState {
49 int fd; /* if -1, only COW mappings */ 51 int fd; /* if -1, only COW mappings */
50 int64_t total_sectors; 52 int64_t total_sectors;
cow.h 0 → 100644
  1 +/* user mode linux compatible COW file */
  2 +#define COW_MAGIC 0x4f4f4f4d /* MOOO */
  3 +#define COW_VERSION 2
  4 +
  5 +struct cow_header_v2 {
  6 + uint32_t magic;
  7 + uint32_t version;
  8 + char backing_file[1024];
  9 + int32_t mtime;
  10 + uint64_t size;
  11 + uint32_t sectorsize;
  12 +};
  13 +
qemu-mkcow.c
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 #include <sys/stat.h> 41 #include <sys/stat.h>
42 #include <netinet/in.h> 42 #include <netinet/in.h>
43 43
44 -#include "vl.h" 44 +#include "cow.h"
45 45
46 #include "bswap.h" 46 #include "bswap.h"
47 47
@@ -101,13 +101,14 @@ void help(void) @@ -101,13 +101,14 @@ void help(void)
101 int main(int argc, char **argv) 101 int main(int argc, char **argv)
102 { 102 {
103 const char *image_filename, *cow_filename; 103 const char *image_filename, *cow_filename;
104 - int cow_fd, c, nb_args; 104 + int cow_fd, c, nb_args, simple_image;
105 int64_t image_size; 105 int64_t image_size;
106 106
107 image_filename = NULL; 107 image_filename = NULL;
108 image_size = 0; 108 image_size = 0;
  109 + simple_image = 0;
109 for(;;) { 110 for(;;) {
110 - c = getopt(argc, argv, "hf:"); 111 + c = getopt(argc, argv, "hf:s");
111 if (c == -1) 112 if (c == -1)
112 break; 113 break;
113 switch(c) { 114 switch(c) {
@@ -117,6 +118,9 @@ int main(int argc, char **argv) @@ -117,6 +118,9 @@ int main(int argc, char **argv)
117 case 'f': 118 case 'f':
118 image_filename = optarg; 119 image_filename = optarg;
119 break; 120 break;
  121 + case 's':
  122 + simple_image = 1;
  123 + break;
120 } 124 }
121 } 125 }
122 if (!image_filename) 126 if (!image_filename)
@@ -131,12 +135,16 @@ int main(int argc, char **argv) @@ -131,12 +135,16 @@ int main(int argc, char **argv)
131 image_size = (int64_t)atoi(argv[optind + 1]) * 2 * 1024; 135 image_size = (int64_t)atoi(argv[optind + 1]) * 2 * 1024;
132 } 136 }
133 137
134 - cow_fd = open(cow_filename, O_RDWR | O_CREAT | O_TRUNC, 0644); 138 + cow_fd = open(cow_filename, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
135 if (!cow_fd < 0) 139 if (!cow_fd < 0)
136 return -1; 140 return -1;
137 - if (cow_create(cow_fd, image_filename, image_size) < 0) {  
138 - fprintf(stderr, "%s: error while formating\n", cow_filename);  
139 - exit(1); 141 + if (simple_image) {
  142 + ftruncate64(cow_fd, image_size * 512);
  143 + } else {
  144 + if (cow_create(cow_fd, image_filename, image_size) < 0) {
  145 + fprintf(stderr, "%s: error while formating\n", cow_filename);
  146 + exit(1);
  147 + }
140 } 148 }
141 close(cow_fd); 149 close(cow_fd);
142 return 0; 150 return 0;
@@ -58,19 +58,6 @@ void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr); @@ -58,19 +58,6 @@ void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
58 int bdrv_commit(BlockDriverState *bs); 58 int bdrv_commit(BlockDriverState *bs);
59 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size); 59 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
60 60
61 -/* user mode linux compatible COW file */  
62 -#define COW_MAGIC 0x4f4f4f4d /* MOOO */  
63 -#define COW_VERSION 2  
64 -  
65 -struct cow_header_v2 {  
66 - uint32_t magic;  
67 - uint32_t version;  
68 - char backing_file[1024];  
69 - int32_t mtime;  
70 - uint64_t size;  
71 - uint32_t sectorsize;  
72 -};  
73 -  
74 /* vga.c */ 61 /* vga.c */
75 62
76 #define VGA_RAM_SIZE (4096 * 1024) 63 #define VGA_RAM_SIZE (4096 * 1024)