Skip to contentSkip to conversation

blktap2: portability fixes

PATCH In review Christoph Egger 2 participants 5 messages Jun 23, 2009 – Jun 24, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blktap2: portability fixes

Hi!

Attached patch makes blktap2 build on NetBSD.

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

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
tools/Makefile +3 -0
diff -r 5f5112a7d2ff tools/Makefile
@@ -23,9 +23,12 @@ SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_Linux) += libaio
 SUBDIRS-$(CONFIG_Linux) += blktap
 SUBDIRS-$(CONFIG_Linux) += blktap2
+SUBDIRS-$(CONFIG_NetBSD) += libaio
+SUBDIRS-$(CONFIG_NetBSD) += blktap2
 SUBDIRS-y += libfsimage
 SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen
 SUBDIRS-$(CONFIG_Linux) += fs-back
+SUBDIRS-$(CONFIG_NetBSD) += fs-back
 SUBDIRS-$(CONFIG_IOEMU) += ioemu-dir
 SUBDIRS-y += xenpmd
 
tools/blktap2/drivers/Makefile +16 -3
diff -r 5f5112a7d2ff 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
tools/blktap2/drivers/blk.h +4 -0
diff -r 5f5112a7d2ff tools/blktap2/drivers/blk.h
@@ -28,3 +28,7 @@
 
 int blk_getimagesize(int fd, uint64_t *size);
 int blk_getsectorsize(int fd, uint64_t *sector_size);
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
tools/blktap2/drivers/blk_netbsd.c new file +41 -0

41 lines not on this page · raw message

tools/blktap2/drivers/block-aio.c +3 -16
diff -r 5f5112a7d2ff 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, 
 	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*/
tools/blktap2/drivers/block-log.c +1 -1
diff -r 5f5112a7d2ff tools/blktap2/drivers/block-log.c
@@ -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;
tools/blktap2/drivers/block-qcow.c +2 -3
diff -r 5f5112a7d2ff 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, 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;
 	}
 
tools/blktap2/drivers/block-ram.c +3 -16
diff -r 5f5112a7d2ff 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_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*/
tools/blktap2/drivers/block-vhd.c +7 -8
diff -r 5f5112a7d2ff 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;
@@ -806,7 +805,7 @@ vhd_validate_parent(td_driver_t *child_d
 	}
 	*/
 
-	if (uuid_compare(child->vhd.header.prt_uuid, parent->vhd.footer.uuid)) {
+	if (uuid_compare(&child->vhd.header.prt_uuid, &parent->vhd.footer.uuid, &status)) {
 		DPRINTF("ERROR: %s: %s, %s: parent uuid has changed since "
 			"snapshot.  Child image no longer valid.\n",
 			__func__, child->vhd.file, parent->vhd.file);
tools/blktap2/drivers/tapdisk-client.c +1 -1
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-client.c
@@ -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;
tools/blktap2/drivers/tapdisk-diff.c +1 -0
diff -r 5f5112a7d2ff 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"
tools/blktap2/drivers/tapdisk-filter.c +4 -3
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-filter.c
@@ -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);
 	}
 }
 
tools/blktap2/drivers/tapdisk-log.c +6 -5
diff -r 5f5112a7d2ff tools/blktap2/drivers/tapdisk-log.c
@@ -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();
tools/blktap2/drivers/tapdisk-queue.c +1 -1
diff -r 5f5112a7d2ff 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)
tools/blktap2/drivers/tapdisk-utils.c +4 -18
diff -r 5f5112a7d2ff 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 
 	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);
tools/blktap2/drivers/tapdisk-vbd.c +5 -4
diff -r 5f5112a7d2ff 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)
tools/blktap2/drivers/tapdisk.h +1 -1
diff -r 5f5112a7d2ff 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;
 };
 
tools/blktap2/include/libvhd.h +35 -13

111 lines not on this page · raw message

