aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap2
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2009-06-23 17:24:14 +0100
committerKeir Fraser <keir.fraser@citrix.com>2009-06-23 17:24:14 +0100
commit2b8ba91b50c9536daac1ee64f4ef6737d03d349d (patch)
tree770ff8eb7600536bfd76015338e87f9349f3f055 /tools/blktap2
parenta114a32c90fb4a3d249de760869cd57d750dff90 (diff)
downloadxen-2b8ba91b50c9536daac1ee64f4ef6737d03d349d.tar.gz
xen-2b8ba91b50c9536daac1ee64f4ef6737d03d349d.tar.bz2
xen-2b8ba91b50c9536daac1ee64f4ef6737d03d349d.zip
blktap2: portability fixes for NetBSD
- Use standard off_t and lseek() instead of non-portable off64_t and lseek64() - Use uuid API as documented in DCE 1.1 RPC specification - Add NetBSD implementation for blk_getimagesize() and blk_getsectorsize() - Use blk_getimagesize() and blk_getsectorsize() - Fix uuid header check Signed-off-by: Christoph Egger <Christoph.Egger@amd.com> Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Diffstat (limited to 'tools/blktap2')
-rw-r--r--tools/blktap2/drivers/Makefile19
-rw-r--r--tools/blktap2/drivers/blk.h6
-rw-r--r--tools/blktap2/drivers/blk_netbsd.c41
-rw-r--r--tools/blktap2/drivers/block-aio.c19
-rw-r--r--tools/blktap2/drivers/block-log.c2
-rw-r--r--tools/blktap2/drivers/block-qcow.c5
-rw-r--r--tools/blktap2/drivers/block-ram.c19
-rw-r--r--tools/blktap2/drivers/block-vhd.c13
-rw-r--r--tools/blktap2/drivers/tapdisk-client.c2
-rw-r--r--tools/blktap2/drivers/tapdisk-diff.c1
-rw-r--r--tools/blktap2/drivers/tapdisk-filter.c7
-rw-r--r--tools/blktap2/drivers/tapdisk-log.c11
-rw-r--r--tools/blktap2/drivers/tapdisk-queue.c2
-rw-r--r--tools/blktap2/drivers/tapdisk-utils.c22
-rw-r--r--tools/blktap2/drivers/tapdisk-vbd.c9
-rw-r--r--tools/blktap2/drivers/tapdisk.h2
-rw-r--r--tools/blktap2/include/libvhd.h44
-rw-r--r--tools/blktap2/include/list.h11
-rw-r--r--tools/blktap2/include/uuid.h73
-rw-r--r--tools/blktap2/include/vhd.h3
-rw-r--r--tools/blktap2/vhd/Makefile2
-rw-r--r--tools/blktap2/vhd/lib/Makefile2
-rw-r--r--tools/blktap2/vhd/lib/libvhd-journal.c50
-rw-r--r--tools/blktap2/vhd/lib/libvhd.c135
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-check.c50
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-coalesce.c6
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-modify.c2
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-query.c2
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-read.c8
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-repair.c2
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-resize.c30
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-scan.c3
-rw-r--r--tools/blktap2/vhd/lib/vhd-util-set-field.c2
-rw-r--r--tools/blktap2/vhd/vhd-update.c2
34 files changed, 368 insertions, 239 deletions
diff --git a/tools/blktap2/drivers/Makefile b/tools/blktap2/drivers/Makefile
index d011080374..c3cb722771 100644
--- a/tools/blktap2/drivers/Makefile
+++ b/tools/blktap2/drivers/Makefile
@@ -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 --git a/tools/blktap2/drivers/blk.h b/tools/blktap2/drivers/blk.h
index 73ca40c629..394ae49640 100644
--- a/tools/blktap2/drivers/blk.h
+++ b/tools/blktap2/drivers/blk.h
@@ -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 --git a/tools/blktap2/drivers/blk_netbsd.c b/tools/blktap2/drivers/blk_netbsd.c
new file mode 100644
index 0000000000..f394fdf008
--- /dev/null
+++ b/tools/blktap2/drivers/blk_netbsd.c
@@ -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 --git a/tools/blktap2/drivers/block-aio.c b/tools/blktap2/drivers/block-aio.c
index 2c5af1483c..c8d36e0472 100644
--- a/tools/blktap2/drivers/block-aio.c
+++ b/tools/blktap2/drivers/block-aio.c
@@ -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, td_disk_info_t *info)
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, td_disk_info_t *info)
(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 --git a/tools/blktap2/drivers/block-log.c b/tools/blktap2/drivers/block-log.c
index 2cc051b7d2..c9612a4b9b 100644
--- a/tools/blktap2/drivers/block-log.c
+++ b/tools/blktap2/drivers/block-log.c
@@ -314,7 +314,7 @@ static int ctl_open(struct tdlog_state* s, const char* name)
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 --git a/tools/blktap2/drivers/block-qcow.c b/tools/blktap2/drivers/block-qcow.c
index f2d989123a..e0590ae59b 100644
--- a/tools/blktap2/drivers/block-qcow.c
+++ b/tools/blktap2/drivers/block-qcow.c
@@ -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, const char *name, td_flag_t flags)
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 --git a/tools/blktap2/drivers/block-ram.c b/tools/blktap2/drivers/block-ram.c
index 16b4ec9dc7..fdf6ace25c 100644
--- a/tools/blktap2/drivers/block-ram.c
+++ b/tools/blktap2/drivers/block-ram.c
@@ -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_disk_info_t *info)
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_disk_info_t *info)
(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 --git a/tools/blktap2/drivers/block-vhd.c b/tools/blktap2/drivers/block-vhd.c
index 54431c12d8..4dd28ca92c 100644
--- a/tools/blktap2/drivers/block-vhd.c
+++ b/tools/blktap2/drivers/block-vhd.c
@@ -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;
diff --git a/tools/blktap2/drivers/tapdisk-client.c b/tools/blktap2/drivers/tapdisk-client.c
index c85b5fc530..c9bda859be 100644
--- a/tools/blktap2/drivers/tapdisk-client.c
+++ b/tools/blktap2/drivers/tapdisk-client.c
@@ -109,7 +109,7 @@ static int tdctl_open(const char* sockpath)
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 --git a/tools/blktap2/drivers/tapdisk-diff.c b/tools/blktap2/drivers/tapdisk-diff.c
index 0f31c57d42..0a36c430d4 100644
--- a/tools/blktap2/drivers/tapdisk-diff.c
+++ b/tools/blktap2/drivers/tapdisk-diff.c
@@ -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 --git a/tools/blktap2/drivers/tapdisk-filter.c b/tools/blktap2/drivers/tapdisk-filter.c
index fc018eadbd..dcd18023f2 100644
--- a/tools/blktap2/drivers/tapdisk-filter.c
+++ b/tools/blktap2/drivers/tapdisk-filter.c
@@ -113,10 +113,11 @@ check_hash(struct tfilter *filter, uint64_t sec, char *buf, char *type)
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 --git a/tools/blktap2/drivers/tapdisk-log.c b/tools/blktap2/drivers/tapdisk-log.c
index 980affa3a2..1220bf927e 100644
--- a/tools/blktap2/drivers/tapdisk-log.c
+++ b/tools/blktap2/drivers/tapdisk-log.c
@@ -126,8 +126,9 @@ __tlog_write(int level, const char *func, const char *fmt, ...)
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, const char *fmt, ...)
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 --git a/tools/blktap2/drivers/tapdisk-queue.c b/tools/blktap2/drivers/tapdisk-queue.c
index 5461d415e0..bc344f67d3 100644
--- a/tools/blktap2/drivers/tapdisk-queue.c
+++ b/tools/blktap2/drivers/tapdisk-queue.c
@@ -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 --git a/tools/blktap2/drivers/tapdisk-utils.c b/tools/blktap2/drivers/tapdisk-utils.c
index 560f3bf6cc..4304ecf0f2 100644
--- a/tools/blktap2/drivers/tapdisk-utils.c
+++ b/tools/blktap2/drivers/tapdisk-utils.c
@@ -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 *_sectors, uint32_t *_sector_size)
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 *_sectors, uint32_t *_sector_size)
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 --git a/tools/blktap2/drivers/tapdisk-vbd.c b/tools/blktap2/drivers/tapdisk-vbd.c
index 1eaaee9634..5e817116fa 100644
--- a/tools/blktap2/drivers/tapdisk-vbd.c
+++ b/tools/blktap2/drivers/tapdisk-vbd.c
@@ -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 --git a/tools/blktap2/drivers/tapdisk.h b/tools/blktap2/drivers/tapdisk.h
index 1147ab3580..b1a91c77f2 100644
--- a/tools/blktap2/drivers/tapdisk.h
+++ b/tools/blktap2/drivers/tapdisk.h
@@ -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 --git a/tools/blktap2/include/libvhd.h b/tools/blktap2/include/libvhd.h
index b128ebaf38..6d5979b1d7 100644
--- a/tools/blktap2/include/libvhd.h
+++ b/tools/blktap2/include/libvhd.h
@@ -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_snapshot(const char *snapshot, uint64_t bytes, const char *parent,
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 @@ int vhd_batmap_test(vhd_context_t *, vhd_batmap_t *, uint32_t);
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_get(vhd_context_t *, char **);
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 --git a/tools/blktap2/include/list.h b/tools/blktap2/include/list.h
index 03a524be01..3efc376584 100644
--- a/tools/blktap2/include/list.h
+++ b/tools/blktap2/include/list.h
@@ -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 --git a/tools/blktap2/include/uuid.h b/tools/blktap2/include/uuid.h
new file mode 100644
index 0000000000..e80832474c
--- /dev/null
+++ b/tools/blktap2/include/uuid.h
@@ -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 --git a/tools/blktap2/include/vhd.h b/tools/blktap2/include/vhd.h
index 4da5f86668..25b8b29e01 100644
--- a/tools/blktap2/include/vhd.h
+++ b/tools/blktap2/include/vhd.h
@@ -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 --git a/tools/blktap2/vhd/Makefile b/tools/blktap2/vhd/Makefile
index d456d7d7a5..aa8257a1a1 100644
--- a/tools/blktap2/vhd/Makefile
+++ b/tools/blktap2/vhd/Makefile
@@ -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 --git a/tools/blktap2/vhd/lib/Makefile b/tools/blktap2/vhd/lib/Makefile
index c768a1ac4d..60e1217849 100644
--- a/tools/blktap2/vhd/lib/Makefile
+++ b/tools/blktap2/vhd/lib/Makefile
@@ -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 --git a/tools/blktap2/vhd/lib/libvhd-journal.c b/tools/blktap2/vhd/lib/libvhd-journal.c
index c52affea1a..4112c9d6af 100644
--- a/tools/blktap2/vhd/lib/libvhd-journal.c
+++ b/tools/blktap2/vhd/lib/libvhd-journal.c
@@ -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 *buf, size_t size)
}
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_t *j, vhd_journal_header_t *header)
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,7 +230,7 @@ vhd_journal_add_journal_header(vhd_journal_t *j)
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_journal_entry_t *entry, char *buf)
}
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 *j)
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_journal_t *j, vhd_footer_t *footer)
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 *j, vhd_batmap_t *batmap)
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_t *j)
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, const char *file, const char *jfile)
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, uint32_t block, char mode)
{
int err;
char *buf;
- off64_t off;
+ off_t off;
size_t size;
uint64_t blk;
vhd_context_t *vhd;
diff --git a/tools/blktap2/vhd/lib/libvhd.c b/tools/blktap2/vhd/lib/libvhd.c
index 1af30ad1f6..add9365f42 100644
--- a/tools/blktap2/vhd/lib/libvhd.c
+++ b/tools/blktap2/vhd/lib/libvhd.c
@@ -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)
+vhd_batmap_header_offset(vhd_context_t *ctx, off_t *_off)
{
- off64_t off;
+ off_t off;
size_t bat;
*_off = 0;
@@ -592,11 +592,11 @@ vhd_bitmap_clear(vhd_context_t *ctx, char *map, uint32_t block)
* 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, off64_t *end)
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, off64_t *end)
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, off64_t *end)
}
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, off64_t *end)
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, vhd_footer_t *footer)
{
int err;
char *buf;
- off64_t eof;
+ off_t eof;
buf = NULL;
@@ -880,7 +880,7 @@ vhd_read_short_footer(vhd_context_t *ctx, vhd_footer_t *footer)
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 @@ 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 +983,7 @@ vhd_read_footer(vhd_context_t *ctx, vhd_footer_t *footer)
}
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 @@ 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 +1044,7 @@ vhd_read_bat(vhd_context_t *ctx, vhd_bat_t *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 *ctx, vhd_batmap_t *batmap)
{
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, vhd_batmap_t *batmap)
{
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, char **out, int *outlen)
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 **out, int *outlen)
}
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 *out, int len)
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 *out, int len)
}
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 *out, int len, char *utf_type)
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 *ctx, char **parent)
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, uint32_t block, char **bufp)
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, uint32_t block, char **bufp)
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 @@ 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 +1943,7 @@ vhd_write_footer(vhd_context_t *ctx, vhd_footer_t *footer)
}
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 @@ 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 +2003,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 +2046,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 +2122,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 +2161,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 +2212,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 +2226,10 @@ vhd_seek(vhd_context_t *ctx, off64_t offset, int whence)
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_context_t *ctx, const char *parent_path)
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_context_t *ctx, const char *parent_path)
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 @@ 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;
@@ -2683,7 +2684,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 +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 *ctx)
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, off64_t *size)
}
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 +2816,7 @@ __vhd_create(const char *name, const char *parent, uint64_t bytes, int type,
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 char *parent, uint64_t bytes, int type,
goto out;
off = vhd_position(&ctx);
- if (off == (off64_t)-1) {
+ if (off == (off_t)-1) {
err = -errno;
goto out;
}
@@ -2976,7 +2977,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 +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 *ctx, uint32_t block)
{
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 *ctx, uint32_t block)
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 *ctx,
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 --git a/tools/blktap2/vhd/lib/vhd-util-check.c b/tools/blktap2/vhd/lib/vhd-util-check.c
index d7d588088a..9dbd9e1941 100644
--- a/tools/blktap2/vhd/lib/vhd-util-check.c
+++ b/tools/blktap2/vhd/lib/vhd-util-check.c
@@ -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, vhd_header_t *header)
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 @@ 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 +249,8 @@ vhd_util_check_validate_batmap(vhd_context_t *vhd, vhd_batmap_t *batmap)
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 @@ 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 +290,8 @@ vhd_util_check_validate_parent_locator(vhd_context_t *vhd,
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(vhd_context_t *vhd,
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_t *footer, int ignore)
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_t *footer, int ignore)
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_t *footer, int ignore)
}
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 @@ 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 +466,8 @@ vhd_util_check_header(int fd, vhd_footer_t *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 @@ vhd_util_check_differencing_header(vhd_context_t *vhd)
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_context_t *vhd)
{
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 --git a/tools/blktap2/vhd/lib/vhd-util-coalesce.c b/tools/blktap2/vhd/lib/vhd-util-coalesce.c
index f6461fc687..63dcf6010e 100644
--- a/tools/blktap2/vhd/lib/vhd-util-coalesce.c
+++ b/tools/blktap2/vhd/lib/vhd-util-coalesce.c
@@ -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 --git a/tools/blktap2/vhd/lib/vhd-util-modify.c b/tools/blktap2/vhd/lib/vhd-util-modify.c
index 3b07e31b25..b563d6a6d3 100644
--- a/tools/blktap2/vhd/lib/vhd-util-modify.c
+++ b/tools/blktap2/vhd/lib/vhd-util-modify.c
@@ -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 --git a/tools/blktap2/vhd/lib/vhd-util-query.c b/tools/blktap2/vhd/lib/vhd-util-query.c
index 3477a17f27..44a22d0335 100644
--- a/tools/blktap2/vhd/lib/vhd-util-query.c
+++ b/tools/blktap2/vhd/lib/vhd-util-query.c
@@ -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 --git a/tools/blktap2/vhd/lib/vhd-util-read.c b/tools/blktap2/vhd/lib/vhd-util-read.c
index 7b5246c5f7..a462fdc4df 100644
--- a/tools/blktap2/vhd/lib/vhd-util-read.c
+++ b/tools/blktap2/vhd/lib/vhd-util-read.c
@@ -59,11 +59,11 @@ 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;
+ 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 hex)
{
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 --git a/tools/blktap2/vhd/lib/vhd-util-repair.c b/tools/blktap2/vhd/lib/vhd-util-repair.c
index a1d2c45c12..14ded81c29 100644
--- a/tools/blktap2/vhd/lib/vhd-util-repair.c
+++ b/tools/blktap2/vhd/lib/vhd-util-repair.c
@@ -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 --git a/tools/blktap2/vhd/lib/vhd-util-resize.c b/tools/blktap2/vhd/lib/vhd-util-resize.c
index 0143d7a0d3..c8a9528530 100644
--- a/tools/blktap2/vhd/lib/vhd-util-resize.c
+++ b/tools/blktap2/vhd/lib/vhd-util-resize.c
@@ -95,7 +95,7 @@ vhd_fixed_shrink(vhd_journal_t *journal, uint64_t secs)
}
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, off64_t off, uint64_t size)
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, uint64_t secs)
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, int right)
}
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 *journal, uint32_t entries)
{
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 *journal, uint32_t entries)
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 *journal, off64_t eob,
}
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, uint64_t secs)
* 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 --git a/tools/blktap2/vhd/lib/vhd-util-scan.c b/tools/blktap2/vhd/lib/vhd-util-scan.c
index 4ecfb52e7d..8fa9376ec7 100644
--- a/tools/blktap2/vhd/lib/vhd-util-scan.c
+++ b/tools/blktap2/vhd/lib/vhd-util-scan.c
@@ -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 --git a/tools/blktap2/vhd/lib/vhd-util-set-field.c b/tools/blktap2/vhd/lib/vhd-util-set-field.c
index ac185735d9..32728abf8a 100644
--- a/tools/blktap2/vhd/lib/vhd-util-set-field.c
+++ b/tools/blktap2/vhd/lib/vhd-util-set-field.c
@@ -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 --git a/tools/blktap2/vhd/vhd-update.c b/tools/blktap2/vhd/vhd-update.c
index fbc23cc7ae..4621a81e20 100644
--- a/tools/blktap2/vhd/vhd-update.c
+++ b/tools/blktap2/vhd/vhd-update.c
@@ -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"