diff options
author | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-08-01 22:00:34 +0000 |
---|---|---|
committer | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-08-01 22:00:34 +0000 |
commit | a3fb0cf9072c4aa89776526592b359b7caea1bb9 (patch) | |
tree | 612778ecd7aa4395b53699b442f971e9db0af17a /qemu-mkcow.c | |
parent | ea2384d36e1e5f6dfd44b748d290762181c38350 (diff) |
removed unneeded tools
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1038 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'qemu-mkcow.c')
-rw-r--r-- | qemu-mkcow.c | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/qemu-mkcow.c b/qemu-mkcow.c deleted file mode 100644 index ee41ec8a14..0000000000 --- a/qemu-mkcow.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * create a COW disk image - * - * Copyright (c) 2003 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> -#include <getopt.h> -#include <inttypes.h> -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> -#include <time.h> -#include <sys/time.h> -#include <errno.h> -#include <sys/stat.h> -#include <netinet/in.h> - -#include "cow.h" - -#include "bswap.h" - -int cow_create(int cow_fd, const char *image_filename, - int64_t image_sectors) -{ - struct cow_header_v2 cow_header; - int fd; - struct stat st; - - memset(&cow_header, 0, sizeof(cow_header)); - cow_header.magic = htonl(COW_MAGIC); - cow_header.version = htonl(COW_VERSION); - if (image_filename) { - fd = open(image_filename, O_RDONLY); - if (fd < 0) { - perror(image_filename); - exit(1); - } - image_sectors = lseek64(fd, 0, SEEK_END); - if (fstat(fd, &st) != 0) { - close(fd); - return -1; - } - close(fd); - image_sectors /= 512; - cow_header.mtime = htonl(st.st_mtime); - realpath(image_filename, cow_header.backing_file); - } - cow_header.sectorsize = htonl(512); - cow_header.size = image_sectors * 512; -#ifndef WORDS_BIGENDIAN - cow_header.size = bswap64(cow_header.size); -#endif - write(cow_fd, &cow_header, sizeof(cow_header)); - /* resize to include at least all the bitmap */ - ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3)); - lseek(cow_fd, 0, SEEK_SET); - return 0; -} - -void help(void) -{ - printf("qemu-mkcow version " QEMU_VERSION ", Copyright (c) 2003 Fabrice Bellard\n" - "usage: qemu-mkcow [-h] [-f disk_image] cow_image [cow_size]\n" - "Create a Copy On Write disk image from an optional raw disk image\n" - "\n" - "-f disk_image set the raw disk image name\n" - "cow_image the created cow_image\n" - "cow_size the create cow_image size in MB if no raw disk image is used\n" - "\n" - "Once the cow_image is created from a raw disk image, you must not modify the original raw disk image\n" - ); - exit(1); -} - -int main(int argc, char **argv) -{ - const char *image_filename, *cow_filename; - int cow_fd, c, nb_args, simple_image; - int64_t image_size; - - image_filename = NULL; - image_size = 0; - simple_image = 0; - for(;;) { - c = getopt(argc, argv, "hf:s"); - if (c == -1) - break; - switch(c) { - case 'h': - help(); - break; - case 'f': - image_filename = optarg; - break; - case 's': - simple_image = 1; - break; - } - } - if (!image_filename) - nb_args = 2; - else - nb_args = 1; - if (optind + nb_args != argc) - help(); - - cow_filename = argv[optind]; - if (nb_args == 2) { - image_size = (int64_t)atoi(argv[optind + 1]) * 2 * 1024; - } - - cow_fd = open(cow_filename, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); - if (!cow_fd < 0) - return -1; - if (simple_image) { - ftruncate64(cow_fd, image_size * 512); - } else { - if (cow_create(cow_fd, image_filename, image_size) < 0) { - fprintf(stderr, "%s: error while formating\n", cow_filename); - exit(1); - } - } - close(cow_fd); - return 0; -} |