tools/blktap2/include/list.h +11 -0
diff -r 5f5112a7d2ff 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) \
tools/blktap2/include/vhd.h +5 -0
diff -r 5f5112a7d2ff tools/blktap2/include/vhd.h
@@ -27,8 +27,13 @@
 #ifndef __VHD_H__
 #define __VHD_H__
 
+#ifdef __Linux__
 #include <asm/types.h>
 #include <uuid/uuid.h>
+#endif
+#ifdef __NetBSD__
+#include <uuid.h>
+#endif
 #include <inttypes.h>
 
 typedef uint32_t u32;
tools/blktap2/vhd/Makefile +2 -0
diff -r 5f5112a7d2ff 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
tools/blktap2/vhd/lib/Makefile +2 -0
diff -r 5f5112a7d2ff 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
tools/blktap2/vhd/lib/libvhd-journal.c +26 -26

184 lines not on this page · raw message

tools/blktap2/vhd/lib/libvhd.c +76 -71

512 lines not on this page · raw message

tools/blktap2/vhd/lib/vhd-util-check.c +30 -26

173 lines not on this page · raw message

tools/blktap2/vhd/lib/vhd-util-coalesce.c +3 -3
diff -r 5f5112a7d2ff 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;
tools/blktap2/vhd/lib/vhd-util-modify.c +1 -1
diff -r 5f5112a7d2ff 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;
tools/blktap2/vhd/lib/vhd-util-query.c +1 -1
diff -r 5f5112a7d2ff 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;
tools/blktap2/vhd/lib/vhd-util-read.c +8 -7
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-read.c
@@ -58,12 +58,12 @@ static void
 vhd_print_header(vhd_context_t *vhd, vhd_header_t *h, int hex)
 {
 	int err;
-	uint32_t  cksm;
-	char      uuid[37], time_str[26], cookie[9], out[512], *name;
+	uint32_t  cksm, status;
+	char      uuid[39], time_str[26], cookie[9], out[512], *name;
 
 	printf("VHD Header Summary:\n-------------------\n");
 
-	snprintf(cookie, 9, "%s", h->cookie);
+	snprintf(cookie, sizeof(cookie), "%s", h->cookie);
 	printf("Cookie              : %s\n", cookie);
 
 	printf("Data offset (unusd) : %s\n", conv(hex, h->data_offset));
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
 	       (err ? "failed to read name" : name));
 	free(name);
 
-	uuid_unparse(h->prt_uuid, uuid);
+	uuid_to_string(&h->prt_uuid, (char **)&uuid, &status);
 	printf("Parent UUID         : %s\n", uuid);
     
 	vhd_time_to_string(h->prt_ts, time_str);
