All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blktap2: portability fixes
@ 2009-06-23 12:29 Christoph Egger
  2009-06-23 16:25 ` Keir Fraser
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Egger @ 2009-06-23 12:29 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 678 bytes --]


Hi!

Attached patch makes blktap2 build on 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>


-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

[-- Attachment #2: xen_blktap2.diff --]
[-- Type: text/x-diff, Size: 57610 bytes --]

diff -r 5f5112a7d2ff tools/Makefile
--- a/tools/Makefile	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/Makefile	Tue Jun 23 14:21:57 2009 +0200
@@ -23,9 +23,12 @@ SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_Linux) += libaio
 SUBDIRS-$(CONFIG_Linux) += blktap
 SUBDIRS-$(CONFIG_Linux) += blktap2
+SUBDIRS-$(CONFIG_NetBSD) += libaio
+SUBDIRS-$(CONFIG_NetBSD) += blktap2
 SUBDIRS-y += libfsimage
 SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen
 SUBDIRS-$(CONFIG_Linux) += fs-back
+SUBDIRS-$(CONFIG_NetBSD) += fs-back
 SUBDIRS-$(CONFIG_IOEMU) += ioemu-dir
 SUBDIRS-y += xenpmd
 
diff -r 5f5112a7d2ff tools/blktap2/drivers/Makefile
--- a/tools/blktap2/drivers/Makefile	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/Makefile	Tue Jun 23 14:21:57 2009 +0200
@@ -24,6 +24,7 @@ endif
 
 LIBS      += -lrt -lz
 
+ifeq ($(CONFIG_Linux),y)
 ifeq ($(shell . ./check_gcrypt $(CC)),yes)
 CFLAGS += -DUSE_GCRYPT
 CRYPT_LIB += -lgcrypt
@@ -31,10 +32,17 @@ else
 CRYPT_LIB += -lcrypto
 $(warning === libgcrypt not installed: falling back to libcrypto ===)
 endif
+else
+CRYPT_LIB += -lcrypto
+endif
 
 LDFLAGS_img := $(CRYPT_LIB) -lpthread -lz
 
-tapdisk2 td-util tapdisk-stream tapdisk-diff $(QCOW_UTIL): LIBS += -L$(LIBVHDDIR) -lvhd -luuid
+LIBS += -L$(LIBVHDDIR) -lvhd
+
+ifeq ($(CONFIG_Linux),y)
+LIBS += -luuid
+endif
 
 LIBAIO_DIR = $(XEN_ROOT)/tools/libaio/src
 tapdisk2 tapdisk-stream tapdisk-diff $(QCOW_UTIL): AIOLIBS := $(LIBAIO_DIR)/libaio.a
@@ -44,6 +52,10 @@ ifeq ($(VHD_STATIC),y)
 td-util: CFLAGS += -static
 endif
 
+PORTABLE-OBJS-y :=
+PORTABLE-OBJS-$(CONFIG_Linux)  += blk_linux.o
+PORTABLE-OBJS-$(CONFIG_NetBSD) += blk_netbsd.o
+
 TAP-OBJS-y  := scheduler.o
 TAP-OBJS-y  += tapdisk-ipc.o
 TAP-OBJS-y  += tapdisk-vbd.o
@@ -57,7 +69,7 @@ TAP-OBJS-y  += tapdisk-log.o
 TAP-OBJS-y  += tapdisk-utils.o
 TAP-OBJS-y  += io-optimize.o
 TAP-OBJS-y  += lock.o
-TAP-OBJS-$(CONFIG_Linux)  += blk_linux.o
+TAP-OBJS-y  += $(PORTABLE-OBJS-y)
 
 MISC-OBJS-y := atomicio.o
 
@@ -68,6 +80,7 @@ BLK-OBJS-y  += block-vhd.o
 BLK-OBJS-y  += block-log.o
 BLK-OBJS-y  += block-qcow.o
 BLK-OBJS-y  += aes.o
+BLK-OBJS-y  += $(PORTABLE-OBJS-y)
 
 all: $(IBIN) lock-util qcow-util
 
@@ -81,7 +94,7 @@ tapdisk-client: tapdisk-client.o
 tapdisk-stream tapdisk-diff: %: %.o $(TAP-OBJS-y) $(BLK-OBJS-y)
 	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS)  $(LDFLAGS_img)
 
-td-util: td.o tapdisk-utils.o tapdisk-log.o
+td-util: td.o tapdisk-utils.o tapdisk-log.o $(PORTABLE-OBJS-y)
 	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)  $(LDFLAGS_img)
 
 lock-util: lock.c
diff -r 5f5112a7d2ff tools/blktap2/drivers/blk.h
--- a/tools/blktap2/drivers/blk.h	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/blk.h	Tue Jun 23 14:21:57 2009 +0200
@@ -28,3 +28,7 @@
 
 int blk_getimagesize(int fd, uint64_t *size);
 int blk_getsectorsize(int fd, uint64_t *sector_size);
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
diff -r 5f5112a7d2ff tools/blktap2/drivers/blk_netbsd.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/drivers/blk_netbsd.c	Tue Jun 23 14:21:57 2009 +0200
@@ -0,0 +1,41 @@
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <errno.h>
+#include <inttypes.h>
+#include "tapdisk.h"
+#include "blk.h"
+
+int blk_getimagesize(int fd, uint64_t *size)
+{
+	int rc;
+	struct disklabel dl;
+
+	*size = 0;
+	rc = ioctl(fd, DIOCGDINFO, &dl);
+	if (rc) {
+		DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
+		return -EINVAL;
+	}
+
+	*size = dl.d_secsize * dl.d_secpercyl;
+
+	return 0;
+}
+
+int blk_getsectorsize(int fd, uint64_t *sector_size)
+{
+	int rc;
+	struct disklabel dl;
+
+	*sector_size = DEV_BSIZE;
+	rc = ioctl(fd, DIOCGDINFO, &dl);
+	if (rc) {
+		DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
+		return 0; /* fallback to DEV_BSIZE */
+	}
+
+	*sector_size = dl.d_secsize;
+	return 0;
+}
+
diff -r 5f5112a7d2ff tools/blktap2/drivers/block-aio.c
--- a/tools/blktap2/drivers/block-aio.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/block-aio.c	Tue Jun 23 14:21:57 2009 +0200
@@ -36,8 +36,8 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 
+#include "blk.h"
 #include "tapdisk.h"
 #include "tapdisk-driver.h"
 #include "tapdisk-interface.h"
@@ -79,10 +79,8 @@ static int tdaio_get_image_info(int fd, 
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
 		info->size = 0;
-		if (ioctl(fd,BLKGETSIZE,&info->size)!=0) {
-			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		if (blk_getimagesize(fd, &info->size) != 0)
 			return -EINVAL;
-		}
 
 		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
 			"sector_shift [%llu]\n",
@@ -90,19 +88,8 @@ static int tdaio_get_image_info(int fd, 
 			(long long unsigned)info->size);
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &info->sector_size) != 0)
 			info->sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &info->sector_size);
-			
-			if (info->sector_size != DEFAULT_SECTOR_SIZE)
-				DPRINTF("Note: sector size is %ld (not %d)\n",
-					info->sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		info->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
 
 	} else {
 		/*Local file? try fstat instead*/
diff -r 5f5112a7d2ff tools/blktap2/drivers/block-log.c
--- a/tools/blktap2/drivers/block-log.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/block-log.c	Tue Jun 23 14:21:57 2009 +0200
@@ -314,7 +314,7 @@ static int ctl_open(struct tdlog_state* 
     goto err_sock;
   }
     
-  if (bind(s->ctl.fd, &saddr, sizeof(saddr)) < 0) {
+  if (bind(s->ctl.fd, (const struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
     BWPRINTF("error binding control socket to %s: %s", s->ctlpath,
 	     strerror(errno));
     goto err_sock;
diff -r 5f5112a7d2ff tools/blktap2/drivers/block-qcow.c
--- a/tools/blktap2/drivers/block-qcow.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/block-qcow.c	Tue Jun 23 14:21:57 2009 +0200
@@ -29,7 +29,6 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 #include <zlib.h>
 #include <inttypes.h>
@@ -990,8 +989,8 @@ int tdqcow_open (td_driver_t *driver, co
 		s->fd_end = s->l1_table_offset +
 			((s->l1_size * sizeof(uint64_t) + 4095) & ~4095);
 	else {
-		s->fd_end = lseek64(fd, 0, SEEK_END);
-		if (s->fd_end == (off64_t)-1)
+		s->fd_end = lseek(fd, 0, SEEK_END);
+		if (s->fd_end == (off_t)-1)
 			goto fail;
 	}
 
diff -r 5f5112a7d2ff tools/blktap2/drivers/block-ram.c
--- a/tools/blktap2/drivers/block-ram.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/block-ram.c	Tue Jun 23 14:21:57 2009 +0200
@@ -34,9 +34,9 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 
+#include "blk.h"
 #include "tapdisk.h"
 #include "tapdisk-driver.h"
 #include "tapdisk-interface.h"
@@ -69,10 +69,8 @@ static int get_image_info(int fd, td_dis
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
 		info->size = 0;
-		if (ioctl(fd,BLKGETSIZE,&info->size)!=0) {
-			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		if (blk_getimagesize(fd, &info->size) != 0)
 			return -EINVAL;
-		}
 
 		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
 			"sector_shift [%llu]\n",
@@ -80,19 +78,8 @@ static int get_image_info(int fd, td_dis
 			(long long unsigned)info->size);
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &info->sector_size) != 0)
 			info->sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &info->sector_size);
-			
-			if (info->sector_size != DEFAULT_SECTOR_SIZE)
-				DPRINTF("Note: sector size is %ld (not %d)\n",
-					info->sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		info->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
 
 	} else {
 		/*Local file? try fstat instead*/
diff -r 5f5112a7d2ff tools/blktap2/drivers/block-vhd.c
--- a/tools/blktap2/drivers/block-vhd.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/block-vhd.c	Tue Jun 23 14:21:57 2009 +0200
@@ -50,8 +50,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <uuid/uuid.h> /* For whatever reason, Linux packages this in */
-                       /* e2fsprogs-devel.                            */
 #include <string.h>    /* for memset.                                 */
 #include <libaio.h>
 #include <sys/mman.h>
@@ -275,7 +273,7 @@ vhd_initialize(struct vhd_state *s)
 		_vhd_zsize += VHD_BLOCK_SIZE;
 
 	_vhd_zeros = mmap(0, _vhd_zsize, PROT_READ,
-			  MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+			  MAP_SHARED | MAP_ANON, -1, 0);
 	if (_vhd_zeros == MAP_FAILED) {
 		EPRINTF("vhd_initialize failed: %d\n", -errno);
 		_vhd_zeros = NULL;
@@ -334,7 +332,7 @@ static int
 vhd_kill_footer(struct vhd_state *s)
 {
 	int err;
-	off64_t end;
+	off_t end;
 	char *zeros;
 
 	if (s->vhd.footer.type == HD_TYPE_FIXED)
@@ -347,10 +345,10 @@ vhd_kill_footer(struct vhd_state *s)
 	err = 1;
 	memset(zeros, 0xc7c7c7c7, 512);
 
-	if ((end = lseek64(s->vhd.fd, 0, SEEK_END)) == -1)
+	if ((end = lseek(s->vhd.fd, 0, SEEK_END)) == -1)
 		goto fail;
 
-	if (lseek64(s->vhd.fd, (end - 512), SEEK_SET) == -1)
+	if (lseek(s->vhd.fd, (end - 512), SEEK_SET) == -1)
 		goto fail;
 
 	if (write(s->vhd.fd, zeros, 512) != 512)
@@ -369,7 +367,7 @@ static inline int
 find_next_free_block(struct vhd_state *s)
 {
 	int err;
-	off64_t eom;
+	off_t eom;
 	uint32_t i, entry;
 
 	err = vhd_end_of_headers(&s->vhd, &eom);
@@ -772,6 +770,7 @@ int
 vhd_validate_parent(td_driver_t *child_driver,
 		    td_driver_t *parent_driver, td_flag_t flags)
 {
+	uint32_t status;
 	struct stat stats;
 	struct vhd_state *child  = (struct vhd_state *)child_driver->data;
 	struct vhd_state *parent;
@@ -806,7 +805,7 @@ vhd_validate_parent(td_driver_t *child_d
 	}
 	*/
 
-	if (uuid_compare(child->vhd.header.prt_uuid, parent->vhd.footer.uuid)) {
+	if (uuid_compare(&child->vhd.header.prt_uuid, &parent->vhd.footer.uuid, &status)) {
 		DPRINTF("ERROR: %s: %s, %s: parent uuid has changed since "
 			"snapshot.  Child image no longer valid.\n",
 			__func__, child->vhd.file, parent->vhd.file);
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-client.c
--- a/tools/blktap2/drivers/tapdisk-client.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-client.c	Tue Jun 23 14:21:57 2009 +0200
@@ -109,7 +109,7 @@ static int tdctl_open(const char* sockpa
   saddr.sun_family = AF_UNIX;
   memcpy(saddr.sun_path, sockpath, strlen(sockpath));
 
-  if (connect(fd, &saddr, sizeof(saddr)) < 0) {
+  if (connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
     BWPRINTF("error connecting to socket %s: %s", sockpath, strerror(errno));
     close(fd);
     return -1;
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-diff.c
--- a/tools/blktap2/drivers/tapdisk-diff.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-diff.c	Tue Jun 23 14:21:57 2009 +0200
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <libgen.h>	/* for basename(3) */
 #include <unistd.h>
 
 #include "list.h"
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-filter.c
--- a/tools/blktap2/drivers/tapdisk-filter.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-filter.c	Tue Jun 23 14:21:57 2009 +0200
@@ -113,10 +113,11 @@ check_hash(struct tfilter *filter, uint6
 	if (hash->hash != chksum(buf)) {
 		struct timeval now;
 		gettimeofday(&now, NULL);
-		DBG("%s: hash table: 0x%020" PRIx64 " at %012lu.%06lu, "
-		    "from disk: 0x%020" PRIx64 " at %012lu.%06lu\n",
+		DBG("%s: hash table: 0x%020" PRIx64 " at %012lu.%06llu, "
+		    "from disk: 0x%020" PRIx64 " at %012lu.%06llu\n",
 		    type, hash->hash, hash->time.tv_sec,
-		    hash->time.tv_usec, sum, now.tv_sec, now.tv_usec);
+		    (unsigned long long)hash->time.tv_usec, sum,
+		    now.tv_sec, (unsigned long long)now.tv_usec);
 	}
 }
 
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-log.c
--- a/tools/blktap2/drivers/tapdisk-log.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-log.c	Tue Jun 23 14:21:57 2009 +0200
@@ -126,8 +126,9 @@ __tlog_write(int level, const char *func
 
 	buf = tapdisk_log.p;
 	gettimeofday(&t, NULL);
-	len = snprintf(buf, MAX_ENTRY_LEN - 1, "%08"PRIu64":%010ld.%06ld:"
-		       "%s ", tapdisk_log.cnt, t.tv_sec, t.tv_usec, func);
+	len = snprintf(buf, MAX_ENTRY_LEN - 1, "%08"PRIu64":%010ld.%06lld:"
+		       "%s ", tapdisk_log.cnt,
+			t.tv_sec, (unsigned long long)t.tv_usec, func);
 
 	va_start(ap, fmt);
 	ret = vsnprintf(buf + len, MAX_ENTRY_LEN - (len + 1), fmt, ap);
@@ -167,8 +168,8 @@ __tlog_error(int err, const char *func, 
 	gettimeofday(&t, NULL);
 	e = &tapdisk_err.errors[tapdisk_err.cnt];
 
-	len = snprintf(e->msg, MAX_ENTRY_LEN - 1, "%010ld.%06ld:%s ",
-		       t.tv_sec, t.tv_usec, func);
+	len = snprintf(e->msg, MAX_ENTRY_LEN - 1, "%010ld.%06lld:%s ",
+		       t.tv_sec, (unsigned long long)t.tv_usec, func);
 
 	va_start(ap, fmt);
 	ret = vsnprintf(e->msg + len, MAX_ENTRY_LEN - (len + 1), fmt, ap);
@@ -237,7 +238,7 @@ tlog_flush(void)
 		return;
 
 	if (tapdisk_log.append)
-		if (lseek64(fd, 0, SEEK_END) == (loff_t)-1)
+		if (lseek(fd, 0, SEEK_END) == (off_t)-1)
 			goto out;
 
 	tlog_flush_errors();
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-queue.c
--- a/tools/blktap2/drivers/tapdisk-queue.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-queue.c	Tue Jun 23 14:21:57 2009 +0200
@@ -174,7 +174,7 @@ iocb_rw(struct iocb *iocb)
 	ssize_t (*func)(int, void *, size_t) = 
 		(iocb->aio_lio_opcode == IO_CMD_PWRITE ? vwrite : read);
 
-	if (lseek64(fd, off, SEEK_SET) == (off64_t)-1)
+	if (lseek(fd, off, SEEK_SET) == (off_t)-1)
 		return -errno;
 	
 	if (atomicio(func, fd, buf, size) != size)
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-utils.c
--- a/tools/blktap2/drivers/tapdisk-utils.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-utils.c	Tue Jun 23 14:21:57 2009 +0200
@@ -29,12 +29,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
-#include <linux/fs.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
 #include <sys/resource.h>
 
+#include "blk.h"
 #include "tapdisk.h"
 #include "disktypes.h"
 #include "blktaplib.h"
@@ -150,7 +150,7 @@ tapdisk_get_image_size(int fd, uint64_t 
 	int ret;
 	struct stat stat;
 	uint64_t sectors;
-	uint32_t sector_size;
+	uint64_t sector_size;
 
 	sectors       = 0;
 	sector_size   = 0;
@@ -164,26 +164,12 @@ tapdisk_get_image_size(int fd, uint64_t 
 
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
-		if (ioctl(fd, BLKGETSIZE, &sectors)) {
-			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		if (blk_getimagesize(fd, &sectors) != 0)
 			return -EINVAL;
-		}
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &sector_size) != 0)
 			sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &sector_size);
-
-			if (sector_size != DEFAULT_SECTOR_SIZE)
-				DPRINTF("Note: sector size is %u (not %d)\n",
-					sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		sector_size = DEFAULT_SECTOR_SIZE;
-#endif
-
 	} else {
 		/*Local file? try fstat instead*/
 		sectors     = (stat.st_size >> SECTOR_SHIFT);
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-vbd.c
--- a/tools/blktap2/drivers/tapdisk-vbd.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk-vbd.c	Tue Jun 23 14:21:57 2009 +0200
@@ -826,10 +826,10 @@ tapdisk_vbd_shutdown(td_vbd_t *vbd)
 	DPRINTF("%s: state: 0x%08x, new: 0x%02x, pending: 0x%02x, "
 		"failed: 0x%02x, completed: 0x%02x\n", 
 		vbd->name, vbd->state, new, pending, failed, completed);
-	DPRINTF("last activity: %010ld.%06ld, errors: 0x%04"PRIx64", "
+	DPRINTF("last activity: %010ld.%06lld, errors: 0x%04"PRIx64", "
 		"retries: 0x%04"PRIx64", received: 0x%08"PRIx64", "
 		"returned: 0x%08"PRIx64", kicked: 0x%08"PRIx64"\n",
-		vbd->ts.tv_sec, vbd->ts.tv_usec,
+		vbd->ts.tv_sec, (unsigned long long)vbd->ts.tv_usec,
 		vbd->errors, vbd->retries, vbd->received, vbd->returned,
 		vbd->kicked);
 
@@ -886,11 +886,12 @@ tapdisk_vbd_debug(td_vbd_t *vbd)
 	tapdisk_vbd_queue_count(vbd, &new, &pending, &failed, &completed);
 
 	DBG(TLOG_WARN, "%s: state: 0x%08x, new: 0x%02x, pending: 0x%02x, "
-	    "failed: 0x%02x, completed: 0x%02x, last activity: %010ld.%06ld, "
+	    "failed: 0x%02x, completed: 0x%02x, last activity: %010ld.%06lld, "
 	    "errors: 0x%04"PRIx64", retries: 0x%04"PRIx64", received: 0x%08"PRIx64", "
 	    "returned: 0x%08"PRIx64", kicked: 0x%08"PRIx64"\n",
 	    vbd->name, vbd->state, new, pending, failed, completed,
-	    vbd->ts.tv_sec, vbd->ts.tv_usec, vbd->errors, vbd->retries,
+	    vbd->ts.tv_sec, (unsigned long long)vbd->ts.tv_usec,
+	    vbd->errors, vbd->retries,
 	    vbd->received, vbd->returned, vbd->kicked);
 
 	tapdisk_vbd_for_each_image(vbd, image, tmp)
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk.h
--- a/tools/blktap2/drivers/tapdisk.h	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/drivers/tapdisk.h	Tue Jun 23 14:21:57 2009 +0200
@@ -111,7 +111,7 @@ struct td_disk_id {
 
 struct td_disk_info {
 	td_sector_t                  size;
-        long                         sector_size;
+        uint64_t                     sector_size;
 	uint32_t                     info;
 };
 
diff -r 5f5112a7d2ff tools/blktap2/include/libvhd.h
--- a/tools/blktap2/include/libvhd.h	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/include/libvhd.h	Tue Jun 23 14:21:57 2009 +0200
@@ -28,19 +28,40 @@
 #define _VHD_LIB_H_
 
 #include <string.h>
+#ifdef __Linux__
 #include <endian.h>
 #include <byteswap.h>
 #include <uuid/uuid.h>
+#endif
+#ifdef __NetBSD__
+#include <sys/endian.h>
+#include <sys/bswap.h>
+#include <uuid.h>
+#endif
 
 #include "vhd.h"
 
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
+
 #if BYTE_ORDER == LITTLE_ENDIAN
+#ifdef __Linux__
   #define BE16_IN(foo)             (*(foo)) = bswap_16(*(foo))
   #define BE32_IN(foo)             (*(foo)) = bswap_32(*(foo))
   #define BE64_IN(foo)             (*(foo)) = bswap_64(*(foo))
   #define BE16_OUT(foo)            (*(foo)) = bswap_16(*(foo))
   #define BE32_OUT(foo)            (*(foo)) = bswap_32(*(foo))
   #define BE64_OUT(foo)            (*(foo)) = bswap_64(*(foo))
+#endif
+#ifdef __NetBSD__
+  #define BE16_IN(foo)             (*(foo)) = bswap16(*(foo))
+  #define BE32_IN(foo)             (*(foo)) = bswap32(*(foo))
+  #define BE64_IN(foo)             (*(foo)) = bswap64(*(foo))
+  #define BE16_OUT(foo)            (*(foo)) = bswap16(*(foo))
+  #define BE32_OUT(foo)            (*(foo)) = bswap32(*(foo))
+  #define BE64_OUT(foo)            (*(foo)) = bswap64(*(foo))
+#endif
 #else
   #define BE16_IN(foo)
   #define BE32_IN(foo)
@@ -198,7 +219,8 @@ vhd_parent_locator_size(vhd_parent_locat
 static inline int
 vhd_parent_raw(vhd_context_t *ctx)
 {
-	return uuid_is_null(ctx->header.prt_uuid);
+	uint32_t status;
+	return uuid_is_nil(&ctx->header.prt_uuid, &status);
 }
 
 void libvhd_set_log_level(int);
@@ -239,16 +261,16 @@ int vhd_snapshot(const char *snapshot, u
 int vhd_hidden(vhd_context_t *, int *);
 int vhd_chain_depth(vhd_context_t *, int *);
 
-off64_t vhd_position(vhd_context_t *);
-int vhd_seek(vhd_context_t *, off64_t, int);
+off_t vhd_position(vhd_context_t *);
+int vhd_seek(vhd_context_t *, off_t, int);
 int vhd_read(vhd_context_t *, void *, size_t);
 int vhd_write(vhd_context_t *, void *, size_t);
 
 int vhd_offset(vhd_context_t *, uint32_t, uint32_t *);
 
-int vhd_end_of_headers(vhd_context_t *ctx, off64_t *off);
-int vhd_end_of_data(vhd_context_t *ctx, off64_t *off);
-int vhd_batmap_header_offset(vhd_context_t *ctx, off64_t *off);
+int vhd_end_of_headers(vhd_context_t *ctx, off_t *off);
+int vhd_end_of_data(vhd_context_t *ctx, off_t *off);
+int vhd_batmap_header_offset(vhd_context_t *ctx, off_t *off);
 
 int vhd_get_header(vhd_context_t *);
 int vhd_get_footer(vhd_context_t *);
@@ -265,8 +287,8 @@ int vhd_batmap_test(vhd_context_t *, vhd
 void vhd_batmap_set(vhd_context_t *, vhd_batmap_t *, uint32_t);
 void vhd_batmap_clear(vhd_context_t *, vhd_batmap_t *, uint32_t);
 
-int vhd_get_phys_size(vhd_context_t *, off64_t *);
-int vhd_set_phys_size(vhd_context_t *, off64_t);
+int vhd_get_phys_size(vhd_context_t *, off_t *);
+int vhd_set_phys_size(vhd_context_t *, off_t);
 
 int vhd_bitmap_test(vhd_context_t *, char *, uint32_t);
 void vhd_bitmap_set(vhd_context_t *, char *, uint32_t);
@@ -277,26 +299,26 @@ int vhd_parent_locator_get(vhd_context_t
 int vhd_parent_locator_read(vhd_context_t *, vhd_parent_locator_t *, char **);
 int vhd_find_parent(vhd_context_t *, const char *, char **);
 int vhd_parent_locator_write_at(vhd_context_t *, const char *,
-				off64_t, uint32_t, size_t,
+				off_t, uint32_t, size_t,
 				vhd_parent_locator_t *);
 
 int vhd_header_decode_parent(vhd_context_t *, vhd_header_t *, char **);
 int vhd_change_parent(vhd_context_t *, char *parent_path, int raw);
 
 int vhd_read_footer(vhd_context_t *, vhd_footer_t *);
-int vhd_read_footer_at(vhd_context_t *, vhd_footer_t *, off64_t);
+int vhd_read_footer_at(vhd_context_t *, vhd_footer_t *, off_t);
 int vhd_read_footer_strict(vhd_context_t *, vhd_footer_t *);
 int vhd_read_header(vhd_context_t *, vhd_header_t *);
-int vhd_read_header_at(vhd_context_t *, vhd_header_t *, off64_t);
+int vhd_read_header_at(vhd_context_t *, vhd_header_t *, off_t);
 int vhd_read_bat(vhd_context_t *, vhd_bat_t *);
 int vhd_read_batmap(vhd_context_t *, vhd_batmap_t *);
 int vhd_read_bitmap(vhd_context_t *, uint32_t block, char **bufp);
 int vhd_read_block(vhd_context_t *, uint32_t block, char **bufp);
 
 int vhd_write_footer(vhd_context_t *, vhd_footer_t *);
-int vhd_write_footer_at(vhd_context_t *, vhd_footer_t *, off64_t);
+int vhd_write_footer_at(vhd_context_t *, vhd_footer_t *, off_t);
 int vhd_write_header(vhd_context_t *, vhd_header_t *);
-int vhd_write_header_at(vhd_context_t *, vhd_header_t *, off64_t);
+int vhd_write_header_at(vhd_context_t *, vhd_header_t *, off_t);
 int vhd_write_bat(vhd_context_t *, vhd_bat_t *);
 int vhd_write_batmap(vhd_context_t *, vhd_batmap_t *);
 int vhd_write_bitmap(vhd_context_t *, uint32_t block, char *bitmap);
diff -r 5f5112a7d2ff tools/blktap2/include/list.h
--- a/tools/blktap2/include/list.h	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/include/list.h	Tue Jun 23 14:21:57 2009 +0200
@@ -2,6 +2,7 @@
  * list.h
  * 
  * This is a subset of linux's list.h intended to be used in user-space.
+ * XXX The namespace conflicts with NetBSD's <sys/queue.h>
  * 
  */
 
@@ -15,6 +16,16 @@ struct list_head {
         struct list_head *next, *prev;
 };
  
+/* XXX workaround for conflicts. The list API should use its own
+ * namespace prefix, i.e. BLK_
+ */
+#ifdef LIST_HEAD_INIT
+#undef LIST_HEAD_INIT
+#endif
+#ifndef LIST_HEAD
+#undef LIST_HEAD
+#endif
+
 #define LIST_HEAD_INIT(name) { &(name), &(name) }
  
 #define LIST_HEAD(name) \
diff -r 5f5112a7d2ff tools/blktap2/include/vhd.h
--- a/tools/blktap2/include/vhd.h	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/include/vhd.h	Tue Jun 23 14:21:57 2009 +0200
@@ -27,8 +27,13 @@
 #ifndef __VHD_H__
 #define __VHD_H__
 
+#ifdef __Linux__
 #include <asm/types.h>
 #include <uuid/uuid.h>
+#endif
+#ifdef __NetBSD__
+#include <uuid.h>
+#endif
 #include <inttypes.h>
 
 typedef uint32_t u32;
diff -r 5f5112a7d2ff tools/blktap2/vhd/Makefile
--- a/tools/blktap2/vhd/Makefile	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/Makefile	Tue Jun 23 14:21:57 2009 +0200
@@ -22,7 +22,9 @@ CFLAGS            += -static
 endif
 
 LIBS              := -Llib -lvhd
+ifeq ($(CONFIG_Linux),y)
 LIBS              += -luuid
+endif
 
 # Get gcc to generate the dependencies for us.
 CFLAGS            += -Wp,-MD,.$(@F).d
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/Makefile
--- a/tools/blktap2/vhd/lib/Makefile	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/Makefile	Tue Jun 23 14:21:57 2009 +0200
@@ -19,7 +19,9 @@ CFLAGS          += -D_GNU_SOURCE
 CFLAGS          += -fPIC
 CFLAGS          += -g
 
+ifeq ($(CONFIG_Linux),y)
 LIBS            := -luuid
+endif
 
 # Get gcc to generate the dependencies for us.
 CFLAGS          += -Wp,-MD,.$(@F).d
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/libvhd-journal.c
--- a/tools/blktap2/vhd/lib/libvhd-journal.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/libvhd-journal.c	Tue Jun 23 14:21:57 2009 +0200
@@ -52,21 +52,21 @@ typedef struct vhd_journal_entry {
 } vhd_journal_entry_t;
 
 static inline int
-vhd_journal_seek(vhd_journal_t *j, off64_t offset, int whence)
+vhd_journal_seek(vhd_journal_t *j, off_t offset, int whence)
 {
-	off64_t off;
+	off_t off;
 
-	off = lseek64(j->jfd, offset, whence);
-	if (off == (off64_t)-1)
+	off = lseek(j->jfd, offset, whence);
+	if (off == (off_t)-1)
 		return -errno;
 
 	return 0;
 }
 
-static inline off64_t
+static inline off_t
 vhd_journal_position(vhd_journal_t *j)
 {
-	return lseek64(j->jfd, 0, SEEK_CUR);
+	return lseek(j->jfd, 0, SEEK_CUR);
 }
 
 static inline int
@@ -98,7 +98,7 @@ vhd_journal_write(vhd_journal_t *j, void
 }
 
 static inline int
-vhd_journal_truncate(vhd_journal_t *j, off64_t length)
+vhd_journal_truncate(vhd_journal_t *j, off_t length)
 {
 	int err;
 
@@ -145,7 +145,7 @@ static int
 vhd_journal_validate_header(vhd_journal_t *j, vhd_journal_header_t *header)
 {
 	int err;
-	off64_t eof;
+	off_t eof;
 
 	if (memcmp(header->cookie,
 		   VHD_JOURNAL_HEADER_COOKIE, sizeof(header->cookie)))
@@ -156,7 +156,7 @@ vhd_journal_validate_header(vhd_journal_
 		return err;
 
 	eof = vhd_journal_position(j);
-	if (eof == (off64_t)-1)
+	if (eof == (off_t)-1)
 		return -errno;
 
 	if (j->header.journal_data_offset > j->header.journal_eof)
@@ -219,7 +219,7 @@ static int
 vhd_journal_add_journal_header(vhd_journal_t *j)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_context_t *vhd;
 
 	vhd = &j->vhd;
@@ -230,14 +230,14 @@ vhd_journal_add_journal_header(vhd_journ
 		return err;
 
 	off = vhd_position(vhd);
-	if (off == (off64_t)-1)
+	if (off == (off_t)-1)
 		return -errno;
 
 	err = vhd_get_footer(vhd);
 	if (err)
 		return err;
 
-	uuid_copy(j->header.uuid, vhd->footer.uuid);
+	memcpy(&j->header.uuid, &vhd->footer.uuid, sizeof(uuid_t));
 	memcpy(j->header.cookie,
 	       VHD_JOURNAL_HEADER_COOKIE, sizeof(j->header.cookie));
 	j->header.vhd_footer_offset = off - sizeof(vhd_footer_t);
@@ -353,11 +353,11 @@ vhd_journal_validate_entry_data(vhd_jour
 }
 
 static int
-vhd_journal_update(vhd_journal_t *j, off64_t offset,
+vhd_journal_update(vhd_journal_t *j, off_t offset,
 		   char *buf, size_t size, uint32_t type)
 {
 	int err;
-	off64_t eof;
+	off_t eof;
 	uint64_t *off, off_bak;
 	uint32_t *entries;
 	vhd_journal_entry_t entry;
@@ -413,7 +413,7 @@ static int
 vhd_journal_add_footer(vhd_journal_t *j)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_context_t *vhd;
 	vhd_footer_t footer;
 
@@ -424,7 +424,7 @@ vhd_journal_add_footer(vhd_journal_t *j)
 		return err;
 
 	off = vhd_position(vhd);
-	if (off == (off64_t)-1)
+	if (off == (off_t)-1)
 		return -errno;
 
 	err = vhd_read_footer_at(vhd, &footer, off - sizeof(vhd_footer_t));
@@ -459,7 +459,7 @@ static int
 vhd_journal_add_header(vhd_journal_t *j)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_context_t *vhd;
 	vhd_header_t header;
 
@@ -495,7 +495,7 @@ vhd_journal_add_locators(vhd_journal_t *
 	n = sizeof(vhd->header.loc) / sizeof(vhd_parent_locator_t);
 	for (i = 0; i < n; i++) {
 		char *buf;
-		off64_t off;
+		off_t off;
 		size_t size;
 		vhd_parent_locator_t *loc;
 
@@ -542,7 +542,7 @@ static int
 vhd_journal_add_bat(vhd_journal_t *j)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	size_t size;
 	vhd_bat_t bat;
 	vhd_context_t *vhd;
@@ -572,7 +572,7 @@ static int
 vhd_journal_add_batmap(vhd_journal_t *j)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	size_t size;
 	vhd_context_t *vhd;
 	vhd_batmap_t batmap;
@@ -611,7 +611,7 @@ static int
 vhd_journal_add_metadata(vhd_journal_t *j)
 {
 	int err;
-	off64_t eof;
+	off_t eof;
 	vhd_context_t *vhd;
 
 	vhd = &j->vhd;
@@ -930,7 +930,7 @@ vhd_journal_restore_footer_copy(vhd_jour
 static int
 vhd_journal_restore_header(vhd_journal_t *j, vhd_header_t *header)
 {
-	off64_t off;
+	off_t off;
 	vhd_context_t *vhd;
 
 	vhd = &j->vhd;
@@ -985,7 +985,7 @@ vhd_journal_restore_batmap(vhd_journal_t
 static int
 vhd_journal_restore_metadata(vhd_journal_t *j)
 {
-	off64_t off;
+	off_t off;
 	char **locators;
 	vhd_footer_t copy;
 	vhd_context_t *vhd;
@@ -1046,7 +1046,7 @@ vhd_journal_restore_metadata(vhd_journal
 
 restore:
 	off  = vhd_journal_position(j);
-	if (off == (off64_t)-1)
+	if (off == (off_t)-1)
 		return -errno;
 
 	if (j->header.journal_data_offset != off)
@@ -1259,7 +1259,7 @@ vhd_journal_create(vhd_journal_t *j, con
 	char *buf;
 	int i, err;
 	size_t size;
-	off64_t off;
+	off_t off;
 	struct stat stats;
 
 	memset(j, 0, sizeof(vhd_journal_t));
@@ -1345,7 +1345,7 @@ vhd_journal_add_block(vhd_journal_t *j, 
 {
 	int err;
 	char *buf;
-	off64_t off;
+	off_t off;
 	size_t size;
 	uint64_t blk;
 	vhd_context_t *vhd;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/libvhd.c
--- a/tools/blktap2/vhd/lib/libvhd.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/libvhd.c	Tue Jun 23 14:21:57 2009 +0200
@@ -250,8 +250,7 @@ vhd_validate_footer(vhd_footer_t *footer
 	if (memcmp(footer->cookie, HD_COOKIE, csize) != 0 &&
 	    memcmp(footer->cookie, VHD_POISON_COOKIE, csize) != 0) {
 		char buf[9];
-		memcpy(buf, footer->cookie, 8);
-		buf[8]= '\0';
+		strlcpy(buf, footer->cookie, sizeof(buf));
 		VHDLOG("invalid footer cookie: %s\n", buf);
 		return -EINVAL;
 	}
@@ -311,8 +310,7 @@ vhd_validate_header(vhd_header_t *header
 
 	if (memcmp(header->cookie, DD_COOKIE, 8) != 0) {
 		char buf[9];
-		memcpy(buf, header->cookie, 8);
-		buf[8] = '\0';
+		strlcpy(buf, header->cookie, sizeof(buf));
 		VHDLOG("invalid header cookie: %s\n", buf);
 		return -EINVAL;
 	}
@@ -403,9 +401,9 @@ vhd_validate_batmap(vhd_batmap_t *batmap
 }
 
 int
-vhd_batmap_header_offset(vhd_context_t *ctx, off64_t *_off)
+vhd_batmap_header_offset(vhd_context_t *ctx, off_t *_off)
 {
-	off64_t off;
+	off_t off;
 	size_t  bat;
 
 	*_off = 0;
@@ -592,11 +590,11 @@ vhd_bitmap_clear(vhd_context_t *ctx, cha
  * byte of the file which is not vhd metadata
  */
 int
-vhd_end_of_headers(vhd_context_t *ctx, off64_t *end)
+vhd_end_of_headers(vhd_context_t *ctx, off_t *end)
 {
 	int err, i, n;
 	uint32_t bat_bytes;
-	off64_t eom, bat_end;
+	off_t eom, bat_end;
 	vhd_parent_locator_t *loc;
 
 	*end = 0;
@@ -612,7 +610,7 @@ vhd_end_of_headers(vhd_context_t *ctx, o
 	eom       = MAX(eom, bat_end);
 
 	if (vhd_has_batmap(ctx)) {
-		off64_t hdr_end, hdr_secs, map_end, map_secs;
+		off_t hdr_end, hdr_secs, map_end, map_secs;
 
 		err = vhd_get_batmap(ctx);
 		if (err)
@@ -636,7 +634,7 @@ vhd_end_of_headers(vhd_context_t *ctx, o
 	n = sizeof(ctx->header.loc) / sizeof(vhd_parent_locator_t);
 
 	for (i = 0; i < n; i++) {
-		off64_t loc_end;
+		off_t loc_end;
 
 		loc = &ctx->header.loc[i];
 		if (loc->code == PLAT_CODE_NONE)
@@ -651,10 +649,10 @@ vhd_end_of_headers(vhd_context_t *ctx, o
 }
 
 int
-vhd_end_of_data(vhd_context_t *ctx, off64_t *end)
+vhd_end_of_data(vhd_context_t *ctx, off_t *end)
 {
 	int i, err;
-	off64_t max;
+	off_t max;
 	uint64_t blk;
 
 	if (!vhd_type_dynamic(ctx)) {
@@ -663,7 +661,7 @@ vhd_end_of_data(vhd_context_t *ctx, off6
 			return err;
 
 		max = vhd_position(ctx);
-		if (max == (off64_t)-1)
+		if (max == (off_t)-1)
 			return -errno;
 
 		*end = max - sizeof(vhd_footer_t);
@@ -871,7 +869,7 @@ vhd_read_short_footer(vhd_context_t *ctx
 {
 	int err;
 	char *buf;
-	off64_t eof;
+	off_t eof;
 
 	buf = NULL;
 
@@ -880,7 +878,7 @@ vhd_read_short_footer(vhd_context_t *ctx
 		goto out;
 
 	eof = vhd_position(ctx);
-	if (eof == (off64_t)-1) {
+	if (eof == (off_t)-1) {
 		err = -errno;
 		goto out;
 	}
@@ -918,7 +916,7 @@ out:
 }
 
 int
-vhd_read_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off64_t off)
+vhd_read_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off_t off)
 {
 	int err;
 	char *buf;
@@ -958,14 +956,14 @@ int
 vhd_read_footer(vhd_context_t *ctx, vhd_footer_t *footer)
 {
 	int err;
-	off64_t off;
+	off_t off;
 
 	err = vhd_seek(ctx, 0, SEEK_END);
 	if (err)
 		return err;
 
 	off = vhd_position(ctx);
-	if (off == (off64_t)-1)
+	if (off == (off_t)-1)
 		return -errno;
 
 	err = vhd_read_footer_at(ctx, footer, off - 512);
@@ -983,7 +981,7 @@ vhd_read_footer(vhd_context_t *ctx, vhd_
 }
 
 int
-vhd_read_header_at(vhd_context_t *ctx, vhd_header_t *header, off64_t off)
+vhd_read_header_at(vhd_context_t *ctx, vhd_header_t *header, off_t off)
 {
 	int err;
 	char *buf;
@@ -1028,7 +1026,7 @@ int
 vhd_read_header(vhd_context_t *ctx, vhd_header_t *header)
 {
 	int err;
-	off64_t off;
+	off_t off;
 
 	if (!vhd_type_dynamic(ctx)) {
 		VHDLOG("%s is not dynamic!\n", ctx->file);
@@ -1044,7 +1042,7 @@ vhd_read_bat(vhd_context_t *ctx, vhd_bat
 {
 	int err;
 	char *buf;
-	off64_t off;
+	off_t off;
 	size_t size;
 
 	buf  = NULL;
@@ -1092,7 +1090,7 @@ vhd_read_batmap_header(vhd_context_t *ct
 {
 	int err;
 	char *buf;
-	off64_t off;
+	off_t off;
 	size_t size;
 
 	buf = NULL;
@@ -1137,7 +1135,7 @@ vhd_read_batmap_map(vhd_context_t *ctx, 
 {
 	int err;
 	char *buf;
-	off64_t off;
+	off_t off;
 	size_t map_size;
 
 	map_size = vhd_sectors_to_bytes(batmap->header.batmap_size);
@@ -1331,9 +1329,9 @@ vhd_macx_encode_location(char *name, cha
 		goto out;
 	}
 
-	sprintf(uri, "file://%s", name);
+	snprintf(uri, ibl+1, "file://%s", name);
 
-	if (iconv(cd, &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
+	if (iconv(cd, (const char **)&urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
 	    ibl || obl) {
 		err = (errno ? -errno : -EIO);
 		goto out;
@@ -1364,7 +1362,8 @@ vhd_w2u_encode_location(char *name, char
 	iconv_t cd;
 	int len, err;
 	size_t ibl, obl;
-	char *uri, *urip, *uri_utf16, *uri_utf16p, *tmp, *ret;
+	char *uri, *uri_utf16, *uri_utf16p, *tmp, *ret;
+	const char *urip;
 
 	err     = 0;
 	ret     = NULL;
@@ -1446,7 +1445,7 @@ vhd_w2u_encode_location(char *name, char
 }
 
 static char *
-vhd_macx_decode_location(char *in, char *out, int len)
+vhd_macx_decode_location(const char *in, char *out, int len)
 {
 	iconv_t cd;
 	char *name;
@@ -1474,7 +1473,7 @@ vhd_macx_decode_location(char *in, char 
 }
 
 static char *
-vhd_w2u_decode_location(char *in, char *out, int len, char *utf_type)
+vhd_w2u_decode_location(const char *in, char *out, int len, char *utf_type)
 {
 	iconv_t cd;
 	char *name, *tmp;
@@ -1646,7 +1645,7 @@ vhd_parent_locator_get(vhd_context_t *ct
 
 int
 vhd_parent_locator_write_at(vhd_context_t *ctx,
-			    const char *parent, off64_t off, uint32_t code,
+			    const char *parent, off_t off, uint32_t code,
 			    size_t max_bytes, vhd_parent_locator_t *loc)
 {
 	struct stat stats;
@@ -1762,7 +1761,7 @@ out:
 }
 
 static int
-vhd_footer_offset_at_eof(vhd_context_t *ctx, off64_t *off)
+vhd_footer_offset_at_eof(vhd_context_t *ctx, off_t *off)
 {
 	int err;
 	if ((err = vhd_seek(ctx, 0, SEEK_END)))
@@ -1777,7 +1776,7 @@ vhd_read_bitmap(vhd_context_t *ctx, uint
 	int err;
 	char *buf;
 	size_t size;
-	off64_t off;
+	off_t off;
 	uint64_t blk;
 
 	buf   = NULL;
@@ -1827,7 +1826,7 @@ vhd_read_block(vhd_context_t *ctx, uint3
 	char *buf;
 	size_t size;
 	uint64_t blk;
-	off64_t end, off;
+	off_t end, off;
 
 	buf   = NULL;
 	*bufp = NULL;
@@ -1881,7 +1880,7 @@ fail:
 }
 
 int
-vhd_write_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off64_t off)
+vhd_write_footer_at(vhd_context_t *ctx, vhd_footer_t *footer, off_t off)
 {
 	int err;
 	vhd_footer_t *f;
@@ -1923,7 +1922,7 @@ int
 vhd_write_footer(vhd_context_t *ctx, vhd_footer_t *footer)
 {
 	int err;
-	off64_t off;
+	off_t off;
 
 	if (ctx->is_block)
 		err = vhd_footer_offset_at_eof(ctx, &off);
@@ -1943,7 +1942,7 @@ vhd_write_footer(vhd_context_t *ctx, vhd
 }
 
 int
-vhd_write_header_at(vhd_context_t *ctx, vhd_header_t *header, off64_t off)
+vhd_write_header_at(vhd_context_t *ctx, vhd_header_t *header, off_t off)
 {
 	int err;
 	vhd_header_t *h;
@@ -1990,7 +1989,7 @@ int
 vhd_write_header(vhd_context_t *ctx, vhd_header_t *header)
 {
 	int err;
-	off64_t off;
+	off_t off;
 
 	if (!vhd_type_dynamic(ctx))
 		return -EINVAL;
@@ -2003,7 +2002,7 @@ int
 vhd_write_bat(vhd_context_t *ctx, vhd_bat_t *bat)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_bat_t b;
 	size_t size;
 
@@ -2046,7 +2045,7 @@ int
 vhd_write_batmap(vhd_context_t *ctx, vhd_batmap_t *batmap)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_batmap_t b;
 	char *buf, *map;
 	size_t size, map_size;
@@ -2122,7 +2121,7 @@ int
 vhd_write_bitmap(vhd_context_t *ctx, uint32_t block, char *bitmap)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	uint64_t blk;
 	size_t secs, size;
 
@@ -2161,7 +2160,7 @@ int
 vhd_write_block(vhd_context_t *ctx, uint32_t block, char *data)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	size_t size;
 	uint64_t blk;
 
@@ -2212,12 +2211,12 @@ namedup(char **dup, const char *name)
 }
 
 int
-vhd_seek(vhd_context_t *ctx, off64_t offset, int whence)
+vhd_seek(vhd_context_t *ctx, off_t offset, int whence)
 {
-	off64_t off;
+	off_t off;
 
-	off = lseek64(ctx->fd, offset, whence);
-	if (off == (off64_t)-1) {
+	off = lseek(ctx->fd, offset, whence);
+	if (off == (off_t)-1) {
 		VHDLOG("%s: seek(0x%08"PRIx64", %d) failed: %d\n",
 		       ctx->file, offset, whence, -errno);
 		return -errno;
@@ -2226,10 +2225,10 @@ vhd_seek(vhd_context_t *ctx, off64_t off
 	return 0;
 }
 
-off64_t
+off_t
 vhd_position(vhd_context_t *ctx)
 {
-	return lseek64(ctx->fd, 0, SEEK_CUR);
+	return lseek(ctx->fd, 0, SEEK_CUR);
 }
 
 int
@@ -2418,9 +2417,11 @@ vhd_close(vhd_context_t *ctx)
 	memset(ctx, 0, sizeof(vhd_context_t));
 }
 
-static inline void
+static inline uint32_t
 vhd_initialize_footer(vhd_context_t *ctx, int type, uint64_t size)
 {
+	uint32_t status;
+
 	memset(&ctx->footer, 0, sizeof(vhd_footer_t));
 	memcpy(ctx->footer.cookie, HD_COOKIE, sizeof(ctx->footer.cookie));
 	ctx->footer.features     = HD_RESERVED;
@@ -2435,7 +2436,8 @@ vhd_initialize_footer(vhd_context_t *ctx
 	ctx->footer.saved        = 0;
 	ctx->footer.data_offset  = 0xFFFFFFFFFFFFFFFF;
 	strcpy(ctx->footer.crtr_app, "tap");
-	uuid_generate(ctx->footer.uuid);
+	uuid_create(&ctx->footer.uuid, &status);
+	return status;
 }
 
 static int
@@ -2444,7 +2446,8 @@ vhd_initialize_header_parent_name(vhd_co
 	int err;
 	iconv_t cd;
 	size_t ibl, obl;
-	char *pname, *ppath, *dst;
+	char *ppath, *dst;
+	const char *pname;
 
 	err   = 0;
 	pname = NULL;
@@ -2487,18 +2490,18 @@ out:
 	return err;
 }
 
-static off64_t
+static off_t
 get_file_size(const char *name)
 {
 	int fd;
-	off64_t end;
+	off_t end;
 
 	fd = open(name, O_LARGEFILE | O_RDONLY);
 	if (fd == -1) {
 		VHDLOG("unable to open '%s': %d\n", name, errno);
 		return -errno;
 	}
-	end = lseek64(fd, 0, SEEK_END);
+	end = lseek(fd, 0, SEEK_END);
 	close(fd); 
 	return end;
 }
@@ -2545,7 +2548,8 @@ vhd_initialize_header(vhd_context_t *ctx
 			return err;
 
 		ctx->header.prt_ts = vhd_time(stats.st_mtime);
-		uuid_copy(ctx->header.prt_uuid, parent.footer.uuid);
+		memcpy(&ctx->header.prt_uuid, &parent.footer.uuid,
+			sizeof(uuid_t));
 		if (!size)
 			size = parent.footer.curr_size;
 		vhd_close(&parent);
@@ -2563,7 +2567,7 @@ static int
 vhd_write_parent_locators(vhd_context_t *ctx, const char *parent)
 {
 	int i, err;
-	off64_t off;
+	off_t off;
 	uint32_t code;
 
 	code = PLAT_CODE_NONE;
@@ -2627,7 +2631,7 @@ vhd_change_parent(vhd_context_t *child, 
 	}
 
 	if (raw) {
-		uuid_clear(child->header.prt_uuid);
+		memset(&child->header.prt_uuid, 0, sizeof(uuid_t));
 	} else {
 		err = vhd_open(&parent, ppath, VHD_OPEN_RDONLY);
 		if (err) {
@@ -2635,7 +2639,8 @@ vhd_change_parent(vhd_context_t *child, 
 			       ppath, child->file, err);
 			goto out;
 		}
-		uuid_copy(child->header.prt_uuid, parent.footer.uuid);
+		memcpy(&child->header.prt_uuid, &parent.footer.uuid,
+			sizeof(uuid_t));
 		vhd_close(&parent);
 	}
 
@@ -2683,7 +2688,7 @@ out:
 static int
 vhd_create_batmap(vhd_context_t *ctx)
 {
-	off64_t off;
+	off_t off;
 	int err, map_bytes;
 	vhd_batmap_header_t *header;
 
@@ -2694,7 +2699,7 @@ vhd_create_batmap(vhd_context_t *ctx)
 	header    = &ctx->batmap.header;
 
 	memset(header, 0, sizeof(vhd_batmap_header_t));
-	memcpy(header->cookie, VHD_BATMAP_COOKIE, sizeof(header->cookie));
+	memcpy(header->cookie, VHD_BATMAP_COOKIE, sizeof(*header->cookie));
 
 	err = vhd_batmap_header_offset(ctx, &off);
 	if (err)
@@ -2763,7 +2768,7 @@ vhd_initialize_fixed_disk(vhd_context_t 
 		return err;
 
 	buf = mmap(0, VHD_BLOCK_SIZE, PROT_READ,
-		   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+		   MAP_SHARED | MAP_ANON, -1, 0);
 	if (buf == MAP_FAILED)
 		return -errno;
 
@@ -2781,7 +2786,7 @@ out:
 }
 
 int 
-vhd_get_phys_size(vhd_context_t *ctx, off64_t *size)
+vhd_get_phys_size(vhd_context_t *ctx, off_t *size)
 {
 	int err;
 
@@ -2792,9 +2797,9 @@ vhd_get_phys_size(vhd_context_t *ctx, of
 }
 
 int 
-vhd_set_phys_size(vhd_context_t *ctx, off64_t size)
+vhd_set_phys_size(vhd_context_t *ctx, off_t size)
 {
-	off64_t phys_size;
+	off_t phys_size;
 	int err;
 
 	err = vhd_get_phys_size(ctx, &phys_size);
@@ -2815,7 +2820,7 @@ __vhd_create(const char *name, const cha
 		vhd_flag_creat_t flags)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_context_t ctx;
 	vhd_footer_t *footer;
 	vhd_header_t *header;
@@ -2901,7 +2906,7 @@ __vhd_create(const char *name, const cha
 		goto out;
 
 	off = vhd_position(&ctx);
-	if (off == (off64_t)-1) {
+	if (off == (off_t)-1) {
 		err = -errno;
 		goto out;
 	}
@@ -2976,7 +2981,7 @@ static int
 __vhd_io_dynamic_read_link(vhd_context_t *ctx, char *map,
 			   char *buf, uint64_t sector, uint32_t secs)
 {
-	off64_t off;
+	off_t off;
 	uint32_t blk, sec;
 	int err, cnt, map_off;
 	char *bitmap, *data, *src;
@@ -3032,7 +3037,7 @@ __raw_read_link(char *filename,
 		char *map, char *buf, uint64_t sec, uint32_t secs)
 {
 	int fd, err;
-	off64_t off;
+	off_t off;
 	uint64_t size;
 	char *data;
 
@@ -3044,8 +3049,8 @@ __raw_read_link(char *filename,
 		return -errno;
 	}
 
-	off = lseek64(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
-	if (off == (off64_t)-1) {
+	off = lseek(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
+	if (off == (off_t)-1) {
 		VHDLOG("%s: seek(0x%08"PRIx64") failed: %d\n",
 		       filename, vhd_sectors_to_bytes(sec), -errno);
 		err = -errno;
@@ -3178,7 +3183,7 @@ __vhd_io_allocate_block(vhd_context_t *c
 {
 	char *buf;
 	size_t size;
-	off64_t off, max;
+	off_t off, max;
 	int i, err, gap, spp;
 
 	spp = getpagesize() >> VHD_SECTOR_SHIFT;
@@ -3202,7 +3207,7 @@ __vhd_io_allocate_block(vhd_context_t *c
 		return err;
 
 	size = vhd_sectors_to_bytes(ctx->spb + ctx->bm_secs + gap);
-	buf  = mmap(0, size, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+	buf  = mmap(0, size, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
 	if (buf == MAP_FAILED)
 		return -errno;
 
@@ -3227,7 +3232,7 @@ __vhd_io_dynamic_write(vhd_context_t *ct
 		       char *buf, uint64_t sector, uint32_t secs)
 {
 	char *map;
-	off64_t off;
+	off_t off;
 	uint32_t blk, sec;
 	int i, err, cnt, ret;
 
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-check.c
--- a/tools/blktap2/vhd/lib/vhd-util-check.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-check.c	Tue Jun 23 14:21:57 2009 +0200
@@ -146,7 +146,7 @@ ok:
 static char *
 vhd_util_check_validate_header(int fd, vhd_header_t *header)
 {
-	off64_t eof;
+	off_t eof;
 	int i, cnt, size;
 	uint32_t checksum;
 
@@ -164,8 +164,8 @@ vhd_util_check_validate_header(int fd, v
 	if (header->data_offset != ~(0ULL))
 		return "invalid data offset";
 
-	eof = lseek64(fd, 0, SEEK_END);
-	if (eof == (off64_t)-1)
+	eof = lseek(fd, 0, SEEK_END);
+	if (eof == (off_t)-1)
 		return "error finding eof";
 
 	if (header->table_offset <= 0  ||
@@ -211,6 +211,8 @@ vhd_util_check_validate_differencing_hea
 
 		free(parent);
 	} else {
+		uint32_t status;
+
 		if (vhd_util_check_zeros(header->prt_name,
 					 sizeof(header->prt_name)))
 			return "invalid non-null parent name";
@@ -218,7 +220,7 @@ vhd_util_check_validate_differencing_hea
 		if (vhd_util_check_zeros(header->loc, sizeof(header->loc)))
 			return "invalid non-null parent locators";
 
-		if (!uuid_is_null(header->prt_uuid))
+		if (!uuid_is_nil(&header->prt_uuid, &status))
 			return "invalid non-null parent uuid";
 
 		if (header->prt_ts)
@@ -232,7 +234,7 @@ static char *
 vhd_util_check_validate_batmap(vhd_context_t *vhd, vhd_batmap_t *batmap)
 {
 	int size;
-	off64_t eof;
+	off_t eof;
 	uint32_t checksum;
 
 	size = sizeof(batmap->header.cookie);
@@ -249,8 +251,8 @@ vhd_util_check_validate_batmap(vhd_conte
 	if (!batmap->header.batmap_size)
 		return "invalid size zero";
 
-	eof = lseek64(vhd->fd, 0, SEEK_END);
-	if (eof == (off64_t)-1)
+	eof = lseek(vhd->fd, 0, SEEK_END);
+	if (eof == (off_t)-1)
 		return "error finding eof";
 
 	if (!batmap->header.batmap_offset ||
@@ -269,7 +271,7 @@ static char *
 vhd_util_check_validate_parent_locator(vhd_context_t *vhd,
 				       vhd_parent_locator_t *loc)
 {
-	off64_t eof;
+	off_t eof;
 
 	if (vhd_validate_platform_code(loc->code))
 		return "invalid platform code";
@@ -290,8 +292,8 @@ vhd_util_check_validate_parent_locator(v
 	if (!loc->data_len)
 		return "invalid data length";
 
-	eof = lseek64(vhd->fd, 0, SEEK_END);
-	if (eof == (off64_t)-1)
+	eof = lseek(vhd->fd, 0, SEEK_END);
+	if (eof == (off_t)-1)
 		return "error finding eof";
 
 	if (loc->data_offset + vhd_parent_locator_size(loc) >
@@ -304,11 +306,12 @@ vhd_util_check_validate_parent_locator(v
 	return NULL;
 }
 
-static char *
+static const char *
 vhd_util_check_validate_parent(vhd_context_t *vhd, const char *ppath)
 {
-	char *msg;
+	const char *msg;
 	vhd_context_t parent;
+	uint32_t status;
 
 	msg = NULL;
 
@@ -319,7 +322,7 @@ vhd_util_check_validate_parent(vhd_conte
 				VHD_OPEN_RDONLY | VHD_OPEN_IGNORE_DISABLED))
 		return "error opening parent";
 
-	if (uuid_compare(vhd->header.prt_uuid, parent.footer.uuid)) {
+	if (uuid_compare(&vhd->header.prt_uuid, &parent.footer.uuid, &status)) {
 		msg = "invalid parent uuid";
 		goto out;
 	}
@@ -335,7 +338,7 @@ vhd_util_check_footer(int fd, vhd_footer
 	size_t size;
 	int err, opened;
 	char *msg, *buf;
-	off64_t eof, off;
+	off_t eof, off;
 	vhd_footer_t primary, backup;
 
 	memset(&primary, 0, sizeof(primary));
@@ -349,16 +352,16 @@ vhd_util_check_footer(int fd, vhd_footer
 
 	memset(buf, 0, sizeof(primary));
 
-	eof = lseek64(fd, 0, SEEK_END);
-	if (eof == (off64_t)-1) {
+	eof = lseek(fd, 0, SEEK_END);
+	if (eof == (off_t)-1) {
 		err = -errno;
 		printf("error calculating end of file: %d\n", err);
 		goto out;
 	}
 
 	size = ((eof % 512) ? 511 : 512);
-	eof  = lseek64(fd, eof - size, SEEK_SET);
-	if (eof == (off64_t)-1) {
+	eof  = lseek(fd, eof - size, SEEK_SET);
+	if (eof == (off_t)-1) {
 		err = -errno;
 		printf("error calculating end of file: %d\n", err);
 		goto out;
@@ -391,8 +394,8 @@ vhd_util_check_footer(int fd, vhd_footer
 	}
 
 check_backup:
-	off = lseek64(fd, 0, SEEK_SET);
-	if (off == (off64_t)-1) {
+	off = lseek(fd, 0, SEEK_SET);
+	if (off == (off_t)-1) {
 		err = -errno;
 		printf("error seeking to backup footer: %d\n", err);
 		goto out;
@@ -454,7 +457,7 @@ static int
 vhd_util_check_header(int fd, vhd_footer_t *footer)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	char *msg, *buf;
 	vhd_header_t header;
 
@@ -465,8 +468,8 @@ vhd_util_check_header(int fd, vhd_footer
 	}
 
 	off = footer->data_offset;
-	off = lseek64(fd, off, SEEK_SET);
-	if (off == (off64_t)-1) {
+	off = lseek(fd, off, SEEK_SET);
+	if (off == (off_t)-1) {
 		err = -errno;
 		printf("error seeking to header: %d\n", err);
 		goto out;
@@ -513,7 +516,7 @@ vhd_util_check_differencing_header(vhd_c
 static int
 vhd_util_check_bat(vhd_context_t *vhd)
 {
-	off64_t eof, eoh;
+	off_t eof, eoh;
 	int i, j, err, block_size;
 
 	err = vhd_seek(vhd, 0, SEEK_END);
@@ -523,7 +526,7 @@ vhd_util_check_bat(vhd_context_t *vhd)
 	}
 
 	eof = vhd_position(vhd);
-	if (eof == (off64_t)-1) {
+	if (eof == (off_t)-1) {
 		printf("error calculating eof: %d\n", -errno);
 		return -errno;
 	}
@@ -645,7 +648,8 @@ vhd_util_check_parent_locators(vhd_conte
 {
 	int i, n, err;
 	vhd_parent_locator_t *loc;
-	char *msg, *file, *ppath, *location, *pname;
+	char *file, *ppath, *location, *pname;
+	const char *msg;
 	int mac, macx, w2ku, w2ru, wi2r, wi2k, found;
 
 	mac      = 0;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-coalesce.c
--- a/tools/blktap2/vhd/lib/vhd-util-coalesce.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-coalesce.c	Tue Jun 23 14:21:57 2009 +0200
@@ -35,12 +35,12 @@
 static int
 __raw_io_write(int fd, char* buf, uint64_t sec, uint32_t secs)
 {
-	off64_t off;
+	off_t off;
 	size_t ret;
 
 	errno = 0;
-	off = lseek64(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
-	if (off == (off64_t)-1) {
+	off = lseek(fd, vhd_sectors_to_bytes(sec), SEEK_SET);
+	if (off == (off_t)-1) {
 		printf("raw parent: seek(0x%08"PRIx64") failed: %d\n",
 		       vhd_sectors_to_bytes(sec), -errno);
 		return -errno;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-modify.c
--- a/tools/blktap2/vhd/lib/vhd-util-modify.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-modify.c	Tue Jun 23 14:21:57 2009 +0200
@@ -56,7 +56,7 @@ vhd_util_modify(int argc, char **argv)
 	char *name;
 	vhd_context_t vhd;
 	int err, c, size, parent, parent_raw;
-	off64_t newsize = 0;
+	off_t newsize = 0;
 	char *newparent = NULL;
 
 	name       = NULL;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-query.c
--- a/tools/blktap2/vhd/lib/vhd-util-query.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-query.c	Tue Jun 23 14:21:57 2009 +0200
@@ -37,7 +37,7 @@ vhd_util_query(int argc, char **argv)
 {
 	char *name;
 	vhd_context_t vhd;
-	off64_t currsize;
+	off_t currsize;
 	int ret, err, c, size, physize, parent, fields, depth;
 
 	name    = NULL;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-read.c
--- a/tools/blktap2/vhd/lib/vhd-util-read.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-read.c	Tue Jun 23 14:21:57 2009 +0200
@@ -58,12 +58,12 @@ static void
 vhd_print_header(vhd_context_t *vhd, vhd_header_t *h, int hex)
 {
 	int err;
-	uint32_t  cksm;
-	char      uuid[37], time_str[26], cookie[9], out[512], *name;
+	uint32_t  cksm, status;
+	char      uuid[39], time_str[26], cookie[9], out[512], *name;
 
 	printf("VHD Header Summary:\n-------------------\n");
 
-	snprintf(cookie, 9, "%s", h->cookie);
+	snprintf(cookie, sizeof(cookie), "%s", h->cookie);
 	printf("Cookie              : %s\n", cookie);
 
 	printf("Data offset (unusd) : %s\n", conv(hex, h->data_offset));
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
 	       (err ? "failed to read name" : name));
 	free(name);
 
-	uuid_unparse(h->prt_uuid, uuid);
+	uuid_to_string(&h->prt_uuid, (char **)&uuid, &status);
 	printf("Parent UUID         : %s\n", uuid);
     
 	vhd_time_to_string(h->prt_ts, time_str);
@@ -95,11 +95,12 @@ vhd_print_footer(vhd_footer_t *f, int he
 {
 	uint64_t  c, h, s;
 	uint32_t  ff_maj, ff_min, cr_maj, cr_min, cksm, cksm_save;
-	char      time_str[26], creator[5], uuid[37], cookie[9];
+	char      time_str[26], creator[5], uuid[39], cookie[9];
+	uint32_t status;
 
 	printf("VHD Footer Summary:\n-------------------\n");
 
-	snprintf(cookie, 9, "%s", f->cookie);
+	snprintf(cookie, sizeof(cookie), "%s", f->cookie);
 	printf("Cookie              : %s\n", cookie);
 
 	printf("Features            : (0x%08x) %s%s\n", f->features,
@@ -153,7 +154,7 @@ vhd_print_footer(vhd_footer_t *f, int he
 	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
 		f->checksum == cksm ? "Good!" : "Bad!");
 
-	uuid_unparse(f->uuid, uuid);
+	uuid_to_string(&f->uuid, (char **)&uuid, &status);
 	printf("UUID                : %s\n", uuid);
 
 	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-repair.c
--- a/tools/blktap2/vhd/lib/vhd-util-repair.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-repair.c	Tue Jun 23 14:21:57 2009 +0200
@@ -37,7 +37,7 @@ vhd_util_repair(int argc, char **argv)
 {
 	char *name;
 	int err, c;
-	off64_t eof;
+	off_t eof;
 	vhd_context_t vhd;
 
 	name = NULL;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-resize.c
--- a/tools/blktap2/vhd/lib/vhd-util-resize.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-resize.c	Tue Jun 23 14:21:57 2009 +0200
@@ -95,7 +95,7 @@ vhd_fixed_shrink(vhd_journal_t *journal,
 }
 
 static int
-vhd_write_zeros(vhd_journal_t *journal, off64_t off, uint64_t size)
+vhd_write_zeros(vhd_journal_t *journal, off_t off, uint64_t size)
 {
 	int err;
 	char *buf;
@@ -109,7 +109,7 @@ vhd_write_zeros(vhd_journal_t *journal, 
 	if (err)
 		return err;
 
-	buf = mmap(0, map, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+	buf = mmap(0, map, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
 	if (buf == MAP_FAILED)
 		return -errno;
 
@@ -143,7 +143,7 @@ vhd_fixed_grow(vhd_journal_t *journal, u
 		goto out;
 
 	eof = vhd_position(vhd);
-	if (eof == (off64_t)-1) {
+	if (eof == (off_t)-1) {
 		err = -errno;
 		goto out;
 	}
@@ -234,13 +234,13 @@ quicksort(vhd_block_t *list, int left, i
 }
 
 static int
-vhd_move_block(vhd_journal_t *journal, uint32_t src, off64_t offset)
+vhd_move_block(vhd_journal_t *journal, uint32_t src, off_t offset)
 {
 	int err;
 	char *buf;
 	size_t size;
 	vhd_context_t *vhd;
-	off64_t off, src_off;
+	off_t off, src_off;
 
 	buf     = NULL;
 	vhd     = &journal->vhd;
@@ -300,7 +300,7 @@ static int
 vhd_clobber_block(vhd_journal_t *journal, uint32_t src, uint32_t dest)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_context_t *vhd;
 
 	vhd = &journal->vhd;
@@ -404,7 +404,7 @@ vhd_clear_bat_entries(vhd_journal_t *jou
 {
 	int i, err;
 	vhd_context_t *vhd;
-	off64_t orig_map_off, new_map_off;
+	off_t orig_map_off, new_map_off;
 	uint32_t orig_entries, new_entries;
 
 	vhd          = &journal->vhd;
@@ -473,7 +473,7 @@ vhd_clear_bat_entries(vhd_journal_t *jou
 static int
 vhd_dynamic_shrink(vhd_journal_t *journal, uint64_t secs)
 {
-	off64_t eof;
+	off_t eof;
 	uint32_t blocks;
 	vhd_context_t *vhd;
 	int i, j, err, free_cnt;
@@ -581,7 +581,7 @@ vhd_next_block_offset(vhd_context_t *vhd
 }
 
 static inline int
-in_range(off64_t off, off64_t start, off64_t size)
+in_range(off_t off, off_t start, off_t size)
 {
 	return (start < off && start + size > off);
 }
@@ -599,7 +599,7 @@ skip_check(int mode, int type)
 }
 
 static int
-vhd_check_for_clobber(vhd_context_t *vhd, off64_t off, int mode)
+vhd_check_for_clobber(vhd_context_t *vhd, off_t off, int mode)
 {
 	int i, n;
 	char *msg;
@@ -676,7 +676,7 @@ fail:
  * take any metadata after the bat (@eob) and shift it
  */
 static int
-vhd_shift_metadata(vhd_journal_t *journal, off64_t eob,
+vhd_shift_metadata(vhd_journal_t *journal, off_t eob,
 		   size_t bat_needed, size_t map_needed)
 {
 	int i, n, err;
@@ -724,7 +724,7 @@ vhd_shift_metadata(vhd_journal_t *journa
 	}
 
 	for (i = 0; i < n; i++) {
-		off64_t off;
+		off_t off;
 		size_t size;
 
 		if (!locators[i])
@@ -775,7 +775,7 @@ static int
 vhd_add_bat_entries(vhd_journal_t *journal, int entries)
 {
 	int i, err;
-	off64_t off;
+	off_t off;
 	vhd_bat_t new_bat;
 	vhd_context_t *vhd;
 	uint32_t new_entries;
@@ -878,7 +878,7 @@ static int
 vhd_dynamic_grow(vhd_journal_t *journal, uint64_t secs)
 {
 	int i, err;
-	off64_t eob, eom;
+	off_t eob, eom;
 	vhd_context_t *vhd;
 	vhd_block_t first_block;
 	uint64_t blocks, size_needed;
@@ -953,7 +953,7 @@ vhd_dynamic_grow(vhd_journal_t *journal,
 	 * move vhd data blocks to the end of the file to make room 
 	 */
 	do {
-		off64_t new_off, bm_size, gap_size;
+		off_t new_off, bm_size, gap_size;
 
 		new_off = vhd_sectors_to_bytes(vhd_next_block_offset(vhd));
 
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-scan.c
--- a/tools/blktap2/vhd/lib/vhd-util-scan.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-scan.c	Tue Jun 23 14:21:57 2009 +0200
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fnmatch.h>
+#include <libgen.h>	/* for basename() */
 
 #include "list.h"
 #include "libvhd.h"
@@ -82,7 +83,7 @@ struct vhd_image {
 	char                *name;
 	char                *parent;
 	uint64_t             capacity;
-	off64_t              size;
+	off_t                size;
 	uint8_t              hidden;
 	int                  error;
 	char                *message;
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-set-field.c
--- a/tools/blktap2/vhd/lib/vhd-util-set-field.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-set-field.c	Tue Jun 23 14:21:57 2009 +0200
@@ -37,7 +37,7 @@ vhd_util_set_field(int argc, char **argv
 {
 	long value;
 	int err, c;
-	off64_t eof;
+	off_t eof;
 	vhd_context_t vhd;
 	char *name, *field;
 
diff -r 5f5112a7d2ff tools/blktap2/vhd/vhd-update.c
--- a/tools/blktap2/vhd/vhd-update.c	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/blktap2/vhd/vhd-update.c	Tue Jun 23 14:21:57 2009 +0200
@@ -36,8 +36,6 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <endian.h>
-#include <byteswap.h>
 
 #include "atomicio.h"
 #include "libvhd.h"
diff -r 5f5112a7d2ff tools/check/check_uuid_devel
--- a/tools/check/check_uuid_devel	Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/check/check_uuid_devel	Tue Jun 23 14:24:36 2009 +0200
@@ -3,4 +3,5 @@
 
 . ./funcs.sh
 
+has_header uuid.h || \
 has_header uuid/uuid.h || fail "missing uuid headers (package uuid-dev)"

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blktap2: portability fixes
  2009-06-23 12:29 [PATCH] blktap2: portability fixes Christoph Egger
@ 2009-06-23 16:25 ` Keir Fraser
  2009-06-24 12:24   ` Christoph Egger
  0 siblings, 1 reply; 5+ messages in thread
From: Keir Fraser @ 2009-06-23 16:25 UTC (permalink / raw)
  To: Christoph Egger, xen-devel

This didn't have a prayer of building on Linux. I fixed it up for Linux and
applied as c/s 19817. It's probably broken for netbsd now, but you should be
able to provide a small fixup patch for that.

 -- Keir

On 23/06/2009 13:29, "Christoph Egger" <Christoph.Egger@amd.com> wrote:

> 
> Hi!
> 
> Attached patch makes blktap2 build on 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>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blktap2: portability fixes
  2009-06-23 16:25 ` Keir Fraser
