WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] blktap2: portability fixes for NetBSD

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] blktap2: portability fixes for NetBSD
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Jun 2009 09:30:16 -0700
Delivery-date: Tue, 23 Jun 2009 09:30:49 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1245774254 -3600
# Node ID b7f73a7f30789c83b6f41c2bf4e485aeb5c09bfa
# Parent  5f5112a7d2ffd203c062b3846bbce31912f499b2
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@xxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 tools/Makefile                             |    3 
 tools/blktap2/drivers/Makefile             |   19 +++
 tools/blktap2/drivers/blk.h                |    6 +
 tools/blktap2/drivers/blk_netbsd.c         |   41 ++++++++
 tools/blktap2/drivers/block-aio.c          |   21 ----
 tools/blktap2/drivers/block-log.c          |    2 
 tools/blktap2/drivers/block-qcow.c         |    5 -
 tools/blktap2/drivers/block-ram.c          |   19 ---
 tools/blktap2/drivers/block-vhd.c          |   13 +-
 tools/blktap2/drivers/tapdisk-client.c     |    2 
 tools/blktap2/drivers/tapdisk-diff.c       |    1 
 tools/blktap2/drivers/tapdisk-filter.c     |    7 -
 tools/blktap2/drivers/tapdisk-log.c        |   11 +-
 tools/blktap2/drivers/tapdisk-queue.c      |    2 
 tools/blktap2/drivers/tapdisk-utils.c      |   22 ----
 tools/blktap2/drivers/tapdisk-vbd.c        |    9 +
 tools/blktap2/drivers/tapdisk.h            |    2 
 tools/blktap2/include/libvhd.h             |   46 ++++++---
 tools/blktap2/include/list.h               |   11 ++
 tools/blktap2/include/uuid.h               |   73 ++++++++++++++
 tools/blktap2/include/vhd.h                |    3 
 tools/blktap2/vhd/Makefile                 |    2 
 tools/blktap2/vhd/lib/Makefile             |    2 
 tools/blktap2/vhd/lib/libvhd-journal.c     |   54 +++++-----
 tools/blktap2/vhd/lib/libvhd.c             |  143 ++++++++++++++---------------
 tools/blktap2/vhd/lib/vhd-util-check.c     |   50 +++++-----
 tools/blktap2/vhd/lib/vhd-util-coalesce.c  |    6 -
 tools/blktap2/vhd/lib/vhd-util-modify.c    |    2 
 tools/blktap2/vhd/lib/vhd-util-query.c     |    2 
 tools/blktap2/vhd/lib/vhd-util-read.c      |    8 -
 tools/blktap2/vhd/lib/vhd-util-repair.c    |    2 
 tools/blktap2/vhd/lib/vhd-util-resize.c    |   30 +++---
 tools/blktap2/vhd/lib/vhd-util-scan.c      |    3 
 tools/blktap2/vhd/lib/vhd-util-set-field.c |    2 
 tools/blktap2/vhd/vhd-update.c             |    2 
 tools/check/check_uuid_devel               |    1 
 36 files changed, 380 insertions(+), 247 deletions(-)

diff -r 5f5112a7d2ff -r b7f73a7f3078 tools/Makefile
--- a/tools/Makefile    Tue Jun 23 11:27:54 2009 +0100
+++ b/tools/Makefile    Tue Jun 23 17:24:14 2009 +0100
@@ -23,9 +23,12 @@ SUBDIRS-$(CONFIG_Linux) += libaio
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 @@ CRYPT_LIB += -lcrypto
 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
@@ -43,6 +51,10 @@ ifeq ($(VHD_STATIC),y)
 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