@@ -95,11 +95,12 @@ vhd_print_footer(vhd_footer_t *f, int he
 {
 	uint64_t  c, h, s;
 	uint32_t  ff_maj, ff_min, cr_maj, cr_min, cksm, cksm_save;
-	char      time_str[26], creator[5], uuid[37], cookie[9];
+	char      time_str[26], creator[5], uuid[39], cookie[9];
+	uint32_t status;
 
 	printf("VHD Footer Summary:\n-------------------\n");
 
-	snprintf(cookie, 9, "%s", f->cookie);
+	snprintf(cookie, sizeof(cookie), "%s", f->cookie);
 	printf("Cookie              : %s\n", cookie);
 
 	printf("Features            : (0x%08x) %s%s\n", f->features,
@@ -153,7 +154,7 @@ vhd_print_footer(vhd_footer_t *f, int he
 	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
 		f->checksum == cksm ? "Good!" : "Bad!");
 
-	uuid_unparse(f->uuid, uuid);
+	uuid_to_string(&f->uuid, (char **)&uuid, &status);
 	printf("UUID                : %s\n", uuid);
 
 	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");
tools/blktap2/vhd/lib/vhd-util-repair.c +1 -1
diff -r 5f5112a7d2ff 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;
tools/blktap2/vhd/lib/vhd-util-resize.c +15 -15
diff -r 5f5112a7d2ff tools/blktap2/vhd/lib/vhd-util-resize.c
@@ -95,7 +95,7 @@ vhd_fixed_shrink(vhd_journal_t *journal,
 }
 
 static int
-vhd_write_zeros(vhd_journal_t *journal, off64_t off, uint64_t size)
+vhd_write_zeros(vhd_journal_t *journal, off_t off, uint64_t size)
 {
 	int err;
 	char *buf;
@@ -109,7 +109,7 @@ vhd_write_zeros(vhd_journal_t *journal, 
 	if (err)
 		return err;
 
-	buf = mmap(0, map, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+	buf = mmap(0, map, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
 	if (buf == MAP_FAILED)
 		return -errno;
 
@@ -143,7 +143,7 @@ vhd_fixed_grow(vhd_journal_t *journal, u
 		goto out;
 
 	eof = vhd_position(vhd);
-	if (eof == (off64_t)-1) {
+	if (eof == (off_t)-1) {
 		err = -errno;
 		goto out;
 	}
@@ -234,13 +234,13 @@ quicksort(vhd_block_t *list, int left, i
 }
 
 static int
-vhd_move_block(vhd_journal_t *journal, uint32_t src, off64_t offset)
+vhd_move_block(vhd_journal_t *journal, uint32_t src, off_t offset)
 {
 	int err;
 	char *buf;
 	size_t size;
 	vhd_context_t *vhd;
-	off64_t off, src_off;
+	off_t off, src_off;
 
 	buf     = NULL;
 	vhd     = &journal->vhd;
@@ -300,7 +300,7 @@ static int
 vhd_clobber_block(vhd_journal_t *journal, uint32_t src, uint32_t dest)
 {
 	int err;
-	off64_t off;
+	off_t off;
 	vhd_context_t *vhd;
 
 	vhd = &journal->vhd;
@@ -404,7 +404,7 @@ vhd_clear_bat_entries(vhd_journal_t *jou
 {
 	int i, err;
 	vhd_context_t *vhd;
-	off64_t orig_map_off, new_map_off;
+	off_t orig_map_off, new_map_off;
 	uint32_t orig_entries, new_entries;
 
 	vhd          = &journal->vhd;
@@ -473,7 +473,7 @@ vhd_clear_bat_entries(vhd_journal_t *jou
 static int
 vhd_dynamic_shrink(vhd_journal_t *journal, uint64_t secs)
 {
-	off64_t eof;
+	off_t eof;
 	uint32_t blocks;
 	vhd_context_t *vhd;
 	int i, j, err, free_cnt;
@@ -581,7 +581,7 @@ vhd_next_block_offset(vhd_context_t *vhd
 }
 
 static inline int
-in_range(off64_t off, off64_t start, off64_t size)
+in_range(off_t off, off_t start, off_t size)
 {
 	return (start < off && start + size > off);
 }
@@ -599,7 +599,7 @@ skip_check(int mode, int type)
 }
 
 static int
-vhd_check_for_clobber(vhd_context_t *vhd, off64_t off, int mode)
+vhd_check_for_clobber(vhd_context_t *vhd, off_t off, int mode)
 {
 	int i, n;
 	char *msg;
@@ -676,7 +676,7 @@ fail:
  * take any metadata after the bat (@eob) and shift it
  */
 static int
-vhd_shift_metadata(vhd_journal_t *journal, off64_t eob,
+vhd_shift_metadata(vhd_journal_t *journal, off_t eob,
 		   size_t bat_needed, size_t map_needed)
 {
 	int i, n, err;
@@ -724,7 +724,7 @@ vhd_shift_metadata(vhd_journal_t *journa
 	}
 
 	for (i = 0; i < n; i++) {
-		off64_t off;
+		off_t off;
 		size_t size;
 
 		if (!locators[i])
@@ -775,7 +775,7 @@ static int
 vhd_add_bat_entries(vhd_journal_t *journal, int entries)
 {
 	int i, err;
-	off64_t off;
+	off_t off;
 	vhd_bat_t new_bat;
 	vhd_context_t *vhd;
 	uint32_t new_entries;
@@ -878,7 +878,7 @@ static int
 vhd_dynamic_grow(vhd_journal_t *journal, uint64_t secs)
 {
 	int i, err;
-	off64_t eob, eom;
+	off_t eob, eom;
 	vhd_context_t *vhd;
 	vhd_block_t first_block;
 	uint64_t blocks, size_needed;
@@ -953,7 +953,7 @@ vhd_dynamic_grow(vhd_journal_t *journal,
 	 * move vhd data blocks to the end of the file to make room 
 	 */
 	do {
-		off64_t new_off, bm_size, gap_size;
+		off_t new_off, bm_size, gap_size;
 
 		new_off = vhd_sectors_to_bytes(vhd_next_block_offset(vhd));
 
tools/blktap2/vhd/lib/vhd-util-scan.c +2 -1
diff -r 5f5112a7d2ff 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;
tools/blktap2/vhd/lib/vhd-util-set-field.c +1 -1
diff -r 5f5112a7d2ff 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;
 
tools/blktap2/vhd/vhd-update.c +0 -2
diff -r 5f5112a7d2ff 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"
tools/check/check_uuid_devel +1 -0
diff -r 5f5112a7d2ff tools/check/check_uuid_devel
@@ -3,4 +3,5 @@
 
 . ./funcs.sh
 
+has_header uuid.h || \
 has_header uuid/uuid.h || fail "missing uuid headers (package uuid-dev)"

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

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

-- Keir

Quoted 13 lines · Christoph Egger

Hi!

Attached patch makes blktap2 build on NetBSD.

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

#2 lore raw

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

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

Quoted 18 lines · On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote:

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

-- Keir

Quoted 11 lines · Christoph Egger

Hi!

Attached patch makes blktap2 build on NetBSD.

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

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
tools/blktap2/drivers/block-vhd.c +1 -1
diff -r b51f9542ab14 tools/blktap2/drivers/block-vhd.c
@@ -806,7 +806,7 @@ vhd_validate_parent(td_driver_t *child_d
 	}
 	*/
 
-	if (uuid_compare(child->vhd.header.prt_uuid, parent->vhd.footer.uuid)) {
+	if (blk_uuid_compare(&child->vhd.header.prt_uuid, &parent->vhd.footer.uuid)) {
 		DPRINTF("ERROR: %s: %s, %s: parent uuid has changed since "
 			"snapshot.  Child image no longer valid.\n",
 			__func__, child->vhd.file, parent->vhd.file);
tools/blktap2/include/blk_uuid.h new file +53 -0

53 lines not on this page · raw message

tools/blktap2/include/libvhd.h +2 -2
diff -r b51f9542ab14 tools/blktap2/include/libvhd.h
@@ -36,7 +36,7 @@
 #include <sys/bswap.h>
 #endif
 
-#include "uuid.h"
+#include "blk_uuid.h"
 #include "vhd.h"
 
 #ifndef O_LARGEFILE
@@ -216,7 +216,7 @@ vhd_parent_locator_size(vhd_parent_locat
 static inline int
 vhd_parent_raw(vhd_context_t *ctx)
 {
-	return uuid_is_null(ctx->header.prt_uuid);
+	return blk_uuid_is_nil(&ctx->header.prt_uuid);
 }
 
 void libvhd_set_log_level(int);
tools/blktap2/include/uuid.h deleted +0 -73

73 lines not on this page · raw message

tools/blktap2/include/vhd.h +0 -1
diff -r b51f9542ab14 tools/blktap2/include/vhd.h
@@ -28,7 +28,6 @@
 #define __VHD_H__
 
 #include <inttypes.h>
-#include "uuid.h"
 
 typedef uint32_t u32;
 typedef uint64_t u64;
tools/blktap2/vhd/lib/Makefile +5 -0
diff -r b51f9542ab14 tools/blktap2/vhd/lib/Makefile
@@ -27,6 +27,10 @@ endif
 CFLAGS          += -Wp,-MD,.$(@F).d
 DEPS             = .*.d
 
+UUID_SRCS-y	:=
+UUID_SRCS-$(CONFIG_Linux) += uuid_linux.c
+UUID_SRCS-$(CONFIG_NetBSD) += uuid_netbsd.c
+
 LIB-SRCS        := libvhd.c
 LIB-SRCS        += libvhd-journal.c
 LIB-SRCS        += vhd-util-coalesce.c
@@ -44,6 +48,7 @@ LIB-SRCS        += vhd-util-scan.c
 LIB-SRCS        += vhd-util-check.c
 LIB-SRCS        += relative-path.c
 LIB-SRCS        += atomicio.c
+LIB-SRCS	+= $(UUID_SRCS-y)
 
 LIB-OBJS         = $(patsubst %.c,%.o,$(LIB-SRCS))
 LIB-OBJS        += $(LVM-UTIL-OBJ)
tools/blktap2/vhd/lib/libvhd-journal.c +1 -1
diff -r b51f9542ab14 tools/blktap2/vhd/lib/libvhd-journal.c
@@ -237,7 +237,7 @@ vhd_journal_add_journal_header(vhd_journ
 	if (err)
 		return err;
 
-	uuid_copy(j->header.uuid, vhd->footer.uuid);
+	blk_uuid_copy(&j->header.uuid, &vhd->footer.uuid);
 	memcpy(j->header.cookie,
 	       VHD_JOURNAL_HEADER_COOKIE, sizeof(j->header.cookie));
 	j->header.vhd_footer_offset = off - sizeof(vhd_footer_t);
tools/blktap2/vhd/lib/libvhd.c +35 -13

126 lines not on this page · raw message

tools/blktap2/vhd/lib/uuid_linux.c new file +43 -0

43 lines not on this page · raw message

tools/blktap2/vhd/lib/uuid_netbsd.c new file +43 -0

43 lines not on this page · raw message

tools/blktap2/vhd/lib/vhd-util-check.c +2 -2
diff -r b51f9542ab14 tools/blktap2/vhd/lib/vhd-util-check.c
@@ -218,7 +218,7 @@ vhd_util_check_validate_differencing_hea
 		if (vhd_util_check_zeros(header->loc, sizeof(header->loc)))
 			return "invalid non-null parent locators";
 
-		if (!uuid_is_null(header->prt_uuid))
+		if (!blk_uuid_is_nil(&header->prt_uuid))
 			return "invalid non-null parent uuid";
 
 		if (header->prt_ts)
@@ -320,7 +320,7 @@ vhd_util_check_validate_parent(vhd_conte
 				VHD_OPEN_RDONLY | VHD_OPEN_IGNORE_DISABLED))
 		return "error opening parent";
 
-	if (uuid_compare(vhd->header.prt_uuid, parent.footer.uuid)) {
+	if (blk_uuid_compare(&vhd->header.prt_uuid, &parent.footer.uuid)) {
 		msg = "invalid parent uuid";
 		goto out;
 	}
tools/blktap2/vhd/lib/vhd-util-read.c +2 -2
diff -r b51f9542ab14 tools/blktap2/vhd/lib/vhd-util-read.c
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
 	       (err ? "failed to read name" : name));
 	free(name);
 
-	uuid_unparse(h->prt_uuid, uuid);
+	blk_uuid_to_string(&h->prt_uuid, (char **)&uuid);
 	printf("Parent UUID         : %s\n", uuid);
     
 	vhd_time_to_string(h->prt_ts, time_str);
@@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int he
 	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
 		f->checksum == cksm ? "Good!" : "Bad!");
 
-	uuid_unparse(f->uuid, uuid);
+	blk_uuid_to_string(&f->uuid, (char **)&uuid);
 	printf("UUID                : %s\n", uuid);
 
 	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

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

-- Keir

Quoted 37 lines · Christoph Egger

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

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

Quoted 18 lines · On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote:

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

-- Keir

Quoted 11 lines · Christoph Egger

Hi!

Attached patch makes blktap2 build on NetBSD.

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

#4 lore raw

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

Quoted 45 lines · On Wednesday 24 June 2009 15:07:50 Keir Fraser wrote:

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

-- Keir

Quoted 33 lines · Christoph Egger

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

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

Quoted 18 lines · On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote:

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

-- Keir

Quoted 11 lines · Christoph Egger

Hi!

Attached patch makes blktap2 build on NetBSD.

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

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
tools/blktap2/include/blk_uuid.h +7 -3
diff -r f1fec38c8228 tools/blktap2/include/blk_uuid.h
@@ -45,7 +45,7 @@ static inline void blk_uuid_generate(blk
 	uuid_generate(uuid->uuid);
 }
 
-static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
+static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
 {
 	uuid_unparse(uuid->uuid, out);
 }
@@ -74,6 +74,7 @@ static inline int blk_uuid_compare(blk_u
 
 #include <uuid.h>
 #include <string.h>
+#include <stdlib.h>
 
 typedef uuid_t blk_uuid_t;
 
@@ -89,10 +90,13 @@ static inline void blk_uuid_generate(blk
 	uuid_create((uuid_t *)uuid, &status);
 }
 
-static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out)
+static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size)
 {
 	uint32_t status;
-	uuid_to_string((uuid_t *)uuid, &out, &status);
+	char *_out = NULL;
+	uuid_to_string((uuid_t *)uuid, &_out, &status);
+	strlcpy(out, _out, size);
+	free(_out);
 }
 
 static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in)
tools/blktap2/vhd/lib/libvhd.c +2 -2
diff -r f1fec38c8228 tools/blktap2/vhd/lib/libvhd.c
@@ -1335,7 +1335,7 @@ vhd_macx_encode_location(char *name, cha
 	snprintf(uri, ibl+1, "file://%s", name);
 
 	if (iconv(cd,
-#if defined(__linux__) || (__Linux__)
+#if defined(__linux__) || defined(__Linux__)
 	    (char **)
 #endif
 	    &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 ||
@@ -1425,7 +1425,7 @@ vhd_w2u_encode_location(char *name, char
 	}
 
 	if (iconv(cd,
-#if defined(__linux__) || (__Linux__)
+#if defined(__linux__) || defined(__Linux__)
 	    (char **)
 #endif
 	    &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 ||
tools/blktap2/vhd/lib/vhd-util-read.c +2 -2
diff -r f1fec38c8228 tools/blktap2/vhd/lib/vhd-util-read.c
@@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd
 	       (err ? "failed to read name" : name));
 	free(name);
 
-	blk_uuid_to_string(&h->prt_uuid, uuid);
+	blk_uuid_to_string(&h->prt_uuid, uuid, sizeof(uuid));
 	printf("Parent UUID         : %s\n", uuid);
     
 	vhd_time_to_string(h->prt_ts, time_str);
@@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int he
 	printf("Checksum            : 0x%x|0x%x (%s)\n", f->checksum, cksm,
 		f->checksum == cksm ? "Good!" : "Bad!");
 
-	blk_uuid_to_string(&f->uuid, uuid);
+	blk_uuid_to_string(&f->uuid, uuid, sizeof(uuid));
 	printf("UUID                : %s\n", uuid);
 
 	printf("Saved state         : %s\n", f->saved == 0 ? "No" : "Yes");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel