ia64/xen-unstable

annotate tools/blktap2/vhd/lib/vhd-util-repair.c @ 19817:b7f73a7f3078

blktap2: portability fixes for NetBSD

- Use standard off_t and lseek() instead of non-portable off64_t and
lseek64()
- Use uuid API as documented in DCE 1.1 RPC specification
- Add NetBSD implementation for blk_getimagesize() and
blk_getsectorsize()
- Use blk_getimagesize() and blk_getsectorsize()
- Fix uuid header check

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jun 23 17:24:14 2009 +0100 (2009-06-23)
parents 1c627434605e
children
rev   line source
keir@19647 1 /* Copyright (c) 2008, XenSource Inc.
keir@19647 2 * All rights reserved.
keir@19647 3 *
keir@19647 4 * Redistribution and use in source and binary forms, with or without
keir@19647 5 * modification, are permitted provided that the following conditions are met:
keir@19647 6 * * Redistributions of source code must retain the above copyright
keir@19647 7 * notice, this list of conditions and the following disclaimer.
keir@19647 8 * * Redistributions in binary form must reproduce the above copyright
keir@19647 9 * notice, this list of conditions and the following disclaimer in the
keir@19647 10 * documentation and/or other materials provided with the distribution.
keir@19647 11 * * Neither the name of XenSource Inc. nor the names of its contributors
keir@19647 12 * may be used to endorse or promote products derived from this software
keir@19647 13 * without specific prior written permission.
keir@19647 14 *
keir@19647 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
keir@19647 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
keir@19647 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
keir@19647 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
keir@19647 19 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
keir@19647 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
keir@19647 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
keir@19647 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
keir@19647 23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
keir@19647 24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
keir@19647 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keir@19647 26 */
keir@19647 27 #include <errno.h>
keir@19647 28 #include <fcntl.h>
keir@19647 29 #include <stdio.h>
keir@19647 30 #include <stdlib.h>
keir@19647 31 #include <unistd.h>
keir@19647 32
keir@19647 33 #include "libvhd.h"
keir@19647 34
keir@19647 35 int
keir@19647 36 vhd_util_repair(int argc, char **argv)
keir@19647 37 {
keir@19647 38 char *name;
keir@19647 39 int err, c;
keir@19817 40 off_t eof;
keir@19647 41 vhd_context_t vhd;
keir@19647 42
keir@19647 43 name = NULL;
keir@19647 44
keir@19647 45 if (!argc || !argv)
keir@19647 46 goto usage;
keir@19647 47
keir@19647 48 optind = 0;
keir@19647 49 while ((c = getopt(argc, argv, "n:h")) != -1) {
keir@19647 50 switch (c) {
keir@19647 51 case 'n':
keir@19647 52 name = optarg;
keir@19647 53 break;
keir@19647 54 case 'h':
keir@19647 55 default:
keir@19647 56 goto usage;
keir@19647 57 }
keir@19647 58 }
keir@19647 59
keir@19647 60 if (!name || optind != argc)
keir@19647 61 goto usage;
keir@19647 62
keir@19647 63 err = vhd_open(&vhd, name, VHD_OPEN_RDWR);
keir@19647 64 if (err) {
keir@19647 65 printf("error opening %s: %d\n", name, err);
keir@19647 66 return err;
keir@19647 67 }
keir@19647 68
keir@19647 69 err = vhd_end_of_data(&vhd, &eof);
keir@19647 70 if (err) {
keir@19647 71 printf("error finding end of data: %d\n", err);
keir@19647 72 goto done;
keir@19647 73 }
keir@19647 74
keir@19647 75 err = vhd_write_footer_at(&vhd, &vhd.footer, eof);
keir@19647 76
keir@19647 77 done:
keir@19647 78 vhd_close(&vhd);
keir@19647 79 return err;
keir@19647 80
keir@19647 81 usage:
keir@19647 82 printf("options: <-n name> [-h help]\n");
keir@19647 83 return -EINVAL;
keir@19647 84 }