@@ -57,7 +69,7 @@ TAP-OBJS-y  += tapdisk-utils.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-log.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-stream tapdisk-diff: %: %.o $(TA
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -26,5 +26,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <inttypes.h>
+
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 @@ vhd_kill_footer(struct vhd_state *s)
 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 @@ find_next_free_block(struct vhd_state *s
 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 @@ vhd_validate_parent(td_driver_t *child_d
 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;
diff -r 5f5112a7d2ff -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -28,19 +28,37 @@
 #define _VHD_LIB_H_
 
 #include <string.h>
+#if defined(__linux__) || defined(__Linux__)
 #include <endian.h>
 #include <byteswap.h>
-#include <uuid/uuid.h>
-
+#elif defined(__NetBSD__)
+#include <sys/endian.h>
+#include <sys/bswap.h>
+#endif
+
+#include "uuid.h"
 #include "vhd.h"
 
+#ifndef O_LARGEFILE
+#define O_LARGEFILE    0
+#endif
+
 #if BYTE_ORDER == LITTLE_ENDIAN
+#if defined(__linux__) || defined(__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))
+#elif defined(__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)
@@ -239,16 +257,16 @@ int vhd_hidden(vhd_context_t *, int *);
 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 +283,8 @@ void vhd_batmap_set(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 +295,26 @@ int vhd_parent_locator_read(vhd_context_
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 tools/blktap2/include/uuid.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/include/uuid.h      Tue Jun 23 17:24:14 2009 +0100
@@ -0,0 +1,73 @@
+/* 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 5f5112a7d2ff -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -27,9 +27,8 @@
 #ifndef __VHD_H__
 #define __VHD_H__
 
-#include <asm/types.h>
-#include <uuid/uuid.h>
 #include <inttypes.h>
+#include "uuid.h"
 
 typedef uint32_t u32;
 typedef uint64_t u64;
diff -r 5f5112a7d2ff -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -22,7 +22,9 @@ endif
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -19,7 +19,9 @@ CFLAGS          += -fPIC
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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)
-{
-       off64_t off;
-
-       off = lseek64(j->jfd, offset, whence);
-       if (off == (off64_t)-1)
+vhd_journal_seek(vhd_journal_t *j, off_t offset, int whence)
+{
+       off_t off;
+
+       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 @@ vhd_journal_validate_header(vhd_journal_
 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 @@ vhd_journal_add_journal_header(vhd_journ
 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,7 +230,7 @@ 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);
@@ -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 @@ vhd_journal_add_footer(vhd_journal_t *j)
 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 @@ vhd_journal_add_header(vhd_journal_t *j)
 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 @@ vhd_journal_add_bat(vhd_journal_t *j)
 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 @@ vhd_journal_add_batmap(vhd_journal_t *j)
 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 @@ vhd_journal_add_metadata(vhd_journal_t *
 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 @@ static int
 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 @@ static int
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -250,8 +250,8 @@ 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';
+               strncpy(buf, footer->cookie, sizeof(buf));
+               buf[sizeof(buf)-1]= '\0';
                VHDLOG("invalid footer cookie: %s\n", buf);
                return -EINVAL;
        }
@@ -311,8 +311,8 @@ 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';
+               strncpy(buf, header->cookie, sizeof(buf));
+               buf[sizeof(buf)-1]= '\0';
                VHDLOG("invalid header cookie: %s\n", buf);
                return -EINVAL;
        }
@@ -403,9 +403,9 @@ vhd_validate_batmap(vhd_batmap_t *batmap
 }
 
 int
-vhd_batmap_header_offset(vhd_context_t *ctx, off64_t *_off)
-{
-       off64_t off;
+vhd_batmap_header_offset(vhd_context_t *ctx, off_t *_off)
+{
+       off_t off;
        size_t  bat;
 
        *_off = 0;
@@ -592,11 +592,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 +612,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 +636,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 +651,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 +663,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 +871,7 @@ vhd_read_short_footer(vhd_context_t *ctx
 {
        int err;
        char *buf;
-       off64_t eof;
+       off_t eof;
 
        buf = NULL;
 
@@ -880,7 +880,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 +918,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 +958,14 @@ vhd_read_footer(vhd_context_t *ctx, vhd_
 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 +983,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 +1028,7 @@ vhd_read_header(vhd_context_t *ctx, vhd_
 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 +1044,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 +1092,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 +1137,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,7 +1331,7 @@ 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 ||
            ibl || obl) {
@@ -1446,7 +1446,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;
@@ -1459,7 +1459,7 @@ vhd_macx_decode_location(char *in, char 
        if (cd == (iconv_t)-1) 
                return NULL;
 
-       if (iconv(cd, &in, &ibl, &out, &obl) == (size_t)-1 || ibl)
+       if (iconv(cd, (char **)&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
                return NULL;
 
        iconv_close(cd);
@@ -1474,7 +1474,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;
@@ -1487,7 +1487,7 @@ vhd_w2u_decode_location(char *in, char *
        if (cd == (iconv_t)-1) 
                return NULL;
 
-       if (iconv(cd, &in, &ibl, &out, &obl) == (size_t)-1 || ibl)
+       if (iconv(cd, (char **)&in, &ibl, &out, &obl) == (size_t)-1 || ibl)
                return NULL;
 
        iconv_close(cd);
@@ -1646,7 +1646,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 +1762,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 +1777,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 +1827,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 +1881,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 +1923,7 @@ vhd_write_footer(vhd_context_t *ctx, vhd
 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 +1943,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 +1990,7 @@ vhd_write_header(vhd_context_t *ctx, vhd
 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 +2003,7 @@ vhd_write_bat(vhd_context_t *ctx, vhd_ba
 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 +2046,7 @@ vhd_write_batmap(vhd_context_t *ctx, vhd
 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 +2122,7 @@ vhd_write_bitmap(vhd_context_t *ctx, uin
 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 +2161,7 @@ vhd_write_block(vhd_context_t *ctx, uint
 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 +2212,12 @@ namedup(char **dup, const char *name)
 }
 
 int
-vhd_seek(vhd_context_t *ctx, off64_t offset, int whence)
-{
-       off64_t off;
-
-       off = lseek64(ctx->fd, offset, whence);
-       if (off == (off64_t)-1) {
+vhd_seek(vhd_context_t *ctx, off_t offset, int whence)
+{
+       off_t off;
+
+       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 +2226,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
@@ -2444,7 +2444,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;
@@ -2478,7 +2479,7 @@ vhd_initialize_header_parent_name(vhd_co
 
        memset(dst, 0, obl);
 
-       if (iconv(cd, &pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
+       if (iconv(cd, (char **)&pname, &ibl, &dst, &obl) == (size_t)-1 || ibl)
                err = (errno ? -errno : -EINVAL);
 
 out:
@@ -2487,18 +2488,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;
 }
@@ -2563,7 +2564,7 @@ vhd_write_parent_locators(vhd_context_t 
 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;
@@ -2683,7 +2684,7 @@ static int
 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 +2695,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 +2764,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 +2782,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 +2793,9 @@ vhd_get_phys_size(vhd_context_t *ctx, of
 }
 
 int 
-vhd_set_phys_size(vhd_context_t *ctx, off64_t size)
-{
-       off64_t phys_size;
+vhd_set_phys_size(vhd_context_t *ctx, off_t size)
+{
+       off_t phys_size;
        int err;
 
        err = vhd_get_phys_size(ctx, &phys_size);
@@ -2815,7 +2816,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 +2902,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 +2977,7 @@ __vhd_io_dynamic_read_link(vhd_context_t
 __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 +3033,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 +3045,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 +3179,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 +3203,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 +3228,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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -146,7 +146,7 @@ static char *
 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  ||
@@ -232,7 +232,7 @@ vhd_util_check_validate_batmap(vhd_conte
 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 +249,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 +269,7 @@ vhd_util_check_validate_parent_locator(v
 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 +290,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 +304,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;
 
@@ -335,7 +336,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 +350,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 +392,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 +455,7 @@ vhd_util_check_header(int fd, vhd_footer
 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 +466,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 +514,7 @@ static int
 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 +524,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 +646,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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -35,12 +35,12 @@ static int
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -59,11 +59,11 @@ vhd_print_header(vhd_context_t *vhd, vhd
 {
        int err;
        uint32_t  cksm;
-       char      uuid[37], time_str[26], cookie[9], out[512], *name;
+       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));
@@ -95,11 +95,11 @@ 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];
 
        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,
diff -r 5f5112a7d2ff -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 @@ vhd_clobber_block(vhd_journal_t *journal
 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 @@ static int
 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 @@ vhd_add_bat_entries(vhd_journal_t *journ
 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 @@ vhd_dynamic_grow(vhd_journal_t *journal,
 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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 
2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -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 -r b7f73a7f3078 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 17:24:14 2009 +0100
@@ -3,4 +3,5 @@
 
 . ./funcs.sh
 
+has_header uuid.h || \
 has_header uuid/uuid.h || fail "missing uuid headers (package uuid-dev)"

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] blktap2: portability fixes for NetBSD, Xen patchbot-unstable <=