aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap2/include
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/include
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/include')
-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
4 files changed, 116 insertions, 15 deletions
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;