3
* Generates a qcow format disk.
5
* (c) 2006 Andrew Warfield and Julian Chesterfield
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License version 2
9
* as published by the Free Software Foundation; or, when distributed
10
* separately from the Linux kernel or incorporated into other
11
* software packages, subject to the following license:
13
* Permission is hereby granted, free of charge, to any person obtaining a copy
14
* of this source file (the "Software"), to deal in the Software without
15
* restriction, including without limitation the rights to use, copy, modify,
16
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
17
* and to permit persons to whom the Software is furnished to do so, subject to
18
* the following conditions:
20
* The above copyright notice and this permission notice shall be included in
21
* all copies or substantial portions of the Software.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
37
#include <sys/statvfs.h>
39
#include <sys/ioctl.h>
44
#define DFPRINTF(_f, _a...) fprintf ( stderr, _f , ## _a )
46
#define DFPRINTF(_f, _a...) ((void)0)
49
#define MAX_NAME_LEN 1000
51
static void help(void)
53
fprintf(stderr, "Qcow-utils: v1.0.0\n");
55
"usage: qcow-create [-h help] [-r reserve] [-f format] <SIZE(MB)> <FILENAME> "
56
"[<BACKING_FILENAME>]\n");
60
int main(int argc, char *argv[])
62
int ret = -1, c, backed = 0;
66
char filename[MAX_NAME_LEN], bfilename[MAX_NAME_LEN];
70
c = getopt(argc, argv, "hrf");
85
fprintf(stderr, "Unknown option\n");
90
printf("Optind %d, argc %d\n", optind, argc);
91
if ( !(optind == (argc - 2) || optind == (argc - 3)) )
94
size = atoi(argv[optind++]);
97
if (snprintf(filename, MAX_NAME_LEN, "%s",argv[optind++]) >=
99
fprintf(stderr,"Device name too long\n");
103
if (optind != argc) {
104
/*Backing file argument*/
106
if (snprintf(bfilename, MAX_NAME_LEN, "%s",argv[optind++]) >=
108
fprintf(stderr,"Device name too long\n");
113
tmpfile = backed ? bfilename: NULL;
114
if (!strcmp(fmt, "qcow")) {
115
ret = qcow_create(filename, size, tmpfile, sparse);
116
} else if(!strcmp(fmt, "qcow2")) {
117
ret = qcow2_create(filename, size, tmpfile, sparse);
119
fprintf(stderr,"Unsupport format:%s\n", fmt);
122
DFPRINTF("Creating file size %llu, name %s\n",(long long unsigned)size, filename);
125
DPRINTF("Unable to create QCOW file\n");
127
DPRINTF("QCOW file successfully created\n");