ia64/xen-unstable

diff tools/blktap2/vhd/lib/vhd-util-check.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 f1fec38c8228
line diff
     1.1 --- a/tools/blktap2/vhd/lib/vhd-util-check.c	Tue Jun 23 11:27:54 2009 +0100
     1.2 +++ b/tools/blktap2/vhd/lib/vhd-util-check.c	Tue Jun 23 17:24:14 2009 +0100
     1.3 @@ -146,7 +146,7 @@ ok:
     1.4  static char *
     1.5  vhd_util_check_validate_header(int fd, vhd_header_t *header)
     1.6  {
     1.7 -	off64_t eof;
     1.8 +	off_t eof;
     1.9  	int i, cnt, size;
    1.10  	uint32_t checksum;
    1.11  
    1.12 @@ -164,8 +164,8 @@ vhd_util_check_validate_header(int fd, v
    1.13  	if (header->data_offset != ~(0ULL))
    1.14  		return "invalid data offset";
    1.15  
    1.16 -	eof = lseek64(fd, 0, SEEK_END);
    1.17 -	if (eof == (off64_t)-1)
    1.18 +	eof = lseek(fd, 0, SEEK_END);
    1.19 +	if (eof == (off_t)-1)
    1.20  		return "error finding eof";
    1.21  
    1.22  	if (header->table_offset <= 0  ||
    1.23 @@ -232,7 +232,7 @@ static char *
    1.24  vhd_util_check_validate_batmap(vhd_context_t *vhd, vhd_batmap_t *batmap)
    1.25  {
    1.26  	int size;
    1.27 -	off64_t eof;
    1.28 +	off_t eof;
    1.29  	uint32_t checksum;
    1.30  
    1.31  	size = sizeof(batmap->header.cookie);
    1.32 @@ -249,8 +249,8 @@ vhd_util_check_validate_batmap(vhd_conte
    1.33  	if (!batmap->header.batmap_size)
    1.34  		return "invalid size zero";
    1.35  
    1.36 -	eof = lseek64(vhd->fd, 0, SEEK_END);
    1.37 -	if (eof == (off64_t)-1)
    1.38 +	eof = lseek(vhd->fd, 0, SEEK_END);
    1.39 +	if (eof == (off_t)-1)
    1.40  		return "error finding eof";
    1.41  
    1.42  	if (!batmap->header.batmap_offset ||
    1.43 @@ -269,7 +269,7 @@ static char *
    1.44  vhd_util_check_validate_parent_locator(vhd_context_t *vhd,
    1.45  				       vhd_parent_locator_t *loc)
    1.46  {
    1.47 -	off64_t eof;
    1.48 +	off_t eof;
    1.49  
    1.50  	if (vhd_validate_platform_code(loc->code))
    1.51  		return "invalid platform code";
    1.52 @@ -290,8 +290,8 @@ vhd_util_check_validate_parent_locator(v
    1.53  	if (!loc->data_len)
    1.54  		return "invalid data length";
    1.55  
    1.56 -	eof = lseek64(vhd->fd, 0, SEEK_END);
    1.57 -	if (eof == (off64_t)-1)
    1.58 +	eof = lseek(vhd->fd, 0, SEEK_END);
    1.59 +	if (eof == (off_t)-1)
    1.60  		return "error finding eof";
    1.61  
    1.62  	if (loc->data_offset + vhd_parent_locator_size(loc) >
    1.63 @@ -304,11 +304,12 @@ vhd_util_check_validate_parent_locator(v
    1.64  	return NULL;
    1.65  }
    1.66  
    1.67 -static char *
    1.68 +static const char *
    1.69  vhd_util_check_validate_parent(vhd_context_t *vhd, const char *ppath)
    1.70  {
    1.71 -	char *msg;
    1.72 +	const char *msg;
    1.73  	vhd_context_t parent;
    1.74 +	uint32_t status;
    1.75  
    1.76  	msg = NULL;
    1.77  
    1.78 @@ -335,7 +336,7 @@ vhd_util_check_footer(int fd, vhd_footer
    1.79  	size_t size;
    1.80  	int err, opened;
    1.81  	char *msg, *buf;
    1.82 -	off64_t eof, off;
    1.83 +	off_t eof, off;
    1.84  	vhd_footer_t primary, backup;
    1.85  
    1.86  	memset(&primary, 0, sizeof(primary));
    1.87 @@ -349,16 +350,16 @@ vhd_util_check_footer(int fd, vhd_footer
    1.88  
    1.89  	memset(buf, 0, sizeof(primary));
    1.90  
    1.91 -	eof = lseek64(fd, 0, SEEK_END);
    1.92 -	if (eof == (off64_t)-1) {
    1.93 +	eof = lseek(fd, 0, SEEK_END);
    1.94 +	if (eof == (off_t)-1) {
    1.95  		err = -errno;
    1.96  		printf("error calculating end of file: %d\n", err);
    1.97  		goto out;
    1.98  	}
    1.99  
   1.100  	size = ((eof % 512) ? 511 : 512);
   1.101 -	eof  = lseek64(fd, eof - size, SEEK_SET);
   1.102 -	if (eof == (off64_t)-1) {
   1.103 +	eof  = lseek(fd, eof - size, SEEK_SET);
   1.104 +	if (eof == (off_t)-1) {
   1.105  		err = -errno;
   1.106  		printf("error calculating end of file: %d\n", err);
   1.107  		goto out;
   1.108 @@ -391,8 +392,8 @@ vhd_util_check_footer(int fd, vhd_footer
   1.109  	}
   1.110  
   1.111  check_backup:
   1.112 -	off = lseek64(fd, 0, SEEK_SET);
   1.113 -	if (off == (off64_t)-1) {
   1.114 +	off = lseek(fd, 0, SEEK_SET);
   1.115 +	if (off == (off_t)-1) {
   1.116  		err = -errno;
   1.117  		printf("error seeking to backup footer: %d\n", err);
   1.118  		goto out;
   1.119 @@ -454,7 +455,7 @@ static int
   1.120  vhd_util_check_header(int fd, vhd_footer_t *footer)
   1.121  {
   1.122  	int err;
   1.123 -	off64_t off;
   1.124 +	off_t off;
   1.125  	char *msg, *buf;
   1.126  	vhd_header_t header;
   1.127  
   1.128 @@ -465,8 +466,8 @@ vhd_util_check_header(int fd, vhd_footer
   1.129  	}
   1.130  
   1.131  	off = footer->data_offset;
   1.132 -	off = lseek64(fd, off, SEEK_SET);
   1.133 -	if (off == (off64_t)-1) {
   1.134 +	off = lseek(fd, off, SEEK_SET);
   1.135 +	if (off == (off_t)-1) {
   1.136  		err = -errno;
   1.137  		printf("error seeking to header: %d\n", err);
   1.138  		goto out;
   1.139 @@ -513,7 +514,7 @@ vhd_util_check_differencing_header(vhd_c
   1.140  static int
   1.141  vhd_util_check_bat(vhd_context_t *vhd)
   1.142  {
   1.143 -	off64_t eof, eoh;
   1.144 +	off_t eof, eoh;
   1.145  	int i, j, err, block_size;
   1.146  
   1.147  	err = vhd_seek(vhd, 0, SEEK_END);
   1.148 @@ -523,7 +524,7 @@ vhd_util_check_bat(vhd_context_t *vhd)
   1.149  	}
   1.150  
   1.151  	eof = vhd_position(vhd);
   1.152 -	if (eof == (off64_t)-1) {
   1.153 +	if (eof == (off_t)-1) {
   1.154  		printf("error calculating eof: %d\n", -errno);
   1.155  		return -errno;
   1.156  	}
   1.157 @@ -645,7 +646,8 @@ vhd_util_check_parent_locators(vhd_conte
   1.158  {
   1.159  	int i, n, err;
   1.160  	vhd_parent_locator_t *loc;
   1.161 -	char *msg, *file, *ppath, *location, *pname;
   1.162 +	char *file, *ppath, *location, *pname;
   1.163 +	const char *msg;
   1.164  	int mac, macx, w2ku, w2ru, wi2r, wi2k, found;
   1.165  
   1.166  	mac      = 0;