aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libfsimage
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-03-26 14:40:54 +0000
committerKeir Fraser <keir.fraser@citrix.com>2008-03-26 14:40:54 +0000
commitbf69b5d7858f83902b5fd61546400334a40c016c (patch)
tree9f227a9eaaf38a9cf228c9fae5ebe71115b56048 /tools/libfsimage
parent88b932f50f86522e70a978c1e081b99aee2f8374 (diff)
downloadxen-bf69b5d7858f83902b5fd61546400334a40c016c.tar.gz
xen-bf69b5d7858f83902b5fd61546400334a40c016c.tar.bz2
xen-bf69b5d7858f83902b5fd61546400334a40c016c.zip
libfsimage: portability fixes for NetBSD
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Diffstat (limited to 'tools/libfsimage')
-rw-r--r--tools/libfsimage/Makefile2
-rw-r--r--tools/libfsimage/Rules.mk1
-rwxr-xr-xtools/libfsimage/check-libext2fs6
-rw-r--r--tools/libfsimage/common/fsimage_grub.c48
-rw-r--r--tools/libfsimage/common/fsimage_grub.h2
-rw-r--r--tools/libfsimage/common/fsimage_plugin.c5
6 files changed, 49 insertions, 15 deletions
diff --git a/tools/libfsimage/Makefile b/tools/libfsimage/Makefile
index 7dd3c4f0fb..b72e51895a 100644
--- a/tools/libfsimage/Makefile
+++ b/tools/libfsimage/Makefile
@@ -2,7 +2,7 @@ XEN_ROOT = ../..
include $(XEN_ROOT)/tools/Rules.mk
SUBDIRS-y = common ufs reiserfs iso9660 fat
-SUBDIRS-y += $(shell env CC="$(CC)" ./check-libext2fs)
+SUBDIRS-y += $(shell $(SHELL) env CC="$(CC)" ./check-libext2fs)
.PHONY: all clean install
all clean install: %: subdirs-%
diff --git a/tools/libfsimage/Rules.mk b/tools/libfsimage/Rules.mk
index 0cc3d2199f..afc08bdaab 100644
--- a/tools/libfsimage/Rules.mk
+++ b/tools/libfsimage/Rules.mk
@@ -11,6 +11,7 @@ FSDIR-$(CONFIG_Linux) = $(LIBDIR)/fs/$(FS)
FSDIR-$(CONFIG_SunOS)-x86_64 = $(PREFIX)/lib/fs/$(FS)/64
FSDIR-$(CONFIG_SunOS)-x86_32 = $(PREFIX)/lib/fs/$(FS)/
FSDIR-$(CONFIG_SunOS) = $(FSDIR-$(CONFIG_SunOS)-$(XEN_TARGET_ARCH))
+FSDIR-$(CONFIG_NetBSD) = $(LIBDIR)/fs/$(FS)
FSDIR = $(FSDIR-y)
FSLIB = fsimage.so
diff --git a/tools/libfsimage/check-libext2fs b/tools/libfsimage/check-libext2fs
index e6a8d186fc..b6fa7fbacd 100755
--- a/tools/libfsimage/check-libext2fs
+++ b/tools/libfsimage/check-libext2fs
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
cat >ext2-test.c <<EOF
#include <ext2fs/ext2fs.h>
@@ -9,7 +9,9 @@ int main()
}
EOF
-${CC:-gcc} -o ext2-test ext2-test.c -lext2fs >/dev/null 2>&1
+if test -z ${CC}; then CC="gcc"; fi
+${CC} -o ext2-test ext2-test.c -lext2fs >/dev/null 2>&1
+
if [ $? = 0 ]; then
echo ext2fs-lib
else
diff --git a/tools/libfsimage/common/fsimage_grub.c b/tools/libfsimage/common/fsimage_grub.c
index 5edb3ba05b..9ea2e35ac6 100644
--- a/tools/libfsimage/common/fsimage_grub.c
+++ b/tools/libfsimage/common/fsimage_grub.c
@@ -204,19 +204,47 @@ int
fsig_devread(fsi_file_t *ffi, unsigned int sector, unsigned int offset,
unsigned int bufsize, char *buf)
{
- uint64_t off = ffi->ff_fsi->f_off + ((uint64_t)sector * 512) + offset;
- ssize_t bytes_read = 0;
+ off_t off;
+ ssize_t ret;
+ int n, r;
+ char tmp[SECTOR_SIZE];
+
+ off = ffi->ff_fsi->f_off + ((off_t)sector * SECTOR_SIZE) + offset;
+
+ /*
+ * Make reads from a raw disk sector-aligned. This is a requirement
+ * for NetBSD. Split the read up into to three parts to meet this
+ * requirement.
+ */
+
+ n = (off & (SECTOR_SIZE - 1));
+ if (n > 0) {
+ r = SECTOR_SIZE - n;
+ if (r > bufsize)
+ r = bufsize;
+ ret = pread(ffi->ff_fsi->f_fd, tmp, SECTOR_SIZE, off - n);
+ if (ret < n + r)
+ return (0);
+ memcpy(buf, tmp + n, r);
+ buf += r;
+ bufsize -= r;
+ off += r;
+ }
- while (bufsize) {
- ssize_t ret = pread(ffi->ff_fsi->f_fd, buf + bytes_read,
- bufsize, (off_t)off);
- if (ret == -1)
+ n = (bufsize & ~(SECTOR_SIZE - 1));
+ if (n > 0) {
+ ret = pread(ffi->ff_fsi->f_fd, buf, n, off);
+ if (ret < n)
return (0);
- if (ret == 0)
+ buf += n;
+ bufsize -= n;
+ off += n;
+ }
+ if (bufsize > 0) {
+ ret = pread(ffi->ff_fsi->f_fd, tmp, SECTOR_SIZE, off);
+ if (ret < bufsize)
return (0);
-
- bytes_read += ret;
- bufsize -= ret;
+ memcpy(buf, tmp, bufsize);
}
return (1);
diff --git a/tools/libfsimage/common/fsimage_grub.h b/tools/libfsimage/common/fsimage_grub.h
index 800a918655..bca481bc28 100644
--- a/tools/libfsimage/common/fsimage_grub.h
+++ b/tools/libfsimage/common/fsimage_grub.h
@@ -44,7 +44,7 @@ typedef struct fsig_plugin_ops {
} fsig_plugin_ops_t;
#define STAGE1_5
-#define FSYS_BUFLEN 0x8000
+#define FSYS_BUFLEN 0x40000
#define SECTOR_BITS 9
#define SECTOR_SIZE 0x200
diff --git a/tools/libfsimage/common/fsimage_plugin.c b/tools/libfsimage/common/fsimage_plugin.c
index d62435c8dd..5ee9d746b2 100644
--- a/tools/libfsimage/common/fsimage_plugin.c
+++ b/tools/libfsimage/common/fsimage_plugin.c
@@ -131,7 +131,10 @@ static int load_plugins(void)
int err;
int ret = -1;
-#ifdef __sun__
+#if defined(FSIMAGE_FSDIR)
+ if (fsdir == NULL)
+ fsdir = FSIMAGE_FSDIR;
+#elif defined(__sun__)
if (fsdir == NULL)
fsdir = "/usr/lib/fs";