From: Christoph Egger <Christoph.Egger@amd.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH][TOOLS] libfsimage: portability fixes
Date: Wed, 26 Mar 2008 15:14:33 +0100 [thread overview]
Message-ID: <200803261514.33378.Christoph.Egger@amd.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 579 bytes --]
Hi Keir!
Attached patch improves portability and adds fixes for NetBSD to libfsimage.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
--
AMD Saxony, Dresden, Germany
Operating System Research Center
Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
Dr. Hans-R. Deppe, Thomas McCoy
[-- Attachment #2: tools_libfsimage.diff --]
[-- Type: text/x-diff, Size: 4009 bytes --]
diff -r 966c04d42e94 tools/libfsimage/Makefile
--- a/tools/libfsimage/Makefile Wed Mar 26 09:12:57 2008 +0000
+++ b/tools/libfsimage/Makefile Wed Mar 26 17:12:55 2008 +0100
@@ -2,7 +2,7 @@ include $(XEN_ROOT)/tools/Rules.mk
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 -r 966c04d42e94 tools/libfsimage/Rules.mk
--- a/tools/libfsimage/Rules.mk Wed Mar 26 09:12:57 2008 +0000
+++ b/tools/libfsimage/Rules.mk Wed Mar 26 17:12:55 2008 +0100
@@ -11,6 +11,7 @@ FSDIR-$(CONFIG_SunOS)-x86_64 = $(PREFIX)
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 -r 966c04d42e94 tools/libfsimage/check-libext2fs
--- a/tools/libfsimage/check-libext2fs Wed Mar 26 09:12:57 2008 +0000
+++ b/tools/libfsimage/check-libext2fs Wed Mar 26 17:12:55 2008 +0100
@@ -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 -r 966c04d42e94 tools/libfsimage/common/fsimage_grub.c
--- a/tools/libfsimage/common/fsimage_grub.c Wed Mar 26 09:12:57 2008 +0000
+++ b/tools/libfsimage/common/fsimage_grub.c Wed Mar 26 17:12:55 2008 +0100
@@ -204,19 +204,47 @@ fsig_devread(fsi_file_t *ffi, unsigned i
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];
- while (bufsize) {
- ssize_t ret = pread(ffi->ff_fsi->f_fd, buf + bytes_read,
- bufsize, (off_t)off);
- if (ret == -1)
+ 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);
- if (ret == 0)
+ memcpy(buf, tmp + n, r);
+ buf += r;
+ bufsize -= r;
+ off += r;
+ }
+
+ n = (bufsize & ~(SECTOR_SIZE - 1));
+ if (n > 0) {
+ ret = pread(ffi->ff_fsi->f_fd, buf, n, off);
+ if (ret < n)
return (0);
-
- bytes_read += ret;
- bufsize -= ret;
+ 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);
+ memcpy(buf, tmp, bufsize);
}
return (1);
diff -r 966c04d42e94 tools/libfsimage/common/fsimage_grub.h
--- a/tools/libfsimage/common/fsimage_grub.h Wed Mar 26 09:12:57 2008 +0000
+++ b/tools/libfsimage/common/fsimage_grub.h Wed Mar 26 17:12:55 2008 +0100
@@ -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 -r 966c04d42e94 tools/libfsimage/common/fsimage_plugin.c
--- a/tools/libfsimage/common/fsimage_plugin.c Wed Mar 26 09:12:57 2008 +0000
+++ b/tools/libfsimage/common/fsimage_plugin.c Wed Mar 26 17:12:55 2008 +0100
@@ -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";
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next reply other threads:[~2008-03-26 14:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-26 14:14 Christoph Egger [this message]
2008-03-27 10:54 ` [PATCH][TOOLS] libfsimage: portability fixes Ian Jackson
2008-03-27 15:13 ` Christoph Egger
2008-03-27 15:36 ` Ian Jackson
2008-03-27 16:23 ` John Levon
2008-03-28 10:08 ` Christoph Egger
2008-03-28 10:42 ` Ian Jackson
2008-03-28 12:40 ` Christoph Egger
2008-03-28 14:19 ` Ian Jackson
2008-03-27 11:05 ` Ian Jackson
2008-03-27 15:16 ` Christoph Egger
2008-03-27 16:26 ` John Levon
2008-03-27 15:05 ` Aron Griffis
2008-03-27 15:13 ` Ian Jackson
2008-03-27 15:56 ` Aron Griffis
-- strict thread matches above, loose matches on Subject: below --
2008-03-27 15:36 Christoph Egger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200803261514.33378.Christoph.Egger@amd.com \
--to=christoph.egger@amd.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.