aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap2/vhd
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/vhd
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/vhd')
-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
14 files changed, 151 insertions, 145 deletions
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"