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-%
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
-#!/bin/bash
+#!/bin/sh
cat >ext2-test.c <<EOF
#include <ext2fs/ext2fs.h>
}
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
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);