@ 2009-06-24 12:24   ` Christoph Egger
  2009-06-24 13:07     ` Keir Fraser
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Egger @ 2009-06-24 12:24 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel

[-- Attachment #1: Type: text/plain, Size: 1635 bytes --]


Patch is attached.
uuid is totally different in Linux and in NetBSD.
uuid_t is a char array in Linux and a struct in NetBSD.
Making NetBSD uuid look like Linux uuid doesn't work at all and
neither the other way around.
I renamed your uuid.h header to avoid a recursive inclusion
of the same header.
I created an uuid abstraction with a Linux and NetBSD implementation.

I also fixed a bug in vhd_create_batmap() which slipped in previously.
iconv() is a bit nasty to make it compile on both NetBSD and Linux.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>


On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote:
> This didn't have a prayer of building on Linux. I fixed it up for Linux and
> applied as c/s 19817. It's probably broken for netbsd now, but you should
> be able to provide a small fixup patch for that.
>
>  -- Keir
>
> On 23/06/2009 13:29, "Christoph Egger" <Christoph.Egger@amd.com> wrote:
> > Hi!
> >
> > Attached patch makes blktap2 build on 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>



-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

[-- Attachment #2: xen_blktap2.diff --]
[-- Type: text/x-diff, Size: 16027 bytes --]

diff -r b51f9542ab14 tools/blktap2/drivers/block-vhd.c
--- a/tools/blktap2/drivers/block-vhd.c	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/drivers/block-vhd.c	Wed Jun 24 12:57:16 2009 +0200
@@ -806,7 +806,7 @@ vhd_validate_parent(td_driver_t *child_d
 	}
 	*/
 
-	if (uuid_compare(child->vhd.header.prt_uuid, parent->vhd.footer.uuid)) {
+	if (blk_uuid_compare(&child->vhd.header.prt_uuid, &parent->vhd.footer.uuid)) {
 		DPRINTF("ERROR: %s: %s, %s: parent uuid has changed since "
 			"snapshot.  Child image no longer valid.\n",
 			__func__, child->vhd.file, parent->vhd.file);
diff -r b51f9542ab14 tools/blktap2/include/blk_uuid.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/include/blk_uuid.h	Wed Jun 24 12:57:16 2009 +0200
@@ -0,0 +1,53 @@
+/* Copyright (c) 2008, XenSource Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of XenSource Inc. nor the names of its contributors
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#ifndef __BLKTAP2_UUID_H__
+#define __BLKTAP2_UUID_H__
+
+#if defined(__linux__) || defined(__Linux__)
+#include <uuid/uuid.h>
+/* enforce use of below API */
+#define uuid_is_null(a)    error use blk_uuid_is_nil
+#define uuid_generate(a)   error use blk_uuid_generate
+#define uuid_unparse(a, b) error use blk_uuid_to_string
+#define uuid_parse(a, b)   error use blk_uuid_from_string
+#define uuid_copy(a, b)    error use blk_uuid_copy
+#define uuid_clear(a)      error use blk_uuid_clear
+#define uuid_compare(a,b)  error use blk_uuid_compare
+#endif
+#if defined(__NetBSD__)
+#include <uuid.h>
+#endif
+
+int blk_uuid_is_nil(uuid_t *uuid);
+void blk_uuid_generate(uuid_t *uuid);
+void blk_uuid_to_string(uuid_t *uuid, char **out);
+void blk_uuid_from_string(uuid_t *uuid, const char *in);
+void blk_uuid_copy(uuid_t *dst, uuid_t *src);
+void blk_uuid_clear(uuid_t *uuid);
+int blk_uuid_compare(uuid_t *uuid1, uuid_t *uuid2);
+
+#endif /* __BLKTAP2_UUID_H__ */
diff -r b51f9542ab14 tools/blktap2/include/libvhd.h
--- a/tools/blktap2/include/libvhd.h	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/include/libvhd.h	Wed Jun 24 12:57:16 2009 +0200
@@ -36,7 +36,7 @@
 #include <sys/bswap.h>
 #endif
 
-#include "uuid.h"
+#include "blk_uuid.h"
 #include "vhd.h"
 
 #ifndef O_LARGEFILE
@@ -216,7 +216,7 @@ vhd_parent_locator_size(vhd_parent_locat
 static inline int
 vhd_parent_raw(vhd_context_t *ctx)
 {
-	return uuid_is_null(ctx->header.prt_uuid);
+	return blk_uuid_is_nil(&ctx->header.prt_uuid);
 }
 
 void libvhd_set_log_level(int);
diff -r b51f9542ab14 tools/blktap2/include/uuid.h
--- a/tools/blktap2/include/uuid.h	Wed Jun 24 11:17:11 2009 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/* Copyright (c) 2008, XenSource Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of XenSource Inc. nor the names of its contributors
- *       may be used to endorse or promote products derived from this software
- *       without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#ifndef __BLKTAP2_UUID_H__
-#define __BLKTAP2_UUID_H__
-
-#if defined(__linux__) || defined(__Linux__)
-
-#include <uuid/uuid.h>
-
-#else
-
-#include <inttypes.h>
-#include <string.h>
-#include <uuid.h>
-
-static inline int uuid_is_null(uuid_t uuid)
-{
-    uint32_t status;
-    return uuid_is_nil(&uuid, &status);
-}
-
-static inline void uuid_generate(uuid_t uuid)
-{
-    uint32_t status;
-    uuid_create(&uuid, &status);
-}
-
-static inline void uuid_unparse(uuid_t uuid, char *out)
-{
-    uint32_t status;
-    uuid_to_string(&uuid, (char **)&out, &status);
-}
-
-static inline void uuid_copy(uuid_t dst, uuid_t src)
-{
-    memcpy(dst, src, sizeof(dst));
-}
-
-static inline void uuid_clear(uuid_t uu)
-{
-    memset(uu, 0, sizeof(uu));
-}
-
-#define uuid_compare(x,y) \
-    ({ uint32_t status; uuid_compare(&(x),&(y),&status); })
-
-#endif
-
-#endif /* __BLKTAP2_UUID_H__ */
diff -r b51f9542ab14 tools/blktap2/include/vhd.h
--- a/tools/blktap2/include/vhd.h	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/include/vhd.h	Wed Jun 24 12:57:16 2009 +0200
@@ -28,7 +28,6 @@
 #define __VHD_H__
 
 #include <inttypes.h>
-#include "uuid.h"
 
 typedef uint32_t u32;
 typedef uint64_t u64;
diff -r b51f9542ab14 tools/blktap2/vhd/lib/Makefile
--- a/tools/blktap2/vhd/lib/Makefile	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/vhd/lib/Makefile	Wed Jun 24 12:57:16 2009 +0200
@@ -27,6 +27,10 @@ endif
 CFLAGS          += -Wp,-MD,.$(@F).d
 DEPS             = .*.d
 
+UUID_SRCS-y	:=
+UUID_SRCS-$(CONFIG_Linux) += uuid_linux.c
+UUID_SRCS-$(CONFIG_NetBSD) += uuid_netbsd.c
+
 LIB-SRCS        := libvhd.c
 LIB-SRCS        += libvhd-journal.c
 LIB-SRCS        += vhd-util-coalesce.c
@@ -44,6 +48,7 @@ LIB-SRCS        += vhd-util-scan.c
 LIB-SRCS        += vhd-util-check.c
 LIB-SRCS        += relative-path.c
 LIB-SRCS        += atomicio.c
+LIB-SRCS	+= $(UUID_SRCS-y)
 
 LIB-OBJS         = $(patsubst %.c,%.o,$(LIB-SRCS))
 LIB-OBJS        += $(LVM-UTIL-OBJ)
diff -r b51f9542ab14 tools/blktap2/vhd/lib/libvhd-journal.c
--- a/tools/blktap2/vhd/lib/libvhd-journal.c	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/vhd/lib/libvhd-journal.c	Wed Jun 24 12:57:16 2009 +0200
@@ -237,7 +237,7 @@ vhd_journal_add_journal_header(vhd_journ
 	if (err)
 		return err;
 
-	uuid_copy(j->header.uuid, vhd->footer.uuid);
+	blk_uuid_copy(&j->header.uuid, &vhd->footer.uuid);
 	memcpy(j->header.cookie,
 	       VHD_JOURNAL_HEADER_COOKIE, sizeof(j->header.cookie));
 	j->header.vhd_footer_offset = off - sizeof(vhd_footer_t);
diff -r b51f9542ab14 tools/blktap2/vhd/lib/libvhd.c
--- a/tools/blktap2/vhd/lib/libvhd.c	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/vhd/lib/libvhd.c	Wed Jun 24 12:57:16 2009 +0200
@@ -1308,7 +1308,8 @@ vhd_macx_encode_location(char *name, cha
 	iconv_t cd;
 	int len, err;
 	size_t ibl, obl;
-	char *uri, *urip, *uri_utf8, *uri_utf8p, *ret;
+	char *uri, *uri_utf8, *uri_utf8p, *ret;
+	const char *urip;
 
 	err     = 0;
 	ret     = NULL;
@@ -1319,7 +1320,7 @@ vhd_macx_encode_location(char *name, cha
 	ibl     = len;
 	obl     = len;
 
-	uri = urip = malloc(ibl + 1);
+	urip = uri = malloc(ibl + 1);
 	uri_utf8 = uri_utf8p = malloc(obl);
 
 	if (!uri || !uri_utf8)
@@ -1333,7 +1334,11 @@ vhd_macx_encode_location(char *name, cha
 
 	snprintf(uri, ibl+1, "file://%s", name);
 
-	if (iconv(cd, &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
+	if (iconv(cd,
+#if defined(__linux__) || (__Linux__)
+	    (char **)
+#endif
+	    &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
 	    ibl || obl) {
 		err = (errno ? -errno : -EIO);
 		goto out;
@@ -1364,7 +1369,8 @@ vhd_w2u_encode_location(char *name, char
 	iconv_t cd;
 	int len, err;
 	size_t ibl, obl;
-	char *uri, *urip, *uri_utf16, *uri_utf16p, *tmp, *ret;
+	char *uri, *uri_utf16, *uri_utf16p, *tmp, *ret;
+	const char *urip;
 
 	err     = 0;
 	ret     = NULL;
@@ -1418,7 +1424,11 @@ vhd_w2u_encode_location(char *name, char
 		goto out;
 	}
 
-	if (iconv(cd, &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
+	if (iconv(cd,
+#if defined(__linux__) || (__Linux__)
+	    (char **)
+#endif
+	    &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
 	    ibl || obl) {
 		err = (errno ? -errno : -EIO);
 		goto out;
@@ -1459,7 +1469,11 @@ vhd_macx_decode_location(const char *in,
 	if (cd == (iconv_t)-1) 
 		return NULL;
 
-	if (iconv(cd, (char **)&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
+	if (iconv(cd,
+#if defined(__linux__) || defined(__Linux__)
+		(char **)
+#endif
+		&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
 		return NULL;
 
 	iconv_close(cd);
@@ -1487,7 +1501,11 @@ vhd_w2u_decode_location(const char *in, 
 	if (cd == (iconv_t)-1) 
 		return NULL;
 
-	if (iconv(cd, (char **)&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
+	if (iconv(cd,
+#if defined(__linux__) || defined(__Linux__)
+		(char **)
+#endif
+		&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
 		return NULL;
 
 	iconv_close(cd);
@@ -2435,7 +2453,7 @@ vhd_initialize_footer(vhd_context_t *ctx
 	ctx->footer.saved        = 0;
 	ctx->footer.data_offset  = 0xFFFFFFFFFFFFFFFF;
 	strcpy(ctx->footer.crtr_app, "tap");
-	uuid_generate(ctx->footer.uuid);
+	blk_uuid_generate(&ctx->footer.uuid);
 }
 
 static int
@@ -2479,7 +2497,11 @@ vhd_initialize_header_parent_name(vhd_co
 
 	memset(dst, 0, obl);
 
-	if (iconv(cd, (char **)&pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
+	if (iconv(cd,
+#if defined(__linux__) || defined(__Linux__)
+		(char **)
+#endif
+		&pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
 		err = (errno ? -errno : -EINVAL);
 
 out:
@@ -2546,7 +2568,7 @@ vhd_initialize_header(vhd_context_t *ctx
 			return err;
 
 		ctx->header.prt_ts = vhd_time(stats.st_mtime);
-		uuid_copy(ctx->header.prt_uuid, parent.footer.uuid);
+		blk_uuid_copy(&ctx->header.prt_uuid, &parent.footer.uuid);
 		if (!size)
 			size = parent.footer.curr_size;
 		vhd_close(&parent);
@@ -2628,7 +2650,7 @@ vhd_change_parent(vhd_context_t *child, 
 	}
 
 	if (raw) {
-		uuid_clear(child->header.prt_uuid);
+		blk_uuid_clear(&child->header.prt_uuid);
 	} else {
 		err = vhd_open(&parent, ppath, VHD_OPEN_RDONLY);
 		if (err) {
@@ -2636,7 +2658,7 @@ vhd_change_parent(vhd_context_t *child, 
 			       ppath, child->file, err);
 			goto out;
 		}
-		uuid_copy(child->header.prt_uuid, parent.footer.uuid);
+		blk_uuid_copy(&child->header.prt_uuid, &parent.footer.uuid);
 		vhd_close(&parent);
 	}
 
@@ -2695,7 +2717,7 @@ vhd_create_batmap(vhd_context_t *ctx)
 	header    = &ctx->batmap.header;
 
 	memset(header, 0, sizeof(vhd_batmap_header_t));
-	memcpy(header->cookie, VHD_BATMAP_COOKIE, sizeof(*header->cookie));
+	memcpy(header->cookie, VHD_BATMAP_COOKIE, sizeof(header->cookie));
 
 	err = vhd_batmap_header_offset(ctx, &off);
 	if (err)
diff -r b51f9542ab14 tools/blktap2/vhd/lib/uuid_linux.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/vhd/lib/uuid_linux.c	Wed Jun 24 12:57:16 2009 +0200
@@ -0,0 +1,43 @@
+#include "blk_uuid.h"
+
+int blk_uuid_is_nil(uuid_t *uuid)
+{
+#undef uuid_is_null
+	return uuid_is_null(*uuid);
+}
+
+void blk_uuid_generate(uuid_t *uuid)
+{
+#undef uuid_generate
+	uuid_generate(*uuid);
+}
+
+void blk_uuid_to_string(uuid_t *uuid, char **out)
+{
+#undef uuid_unparse
+	uuid_unparse(*uuid, *out);
+}
+
+void blk_uuid_from_string(uuid_t *uuid, const char *in)
+{
+#undef uuid_parse
+	uuid_parse(in, *uuid);
+}
+
+void blk_uuid_copy(uuid_t *dst, uuid_t *src)
+{
+#undef uuid_copy
+	uuid_copy(*dst, *src);
+}
+
+void blk_uuid_clear(uuid_t *uuid)
+{
+#undef uuid_clear
+	uuid_clear(*uuid);
+}
+
+int blk_uuid_compare(uuid_t *uuid1, uuid_t *uuid2)
+{
+#undef uuid_compare
+	return uuid_compare(*uuid1, *uuid2);
+}
diff -r b51f9542ab14 tools/blktap2/vhd/lib/uuid_netbsd.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/vhd/lib/uuid_netbsd.c	Wed Jun 24 12:57:16 2009 +0200
@@ -0,0 +1,43 @@
+#include <string.h>
+#include "blk_uuid.h"
+
+int blk_uuid_is_nil(uuid_t *uuid)
+{
+	uint32_t status;
+	return uuid_is_nil(uuid, &status);
+}
+
+void blk_uuid_generate(uuid_t *uuid)
+{
+	uint32_t status;
+	uuid_create(uuid, &status);
+}
+
+void blk_uuid_to_string(uuid_t *uuid, char **out)
+{
+	uint32_t status;
+	uuid_to_string(uuid, out, &status);
+}
+
+void blk_uuid_from_string(uuid_t *uuid, const char *in)
+{
+	uint32_t status;
+	uuid_from_string(in, uuid, &status);
+}
+
+void blk_uuid_copy(uuid_t *dst, uuid_t *src)
+{
+	memcpy(dst, src, sizeof(uuid_t));
+}
+
+void blk_uuid_clear(uuid_t *uuid)
+{
+	memset(uuid, 0, sizeof(uuid_t));
+}
+
+int blk_uuid_compare(uuid_t *uuid1, uuid_t *uuid2)
+{
+	uint32_t status;
+	return uuid_compare(uuid1, uuid2, &status);
+}
+
diff -r b51f9542ab14 tools/blktap2/vhd/lib/vhd-util-check.c
--- a/tools/blktap2/vhd/lib/vhd-util-check.c	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-check.c	Wed Jun 24 12:57:16 2009 +0200
@@ -218,7 +218,7 @@ vhd_util_check_validate_differencing_hea
 		if (vhd_util_check_zeros(header->loc, sizeof(header->loc)))
 			return "invalid non-null parent locators";
 
-		if (!uuid_is_null(header->prt_uuid))
+		if (!blk_uuid_is_nil(&header->prt_uuid))
 			return "invalid non-null parent uuid";
 
 		if (header->prt_ts)
@@ -320,7 +320,7 @@ vhd_util_check_validate_parent(vhd_conte
 				VHD_OPEN_RDONLY | VHD_OPEN_IGNORE_DISABLED))
 		return "error opening parent";
 
-	if (uuid_compare(vhd->header.prt_uuid, parent.footer.uuid)) {
+	if (blk_uuid_compare(&vhd->header.prt_uuid, &parent.footer.uuid)) {
 		msg = "invalid parent uuid";
 		goto out;
 	}
diff -r b51f9542ab14 tools/blktap2/vhd/lib/vhd-util-read.c
--- a/tools/blktap2/vhd/lib/vhd-util-read.c	Wed Jun 24 11:17:11 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-read.c	Wed Jun 24 12:57:16 2009 +0200
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
 	       (err ? "failed to read name" : name));
 	free(name);
 
-	uuid_unparse(h->prt_uuid, uuid);
+	blk_uuid_to_string(&h->prt_uuid, (char **)&uuid);
 	printf("Parent UUID         : %s\n", uuid);
     
 	vhd_time_to_string(h->prt_ts, time_str);
@@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int he
 	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
 		f->checksum == cksm ? "Good!" : "Bad!");
 
-	uuid_unparse(f->uuid, uuid);
+	blk_uuid_to_string(&f->uuid, (char **)&uuid);
 	printf("UUID                : %s\n", uuid);
 
 	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blktap2: portability fixes
  2009-06-24 12:24   ` Christoph Egger
@ 2009-06-24 13:07     ` Keir Fraser
  2009-06-24 13:57       ` Christoph Egger
  0 siblings, 1 reply; 5+ messages in thread
From: Keir Fraser @ 2009-06-24 13:07 UTC (permalink / raw)
  To: Christoph Egger; +Cc: xen-devel

I changed this some and applied as c/s 19832. Of particular note is that
your definition of blk_uuid_to_string() was very broken; all that could be
said of it is that it builds, but it was fundamentally broken for both Linux
and NetBSD. Note that uuid_to_string() itself allocates a string buffer and
returns a pointer to it -- so you need to copy that string to the buffer
passed to blk_uuid_to_string() and then free it. I didn't implement that bit
for you, so you need to provide a patch to fix NetBSD's
blk_uuid_to_string().

 -- Keir

On 24/06/2009 13:24, "Christoph Egger" <Christoph.Egger@amd.com> wrote:

> 
> Patch is attached.
> uuid is totally different in Linux and in NetBSD.
> uuid_t is a char array in Linux and a struct in NetBSD.
> Making NetBSD uuid look like Linux uuid doesn't work at all and
> neither the other way around.
> I renamed your uuid.h header to avoid a recursive inclusion
> of the same header.
> I created an uuid abstraction with a Linux and NetBSD implementation.
> 
> I also fixed a bug in vhd_create_batmap() which slipped in previously.
> iconv() is a bit nasty to make it compile on both NetBSD and Linux.
> 
> Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
> 
> 
> On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote:
>> This didn't have a prayer of building on Linux. I fixed it up for Linux and
>> applied as c/s 19817. It's probably broken for netbsd now, but you should
>> be able to provide a small fixup patch for that.
>> 
>>  -- Keir
>> 
>> On 23/06/2009 13:29, "Christoph Egger" <Christoph.Egger@amd.com> wrote:
>>> Hi!
>>> 
>>> Attached patch makes blktap2 build on 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>
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blktap2: portability fixes
  2009-06-24 13:07     ` Keir Fraser
@ 2009-06-24 13:57       ` Christoph Egger
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Egger @ 2009-06-24 13:57 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel

[-- Attachment #1: Type: text/plain, Size: 2668 bytes --]


Oh, indeed! It's always good to have a second pair of eyes over it.
Attached patch implements blk_uuid_to_string() for NetBSD correctly.
I hope, this is the last iteration over blktap2.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>


On Wednesday 24 June 2009 15:07:50 Keir Fraser wrote:
> I changed this some and applied as c/s 19832. Of particular note is that
> your definition of blk_uuid_to_string() was very broken; all that could be
> said of it is that it builds, but it was fundamentally broken for both
> Linux and NetBSD. Note that uuid_to_string() itself allocates a string
> buffer and returns a pointer to it -- so you need to copy that string to
> the buffer passed to blk_uuid_to_string() and then free it. I didn't
> implement that bit for you, so you need to provide a patch to fix NetBSD's
> blk_uuid_to_string().
>
>  -- Keir
>
> On 24/06/2009 13:24, "Christoph Egger" <Christoph.Egger@amd.com> wrote:
> > Patch is attached.
> > uuid is totally different in Linux and in NetBSD.
> > uuid_t is a char array in Linux and a struct in NetBSD.
> > Making NetBSD uuid look like Linux uuid doesn't work at all and
> > neither the other way around.
> > I renamed your uuid.h header to avoid a recursive inclusion
> > of the same header.
> > I created an uuid abstraction with a Linux and NetBSD implementation.
> >
> > I also fixed a bug in vhd_create_batmap() which slipped in previously.
> > iconv() is a bit nasty to make it compile on both NetBSD and Linux.
> >
> > Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
> >
> > On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote:
> >> This didn't have a prayer of building on Linux. I fixed it up for Linux
> >> and applied as c/s 19817. It's probably broken for netbsd now, but you
> >> should be able to provide a small fixup patch for that.
> >>
> >>  -- Keir
> >>
> >> On 23/06/2009 13:29, "Christoph Egger" <Christoph.Egger@amd.com> wrote:
> >>> Hi!
> >>>
> >>> Attached patch makes blktap2 build on 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>



-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

[-- Attachment #2: xen_blktap2.diff --]
[-- Type: text/x-diff, Size: 2782 bytes --]

diff -r f1fec38c8228 tools/blktap2/include/blk_uuid.h
--- a/tools/blktap2/include/blk_uuid.h	Wed Jun 24 14:03:20 2009 +0100
+++ b/tools/blktap2/include/blk_uuid.h	Wed Jun 24 15:45:27 2009 +0200
@@ -45,7 +45,7 @@ static inline void blk_uuid_generate(blk
 	uuid_generate(uuid->uuid);
 }
 
-static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
+static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
 {
 	uuid_unparse(uuid->uuid, out);
 }
@@ -74,6 +74,7 @@ static inline int blk_uuid_compare(blk_u
 
 #include <uuid.h>
 #include <string.h>
+#include <stdlib.h>
 
 typedef uuid_t blk_uuid_t;
 
@@ -89,10 +90,13 @@ static inline void blk_uuid_generate(blk
 	uuid_create((uuid_t *)uuid, &status);
 }
 
-static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
+static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
 {
 	uint32_t status;
-	uuid_to_string((uuid_t *)uuid, &out, &status);
+	char *_out = NULL;
+	uuid_to_string((uuid_t *)uuid, &_out, &status);
+	strlcpy(out, _out, size);
+	free(_out);
 }
 
 static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
diff -r f1fec38c8228 tools/blktap2/vhd/lib/libvhd.c
--- a/tools/blktap2/vhd/lib/libvhd.c	Wed Jun 24 14:03:20 2009 +0100
+++ b/tools/blktap2/vhd/lib/libvhd.c	Wed Jun 24 15:45:27 2009 +0200
@@ -1335,7 +1335,7 @@ vhd_macx_encode_location(char *name, cha
 	snprintf(uri, ibl+1, "file://%s", name);
 
 	if (iconv(cd,
-#if defined(__linux__) || (__Linux__)
+#if defined(__linux__) || defined(__Linux__)
 	    (char **)
 #endif
 	    &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
@@ -1425,7 +1425,7 @@ vhd_w2u_encode_location(char *name, char
 	}
 
 	if (iconv(cd,
-#if defined(__linux__) || (__Linux__)
+#if defined(__linux__) || defined(__Linux__)
 	    (char **)
 #endif
 	    &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
diff -r f1fec38c8228 tools/blktap2/vhd/lib/vhd-util-read.c
--- a/tools/blktap2/vhd/lib/vhd-util-read.c	Wed Jun 24 14:03:20 2009 +0100
+++ b/tools/blktap2/vhd/lib/vhd-util-read.c	Wed Jun 24 15:45:27 2009 +0200
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
 	       (err ? "failed to read name" : name));
 	free(name);
 
-	blk_uuid_to_string(&h->prt_uuid, uuid);
+	blk_uuid_to_string(&h->prt_uuid, uuid, sizeof(uuid));
 	printf("Parent UUID         : %s\n", uuid);
     
 	vhd_time_to_string(h->prt_ts, time_str);
@@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int he
 	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
 		f->checksum == cksm ? "Good!" : "Bad!");
 
-	blk_uuid_to_string(&f->uuid, uuid);
+	blk_uuid_to_string(&f->uuid, uuid, sizeof(uuid));
 	printf("UUID                : %s\n", uuid);
 
 	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-06-24 13:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-23 12:29 [PATCH] blktap2: portability fixes Christoph Egger
2009-06-23 16:25 ` Keir Fraser
2009-06-24 12:24   ` Christoph Egger
2009-06-24 13:07     ` Keir Fraser
2009-06-24 13:57       ` Christoph Egger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.