|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 1/5] stubdom: remove support for grub-pv
The Mini-OS based grub-pv is not being built by default since Xen 4.16.
Additionally it can be replaced in most cases by the more modern pvgrub
(part of grub upstream), while grub-pv is based on legacy grub 0.97.
In case someone is really depending on grub-pv, an old build from a
previous Xen version can be used without any problem, as only stable
hypercall interfaces are used by it.
Remove grub-pv from the build system.
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
Makefile | 3 -
config/Stubdom.mk.in | 3 -
stubdom/.gitignore | 1 -
stubdom/Makefile | 54 -
stubdom/configure | 65 -
stubdom/configure.ac | 2 -
stubdom/grub.patches/00cvs | 1022 -----
stubdom/grub.patches/10graphics.diff | 2297 -----------
stubdom/grub.patches/11graphics-keyboard.diff | 13 -
stubdom/grub.patches/20print_func.diff | 52 -
stubdom/grub.patches/30savedefault.diff | 186 -
.../grub.patches/40ext3_256byte_inode.diff | 114 -
stubdom/grub.patches/50fs_fulldisk.diff | 72 -
stubdom/grub.patches/60ext4.diff | 474 ---
stubdom/grub.patches/61btrfs.diff | 3499 -----------------
stubdom/grub.patches/70compiler_warnings.diff | 45 -
stubdom/grub.patches/99minios | 1570 --------
stubdom/grub/Makefile | 88 -
stubdom/grub/boot-x86_32.S | 112 -
stubdom/grub/boot-x86_64.S | 108 -
stubdom/grub/config.h | 12 -
stubdom/grub/kexec.c | 434 --
stubdom/grub/mini-os.c | 771 ----
stubdom/grub/mini-os.h | 7 -
stubdom/grub/minios.cfg | 4 -
stubdom/grub/osdep.h | 30 -
26 files changed, 11038 deletions(-)
delete mode 100644 stubdom/grub.patches/00cvs
delete mode 100644 stubdom/grub.patches/10graphics.diff
delete mode 100644 stubdom/grub.patches/11graphics-keyboard.diff
delete mode 100644 stubdom/grub.patches/20print_func.diff
delete mode 100644 stubdom/grub.patches/30savedefault.diff
delete mode 100644 stubdom/grub.patches/40ext3_256byte_inode.diff
delete mode 100644 stubdom/grub.patches/50fs_fulldisk.diff
delete mode 100644 stubdom/grub.patches/60ext4.diff
delete mode 100644 stubdom/grub.patches/61btrfs.diff
delete mode 100644 stubdom/grub.patches/70compiler_warnings.diff
delete mode 100644 stubdom/grub.patches/99minios
delete mode 100644 stubdom/grub/Makefile
delete mode 100644 stubdom/grub/boot-x86_32.S
delete mode 100644 stubdom/grub/boot-x86_64.S
delete mode 100644 stubdom/grub/config.h
delete mode 100644 stubdom/grub/kexec.c
delete mode 100644 stubdom/grub/mini-os.c
delete mode 100644 stubdom/grub/mini-os.h
delete mode 100644 stubdom/grub/minios.cfg
delete mode 100644 stubdom/grub/osdep.h
diff --git a/Makefile b/Makefile
index 67b71ac3d4..eb388726b0 100644
--- a/Makefile
+++ b/Makefile
@@ -71,9 +71,6 @@ build-tools-oxenstored: build-tools-public-headers
.PHONY: build-stubdom
build-stubdom: mini-os-dir build-tools-public-headers
$(MAKE) -C stubdom build
-ifeq (x86_64,$(XEN_TARGET_ARCH))
- XEN_TARGET_ARCH=x86_32 $(MAKE) -C stubdom pv-grub-if-enabled
-endif
define do-subtree
$(1)/%: FORCE
diff --git a/config/Stubdom.mk.in b/config/Stubdom.mk.in
index b399d77740..0d70d03941 100644
--- a/config/Stubdom.mk.in
+++ b/config/Stubdom.mk.in
@@ -23,9 +23,6 @@ NEWLIB_URL := @NEWLIB_URL@
LWIP_VERSION := @LWIP_VERSION@
LWIP_URL := @LWIP_URL@
-GRUB_VERSION := @GRUB_VERSION@
-GRUB_URL := @GRUB_URL@
-
GMP_VERSION := @GMP_VERSION@
GMP_URL := @GMP_URL@
diff --git a/stubdom/.gitignore b/stubdom/.gitignore
index 1b69656d45..08f2e9b432 100644
--- a/stubdom/.gitignore
+++ b/stubdom/.gitignore
@@ -9,7 +9,6 @@
/cross-root-*
/gcc-*
/gmp-*
-/grub-*
/include
/libs-*
/libxencall-*
diff --git a/stubdom/Makefile b/stubdom/Makefile
index acd5e56f16..850e8544ca 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -361,32 +361,6 @@ vtpmmgr-minios-config.mk: $(CURDIR)/vtpmmgr/minios.cfg
vtpmmgr: cross-polarssl vtpmmgr-minios-config.mk
XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)
$(shell cat vtpmmgr-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
-######
-# Grub
-######
-
-grub-$(GRUB_VERSION).tar.gz:
- $(FETCHER) $@ $(GRUB_URL)/$@
-
-grub-upstream: grub-$(GRUB_VERSION).tar.gz
- tar xzf $<
- mv grub-$(GRUB_VERSION) $@
- for i in grub.patches/* ; do \
- patch -d $@ -p1 < $$i || exit 1; \
- done
-
-grub/minios.gen.cfg: APP_LIBS = guest ctrl toollog
-grub/minios.gen.cfg: grub/minios.cfg Makefile
- $(GEN_config) >$@
-
-grub-$(XEN_TARGET_ARCH)-minios-config.mk: grub/minios.gen.cfg
- MINIOS_CONFIG="$(CURDIR)/$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE)
DESTDIR= -C $(MINI_OS) config
-
-.PHONY: grub
-grub: cross-polarssl grub-upstream $(CROSS_ROOT)
grub-$(XEN_TARGET_ARCH)-minios-config.mk
- mkdir -p grub-$(XEN_TARGET_ARCH)
- CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat
grub-$(XEN_TARGET_ARCH)-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE)
DESTDIR= -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
-
##########
# xenstore
##########
@@ -429,17 +403,6 @@ vtpm-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpm vtpm
vtpmmgr-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpmmgr vtpmmgr
DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)"
DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpmmgr/minios.cfg"
$(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$<
APP_OBJS="$(CURDIR)/vtpmmgr/vtpmmgr.a" APP_LDLIBS="-lm -lpolarssl"
-.PHONY: pv-grub
-pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxenguest grub
- DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)"
DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/grub/minios.gen.cfg"
$(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$<
APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
-
-.PHONY: pv-grub-if-enabled
-ifneq ($(filter grub,$(STUBDOM_TARGETS)),)
-pv-grub-if-enabled: pv-grub
-else
-pv-grub-if-enabled:
-endif
-
XENSTORE_DEPS := libxenevtchn libxengnttab libxenmanage
.PHONY: xenstore-stubdom
@@ -460,16 +423,6 @@ else
install:
endif
-install-grub: pv-grub
- $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
- $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz
"$(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz"
-
-ifneq ($(filter grub,$(STUBDOM_TARGETS)),)
-install-grub-if-enabled: install-grub
-else
-install-grub-if-enabled:
-endif
-
install-xenstore: xenstore-stubdom
$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-xenstore/mini-os.gz
"$(DESTDIR)$(XENFIRMWAREDIR)/xenstore-stubdom.gz"
@@ -500,9 +453,6 @@ else
uninstall:
endif
-uninstall-grub:
- rm -f $(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz
-
uninstall-xenstore:
rm -f $(DESTDIR)$(XENFIRMWAREDIR)/xenstore-stubdom.gz
@@ -523,14 +473,12 @@ uninstall-vtpmmgr:
.PHONY: clean
clean: $(foreach lib,$(STUB_LIBS),clean-libxen$(lib))
clean:
- rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
rm -fr mini-os-$(XEN_TARGET_ARCH)-xenstore
rm -fr mini-os-$(XEN_TARGET_ARCH)-xenstorepvh
rm -fr mini-os-$(XEN_TARGET_ARCH)-vtpm
rm -fr mini-os-$(XEN_TARGET_ARCH)-vtpmmgr
$(MAKE) -C vtpm clean
$(MAKE) -C vtpmmgr clean
- rm -fr grub-$(XEN_TARGET_ARCH)
rm -f *-minios-config.mk
rm -f *.gen.cfg
rm -fr pkg-config
@@ -559,7 +507,6 @@ patchclean: crossclean
rm -fr polarssl-$(XEN_TARGET_ARCH)
rm -fr tpm_emulator-$(XEN_TARGET_ARCH)
rm -fr lwip-$(XEN_TARGET_ARCH)
- rm -fr grub-upstream
# clean downloads
.PHONY: downloadclean
@@ -569,7 +516,6 @@ downloadclean: patchclean
rm -f gmp-$(GMP_VERSION).tar.bz2
rm -f tpm_emulator-$(TPMEMU_VERSION).tar.gz
rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
- rm -f grub-$(GRUB_VERSION).tar.gz
rm -f lwip-$(LWIP_VERSION).tar.gz
rm -f polarssl-$(POLARSSL_VERSION)-gpl.tgz
diff --git a/stubdom/configure b/stubdom/configure
index 8a0a798bd2..689ff4d6ed 100755
--- a/stubdom/configure
+++ b/stubdom/configure
@@ -630,8 +630,6 @@ POLARSSL_VERSION
POLARSSL_URL
GMP_VERSION
GMP_URL
-GRUB_VERSION
-GRUB_URL
LWIP_VERSION
LWIP_URL
NEWLIB_VERSION
@@ -660,7 +658,6 @@ extfiles
debug
xenstorepvh
xenstore
-grub
host_os
host_vendor
host_cpu
@@ -711,7 +708,6 @@ SHELL'
ac_subst_files=''
ac_user_opts='
enable_option_checking
-enable_pv_grub
enable_xenstore_stubdom
enable_xenstorepvh_stubdom
enable_vtpm_stubdom
@@ -732,7 +728,6 @@ ZLIB_URL
LIBPCI_URL
NEWLIB_URL
LWIP_URL
-GRUB_URL
GMP_URL
POLARSSL_URL
TPMEMU_URL'
@@ -1358,7 +1353,6 @@ Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
- --enable-pv-grub Build and install pv-grub (default is DISABLED)
--disable-xenstore-stubdom
Build and install xenstore-stubdom (default is
ENABLED)
@@ -1385,7 +1379,6 @@ Some influential environment variables:
LIBPCI_URL Download url for libpci
NEWLIB_URL Download url for newlib
LWIP_URL Download url for lwip
- GRUB_URL Download url for grub
GMP_URL Download url for libgmp
POLARSSL_URL
Download url for polarssl
@@ -2403,47 +2396,6 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed
's/ /-/g'`;; esac
# Enable/disable stub domains
-# Check whether --enable-pv-grub was given.
-if test ${enable_pv_grub+y}
-then :
- enableval=$enable_pv_grub;
-
-if test "x$enableval" = "xyes"
-then :
-
-
-grub=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS grub"
-STUBDOM_BUILD="$STUBDOM_BUILD pv-grub"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-grub"
-STUBDOM_UNINSTALL="$STUBDOM_UNINSTALL install-grub"
-
-
-else $as_nop
-
-if test "x$enableval" = "xno"
-then :
-
-
-grub=n
-
-
-fi
-
-fi
-
-
-else $as_nop
-
-
-grub=n
-
-
-fi
-
-
-
-
# Check whether --enable-xenstore-stubdom was given.
if test ${enable_xenstore_stubdom+y}
then :
@@ -4137,23 +4089,6 @@ LWIP_VERSION="1.3.0"
-if test "x$GRUB_URL" = "x"
-then :
-
- if test "x$extfiles" = "xy"
-then :
- GRUB_URL=\$\(XEN_EXTFILES_URL\)
-else $as_nop
- GRUB_URL="https://alpha.gnu.org/gnu/grub"
-fi
-
-fi
-GRUB_VERSION="0.97"
-
-
-
-
-
if test "x$GMP_URL" = "x"
then :
diff --git a/stubdom/configure.ac b/stubdom/configure.ac
index 33f170144e..6ff3ab0ee9 100644
--- a/stubdom/configure.ac
+++ b/stubdom/configure.ac
@@ -18,7 +18,6 @@ m4_include([../m4/depends.m4])
m4_include([../m4/fetcher.m4])
# Enable/disable stub domains
-AX_STUBDOM_DEFAULT_DISABLE([pv-grub], [grub])
AX_STUBDOM_DEFAULT_ENABLE([xenstore-stubdom], [xenstore])
AX_STUBDOM_DEFAULT_ENABLE([xenstorepvh-stubdom], [xenstorepvh])
AX_STUBDOM_CONDITIONAL([vtpm-stubdom], [vtpm])
@@ -43,7 +42,6 @@ AX_STUBDOM_LIB([ZLIB], [zlib], [1.2.3])
AX_STUBDOM_LIB([LIBPCI], [libpci], [2.2.9],
[https://mirrors.edge.kernel.org/pub/software/utils/pciutils])
AX_STUBDOM_LIB([NEWLIB], [newlib], [1.16.0],
[https://sourceware.org/ftp/newlib])
AX_STUBDOM_LIB([LWIP], [lwip], [1.3.0],
[https://download.savannah.gnu.org/releases/lwip])
-AX_STUBDOM_LIB([GRUB], [grub], [0.97], [https://alpha.gnu.org/gnu/grub])
AX_STUBDOM_LIB([GMP], [libgmp], [4.3.2],
[https://gmplib.org/download/gmp/archive])
AX_STUBDOM_LIB([POLARSSL], [polarssl], [1.1.4])
AX_STUBDOM_LIB([TPMEMU], [berlios tpm emulator], [0.7.4])
diff --git a/stubdom/grub.patches/00cvs b/stubdom/grub.patches/00cvs
deleted file mode 100644
index 47d66f3a3b..0000000000
--- a/stubdom/grub.patches/00cvs
+++ /dev/null
@@ -1,1022 +0,0 @@
-diff -uprN grub-0.97/acinclude.m4 grub/acinclude.m4
---- grub-0.97/acinclude.m4 2004-04-27 21:48:06.000000000 +0100
-+++ grub/acinclude.m4 2007-11-05 01:29:46.000000000 +0000
-@@ -57,7 +57,7 @@ else
- fi
- grub_cv_prog_objcopy_absolute=yes
- for link_addr in 2000 8000 7C00; do
-- if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext
-Wl,$link_addr conftest.o -o conftest.exec]); then :
-+ if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N
-Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
- else
- AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
- fi
-diff -uprN grub-0.97/ChangeLog grub/ChangeLog
---- grub-0.97/ChangeLog 2005-05-08 03:47:02.000000000 +0100
-+++ grub/ChangeLog 2008-05-20 12:04:18.000000000 +0100
-@@ -1,3 +1,127 @@
-+2008-05-20 Robert Millan <rmh@xxxxxxxxxxx>
-+
-+ * netboot/cs89x0.c: Fix license violation.
-+ * netboot/cs89x0.h: Likewise.
-+
-+2008-04-10 Pavel Roskin <proski@xxxxxxx>
-+
-+ * configure.ac: Always use "_cv_" in cache variables for
-+ compatibility with Autoconf 2.62.
-+
-+2008-03-28 Robert Millan <rmh@xxxxxxxxxxx>
-+
-+ Surpass 1 TiB disk addressing limit. Note: there are no plans to handle
-+ the 2 TiB disk limit in GRUB Legacy, since that would need considerable
-+ rework. If you have >2TiB disks, use GRUB 2 instead.
-+
-+ * grub/asmstub.c (biosdisk): Add unsigned qualifier to `sector'.
-+ * stage2/bios.c (biosdisk): Likewise.
-+ * stage2/disk_io.c (rawread, devread, rawwrite, devwrite): Likewise.
-+ * stage2/shared.h (rawread, devread, rawwrite, devwrite): Likewise.
-+ * lib/device.c (get_drive_geometry): Replace BLKGETSIZE with
-+ BLKGETSIZE64.
-+
-+2007-10-29 Pavel Roskin <proski@xxxxxxx>
-+
-+ * configure.ac: Test if '--build-id=none' is supported by the
-+ linker and add it to LDFLAGS if possible. Build ID causes
-+ objcopy to generate huge binary files.
-+ * aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Use LDFLAGS when
-+ linking, so that build ID doesn't break the test.
-+ * stage1/Makefile.am: Preserve LDFLAGS, use stage1_exec_LDFLAGS.
-+
-+2007-02-22 Pavel Roskin <proski@xxxxxxx>
-+
-+ * stage2/iso9660.h: Remove unnecessary packed attributes.
-+
-+2007-02-22 Robert Millan <rmh@xxxxxxxxxxx>
-+
-+ * util/mkbimage: Update my email address, and remove my name from
-+ some places where unnecessary credit is given.
-+
-+2006-09-10 Pavel Roskin <proski@xxxxxxx>
-+
-+ * netboot/natsemi.c: Fix compile error with gcc 4.1.1. Cast
-+ cannot make a variable volatile - it should be declared as such.
-+ * netboot/sis900.c: Likewise.
-+
-+2006-09-08 Pavel Roskin <proski@xxxxxxx>
-+
-+ * netboot/etherboot.h: Remove incorrect extern declarations of
-+ the variables later declared static. Move BOOTP_DATA_ADDR ...
-+ * netboot/main.c: ... here. Eliminate end_of_rfc1533 - it's
-+ write-only.
-+
-+2006-06-24 Yoshinori K. Okuji <okuji@xxxxxxxxx>
-+
-+ * docs/grub.texi: Changed the license term to the GNU Free
-+ Documentation License 1.2.
-+
-+ * docs/multiboot.texi: Reformatted to show the license term
-+ and the version number explicitly.
-+
-+ * docs/fdl.texi: New file.
-+
-+ * docs/Makefile.am (grub_TEXINFOS): Added fdl.texi.
-+
-+2006-06-24 Robert Millan <robertmh@xxxxxxx>
-+
-+ * lib/device.c (write_to_partition): /dev/ataraid/ and /dev/rd/
-+ partitions have a "p" prefix. Add it.
-+
-+2006-06-24 Robert Millan <robertmh@xxxxxxx>
-+
-+ * lib/device.c (get_i2o_disk_name): New function.
-+ (init_device_map) [__linux__]: Add support for I2O devices.
-+
-+2006-05-02 Pavel Roskin <proski@xxxxxxx>
-+
-+ * stage2/stage2.c (run_menu): Fix "savedefault" to save only top
-+ level menu positions. Remember current position when calling a
-+ submenu. Don't recalculate it when booting from a submenu.
-+
-+ * grub/main.c (main): Make sure the boot drive number doesn't
-+ exceed 255.
-+
-+2006-05-02 Vesa Jaaskelainen <chaac@xxxxxx>
-+
-+ * stage2/shared.h (vbe_mode): Back ported aligment fix from GRUB 2
-+ to GRUB Legacy. Problem reported by Gerardo Richarte.
-+
-+2006-04-23 Robert Millan <robertmh@xxxxxxx>
-+
-+ * grub/asmstub.c (get_diskinfo): Optimize sysctl routine.
-+
-+2006-04-20 Robert Millan <robertmh@xxxxxxx>
-+
-+ Fixes for kernel of FreeBSD:
-+ * grub/asmstub.c (get_diskinfo): Toggle "kern.geom.debugflags" sysctl
-+ before opening a device for writing.
-+ * util/grub-install.in: Devices don't have this "r" prefix anymore.
-+
-+2006-04-16 Yoshinori K. Okuji <okuji@xxxxxxxxx>
-+
-+ * docs/multiboot.texi: Correct the offset of address
-+ fields. Reported by Jeroen Dekkers.
-+
-+2006-03-21 Yoshinori K. Okuji <okuji@xxxxxxxxx>
-+
-+ * stage2/builtins.c (setup_func): Specify the size of DEVICE to
-+ grub_strncat instead of a strange number 256. Reported by Vitaly
-+ Fertman <vitaly@xxxxxxxxxxx>.
-+
-+2005-09-29 Yoshinori K. Okuji <okuji@xxxxxxxxx>
-+
-+ * docs/multiboot.texi: Fix a bug in the byte order of
-+ boot_device. I hope this won't affect any OS image.
-+ Increased the version number to 0.6.94.
-+
-+2005-09-28 Yoshinori K. Okuji <okuji@xxxxxxxxx>
-+
-+ * stage2/boot.c (load_image): Even if an OS image is an ELF
-+ object, use the a.out kludge if MULTIBOOT_AOUT_KLUDGE is
-+ specified.
-+
- 2005-05-08 Yoshinori K. Okuji <okuji@xxxxxxxxx>
-
- * configure.ac (AC_INIT): Upgraded to 0.97.
-diff -uprN grub-0.97/configure grub/configure
---- grub-0.97/configure 2005-05-08 03:48:12.000000000 +0100
-+++ grub/configure 2007-11-05 01:29:46.000000000 +0000
-@@ -3694,6 +3694,64 @@ if test "x$undef_flag" = xyes; then
- CPPFLAGS="$CPPFLAGS -Wundef"
- fi
-
-+# Check if build ID can be disabled in the linker
-+echo "$as_me:$LINENO: checking whether linker accepts \`--build-id=none'" >&5
-+echo $ECHO_N "checking whether linker accepts \`--build-id=none'... $ECHO_C"
>&6
-+save_LDFLAGS="$LDFLAGS"
-+LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+cat >conftest.$ac_ext <<_ACEOF
-+/* confdefs.h. */
-+_ACEOF
-+cat confdefs.h >>conftest.$ac_ext
-+cat >>conftest.$ac_ext <<_ACEOF
-+/* end confdefs.h. */
-+
-+int
-+main ()
-+{
-+
-+ ;
-+ return 0;
-+}
-+_ACEOF
-+rm -f conftest.$ac_objext conftest$ac_exeext
-+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-+ (eval $ac_link) 2>conftest.er1
-+ ac_status=$?
-+ grep -v '^ *+' conftest.er1 >conftest.err
-+ rm -f conftest.er1
-+ cat conftest.err >&5
-+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
-+ (exit $ac_status); } &&
-+ { ac_try='test -z "$ac_c_werror_flag"
-+ || test ! -s conftest.err'
-+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-+ (eval $ac_try) 2>&5
-+ ac_status=$?
-+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
-+ (exit $ac_status); }; } &&
-+ { ac_try='test -s conftest$ac_exeext'
-+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-+ (eval $ac_try) 2>&5
-+ ac_status=$?
-+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
-+ (exit $ac_status); }; }; then
-+ build_id_flag=yes
-+else
-+ echo "$as_me: failed program was:" >&5
-+sed 's/^/| /' conftest.$ac_ext >&5
-+
-+build_id_flag=no
-+fi
-+rm -f conftest.err conftest.$ac_objext \
-+ conftest$ac_exeext conftest.$ac_ext
-+echo "$as_me:$LINENO: result: $build_id_flag" >&5
-+echo "${ECHO_T}$build_id_flag" >&6
-+LDFLAGS="$save_LDFLAGS"
-+if test "x$build_id_flag" = xyes; then
-+ LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+fi
-+
- if test "x$with_binutils" != x; then
- # Extract the first word of "objcopy", so it can be a program name with
args.
- set dummy objcopy; ac_word=$2
-@@ -3892,7 +3950,7 @@ echo "$as_me: error: ${CC-cc} cannot com
- fi
- grub_cv_prog_objcopy_absolute=yes
- for link_addr in 2000 8000 7C00; do
-- if { ac_try='${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr
conftest.o -o conftest.exec'
-+ if { ac_try='${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext
-Wl,$link_addr conftest.o -o conftest.exec'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
-diff -uprN grub-0.97/configure.ac grub/configure.ac
---- grub-0.97/configure.ac 2005-05-08 03:36:03.000000000 +0100
-+++ grub/configure.ac 2008-04-10 23:26:50.000000000 +0100
-@@ -86,13 +86,13 @@ if test "x$ac_cv_prog_gcc" = xyes; then
- fi
- STAGE1_CFLAGS="-O2"
- GRUB_CFLAGS="-O2"
-- AC_CACHE_CHECK([whether optimization for size works], size_flag, [
-+ AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
- saved_CFLAGS=$CFLAGS
- CFLAGS="-Os -g"
-- AC_TRY_COMPILE(, , size_flag=yes, size_flag=no)
-+ AC_TRY_COMPILE(, , grub_cv_cc_Os=yes, grub_cv_cc_Os=no)
- CFLAGS=$saved_CFLAGS
- ])
-- if test "x$size_flag" = xyes; then
-+ if test "x$grub_cv_cc_Os" = xyes; then
- STAGE2_CFLAGS="-Os"
- else
- STAGE2_CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops"
-@@ -100,16 +100,16 @@ if test "x$ac_cv_prog_gcc" = xyes; then
- # OpenBSD has a GCC extension for protecting applications from
- # stack smashing attacks, but GRUB doesn't want this feature.
- AC_CACHE_CHECK([whether gcc has -fno-stack-protector],
-- no_stack_protector_flag, [
-+ grub_cv_cc_no_stack_protector, [
- saved_CFLAGS=$CFLAGS
- CFLAGS="-fno-stack-protector"
- AC_TRY_COMPILE(,
- ,
-- no_stack_protector_flag=yes,
-- no_stack_protector_flag=no)
-+ grub_cv_cc_no_stack_protector=yes,
-+ grub_cv_cc_no_stack_protector=no)
- CFLAGS=$saved_CFLAGS
- ])
-- if test "x$no_stack_protector_flag" = xyes; then
-+ if test "x$grub_cv_cc_no_stack_protector" = xyes; then
- STAGE2_CFLAGS="$STAGE2_CFLAGS -fno-stack-protector"
- fi
- fi
-@@ -123,33 +123,44 @@ AC_SUBST(GRUB_CFLAGS)
- CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wunused -Wshadow"
- CPPFLAGS="$CPPFLAGS -Wpointer-arith"
-
--AC_CACHE_CHECK([whether -Wundef works], undef_flag, [
-+AC_CACHE_CHECK([whether -Wundef works], grub_cv_cc_Wundef, [
- saved_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="-Wundef"
-- AC_TRY_COMPILE(, , undef_flag=yes, undef_flag=no)
-+ AC_TRY_COMPILE(, , grub_cv_cc_Wundef=yes, grub_cv_cc_Wundef=no)
- CPPFLAGS="$saved_CPPFLAGS"
- ])
-
- # The options `-falign-*' are supported by gcc 3.0 or later.
- # Probably it is sufficient to only check for -falign-loops.
--AC_CACHE_CHECK([whether -falign-loops works], [falign_loop_flag], [
-+AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
- saved_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="-falign-loops=1"
-- AC_TRY_COMPILE(, , [falign_loop_flag=yes], [falign_loop_flag=no])
-+ AC_TRY_COMPILE(, , [grub_cv_cc_falign_loop=yes],
[grub_cv_cc_falign_loop=no])
- CPPFLAGS="$saved_CPPFLAGS"
- ])
-
- # Force no alignment to save space.
--if test "x$falign_loop_flag" = xyes; then
-+if test "x$grub_cv_cc_falign_loop" = xyes; then
- CPPFLAGS="$CPPFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
- else
- CPPFLAGS="$CPPFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
- fi
-
--if test "x$undef_flag" = xyes; then
-+if test "x$grub_cv_cc_Wundef" = xyes; then
- CPPFLAGS="$CPPFLAGS -Wundef"
- fi
-
-+# Check if build ID can be disabled in the linker
-+AC_MSG_CHECKING([whether linker accepts `--build-id=none'])
-+save_LDFLAGS="$LDFLAGS"
-+LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+AC_TRY_LINK(, , build_id_flag=yes, build_id_flag=no)
-+AC_MSG_RESULT([$build_id_flag])
-+LDFLAGS="$save_LDFLAGS"
-+if test "x$build_id_flag" = xyes; then
-+ LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+fi
-+
- if test "x$with_binutils" != x; then
- dnl AC_PATH_TOOL(OBJCOPY, objcopy, , "$with_binutils:$PATH")
- AC_PATH_PROG(OBJCOPY, objcopy, , "$with_binutils:$PATH")
-diff -uprN grub-0.97/grub/asmstub.c grub/grub/asmstub.c
---- grub-0.97/grub/asmstub.c 2005-02-16 20:45:14.000000000 +0000
-+++ grub/grub/asmstub.c 2008-03-28 13:22:28.000000000 +0000
-@@ -55,6 +55,10 @@ int grub_stage2 (void);
- # endif /* ! BLKFLSBUF */
- #endif /* __linux__ */
-
-+#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-+# include <sys/sysctl.h>
-+#endif
-+
- /* We want to prevent any circularararity in our stubs, as well as
- libc name clashes. */
- #define WITHOUT_LIBC_STUBS 1
-@@ -777,7 +781,39 @@ get_diskinfo (int drive, struct geometry
-
- /* Open read/write, or read-only if that failed. */
- if (! read_only)
-- disks[drive].flags = open (devname, O_RDWR);
-+ {
-+/* By default, kernel of FreeBSD does not allow overwriting MBR */
-+#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-+#define GEOM_SYSCTL "kern.geom.debugflags"
-+ int old_flags, flags;
-+ size_t sizeof_int = sizeof (int);
-+
-+ if (sysctlbyname (GEOM_SYSCTL, &old_flags, &sizeof_int, NULL, 0) != 0)
-+ grub_printf ("failed to get " GEOM_SYSCTL "sysctl: %s\n", strerror
(errno));
-+
-+ if ((old_flags & 0x10) == 0)
-+ {
-+ /* "allow foot shooting", see geom(4) */
-+ flags = old_flags | 0x10;
-+
-+ if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &flags, sizeof (int))
!= 0)
-+ {
-+ flags = old_flags;
-+ grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n",
strerror (errno));
-+ }
-+ }
-+ else
-+ flags = old_flags;
-+#endif
-+ disks[drive].flags = open (devname, O_RDWR);
-+#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-+ if (flags != old_flags)
-+ {
-+ if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &old_flags, sizeof
(int)) != 0)
-+ grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n",
strerror (errno));
-+ }
-+#endif
-+ }
-
- if (disks[drive].flags == -1)
- {
-@@ -926,7 +962,7 @@ hex_dump (void *buf, size_t size)
-
- int
- biosdisk (int subfunc, int drive, struct geometry *geometry,
-- int sector, int nsec, int segment)
-+ unsigned int sector, int nsec, int segment)
- {
- char *buf;
- int fd = geometry->flags;
-diff -uprN grub-0.97/grub/main.c grub/grub/main.c
---- grub-0.97/grub/main.c 2003-07-09 12:45:36.000000000 +0100
-+++ grub/grub/main.c 2006-05-05 22:43:46.000000000 +0100
-@@ -32,6 +32,7 @@ int grub_stage2 (void);
- #define WITHOUT_LIBC_STUBS 1
- #include <shared.h>
- #include <term.h>
-+#include <device.h>
-
- char *program_name = 0;
- int use_config_file = 1;
-@@ -192,6 +193,12 @@ main (int argc, char **argv)
- perror ("strtoul");
- exit (1);
- }
-+ if (boot_drive >= NUM_DISKS)
-+ {
-+ fprintf (stderr, "boot_drive should be from 0 to %d\n",
-+ NUM_DISKS - 1);
-+ exit (1);
-+ }
- break;
-
- case OPT_NO_CONFIG_FILE:
-diff -uprN grub-0.97/lib/device.c grub/lib/device.c
---- grub-0.97/lib/device.c 2005-03-28 00:14:25.000000000 +0100
-+++ grub/lib/device.c 2008-03-28 13:22:28.000000000 +0000
-@@ -69,9 +69,9 @@ struct hd_geometry
- # ifndef CDROM_GET_CAPABILITY
- # define CDROM_GET_CAPABILITY 0x5331 /* get capabilities */
- # endif /* ! CDROM_GET_CAPABILITY */
--# ifndef BLKGETSIZE
--# define BLKGETSIZE _IO(0x12,96) /* return device size */
--# endif /* ! BLKGETSIZE */
-+# ifndef BLKGETSIZE64
-+# define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size */
-+# endif /* ! BLKGETSIZE64 */
- #endif /* __linux__ */
-
- /* Use __FreeBSD_kernel__ instead of __FreeBSD__ for compatibility with
-@@ -152,19 +152,19 @@ get_drive_geometry (struct geometry *geo
- /* Linux */
- {
- struct hd_geometry hdg;
-- unsigned long nr;
-+ unsigned long long nr;
-
- if (ioctl (fd, HDIO_GETGEO, &hdg))
- goto fail;
-
-- if (ioctl (fd, BLKGETSIZE, &nr))
-+ if (ioctl (fd, BLKGETSIZE64, &nr))
- goto fail;
-
- /* Got the geometry, so save it. */
- geom->cylinders = hdg.cylinders;
- geom->heads = hdg.heads;
- geom->sectors = hdg.sectors;
-- geom->total_sectors = nr;
-+ geom->total_sectors = nr / 512;
-
- goto success;
- }
-@@ -407,6 +407,12 @@ get_ataraid_disk_name (char *name, int u
- {
- sprintf (name, "/dev/ataraid/d%c", unit + '0');
- }
-+
-+static void
-+get_i2o_disk_name (char *name, char unit)
-+{
-+ sprintf (name, "/dev/i2o/hd%c", unit);
-+}
- #endif
-
- /* Check if DEVICE can be read. If an error occurs, return zero,
-@@ -801,6 +807,29 @@ init_device_map (char ***map, const char
- }
- }
- }
-+
-+ /* This is for I2O - we have /dev/i2o/hd<logical drive><partition> */
-+ {
-+ int unit;
-+
-+ for (unit = 'a'; unit < 'f'; unit++)
-+ {
-+ char name[24];
-+
-+ get_i2o_disk_name (name, unit);
-+ if (check_device (name))
-+ {
-+ (*map)[num_hd + 0x80] = strdup (name);
-+ assert ((*map)[num_hd + 0x80]);
-+
-+ /* If the device map file is opened, write the map. */
-+ if (fp)
-+ fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
-+
-+ num_hd++;
-+ }
-+ }
-+ }
- #endif /* __linux__ */
-
- /* OK, close the device map file if opened. */
-@@ -861,6 +890,12 @@ write_to_partition (char **map, int driv
- if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
- strcpy (dev + strlen(dev) - 5, "/part");
- }
-+ else
-+ {
-+ if ((strncmp (dev, "/dev/ataraid/", 13) == 0) ||
-+ (strncmp (dev, "/dev/rd/", 8) == 0))
-+ strcpy (dev + strlen(dev), "p");
-+ }
- sprintf (dev + strlen(dev), "%d", ((partition >> 16) & 0xFF) + 1);
-
- /* Open the partition. */
-diff -uprN grub-0.97/netboot/3c509.c grub/netboot/3c509.c
---- grub-0.97/netboot/3c509.c 2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/3c509.c 2002-01-02 21:56:40.000000000 +0000
-@@ -18,7 +18,7 @@ Author: Martin Renters.
-
- 3c509 support added by Serge Babkin (babkin@xxxxxxxxxxxxxx)
-
--$Id: 3c509.c,v 1.4 2002/01/02 21:56:40 okuji Exp $
-+$Id: 3c509.c 609 2002-01-02 21:56:40Z okuji $
-
- ***************************************************************************/
-
-diff -uprN grub-0.97/netboot/cs89x0.c grub/netboot/cs89x0.c
---- grub-0.97/netboot/cs89x0.c 2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/cs89x0.c 2008-05-20 12:04:18.000000000 +0100
-@@ -1,3 +1,21 @@
-+/**
-+ Per an email message from Russ Nelson <nelson@xxxxxxxxxx> on
-+ 18 March 2008 this file is now licensed under GPL Version 2.
-+
-+ From: Russ Nelson <nelson@xxxxxxxxxx>
-+ Date: Tue, 18 Mar 2008 12:42:00 -0400
-+ Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
-+ -- quote from email
-+ As copyright holder, if I say it doesn't conflict with the GPL,
-+ then it doesn't conflict with the GPL.
-+
-+ However, there's no point in causing people's brains to overheat,
-+ so yes, I grant permission for the code to be relicensed under the
-+ GPLv2. Please make sure that this change in licensing makes its
-+ way upstream. -russ
-+ -- quote from email
-+**/
-+
- /* cs89x0.c: A Crystal Semiconductor CS89[02]0 driver for etherboot. */
- /*
- Permission is granted to distribute the enclosed cs89x0.[ch] driver
-diff -uprN grub-0.97/netboot/cs89x0.h grub/netboot/cs89x0.h
---- grub-0.97/netboot/cs89x0.h 2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/cs89x0.h 2008-05-20 12:04:18.000000000 +0100
-@@ -1,3 +1,21 @@
-+/**
-+ Per an email message from Russ Nelson <nelson@xxxxxxxxxx> on
-+ 18 March 2008 this file is now licensed under GPL Version 2.
-+
-+ From: Russ Nelson <nelson@xxxxxxxxxx>
-+ Date: Tue, 18 Mar 2008 12:42:00 -0400
-+ Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
-+ -- quote from email
-+ As copyright holder, if I say it doesn't conflict with the GPL,
-+ then it doesn't conflict with the GPL.
-+
-+ However, there's no point in causing people's brains to overheat,
-+ so yes, I grant permission for the code to be relicensed under the
-+ GPLv2. Please make sure that this change in licensing makes its
-+ way upstream. -russ
-+ -- quote from email
-+**/
-+
- /* Copyright, 1988-1992, Russell Nelson, Crynwr Software
-
- This program is free software; you can redistribute it and/or modify
-diff -uprN grub-0.97/netboot/etherboot.h grub/netboot/etherboot.h
---- grub-0.97/netboot/etherboot.h 2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/etherboot.h 2006-09-08 13:56:22.000000000 +0100
-@@ -531,9 +531,6 @@ extern int ip_abort;
- extern int network_ready;
- extern struct rom_info rom;
- extern struct arptable_t arptable[MAX_ARP];
--extern struct bootpd_t bootp_data;
--#define BOOTP_DATA_ADDR (&bootp_data)
--extern unsigned char *end_of_rfc1533;
-
- /* config.c */
- extern struct nic nic;
-diff -uprN grub-0.97/netboot/main.c grub/netboot/main.c
---- grub-0.97/netboot/main.c 2004-05-20 23:19:33.000000000 +0100
-+++ grub/netboot/main.c 2006-09-08 13:56:22.000000000 +0100
-@@ -56,7 +56,8 @@ static int vendorext_isvalid;
- static unsigned long netmask;
- static struct bootpd_t bootp_data;
- static unsigned long xid;
--static unsigned char *end_of_rfc1533 = NULL;
-+
-+#define BOOTP_DATA_ADDR (&bootp_data)
-
- #ifndef NO_DHCP_SUPPORT
- #endif /* NO_DHCP_SUPPORT */
-@@ -967,7 +968,6 @@ decode_rfc1533 (unsigned char *p, int bl
-
- if (block == 0)
- {
-- end_of_rfc1533 = NULL;
- vendorext_isvalid = 0;
-
- if (grub_memcmp (p, rfc1533_cookie, 4))
-@@ -1021,7 +1021,7 @@ decode_rfc1533 (unsigned char *p, int bl
- }
- else if (c == RFC1533_END)
- {
-- end_of_rfc1533 = endp = p;
-+ endp = p;
- continue;
- }
- else if (c == RFC1533_NETMASK)
-diff -uprN grub-0.97/netboot/natsemi.c grub/netboot/natsemi.c
---- grub-0.97/netboot/natsemi.c 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/natsemi.c 2006-09-10 08:26:10.000000000 +0100
-@@ -608,7 +608,7 @@ natsemi_transmit(struct nic *nic,
- const char *p) /* Packet */
- {
- u32 status, to, nstype;
-- u32 tx_status;
-+ volatile u32 tx_status;
-
- /* Stop the transmitter */
- outl(TxOff, ioaddr + ChipCmd);
-@@ -647,7 +647,7 @@ natsemi_transmit(struct nic *nic,
-
- to = currticks() + TX_TIMEOUT;
-
-- while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() <
to))
-+ while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
- /* wait */ ;
-
- if (currticks() >= to) {
-diff -uprN grub-0.97/netboot/sis900.c grub/netboot/sis900.c
---- grub-0.97/netboot/sis900.c 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/sis900.c 2006-09-10 08:26:10.000000000 +0100
-@@ -901,7 +901,7 @@ sis900_transmit(struct nic *nic,
- const char *p) /* Packet */
- {
- u32 status, to, nstype;
-- u32 tx_status;
-+ volatile u32 tx_status;
-
- /* Stop the transmitter */
- outl(TxDIS, ioaddr + cr);
-@@ -940,7 +940,7 @@ sis900_transmit(struct nic *nic,
-
- to = currticks() + TX_TIMEOUT;
-
-- while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() <
to))
-+ while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
- /* wait */ ;
-
- if (currticks() >= to) {
-diff -uprN grub-0.97/netboot/sk_g16.c grub/netboot/sk_g16.c
---- grub-0.97/netboot/sk_g16.c 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/sk_g16.c 2002-01-02 21:56:40.000000000 +0000
-@@ -13,12 +13,12 @@ Changes to make it work with Etherboot b
- *
- * Module : sk_g16.c
- *
-- * Version : $Revision: 1.4 $
-+ * Version : $Revision: 609 $
- *
- * Author : Patrick J.D. Weichmann
- *
- * Date Created : 94/05/26
-- * Last Updated : $Date: 2002/01/02 21:56:40 $
-+ * Last Updated : $Date: 2002-01-02 21:56:40 +0000 (mer 02 jan 2002) $
- *
- * Description : Schneider & Koch G16 Ethernet Device Driver for
- * Linux Kernel >= 1.1.22
-diff -uprN grub-0.97/netboot/sk_g16.h grub/netboot/sk_g16.h
---- grub-0.97/netboot/sk_g16.h 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/sk_g16.h 2000-07-29 20:22:54.000000000 +0100
-@@ -4,7 +4,7 @@
- * of the GNU Public License, incorporated herein by reference.
- *
- * Module : sk_g16.h
-- * Version : $Revision: 1.3 $
-+ * Version : $Revision: 388 $
- *
- * Author : M.Hipp (mhipp@xxxxxxxxxxxxxxxxxxxxxxxx)
- * changes by : Patrick J.D. Weichmann
-@@ -15,8 +15,8 @@
- * the am7990 (LANCE) chip used for writing a
- * network device driver which uses this chip
- *
-- * $Log: sk_g16.h,v $
-- * Revision 1.3 2000/07/29 19:22:54 okuji
-+ * $Log$
-+ * Revision 1.3 2000-07-29 19:22:54 okuji
- * update the network support to etherboot-4.6.4.
- *
- -*/
-diff -uprN grub-0.97/stage1/Makefile.am grub/stage1/Makefile.am
---- grub-0.97/stage1/Makefile.am 2004-07-16 12:44:56.000000000 +0100
-+++ grub/stage1/Makefile.am 2007-11-05 01:29:46.000000000 +0000
-@@ -5,7 +5,7 @@ CLEANFILES = $(nodist_pkglib_DATA)
-
- # We can't use builtins or standard includes.
- AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
--LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
-+stage1_exec_LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
-
- noinst_PROGRAMS = stage1.exec
- stage1_exec_SOURCES = stage1.S stage1.h
-diff -uprN grub-0.97/stage1/Makefile.in grub/stage1/Makefile.in
---- grub-0.97/stage1/Makefile.in 2005-05-08 03:42:36.000000000 +0100
-+++ grub/stage1/Makefile.in 2007-11-05 01:29:46.000000000 +0000
-@@ -110,7 +110,7 @@ INSTALL_DATA = @INSTALL_DATA@
- INSTALL_PROGRAM = @INSTALL_PROGRAM@
- INSTALL_SCRIPT = @INSTALL_SCRIPT@
- INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
--LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
-+LDFLAGS = @LDFLAGS@
- LIBOBJS = @LIBOBJS@
- LIBS = @LIBS@
- LTLIBOBJS = @LTLIBOBJS@
-@@ -188,6 +188,7 @@ CLEANFILES = $(nodist_pkglib_DATA)
-
- # We can't use builtins or standard includes.
- AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
-+stage1_exec_LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
- stage1_exec_SOURCES = stage1.S stage1.h
- SUFFIXES = .exec
- all: all-am
-diff -uprN grub-0.97/stage2/bios.c grub/stage2/bios.c
---- grub-0.97/stage2/bios.c 2004-03-27 16:34:04.000000000 +0000
-+++ grub/stage2/bios.c 2008-03-28 13:22:28.000000000 +0000
-@@ -47,7 +47,7 @@ extern int get_diskinfo_floppy (int driv
- return the error number. Otherwise, return 0. */
- int
- biosdisk (int read, int drive, struct geometry *geometry,
-- int sector, int nsec, int segment)
-+ unsigned int sector, int nsec, int segment)
- {
- int err;
-
-diff -uprN grub-0.97/stage2/boot.c grub/stage2/boot.c
---- grub-0.97/stage2/boot.c 2004-03-30 12:44:08.000000000 +0100
-+++ grub/stage2/boot.c 2005-09-28 22:47:55.000000000 +0100
-@@ -1,7 +1,7 @@
- /* boot.c - load and bootstrap a kernel */
- /*
- * GRUB -- GRand Unified Bootloader
-- * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation,
Inc.
-+ * Copyright (C) 1999,2000,2001,2002,2003,2004,2005 Free Software
Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
-@@ -96,7 +96,7 @@ load_image (char *kernel, char *arg, ker
- lh = (struct linux_kernel_header *) buffer;
-
- /* ELF loading supported if multiboot, FreeBSD and NetBSD. */
-- if ((type == KERNEL_TYPE_MULTIBOOT
-+ if (((type == KERNEL_TYPE_MULTIBOOT && ! (flags & MULTIBOOT_AOUT_KLUDGE))
- || pu.elf->e_ident[EI_OSABI] == ELFOSABI_FREEBSD
- || grub_strcmp (pu.elf->e_ident + EI_BRAND, "FreeBSD") == 0
- || suggested_type == KERNEL_TYPE_NETBSD)
-diff -uprN grub-0.97/stage2/builtins.c grub/stage2/builtins.c
---- grub-0.97/stage2/builtins.c 2005-02-15 21:58:23.000000000 +0000
-+++ grub/stage2/builtins.c 2006-03-21 20:51:58.000000000 +0000
-@@ -3830,15 +3830,15 @@ setup_func (char *arg, int flags)
- {
- char tmp[16];
- grub_sprintf (tmp, ",%d", (partition >> 16) & 0xFF);
-- grub_strncat (device, tmp, 256);
-+ grub_strncat (device, tmp, sizeof (device));
- }
- if ((partition & 0x00FF00) != 0x00FF00)
- {
- char tmp[16];
- grub_sprintf (tmp, ",%c", 'a' + ((partition >> 8) & 0xFF));
-- grub_strncat (device, tmp, 256);
-+ grub_strncat (device, tmp, sizeof (device));
- }
-- grub_strncat (device, ")", 256);
-+ grub_strncat (device, ")", sizeof (device));
- }
-
- int embed_stage1_5 (char *stage1_5, int drive, int partition)
-diff -uprN grub-0.97/stage2/disk_io.c grub/stage2/disk_io.c
---- grub-0.97/stage2/disk_io.c 2004-05-23 17:35:24.000000000 +0100
-+++ grub/stage2/disk_io.c 2008-03-28 13:22:28.000000000 +0000
-@@ -137,7 +137,7 @@ log2 (unsigned long word)
- }
-
- int
--rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
-+rawread (int drive, unsigned int sector, int byte_offset, int byte_len, char
*buf)
- {
- int slen, sectors_per_vtrack;
- int sector_size_bits = log2 (buf_geom.sector_size);
-@@ -261,7 +261,7 @@ rawread (int drive, int sector, int byte
- */
- if (disk_read_func)
- {
-- int sector_num = sector;
-+ unsigned int sector_num = sector;
- int length = buf_geom.sector_size - byte_offset;
- if (length > size)
- length = size;
-@@ -291,7 +291,7 @@ rawread (int drive, int sector, int byte
-
-
- int
--devread (int sector, int byte_offset, int byte_len, char *buf)
-+devread (unsigned int sector, int byte_offset, int byte_len, char *buf)
- {
- /*
- * Check partition boundaries
-@@ -330,7 +330,7 @@ devread (int sector, int byte_offset, in
-
- #ifndef STAGE1_5
- int
--rawwrite (int drive, int sector, char *buf)
-+rawwrite (int drive, unsigned int sector, char *buf)
- {
- if (sector == 0)
- {
-@@ -363,7 +363,7 @@ rawwrite (int drive, int sector, char *b
- }
-
- int
--devwrite (int sector, int sector_count, char *buf)
-+devwrite (unsigned int sector, int sector_count, char *buf)
- {
- #if defined(GRUB_UTIL) && defined(__linux__)
- if (current_partition != 0xFFFFFF
-diff -uprN grub-0.97/stage2/fsys_ffs.c grub/stage2/fsys_ffs.c
---- grub-0.97/stage2/fsys_ffs.c 2003-07-09 12:45:52.000000000 +0100
-+++ grub/stage2/fsys_ffs.c 2001-11-12 06:57:29.000000000 +0000
-@@ -50,7 +50,7 @@
- * the rights to redistribute these changes.
- *
- * from: Mach, Revision 2.2 92/04/04 11:35:49 rpd
-- * $Id: fsys_ffs.c,v 1.10 2001/11/12 06:57:29 okuji Exp $
-+ * $Id: fsys_ffs.c 594 2001-11-12 06:57:29Z okuji $
- */
-
- #ifdef FSYS_FFS
-diff -uprN grub-0.97/stage2/fsys_ufs2.c grub/stage2/fsys_ufs2.c
---- grub-0.97/stage2/fsys_ufs2.c 2004-06-19 13:17:52.000000000 +0100
-+++ grub/stage2/fsys_ufs2.c 2004-06-19 13:17:52.000000000 +0100
-@@ -51,7 +51,7 @@
- * the rights to redistribute these changes.
- *
- * from: Mach, Revision 2.2 92/04/04 11:35:49 rpd
-- * $Id: fsys_ufs2.c,v 1.2 2004/06/19 12:17:52 okuji Exp $
-+ * $Id: fsys_ufs2.c 841 2004-06-19 12:17:52Z okuji $
- */
-
- #ifdef FSYS_UFS2
-diff -uprN grub-0.97/stage2/imgact_aout.h grub/stage2/imgact_aout.h
---- grub-0.97/stage2/imgact_aout.h 2003-07-09 12:45:53.000000000 +0100
-+++ grub/stage2/imgact_aout.h 1999-06-24 01:03:29.000000000 +0100
-@@ -32,7 +32,7 @@
- * SUCH DAMAGE.
- *
- * from: @(#)exec.h 8.1 (Berkeley) 6/11/93
-- * $Id: imgact_aout.h,v 1.1 1999/06/24 00:03:22 okuji Exp $
-+ * $Id: imgact_aout.h 98 1999-06-24 00:03:29Z okuji $
- */
- /*
- * 11/23/95 - Kludge to get "ntohl" null macro added. -- ESB
-diff -uprN grub-0.97/stage2/iso9660.h grub/stage2/iso9660.h
---- grub-0.97/stage2/iso9660.h 2004-03-27 16:02:38.000000000 +0000
-+++ grub/stage2/iso9660.h 2007-02-22 23:40:25.000000000 +0000
-@@ -73,11 +73,11 @@ typedef union {
-
- typedef struct __iso_16bit {
- u_int16_t l, b;
--} iso_16bit_t __attribute__ ((packed));
-+} iso_16bit_t;
-
- typedef struct __iso_32bit {
- u_int32_t l, b;
--} iso_32bit_t __attribute__ ((packed));
-+} iso_32bit_t;
-
- typedef u_int8_t iso_date_t[7];
-
-diff -uprN grub-0.97/stage2/shared.h grub/stage2/shared.h
---- grub-0.97/stage2/shared.h 2004-06-19 17:40:09.000000000 +0100
-+++ grub/stage2/shared.h 2008-03-28 13:22:28.000000000 +0000
-@@ -499,7 +499,11 @@ struct vbe_mode
- unsigned char linear_reserved_field_position;
- unsigned long max_pixel_clock;
-
-- unsigned char reserved3[189];
-+ /* Reserved field to make structure to be 256 bytes long, VESA BIOS
-+ Extension 3.0 Specification says to reserve 189 bytes here but
-+ that doesn't make structure to be 256 bytes. So additional one is
-+ added here. */
-+ unsigned char reserved3[189 + 1];
- } __attribute__ ((packed));
-
-
-@@ -807,7 +811,7 @@ int checkkey (void);
- /* Low-level disk I/O */
- int get_diskinfo (int drive, struct geometry *geometry);
- int biosdisk (int subfunc, int drive, struct geometry *geometry,
-- int sector, int nsec, int segment);
-+ unsigned int sector, int nsec, int segment);
- void stop_floppy (void);
-
- /* Command-line interface functions. */
-@@ -920,10 +924,10 @@ int gunzip_test_header (void);
- int gunzip_read (char *buf, int len);
- #endif /* NO_DECOMPRESSION */
-
--int rawread (int drive, int sector, int byte_offset, int byte_len, char *buf);
--int devread (int sector, int byte_offset, int byte_len, char *buf);
--int rawwrite (int drive, int sector, char *buf);
--int devwrite (int sector, int sector_len, char *buf);
-+int rawread (int drive, unsigned int sector, int byte_offset, int byte_len,
char *buf);
-+int devread (unsigned int sector, int byte_offset, int byte_len, char *buf);
-+int rawwrite (int drive, unsigned int sector, char *buf);
-+int devwrite (unsigned int sector, int sector_len, char *buf);
-
- /* Parse a device string and initialize the global parameters. */
- char *set_device (char *device);
-diff -uprN grub-0.97/stage2/stage2.c grub/stage2/stage2.c
---- grub-0.97/stage2/stage2.c 2005-03-19 17:51:57.000000000 +0000
-+++ grub/stage2/stage2.c 2006-05-05 23:06:31.000000000 +0100
-@@ -651,7 +651,10 @@ restart:
- *(new_heap++) = 0;
-
- if (config_entries)
-- run_menu (heap, NULL, new_num_entries, new_heap, 0);
-+ {
-+ current_entryno = first_entry + entryno;
-+ run_menu (heap, NULL, new_num_entries, new_heap, 0);
-+ }
- else
- {
- cls ();
-@@ -727,7 +730,8 @@ restart:
- cur_entry = get_entry (config_entries, first_entry + entryno, 1);
-
- /* Set CURRENT_ENTRYNO for the command "savedefault". */
-- current_entryno = first_entry + entryno;
-+ if (config_entries)
-+ current_entryno = first_entry + entryno;
-
- if (run_script (cur_entry, heap))
- {
-diff -uprN grub-0.97/stage2/tparm.c grub/stage2/tparm.c
---- grub-0.97/stage2/tparm.c 2003-07-09 12:45:53.000000000 +0100
-+++ grub/stage2/tparm.c 2002-11-29 20:39:24.000000000 +0000
-@@ -63,7 +63,7 @@ typedef char grub_bool;
- #define MAX_FORMAT_LEN 256
- #define max(a,b) ((a) > (b) ? (a) : (b))
-
--//MODULE_ID("$Id: tparm.c,v 1.1 2002/11/29 20:39:24 okuji Exp $")
-+//MODULE_ID("$Id: tparm.c 708 2002-11-29 20:39:24Z okuji $")
-
- /*
- * char *
-diff -uprN grub-0.97/stamp-h.in grub/stamp-h.in
---- grub-0.97/stamp-h.in 1970-01-01 01:00:00.000000000 +0100
-+++ grub/stamp-h.in 1999-09-13 14:32:31.000000000 +0100
-@@ -0,0 +1 @@
-+timestamp
-diff -uprN grub-0.97/THANKS grub/THANKS
---- grub-0.97/THANKS 2005-05-08 03:17:43.000000000 +0100
-+++ grub/THANKS 2006-03-21 20:51:58.000000000 +0000
-@@ -121,3 +121,4 @@ Vesa Jaaskelainen <jaaskela@tietomyrsky.
- Yedidyah Bar-David <didi@xxxxxxxxxxxxxx>
- Yury V. Umanets <umka@xxxxxxxxxxx>
- Yuri Zaporogets <yuriz@xxxxxxx>
-+Vitaly Fertman <vitaly@xxxxxxxxxxx>
-diff -uprN grub-0.97/util/grub-install.in grub/util/grub-install.in
---- grub-0.97/util/grub-install.in 2004-07-24 19:57:31.000000000 +0100
-+++ grub/util/grub-install.in 2006-04-20 14:46:46.000000000 +0100
-@@ -112,8 +112,8 @@ convert () {
- tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
- tmp_part=`echo "$1" | sed "s%$tmp_disk%%"` ;;
- freebsd* | kfreebsd*-gnu)
-- tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%r\1%' \
-- | sed 's%r\{0,1\}\(da[0-9]*\).*$%r\1%'`
-+ tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%\1%' \
-+ | sed 's%r\{0,1\}\(da[0-9]*\).*$%\1%'`
- tmp_part=`echo "$1" \
- | sed "s%.*/r\{0,1\}[saw]d[0-9]\(s[0-9]*[a-h]\)%\1%" \
- | sed "s%.*/r\{0,1\}da[0-9]\(s[0-9]*[a-h]\)%\1%"`
-diff -uprN grub-0.97/util/mkbimage grub/util/mkbimage
---- grub-0.97/util/mkbimage 2004-07-24 19:57:31.000000000 +0100
-+++ grub/util/mkbimage 2007-02-22 16:01:03.000000000 +0000
-@@ -1,7 +1,7 @@
- #!/bin/sh
- # MaKe a Bootable IMAGE --- 1.44, 2.88 and El Torito no-emulation mode
- # C) 2001,2002,2003 Thierry Laronde <tlaronde@xxxxxxxxxxx>
--# C) 2001,2002,2003 Robert Millan <robertmh@xxxxxxx>
-+# C) 2001,2002,2003 Robert Millan <rmh@xxxxxxxxxxx>
-
-
- # This program is free software; you can redistribute it and/or modify
-@@ -19,7 +19,7 @@
- # program's maintainer or write to: The Free Software Foundation,
- # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
-
--# $Id: mkbimage,v 1.19 2004/07/21 14:43:04 robertmh Exp $
-+# $Id: mkbimage 1233 2007-02-22 16:01:03Z robertmh $
-
- # Global variables
- tarfile=
-@@ -58,7 +58,7 @@ stage2_os_name=
-
- # Name by which this script was invoked.
- program=`echo "$0" | sed -e 's/[^\/]*\///g'`
--version_number='$Revision: 1.19 $'
-+version_number='$Revision: 1233 $'
-
- usage="
- Usage: $program [-hVF] [-t TYPE] [-d DIRECTORY] [-s FS_TYPE] -f TAR_FILE
-@@ -94,15 +94,13 @@ Options:
- display Version information and exit
-
- Copyright (c) 2001,2002,2003 Thierry Laronde <tlaronde@xxxxxxxxxxx>.
--Copyright (c) 2001,2002 Robert Millan <zeratul2@xxxxxxxxxx>.
- GPLed."
-
- version="mkbimage $version_number
-
--Written by Thierry Laronde and Robert Millan.
-+Written by Thierry Laronde.
-
- Copyright (c) 2001,2002,2003 Thierry Laronde <tlaronde@xxxxxxxxxxx>.
--Copyright (c) 2001,2002,2003 Robert Millan <zeratul2@xxxxxxxxxx>.
-
- This is free software under the GPL version 2 or later; see the source for
- copying conditions. There is NO warranty, not even for MERCHANTABILITY or
diff --git a/stubdom/grub.patches/10graphics.diff
b/stubdom/grub.patches/10graphics.diff
deleted file mode 100644
index 5ee2852fd7..0000000000
--- a/stubdom/grub.patches/10graphics.diff
+++ /dev/null
@@ -1,2297 +0,0 @@
-diff -Naur grub-0.97.orig/configure.ac grub-0.97/configure.ac
---- grub-0.97.orig/configure.ac 2005-05-07 23:36:03.000000000 -0300
-+++ grub-0.97/configure.ac 2005-06-12 20:56:49.000000000 -0300
-@@ -595,6 +595,11 @@
- [ --enable-diskless enable diskless support])
- AM_CONDITIONAL(DISKLESS_SUPPORT, test "x$enable_diskless" = xyes)
-
-+dnl Graphical splashscreen support
-+AC_ARG_ENABLE(graphics,
-+ [ --disable-graphics disable graphics terminal support])
-+AM_CONDITIONAL(GRAPHICS_SUPPORT, test "x$enable_graphics" != xno)
-+
- dnl Hercules terminal
- AC_ARG_ENABLE(hercules,
- [ --disable-hercules disable hercules terminal support])
-diff -Naur grub-0.97.orig/stage2/asm.S grub-0.97/stage2/asm.S
---- grub-0.97.orig/stage2/asm.S 2004-06-19 13:55:22.000000000 -0300
-+++ grub-0.97/stage2/asm.S 2005-06-13 14:05:31.000000000 -0300
-@@ -2216,7 +2216,304 @@
- pop %ebx
- pop %ebp
- ret
--
-+
-+
-+/* graphics mode functions */
-+#ifdef SUPPORT_GRAPHICS
-+VARIABLE(cursorX)
-+.word 0
-+VARIABLE(cursorY)
-+.word 0
-+VARIABLE(cursorCount)
-+.word 0
-+VARIABLE(cursorBuf)
-+.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-+
-+
-+/*
-+ * set_int1c_handler(void)
-+ */
-+ENTRY(set_int1c_handler)
-+ pushl %edi
-+
-+ /* save the original int1c handler */
-+ movl $0x70, %edi
-+ movw (%edi), %ax
-+ movw %ax, ABS(int1c_offset)
-+ movw 2(%edi), %ax
-+ movw %ax, ABS(int1c_segment)
-+
-+ /* save the new int1c handler */
-+ movw $ABS(int1c_handler), %ax
-+ movw %ax, (%edi)
-+ xorw %ax, %ax
-+ movw %ax, 2(%edi)
-+
-+ popl %edi
-+ ret
-+
-+
-+/*
-+ * unset_int1c_handler(void)
-+ */
-+ENTRY(unset_int1c_handler)
-+ pushl %edi
-+
-+ /* check if int1c_handler is set */
-+ movl $0x70, %edi
-+ movw $ABS(int1c_handler), %ax
-+ cmpw %ax, (%edi)
-+ jne int1c_1
-+ xorw %ax, %ax
-+ cmpw %ax, 2(%edi)
-+ jne int1c_1
-+
-+ /* restore the original */
-+ movw ABS(int1c_offset), %ax
-+ movw %ax, (%edi)
-+ movw ABS(int1c_segment), %ax
-+ movw %ax, 2(%edi)
-+
-+int1c_1:
-+ popl %edi
-+ ret
-+
-+
-+/*
-+ * blinks graphics cursor
-+ */
-+ .code16
-+write_data:
-+ movw $0, %ax
-+ movw %ax, %ds
-+
-+ mov $0xA000, %ax /* video in es:di */
-+ mov %ax, %es
-+ mov $80, %ax
-+ movw $ABS(cursorY), %si
-+ mov %ds:(%si), %bx
-+ mul %bx
-+ movw $ABS(cursorX), %si
-+ mov %ds:(%si), %bx
-+ shr $3, %bx /* %bx /= 8 */
-+ add %bx, %ax
-+ mov %ax, %di
-+
-+ movw $ABS(cursorBuf), %si /* fontBuf in ds:si */
-+
-+ /* prepare for data moving */
-+ mov $16, %dx /* altura da fonte */
-+ mov $80, %bx /* bytes por linha */
-+
-+write_loop:
-+ movb %ds:(%si), %al
-+ xorb $0xff, %al
-+ movb %al, %ds:(%si) /* invert cursorBuf */
-+ movb %al, %es:(%di) /* write to video */
-+ add %bx, %di
-+ inc %si
-+ dec %dx
-+ jg write_loop
-+ ret
-+
-+int1c_handler:
-+ pusha
-+ mov $0, %ax
-+ mov %ax, %ds
-+ mov $ABS(cursorCount), %si
-+ mov %ds:(%si), %ax
-+ inc %ax
-+ mov %ax, %ds:(%si)
-+ cmp $9, %ax
-+ jne int1c_done
-+
-+ mov $0, %ax
-+ mov %ax, %ds:(%si)
-+ call write_data
-+
-+int1c_done:
-+ popa
-+ iret
-+ /* call previous int1c handler */
-+ /* ljmp */
-+ .byte 0xea
-+int1c_offset: .word 0
-+int1c_segment: .word 0
-+ .code32
-+
-+
-+/*
-+ * unsigned char set_videomode(unsigned char mode)
-+ * BIOS call "INT 10H Function 0h" to set video mode
-+ * Call with %ah = 0x0
-+ * %al = video mode
-+ * Returns old videomode.
-+ */
-+ENTRY(set_videomode)
-+ pushl %ebp
-+ movl %esp,%ebp
-+ pushl %ebx
-+ pushl %ecx
-+
-+ movb 8(%ebp), %cl
-+
-+ call EXT_C(prot_to_real)
-+ .code16
-+
-+ xorb %al, %al
-+ movb $0xf, %ah
-+ int $0x10 /* Get Current Video mode */
-+ movb %al, %ch
-+ xorb %ah, %ah
-+ movb %cl, %al
-+ int $0x10 /* Set Video mode */
-+
-+ DATA32 call EXT_C(real_to_prot)
-+ .code32
-+
-+ xorl %eax, %eax
-+ movb %ch, %al
-+
-+ popl %ecx
-+ popl %ebx
-+ popl %ebp
-+ ret
-+
-+
-+/*
-+ * int get_videomode()
-+ * BIOS call "INT 10H Function 0Fh" to get current video mode
-+ * Call with %al = 0x0
-+ * %ah = 0xF
-+ * Returns current videomode.
-+ */
-+ENTRY(get_videomode)
-+ pushl %ebp
-+ movl %esp,%ebp
-+ pushl %ebx
-+ pushl %ecx
-+
-+ call EXT_C(prot_to_real)
-+ .code16
-+
-+ xorb %al, %al
-+ movb $0xF, %ah
-+ int $0x10 /* Get Current Video mode */
-+ movb %al, %cl /* For now we only want display mode */
-+
-+ DATA32 call EXT_C(real_to_prot)
-+ .code32
-+
-+ xorl %eax, %eax
-+ movb %cl, %al
-+
-+ popl %ecx
-+ popl %ebx
-+ popl %ebp
-+ ret
-+
-+
-+/*
-+ * unsigned char * graphics_get_font()
-+ * BIOS call "INT 10H Function 11h" to set font
-+ * Call with %ah = 0x11
-+ */
-+ENTRY(graphics_get_font)
-+ push %ebp
-+ push %ebx
-+ push %ecx
-+ push %edx
-+
-+ call EXT_C(prot_to_real)
-+ .code16
-+
-+ movw $0x1130, %ax
-+ movb $6, %bh /* font 8x16 */
-+ int $0x10
-+ movw %bp, %dx
-+ movw %es, %cx
-+
-+ DATA32 call EXT_C(real_to_prot)
-+ .code32
-+
-+ xorl %eax, %eax
-+ movw %cx, %ax
-+ shll $4, %eax
-+ movw %dx, %ax
-+
-+ pop %edx
-+ pop %ecx
-+ pop %ebx
-+ pop %ebp
-+ ret
-+
-+
-+/*
-+ * graphics_set_palette(index, red, green, blue)
-+ * BIOS call "INT 10H Function 10h" to set individual dac register
-+ * Call with %ah = 0x10
-+ * %bx = register number
-+ * %ch = new value for green (0-63)
-+ * %cl = new value for blue (0-63)
-+ * %dh = new value for red (0-63)
-+ */
-+
-+ENTRY(graphics_set_palette)
-+ push %ebp
-+ push %eax
-+ push %ebx
-+ push %ecx
-+ push %edx
-+
-+ movw $0x3c8, %bx /* address write mode register */
-+
-+ /* wait vertical retrace */
-+ movw $0x3da, %dx
-+l1b:
-+ inb %dx, %al /* wait vertical active display */
-+ test $8, %al
-+ jnz l1b
-+
-+l2b:
-+ inb %dx, %al /* wait vertical retrace */
-+ test $8, %al
-+ jnz l2b
-+
-+ mov %bx, %dx
-+ movb 0x18(%esp), %al /* index */
-+ outb %al, %dx
-+ inc %dx
-+
-+ movb 0x1c(%esp), %al /* red */
-+ outb %al, %dx
-+
-+ movb 0x20(%esp), %al /* green */
-+ outb %al, %dx
-+
-+ movb 0x24(%esp), %al /* blue */
-+ outb %al, %dx
-+
-+ movw 0x18(%esp), %bx
-+
-+ call EXT_C(prot_to_real)
-+ .code16
-+
-+ movb %bl, %bh
-+ movw $0x1000, %ax
-+ int $0x10
-+
-+ DATA32 call EXT_C(real_to_prot)
-+ .code32
-+
-+ pop %edx
-+ pop %ecx
-+ pop %ebx
-+ pop %eax
-+ pop %ebp
-+ ret
-+#endif /* SUPPORT_GRAPHICS */
-+
-+
- /*
- * getrtsecs()
- * if a seconds value can be read, read it and return it (BCD),
-diff -Naur grub-0.97.orig/stage2/builtins.c grub-0.97/stage2/builtins.c
---- grub-0.97.orig/stage2/builtins.c 2005-02-15 19:58:23.000000000 -0200
-+++ grub-0.97/stage2/builtins.c 2005-06-13 18:44:03.000000000 -0300
-@@ -28,6 +28,10 @@
- #include <filesys.h>
- #include <term.h>
-
-+#ifdef SUPPORT_GRAPHICS
-+# include <graphics.h>
-+#endif
-+
- #ifdef SUPPORT_NETBOOT
- # define GRUB 1
- # include <etherboot.h>
-@@ -237,12 +241,22 @@
- static int
- boot_func (char *arg, int flags)
- {
-+ struct term_entry *prev_term = current_term;
- /* Clear the int15 handler if we can boot the kernel successfully.
- This assumes that the boot code never fails only if KERNEL_TYPE is
- not KERNEL_TYPE_NONE. Is this assumption is bad? */
- if (kernel_type != KERNEL_TYPE_NONE)
- unset_int15_handler ();
-
-+ /* if our terminal needed initialization, we should shut it down
-+ * before booting the kernel, but we want to save what it was so
-+ * we can come back if needed */
-+ if (current_term->shutdown)
-+ {
-+ current_term->shutdown();
-+ current_term = term_table; /* assumption: console is first */
-+ }
-+
- #ifdef SUPPORT_NETBOOT
- /* Shut down the networking. */
- cleanup_net ();
-@@ -306,6 +320,13 @@
- return 1;
- }
-
-+ /* if we get back here, we should go back to what our term was before */
-+ current_term = prev_term;
-+ if (current_term->startup)
-+ /* if our terminal fails to initialize, fall back to console since
-+ * it should always work */
-+ if (current_term->startup() == 0)
-+ current_term = term_table; /* we know that console is first */
- return 0;
- }
-
-@@ -852,6 +873,251 @@
- };
- #endif /* SUPPORT_NETBOOT */
-
-+#ifdef SUPPORT_GRAPHICS
-+
-+static int splashimage_func(char *arg, int flags) {
-+ int i;
-+
-+ /* filename can only be 256 characters due to our buffer size */
-+ if (grub_strlen(arg) > 256) {
-+ grub_printf("Splash image filename too large\n");
-+ grub_printf("Press any key to continue...");
-+ getkey();
-+ return 1;
-+ }
-+
-+ /* get rid of TERM_NEED_INIT from the graphics terminal. */
-+ for (i = 0; term_table[i].name; i++) {
-+ if (grub_strcmp (term_table[i].name, "graphics") == 0) {
-+ term_table[i].flags &= ~TERM_NEED_INIT;
-+ break;
-+ }
-+ }
-+
-+ graphics_set_splash(arg);
-+
-+ if (flags == BUILTIN_CMDLINE && graphics_inited) {
-+ graphics_end();
-+ if (graphics_init() == 0) {
-+ /* Fallback to default term */
-+ current_term = term_table;
-+ max_lines = current_term->max_lines;
-+ if (current_term->cls)
-+ current_term->cls();
-+ grub_printf("Failed to set splash image and/or graphics mode\n");
-+ return 1;
-+ }
-+ graphics_cls();
-+ }
-+
-+ if (flags == BUILTIN_MENU)
-+ current_term = term_table + i;
-+
-+ return 0;
-+}
-+
-+static struct builtin builtin_splashimage =
-+{
-+ "splashimage",
-+ splashimage_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+ "splashimage FILE",
-+ "Load FILE as the background image when in graphics mode."
-+};
-+
-+
-+/* shade */
-+static int
-+shade_func(char *arg, int flags)
-+{
-+ int new_shade;
-+
-+ if (!arg || safe_parse_maxint(&arg, &new_shade) == 0)
-+ return (1);
-+
-+ if (shade != new_shade) {
-+ shade = new_shade;
-+ if (flags == BUILTIN_CMDLINE && graphics_inited) {
-+ graphics_end();
-+ graphics_init();
-+ graphics_cls();
-+ }
-+ }
-+
-+ return 0;
-+}
-+
-+static struct builtin builtin_shade =
-+{
-+ "shade",
-+ shade_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+ "shade INTEGER",
-+ "If set to 0, disables the use of shaded text, else enables it."
-+};
-+
-+
-+/* foreground */
-+static int
-+foreground_func(char *arg, int flags)
-+{
-+ if (grub_strlen(arg) == 6) {
-+ int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
-+ int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
-+ int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
-+
-+ foreground = (r << 16) | (g << 8) | b;
-+ if (graphics_inited)
-+ graphics_set_palette(15, r, g, b);
-+
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct builtin builtin_foreground =
-+{
-+ "foreground",
-+ foreground_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+ "foreground RRGGBB",
-+ "Sets the foreground color when in graphics mode."
-+ "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
-+};
-+
-+
-+/* background */
-+static int
-+background_func(char *arg, int flags)
-+{
-+ if (grub_strlen(arg) == 6) {
-+ int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
-+ int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
-+ int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
-+
-+ background = (r << 16) | (g << 8) | b;
-+ if (graphics_inited)
-+ graphics_set_palette(0, r, g, b);
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct builtin builtin_background =
-+{
-+ "background",
-+ background_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+ "background RRGGBB",
-+ "Sets the background color when in graphics mode."
-+ "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
-+};
-+
-+
-+/* border */
-+static int
-+border_func(char *arg, int flags)
-+{
-+ if (grub_strlen(arg) == 6) {
-+ int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
-+ int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
-+ int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
-+
-+ window_border = (r << 16) | (g << 8) | b;
-+ if (graphics_inited)
-+ graphics_set_palette(0x11, r, g, b);
-+
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct builtin builtin_border =
-+{
-+ "border",
-+ border_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+ "border RRGGBB",
-+ "Sets the border video color when in graphics mode."
-+ "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
-+};
-+
-+
-+/* viewport */
-+static int
-+viewport_func (char *arg, int flags)
-+{
-+ int i;
-+ int x0 = 0, y0 = 0, x1 = 80, y1 = 30;
-+ int *pos[4] = { &x0, &y0, &x1, &y1 };
-+
-+ if (!arg)
-+ return (1);
-+ for (i = 0; i < 4; i++) {
-+ if (!*arg)
-+ return (1);
-+ while (*arg && (*arg == ' ' || *arg == '\t'))
-+ ++arg;
-+ if (!safe_parse_maxint(&arg, pos[i]))
-+ return (1);
-+ while (*arg && (*arg != ' ' && *arg != '\t'))
-+ ++arg;
-+ }
-+
-+ /* minimum size is 65 colums and 16 rows */
-+ if (x0 > x1 - 66 || y0 > y1 - 16 || x0 < 0 || y0 < 0 || x1 > 80 || y1 >
30)
-+ return 1;
-+
-+ view_x0 = x0;
-+ view_y0 = y0;
-+ view_x1 = x1;
-+ view_y1 = y1;
-+
-+ if (flags == BUILTIN_CMDLINE && graphics_inited) {
-+ graphics_end();
-+ graphics_init();
-+ graphics_cls();
-+ }
-+
-+ return 0;
-+}
-+
-+static struct builtin builtin_viewport =
-+{
-+ "viewport",
-+ viewport_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+ "viewport x0 y0 x1 y1",
-+ "Changes grub internals to output text in the window defined by"
-+ " four parameters. The x and y parameters are 0 based. This option"
-+ " only works with the graphics interface."
-+};
-+
-+#endif /* SUPPORT_GRAPHICS */
-+
-+
-+/* clear */
-+static int
-+clear_func()
-+{
-+ if (current_term->cls)
-+ current_term->cls();
-+
-+ return 0;
-+}
-+
-+static struct builtin builtin_clear =
-+{
-+ "clear",
-+ clear_func,
-+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
-+ "clear",
-+ "Clear the screen"
-+};
-+
-
- /* displayapm */
- static int
-@@ -1454,14 +1720,20 @@
-
-
- /* help */
--#define MAX_SHORT_DOC_LEN 39
--#define MAX_LONG_DOC_LEN 66
--
- static int
- help_func (char *arg, int flags)
- {
-- int all = 0;
--
-+ int all = 0, max_short_doc_len, max_long_doc_len;
-+ max_short_doc_len = 39;
-+ max_long_doc_len = 66;
-+#ifdef SUPPORT_GRAPHICS
-+ if (grub_memcmp (current_term->name, "graphics", sizeof ("graphics") - 1)
== 0)
-+ {
-+ max_short_doc_len = (view_x1 - view_x0 + 1) / 2 - 1;
-+ max_long_doc_len = (view_x1 - view_x0) - 14;
-+ }
-+#endif
-+
- if (grub_memcmp (arg, "--all", sizeof ("--all") - 1) == 0)
- {
- all = 1;
-@@ -1491,13 +1763,13 @@
-
- len = grub_strlen ((*builtin)->short_doc);
- /* If the length of SHORT_DOC is too long, truncate it. */
-- if (len > MAX_SHORT_DOC_LEN - 1)
-- len = MAX_SHORT_DOC_LEN - 1;
-+ if (len > max_short_doc_len - 1)
-+ len = max_short_doc_len - 1;
-
- for (i = 0; i < len; i++)
- grub_putchar ((*builtin)->short_doc[i]);
-
-- for (; i < MAX_SHORT_DOC_LEN; i++)
-+ for (; i < max_short_doc_len; i++)
- grub_putchar (' ');
-
- if (! left)
-@@ -1546,10 +1818,10 @@
- int i;
-
- /* If LEN is too long, fold DOC. */
-- if (len > MAX_LONG_DOC_LEN)
-+ if (len > max_long_doc_len)
- {
- /* Fold this line at the position of a space. */
-- for (len = MAX_LONG_DOC_LEN; len > 0; len--)
-+ for (len = max_long_doc_len; len > 0; len--)
- if (doc[len - 1] == ' ')
- break;
- }
-@@ -4085,7 +4357,7 @@
- };
-
-
--#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES)
-+#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES) ||
defined(SUPPORT_GRAPHICS)
- /* terminal */
- static int
- terminal_func (char *arg, int flags)
-@@ -4244,17 +4516,29 @@
- end:
- current_term = term_table + default_term;
- current_term->flags = term_flags;
--
-+
- if (lines)
- max_lines = lines;
- else
-- /* 24 would be a good default value. */
-- max_lines = 24;
--
-+ max_lines = current_term->max_lines;
-+
- /* If the interface is currently the command-line,
- restart it to repaint the screen. */
-- if (current_term != prev_term && (flags & BUILTIN_CMDLINE))
-+ if ((current_term != prev_term) && (flags & BUILTIN_CMDLINE)){
-+ if (prev_term->shutdown)
-+ prev_term->shutdown();
-+ if (current_term->startup) {
-+ /* If startup fails, return to previous term */
-+ if (current_term->startup() == 0) {
-+ current_term = prev_term;
-+ max_lines = current_term->max_lines;
-+ if (current_term->cls) {
-+ current_term->cls();
-+ }
-+ }
-+ }
- grub_longjmp (restart_cmdline_env, 0);
-+ }
-
- return 0;
- }
-@@ -4264,7 +4548,7 @@
- "terminal",
- terminal_func,
- BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
-- "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES]
[--silent] [console] [serial] [hercules]",
-+ "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES]
[--silent] [console] [serial] [hercules] [graphics]",
- "Select a terminal. When multiple terminals are specified, wait until"
- " you push any key to continue. If both console and serial are specified,"
- " the terminal to which you input a key first will be selected. If no"
-@@ -4276,7 +4560,7 @@
- " seconds. The option --lines specifies the maximum number of lines."
- " The option --silent is used to suppress messages."
- };
--#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES */
-+#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES || SUPPORT_GRAPHICS */
-
-
- #ifdef SUPPORT_SERIAL
-@@ -4795,13 +5079,20 @@
- /* The table of builtin commands. Sorted in dictionary order. */
- struct builtin *builtin_table[] =
- {
-+#ifdef SUPPORT_GRAPHICS
-+ &builtin_background,
-+#endif
- &builtin_blocklist,
- &builtin_boot,
- #ifdef SUPPORT_NETBOOT
- &builtin_bootp,
- #endif /* SUPPORT_NETBOOT */
-+#ifdef SUPPORT_GRAPHICS
-+ &builtin_border,
-+#endif
- &builtin_cat,
- &builtin_chainloader,
-+ &builtin_clear,
- &builtin_cmp,
- &builtin_color,
- &builtin_configfile,
-@@ -4821,6 +5112,9 @@
- &builtin_embed,
- &builtin_fallback,
- &builtin_find,
-+#ifdef SUPPORT_GRAPHICS
-+ &builtin_foreground,
-+#endif
- &builtin_fstest,
- &builtin_geometry,
- &builtin_halt,
-@@ -4864,9 +5158,13 @@
- #endif /* SUPPORT_SERIAL */
- &builtin_setkey,
- &builtin_setup,
--#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES)
-+#ifdef SUPPORT_GRAPHICS
-+ &builtin_shade,
-+ &builtin_splashimage,
-+#endif /* SUPPORT_GRAPHICS */
-+#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES) ||
defined(SUPPORT_GRAPHICS)
- &builtin_terminal,
--#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES */
-+#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES || SUPPORT_GRAPHICS */
- #ifdef SUPPORT_SERIAL
- &builtin_terminfo,
- #endif /* SUPPORT_SERIAL */
-@@ -4880,5 +5178,8 @@
- &builtin_unhide,
- &builtin_uppermem,
- &builtin_vbeprobe,
-+#ifdef SUPPORT_GRAPHICS
-+ &builtin_viewport,
-+#endif
- 0
- };
-diff -Naur grub-0.97.orig/stage2/char_io.c grub-0.97/stage2/char_io.c
---- grub-0.97.orig/stage2/char_io.c 2005-02-01 18:51:23.000000000 -0200
-+++ grub-0.97/stage2/char_io.c 2005-06-12 20:56:49.000000000 -0300
-@@ -29,12 +29,17 @@
- # include <serial.h>
- #endif
-
-+#ifdef SUPPORT_GRAPHICS
-+# include <graphics.h>
-+#endif
-+
- #ifndef STAGE1_5
- struct term_entry term_table[] =
- {
- {
- "console",
- 0,
-+ 24,
- console_putchar,
- console_checkkey,
- console_getkey,
-@@ -43,13 +48,16 @@
- console_cls,
- console_setcolorstate,
- console_setcolor,
-- console_setcursor
-+ console_setcursor,
-+ 0,
-+ 0
- },
- #ifdef SUPPORT_SERIAL
- {
- "serial",
- /* A serial device must be initialized. */
- TERM_NEED_INIT,
-+ 24,
- serial_putchar,
- serial_checkkey,
- serial_getkey,
-@@ -58,6 +66,8 @@
- serial_cls,
- serial_setcolorstate,
- 0,
-+ 0,
-+ 0,
- 0
- },
- #endif /* SUPPORT_SERIAL */
-@@ -65,6 +75,7 @@
- {
- "hercules",
- 0,
-+ 24,
- hercules_putchar,
- console_checkkey,
- console_getkey,
-@@ -73,11 +84,30 @@
- hercules_cls,
- hercules_setcolorstate,
- hercules_setcolor,
-- hercules_setcursor
-+ hercules_setcursor,
-+ 0,
-+ 0
- },
- #endif /* SUPPORT_HERCULES */
-+#ifdef SUPPORT_GRAPHICS
-+ { "graphics",
-+ TERM_NEED_INIT, /* flags */
-+ 30, /* number of lines */
-+ graphics_putchar, /* putchar */
-+ console_checkkey, /* checkkey */
-+ console_getkey, /* getkey */
-+ graphics_getxy, /* getxy */
-+ graphics_gotoxy, /* gotoxy */
-+ graphics_cls, /* cls */
-+ graphics_setcolorstate, /* setcolorstate */
-+ graphics_setcolor, /* setcolor */
-+ graphics_setcursor, /* nocursor */
-+ graphics_init, /* initialize */
-+ graphics_end /* shutdown */
-+ },
-+#endif /* SUPPORT_GRAPHICS */
- /* This must be the last entry. */
-- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
- };
-
- /* This must be console. */
-@@ -305,9 +335,10 @@
-
- /* XXX: These should be defined in shared.h, but I leave these here,
- until this code is freezed. */
--#define CMDLINE_WIDTH 78
- #define CMDLINE_MARGIN 10
--
-+
-+ /* command-line limits */
-+ int cmdline_width = 78, col_start = 0;
- int xpos, lpos, c, section;
- /* The length of PROMPT. */
- int plen;
-@@ -338,7 +369,7 @@
-
- /* If the cursor is in the first section, display the first section
- instead of the second. */
-- if (section == 1 && plen + lpos < CMDLINE_WIDTH)
-+ if (section == 1 && plen + lpos < cmdline_width)
- cl_refresh (1, 0);
- else if (xpos - count < 1)
- cl_refresh (1, 0);
-@@ -354,7 +385,7 @@
- grub_putchar ('\b');
- }
- else
-- gotoxy (xpos, getxy () & 0xFF);
-+ gotoxy (xpos + col_start, getxy () & 0xFF);
- }
- }
-
-@@ -364,7 +395,7 @@
- lpos += count;
-
- /* If the cursor goes outside, scroll the screen to the right. */
-- if (xpos + count >= CMDLINE_WIDTH)
-+ if (xpos + count >= cmdline_width)
- cl_refresh (1, 0);
- else
- {
-@@ -383,7 +414,7 @@
- }
- }
- else
-- gotoxy (xpos, getxy () & 0xFF);
-+ gotoxy (xpos + col_start, getxy () & 0xFF);
- }
- }
-
-@@ -398,14 +429,14 @@
- if (full)
- {
- /* Recompute the section number. */
-- if (lpos + plen < CMDLINE_WIDTH)
-+ if (lpos + plen < cmdline_width)
- section = 0;
- else
-- section = ((lpos + plen - CMDLINE_WIDTH)
-- / (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN) + 1);
-+ section = ((lpos + plen - cmdline_width)
-+ / (cmdline_width - 1 - CMDLINE_MARGIN) + 1);
-
- /* From the start to the end. */
-- len = CMDLINE_WIDTH;
-+ len = cmdline_width;
- pos = 0;
- grub_putchar ('\r');
-
-@@ -445,8 +476,8 @@
- if (! full)
- offset = xpos - 1;
-
-- start = ((section - 1) * (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN)
-- + CMDLINE_WIDTH - plen - CMDLINE_MARGIN);
-+ start = ((section - 1) * (cmdline_width - 1 - CMDLINE_MARGIN)
-+ + cmdline_width - plen - CMDLINE_MARGIN);
- xpos = lpos + 1 - start;
- start += offset;
- }
-@@ -471,7 +502,7 @@
-
- /* If the cursor is at the last position, put `>' or a space,
- depending on if there are more characters in BUF. */
-- if (pos == CMDLINE_WIDTH)
-+ if (pos == cmdline_width)
- {
- if (start + len < llen)
- grub_putchar ('>');
-@@ -488,7 +519,7 @@
- grub_putchar ('\b');
- }
- else
-- gotoxy (xpos, getxy () & 0xFF);
-+ gotoxy (xpos + col_start, getxy () & 0xFF);
- }
-
- /* Initialize the command-line. */
-@@ -518,10 +549,10 @@
-
- llen += l;
- lpos += l;
-- if (xpos + l >= CMDLINE_WIDTH)
-+ if (xpos + l >= cmdline_width)
- cl_refresh (1, 0);
-- else if (xpos + l + llen - lpos > CMDLINE_WIDTH)
-- cl_refresh (0, CMDLINE_WIDTH - xpos);
-+ else if (xpos + l + llen - lpos > cmdline_width)
-+ cl_refresh (0, cmdline_width - xpos);
- else
- cl_refresh (0, l + llen - lpos);
- }
-@@ -533,12 +564,22 @@
- grub_memmove (buf + lpos, buf + lpos + count, llen - count + 1);
- llen -= count;
-
-- if (xpos + llen + count - lpos > CMDLINE_WIDTH)
-- cl_refresh (0, CMDLINE_WIDTH - xpos);
-+ if (xpos + llen + count - lpos > cmdline_width)
-+ cl_refresh (0, cmdline_width - xpos);
- else
- cl_refresh (0, llen + count - lpos);
- }
-
-+ max_lines = current_term->max_lines;
-+#ifdef SUPPORT_GRAPHICS
-+ if (grub_memcmp (current_term->name, "graphics", sizeof ("graphics") - 1)
== 0)
-+ {
-+ cmdline_width = (view_x1 - view_x0) - 2;
-+ col_start = view_x0;
-+ max_lines = view_y1 - view_y0;
-+ }
-+#endif
-+
- plen = grub_strlen (prompt);
- llen = grub_strlen (cmdline);
-
-@@ -1006,6 +1047,48 @@
- }
- #endif /* ! STAGE1_5 */
-
-+#ifndef STAGE1_5
-+/* Internal pager. */
-+int
-+do_more (void)
-+{
-+ if (count_lines >= 0)
-+ {
-+ count_lines++;
-+ if (count_lines >= max_lines - 2)
-+ {
-+ int tmp;
-+
-+ /* It's important to disable the feature temporarily, because
-+ the following grub_printf call will print newlines. */
-+ count_lines = -1;
-+
-+ grub_printf("\n");
-+ if (current_term->setcolorstate)
-+ current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
-+
-+ grub_printf ("[Hit return to continue]");
-+
-+ if (current_term->setcolorstate)
-+ current_term->setcolorstate (COLOR_STATE_NORMAL);
-+
-+
-+ do
-+ {
-+ tmp = ASCII_CHAR (getkey ());
-+ }
-+ while (tmp != '\n' && tmp != '\r');
-+ grub_printf ("\r \r");
-+
-+ /* Restart to count lines. */
-+ count_lines = 0;
-+ return 1;
-+ }
-+ }
-+ return 0;
-+}
-+#endif
-+
- /* Display an ASCII character. */
- void
- grub_putchar (int c)
-@@ -1034,38 +1117,11 @@
-
- if (c == '\n')
- {
-+ int flag;
- /* Internal `more'-like feature. */
-- if (count_lines >= 0)
-- {
-- count_lines++;
-- if (count_lines >= max_lines - 2)
-- {
-- int tmp;
--
-- /* It's important to disable the feature temporarily, because
-- the following grub_printf call will print newlines. */
-- count_lines = -1;
--
-- if (current_term->setcolorstate)
-- current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
--
-- grub_printf ("\n[Hit return to continue]");
--
-- if (current_term->setcolorstate)
-- current_term->setcolorstate (COLOR_STATE_NORMAL);
--
-- do
-- {
-- tmp = ASCII_CHAR (getkey ());
-- }
-- while (tmp != '\n' && tmp != '\r');
-- grub_printf ("\r \r");
--
-- /* Restart to count lines. */
-- count_lines = 0;
-- return;
-- }
-- }
-+ flag = do_more ();
-+ if (flag)
-+ return;
- }
-
- current_term->putchar (c);
-@@ -1090,7 +1146,7 @@
- cls (void)
- {
- /* If the terminal is dumb, there is no way to clean the terminal. */
-- if (current_term->flags & TERM_DUMB)
-+ if (current_term->flags & TERM_DUMB)
- grub_putchar ('\n');
- else
- current_term->cls ();
-@@ -1217,6 +1273,16 @@
- return ! errnum;
- }
-
-+void
-+grub_memcpy(void *dest, const void *src, int len)
-+{
-+ int i;
-+ register char *d = (char*)dest, *s = (char*)src;
-+
-+ for (i = 0; i < len; i++)
-+ d[i] = s[i];
-+}
-+
- void *
- grub_memmove (void *to, const void *from, int len)
- {
-diff -Naur grub-0.97.orig/stage2/cmdline.c grub-0.97/stage2/cmdline.c
---- grub-0.97.orig/stage2/cmdline.c 2004-08-16 20:23:01.000000000 -0300
-+++ grub-0.97/stage2/cmdline.c 2005-06-12 20:56:49.000000000 -0300
-@@ -50,10 +50,11 @@
- void
- print_cmdline_message (int forever)
- {
-- printf (" [ Minimal BASH-like line editing is supported. For the first
word, TAB\n"
-- " lists possible command completions. Anywhere else TAB lists the
possible\n"
-- " completions of a device/filename.%s ]\n",
-- (forever ? "" : " ESC at any time exits."));
-+ grub_printf(" [ Minimal BASH-like line editing is supported. For\n"
-+ " the first word, TAB lists possible command\n"
-+ " completions. Anywhere else TAB lists the possible\n"
-+ " completions of a device/filename.%s ]\n",
-+ (forever ? "" : " ESC at any time\n exits."));
- }
-
- /* Find the builtin whose command name is COMMAND and return the
-diff -Naur grub-0.97.orig/stage2/graphics.c grub-0.97/stage2/graphics.c
---- grub-0.97.orig/stage2/graphics.c 1969-12-31 21:00:00.000000000 -0300
-+++ grub-0.97/stage2/graphics.c 2005-06-13 19:13:31.000000000 -0300
-@@ -0,0 +1,584 @@
-+/*
-+ * graphics.c - graphics mode support for GRUB
-+ * Implemented as a terminal type by Jeremy Katz <katzj@xxxxxxxxxx> based
-+ * on a patch by Paulo C�sar Pereira de Andrade <pcpa@xxxxxxxxxxxxxxxx>
-+ * Options and enhancements made by Herton Ronaldo Krzesinski
-+ * <herton@xxxxxxxxxxxx>
-+ *
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2001,2002 Red Hat, Inc.
-+ * Portions copyright (C) 2000 Conectiva, Inc.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; If not, see <http://www.gnu.org/licenses/>
-+ */
-+
-+#ifdef SUPPORT_GRAPHICS
-+
-+#include <term.h>
-+#include <shared.h>
-+#include <graphics.h>
-+
-+int saved_videomode;
-+unsigned char *font8x16;
-+
-+int graphics_inited = 0;
-+static char splashimage[256];
-+
-+int shade = 1, no_cursor = 0;
-+
-+#define VSHADOW VSHADOW1
-+unsigned char VSHADOW1[38400];
-+unsigned char VSHADOW2[38400];
-+unsigned char VSHADOW4[38400];
-+unsigned char VSHADOW8[38400];
-+
-+/* define the default viewable area */
-+int view_x0 = 0;
-+int view_y0 = 0;
-+int view_x1 = 80;
-+int view_y1 = 30;
-+
-+/* text buffer has to be kept around so that we can write things as we
-+ * scroll and the like */
-+unsigned short text[80 * 30];
-+
-+/* graphics options */
-+int foreground = (63 << 16) | (63 << 8) | (63), background = 0, window_border
= 0;
-+
-+/* current position */
-+static int fontx = 0;
-+static int fonty = 0;
-+
-+/* global state so that we don't try to recursively scroll or cursor */
-+static int no_scroll = 0;
-+
-+/* color state */
-+static int graphics_standard_color = A_NORMAL;
-+static int graphics_normal_color = A_NORMAL;
-+static int graphics_highlight_color = A_REVERSE;
-+static int graphics_current_color = A_NORMAL;
-+static color_state graphics_color_state = COLOR_STATE_STANDARD;
-+
-+static inline void outb(unsigned short port, unsigned char val)
-+{
-+ __asm __volatile ("outb %0,%1"::"a" (val), "d" (port));
-+}
-+
-+static void MapMask(int value) {
-+ outb(0x3c4, 2);
-+ outb(0x3c5, value);
-+}
-+
-+/* bit mask register */
-+static void BitMask(int value) {
-+ outb(0x3ce, 8);
-+ outb(0x3cf, value);
-+}
-+
-+/* move the graphics cursor location to col, row */
-+static void graphics_setxy(int col, int row) {
-+ if (col >= view_x0 && col < view_x1) {
-+ fontx = col;
-+ cursorX = col << 3;
-+ }
-+ if (row >= view_y0 && row < view_y1) {
-+ fonty = row;
-+ cursorY = row << 4;
-+ }
-+}
-+
-+/* scroll the screen */
-+static void graphics_scroll() {
-+ int i, j, k;
-+
-+ /* we don't want to scroll recursively... that would be bad */
-+ if (no_scroll)
-+ return;
-+ no_scroll = 1;
-+
-+ /* disable pager temporarily */
-+ k = count_lines;
-+ count_lines = -1;
-+
-+ /* move everything up a line */
-+ for (j = view_y0 + 1; j < view_y1; j++) {
-+ graphics_gotoxy(view_x0, j - 1);
-+ for (i = view_x0; i < view_x1; i++) {
-+ graphics_putchar(text[j * 80 + i]);
-+ }
-+ }
-+
-+ /* last line should be blank */
-+ graphics_gotoxy(view_x0, view_y1 - 1);
-+ for (i = view_x0; i < view_x1; i++)
-+ graphics_putchar(' ');
-+ graphics_setxy(view_x0, view_y1 - 1);
-+
-+ count_lines = k;
-+
-+ no_scroll = 0;
-+}
-+
-+/* Set the splash image */
-+void graphics_set_splash(char *splashfile) {
-+ grub_strcpy(splashimage, splashfile);
-+}
-+
-+/* Get the current splash image */
-+char *graphics_get_splash(void) {
-+ return splashimage;
-+}
-+
-+/*
-+ * Initialize a vga16 graphics display with the palette based off of
-+ * the image in splashimage. If the image doesn't exist, leave graphics
-+ * mode. The mode initiated is 12h. From "Ralf Brown's Interrupt List":
-+ * text/ text pixel pixel colors disply scrn system
-+ * grph resol box resolution pages addr
-+ * 12h G 80x30 8x16 640x480 16/256K . A000 VGA,ATI VIP
-+ * G 80x30 8x16 640x480 16/64 . A000 ATI EGA Wonder
-+ * G . . 640x480 16 . . UltraVision+256K EGA
-+ */
-+int graphics_init()
-+{
-+ if (!graphics_inited) {
-+ saved_videomode = set_videomode(0x12);
-+ if (get_videomode() != 0x12) {
-+ set_videomode(saved_videomode);
-+ return 0;
-+ }
-+ graphics_inited = 1;
-+ }
-+ else
-+ return 1;
-+
-+ font8x16 = (unsigned char*)graphics_get_font();
-+
-+ /* make sure that the highlight color is set correctly */
-+ graphics_highlight_color = ((graphics_normal_color >> 4) |
-+ ((graphics_normal_color & 0xf) << 4));
-+
-+ graphics_cls();
-+
-+ if (!read_image(splashimage)) {
-+ grub_printf("Failed to read splash image (%s)\n", splashimage);
-+ grub_printf("Press any key to continue...");
-+ getkey();
-+ set_videomode(saved_videomode);
-+ graphics_inited = 0;
-+ return 0;
-+ }
-+
-+ set_int1c_handler();
-+
-+ return 1;
-+}
-+
-+/* Leave graphics mode */
-+void graphics_end(void)
-+{
-+ if (graphics_inited) {
-+ unset_int1c_handler();
-+ set_videomode(saved_videomode);
-+ graphics_inited = 0;
-+ no_cursor = 0;
-+ }
-+}
-+
-+/* Print ch on the screen. Handle any needed scrolling or the like */
-+void graphics_putchar(int ch) {
-+ ch &= 0xff;
-+
-+ graphics_cursor(0);
-+
-+ if (ch == '\n') {
-+ if (fonty + 1 < view_y1)
-+ graphics_setxy(fontx, fonty + 1);
-+ else
-+ graphics_scroll();
-+ graphics_cursor(1);
-+ return;
-+ } else if (ch == '\r') {
-+ graphics_setxy(view_x0, fonty);
-+ graphics_cursor(1);
-+ return;
-+ }
-+
-+ graphics_cursor(0);
-+
-+ text[fonty * 80 + fontx] = ch;
-+ text[fonty * 80 + fontx] &= 0x00ff;
-+ if (graphics_current_color & 0xf0)
-+ text[fonty * 80 + fontx] |= 0x100;
-+
-+ graphics_cursor(0);
-+
-+ if ((fontx + 1) >= view_x1) {
-+ graphics_setxy(view_x0, fonty);
-+ if (fonty + 1 < view_y1)
-+ graphics_setxy(view_x0, fonty + 1);
-+ else
-+ graphics_scroll();
-+ graphics_cursor(1);
-+ do_more ();
-+ graphics_cursor(0);
-+ } else {
-+ graphics_setxy(fontx + 1, fonty);
-+ }
-+
-+ graphics_cursor(1);
-+}
-+
-+/* get the current location of the cursor */
-+int graphics_getxy(void) {
-+ return (fontx << 8) | fonty;
-+}
-+
-+void graphics_gotoxy(int x, int y) {
-+ graphics_cursor(0);
-+
-+ graphics_setxy(x, y);
-+
-+ graphics_cursor(1);
-+}
-+
-+void graphics_cls(void) {
-+ int i;
-+ unsigned char *mem, *s1, *s2, *s4, *s8;
-+
-+ graphics_cursor(0);
-+ graphics_gotoxy(view_x0, view_y0);
-+
-+ mem = (unsigned char*)VIDEOMEM;
-+ s1 = (unsigned char*)VSHADOW1;
-+ s2 = (unsigned char*)VSHADOW2;
-+ s4 = (unsigned char*)VSHADOW4;
-+ s8 = (unsigned char*)VSHADOW8;
-+
-+ for (i = 0; i < 80 * 30; i++)
-+ text[i] = ' ';
-+ graphics_cursor(1);
-+
-+ BitMask(0xff);
-+
-+ /* plane 1 */
-+ MapMask(1);
-+ grub_memcpy(mem, s1, 38400);
-+
-+ /* plane 2 */
-+ MapMask(2);
-+ grub_memcpy(mem, s2, 38400);
-+
-+ /* plane 3 */
-+ MapMask(4);
-+ grub_memcpy(mem, s4, 38400);
-+
-+ /* plane 4 */
-+ MapMask(8);
-+ grub_memcpy(mem, s8, 38400);
-+
-+ MapMask(15);
-+
-+ if (no_cursor) {
-+ no_cursor = 0;
-+ set_int1c_handler();
-+ }
-+}
-+
-+void graphics_setcolorstate (color_state state) {
-+ switch (state) {
-+ case COLOR_STATE_STANDARD:
-+ graphics_current_color = graphics_standard_color;
-+ break;
-+ case COLOR_STATE_NORMAL:
-+ graphics_current_color = graphics_normal_color;
-+ break;
-+ case COLOR_STATE_HIGHLIGHT:
-+ graphics_current_color = graphics_highlight_color;
-+ break;
-+ default:
-+ graphics_current_color = graphics_standard_color;
-+ break;
-+ }
-+
-+ graphics_color_state = state;
-+}
-+
-+void graphics_setcolor (int normal_color, int highlight_color) {
-+ graphics_normal_color = normal_color;
-+ graphics_highlight_color = highlight_color;
-+
-+ graphics_setcolorstate (graphics_color_state);
-+}
-+
-+int graphics_setcursor (int on) {
-+ if (!no_cursor && !on) {
-+ no_cursor = 1;
-+ unset_int1c_handler();
-+ graphics_cursor(0);
-+ }
-+ else if(no_cursor && on) {
-+ no_cursor = 0;
-+ set_int1c_handler();
-+ graphics_cursor(1);
-+ }
-+ return 0;
-+}
-+
-+/* Read in the splashscreen image and set the palette up appropriately.
-+ * Format of splashscreen is an xpm (can be gzipped) with 16 colors and
-+ * 640x480. */
-+int read_image(char *s)
-+{
-+ char buf[32], pal[16], c;
-+ unsigned char base, mask, *s1, *s2, *s4, *s8;
-+ unsigned i, len, idx, colors, x, y, width, height;
-+
-+ if (!grub_open(s))
-+ return 0;
-+
-+ /* read header */
-+ if (!grub_read((char*)&buf, 10) || grub_memcmp(buf, "/* XPM */\n", 10)) {
-+ grub_close();
-+ return 0;
-+ }
-+
-+ /* parse info */
-+ while (grub_read(&c, 1)) {
-+ if (c == '"')
-+ break;
-+ }
-+
-+ while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
-+ ;
-+
-+ i = 0;
-+ width = c - '0';
-+ while (grub_read(&c, 1)) {
-+ if (c >= '0' && c <= '9')
-+ width = width * 10 + c - '0';
-+ else
-+ break;
-+ }
-+ while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
-+ ;
-+
-+ height = c - '0';
-+ while (grub_read(&c, 1)) {
-+ if (c >= '0' && c <= '9')
-+ height = height * 10 + c - '0';
-+ else
-+ break;
-+ }
-+ while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
-+ ;
-+
-+ colors = c - '0';
-+ while (grub_read(&c, 1)) {
-+ if (c >= '0' && c <= '9')
-+ colors = colors * 10 + c - '0';
-+ else
-+ break;
-+ }
-+
-+ base = 0;
-+ while (grub_read(&c, 1) && c != '"')
-+ ;
-+
-+ /* palette */
-+ for (i = 0, idx = 1; i < colors; i++) {
-+ len = 0;
-+
-+ while (grub_read(&c, 1) && c != '"')
-+ ;
-+ grub_read(&c, 1); /* char */
-+ base = c;
-+ grub_read(buf, 4); /* \t c # */
-+
-+ while (grub_read(&c, 1) && c != '"') {
-+ if (len < sizeof(buf))
-+ buf[len++] = c;
-+ }
-+
-+ if (len == 6 && idx < 15) {
-+ int r = ((hex(buf[0]) << 4) | hex(buf[1])) >> 2;
-+ int g = ((hex(buf[2]) << 4) | hex(buf[3])) >> 2;
-+ int b = ((hex(buf[4]) << 4) | hex(buf[5])) >> 2;
-+
-+ pal[idx] = base;
-+ graphics_set_palette(idx, r, g, b);
-+ ++idx;
-+ }
-+ }
-+
-+ x = y = len = 0;
-+
-+ s1 = (unsigned char*)VSHADOW1;
-+ s2 = (unsigned char*)VSHADOW2;
-+ s4 = (unsigned char*)VSHADOW4;
-+ s8 = (unsigned char*)VSHADOW8;
-+
-+ for (i = 0; i < 38400; i++)
-+ s1[i] = s2[i] = s4[i] = s8[i] = 0;
-+
-+ /* parse xpm data */
-+ while (y < height) {
-+ while (1) {
-+ if (!grub_read(&c, 1)) {
-+ grub_close();
-+ return 0;
-+ }
-+ if (c == '"')
-+ break;
-+ }
-+
-+ while (grub_read(&c, 1) && c != '"') {
-+ for (i = 1; i < 15; i++)
-+ if (pal[i] == c) {
-+ c = i;
-+ break;
-+ }
-+
-+ mask = 0x80 >> (x & 7);
-+ if (c & 1)
-+ s1[len + (x >> 3)] |= mask;
-+ if (c & 2)
-+ s2[len + (x >> 3)] |= mask;
-+ if (c & 4)
-+ s4[len + (x >> 3)] |= mask;
-+ if (c & 8)
-+ s8[len + (x >> 3)] |= mask;
-+
-+ if (++x >= 640) {
-+ x = 0;
-+
-+ if (y < 480)
-+ len += 80;
-+ ++y;
-+ }
-+ }
-+ }
-+
-+ grub_close();
-+
-+ graphics_set_palette(0, (background >> 16), (background >> 8) & 63,
-+ background & 63);
-+ graphics_set_palette(15, (foreground >> 16), (foreground >> 8) & 63,
-+ foreground & 63);
-+ graphics_set_palette(0x11, (window_border >> 16), (window_border >> 8) &
63,
-+ window_border & 63);
-+
-+ return 1;
-+}
-+
-+/* Convert a character which is a hex digit to the appropriate integer */
-+int hex(int v)
-+{
-+ if (v >= 'A' && v <= 'F')
-+ return (v - 'A' + 10);
-+ if (v >= 'a' && v <= 'f')
-+ return (v - 'a' + 10);
-+ return (v - '0');
-+}
-+
-+void graphics_cursor(int set) {
-+ unsigned char *pat, *mem, *ptr, chr[16 << 2];
-+ int i, ch, invert, offset;
-+
-+ if (set && (no_cursor || no_scroll))
-+ return;
-+
-+ offset = cursorY * 80 + fontx;
-+ ch = text[fonty * 80 + fontx] & 0xff;
-+ invert = (text[fonty * 80 + fontx] & 0xff00) != 0;
-+ pat = font8x16 + (ch << 4);
-+
-+ mem = (unsigned char*)VIDEOMEM + offset;
-+
-+ if (!set) {
-+ for (i = 0; i < 16; i++) {
-+ unsigned char mask = pat[i];
-+
-+ if (!invert) {
-+ chr[i ] = ((unsigned char*)VSHADOW1)[offset];
-+ chr[16 + i] = ((unsigned char*)VSHADOW2)[offset];
-+ chr[32 + i] = ((unsigned char*)VSHADOW4)[offset];
-+ chr[48 + i] = ((unsigned char*)VSHADOW8)[offset];
-+
-+ if (shade) {
-+ if (ch == DISP_VERT || ch == DISP_LL ||
-+ ch == DISP_UR || ch == DISP_LR) {
-+ unsigned char pmask = ~(pat[i] >> 1);
-+
-+ chr[i ] &= pmask;
-+ chr[16 + i] &= pmask;
-+ chr[32 + i] &= pmask;
-+ chr[48 + i] &= pmask;
-+ }
-+ if (i > 0 && ch != DISP_VERT) {
-+ unsigned char pmask = ~(pat[i - 1] >> 1);
-+
-+ chr[i ] &= pmask;
-+ chr[16 + i] &= pmask;
-+ chr[32 + i] &= pmask;
-+ chr[48 + i] &= pmask;
-+ if (ch == DISP_HORIZ || ch == DISP_UR || ch ==
DISP_LR) {
-+ pmask = ~pat[i - 1];
-+
-+ chr[i ] &= pmask;
-+ chr[16 + i] &= pmask;
-+ chr[32 + i] &= pmask;
-+ chr[48 + i] &= pmask;
-+ }
-+ }
-+ }
-+ chr[i ] |= mask;
-+ chr[16 + i] |= mask;
-+ chr[32 + i] |= mask;
-+ chr[48 + i] |= mask;
-+
-+ offset += 80;
-+ }
-+ else {
-+ chr[i ] = mask;
-+ chr[16 + i] = mask;
-+ chr[32 + i] = mask;
-+ chr[48 + i] = mask;
-+ }
-+ }
-+ }
-+ else {
-+ MapMask(15);
-+ ptr = mem;
-+ for (i = 0; i < 16; i++, ptr += 80) {
-+ cursorBuf[i] = pat[i];
-+ *ptr = ~pat[i];
-+ }
-+ return;
-+ }
-+
-+ offset = 0;
-+ for (i = 1; i < 16; i <<= 1, offset += 16) {
-+ int j;
-+
-+ MapMask(i);
-+ ptr = mem;
-+ for (j = 0; j < 16; j++, ptr += 80)
-+ *ptr = chr[j + offset];
-+ }
-+
-+ MapMask(15);
-+}
-+
-+#endif /* SUPPORT_GRAPHICS */
-diff -Naur grub-0.97.orig/stage2/graphics.h grub-0.97/stage2/graphics.h
---- grub-0.97.orig/stage2/graphics.h 1969-12-31 21:00:00.000000000 -0300
-+++ grub-0.97/stage2/graphics.h 2005-06-12 20:56:49.000000000 -0300
-@@ -0,0 +1,43 @@
-+/* graphics.h - graphics console interface */
-+/*
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2002 Free Software Foundation, Inc.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; If not, see <http://www.gnu.org/licenses/>
-+ */
-+
-+#ifndef GRAPHICS_H
-+#define GRAPHICS_H
-+
-+/* magic constant */
-+#define VIDEOMEM 0xA0000
-+
-+/* function prototypes */
-+char *graphics_get_splash(void);
-+
-+int read_image(char *s);
-+void graphics_cursor(int set);
-+
-+/* function prototypes for asm functions */
-+void * graphics_get_font();
-+void graphics_set_palette(int idx, int red, int green, int blue);
-+void set_int1c_handler();
-+void unset_int1c_handler();
-+
-+extern short cursorX, cursorY;
-+extern char cursorBuf[16];
-+extern int shade;
-+extern int view_x0, view_y0, view_x1, view_y1;
-+
-+#endif /* GRAPHICS_H */
-diff -Naur grub-0.97.orig/stage2/Makefile.am grub-0.97/stage2/Makefile.am
---- grub-0.97.orig/stage2/Makefile.am 2005-02-02 18:37:35.000000000 -0200
-+++ grub-0.97/stage2/Makefile.am 2005-06-12 20:56:49.000000000 -0300
-@@ -7,7 +7,7 @@
- fat.h filesys.h freebsd.h fs.h hercules.h i386-elf.h \
- imgact_aout.h iso9660.h jfs.h mb_header.h mb_info.h md5.h \
- nbi.h pc_slice.h serial.h shared.h smp-imps.h term.h \
-- terminfo.h tparm.h nbi.h ufs2.h vstafs.h xfs.h
-+ terminfo.h tparm.h nbi.h ufs2.h vstafs.h xfs.h graphics.h
- EXTRA_DIST = setjmp.S apm.S $(noinst_SCRIPTS)
-
- # For <stage1.h>.
-@@ -19,7 +19,7 @@
- disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ffs.c fsys_iso9660.c \
- fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
- fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c stage2.c \
-- terminfo.c tparm.c
-+ terminfo.c tparm.c graphics.c
- libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
- -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
- -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
-@@ -79,8 +79,14 @@
- HERCULES_FLAGS =
- endif
-
-+if GRAPHICS_SUPPORT
-+GRAPHICS_FLAGS = -DSUPPORT_GRAPHICS=1
-+else
-+GRAPHICS_FLAGS =
-+endif
-+
- STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
-- $(NETBOOT_FLAGS) $(SERIAL_FLAGS) $(HERCULES_FLAGS)
-+ $(NETBOOT_FLAGS) $(SERIAL_FLAGS) $(HERCULES_FLAGS) $(GRAPHICS_FLAGS)
-
- STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
- STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1
-@@ -90,7 +96,8 @@
- cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
- fsys_fat.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
- fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c gunzip.c \
-- hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c
-+ hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c \
-+ graphics.c
- pre_stage2_exec_CFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_LDFLAGS = $(PRE_STAGE2_LINK)
-diff -Naur grub-0.97.orig/stage2/shared.h grub-0.97/stage2/shared.h
---- grub-0.97.orig/stage2/shared.h 2004-06-19 13:40:09.000000000 -0300
-+++ grub-0.97/stage2/shared.h 2005-06-12 20:56:49.000000000 -0300
-@@ -792,6 +792,11 @@
- /* Set the cursor position. */
- void gotoxy (int x, int y);
-
-+/* Internal pager
-+ Returns 1 = if pager was used
-+ 0 = if pager wasn't used */
-+int do_more (void);
-+
- /* Displays an ASCII character. IBM displays will translate some
- characters to special graphical ones (see the DISP_* constants). */
- void grub_putchar (int c);
-@@ -871,6 +876,7 @@
- int grub_tolower (int c);
- int grub_isspace (int c);
- int grub_strncat (char *s1, const char *s2, int n);
-+void grub_memcpy(void *dest, const void *src, int len);
- void *grub_memmove (void *to, const void *from, int len);
- void *grub_memset (void *start, int c, int len);
- int grub_strncat (char *s1, const char *s2, int n);
-diff -Naur grub-0.97.orig/stage2/stage2.c grub-0.97/stage2/stage2.c
---- grub-0.97.orig/stage2/stage2.c 2005-03-19 14:51:57.000000000 -0300
-+++ grub-0.97/stage2/stage2.c 2005-06-13 22:38:08.000000000 -0300
-@@ -20,6 +20,12 @@
- #include <shared.h>
- #include <term.h>
-
-+#ifdef SUPPORT_GRAPHICS
-+# include <graphics.h>
-+#endif
-+
-+int col_start, col_end, row_start, box_size;
-+
- grub_jmp_buf restart_env;
-
- #if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
-@@ -105,13 +111,13 @@
- if (highlight && current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
-
-- gotoxy (2, y);
-+ gotoxy (2 + col_start, y);
- grub_putchar (' ');
-- for (x = 3; x < 75; x++)
-+ for (x = 3 + col_start; x < (col_end - 5); x++)
- {
-- if (*entry && x <= 72)
-+ if (*entry && x <= (col_end - 8))
- {
-- if (x == 72)
-+ if (x == (col_end - 8))
- grub_putchar (DISP_RIGHT);
- else
- grub_putchar (*entry++);
-@@ -119,7 +125,7 @@
- else
- grub_putchar (' ');
- }
-- gotoxy (74, y);
-+ gotoxy ((col_end - 6), y);
-
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_STANDARD);
-@@ -131,7 +137,7 @@
- {
- int i;
-
-- gotoxy (77, y + 1);
-+ gotoxy ((col_end - 3), y + 1);
-
- if (first)
- grub_putchar (DISP_UP);
-@@ -151,14 +157,14 @@
- menu_entries++;
- }
-
-- gotoxy (77, y + size);
-+ gotoxy ((col_end - 3), y + size);
-
- if (*menu_entries)
- grub_putchar (DISP_DOWN);
- else
- grub_putchar (' ');
-
-- gotoxy (74, y + entryno + 1);
-+ gotoxy ((col_end - 6), y + entryno + 1);
- }
-
- static void
-@@ -196,30 +202,30 @@
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_NORMAL);
-
-- gotoxy (1, y);
-+ gotoxy (1 + col_start, y);
-
- grub_putchar (DISP_UL);
-- for (i = 0; i < 73; i++)
-+ for (i = col_start; i < (col_end - 7); i++)
- grub_putchar (DISP_HORIZ);
- grub_putchar (DISP_UR);
-
- i = 1;
- while (1)
- {
-- gotoxy (1, y + i);
-+ gotoxy (1 + col_start, y + i);
-
- if (i > size)
- break;
-
- grub_putchar (DISP_VERT);
-- gotoxy (75, y + i);
-+ gotoxy ((col_end - 5), y + i);
- grub_putchar (DISP_VERT);
-
- i++;
- }
-
- grub_putchar (DISP_LL);
-- for (i = 0; i < 73; i++)
-+ for (i = col_start; i < (col_end - 7); i++)
- grub_putchar (DISP_HORIZ);
- grub_putchar (DISP_LR);
-
-@@ -233,6 +239,7 @@
- {
- int c, time1, time2 = -1, first_entry = 0;
- char *cur_entry = 0;
-+ struct term_entry *prev_term = NULL;
-
- /*
- * Main loop for menu UI.
-@@ -250,6 +257,22 @@
- }
- }
-
-+ col_start = 0;
-+ col_end = 80;
-+ row_start = 0;
-+ box_size = 12;
-+ /* if we're using viewport we need to make sure to setup
-+ coordinates correctly. */
-+#ifdef SUPPORT_GRAPHICS
-+ if (grub_memcmp (current_term->name, "graphics", sizeof ("graphics") - 1)
== 0)
-+ {
-+ col_start = view_x0;
-+ col_end = view_x1;
-+ row_start = view_y0;
-+ box_size = (view_y1 - view_y0) - 13;
-+ }
-+#endif
-+
- /* If the timeout was expired or wasn't set, force to show the menu
- interface. */
- if (grub_timeout < 0)
-@@ -302,36 +325,36 @@
- if (current_term->flags & TERM_DUMB)
- print_entries_raw (num_entries, first_entry, menu_entries);
- else
-- print_border (3, 12);
-+ print_border (3 + row_start, box_size);
-
- grub_printf ("\n\
-- Use the %c and %c keys to select which entry is highlighted.\n",
-+ Use the %c and %c keys to select which entry is highlighted.\n",
- DISP_UP, DISP_DOWN);
-
- if (! auth && password)
- {
- printf ("\
-- Press enter to boot the selected OS or \'p\' to enter a\n\
-- password to unlock the next set of features.");
-+ Press enter to boot the selected OS or \'p\' to enter a\n\
-+ password to unlock the next set of features.");
- }
- else
- {
- if (config_entries)
- printf ("\
-- Press enter to boot the selected OS, \'e\' to edit the\n\
-- commands before booting, or \'c\' for a command-line.");
-+ Press enter to boot the selected OS, \'e\' to edit the\n\
-+ commands before booting, or \'c\' for a command-line.");
- else
- printf ("\
-- Press \'b\' to boot, \'e\' to edit the selected command in the\n\
-- boot sequence, \'c\' for a command-line, \'o\' to open a new line\n\
-- after (\'O\' for before) the selected line, \'d\' to remove the\n\
-- selected line, or escape to go back to the main menu.");
-+ Press \'b\' to boot, \'e\' to edit the selected command in the\n\
-+ boot sequence, \'c\' for a command-line, \'o\' to open a new line\n\
-+ after (\'O\' for before) the selected line, \'d\' to remove the\n\
-+ selected line, or escape to go back to the main menu.");
- }
-
- if (current_term->flags & TERM_DUMB)
- grub_printf ("\n\nThe selected entry is %d ", entryno);
- else
-- print_entries (3, 12, first_entry, entryno, menu_entries);
-+ print_entries (3 + row_start, box_size, first_entry, entryno,
menu_entries);
- }
-
- /* XX using RT clock now, need to initialize value */
-@@ -358,10 +381,10 @@
- entryno, grub_timeout);
- else
- {
-- gotoxy (3, 22);
-- grub_printf ("The highlighted entry will be booted automatically
in %d seconds. ",
-+ gotoxy (3 + col_start, 10 + box_size + row_start);
-+ grub_printf (" The highlighted entry will be booted automatically
in %d seconds. ",
- grub_timeout);
-- gotoxy (74, 4 + entryno);
-+ gotoxy ((col_end - 6), 4 + entryno + row_start);
- }
-
- grub_timeout--;
-@@ -387,12 +410,12 @@
- if (current_term->flags & TERM_DUMB)
- grub_putchar ('\r');
- else
-- gotoxy (3, 22);
-+ gotoxy (3 + col_start, 10 + box_size + row_start);
- printf ("
");
- grub_timeout = -1;
- fallback_entryno = -1;
- if (! (current_term->flags & TERM_DUMB))
-- gotoxy (74, 4 + entryno);
-+ gotoxy ((col_end - 6), 4 + entryno + row_start);
- }
-
- /* We told them above (at least in SUPPORT_SERIAL) to use
-@@ -408,12 +431,12 @@
- {
- if (entryno > 0)
- {
-- print_entry (4 + entryno, 0,
-+ print_entry (4 + entryno + row_start, 0,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- entryno--;
-- print_entry (4 + entryno, 1,
-+ print_entry (4 + entryno + row_start, 1,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
-@@ -421,7 +444,7 @@
- else if (first_entry > 0)
- {
- first_entry--;
-- print_entries (3, 12, first_entry, entryno,
-+ print_entries (3 + row_start, box_size, first_entry,
entryno,
- menu_entries);
- }
- }
-@@ -433,29 +456,29 @@
- entryno++;
- else
- {
-- if (entryno < 11)
-+ if (entryno < (box_size - 1))
- {
-- print_entry (4 + entryno, 0,
-+ print_entry (4 + entryno + row_start, 0,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- entryno++;
-- print_entry (4 + entryno, 1,
-+ print_entry (4 + entryno + row_start, 1,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- }
-- else if (num_entries > 12 + first_entry)
-+ else if (num_entries > box_size + first_entry)
- {
- first_entry++;
-- print_entries (3, 12, first_entry, entryno, menu_entries);
-+ print_entries (3 + row_start, box_size, first_entry,
entryno, menu_entries);
- }
- }
- }
- else if (c == 7)
- {
- /* Page Up */
-- first_entry -= 12;
-+ first_entry -= box_size;
- if (first_entry < 0)
- {
- entryno += first_entry;
-@@ -463,20 +486,20 @@
- if (entryno < 0)
- entryno = 0;
- }
-- print_entries (3, 12, first_entry, entryno, menu_entries);
-+ print_entries (3 + row_start, box_size, first_entry, entryno,
menu_entries);
- }
- else if (c == 3)
- {
- /* Page Down */
-- first_entry += 12;
-+ first_entry += box_size;
- if (first_entry + entryno + 1 >= num_entries)
- {
-- first_entry = num_entries - 12;
-+ first_entry = num_entries - box_size;
- if (first_entry < 0)
- first_entry = 0;
- entryno = num_entries - first_entry - 1;
- }
-- print_entries (3, 12, first_entry, entryno, menu_entries);
-+ print_entries (3 + row_start, box_size, first_entry, entryno,
menu_entries);
- }
-
- if (config_entries)
-@@ -489,7 +512,7 @@
- if ((c == 'd') || (c == 'o') || (c == 'O'))
- {
- if (! (current_term->flags & TERM_DUMB))
-- print_entry (4 + entryno, 0,
-+ print_entry (4 + entryno + row_start, 0,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
-@@ -537,7 +560,7 @@
-
- if (entryno >= num_entries)
- entryno--;
-- if (first_entry && num_entries < 12 + first_entry)
-+ if (first_entry && num_entries < box_size + first_entry)
- first_entry--;
- }
-
-@@ -549,7 +572,7 @@
- grub_printf ("\n");
- }
- else
-- print_entries (3, 12, first_entry, entryno, menu_entries);
-+ print_entries (3 + row_start, box_size, first_entry,
entryno, menu_entries);
- }
-
- cur_entry = menu_entries;
-@@ -570,7 +593,7 @@
- if (current_term->flags & TERM_DUMB)
- grub_printf ("\r ");
- else
-- gotoxy (1, 21);
-+ gotoxy (1 + col_start, 9 + box_size + row_start);
-
- /* Wipe out the previously entered password */
- grub_memset (entered, 0, sizeof (entered));
-@@ -714,6 +737,15 @@
-
- cls ();
- setcursor (1);
-+ /* if our terminal needed initialization, we should shut it down
-+ * before booting the kernel, but we want to save what it was so
-+ * we can come back if needed */
-+ prev_term = current_term;
-+ if (current_term->shutdown)
-+ {
-+ current_term->shutdown();
-+ current_term = term_table; /* assumption: console is first */
-+ }
-
- while (1)
- {
-@@ -748,6 +780,13 @@
- break;
- }
-
-+ /* if we get back here, we should go back to what our term was before */
-+ current_term = prev_term;
-+ if (current_term->startup)
-+ /* if our terminal fails to initialize, fall back to console since
-+ * it should always work */
-+ if (current_term->startup() == 0)
-+ current_term = term_table; /* we know that console is first */
- show_menu = 1;
- goto restart;
- }
-@@ -1050,6 +1089,16 @@
- while (is_preset);
- }
-
-+ /* go ahead and make sure the terminal is setup */
-+ if (current_term->startup)
-+ {
-+ /* If initialization fails, go back to default terminal */
-+ if (current_term->startup() == 0)
-+ {
-+ current_term = term_table;
-+ }
-+ }
-+
- if (! num_entries)
- {
- /* If no acceptable config file, goto command-line, starting
-diff -Naur grub-0.97.orig/stage2/term.h grub-0.97/stage2/term.h
---- grub-0.97.orig/stage2/term.h 2003-07-09 08:45:53.000000000 -0300
-+++ grub-0.97/stage2/term.h 2005-06-13 14:07:40.000000000 -0300
-@@ -60,6 +60,8 @@
- const char *name;
- /* The feature flags defined above. */
- unsigned long flags;
-+ /* Default for maximum number of lines if not specified */
-+ unsigned short max_lines;
- /* Put a character. */
- void (*putchar) (int c);
- /* Check if any input character is available. */
-@@ -79,6 +81,10 @@
- void (*setcolor) (int normal_color, int highlight_color);
- /* Turn on/off the cursor. */
- int (*setcursor) (int on);
-+ /* function to start a terminal */
-+ int (*startup) (void);
-+ /* function to use to shutdown a terminal */
-+ void (*shutdown) (void);
- };
-
- /* This lists up available terminals. */
-@@ -124,4 +130,24 @@
- int hercules_setcursor (int on);
- #endif
-
-+#ifdef SUPPORT_GRAPHICS
-+extern int foreground, background, window_border, graphics_inited,
saved_videomode;
-+
-+void graphics_set_splash(char *splashfile);
-+int set_videomode(int mode);
-+int get_videomode(void);
-+void graphics_putchar (int c);
-+int graphics_getxy(void);
-+void graphics_gotoxy(int x, int y);
-+void graphics_cls(void);
-+void graphics_setcolorstate (color_state state);
-+void graphics_setcolor (int normal_color, int highlight_color);
-+int graphics_setcursor (int on);
-+int graphics_init(void);
-+void graphics_end(void);
-+
-+int hex(int v);
-+void graphics_set_palette(int idx, int red, int green, int blue);
-+#endif /* SUPPORT_GRAPHICS */
-+
- #endif /* ! GRUB_TERM_HEADER */
diff --git a/stubdom/grub.patches/11graphics-keyboard.diff
b/stubdom/grub.patches/11graphics-keyboard.diff
deleted file mode 100644
index fe17b20a6f..0000000000
--- a/stubdom/grub.patches/11graphics-keyboard.diff
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/stage2/stage2.c b/stage2/stage2.c
-index 9d9fcc3..8353a3b 100644
---- a/stage2/stage2.c
-+++ b/stage2/stage2.c
-@@ -395,7 +395,7 @@ restart:
- pressed.
- This avoids polling (relevant in the grub-shell and later on
- in grub if interrupt driven I/O is done). */
-- if (checkkey () >= 0 || grub_timeout < 0)
-+ if (checkkey () > 0 || grub_timeout < 0)
- {
- /* Key was pressed, show which entry is selected before GETKEY,
- since we're comming in here also on GRUB_TIMEOUT == -1 and
diff --git a/stubdom/grub.patches/20print_func.diff
b/stubdom/grub.patches/20print_func.diff
deleted file mode 100644
index 71ad042ac2..0000000000
--- a/stubdom/grub.patches/20print_func.diff
+++ /dev/null
@@ -1,52 +0,0 @@
-2006-01-05 Otavio Salvador <otavio@xxxxxxxxxx>
-
- * Rediff.
-
-2005-16-10 Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
-
- * docs/grub.texi: Added print command description.
- * stage2/builtins.c(print_func): New function.
- (builtin_print): New variable.
- (builtin_table): Added builtin_print in table.
-
-Debian Status Following:
- Added by: Otavio Salvador
- Date: 2006-01-05
-
-diff -Nur grub-0.97-bkp/stage2/builtins.c grub-0.97/stage2/builtins.c
---- grub-0.97-bkp/stage2/builtins.c 2006-01-05 10:59:05.550350040 -0200
-+++ grub-0.97/stage2/builtins.c 2006-01-05 11:19:28.422445224 -0200
-@@ -2323,6 +2323,25 @@
- "Probe I/O ports used for the drive DRIVE."
- };
-
-+/* print */
-+static int
-+print_func (char *arg, int flags)
-+{
-+ printf("%s\n", arg);
-+
-+ return 0;
-+}
-+
-+static struct builtin builtin_print =
-+{
-+ "print",
-+ print_func,
-+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_NO_ECHO,
-+ "print [MESSAGE ...]",
-+ "Print MESSAGE."
-+};
-+
-+
-
- /* kernel */
- static int
-@@ -4848,6 +4867,7 @@
- &builtin_parttype,
- &builtin_password,
- &builtin_pause,
-+ &builtin_print,
- #ifdef GRUB_UTIL
- &builtin_quit,
- #endif /* GRUB_UTIL */
diff --git a/stubdom/grub.patches/30savedefault.diff
b/stubdom/grub.patches/30savedefault.diff
deleted file mode 100644
index 2902b876ec..0000000000
--- a/stubdom/grub.patches/30savedefault.diff
+++ /dev/null
@@ -1,186 +0,0 @@
-Index: grub/stage2/builtins.c
-===================================================================
---- grub.orig/stage2/builtins.c 2008-06-02 18:06:08.942580000 +0100
-+++ grub/stage2/builtins.c 2008-06-06 18:35:07.548390000 +0100
-@@ -86,6 +86,10 @@
- inside other functions. */
- static int configfile_func (char *arg, int flags);
-
-+static int savedefault_helper (char *arg, int flags);
-+
-+static int savedefault_shell (char *arg, int flags);
-+
- /* Initialize the data for builtins. */
- void
- init_builtins (void)
-@@ -3512,7 +3516,109 @@
- static int
- savedefault_func (char *arg, int flags)
- {
--#if !defined(SUPPORT_DISKLESS) && !defined(GRUB_UTIL)
-+#if !defined(SUPPORT_DISKLESS)
-+ #if !defined(GRUB_UTIL)
-+ return savedefault_helper(arg, flags);
-+ #else
-+ return savedefault_shell(arg, flags);
-+ #endif
-+#else /* !SUPPORT_DISKLESS */
-+ errnum = ERR_UNRECOGNIZED;
-+ return 1;
-+#endif /* !SUPPORT_DISKLESS */
-+}
-+
-+#if !defined(SUPPORT_DISKLESS) && defined(GRUB_UTIL)
-+/* savedefault_shell */
-+static int
-+savedefault_shell(char *arg, int flags)
-+ {
-+ int once_only = 0;
-+ int new_default;
-+ int curr_default = -1;
-+ int curr_prev_default = -1;
-+ int new_prev_default = -1;
-+ FILE *fp;
-+ size_t bytes = 10;
-+ char line[bytes];
-+ char *default_file = (char *) DEFAULT_FILE_BUF;
-+ char buf[bytes];
-+ int i;
-+
-+ while (1)
-+ {
-+ if (grub_memcmp ("--default=", arg, sizeof ("--default=") - 1) == 0)
-+ {
-+ char *p = arg + sizeof ("--default=") - 1;
-+ if (! safe_parse_maxint (&p, &new_default))
-+ return 1;
-+ arg = skip_to (0, arg);
-+ }
-+ else if (grub_memcmp ("--once", arg, sizeof ("--once") - 1) == 0)
-+ {
-+ once_only = 1;
-+ arg = skip_to (0, arg);
-+ }
-+ else
-+ break;
-+ }
-+
-+ *default_file = 0;
-+ grub_strncat (default_file, config_file, DEFAULT_FILE_BUFLEN);
-+ for (i = grub_strlen(default_file); i >= 0; i--)
-+ if (default_file[i] == '/')
-+ {
-+ i++;
-+ break;
-+ }
-+ default_file[i] = 0;
-+ grub_strncat (default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
-+
-+ if(!(fp = fopen(default_file,"r")))
-+ {
-+ errnum = ERR_READ;
-+ goto fail;
-+ }
-+
-+ fgets(line, bytes, fp);
-+ fclose(fp);
-+
-+ sscanf(line, "%d:%d", &curr_prev_default, &curr_default);
-+
-+ if(curr_default != -1)
-+ new_prev_default = curr_default;
-+ else
-+ {
-+ if(curr_prev_default != -1)
-+ new_prev_default = curr_prev_default;
-+ else
-+ new_prev_default = 0;
-+ }
-+
-+ if(once_only)
-+ sprintf(buf, "%d:%d", new_prev_default, new_default);
-+ else
-+ sprintf(buf, "%d", new_default);
-+
-+ if(!(fp = fopen(default_file,"w")))
-+ {
-+ errnum = ERR_READ;
-+ goto fail;
-+ }
-+
-+ fprintf(fp, buf);
-+
-+fail:
-+ fclose(fp);
-+ return errnum;
-+}
-+#endif
-+
-+/* savedefault_helper */
-+static int
-+savedefault_helper (char *arg, int flags)
-+{
-+#if !defined(SUPPORT_DISKLESS)
- unsigned long tmp_drive = saved_drive;
- unsigned long tmp_partition = saved_partition;
- char *default_file = (char *) DEFAULT_FILE_BUF;
-@@ -3588,22 +3694,26 @@
-
- disk_read_hook = disk_read_savesect_func;
- len = grub_read (buf, sizeof (buf));
-+ buf[9]='\0';/* Make sure grub_strstr() below terminates */
- disk_read_hook = 0;
- grub_close ();
-
-- if (len != sizeof (buf))
-- {
-- /* This is too small. Do not modify the file manually, please! */
-- errnum = ERR_READ;
-- goto fail;
-- }
--
- if (sector_count > 2)
- {
- /* Is this possible?! Too fragmented! */
- errnum = ERR_FSYS_CORRUPT;
- goto fail;
- }
-+
-+ char *tmp;
-+ if((tmp = grub_strstr(buf, ":")) != NULL)
-+ {
-+ int f_len = grub_strlen(buf) - grub_strlen(tmp);
-+ char *def;
-+ buf[f_len] = '\0';
-+ def = buf;
-+ safe_parse_maxint (&def, &entryno);
-+ }
-
- /* Set up a string to be written. */
- grub_memset (buf, '\n', sizeof (buf));
-Index: grub/stage2/stage2.c
-===================================================================
---- grub.orig/stage2/stage2.c 2008-06-02 18:06:08.858579000 +0100
-+++ grub/stage2/stage2.c 2008-06-06 18:04:03.585354000 +0100
-@@ -49,7 +49,8 @@
- return 0;
- #endif /* GRUB_UTIL */
-
-- preset_menu_offset = 0;
-+ if (preset_menu_offset)
-+ return 0;
- return preset_menu != 0;
- }
-
-@@ -934,7 +935,11 @@
- len = grub_read (buf, sizeof (buf));
- if (len > 0)
- {
-+ char *tmp;
- buf[sizeof (buf) - 1] = 0;
-+ if((tmp = grub_strstr(p, ":")) != NULL)
-+ p = tmp + 1;
-+
- safe_parse_maxint (&p, &saved_entryno);
- }
-
diff --git a/stubdom/grub.patches/40ext3_256byte_inode.diff
b/stubdom/grub.patches/40ext3_256byte_inode.diff
deleted file mode 100644
index 0c40854f94..0000000000
--- a/stubdom/grub.patches/40ext3_256byte_inode.diff
+++ /dev/null
@@ -1,114 +0,0 @@
-
-Patch from Red Hat. See #463236, #463123.
-
-Index: grub/stage2/fsys_ext2fs.c
-===================================================================
---- grub.orig/stage2/fsys_ext2fs.c 2008-05-27 18:47:19.045183000 +0100
-+++ grub/stage2/fsys_ext2fs.c 2008-05-27 19:09:21.293187000 +0100
-@@ -79,7 +79,52 @@
- __u32 s_rev_level; /* Revision level */
- __u16 s_def_resuid; /* Default uid for reserved blocks */
- __u16 s_def_resgid; /* Default gid for reserved blocks */
-- __u32 s_reserved[235]; /* Padding to the end of the block */
-+ /*
-+ * These fields are for EXT2_DYNAMIC_REV superblocks only.
-+ *
-+ * Note: the difference between the compatible feature set and
-+ * the incompatible feature set is that if there is a bit set
-+ * in the incompatible feature set that the kernel doesn't
-+ * know about, it should refuse to mount the filesystem.
-+ *
-+ * e2fsck's requirements are more strict; if it doesn't know
-+ * about a feature in either the compatible or incompatible
-+ * feature set, it must abort and not try to meddle with
-+ * things it doesn't understand...
-+ */
-+ __u32 s_first_ino; /* First non-reserved inode */
-+ __u16 s_inode_size; /* size of inode structure */
-+ __u16 s_block_group_nr; /* block group # of this superblock */
-+ __u32 s_feature_compat; /* compatible feature set */
-+ __u32 s_feature_incompat; /* incompatible feature set */
-+ __u32 s_feature_ro_compat; /* readonly-compatible feature set */
-+ __u8 s_uuid[16]; /* 128-bit uuid for volume */
-+ char s_volume_name[16]; /* volume name */
-+ char s_last_mounted[64]; /* directory where last mounted */
-+ __u32 s_algorithm_usage_bitmap; /* For compression */
-+ /*
-+ * Performance hints. Directory preallocation should only
-+ * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
-+ */
-+ __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
-+ __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
-+ __u16 s_reserved_gdt_blocks;/* Per group table for online growth */
-+ /*
-+ * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
-+ */
-+ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
-+ __u32 s_journal_inum; /* inode number of journal file */
-+ __u32 s_journal_dev; /* device number of journal file */
-+ __u32 s_last_orphan; /* start of list of inodes to delete */
-+ __u32 s_hash_seed[4]; /* HTREE hash seed */
-+ __u8 s_def_hash_version; /* Default hash version to use */
-+ __u8 s_jnl_backup_type; /* Default type of journal backup */
-+ __u16 s_reserved_word_pad;
-+ __u32 s_default_mount_opts;
-+ __u32 s_first_meta_bg; /* First metablock group */
-+ __u32 s_mkfs_time; /* When the filesystem was created */
-+ __u32 s_jnl_blocks[17]; /* Backup of the journal inode */
-+ __u32 s_reserved[172]; /* Padding to the end of the block */
- };
-
- struct ext2_group_desc
-@@ -218,6 +263,9 @@
- #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
- #define EXT2_ADDR_PER_BLOCK_BITS(s) (log2(EXT2_ADDR_PER_BLOCK(s)))
-
-+#define EXT2_INODE_SIZE(s) (SUPERBLOCK->s_inode_size)
-+#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
-+
- /* linux/ext2_fs.h */
- #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
- /* kind of from ext2/super.c */
-@@ -242,7 +290,14 @@
- static __inline__ unsigned long
- ffz (unsigned long word)
- {
-- __asm__ ("bsfl %1,%0"
-+ __asm__ ("bsf"
-+#ifdef __i386__
-+ "l"
-+#endif
-+#ifdef __x86_64__
-+ "q"
-+#endif
-+ " %1,%0"
- : "=r" (word)
- : "r" (~word));
- return word;
-@@ -553,7 +608,7 @@
- gdp = GROUP_DESC;
- ino_blk = gdp[desc].bg_inode_table +
- (((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
-- >> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
-+ >> log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
- #ifdef E2DEBUG
- printf ("inode table fsblock=%d\n", ino_blk);
- #endif /* E2DEBUG */
-@@ -565,13 +620,12 @@
- /* reset indirect blocks! */
- mapblock2 = mapblock1 = -1;
-
-- raw_inode = INODE +
-- ((current_ino - 1)
-- & (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode) - 1));
-+ raw_inode = (struct ext2_inode *)((char *)INODE +
-+ ((current_ino - 1) & (EXT2_INODES_PER_BLOCK (SUPERBLOCK) - 1)) *
-+ EXT2_INODE_SIZE (SUPERBLOCK));
- #ifdef E2DEBUG
- printf ("ipb=%d, sizeof(inode)=%d\n",
-- (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)),
-- sizeof (struct ext2_inode));
-+ EXT2_INODES_PER_BLOCK (SUPERBLOCK), EXT2_INODE_SIZE (SUPERBLOCK));
- printf ("inode=%x, raw_inode=%x\n", INODE, raw_inode);
- printf ("offset into inode table block=%d\n", (int) raw_inode - (int)
INODE);
- for (i = (unsigned char *) INODE; i <= (unsigned char *) raw_inode;
diff --git a/stubdom/grub.patches/50fs_fulldisk.diff
b/stubdom/grub.patches/50fs_fulldisk.diff
deleted file mode 100644
index d0fbb07bc1..0000000000
--- a/stubdom/grub.patches/50fs_fulldisk.diff
+++ /dev/null
@@ -1,72 +0,0 @@
-diff -urN grub-0.97.orig/stage2/fsys_ext2fs.c grub-0.97/stage2/fsys_ext2fs.c
---- grub-0.97.orig/stage2/fsys_ext2fs.c 2004-08-08 18:19:18.000000000
+0000
-+++ grub-0.97/stage2/fsys_ext2fs.c 2008-09-16 19:31:15.000000000 +0000
-@@ -254,7 +254,7 @@
- {
- int retval = 1;
-
-- if ((((current_drive & 0x80) || (current_slice != 0))
-+ if ((((current_slice != 0))
- && (current_slice != PC_SLICE_TYPE_EXT2FS)
- && (current_slice != PC_SLICE_TYPE_LINUX_RAID)
- && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_EXT2FS))
-diff -urN grub-0.97.orig/stage2/fsys_fat.c grub-0.97/stage2/fsys_fat.c
---- grub-0.97.orig/stage2/fsys_fat.c 2005-03-15 16:52:00.000000000 +0000
-+++ grub-0.97/stage2/fsys_fat.c 2008-09-16 19:31:26.000000000 +0000
-@@ -70,7 +70,7 @@
- __u32 magic, first_fat;
-
- /* Check partition type for harddisk */
-- if (((current_drive & 0x80) || (current_slice != 0))
-+ if (((current_slice != 0))
- && ! IS_PC_SLICE_TYPE_FAT (current_slice)
- && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_MSDOS)))
- return 0;
-diff -urN grub-0.97.orig/stage2/fsys_ffs.c grub-0.97/stage2/fsys_ffs.c
---- grub-0.97.orig/stage2/fsys_ffs.c 2003-07-09 11:45:52.000000000 +0000
-+++ grub-0.97/stage2/fsys_ffs.c 2008-09-16 19:31:32.000000000 +0000
-@@ -82,7 +82,7 @@
- {
- int retval = 1;
-
-- if ((((current_drive & 0x80) || (current_slice != 0))
-+ if ((((current_slice != 0))
- && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_BSDFFS))
- || part_length < (SBLOCK + (SBSIZE / DEV_BSIZE))
- || !devread (SBLOCK, 0, SBSIZE, (char *) SUPERBLOCK)
-diff -urN grub-0.97.orig/stage2/fsys_minix.c grub-0.97/stage2/fsys_minix.c
---- grub-0.97.orig/stage2/fsys_minix.c 2003-07-09 11:45:53.000000000 +0000
-+++ grub-0.97/stage2/fsys_minix.c 2008-09-16 19:32:01.000000000 +0000
-@@ -160,7 +160,7 @@
- int
- minix_mount (void)
- {
-- if (((current_drive & 0x80) || current_slice != 0)
-+ if ((current_slice != 0)
- && ! IS_PC_SLICE_TYPE_MINIX (current_slice)
- && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER))
- return 0; /* The partition is not of MINIX type */
-diff -urN grub-0.97.orig/stage2/fsys_ufs2.c grub-0.97/stage2/fsys_ufs2.c
---- grub-0.97.orig/stage2/fsys_ufs2.c 2004-06-19 12:17:52.000000000 +0000
-+++ grub-0.97/stage2/fsys_ufs2.c 2008-09-16 19:32:32.000000000 +0000
-@@ -87,7 +87,7 @@
- sblockloc = -1;
- type = 0;
-
-- if (! (((current_drive & 0x80) || (current_slice != 0))
-+ if (! (((current_slice != 0))
- && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_BSDFFS)))
- {
- for (i = 0; sblock_try[i] != -1; ++i)
-diff -urN grub-0.97.orig/stage2/fsys_vstafs.c grub-0.97/stage2/fsys_vstafs.c
---- grub-0.97.orig/stage2/fsys_vstafs.c 2003-07-09 11:45:53.000000000
+0000
-+++ grub-0.97/stage2/fsys_vstafs.c 2008-09-16 19:32:39.000000000 +0000
-@@ -47,7 +47,7 @@
- {
- int retval = 1;
-
-- if( (((current_drive & 0x80) || (current_slice != 0))
-+ if( (((current_slice != 0))
- && current_slice != PC_SLICE_TYPE_VSTAFS)
- || ! devread (0, 0, BLOCK_SIZE, (char *) FSYS_BUF)
- || FIRST_SECTOR->fs_magic != 0xDEADFACE)
diff --git a/stubdom/grub.patches/60ext4.diff b/stubdom/grub.patches/60ext4.diff
deleted file mode 100644
index c71cfe1c4f..0000000000
--- a/stubdom/grub.patches/60ext4.diff
+++ /dev/null
@@ -1,474 +0,0 @@
-Index: grub-0.97/stage2/fsys_ext2fs.c
-===================================================================
---- grub-0.97.orig/stage2/fsys_ext2fs.c
-+++ grub-0.97/stage2/fsys_ext2fs.c
-@@ -41,6 +41,7 @@ typedef __signed__ short __s16;
- typedef unsigned short __u16;
- typedef __signed__ int __s32;
- typedef unsigned int __u32;
-+typedef unsigned long long __u64;
-
- /*
- * Constants relative to the data blocks, from ext2_fs.h
-@@ -51,7 +52,7 @@ typedef unsigned int __u32;
- #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
- #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
-
--/* include/linux/ext2_fs.h */
-+/* lib/ext2fs/ext2_fs.h from e2fsprogs */
- struct ext2_super_block
- {
- __u32 s_inodes_count; /* Inodes count */
-@@ -61,9 +62,9 @@ struct ext2_super_block
- __u32 s_free_inodes_count; /* Free inodes count */
- __u32 s_first_data_block; /* First Data Block */
- __u32 s_log_block_size; /* Block size */
-- __s32 s_log_frag_size; /* Fragment size */
-+ __s32 s_obso_log_frag_size; /* Obsoleted Fragment size */
- __u32 s_blocks_per_group; /* # Blocks per group */
-- __u32 s_frags_per_group; /* # Fragments per group */
-+ __u32 s_obso_frags_per_group; /* Obsoleted Fragments per group */
- __u32 s_inodes_per_group; /* # Inodes per group */
- __u32 s_mtime; /* Mount time */
- __u32 s_wtime; /* Write time */
-@@ -72,7 +73,7 @@ struct ext2_super_block
- __u16 s_magic; /* Magic signature */
- __u16 s_state; /* File system state */
- __u16 s_errors; /* Behaviour when detecting errors */
-- __u16 s_pad;
-+ __u16 s_minor_rev_level; /* minor revision level */
- __u32 s_lastcheck; /* time of last check */
- __u32 s_checkinterval; /* max. time between checks */
- __u32 s_creator_os; /* OS */
-@@ -119,15 +120,29 @@ struct ext2_super_block
- __u32 s_hash_seed[4]; /* HTREE hash seed */
- __u8 s_def_hash_version; /* Default hash version to use */
- __u8 s_jnl_backup_type; /* Default type of journal backup */
-- __u16 s_reserved_word_pad;
-+ __u16 s_desc_size; /* size of group descriptor */
- __u32 s_default_mount_opts;
- __u32 s_first_meta_bg; /* First metablock group */
- __u32 s_mkfs_time; /* When the filesystem was created */
- __u32 s_jnl_blocks[17]; /* Backup of the journal inode */
-- __u32 s_reserved[172]; /* Padding to the end of the block */
-- };
-+ /* 64bit desc support valid if EXT4_FEATURE_INCOMPAT_64BIT */
-+ __u32 s_blocks_count_hi; /* Blocks count */
-+ __u32 s_r_blocks_count_hi; /* Reserved blocks count */
-+ __u32 s_free_blocks_count_hi; /* Free blocks count */
-+ __u16 s_min_extra_isize; /* All inodes have at least # bytes */
-+ __u16 s_max_extra_isize; /* New inodes should reverve # bytes */
-+ __u32 s_flags; /* Miscellaneous flags */
-+ __u16 s_raid_stride; /* Raid stride */
-+ __u16 s_mmp_interval; /* # seconds to wait MMP checking */
-+ __u64 s_mmp_block; /* Block for multi-mount protection */
-+ __u32 s_raid_stripe_width; /* Blocks on all data disks (N*stride)*/
-+ __u8 s_log_groups_per_flex;/* FLEX_BG group size*/
-+ __u8 s_reserved_char_pad;
-+ __u16 s_reserved_pad;
-+ __u32 s_reserved[162]; /* Padding to the end of the block */
-+};
-
--struct ext2_group_desc
-+struct ext4_group_desc
- {
- __u32 bg_block_bitmap; /* Blocks bitmap block */
- __u32 bg_inode_bitmap; /* Inodes bitmap block */
-@@ -135,8 +150,18 @@ struct ext2_group_desc
- __u16 bg_free_blocks_count; /* Free blocks count */
- __u16 bg_free_inodes_count; /* Free inodes count */
- __u16 bg_used_dirs_count; /* Directories count */
-- __u16 bg_pad;
-- __u32 bg_reserved[3];
-+ __u16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
-+ __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */
-+ __u16 bg_itable_unused; /* Unused inodes count */
-+ __u16 bg_checksum; /* crc16(sb_uuid+group+desc) */
-+ __u32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
-+ __u32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
-+ __u32 bg_inode_table_hi; /* Inodes table block MSB */
-+ __u16 bg_free_blocks_count_hi;/* Free blocks count MSB */
-+ __u16 bg_free_inodes_count_hi;/* Free inodes count MSB */
-+ __u16 bg_used_dirs_count_hi; /* Directories count MSB */
-+ __u16 bg_itable_unused_hi; /* Unused inodes count MSB */
-+ __u32 bg_reserved2[3];
- };
-
- struct ext2_inode
-@@ -174,22 +199,22 @@ struct ext2_inode
- __u32 i_block[EXT2_N_BLOCKS]; /* 40: Pointers to blocks */
- __u32 i_version; /* File version (for NFS) */
- __u32 i_file_acl; /* File ACL */
-- __u32 i_dir_acl; /* Directory ACL */
-- __u32 i_faddr; /* Fragment address */
-+ __u32 i_size_high;
-+ __u32 i_obso_faddr; /* Obsoleted fragment address */
- union
- {
- struct
- {
-- __u8 l_i_frag; /* Fragment number */
-- __u8 l_i_fsize; /* Fragment size */
-- __u16 i_pad1;
-- __u32 l_i_reserved2[2];
-+ __u16 l_i_blocks_high; /* were l_i_reserved1 */
-+ __u16 l_i_file_acl_high;
-+ __u16 l_i_uid_high; /* these 2 fields */
-+ __u16 l_i_gid_high; /* were reserved2[0] */
-+ __u32 l_i_reserved2;
- }
- linux2;
- struct
- {
-- __u8 h_i_frag; /* Fragment number */
-- __u8 h_i_fsize; /* Fragment size */
-+ __u16 h_i_reserved1; /* Obsoleted fragment number/size which
are removed in ext4 */
- __u16 h_i_mode_high;
- __u16 h_i_uid_high;
- __u16 h_i_gid_high;
-@@ -198,16 +223,36 @@ struct ext2_inode
- hurd2;
- struct
- {
-- __u8 m_i_frag; /* Fragment number */
-- __u8 m_i_fsize; /* Fragment size */
-- __u16 m_pad1;
-+ __u16 h_i_reserved1; /* Obsoleted fragment number/size which
are removed in ext4 */
-+ __u16 m_i_file_acl_high;
- __u32 m_i_reserved2[2];
- }
- masix2;
- }
- osd2; /* OS dependent 2 */
-+ __u16 i_extra_isize;
-+ __u16 i_pad1;
-+ __u32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
-+ __u32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
-+ __u32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
-+ __u32 i_crtime; /* File Creation time */
-+ __u32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
-+ __u32 i_version_hi; /* high 32 bits for 64-bit version */
- };
-
-+#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
-+#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 /* grub not
supported*/
-+#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
-+#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
-+
-+#define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
-+ ( sb->s_feature_incompat & mask )
-+
-+#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
-+#define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
-+
-+#define EXT4_MIN_DESC_SIZE 32
-+
- /* linux/limits.h */
- #define NAME_MAX 255 /* # chars in a file name */
-
-@@ -225,6 +270,57 @@ struct ext2_dir_entry
- char name[EXT2_NAME_LEN]; /* File name */
- };
-
-+/* linux/ext4_fs_extents.h */
-+/* This is the extent on-disk structure.
-+ * It's used at the bottom of the tree.
-+ */
-+struct ext4_extent
-+ {
-+ __u32 ee_block; /* first logical block extent covers */
-+ __u16 ee_len; /* number of blocks covered by extent */
-+ __u16 ee_start_hi; /* high 16 bits of physical block */
-+ __u32 ee_start_lo; /* low 32 bits of physical block */
-+ };
-+
-+/*
-+ * This is index on-disk structure.
-+ * It's used at all the levels except the bottom.
-+ */
-+struct ext4_extent_idx
-+ {
-+ __u32 ei_block; /* index covers logical blocks from 'block' */
-+ __u32 ei_leaf_lo; /* pointer to the physical block of the next *
-+ * level. leaf or next index could be there */
-+ __u16 ei_leaf_hi; /* high 16 bits of physical block */
-+ __u16 ei_unused;
-+ };
-+
-+/*
-+ * Each block (leaves and indexes), even inode-stored has header.
-+ */
-+struct ext4_extent_header
-+ {
-+ __u16 eh_magic; /* probably will support different formats */
-+ __u16 eh_entries; /* number of valid entries */
-+ __u16 eh_max; /* capacity of store in entries */
-+ __u16 eh_depth; /* has tree real underlying blocks? */
-+ __u32 eh_generation; /* generation of the tree */
-+ };
-+
-+#define EXT4_EXT_MAGIC (0xf30a)
-+#define EXT_FIRST_EXTENT(__hdr__) \
-+ ((struct ext4_extent *) (((char *) (__hdr__)) + \
-+ sizeof(struct ext4_extent_header)))
-+#define EXT_FIRST_INDEX(__hdr__) \
-+ ((struct ext4_extent_idx *) (((char *) (__hdr__)) + \
-+ sizeof(struct ext4_extent_header)))
-+#define EXT_LAST_EXTENT(__hdr__) \
-+ (EXT_FIRST_EXTENT((__hdr__)) + (__u16)((__hdr__)->eh_entries) - 1)
-+#define EXT_LAST_INDEX(__hdr__) \
-+ (EXT_FIRST_INDEX((__hdr__)) + (__u16)((__hdr__)->eh_entries) - 1)
-+
-+
-+
- /* linux/ext2fs.h */
- /*
- * EXT2_DIR_PAD defines the directory entries boundaries
-@@ -271,8 +367,17 @@ struct ext2_dir_entry
- /* kind of from ext2/super.c */
- #define EXT2_BLOCK_SIZE(s) (1 << EXT2_BLOCK_SIZE_BITS(s))
- /* linux/ext2fs.h */
-+/* sizeof(struct ext2_group_desc) is changed in ext4
-+ * in kernel code, ext2/3 uses sizeof(struct ext2_group_desc) to calculate
-+ * number of desc per block, while ext4 uses superblock->s_desc_size in stead
-+ * superblock->s_desc_size is not available in ext2/3
-+ * */
-+#define EXT2_DESC_SIZE(s) \
-+ (EXT4_HAS_INCOMPAT_FEATURE(s,EXT4_FEATURE_INCOMPAT_64BIT)? \
-+ s->s_desc_size : EXT4_MIN_DESC_SIZE)
- #define EXT2_DESC_PER_BLOCK(s) \
-- (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
-+ (EXT2_BLOCK_SIZE(s) / EXT2_DESC_SIZE(s))
-+
- /* linux/stat.h */
- #define S_IFMT 00170000
- #define S_IFLNK 0120000
-@@ -434,6 +539,122 @@ ext2fs_block_map (int logical_block)
- [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
- }
-
-+/* extent binary search index
-+ * find closest index in the current level extent tree
-+ * kind of from ext4_ext_binsearch_idx in ext4/extents.c
-+ */
-+static struct ext4_extent_idx*
-+ext4_ext_binsearch_idx(struct ext4_extent_header* eh, int logical_block)
-+{
-+ struct ext4_extent_idx *r, *l, *m;
-+ l = EXT_FIRST_INDEX(eh) + 1;
-+ r = EXT_LAST_INDEX(eh);
-+ while (l <= r)
-+ {
-+ m = l + (r - l) / 2;
-+ if (logical_block < m->ei_block)
-+ r = m - 1;
-+ else
-+ l = m + 1;
-+ }
-+ return (struct ext4_extent_idx*)(l - 1);
-+}
-+
-+/* extent binary search
-+ * find closest extent in the leaf level
-+ * kind of from ext4_ext_binsearch in ext4/extents.c
-+ */
-+static struct ext4_extent*
-+ext4_ext_binsearch(struct ext4_extent_header* eh, int logical_block)
-+{
-+ struct ext4_extent *r, *l, *m;
-+ l = EXT_FIRST_EXTENT(eh) + 1;
-+ r = EXT_LAST_EXTENT(eh);
-+ while (l <= r)
-+ {
-+ m = l + (r - l) / 2;
-+ if (logical_block < m->ee_block)
-+ r = m - 1;
-+ else
-+ l = m + 1;
-+ }
-+ return (struct ext4_extent*)(l - 1);
-+}
-+
-+/* Maps extents enabled logical block into physical block via an inode.
-+ * EXT4_HUGE_FILE_FL should be checked before calling this.
-+ */
-+static int
-+ext4fs_block_map (int logical_block)
-+{
-+ struct ext4_extent_header *eh;
-+ struct ext4_extent *ex, *extent;
-+ struct ext4_extent_idx *ei, *index;
-+ int depth;
-+ int i;
-+
-+#ifdef E2DEBUG
-+ unsigned char *i;
-+ for (i = (unsigned char *) INODE;
-+ i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
-+ i++)
-+ {
-+ printf ("%c", "0123456789abcdef"[*i >> 4]);
-+ printf ("%c", "0123456789abcdef"[*i % 16]);
-+ if (!((i + 1 - (unsigned char *) INODE) % 16))
-+ {
-+ printf ("\n");
-+ }
-+ else
-+ {
-+ printf (" ");
-+ }
-+ }
-+ printf ("logical block %d\n", logical_block);
-+#endif /* E2DEBUG */
-+ eh = (struct ext4_extent_header*)INODE->i_block;
-+ if (eh->eh_magic != EXT4_EXT_MAGIC)
-+ {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return -1;
-+ }
-+ while((depth = eh->eh_depth) != 0)
-+ { /* extent index */
-+ if (eh->eh_magic != EXT4_EXT_MAGIC)
-+ {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return -1;
-+ }
-+ ei = ext4_ext_binsearch_idx(eh, logical_block);
-+ if (ei->ei_leaf_hi)
-+ {/* 64bit physical block number not supported */
-+ errnum = ERR_FILELENGTH;
-+ return -1;
-+ }
-+ if (!ext2_rdfsb(ei->ei_leaf_lo, DATABLOCK1))
-+ {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return -1;
-+ }
-+ eh = (struct ext4_extent_header*)DATABLOCK1;
-+ }
-+
-+ /* depth==0, we come to the leaf */
-+ ex = ext4_ext_binsearch(eh, logical_block);
-+ if (ex->ee_start_hi)
-+ {/* 64bit physical block number not supported */
-+ errnum = ERR_FILELENGTH;
-+ return -1;
-+ }
-+ if ((ex->ee_block + ex->ee_len) < logical_block)
-+ {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return -1;
-+ }
-+ return ex->ee_start_lo + logical_block - ex->ee_block;
-+
-+}
-+
- /* preconditions: all preconds of ext2fs_block_map */
- int
- ext2fs_read (char *buf, int len)
-@@ -468,6 +689,11 @@ ext2fs_read (char *buf, int len)
- /* find the (logical) block component of our location */
- logical_block = filepos >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
- offset = filepos & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
-+ /* map extents enabled logical block number to physical fs on-disk
block number */
-+ if (EXT4_HAS_INCOMPAT_FEATURE(SUPERBLOCK,EXT4_FEATURE_INCOMPAT_EXTENTS)
-+ && INODE->i_flags & EXT4_EXTENTS_FL)
-+ map = ext4fs_block_map (logical_block);
-+ else
- map = ext2fs_block_map (logical_block);
- #ifdef E2DEBUG
- printf ("map=%d\n", map);
-@@ -552,7 +778,7 @@ ext2fs_dir (char *dirname)
- int desc; /* index within that group */
- int ino_blk; /* fs pointer of the inode's
information */
- int str_chk = 0; /* used to hold the results of a string compare
*/
-- struct ext2_group_desc *gdp;
-+ struct ext4_group_desc *ext4_gdp;
- struct ext2_inode *raw_inode; /* inode info corresponding to
current_ino */
-
- char linkbuf[PATH_MAX]; /* buffer for following symbolic links */
-@@ -598,8 +824,15 @@ ext2fs_dir (char *dirname)
- {
- return 0;
- }
-- gdp = GROUP_DESC;
-- ino_blk = gdp[desc].bg_inode_table +
-+ ext4_gdp = (struct ext4_group_desc *)( (__u8*)GROUP_DESC +
-+ desc * EXT2_DESC_SIZE(SUPERBLOCK));
-+ if (EXT4_HAS_INCOMPAT_FEATURE(SUPERBLOCK, EXT4_FEATURE_INCOMPAT_64BIT)
-+ && (! ext4_gdp->bg_inode_table_hi))
-+ {/* 64bit itable not supported */
-+ errnum = ERR_FILELENGTH;
-+ return -1;
-+ }
-+ ino_blk = ext4_gdp->bg_inode_table +
- (((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
- >> log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
- #ifdef E2DEBUG
-@@ -676,7 +909,10 @@ ext2fs_dir (char *dirname)
- }
- linkbuf[filemax + len] = '\0';
-
-- /* Read the symlink data. */
-+ /* Read the symlink data.
-+ * Slow symlink is extents enabled
-+ * But since grub_read invokes ext2fs_read, nothing to change here
-+ */
- if (! ext2_is_fast_symlink ())
- {
- /* Read the necessary blocks, and reset the file pointer. */
-@@ -687,7 +923,9 @@ ext2fs_dir (char *dirname)
- }
- else
- {
-- /* Copy the data directly from the inode. */
-+ /* Copy the data directly from the inode.
-+ * Fast symlink is not extents enabled
-+ */
- len = filemax;
- memmove (linkbuf, (char *) INODE->i_block, len);
- }
-@@ -721,6 +959,13 @@ ext2fs_dir (char *dirname)
- errnum = ERR_BAD_FILETYPE;
- return 0;
- }
-+ /* if file is too large, just stop and report an error*/
-+ if ( (INODE->i_flags & EXT4_HUGE_FILE_FL) && !(INODE->i_size_high))
-+ {
-+ /* file too large, stop reading */
-+ errnum = ERR_FILELENGTH;
-+ return 0;
-+ }
-
- filemax = (INODE->i_size);
- return 1;
-@@ -775,17 +1020,28 @@ ext2fs_dir (char *dirname)
- }
-
- /* else, find the (logical) block component of our location */
-+ /* ext4 logical block number the same as ext2/3 */
- blk = loc >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
-
- /* we know which logical block of the directory entry we are looking
- for, now we have to translate that to the physical (fs) block on
- the disk */
-+ /* map extents enabled logical block number to physical fs on-disk
block number */
-+ if
(EXT4_HAS_INCOMPAT_FEATURE(SUPERBLOCK,EXT4_FEATURE_INCOMPAT_EXTENTS)
-+ && INODE->i_flags & EXT4_EXTENTS_FL)
-+ map = ext4fs_block_map (blk);
-+ else
- map = ext2fs_block_map (blk);
- #ifdef E2DEBUG
- printf ("fs block=%d\n", map);
- #endif /* E2DEBUG */
- mapblock2 = -1;
-- if ((map < 0) || !ext2_rdfsb (map, DATABLOCK2))
-+ if (map < 0)
-+ {
-+ *rest = ch;
-+ return 0;
-+ }
-+ if (!ext2_rdfsb (map, DATABLOCK2))
- {
- errnum = ERR_FSYS_CORRUPT;
- *rest = ch;
diff --git a/stubdom/grub.patches/61btrfs.diff
b/stubdom/grub.patches/61btrfs.diff
deleted file mode 100644
index ae8f866e50..0000000000
--- a/stubdom/grub.patches/61btrfs.diff
+++ /dev/null
@@ -1,3499 +0,0 @@
-diff -up grub-upstream.wip/AUTHORS.btrfs grub-upstream.wip/AUTHORS
---- grub-upstream.wip/AUTHORS.btrfs 2004-03-27 16:25:17.000000000 +0000
-+++ grub-upstream.wip/AUTHORS 2012-03-20 05:07:09.000000000 +0000
-@@ -41,6 +41,8 @@ Kristoffer Branemyr added VSTa filesyste
-
- Serguei Tzukanov added JFS and XFS support.
-
-+Edward Shishkin added Btrfs support.
-+
- Jason Thomas added Linux DAC960 support and support for hiding/unhiding
- logical partitions, and did a significant bugfix for the terminal stuff.
-
-diff -up grub-upstream.wip/configure.ac.btrfs grub-upstream.wip/configure.ac
---- grub-upstream.wip/configure.ac.btrfs 2012-03-20 05:06:49.000000000
+0000
-+++ grub-upstream.wip/configure.ac 2012-03-20 05:07:09.000000000 +0000
-@@ -274,6 +274,13 @@ if test x"$enable_reiserfs" != xno; then
- FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_REISERFS=1"
- fi
-
-+AC_ARG_ENABLE(btrfs,
-+ [ --disable-btrfs disable BtrFS support in Stage 2])
-+
-+if test x"$enable_btrfs" != xno; then
-+ FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_BTRFS=1"
-+fi
-+
- AC_ARG_ENABLE(vstafs,
- [ --disable-vstafs disable VSTa FS support in Stage 2])
-
-diff -up grub-upstream.wip/grub/Makefile.am.btrfs
grub-upstream.wip/grub/Makefile.am
---- grub-upstream.wip/grub/Makefile.am.btrfs 2005-02-02 20:38:19.000000000
+0000
-+++ grub-upstream.wip/grub/Makefile.am 2012-03-20 05:07:09.000000000 +0000
-@@ -8,7 +8,7 @@ endif
-
- AM_CPPFLAGS = -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
- -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
-- -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
-+ -DFSYS_BTRFS=1 -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
- -DUSE_MD5_PASSWORDS=1 -DSUPPORT_HERCULES=1 \
- $(SERIAL_FLAGS) -I$(top_srcdir)/stage2 \
- -I$(top_srcdir)/stage1 -I$(top_srcdir)/lib
-diff -up grub-upstream.wip/INSTALL.btrfs grub-upstream.wip/INSTALL
---- grub-upstream.wip/INSTALL.btrfs 2005-05-08 02:43:15.000000000 +0000
-+++ grub-upstream.wip/INSTALL 2012-03-20 05:07:09.000000000 +0000
-@@ -207,6 +207,9 @@ operates.
- `--disable-reiserfs'
- Omit the ReiserFS support in Stage 2.
-
-+`--disable-btrfs'
-+ Omit the BtrFS support in Stage 2.
-+
- `--disable-vstafs'
- Omit the VSTa filesystem support in Stage 2.
-
-diff -up /dev/null grub-upstream.wip/stage2/btrfs.h
---- /dev/null 2009-06-03 06:46:26.160951000 +0000
-+++ grub-upstream.wip/stage2/btrfs.h 2012-03-20 05:07:09.000000000 +0000
-@@ -0,0 +1,1413 @@
-+/* btrfs.h - an extraction from btrfs-progs-0.18/ctree.h into one file
-+ *
-+ * Copyright (C) 2007 Oracle. All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public
-+ * License v2 as published by the Free Software Foundation.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-+ * General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public
-+ * License along with this program; If not, see <http://www.gnu.org/licenses/>
-+ */
-+
-+/* include/asm-i386/types.h */
-+
-+typedef __signed__ char __s8;
-+typedef unsigned char __u8;
-+typedef __signed__ short __s16;
-+typedef unsigned short __u16;
-+typedef __signed__ int __s32;
-+typedef unsigned int __u32;
-+typedef unsigned long long __u64;
-+typedef __signed__ long long __s64;
-+
-+typedef __s8 s8;
-+typedef __u8 u8;
-+typedef __u16 u16;
-+typedef __u32 u32;
-+typedef __u64 u64;
-+typedef __s64 s64;
-+
-+#define __bitwise
-+
-+typedef u16 __bitwise __le16;
-+typedef u32 __bitwise __le32;
-+typedef u64 __bitwise __le64;
-+
-+/* linux/posix_type.h */
-+typedef long linux_off_t;
-+
-+/* linux/little_endian.h */
-+#define cpu_to_le64(x) ((__u64) (x))
-+#define le64_to_cpu(x) ((__u64) (x))
-+#define cpu_to_le32(x) ((__u32) (x))
-+#define le32_to_cpu(x) ((__u32) (x))
-+#define cpu_to_le16(x) ((__u16) (x))
-+#define le16_to_cpu(x) ((__u16) (x))
-+#define le8_to_cpu(x) ((__u8) (x))
-+#define cpu_to_le8(x) ((__u8) (x))
-+
-+/* linux/stat.h */
-+#define S_IFMT 00170000
-+#define S_IFLNK 0120000
-+#define S_IFREG 0100000
-+#define S_IFDIR 0040000
-+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
-+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
-+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-+
-+struct btrfs_root;
-+#define BTRFS_MAGIC "_BHRfS_M"
-+
-+#define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
-+#define BTRFS_SUPER_INFO_SIZE 4096
-+
-+#define BTRFS_SUPER_MIRROR_MAX 3
-+#define BTRFS_SUPER_MIRROR_SHIFT 12
-+
-+#define PATH_MAX 1024 /* include/linux/limits.h */
-+#define MAX_LINK_COUNT 5 /* number of symbolic links
-+ to follow */
-+#define BTRFS_MAX_LEVEL 8
-+#define BTRFS_ROOT_TREE_OBJECTID 1ULL
-+#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
-+#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
-+#define BTRFS_DEV_TREE_OBJECTID 4ULL
-+#define BTRFS_FS_TREE_OBJECTID 5ULL
-+#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
-+#define BTRFS_CSUM_TREE_OBJECTID 7ULL
-+
-+#define BTRFS_ORPHAN_OBJECTID -5ULL
-+#define BTRFS_TREE_LOG_OBJECTID -6ULL
-+#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
-+#define BTRFS_TREE_RELOC_OBJECTID -8ULL
-+#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
-+#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
-+
-+#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
-+#define BTRFS_FIRST_FREE_OBJECTID 256ULL
-+#define BTRFS_LAST_FREE_OBJECTID -256ULL
-+#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
-+#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
-+
-+
-+#define BTRFS_NAME_LEN 255
-+#define BTRFS_CSUM_SIZE 32
-+#define BTRFS_CSUM_TYPE_CRC32 0
-+
-+static int btrfs_csum_sizes[] = { 4, 0 };
-+
-+/* four bytes for CRC32 */
-+#define BTRFS_CRC32_SIZE 4
-+#define BTRFS_EMPTY_DIR_SIZE 0
-+
-+#define BTRFS_FT_UNKNOWN 0
-+#define BTRFS_FT_REG_FILE 1
-+#define BTRFS_FT_DIR 2
-+#define BTRFS_FT_CHRDEV 3
-+#define BTRFS_FT_BLKDEV 4
-+#define BTRFS_FT_FIFO 5
-+#define BTRFS_FT_SOCK 6
-+#define BTRFS_FT_SYMLINK 7
-+#define BTRFS_FT_XATTR 8
-+#define BTRFS_FT_MAX 9
-+
-+#define BTRFS_UUID_SIZE 16
-+
-+#define BTRFS_DEFAULT_NUM_DEVICES 1
-+#define BTRFS_DEFAULT_NODE_SIZE 4096
-+#define BTRFS_DEFAULT_LEAF_SIZE 4096
-+#define BTRFS_NUM_CACHED_DEVICES 128
-+
-+#define WARN_ON(c)
-+#define cassert(cond) ({ switch (-1) { case (cond): case 0: break; } })
-+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-+
-+#define offsetof(type, memb) \
-+ ((unsigned long)(&((type *)0)->memb))
-+
-+struct btrfs_disk_key {
-+ __le64 objectid;
-+ u8 type;
-+ __le64 offset;
-+} __attribute__ ((__packed__));
-+
-+/* cpu key */
-+struct btrfs_key {
-+ u64 objectid;
-+ u8 type;
-+ u64 offset;
-+} __attribute__ ((__packed__));
-+
-+/* this represents a divice in a chunk tree */
-+struct btrfs_dev_item {
-+ __le64 devid; /* internal device id */
-+ __le64 total_bytes; /* size of the device */
-+ __le64 bytes_used;
-+ __le32 io_align; /* optimal io alignment */
-+ __le32 io_width; /* optimal io width */
-+ __le32 sector_size; /* minimal io size */
-+ __le64 type; /* type and info about this device */
-+ __le64 generation; /* expected generation */
-+ __le64 start_offset; /* of the partition on a device */
-+
-+ /* info for allocation decisions */
-+ __le32 dev_group;
-+
-+ u8 seek_speed; /* 0-100 (100 is fastest) */
-+ u8 bandwidth; /* 0-100 (100 is fastest) */
-+
-+ u8 uuid[BTRFS_UUID_SIZE]; /* dev uuid generated by btrfs */
-+ u8 fsid[BTRFS_UUID_SIZE]; /* uuid of the host FS */
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_stripe {
-+ __le64 devid;
-+ __le64 offset;
-+ u8 dev_uuid[BTRFS_UUID_SIZE];
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_chunk {
-+ /* size of this chunk in bytes */
-+ __le64 length;
-+ __le64 owner; /* objectid of the root referincing this chunk */
-+ __le64 stripe_len;
-+ __le64 type;
-+ __le32 io_align; /* optimal io alignment for this chunk */
-+ __le32 io_width; /* optimal io width for this chunk */
-+ __le32 sector_size; /* minimal io size for this chunk */
-+ __le16 num_stripes;
-+ __le16 sub_stripes; /* sub stripes (for raid10) */
-+ struct btrfs_stripe stripe;
-+} __attribute__ ((__packed__));
-+
-+static inline unsigned long btrfs_chunk_item_size(int num_stripes)
-+{
-+ return sizeof(struct btrfs_chunk) +
-+ sizeof(struct btrfs_stripe) * (num_stripes - 1);
-+}
-+
-+#define BTRFS_FSID_SIZE 16
-+#define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
-+
-+struct btrfs_header {
-+ /* these first four must match the super block */
-+ u8 csum[BTRFS_CSUM_SIZE];
-+ u8 fsid[BTRFS_FSID_SIZE]; /* uuid of the host fs */
-+ __le64 bytenr; /* which block this node is supposed to live in */
-+ __le64 flags;
-+
-+ /* allowed to be different from the super from here on down */
-+ u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
-+ __le64 generation;
-+ __le64 owner;
-+ __le32 nritems;
-+ u8 level;
-+} __attribute__ ((__packed__));
-+
-+#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
-+ sizeof(struct btrfs_header)) / \
-+ sizeof(struct btrfs_key_ptr))
-+#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
-+#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
-+#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
-+ sizeof(struct btrfs_item) - \
-+ sizeof(struct btrfs_file_extent_item))
-+
-+#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
-+#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
-+
-+/*
-+ * a portion of superblock which is used
-+ * for chunk translation (up to 14 chunks
-+ * with 3 stripes each.
-+ */
-+#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
-+#define BTRFS_LABEL_SIZE 256
-+
-+/*
-+ * the super block basically lists the main trees of the FS
-+ * it currently lacks any block count etc etc
-+ */
-+
-+struct btrfs_super_block {
-+ u8 csum[BTRFS_CSUM_SIZE];
-+ /* the first 3 fields must match struct btrfs_header */
-+ u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
-+ __le64 bytenr; /* this block number */
-+ __le64 flags;
-+
-+ /* allowed to be different from the btrfs_header from here own down */
-+ __le64 magic;
-+ __le64 generation;
-+ __le64 root; /* tree root */
-+ __le64 chunk_root;
-+ __le64 log_root;
-+
-+ /* this will help find the new super based on the log root */
-+ __le64 log_root_transid;
-+ __le64 total_bytes;
-+ __le64 bytes_used;
-+ __le64 root_dir_objectid;
-+ __le64 num_devices;
-+ __le32 sectorsize;
-+ __le32 nodesize;
-+ __le32 leafsize;
-+ __le32 stripesize;
-+ __le32 sys_chunk_array_size;
-+ __le64 chunk_root_generation;
-+ __le64 compat_flags;
-+ __le64 compat_ro_flags;
-+ __le64 incompat_flags;
-+ __le16 csum_type;
-+ u8 root_level;
-+ u8 chunk_root_level;
-+ u8 log_root_level;
-+ struct btrfs_dev_item dev_item;
-+
-+ char label[BTRFS_LABEL_SIZE];
-+
-+ /* future expansion */
-+ __le64 reserved[32];
-+ u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * Compat flags that we support. If any incompat flags are set other than the
-+ * ones specified below then we will fail to mount
-+ */
-+#define BTRFS_FEATURE_COMPAT_SUPP 0x0
-+#define BTRFS_FEATURE_COMPAT_RO_SUPP 0x0
-+#define BTRFS_FEATURE_INCOMPAT_SUPP 0x0
-+
-+/* Item header for per-leaf lookup */
-+struct btrfs_item {
-+ struct btrfs_disk_key key;
-+ __le32 offset;
-+ __le32 size;
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * Format of the leaves:
-+ * [item0, item1....itemN] [free space] [dataN...data1, data0]
-+ */
-+struct btrfs_leaf {
-+ struct btrfs_header header;
-+ struct btrfs_item items[];
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * keys-pointers pairs for per-node (non-leaf) lookup
-+ */
-+struct btrfs_key_ptr {
-+ struct btrfs_disk_key key;
-+ __le64 blockptr;
-+ __le64 generation;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_node {
-+ struct btrfs_header header;
-+ struct btrfs_key_ptr ptrs[];
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_device {
-+ /* the internal btrfs device id */
-+ u64 devid;
-+ /* the internal grub device representation */
-+ unsigned long drive;
-+ unsigned long part;
-+ unsigned long length;
-+};
-+
-+struct extent_buffer {
-+ /* metadata */
-+ struct btrfs_device dev;
-+ u64 start;
-+ u64 dev_bytenr;
-+ u32 len;
-+ /* data */
-+ char *data;
-+};
-+
-+static inline void read_extent_buffer(struct extent_buffer *eb,
-+ void *dst, unsigned long start,
-+ unsigned long len)
-+{
-+ memcpy(dst, eb->data + start, len);
-+}
-+
-+static inline void write_extent_buffer(struct extent_buffer *eb,
-+ const void *src, unsigned long start,
-+ unsigned long len)
-+{
-+ memcpy(eb->data + start, src, len);
-+}
-+
-+/*
-+ * NOTE:
-+ * don't increase a number of levels for grub-0.97!
-+ */
-+typedef enum {
-+ FIRST_EXTERNAL_LOOKUP_POOL,
-+ SECOND_EXTERNAL_LOOKUP_POOL,
-+ INTERNAL_LOOKUP_POOL,
-+ LAST_LOOKUP_POOL
-+} lookup_pool_id;
-+
-+/* Relationship between lookup pools:
-+ * depth
-+ *
-+ * ^ +----> INTERNAL <----+
-+ * | | |
-+ * | | |
-+ * - FIRST_EXTERNAL SECOND_EXTERNAL
-+ */
-+
-+struct btrfs_path {
-+ lookup_pool_id lpid;
-+ struct extent_buffer nodes[BTRFS_MAX_LEVEL];
-+ int slots[BTRFS_MAX_LEVEL];
-+};
-+
-+/*
-+ * items in the extent btree are used to record the objectid of the
-+ * owner of the block and the number of references
-+ */
-+struct btrfs_extent_item {
-+ __le32 refs;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_extent_ref {
-+ __le64 root;
-+ __le64 generation;
-+ __le64 objectid;
-+ __le32 num_refs;
-+} __attribute__ ((__packed__));
-+
-+/* dev extents record free space on individual devices. The owner
-+ * field points back to the chunk allocation mapping tree that allocated
-+ * the extent. The chunk tree uuid field is a way to double check the owner
-+ */
-+struct btrfs_dev_extent {
-+ __le64 chunk_tree;
-+ __le64 chunk_objectid;
-+ __le64 chunk_offset;
-+ __le64 length;
-+ u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_inode_ref {
-+ __le64 index;
-+ __le16 name_len;
-+ /* name goes here */
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_timespec {
-+ __le64 sec;
-+ __le32 nsec;
-+} __attribute__ ((__packed__));
-+
-+typedef enum {
-+ BTRFS_COMPRESS_NONE = 0,
-+ BTRFS_COMPRESS_ZLIB = 1,
-+ BTRFS_COMPRESS_LAST = 2,
-+} btrfs_compression_type;
-+
-+/* we don't understand any encryption methods right now */
-+typedef enum {
-+ BTRFS_ENCRYPTION_NONE = 0,
-+ BTRFS_ENCRYPTION_LAST = 1,
-+} btrfs_encryption_type;
-+
-+struct btrfs_inode_item {
-+ /* nfs style generation number */
-+ __le64 generation;
-+ /* transid that last touched this inode */
-+ __le64 transid;
-+ __le64 size;
-+ __le64 nbytes;
-+ __le64 block_group;
-+ __le32 nlink;
-+ __le32 uid;
-+ __le32 gid;
-+ __le32 mode;
-+ __le64 rdev;
-+ __le64 flags;
-+
-+ /* modification sequence number for NFS */
-+ __le64 sequence;
-+
-+ /*
-+ * a little future expansion, for more than this we can
-+ * just grow the inode item and version it
-+ */
-+ __le64 reserved[4];
-+ struct btrfs_timespec atime;
-+ struct btrfs_timespec ctime;
-+ struct btrfs_timespec mtime;
-+ struct btrfs_timespec otime;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_dir_item {
-+ struct btrfs_disk_key location;
-+ __le64 transid;
-+ __le16 data_len;
-+ __le16 name_len;
-+ u8 type;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_root_item {
-+ struct btrfs_inode_item inode;
-+ __le64 generation;
-+ __le64 root_dirid;
-+ __le64 bytenr;
-+ __le64 byte_limit;
-+ __le64 bytes_used;
-+ __le64 last_snapshot;
-+ __le64 flags;
-+ __le32 refs;
-+ struct btrfs_disk_key drop_progress;
-+ u8 drop_level;
-+ u8 level;
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * this is used for both forward and backward root refs
-+ */
-+struct btrfs_root_ref {
-+ __le64 dirid;
-+ __le64 sequence;
-+ __le16 name_len;
-+} __attribute__ ((__packed__));
-+
-+#define BTRFS_FILE_EXTENT_INLINE 0
-+#define BTRFS_FILE_EXTENT_REG 1
-+#define BTRFS_FILE_EXTENT_PREALLOC 2
-+
-+struct btrfs_file_extent_item {
-+ /*
-+ * transaction id that created this extent
-+ */
-+ __le64 generation;
-+ /*
-+ * max number of bytes to hold this extent in ram
-+ * when we split a compressed extent we can't know how big
-+ * each of the resulting pieces will be. So, this is
-+ * an upper limit on the size of the extent in ram instead of
-+ * an exact limit.
-+ */
-+ __le64 ram_bytes;
-+
-+ /*
-+ * 32 bits for the various ways we might encode the data,
-+ * including compression and encryption. If any of these
-+ * are set to something a given disk format doesn't understand
-+ * it is treated like an incompat flag for reading and writing,
-+ * but not for stat.
-+ */
-+ u8 compression;
-+ u8 encryption;
-+ __le16 other_encoding; /* spare for later use */
-+
-+ /* are we inline data or a real extent? */
-+ u8 type;
-+
-+ /*
-+ * disk space consumed by the extent, checksum blocks are included
-+ * in these numbers
-+ */
-+ __le64 disk_bytenr;
-+ __le64 disk_num_bytes;
-+ /*
-+ * the logical offset in file blocks (no csums)
-+ * this extent record is for. This allows a file extent to point
-+ * into the middle of an existing extent on disk, sharing it
-+ * between two snapshots (useful if some bytes in the middle of the
-+ * extent have changed
-+ */
-+ __le64 offset;
-+ /*
-+ * the logical number of file blocks (no csums included)
-+ */
-+ __le64 num_bytes;
-+
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_csum_item {
-+ u8 csum;
-+} __attribute__ ((__packed__));
-+
-+/* tag for the radix tree of block groups in ram */
-+#define BTRFS_BLOCK_GROUP_DATA (1 << 0)
-+#define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
-+#define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
-+#define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
-+#define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
-+#define BTRFS_BLOCK_GROUP_DUP (1 << 5)
-+#define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
-+
-+struct btrfs_block_group_item {
-+ __le64 used;
-+ __le64 chunk_objectid;
-+ __le64 flags;
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * in ram representation of the tree. extent_root is used for all allocations
-+ * and for the extent tree extent_root root.
-+ */
-+struct btrfs_root {
-+ struct extent_buffer node;
-+ char data[4096];
-+ struct btrfs_root_item root_item;
-+ u64 objectid;
-+
-+ /* data allocations are done in sectorsize units */
-+ u32 sectorsize;
-+
-+ /* node allocations are done in nodesize units */
-+ u32 nodesize;
-+
-+ /* leaf allocations are done in leafsize units */
-+ u32 leafsize;
-+
-+ /* leaf allocations are done in leafsize units */
-+ u32 stripesize;
-+};
-+
-+struct btrfs_file_info {
-+ struct btrfs_key key;
-+};
-+
-+struct btrfs_root;
-+struct btrfs_fs_devices;
-+struct btrfs_fs_info {
-+ u8 fsid[BTRFS_FSID_SIZE];
-+ struct btrfs_root fs_root;
-+ struct btrfs_root tree_root;
-+ struct btrfs_root chunk_root;
-+
-+ struct btrfs_file_info file_info; /* currently opened file */
-+ struct btrfs_path paths [LAST_LOOKUP_POOL];
-+
-+ char mbr[SECTOR_SIZE];
-+
-+ int sb_mirror;
-+ u64 sb_transid;
-+ struct btrfs_device sb_dev;
-+ struct btrfs_super_block sb_copy;
-+
-+ struct btrfs_device devices[BTRFS_NUM_CACHED_DEVICES + 1];
-+};
-+
-+/*
-+ * inode items have the data typically returned from stat and store other
-+ * info about object characteristics. There is one for every file and dir in
-+ * the FS
-+ */
-+#define BTRFS_INODE_ITEM_KEY 1
-+#define BTRFS_INODE_REF_KEY 12
-+#define BTRFS_XATTR_ITEM_KEY 24
-+#define BTRFS_ORPHAN_ITEM_KEY 48
-+
-+#define BTRFS_DIR_LOG_ITEM_KEY 60
-+#define BTRFS_DIR_LOG_INDEX_KEY 72
-+/*
-+ * dir items are the name -> inode pointers in a directory. There is one
-+ * for every name in a directory.
-+ */
-+#define BTRFS_DIR_ITEM_KEY 84
-+#define BTRFS_DIR_INDEX_KEY 96
-+
-+/*
-+ * extent data is for file data
-+ */
-+#define BTRFS_EXTENT_DATA_KEY 108
-+
-+/*
-+ * csum items have the checksums for data in the extents
-+ */
-+#define BTRFS_CSUM_ITEM_KEY 120
-+/*
-+ * extent csums are stored in a separate tree and hold csums for
-+ * an entire extent on disk.
-+ */
-+#define BTRFS_EXTENT_CSUM_KEY 128
-+
-+/*
-+ * root items point to tree roots. There are typically in the root
-+ * tree used by the super block to find all the other trees
-+ */
-+#define BTRFS_ROOT_ITEM_KEY 132
-+
-+/*
-+ * root backrefs tie subvols and snapshots to the directory entries that
-+ * reference them
-+ */
-+#define BTRFS_ROOT_BACKREF_KEY 144
-+
-+/*
-+ * root refs make a fast index for listing all of the snapshots and
-+ * subvolumes referenced by a given root. They point directly to the
-+ * directory item in the root that references the subvol
-+ */
-+#define BTRFS_ROOT_REF_KEY 156
-+
-+/*
-++ * extent items are in the extent map tree. These record which blocks
-++ * are used, and how many references there are to each block
-++ */
-+#define BTRFS_EXTENT_ITEM_KEY 168
-+#define BTRFS_EXTENT_REF_KEY 180
-+
-+/*
-+ * block groups give us hints into the extent allocation trees. Which
-+ * blocks are free etc etc
-+ */
-+#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
-+
-+#define BTRFS_DEV_EXTENT_KEY 204
-+#define BTRFS_DEV_ITEM_KEY 216
-+#define BTRFS_CHUNK_ITEM_KEY 228
-+
-+/*
-+ * string items are for debugging. They just store a short string of
-+ * data in the FS
-+ */
-+#define BTRFS_STRING_ITEM_KEY 253
-+/*
-+ * Inode flags
-+ */
-+#define BTRFS_INODE_NODATASUM (1 << 0)
-+#define BTRFS_INODE_NODATACOW (1 << 1)
-+#define BTRFS_INODE_READONLY (1 << 2)
-+
-+#define read_eb_member(eb, ptr, type, member, result) (
\
-+ read_extent_buffer(eb, (char *)(result), \
-+ ((unsigned long)(ptr)) + \
-+ offsetof(type, member), \
-+ sizeof(((type *)0)->member)))
-+
-+#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
-+static inline u##bits btrfs_##name(struct extent_buffer *eb) \
-+{ \
-+ struct btrfs_header *h = (struct btrfs_header *)eb->data; \
-+ return le##bits##_to_cpu(h->member); \
-+} \
-+static inline void btrfs_set_##name(struct extent_buffer *eb, \
-+ u##bits val) \
-+{ \
-+ struct btrfs_header *h = (struct btrfs_header *)eb->data; \
-+ h->member = cpu_to_le##bits(val); \
-+}
-+
-+#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
-+static inline u##bits btrfs_##name(struct extent_buffer *eb, \
-+ type *s) \
-+{ \
-+ unsigned long offset = (unsigned long)s; \
-+ type *p = (type *) (eb->data + offset); \
-+ return le##bits##_to_cpu(p->member); \
-+} \
-+static inline void btrfs_set_##name(struct extent_buffer *eb, \
-+ type *s, u##bits val) \
-+{ \
-+ unsigned long offset = (unsigned long)s; \
-+ type *p = (type *) (eb->data + offset); \
-+ p->member = cpu_to_le##bits(val); \
-+}
-+
-+#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
-+static inline u##bits btrfs_##name(type *s) \
-+{ \
-+ return le##bits##_to_cpu(s->member); \
-+} \
-+static inline void btrfs_set_##name(type *s, u##bits val) \
-+{ \
-+ s->member = cpu_to_le##bits(val); \
-+}
-+
-+BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
-+BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes,
64);
-+BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
-+BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
-+BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
-+BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
-+ start_offset, 64);
-+BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size,
32);
-+BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
-+BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
-+BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
-+BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
-+BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
-+ total_bytes, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
-+ bytes_used, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
-+ io_align, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
-+ io_width, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
-+ sector_size, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
-+ dev_group, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
-+ seek_speed, 8);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
-+ bandwidth, 8);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
-+ generation, 64);
-+
-+static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
-+{
-+ return (char *)d + offsetof(struct btrfs_dev_item, uuid);
-+}
-+
-+static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
-+{
-+ return (char *)d + offsetof(struct btrfs_dev_item, fsid);
-+}
-+
-+BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
-+BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
-+BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
-+BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
-+BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
-+BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
-+BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
-+BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
-+BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
-+BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
-+BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
-+
-+static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
-+{
-+ return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
-+}
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
-+ stripe_len, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
-+ io_align, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
-+ io_width, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
-+ sector_size, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
-+ num_stripes, 16);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
-+ sub_stripes, 16);
-+BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset,
64);
-+
-+static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
-+ int nr)
-+{
-+ unsigned long offset = (unsigned long)c;
-+ offset += offsetof(struct btrfs_chunk, stripe);
-+ offset += nr * sizeof(struct btrfs_stripe);
-+ return (struct btrfs_stripe *)offset;
-+}
-+
-+static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
-+{
-+ return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
-+}
-+
-+static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
-+ struct btrfs_chunk *c, int nr)
-+{
-+ return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
-+}
-+
-+static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
-+ struct btrfs_chunk *c, int nr,
-+ u64 val)
-+{
-+ btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
-+}
-+
-+static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
-+ struct btrfs_chunk *c, int nr)
-+{
-+ return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
-+}
-+
-+static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
-+ struct btrfs_chunk *c, int nr,
-+ u64 val)
-+{
-+ btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
-+}
-+
-+/* struct btrfs_block_group_item */
-+BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
-+ used, 64);
-+BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
-+ used, 64);
-+BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
-+ struct btrfs_block_group_item, chunk_objectid, 64);
-+
-+BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
-+ struct btrfs_block_group_item, chunk_objectid, 64);
-+BTRFS_SETGET_FUNCS(disk_block_group_flags,
-+ struct btrfs_block_group_item, flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(block_group_flags,
-+ struct btrfs_block_group_item, flags, 64);
-+
-+/* struct btrfs_inode_ref */
-+BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
-+BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
-+
-+/* struct btrfs_inode_item */
-+BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
-+BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
-+BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
-+BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
-+BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
-+BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group,
64);
-+BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
-+BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
-+BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
-+BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
-+BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
-+BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
-+ struct btrfs_inode_item, generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence,
-+ struct btrfs_inode_item, generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
-+ struct btrfs_inode_item, size, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes,
-+ struct btrfs_inode_item, nbytes, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
-+ struct btrfs_inode_item, block_group, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
-+ struct btrfs_inode_item, nlink, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
-+ struct btrfs_inode_item, uid, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
-+ struct btrfs_inode_item, gid, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
-+ struct btrfs_inode_item, mode, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
-+ struct btrfs_inode_item, rdev, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
-+ struct btrfs_inode_item, flags, 64);
-+
-+BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
-+BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
-+ sec, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
-+ nsec, 32);
-+
-+/* struct btrfs_dev_extent */
-+BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
-+ chunk_tree, 64);
-+BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
-+ chunk_objectid, 64);
-+BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
-+ chunk_offset, 64);
-+BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
-+
-+static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent
*dev)
-+{
-+ unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
-+ return (u8 *)((unsigned long)dev + ptr);
-+}
-+
-+/* struct btrfs_extent_ref */
-+BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
-+BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
-+BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
-+BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
-+ generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
-+ objectid, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
-+ num_refs, 32);
-+
-+/* struct btrfs_extent_item */
-+BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
-+ refs, 32);
-+
-+/* struct btrfs_node */
-+BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
-+BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
-+
-+static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
-+{
-+ unsigned long ptr;
-+ ptr = offsetof(struct btrfs_node, ptrs) +
-+ sizeof(struct btrfs_key_ptr) * nr;
-+ return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
-+}
-+
-+static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
-+ int nr, u64 val)
-+{
-+ unsigned long ptr;
-+ ptr = offsetof(struct btrfs_node, ptrs) +
-+ sizeof(struct btrfs_key_ptr) * nr;
-+ btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
-+}
-+
-+static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
-+{
-+ unsigned long ptr;
-+ ptr = offsetof(struct btrfs_node, ptrs) +
-+ sizeof(struct btrfs_key_ptr) * nr;
-+ return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
-+}
-+
-+static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
-+ int nr, u64 val)
-+{
-+ unsigned long ptr;
-+ ptr = offsetof(struct btrfs_node, ptrs) +
-+ sizeof(struct btrfs_key_ptr) * nr;
-+ btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
-+}
-+
-+static inline unsigned long btrfs_node_key_ptr_offset(int nr)
-+{
-+ return offsetof(struct btrfs_node, ptrs) +
-+ sizeof(struct btrfs_key_ptr) * nr;
-+}
-+
-+static inline void btrfs_node_key(struct extent_buffer *eb,
-+ struct btrfs_disk_key *disk_key, int nr)
-+{
-+ unsigned long ptr;
-+ ptr = btrfs_node_key_ptr_offset(nr);
-+ read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
-+ struct btrfs_key_ptr, key, disk_key);
-+}
-+
-+/* struct btrfs_item */
-+BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
-+BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
-+
-+static inline unsigned long btrfs_item_nr_offset(int nr)
-+{
-+ return offsetof(struct btrfs_leaf, items) +
-+ sizeof(struct btrfs_item) * nr;
-+}
-+
-+static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
-+ int nr)
-+{
-+ return (struct btrfs_item *)btrfs_item_nr_offset(nr);
-+}
-+
-+static inline u32 btrfs_item_end(struct extent_buffer *eb,
-+ struct btrfs_item *item)
-+{
-+ return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
-+}
-+
-+static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
-+{
-+ return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
-+}
-+
-+static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
-+{
-+ return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
-+}
-+
-+static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
-+{
-+ return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
-+}
-+
-+static inline void btrfs_item_key(struct extent_buffer *eb,
-+ struct btrfs_disk_key *disk_key, int nr)
-+{
-+ struct btrfs_item *item = btrfs_item_nr(eb, nr);
-+ read_eb_member(eb, item, struct btrfs_item, key, disk_key);
-+}
-+
-+/*
-+ * struct btrfs_root_ref
-+ */
-+BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
-+BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
-+BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
-+
-+/* struct btrfs_dir_item */
-+BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
-+BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
-+BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
-+BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
-+
-+static inline void btrfs_dir_item_key(struct extent_buffer *eb,
-+ struct btrfs_dir_item *item,
-+ struct btrfs_disk_key *key)
-+{
-+ read_eb_member(eb, item, struct btrfs_dir_item, location, key);
-+}
-+
-+/* struct btrfs_disk_key */
-+BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
-+ objectid, 64);
-+BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
-+BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
-+
-+static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
-+ struct btrfs_disk_key *disk)
-+{
-+ cpu->offset = le64_to_cpu(disk->offset);
-+ cpu->type = disk->type;
-+ cpu->objectid = le64_to_cpu(disk->objectid);
-+}
-+
-+static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
-+ struct btrfs_key *cpu)
-+{
-+ disk->offset = cpu_to_le64(cpu->offset);
-+ disk->type = cpu->type;
-+ disk->objectid = cpu_to_le64(cpu->objectid);
-+}
-+
-+static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
-+ struct btrfs_key *key, int nr)
-+{
-+ struct btrfs_disk_key disk_key;
-+ btrfs_node_key(eb, &disk_key, nr);
-+ btrfs_disk_key_to_cpu(key, &disk_key);
-+}
-+
-+static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
-+ struct btrfs_key *key, int nr)
-+{
-+ struct btrfs_disk_key disk_key;
-+ btrfs_item_key(eb, &disk_key, nr);
-+ btrfs_disk_key_to_cpu(key, &disk_key);
-+}
-+
-+static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
-+ struct btrfs_dir_item *item,
-+ struct btrfs_key *key)
-+{
-+ struct btrfs_disk_key disk_key;
-+ btrfs_dir_item_key(eb, item, &disk_key);
-+ btrfs_disk_key_to_cpu(key, &disk_key);
-+}
-+
-+static inline u8 btrfs_key_type(struct btrfs_key *key)
-+{
-+ return key->type;
-+}
-+
-+static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
-+{
-+ key->type = val;
-+}
-+
-+static inline u64 btrfs_super_devid(struct btrfs_super_block *disk_super)
-+{
-+ return le64_to_cpu(disk_super->dev_item.devid);
-+}
-+
-+/* struct btrfs_header */
-+BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
-+ generation, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
-+BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
-+
-+/* struct btrfs_root_item */
-+BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
-+ generation, 64);
-+BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
-+BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
-+BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
-+
-+BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
-+ generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
-+BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
-+BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
-+ last_snapshot, 64);
-+
-+/* struct btrfs_super_block */
-+
-+BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
-+ generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
-+ struct btrfs_super_block, sys_chunk_array_size, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
-+ struct btrfs_super_block, chunk_root_generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
-+ root_level, 8);
-+BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
-+ chunk_root, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
-+ chunk_root_level, 8);
-+BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
-+ log_root, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
-+ log_root_transid, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
-+ log_root_level, 8);
-+BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
-+ total_bytes, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
-+ bytes_used, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
-+ sectorsize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
-+ nodesize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
-+ leafsize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
-+ stripesize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
-+ root_dir_objectid, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
-+ num_devices, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
-+ compat_flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
-+ compat_flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
-+ incompat_flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
-+ csum_type, 16);
-+
-+static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
-+{
-+ int t = btrfs_super_csum_type(s);
-+ //BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
-+ return btrfs_csum_sizes[t];
-+}
-+
-+static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
-+{
-+ return offsetof(struct btrfs_leaf, items);
-+}
-+
-+/* struct btrfs_file_extent_item */
-+BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
-+
-+static inline unsigned long btrfs_file_extent_inline_start(struct
-+ btrfs_file_extent_item *e)
-+{
-+ unsigned long offset = (unsigned long)e;
-+ offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
-+ return offset;
-+}
-+
-+static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
-+{
-+ return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
-+}
-+
-+BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
-+ disk_bytenr, 64);
-+BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
-+ generation, 64);
-+BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
-+ disk_num_bytes, 64);
-+BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
-+ offset, 64);
-+BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
-+ num_bytes, 64);
-+BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
-+ ram_bytes, 64);
-+BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
-+ compression, 8);
-+BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
-+ encryption, 8);
-+BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
-+ other_encoding, 16);
-+
-+/* this returns the number of file bytes represented by the inline item.
-+ * If an item is compressed, this is the uncompressed size
-+ */
-+static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
-+ struct btrfs_file_extent_item *e)
-+{
-+ return btrfs_file_extent_ram_bytes(eb, e);
-+}
-+
-+/*
-+ * this returns the number of bytes used by the item on disk, minus the
-+ * size of any extent headers. If a file is compressed on disk, this is
-+ * the compressed size
-+ */
-+static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
-+ struct btrfs_item *e)
-+{
-+ unsigned long offset;
-+ offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
-+ return btrfs_item_size(eb, e) - offset;
-+}
-+
-+static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
-+ if (level == 0)
-+ return root->leafsize;
-+ return root->nodesize;
-+}
-+
-+static inline u32 btrfs_root_level_size(struct btrfs_super_block *sb) {
-+ return btrfs_super_root_level(sb) == 0 ?
-+ btrfs_super_leafsize(sb) :
-+ btrfs_super_nodesize(sb);
-+}
-+
-+static inline u32 btrfs_chunk_root_level_size(struct btrfs_super_block *sb) {
-+ return btrfs_super_chunk_root_level(sb) == 0 ?
-+ btrfs_super_leafsize(sb) :
-+ btrfs_super_nodesize(sb);
-+}
-+
-+/* helper function to cast into the data area of the leaf. */
-+#define btrfs_item_ptr(leaf, slot, type) \
-+ ((type *)(btrfs_leaf_data(leaf) + \
-+ btrfs_item_offset_nr(leaf, slot)))
-+
-+#define btrfs_item_ptr_offset(leaf, slot) \
-+ ((unsigned long)(btrfs_leaf_data(leaf) + \
-+ btrfs_item_offset_nr(leaf, slot)))
-+
-+/*volumes.h */
-+
-+struct btrfs_fs_devices {
-+ u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
-+
-+ /* the device with this id has the most recent coyp of the super */
-+ u64 latest_devid;
-+ u64 latest_trans;
-+ u64 lowest_devid;
-+ int latest_bdev;
-+ int lowest_bdev;
-+ int seeding;
-+ struct btrfs_fs_devices *seed;
-+};
-+
-+struct btrfs_bio_stripe {
-+ struct btrfs_device dev;
-+ u64 physical;
-+};
-+
-+#define MAX_NRSTRIPES 8
-+struct btrfs_multi_bio {
-+ int error;
-+ int num_stripes;
-+ struct btrfs_bio_stripe stripes[MAX_NRSTRIPES];
-+};
-+
-+#define btrfs_multi_bio_size(n) (sizeof(struct btrfs_multi_bio) + \
-+ (sizeof(struct btrfs_bio_stripe) * (n)))
-+
-+static int aux_tree_lookup(struct btrfs_root *root,
-+ struct btrfs_key *key,
-+ struct btrfs_path *path);
-+
-+struct cache_extent {
-+ u64 start;
-+ u64 size;
-+};
-+
-+struct map_lookup {
-+ struct cache_extent ce;
-+ u64 type;
-+ int io_align;
-+ int io_width;
-+ int stripe_len;
-+ int sector_size;
-+ int num_stripes;
-+ int sub_stripes;
-+ struct btrfs_bio_stripe stripes[MAX_NRSTRIPES];
-+};
-+
-+/* "VFS" things */
-+
-+/* file types recognized by grub */
-+typedef enum {
-+ BTRFS_REGULAR_FILE,
-+ BTRFS_DIRECTORY_FILE,
-+ BTRFS_SYMLINK_FILE,
-+ BTRFS_UNKNOWN_FILE
-+} btrfs_file_type;
-+
-+static inline int coord_is_root(struct btrfs_root *root,
-+ struct btrfs_path *path)
-+{
-+ return btrfs_header_bytenr(&path->nodes[0]) ==
-+ btrfs_header_bytenr(&root->node);
-+}
-+
-+static inline btrfs_file_type btrfs_get_file_type (int mode)
-+{
-+ if (S_ISLNK(mode))
-+ return BTRFS_SYMLINK_FILE;
-+ if (S_ISREG(mode))
-+ return BTRFS_REGULAR_FILE;
-+ if (S_ISDIR(mode))
-+ return BTRFS_DIRECTORY_FILE;
-+ return BTRFS_UNKNOWN_FILE;
-+}
-+
-+#define min_t(type,x,y)
\
-+ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
-+#define max_t(type,x,y)
\
-+ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
-+
-+
-+int sys_array_lookup(struct map_lookup *map, u64 logical);
-+int tree_chunk_lookup(struct map_lookup *map,
-+ u64 logical);
-+int __btrfs_map_block(u64 logical, u64 *length,
-+ struct btrfs_multi_bio *multi_ret, int mirror_num);
-+int read_tree_block(struct btrfs_root *root,
-+ struct extent_buffer *eb,
-+ u64 bytenr, /* logical */
-+ u32 blocksize,
-+ u64 parent_transid,
-+ lookup_pool_id lpid);
-+int check_read_chunk(struct btrfs_key *key,
-+ struct extent_buffer *leaf,
-+ struct btrfs_chunk *chunk,
-+ struct map_lookup *map,
-+ u64 logical);
-+/*
-+ Local variables:
-+ c-indentation-style: "K&R"
-+ mode-name: "LC"
-+ c-basic-offset: 8
-+ tab-width: 8
-+ fill-column: 80
-+ scroll-step: 1
-+ End:
-+*/
-\ No newline at end of file
-diff -up grub-upstream.wip/stage2/builtins.c.btrfs
grub-upstream.wip/stage2/builtins.c
---- grub-upstream.wip/stage2/builtins.c.btrfs 2012-03-20 05:06:49.000000000
+0000
-+++ grub-upstream.wip/stage2/builtins.c 2012-03-20 05:11:13.000000000
+0000
-@@ -2456,6 +2456,16 @@ install_func (char *arg, int flags)
- else
- #endif /* GRUB_UTIL */
- {
-+ /*
-+ * FIXME: Ugly hack.
-+ * Do not write to btrfs partition
-+ * without a help of the file system!
-+ */
-+ if (!strcmp(fsys_table[fsys_type].name, "btrfs"))
-+ {
-+ errnum = ERR_BAD_ARGUMENT;
-+ goto fail;
-+ }
- if (! devwrite (saved_sector - part_start, 1, stage2_buffer))
- goto fail;
- }
-@@ -4281,6 +4291,7 @@ setup_func (char *arg, int flags)
- {"jfs", "/jfs_stage1_5"},
- {"minix", "/minix_stage1_5"},
- {"reiserfs", "/reiserfs_stage1_5"},
-+ {"btrfs", "/btrfs_stage1_5"},
- {"vstafs", "/vstafs_stage1_5"},
- {"xfs", "/xfs_stage1_5"}
- };
-diff -up grub-upstream.wip/stage2/disk_io.c.btrfs
grub-upstream.wip/stage2/disk_io.c
---- grub-upstream.wip/stage2/disk_io.c.btrfs 2012-03-20 05:06:49.000000000
+0000
-+++ grub-upstream.wip/stage2/disk_io.c 2012-03-20 05:07:09.000000000 +0000
-@@ -78,6 +78,9 @@ struct fsys_entry fsys_table[NUM_FSYS +
- # ifdef FSYS_ISO9660
- {"iso9660", iso9660_mount, iso9660_read, iso9660_dir, 0, 0},
- # endif
-+# ifdef FSYS_BTRFS
-+ {"btrfs", btrfs_mount, btrfs_read, btrfs_dir, 0, btrfs_embed},
-+# endif
- /* XX FFS should come last as it's superblock is commonly crossing tracks
- on floppies from track 1 to 2, while others only use 1. */
- # ifdef FSYS_FFS
-diff -up grub-upstream.wip/stage2/filesys.h.btrfs
grub-upstream.wip/stage2/filesys.h
---- grub-upstream.wip/stage2/filesys.h.btrfs 2004-05-14 19:36:43.000000000
+0000
-+++ grub-upstream.wip/stage2/filesys.h 2012-03-20 05:07:09.000000000 +0000
-@@ -77,6 +77,16 @@ int reiserfs_embed (int *start_sector, i
- #define FSYS_REISERFS_NUM 0
- #endif
-
-+#ifdef FSYS_BTRFS
-+#define FSYS_BTRFS_NUM 1
-+int btrfs_mount (void);
-+int btrfs_read (char *buf, int len);
-+int btrfs_dir (char *dirname);
-+int btrfs_embed (int *start_sector, int needed_sectors);
-+#else
-+#define FSYS_BTRFS_NUM 0
-+#endif
-+
- #ifdef FSYS_VSTAFS
- #define FSYS_VSTAFS_NUM 1
- int vstafs_mount (void);
-@@ -127,8 +137,8 @@ int iso9660_dir (char *dirname);
- #ifndef NUM_FSYS
- #define NUM_FSYS \
- (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM \
-- + FSYS_REISERFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM + FSYS_XFS_NUM
\
-- + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
-+ + FSYS_REISERFS_NUM + FSYS_BTRFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM \
-+ + FSYS_XFS_NUM + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
- #endif
-
- /* defines for the block filesystem info area */
-diff -up /dev/null grub-upstream.wip/stage2/fsys_btrfs.c
---- /dev/null 2009-06-03 06:46:26.160951000 +0000
-+++ grub-upstream.wip/stage2/fsys_btrfs.c 2012-03-20 05:07:09.000000000
+0000
-@@ -0,0 +1,1820 @@
-+/* fsys_btrfs.c - an implementation for the Btrfs filesystem
-+ *
-+ * Copyright 2009 Red Hat, Inc. All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
-+ */
-+
-+#ifdef FSYS_BTRFS
-+
-+#include "shared.h"
-+#include "filesys.h"
-+#include "btrfs.h"
-+
-+#define BTRFS_VERBOSE 0
-+
-+/* Cache layouts */
-+
-+#define LOOKUP_CACHE_BUF_SIZE (4096)
-+#define LOOKUP_CACHE_SIZE (LOOKUP_CACHE_BUF_SIZE * LAST_LOOKUP_POOL)
-+#define BTRFS_FS_INFO \
-+ ((struct btrfs_fs_info *)((unsigned long)FSYS_BUF + \
-+ LOOKUP_CACHE_SIZE))
-+#define BTRFS_CACHE_SIZE (sizeof(struct btrfs_fs_info) + \
-+ LOOKUP_CACHE_SIZE)
-+#define BTRFS_TREE_ROOT (&BTRFS_FS_INFO->tree_root)
-+#define BTRFS_CHUNK_ROOT (&BTRFS_FS_INFO->chunk_root)
-+#define BTRFS_FS_ROOT (&BTRFS_FS_INFO->fs_root)
-+#define BTRFS_SUPER (&BTRFS_FS_INFO->sb_copy)
-+#define BTRFS_DEVICES (&BTRFS_FS_INFO->devices[0])
-+#define BTRFS_FILE_INFO (&BTRFS_FS_INFO->file_info)
-+#define BTRFS_FILE_INFO_KEY (&BTRFS_FILE_INFO->key)
-+
-+#define BTRFS_VOLATILE_DEV_CACHE \
-+ (&BTRFS_FS_INFO->devices[BTRFS_NUM_CACHED_DEVICES])
-+
-+#define LOOKUP_CACHE_BUF(id) ((char *)((unsigned long)FSYS_BUF + \
-+ id * LOOKUP_CACHE_BUF_SIZE))
-+
-+#define noop do {; } while (0)
-+
-+#if BTRFS_VERBOSE
-+#define btrfs_msg(format, ...) printf(format , ## __VA_ARGS__)
-+#else
-+#define btrfs_msg(format, args...) noop
-+#endif
-+
-+/* compile-time check to make sure we don't overlap
-+ filesystem buffer */
-+static inline void check_btrfs_cache_size(void)
-+{
-+ cassert(BTRFS_CACHE_SIZE <= FSYS_BUFLEN);
-+}
-+
-+static inline u64 btrfs_sb_offset(int mirror)
-+{
-+ u64 start = 16 * 1024;
-+ if (mirror)
-+ return start << (BTRFS_SUPER_MIRROR_SHIFT * mirror);
-+ return BTRFS_SUPER_INFO_OFFSET;
-+}
-+
-+static inline char *grab_lookup_cache(lookup_pool_id lpid)
-+{
-+ char *buf = LOOKUP_CACHE_BUF(lpid);
-+ memset(buf, 0, LOOKUP_CACHE_BUF_SIZE);
-+ return buf;
-+}
-+
-+static inline struct btrfs_path *btrfs_grab_path(lookup_pool_id lpid)
-+{
-+ return &BTRFS_FS_INFO->paths[lpid];
-+}
-+
-+static inline void btrfs_set_path_key(struct btrfs_path *path,
-+ struct btrfs_key *key)
-+{
-+ btrfs_item_key_to_cpu(&path->nodes[0],
-+ key,
-+ path->slots[0]);
-+}
-+
-+static inline void btrfs_update_file_info(struct btrfs_path *path)
-+{
-+ btrfs_set_path_key(path, BTRFS_FILE_INFO_KEY);
-+}
-+
-+static inline void btrfs_set_root_dir_key(struct btrfs_key *key)
-+{
-+ key->objectid = BTRFS_FIRST_FREE_OBJECTID;
-+ btrfs_set_key_type(key, BTRFS_INODE_ITEM_KEY);
-+ key->offset = 0;
-+}
-+
-+static inline void copy_extent_buffer(struct extent_buffer *dst,
-+ struct extent_buffer *src)
-+{
-+ char *data = dst->data;
-+ memcpy(dst, src, sizeof(*dst));
-+ memcpy(data, src->data, 4096);
-+ dst->data = data;
-+}
-+
-+static inline void move_extent_buffer(struct extent_buffer *dst,
-+ struct extent_buffer *src)
-+{
-+ memcpy(dst, src, sizeof(*dst));
-+}
-+
-+static inline void init_btrfs_root (struct btrfs_root *root)
-+{
-+ root->node.data = root->data;
-+}
-+
-+static inline void init_btrfs_path(lookup_pool_id lpid)
-+{
-+ struct btrfs_path *path;
-+ path = btrfs_grab_path(lpid);
-+ path->lpid = lpid;
-+}
-+
-+static inline void init_btrfs_info(void)
-+{
-+ int i;
-+
-+ memset(BTRFS_FS_INFO, 0, sizeof(struct btrfs_fs_info));
-+ for(i = 0; i < LAST_LOOKUP_POOL; i++)
-+ init_btrfs_path(i);
-+ init_btrfs_root(BTRFS_TREE_ROOT);
-+ init_btrfs_root(BTRFS_CHUNK_ROOT);
-+ init_btrfs_root(BTRFS_FS_ROOT);
-+}
-+
-+static void setup_root(struct btrfs_root *root,
-+ u32 nodesize,
-+ u32 leafsize,
-+ u32 sectorsize,
-+ u32 stripesize,
-+ u64 objectid)
-+{
-+ root->nodesize = nodesize;
-+ root->leafsize = leafsize;
-+ root->sectorsize = sectorsize;
-+ root->stripesize = stripesize;
-+ root->objectid = objectid;
-+}
-+
-+/*
-+ * Pick up the latest root of a
-+ * tree with specified @objectid
-+ */
-+static int btrfs_find_last_root(struct btrfs_root *tree_root,
-+ u64 objectid,
-+ struct btrfs_root_item *item,
-+ lookup_pool_id lpid)
-+{
-+ int ret;
-+ int slot;
-+ struct btrfs_key search_key;
-+ struct btrfs_key found_key;
-+ struct btrfs_path *path;
-+
-+ search_key.objectid = objectid;
-+ search_key.type = BTRFS_ROOT_ITEM_KEY;
-+ search_key.offset = (u64)-1;
-+ path = btrfs_grab_path(lpid);
-+
-+ ret = aux_tree_lookup(tree_root, &search_key, path);
-+ if (ret < 0)
-+ return 1;
-+ slot = path->slots[0];
-+ WARN_ON(slot == 0);
-+ slot -= 1;
-+ btrfs_item_key_to_cpu(&path->nodes[0], &found_key, slot);
-+ if (found_key.objectid != objectid)
-+ return 1;
-+
-+ read_extent_buffer(&path->nodes[0], item,
-+ btrfs_item_ptr_offset(&path->nodes[0], slot),
-+ sizeof(*item));
-+ return 0;
-+}
-+
-+static int find_setup_root(struct btrfs_root *tree_root,
-+ u32 nodesize,
-+ u32 leafsize,
-+ u32 sectorsize,
-+ u32 stripesize,
-+ u64 objectid,
-+ struct btrfs_root *dest_root,
-+ u64 bytenr,
-+ u32 blocksize,
-+ u64 generation,
-+ lookup_pool_id lpid)
-+{
-+ int ret;
-+ struct extent_buffer eb;
-+
-+ setup_root(dest_root,
-+ nodesize,
-+ leafsize,
-+ sectorsize,
-+ stripesize,
-+ objectid);
-+ if (tree_root) {
-+ /*
-+ * pick up the latest version
-+ * of the root we want to set up
-+ */
-+ ret = btrfs_find_last_root(tree_root, objectid,
-+ &dest_root->root_item,
-+ lpid);
-+ if (ret)
-+ return ret;
-+ bytenr = btrfs_root_bytenr(&dest_root->root_item);
-+ blocksize = btrfs_level_size(dest_root,
-+ btrfs_root_level(&dest_root->root_item));
-+ generation = btrfs_root_generation(&dest_root->root_item);
-+ }
-+ ret = read_tree_block(dest_root,
-+ &eb,
-+ bytenr,
-+ blocksize,
-+ generation,
-+ lpid);
-+ if (!ret)
-+ return 1;
-+ copy_extent_buffer(&dest_root->node, &eb);
-+ return 0;
-+}
-+
-+static inline int btrfs_strncmp(const char *cs, const char *ct, int count)
-+{
-+ signed char __res = 0;
-+
-+ while (count) {
-+ if ((__res = *cs - *ct++) != 0 || !*cs++)
-+ break;
-+ count--;
-+ }
-+ return __res;
-+}
-+
-+/*
-+ * the same as devread, but accepts
-+ * device number, start and length.
-+ */
-+static int btrfs_devread(unsigned long drive, unsigned long part,
-+ unsigned long dev_len, int sector,
-+ int byte_offset, int byte_len, char *buf)
-+{
-+ if (sector < 0
-+ || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
-+ >= dev_len)) {
-+ errnum = ERR_OUTSIDE_PART;
-+ return 0;
-+ }
-+ sector += byte_offset >> SECTOR_BITS;
-+ byte_offset &= SECTOR_SIZE - 1;
-+#if !defined(STAGE1_5)
-+ if (disk_read_hook && debug)
-+ printf ("<%d, %d, %d>", sector, byte_offset, byte_len);
-+#endif /* !STAGE1_5 */
-+ return rawread(drive, part + sector, byte_offset,
-+ byte_len, buf);
-+}
-+
-+static int btrfs_check_super(void)
-+{
-+ struct btrfs_super_block *sb = BTRFS_SUPER;
-+
-+ if (sb->nodesize != BTRFS_DEFAULT_NODE_SIZE) {
-+ btrfs_msg("Btrfs node size (%d) != %d unsupported\n",
-+ sb->nodesize, BTRFS_DEFAULT_NODE_SIZE);
-+ goto error;
-+ }
-+ if (sb->leafsize != BTRFS_DEFAULT_LEAF_SIZE) {
-+ btrfs_msg("Btrfs leaf size (%d) != %d unsupported\n",
-+ sb->leafsize, BTRFS_DEFAULT_LEAF_SIZE);
-+ goto error;
-+ }
-+
-+ return 0;
-+error:
-+ return 1;
-+}
-+
-+/* lift the super block */
-+static int btrfs_uptodate_super_copy(struct btrfs_fs_info *fs)
-+{
-+ errnum = ERR_NONE;
-+ btrfs_devread(BTRFS_FS_INFO->sb_dev.drive,
-+ BTRFS_FS_INFO->sb_dev.part,
-+ BTRFS_FS_INFO->sb_dev.length,
-+ btrfs_sb_offset(BTRFS_FS_INFO->sb_mirror) >> SECTOR_BITS,
-+ 0,
-+ sizeof(struct btrfs_super_block),
-+ (char *)BTRFS_SUPER);
-+ return btrfs_check_super();
-+}
-+
-+/*
-+ * Looking for a btrfs super block by magic, @fsid and @devid
-+ * (the last two ones are optional). Update latest transid (if
-+ * any). Return 0, if such super block was found. Otherwise,
-+ * return 1.
-+ *
-+ * NOTE:
-+ * After calling this function the sb_copy of global btrfs_fs_info
-+ * can contain garbage, so the caller is responsible for this to be
-+ * uptodate (see the function btrfs_uptodate_super_copy()).
-+ */
-+static int btrfs_find_super(struct btrfs_device *dev, char *fsid, u64 *devid)
-+{
-+ int i, ret;
-+ int found = 0;
-+
-+ for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
-+ ret = btrfs_devread(dev->drive,
-+ dev->part,
-+ dev->length,
-+ btrfs_sb_offset(i) >> SECTOR_BITS,
-+ 0,
-+ sizeof(struct btrfs_super_block),
-+ (char *)BTRFS_SUPER);
-+ if (!ret) {
-+ if (errnum == ERR_OUTSIDE_PART) {
-+ errnum = ERR_NONE;
-+ break;
-+ } else {
-+ errnum = ERR_NONE;
-+ continue;
-+ }
-+ }
-+ if (btrfs_super_bytenr(BTRFS_SUPER) != btrfs_sb_offset(i) ||
-+ btrfs_strncmp((char *)(&BTRFS_SUPER->magic),
-+ BTRFS_MAGIC,
-+ sizeof(BTRFS_SUPER->magic)))
-+ continue;
-+ if (fsid &&
-+ btrfs_strncmp(fsid,
-+ (char *)BTRFS_SUPER->fsid,
-+ BTRFS_FSID_SIZE))
-+ return 1;
-+ if (devid &&
-+ *devid != btrfs_super_devid(BTRFS_SUPER))
-+ return 1;
-+ found = 1;
-+ dev->devid = btrfs_super_devid(BTRFS_SUPER);
-+
-+ if (btrfs_super_generation(BTRFS_SUPER) >
-+ BTRFS_FS_INFO->sb_transid) {
-+ BTRFS_FS_INFO->sb_transid =
-+ btrfs_super_generation(BTRFS_SUPER);
-+ BTRFS_FS_INFO->sb_mirror = i;
-+ BTRFS_FS_INFO->sb_dev.devid =
-+ btrfs_super_devid(BTRFS_SUPER);
-+ BTRFS_FS_INFO->sb_dev.drive = dev->drive;
-+ BTRFS_FS_INFO->sb_dev.part = dev->part;
-+ BTRFS_FS_INFO->sb_dev.length = dev->length;
-+ }
-+ }
-+ return !found;
-+}
-+
-+/*
-+ * "Discern" a btrfs device by fsid and
-+ * optionaly by devid (if lookup is set).
-+ * Populate persistent device cache (if
-+ * there are free slots).
-+ */
-+static int btrfs_discerner(struct btrfs_device **dev, int lookup)
-+{
-+ if (btrfs_find_super(*dev,
-+ (char *)BTRFS_FS_INFO->fsid,
-+ (lookup ? &(*dev)->devid : 0)))
-+ /* not found */
-+ return 0;
-+ if (*dev < BTRFS_VOLATILE_DEV_CACHE) {
-+ /* populate persistent device cache */
-+ memcpy(*dev + 1, *dev, sizeof(struct btrfs_device));
-+ (*dev)++;
-+ }
-+ return 1;
-+}
-+
-+/*
-+ * Scan available grub devices and call discerner
-+ * for them. Return a number of discerned devices
-+ * The scanner was stolen from print_completions().
-+ *
-+ * Preconditions:
-+ * The global structure btrfs_fs_info contains
-+ * the latest valid version of btrfs superblock
-+ * (the field @sb_copy)
-+ */
-+static u64 scan_grub_devices(struct btrfs_device *dev,
-+ int (*discerner)(struct btrfs_device **, int),
-+ int lookup)
-+{
-+ int i, j;
-+ u64 count = 0;
-+ struct geometry geom;
-+
-+ for (i = 0; i < 2; i++)
-+ for (j = 0; j < 8; j++) {
-+ unsigned long part = 0xFFFFFF;
-+ int type, entry, gpt_count, gpt_size;
-+ unsigned long offset, ext_offset, gpt_offset;
-+
-+ dev->drive = (i * 0x80) + j;
-+ if (get_diskinfo(dev->drive, &geom))
-+ continue;
-+ while (1) {
-+ int ret;
-+ buf_drive = -1;
-+ errnum = ERR_NONE;
-+ ret = next_partition(dev->drive, 0xFFFFFF,
-+ &part, &type, &dev->part,
-+ &dev->length, &offset,
-+ &entry, &ext_offset,
-+ &gpt_offset, &gpt_count,
-+ &gpt_size,
-+ BTRFS_FS_INFO->mbr);
-+ if (!ret)
-+ break;
-+ if (discerner(&dev, lookup)) {
-+ count++;
-+ if (lookup)
-+ goto exit;
-+ }
-+ }
-+ }
-+#if 0
-+ errnum = ERR_NONE;
-+ if (cdrom_drive != GRUB_INVALID_DRIVE &&
-+ !get_diskinfo(cdrom_drive, &geom)) {
-+ dev->drive = cdrom_drive;
-+ dev->part = 0;
-+ dev->length = geom.total_sectors;
-+ if (discerner(&dev, lookup)) {
-+ count++;
-+ if (lookup)
-+ goto exit;
-+ }
-+ }
-+#ifdef SUPPORT_NETBOOT
-+ errnum = ERR_NONE;
-+ if (network_ready &&
-+ !get_diskinfo(NETWORK_DRIVE, &geom)) {
-+ dev->drive = NETWORK_DRIVE;
-+ dev->part = 0;
-+ dev->length = geom.total_sectors;
-+ if (discerner(&dev, lookup)) {
-+ count++;
-+ if (lookup)
-+ goto exit;
-+ }
-+ }
-+#endif /* SUPPORT_NETBOOT */
-+#endif /* 0 */
-+ exit:
-+ return count;
-+}
-+
-+#if 0
-+static int btrfs_next_item(struct btrfs_root *root,
-+ struct btrfs_path *path);
-+
-+/*
-+ * Scan the chunk tree for dev items
-+ * and call a seeker for all of them.
-+ * Preconditions: chunk root is installed
-+ * to the global btrfs_fs_info.
-+ */
-+static int scan_dev_tree(struct btrfs_device* (*seeker)(u64))
-+{
-+ int ret;
-+ u64 num_devices = 0;
-+ struct btrfs_key key;
-+ struct btrfs_key found_key;
-+ struct btrfs_path *path;
-+ struct btrfs_root *root;
-+
-+ root = BTRFS_CHUNK_ROOT;
-+ path = btrfs_grab_path(FIRST_EXTERNAL_LOOKUP_POOL);
-+ key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
-+ key.type = 0;
-+ key.offset = 0;
-+
-+ ret = aux_tree_lookup(root, &key, path);
-+ if (ret == -1)
-+ goto corrupted;
-+ while (1) {
-+ struct btrfs_device *result;
-+ struct btrfs_dev_item *dev_item;
-+
-+ btrfs_item_key_to_cpu(&path->nodes[0],
-+ &found_key,
-+ path->slots[0]);
-+ if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID)
-+ break;
-+ dev_item = btrfs_item_ptr(&path->nodes[0],
-+ path->slots[0],
-+ struct btrfs_dev_item);
-+ result = seeker(btrfs_device_id(&path->nodes[0], dev_item));
-+ if (result == NULL) {
-+ btrfs_msg("Btrfs device %llu is not available\n",
-+ btrfs_device_id(&path->nodes[0], dev_item));
-+ goto missed_dev;
-+ }
-+ num_devices++;
-+ ret = btrfs_next_item(root, path);
-+ if (ret)
-+ break;
-+ }
-+ if (num_devices == btrfs_super_num_devices(BTRFS_SUPER))
-+ return 0;
-+ corrupted:
-+ errnum = ERR_FSYS_CORRUPT;
-+ return 1;
-+ missed_dev:
-+ errnum = ERR_FSYS_MOUNT;
-+ return 1;
-+}
-+#endif /* 0 */
-+
-+/*
-+ * Find a grub btrfs device by devid.
-+ * Preconditions: global btrfs_fs_info
-+ * contains a copy of btrfs super block.
-+ *
-+ * Return pointer to the cached device on success.
-+ * Otherwise return NULL.
-+ */
-+static struct btrfs_device *btrfs_lookup_device(u64 devid)
-+{
-+ int i, result;
-+ struct btrfs_device *cdev;
-+
-+ for (i = 0; i < BTRFS_NUM_CACHED_DEVICES; i++) {
-+ cdev = &BTRFS_DEVICES[i];
-+ if (cdev->devid == devid)
-+ goto found_in_cache;
-+ if (cdev->devid == 0)
-+ goto not_found_in_cache;
-+ }
-+not_found_in_cache:
-+ cdev = BTRFS_VOLATILE_DEV_CACHE;
-+ cdev->devid = devid;
-+ result = scan_grub_devices(cdev,
-+ btrfs_discerner,
-+ 1);
-+ if (result == 0)
-+ /*
-+ * At mount time we have figured out that
-+ * number of available devices is not less
-+ * then number of devices recorded in the
-+ * super block. Hence we treat this case as
-+ * file system corruption.
-+ */
-+ goto corrupt;
-+ result = btrfs_uptodate_super_copy(BTRFS_FS_INFO);
-+ if (result)
-+ goto corrupt;
-+found_in_cache:
-+ return cdev;
-+corrupt:
-+ errnum = ERR_FSYS_CORRUPT;
-+ return NULL;
-+}
-+
-+static int btrfs_find_device(struct btrfs_device *dev)
-+{
-+ struct btrfs_device *cdev;
-+
-+ if (btrfs_super_num_devices(BTRFS_SUPER) == 1) {
-+ dev->drive = current_drive;
-+ dev->part = part_start;
-+ dev->length = part_length;
-+ return 0;
-+ }
-+ cdev = btrfs_lookup_device(dev->devid);
-+ if (cdev == NULL)
-+ return 1;
-+ dev->drive = cdev->drive;
-+ dev->part = cdev->part;
-+ dev->length = cdev->length;
-+ return 0;
-+}
-+
-+static inline void init_btrfs_volatile_dev_cache(void)
-+{
-+ BTRFS_VOLATILE_DEV_CACHE->devid = 0;
-+ BTRFS_VOLATILE_DEV_CACHE->drive = current_drive;
-+ BTRFS_VOLATILE_DEV_CACHE->part = part_start;
-+ BTRFS_VOLATILE_DEV_CACHE->length = part_length;
-+}
-+
-+/*
-+ * check availability of btrfs devices
-+ * and populate the persistent device cache
-+ */
-+static int btrfs_check_devices(void)
-+{
-+ u64 num_dev;
-+
-+ if (btrfs_super_num_devices(BTRFS_SUPER) == 1)
-+ return 0;
-+ num_dev = scan_grub_devices(BTRFS_DEVICES,
-+ btrfs_discerner, 0);
-+ if (btrfs_uptodate_super_copy(BTRFS_FS_INFO))
-+ return 1;
-+ if (num_dev < btrfs_super_num_devices(BTRFS_SUPER)) {
-+ btrfs_msg("Some (%llu) Btrfs devices is not available\n",
-+ btrfs_super_num_devices(BTRFS_SUPER) - num_dev);
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+int btrfs_mount(void)
-+{
-+ int ret;
-+
-+ check_btrfs_cache_size();
-+ init_btrfs_info();
-+ init_btrfs_volatile_dev_cache();
-+
-+ ret = btrfs_find_super(BTRFS_VOLATILE_DEV_CACHE, NULL, NULL);
-+ if (ret) {
-+ btrfs_msg("Drive %lu, partition %lu: no Btrfs metadata\n",
-+ current_drive, part_start);
-+ goto error;
-+ }
-+ ret = btrfs_uptodate_super_copy(BTRFS_FS_INFO);
-+ if (ret)
-+ goto error;
-+ BTRFS_FS_INFO->sb_transid =
-+ btrfs_super_generation(BTRFS_SUPER);
-+ memcpy(BTRFS_FS_INFO->fsid,
-+ BTRFS_SUPER->fsid,
-+ BTRFS_FSID_SIZE);
-+ ret = btrfs_check_devices();
-+ if (ret)
-+ goto error;
-+ /* setup chunk root */
-+ ret = find_setup_root(NULL,
-+ btrfs_super_nodesize(BTRFS_SUPER),
-+ btrfs_super_leafsize(BTRFS_SUPER),
-+ btrfs_super_sectorsize(BTRFS_SUPER),
-+ btrfs_super_stripesize(BTRFS_SUPER),
-+ BTRFS_CHUNK_TREE_OBJECTID,
-+ BTRFS_CHUNK_ROOT,
-+ btrfs_super_chunk_root(BTRFS_SUPER),
-+ btrfs_chunk_root_level_size(BTRFS_SUPER),
-+ btrfs_super_chunk_root_generation(BTRFS_SUPER),
-+ FIRST_EXTERNAL_LOOKUP_POOL);
-+ if (ret)
-+ return 0;
-+ /* setup tree root */
-+ ret = find_setup_root(NULL,
-+ btrfs_super_nodesize(BTRFS_SUPER),
-+ btrfs_super_leafsize(BTRFS_SUPER),
-+ btrfs_super_sectorsize(BTRFS_SUPER),
-+ btrfs_super_stripesize(BTRFS_SUPER),
-+ BTRFS_ROOT_TREE_OBJECTID,
-+ BTRFS_TREE_ROOT,
-+ btrfs_super_root(BTRFS_SUPER),
-+ btrfs_root_level_size(BTRFS_SUPER),
-+ btrfs_super_generation(BTRFS_SUPER),
-+ FIRST_EXTERNAL_LOOKUP_POOL);
-+ if (ret)
-+ return 0;
-+ /* setup fs_root */
-+ ret = find_setup_root(BTRFS_TREE_ROOT,
-+ btrfs_super_nodesize(BTRFS_SUPER),
-+ btrfs_super_leafsize(BTRFS_SUPER),
-+ btrfs_super_sectorsize(BTRFS_SUPER),
-+ btrfs_super_stripesize(BTRFS_SUPER),
-+ BTRFS_FS_TREE_OBJECTID,
-+ BTRFS_FS_ROOT,
-+ 0,
-+ 0,
-+ 0,
-+ FIRST_EXTERNAL_LOOKUP_POOL);
-+ return !ret;
-+
-+error:
-+ errnum = ERR_FSYS_MOUNT;
-+ return 0;
-+}
-+
-+/*
-+ * Check, whether @chunk is the map for a
-+ * block with @logical block number.
-+ * If yes, then fill the @map.
-+ * Return 1 on affirmative result,
-+ * otherwise return 0.
-+ */
-+int check_read_chunk(struct btrfs_key *key,
-+ struct extent_buffer *leaf,
-+ struct btrfs_chunk *chunk,
-+ struct map_lookup *map,
-+ u64 logical)
-+{
-+ int i, ret;
-+ u64 chunk_start;
-+ u64 chunk_size;
-+ int num_stripes;
-+
-+ chunk_start = key->offset;
-+ chunk_size = btrfs_chunk_length(leaf, chunk);
-+
-+ if (logical + 1 > chunk_start + chunk_size ||
-+ logical < chunk_start)
-+ /* not a fit */
-+ return 0;
-+ num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
-+ map->ce.start = chunk_start;
-+ map->ce.size = chunk_size;
-+ map->num_stripes = num_stripes;
-+ map->io_width = btrfs_chunk_io_width(leaf, chunk);
-+ map->io_align = btrfs_chunk_io_align(leaf, chunk);
-+ map->sector_size = btrfs_chunk_sector_size(leaf, chunk);
-+ map->stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
-+ map->type = btrfs_chunk_type(leaf, chunk);
-+ map->sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk);
-+
-+ for (i = 0; i < num_stripes; i++) {
-+ map->stripes[i].physical =
-+ btrfs_stripe_offset_nr(leaf, chunk, i);
-+ map->stripes[i].dev.devid =
-+ btrfs_stripe_devid_nr(leaf, chunk, i);
-+ ret = btrfs_find_device(&map->stripes[i].dev);
-+ if (ret)
-+ return 0;
-+ }
-+ return 1;
-+}
-+
-+static void init_extent_buffer(struct extent_buffer *eb,
-+ struct btrfs_device *dev,
-+ u64 logical,
-+ u32 blocksize,
-+ u64 physical,
-+ lookup_pool_id lpid)
-+{
-+ if (dev)
-+ memcpy(&eb->dev, dev, sizeof(*dev));
-+ eb->start = logical;
-+ eb->len = blocksize;
-+ eb->dev_bytenr = physical;
-+ eb->data = grab_lookup_cache(lpid);
-+}
-+
-+/*
-+ * Search for a map by logical offset in sys array.
-+ * Return -1 on errors;
-+ * Return 1 if the map is found,
-+ * Return 0 if the map is not found.
-+ */
-+int sys_array_lookup(struct map_lookup *map, u64 logical)
-+{
-+ struct extent_buffer sb;
-+ struct btrfs_disk_key *disk_key;
-+ struct btrfs_chunk *chunk;
-+ struct btrfs_key key;
-+ u32 num_stripes;
-+ u32 array_size;
-+ u32 len = 0;
-+ u8 *ptr;
-+ unsigned long sb_ptr;
-+ u32 cur;
-+ int ret;
-+ int i = 0;
-+
-+ sb.data = (char *)BTRFS_SUPER;
-+ array_size = btrfs_super_sys_array_size(BTRFS_SUPER);
-+
-+ ptr = BTRFS_SUPER->sys_chunk_array;
-+ sb_ptr = offsetof(struct btrfs_super_block, sys_chunk_array);
-+ cur = 0;
-+
-+ while (cur < array_size) {
-+ disk_key = (struct btrfs_disk_key *)ptr;
-+ btrfs_disk_key_to_cpu(&key, disk_key);
-+
-+ len = sizeof(*disk_key);
-+ ptr += len;
-+ sb_ptr += len;
-+ cur += len;
-+
-+ if (key.type == BTRFS_CHUNK_ITEM_KEY) {
-+ chunk = (struct btrfs_chunk *)sb_ptr;
-+ ret = check_read_chunk(&key, &sb,
-+ chunk, map, logical);
-+ if (ret)
-+ /* map is found */
-+ return ret;
-+ num_stripes = btrfs_chunk_num_stripes(&sb, chunk);
-+ len = btrfs_chunk_item_size(num_stripes);
-+ } else {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return -1;
-+ }
-+ ptr += len;
-+ sb_ptr += len;
-+ cur += len;
-+ i++;
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * Search for a map by logical offset in the chunk tree.
-+ * Return 1 if map is found, otherwise return 0.
-+ */
-+static int chunk_tree_lookup(struct map_lookup *map,
-+ u64 logical)
-+{
-+ int ret;
-+ int slot;
-+ struct extent_buffer *leaf;
-+ struct btrfs_key key;
-+ struct btrfs_key found_key;
-+ struct btrfs_chunk *chunk;
-+ struct btrfs_path *path;
-+
-+ path = btrfs_grab_path(INTERNAL_LOOKUP_POOL);
-+
-+ key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
-+ key.offset = logical;
-+ key.type = BTRFS_CHUNK_ITEM_KEY;
-+
-+ ret = aux_tree_lookup(BTRFS_CHUNK_ROOT, &key, path);
-+ if (ret < 0)
-+ return 0;
-+ leaf = &path->nodes[0];
-+ slot = path->slots[0];
-+ if (ret == 1) {
-+ WARN_ON(slot == 0);
-+ slot -= 1;
-+ }
-+ btrfs_item_key_to_cpu(leaf, &found_key, slot);
-+ if (found_key.type != BTRFS_CHUNK_ITEM_KEY)
-+ return 0;
-+ chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
-+ return check_read_chunk(&found_key, leaf,
-+ chunk, map, logical);
-+}
-+
-+/*
-+ * Btrfs logical/physical block mapper.
-+ * Look for an appropriate map-extent and
-+ * perform a translation. Return 1 on errors.
-+ */
-+static int btrfs_map_block(u64 logical, u64 *length,
-+ struct btrfs_multi_bio *multi,
-+ int mirror_num)
-+{
-+ struct map_lookup map;
-+ u64 offset;
-+ u64 stripe_offset;
-+ u64 stripe_nr;
-+ struct cache_extent *ce;
-+ int stripe_index;
-+ int i;
-+ int ret;
-+
-+ memset(&map, 0, sizeof(map));
-+ ret = sys_array_lookup(&map, logical);
-+ if (ret == -1) {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return 1;
-+ }
-+ if (ret == 0) {
-+ ret = chunk_tree_lookup(&map, logical);
-+ if (!ret) {
-+ /* something should be found! */
-+ errnum = ERR_FSYS_CORRUPT;
-+ return 1;
-+ }
-+ }
-+ /* do translation */
-+ ce = &map.ce;
-+
-+ offset = logical - ce->start;
-+ stripe_nr = offset / map.stripe_len;
-+ stripe_offset = stripe_nr * map.stripe_len;
-+ WARN_ON(offset < stripe_offset);
-+
-+ stripe_offset = offset - stripe_offset;
-+
-+ if (map.type & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
-+ BTRFS_BLOCK_GROUP_RAID10 |
-+ BTRFS_BLOCK_GROUP_DUP)) {
-+ *length = min_t(u64, ce->size - offset,
-+ map.stripe_len - stripe_offset);
-+ } else {
-+ *length = ce->size - offset;
-+ }
-+ multi->num_stripes = 1;
-+ stripe_index = 0;
-+ if (map.type & BTRFS_BLOCK_GROUP_RAID1) {
-+ if (mirror_num)
-+ stripe_index = mirror_num - 1;
-+ else
-+ stripe_index = stripe_nr % map.num_stripes;
-+ } else if (map.type & BTRFS_BLOCK_GROUP_RAID10) {
-+ int factor = map.num_stripes / map.sub_stripes;
-+
-+ stripe_index = stripe_nr % factor;
-+ stripe_index *= map.sub_stripes;
-+
-+ if (mirror_num)
-+ stripe_index += mirror_num - 1;
-+ else
-+ stripe_index = stripe_nr % map.sub_stripes;
-+
-+ stripe_nr = stripe_nr / factor;
-+ } else if (map.type & BTRFS_BLOCK_GROUP_DUP) {
-+ if (mirror_num)
-+ stripe_index = mirror_num - 1;
-+ } else {
-+ stripe_index = stripe_nr % map.num_stripes;
-+ stripe_nr = stripe_nr / map.num_stripes;
-+ }
-+ WARN_ON(stripe_index >= map.num_stripes);
-+
-+ for (i = 0; i < multi->num_stripes; i++) {
-+ asm("" : "+r"(multi));
-+ multi->stripes[i].physical =
-+ map.stripes[stripe_index].physical + stripe_offset +
-+ stripe_nr * map.stripe_len;
-+ memcpy(&multi->stripes[i].dev,
-+ &map.stripes[stripe_index].dev,
-+ sizeof(struct btrfs_device));
-+ stripe_index++;
-+ }
-+ return 0;
-+}
-+
-+static u64 read_data_extent(u64 logical_start, u64 to_read, char *pos)
-+{
-+ int ret;
-+ u64 length;
-+ struct btrfs_multi_bio multi;
-+
-+ while (to_read) {
-+ ret = btrfs_map_block(logical_start, &length, &multi, 0);
-+ if (ret) {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return ret;
-+ }
-+ if (length > to_read)
-+ length = to_read;
-+ disk_read_func = disk_read_hook;
-+ ret = btrfs_devread(multi.stripes[0].dev.drive,
-+ multi.stripes[0].dev.part,
-+ multi.stripes[0].dev.length,
-+ multi.stripes[0].physical >> SECTOR_BITS,
-+ logical_start & ((u64)SECTOR_SIZE - 1),
-+ length,
-+ pos);
-+ disk_read_func = NULL;
-+ if (!ret)
-+ return 1;
-+ btrfs_msg("BTRFS data extent: read %llu bytes\n", length);
-+ to_read -= length;
-+ pos += length;
-+ logical_start += length;
-+ }
-+ return 0;
-+}
-+
-+static int read_extent_from_disk(struct extent_buffer *eb)
-+{
-+ WARN_ON(eb->dev_bytenr % SECTOR_BITS);
-+ return btrfs_devread(eb->dev.drive,
-+ eb->dev.part,
-+ eb->dev.length,
-+ eb->dev_bytenr >> SECTOR_BITS,
-+ 0,
-+ eb->len,
-+ eb->data);
-+}
-+
-+static int verify_parent_transid(struct extent_buffer *eb, u64 parent_transid)
-+{
-+ return parent_transid && (btrfs_header_generation(eb) !=
parent_transid);
-+}
-+
-+static int btrfs_num_copies(u64 logical, u64 len)
-+{
-+ return 1;
-+}
-+
-+static int check_tree_block(struct btrfs_root *root, struct extent_buffer
*buf)
-+{
-+ return 0;
-+}
-+
-+static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
-+ int verify)
-+{
-+ return 0;
-+}
-+
-+/*
-+ * Read a block of logical number @bytenr
-+ * from disk to buffer @eb.
-+ * Return 1 on success.
-+ */
-+int read_tree_block(struct btrfs_root *root,
-+ struct extent_buffer *eb,
-+ u64 bytenr, /* logical */
-+ u32 blocksize,
-+ u64 parent_transid,
-+ lookup_pool_id lpid)
-+{
-+ int ret;
-+ int dev_nr;
-+ u64 length;
-+ struct btrfs_multi_bio multi;
-+ int mirror_num = 0;
-+ int num_copies;
-+
-+ dev_nr = 0;
-+ length = blocksize;
-+ while (1) {
-+ ret = btrfs_map_block(bytenr,
-+ &length, &multi, mirror_num);
-+ if (ret) {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return 0;
-+ }
-+ init_extent_buffer(eb,
-+ &multi.stripes[0].dev,
-+ bytenr,
-+ blocksize,
-+ multi.stripes[0].physical,
-+ lpid);
-+
-+ ret = read_extent_from_disk(eb);
-+ if (ret &&
-+ check_tree_block(root, eb) == 0 &&
-+ csum_tree_block(root, eb, 1) == 0 &&
-+ verify_parent_transid(eb, parent_transid) == 0)
-+ return 1;
-+
-+ num_copies = btrfs_num_copies(eb->start, eb->len);
-+ if (num_copies == 1)
-+ break;
-+ mirror_num++;
-+ if (mirror_num > num_copies)
-+ break;
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * Read a child pointed by @slot node pointer
-+ * of @parent. Put the result to @parent.
-+ * Return 1 on success.
-+ */
-+static int parent2child(struct btrfs_root *root,
-+ struct extent_buffer *parent,
-+ int slot,
-+ lookup_pool_id lpid)
-+{
-+ int level;
-+
-+ WARN_ON(slot < 0);
-+ WARN_ON(slot >= btrfs_header_nritems(parent));
-+
-+ level = btrfs_header_level(parent);
-+ WARN_ON(level <= 0);
-+
-+ return read_tree_block(root,
-+ parent,
-+ btrfs_node_blockptr(parent, slot),
-+ btrfs_level_size(root, level - 1),
-+ btrfs_node_ptr_generation(parent, slot),
-+ lpid);
-+}
-+
-+static int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
-+{
-+ struct btrfs_key k1;
-+
-+ btrfs_disk_key_to_cpu(&k1, disk);
-+
-+ if (k1.objectid > k2->objectid)
-+ return 1;
-+ if (k1.objectid < k2->objectid)
-+ return -1;
-+ if (k1.type > k2->type)
-+ return 1;
-+ if (k1.type < k2->type)
-+ return -1;
-+ if (k1.offset > k2->offset)
-+ return 1;
-+ if (k1.offset < k2->offset)
-+ return -1;
-+ return 0;
-+}
-+
-+static int bin_search(struct extent_buffer *eb, unsigned long p,
-+ int item_size, struct btrfs_key *key,
-+ int max, int *slot)
-+{
-+ int low = 0;
-+ int high = max;
-+ int mid;
-+ int ret;
-+ unsigned long offset;
-+ struct btrfs_disk_key *tmp;
-+
-+ while(low < high) {
-+ mid = (low + high) / 2;
-+ offset = p + mid * item_size;
-+
-+ tmp = (struct btrfs_disk_key *)(eb->data + offset);
-+ ret = btrfs_comp_keys(tmp, key);
-+
-+ if (ret < 0)
-+ low = mid + 1;
-+ else if (ret > 0)
-+ high = mid;
-+ else {
-+ *slot = mid;
-+ return 0;
-+ }
-+ }
-+ *slot = low;
-+ return 1;
-+}
-+
-+/* look for a key in a node */
-+static int node_lookup(struct extent_buffer *eb,
-+ struct btrfs_key *key,
-+ int *slot)
-+{
-+ if (btrfs_header_level(eb) == 0) {
-+ return bin_search(eb,
-+ offsetof(struct btrfs_leaf, items),
-+ sizeof(struct btrfs_item),
-+ key, btrfs_header_nritems(eb),
-+ slot);
-+ } else {
-+ return bin_search(eb,
-+ offsetof(struct btrfs_node, ptrs),
-+ sizeof(struct btrfs_key_ptr),
-+ key, btrfs_header_nritems(eb),
-+ slot);
-+ }
-+ return -1;
-+}
-+
-+static inline int check_node(struct extent_buffer *buf, int slot)
-+{
-+ return 0;
-+}
-+
-+/*
-+ * Look for an item by key in read-only tree.
-+ * Return 0, if key was found. Return -1 on io errors.
-+ *
-+ * Preconditions: btrfs_mount already executed.
-+ * Postconditions: if returned value is non-negative,
-+ * then path[0] represents the found position in the
-+ * tree. All components of the @path from leaf to root
-+ * are valid except their data buffers (only path[0]
-+ * has valid attached data buffer).
-+ */
-+
-+int aux_tree_lookup(struct btrfs_root *root,
-+ struct btrfs_key *key,
-+ struct btrfs_path *path)
-+{
-+ int ret;
-+ int slot = 0;
-+ int level;
-+ struct extent_buffer node;
-+ init_extent_buffer(&node,
-+ NULL,
-+ 0,
-+ 0,
-+ 0,
-+ path->lpid);
-+ copy_extent_buffer(&node, &root->node);
-+ do {
-+ level = btrfs_header_level(&node);
-+ ret = check_node(&node, slot);
-+ if (ret)
-+ return -1;
-+ move_extent_buffer(&path->nodes[level],
-+ &node);
-+ ret = node_lookup(&node, key, &slot);
-+ if (ret < 0)
-+ return ret;
-+ if (level) {
-+ /*
-+ * non-leaf,
-+ * jump to the next level
-+ */
-+ if (ret && slot > 0)
-+ slot -= 1;
-+ ret = parent2child(root, &node, slot, path->lpid);
-+ if (ret == 0)
-+ return -1;
-+ }
-+ path->slots[level] = slot;
-+ } while (level);
-+ return ret;
-+}
-+
-+static int readup_buffer(struct extent_buffer *buf, lookup_pool_id lpid)
-+{
-+ buf->data = grab_lookup_cache(lpid);
-+ return read_extent_from_disk(buf);
-+}
-+
-+/*
-+ * Find the next leaf in accordance with tree order;
-+ * walk up the tree as far as required to find it.
-+ * Returns 0 if something was found, or 1 if there
-+ * are no greater leaves. Returns < 0 on io errors.
-+ *
-+ * Preconditions: all @path components from leaf to
-+ * root have valid meta-data fields. path[0] has a
-+ * valid attached data buffer with initial leaf.
-+ * Postcondition: the same as above, but path[0] has
-+ * an attached data buffer with the next leaf.
-+ */
-+static int btrfs_next_leaf(struct btrfs_root *root,
-+ struct btrfs_path *path)
-+{
-+ int res;
-+ int slot;
-+ int level = 1;
-+ struct extent_buffer *buf;
-+
-+ while(level < BTRFS_MAX_LEVEL) {
-+ buf = &path->nodes[level];
-+ slot = path->slots[level] + 1;
-+ /*
-+ * lift data on this level
-+ */
-+ res = readup_buffer(buf, path->lpid);
-+ if (!res)
-+ break;
-+ if (slot >= btrfs_header_nritems(buf)) {
-+ /* alas, go to parent (if any) */
-+ level++;
-+ res = 1;
-+ continue;
-+ }
-+ break;
-+ }
-+ if (!res)
-+ return 1;
-+ /*
-+ * At this level slot points to
-+ * the subtree we are interested in.
-+ */
-+ path->slots[level] = slot;
-+ while(level) {
-+ struct extent_buffer tmp;
-+ move_extent_buffer(&tmp, &path->nodes[level]);
-+ res = parent2child(root, &tmp, slot, path->lpid);
-+ if (res == 0)
-+ return -1;
-+ level --;
-+ slot = 0;
-+ move_extent_buffer(&path->nodes[level], &tmp);
-+ path->slots[level] = slot;
-+ }
-+ return 0;
-+}
-+
-+/* Preconditions: path is valid, data buffer
-+ * is attached to leaf node.
-+ * Postcondition: path is updated to point to
-+ * the next position with respect to the tree
-+ * order.
-+ *
-+ * Return -1 on io errors.
-+ * Return 0, if next item was found.
-+ * Return 1, if next item wasn't found (no more items).
-+ */
-+static int btrfs_next_item(struct btrfs_root *root,
-+ struct btrfs_path *path)
-+{
-+ WARN_ON(path->slots[0] >= btrfs_header_nritems(&path->nodes[0]));
-+
-+ path->slots[0] += 1;
-+
-+ if (path->slots[0] < btrfs_header_nritems(&path->nodes[0]))
-+ return 0;
-+ if (coord_is_root(root, path))
-+ /* no more items */
-+ return 1;
-+ return btrfs_next_leaf(root, path);
-+}
-+
-+/*
-+ * check if we can reuse results of previous
-+ * search for read operation
-+ */
-+static int path_is_valid(struct btrfs_path *path,
-+ struct btrfs_key *key, u64 offset)
-+{
-+ btrfs_item_key_to_cpu(&path->nodes[0],
-+ key,
-+ path->slots[0]);
-+ if (BTRFS_FILE_INFO_KEY->objectid != key->objectid)
-+ return 0;
-+ if (btrfs_key_type(key) == BTRFS_INODE_ITEM_KEY)
-+ return 1;
-+ if (btrfs_key_type(key) != BTRFS_EXTENT_DATA_KEY)
-+ return 0;
-+ return BTRFS_FILE_INFO_KEY->offset <= offset;
-+}
-+
-+/* ->read_func() */
-+int btrfs_read(char *buf, int len)
-+{
-+ int ret;
-+ struct btrfs_root *fs_root;
-+ struct btrfs_path *path;
-+ struct btrfs_key path_key;
-+ u64 ioff;
-+ u64 bytes;
-+ int to_read;
-+ char *pos = buf;
-+
-+ fs_root = BTRFS_FS_ROOT;
-+ path = btrfs_grab_path(FIRST_EXTERNAL_LOOKUP_POOL);
-+
-+ if (!path_is_valid(path, &path_key, filepos)) {
-+ ret = aux_tree_lookup(fs_root, BTRFS_FILE_INFO_KEY, path);
-+ if (ret < 0)
-+ errnum = ERR_FSYS_CORRUPT;
-+ }
-+ while (!errnum) {
-+ struct btrfs_item *item;
-+ struct btrfs_file_extent_item *fi;
-+ u64 from;
-+
-+ btrfs_item_key_to_cpu(&path->nodes[0],
-+ &path_key,
-+ path->slots[0]);
-+ if (BTRFS_FILE_INFO_KEY->objectid != path_key.objectid)
-+ break;
-+ if (btrfs_key_type(&path_key) != BTRFS_EXTENT_DATA_KEY)
-+ goto next;
-+ /*
-+ * current position is extent item
-+ */
-+ item = btrfs_item_nr(&path->nodes[0], path->slots[0]);
-+ fi = btrfs_item_ptr(&path->nodes[0],
-+ path->slots[0],
-+ struct btrfs_file_extent_item);
-+ if (btrfs_file_extent_compression(&path->nodes[0], fi)) {
-+ btrfs_msg("Btrfs transparent compression unsupported\n");
-+ errnum = ERR_BAD_FILETYPE;
-+ goto exit;
-+ }
-+ ioff = filepos - path_key.offset;
-+
-+ switch (btrfs_file_extent_type(&path->nodes[0], fi)) {
-+ case BTRFS_FILE_EXTENT_INLINE:
-+ bytes = btrfs_file_extent_inline_item_len(&path->
-+ nodes[0],
-+ item);
-+ if (path_key.offset + bytes < filepos)
-+ goto next;
-+ to_read = bytes - ioff;
-+ if (to_read > len)
-+ to_read = len;
-+ from = ioff + btrfs_file_extent_inline_start(fi);
-+ if (disk_read_hook != NULL) {
-+ disk_read_func = disk_read_hook;
-+ ret = btrfs_devread(path->nodes[0].dev.drive,
-+ path->nodes[0].dev.part,
-+ path->nodes[0].dev.length,
-+ path->nodes[0].dev_bytenr >>
-+ SECTOR_BITS,
-+ from,
-+ to_read,
-+ pos);
-+ disk_read_func = NULL;
-+ if (ret)
-+ goto exit;
-+ } else
-+ memcpy(pos,
-+ path->nodes[0].data + from,
-+ to_read);
-+ btrfs_msg("BTRFS inline extent: read %d bytes pos %d\n",
-+ to_read, filepos);
-+ break;
-+ case BTRFS_FILE_EXTENT_REG:
-+ bytes = btrfs_file_extent_num_bytes(&path->nodes[0],
-+ fi);
-+ if (path_key.offset + bytes < filepos)
-+ goto next;
-+ to_read = bytes - ioff;
-+ if (to_read > len)
-+ to_read = len;
-+ from = ioff +
-+ btrfs_file_extent_disk_bytenr(&path->nodes[0],
-+ fi) +
-+ btrfs_file_extent_offset(&path->nodes[0],
-+ fi);
-+ ret = read_data_extent(from, to_read, pos);
-+ if (ret)
-+ goto exit;
-+ break;
-+ case BTRFS_FILE_EXTENT_PREALLOC:
-+ btrfs_msg("Btrfs preallocated extents unsupported\n");
-+ errnum = ERR_BAD_FILETYPE;
-+ goto exit;
-+ default:
-+ errnum = ERR_FSYS_CORRUPT;
-+ goto exit;
-+ }
-+ len -= to_read;
-+ pos += to_read;
-+ filepos += to_read;
-+ if (len == 0)
-+ break;
-+ /* not everything was read */
-+ next:
-+ ret = btrfs_next_item(fs_root, path);
-+ if (ret < 0) {
-+ errnum = ERR_FSYS_CORRUPT;
-+ break;
-+ }
-+ btrfs_update_file_info(path);
-+ continue;
-+ }
-+exit:
-+ return errnum ? 0 : pos - buf;
-+}
-+
-+static int btrfs_follow_link(struct btrfs_root *root,
-+ struct btrfs_path *path,
-+ char **dirname, char *linkbuf,
-+ int *link_count,
-+ struct btrfs_inode_item *sd)
-+{
-+ int ret;
-+ int len;
-+ char *name = *dirname;
-+
-+ if (++(*link_count) > MAX_LINK_COUNT) {
-+ errnum = ERR_SYMLINK_LOOP;
-+ return 0;
-+ }
-+ /* calculate remaining name size */
-+ filemax = btrfs_inode_size(&path->nodes[0], sd);
-+ for (len = 0;
-+ name[len] && isspace(name[len]);
-+ len ++);
-+
-+ if (filemax + len > PATH_MAX - 1) {
-+ errnum = ERR_FILELENGTH;
-+ return 0;
-+ }
-+ grub_memmove(linkbuf + filemax, name, len + 1);
-+ btrfs_update_file_info(path);
-+ filepos = 0;
-+ /* extract symlink content */
-+ while (1) {
-+ u64 oid = BTRFS_FILE_INFO_KEY->objectid;
-+ ret = btrfs_next_item(root, path);
-+ if (ret)
-+ break;
-+ btrfs_update_file_info(path);
-+ if (oid != BTRFS_FILE_INFO_KEY->objectid)
-+ break;
-+ if (btrfs_key_type(BTRFS_FILE_INFO_KEY) ==
-+ BTRFS_EXTENT_DATA_KEY)
-+ goto found;
-+ }
-+ /* no target was found */
-+ errnum = ERR_FSYS_CORRUPT;
-+ return 0;
-+found:
-+ /* fill the rest of linkbuf with the content */
-+ ret = btrfs_read(linkbuf, filemax);
-+ if (ret != filemax) {
-+ errnum = ERR_FSYS_CORRUPT;
-+ return 0;
-+ }
-+ return 1;
-+}
-+
-+static int update_fs_root(struct btrfs_root *fs_root,
-+ struct btrfs_key *location)
-+{
-+ int ret;
-+ struct btrfs_root *tree_root;
-+
-+ if (location->offset != (u64)-1)
-+ return 0;
-+ tree_root = &BTRFS_FS_INFO->tree_root;
-+ ret = find_setup_root(tree_root,
-+ tree_root->nodesize,
-+ tree_root->leafsize,
-+ tree_root->sectorsize,
-+ tree_root->stripesize,
-+ location->objectid,
-+ fs_root,
-+ 0,
-+ 0,
-+ 0,
-+ SECOND_EXTERNAL_LOOKUP_POOL);
-+ if (ret)
-+ return ret;
-+ location->objectid = btrfs_root_dirid(&fs_root->root_item);
-+ btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
-+ location->offset = 0;
-+ return 0;
-+}
-+
-+#ifndef STAGE1_5
-+static inline void update_possibilities(void)
-+{
-+ if (print_possibilities > 0)
-+ print_possibilities =
-+ -print_possibilities;
-+}
-+#endif
-+
-+/*
-+ * Look for a directory item by name.
-+ * Print possibilities, if needed.
-+ * Postconditions: on success @sd_key points
-+ * to the key contained in the directory entry.
-+ */
-+static int btrfs_de_index_by_name(struct btrfs_root *root,
-+ struct btrfs_path *path,
-+ char **dirname,
-+ struct btrfs_key *sd_key)
-+{
-+ char ch;
-+ int ret;
-+ char *rest;
-+ struct btrfs_dir_item *di;
-+#ifndef STAGE1_5
-+ int do_possibilities = 0;
-+#endif
-+ for (; **dirname == '/'; (*dirname)++);
-+ for (rest = *dirname;
-+ (ch = *rest) && !isspace(ch) && ch != '/';
-+ rest++);
-+ *rest = 0; /* for substrung() */
-+#ifndef STAGE1_5
-+ if (print_possibilities && ch != '/')
-+ do_possibilities = 1;
-+#endif
-+ /* scan a directory */
-+ while (1) {
-+ u32 total;
-+ u32 cur = 0;
-+ u32 len;
-+ struct btrfs_key di_key;
-+ struct btrfs_disk_key location;
-+ struct btrfs_item *item;
-+
-+ /* extract next dir entry */
-+ ret = btrfs_next_item(root, path);
-+ if (ret)
-+ break;
-+ item = btrfs_item_nr(&path->nodes[0],
-+ path->slots[0]);
-+ btrfs_item_key_to_cpu(&path->nodes[0],
-+ &di_key,
-+ path->slots[0]);
-+ if (di_key.objectid != sd_key->objectid)
-+ /* no more entries */
-+ break;
-+ di = btrfs_item_ptr(&path->nodes[0],
-+ path->slots[0],
-+ struct btrfs_dir_item);
-+ /*
-+ * working around special cases:
-+ * btrfs doesn't maintain directory entries
-+ * which contain names "." and ".."
-+ */
-+ if (!substring(".", *dirname)) {
-+#ifndef STAGE1_5
-+ if (do_possibilities) {
-+ update_possibilities();
-+ return 1;
-+ }
-+#endif
-+ goto found;
-+ }
-+ if (!substring("..", *dirname)) {
-+ if (di_key.type != BTRFS_INODE_REF_KEY)
-+ continue;
-+ sd_key->objectid = di_key.offset;
-+ btrfs_set_key_type(sd_key, BTRFS_INODE_ITEM_KEY);
-+ sd_key->offset = 0;
-+#ifndef STAGE1_5
-+ if (do_possibilities) {
-+ update_possibilities();
-+ return 1;
-+ }
-+#endif
-+ goto found;
-+ }
-+ if (di_key.type != BTRFS_DIR_ITEM_KEY)
-+ continue;
-+ total = btrfs_item_size(&path->nodes[0], item);
-+ /* scan a directory item */
-+ while (cur < total) {
-+ char tmp;
-+ int result;
-+ char *filename;
-+ char *end_of_name;
-+ int name_len;
-+ int data_len;
-+
-+ btrfs_dir_item_key(&path->nodes[0], di, &location);
-+
-+ name_len = btrfs_dir_name_len(&path->nodes[0], di);
-+ data_len = btrfs_dir_data_len(&path->nodes[0], di);
-+
-+ WARN_ON(name_len > BTRFS_NAME_LEN);
-+
-+ filename = (char *)(path->nodes[0].data +
-+ (unsigned long)(di + 1));
-+ end_of_name = filename + name_len;
-+ /*
-+ * working around not null-terminated
-+ * directory names in btrfs: just
-+ * a short-term overwrite of the
-+ * cache with the following rollback
-+ * of the change.
-+ */
-+ tmp = *end_of_name;
-+ *end_of_name = 0;
-+ result = substring(*dirname, filename);
-+ *end_of_name = tmp;
-+#ifndef STAGE1_5
-+ if (do_possibilities) {
-+ if (result <= 0) {
-+ update_possibilities();
-+ *end_of_name = 0;
-+ print_a_completion(filename);
-+ *end_of_name = tmp;
-+ }
-+ }
-+ else
-+#endif
-+ if (result == 0) {
-+ btrfs_dir_item_key_to_cpu(&path->nodes[0],
-+ di, sd_key);
-+ goto found;
-+ }
-+ len = sizeof(*di) + name_len + data_len;
-+ di = (struct btrfs_dir_item *)((char *)di + len);
-+ cur += len;
-+ }
-+ }
-+#ifndef STAGE1_5
-+ if (print_possibilities < 0)
-+ return 1;
-+#endif
-+ errnum = ERR_FILE_NOT_FOUND;
-+ *rest = ch;
-+ return 0;
-+ found:
-+ *rest = ch;
-+ *dirname = rest;
-+ return 1;
-+}
-+
-+/*
-+ * ->dir_func().
-+ * Postcondition: on a non-zero return BTRFS_FS_INFO
-+ * contains the latest fs_root of file's subvolume.
-+ * BTRFS_FS_INFO points to a subvolume of a file we
-+ * were trying to look up.
-+ * BTRFS_FILE_INFO contains info of the file we were
-+ * trying to look up.
-+ */
-+
-+int btrfs_dir(char *dirname)
-+{
-+ int ret;
-+ int mode;
-+ u64 size;
-+ int linkcount = 0;
-+ char linkbuf[PATH_MAX];
-+
-+ struct btrfs_path *path;
-+ struct btrfs_root *root;
-+
-+ struct btrfs_key sd_key;
-+ struct btrfs_inode_item *sd;
-+ struct btrfs_key parent_sd_key;
-+
-+ root = BTRFS_FS_ROOT;
-+ path = btrfs_grab_path(FIRST_EXTERNAL_LOOKUP_POOL);
-+
-+ btrfs_set_root_dir_key(&sd_key);
-+ while (1) {
-+ struct extent_buffer *leaf;
-+ ret = aux_tree_lookup(root, &sd_key, path);
-+ if (ret)
-+ return 0;
-+ leaf = &path->nodes[0];
-+ sd = btrfs_item_ptr(leaf,
-+ path->slots[0],
-+ struct btrfs_inode_item);
-+ mode = btrfs_inode_mode(leaf, sd);
-+ size = btrfs_inode_size(leaf, sd);
-+ switch (btrfs_get_file_type(mode)) {
-+ case BTRFS_SYMLINK_FILE:
-+ ret = btrfs_follow_link(root,
-+ path,
-+ &dirname,
-+ linkbuf,
-+ &linkcount,
-+ sd);
-+ if (!ret)
-+ return 0;
-+ dirname = linkbuf;
-+ if (*dirname == '/')
-+ /* absolute name */
-+ btrfs_set_root_dir_key(&sd_key);
-+ else
-+ memcpy(&sd_key, &parent_sd_key,
-+ sizeof(sd_key));
-+ continue;
-+ case BTRFS_REGULAR_FILE:
-+ /*
-+ * normally we want to exit here
-+ */
-+ if (*dirname && !isspace (*dirname)) {
-+ errnum = ERR_BAD_FILETYPE;
-+ return 0;
-+ }
-+ filepos = 0;
-+ filemax = btrfs_inode_size(leaf, sd);
-+ btrfs_update_file_info(path);
-+ return 1;
-+ case BTRFS_DIRECTORY_FILE:
-+ memcpy(&parent_sd_key, &sd_key, sizeof(sd_key));
-+ ret = btrfs_de_index_by_name(root,
-+ path,
-+ &dirname,
-+ &sd_key);
-+ if (!ret)
-+ return 0;
-+#ifndef STAGE1_5
-+ if (print_possibilities < 0)
-+ return 1;
-+#endif
-+ /*
-+ * update fs_tree:
-+ * subvolume stuff goes here
-+ */
-+ ret = update_fs_root(root, &sd_key);
-+ if (ret)
-+ return 0;
-+ continue;
-+ case BTRFS_UNKNOWN_FILE:
-+ default:
-+ btrfs_msg("Btrfs: bad file type\n");
-+ errnum = ERR_BAD_FILETYPE;
-+ return 0;
-+ }
-+ }
-+}
-+
-+int btrfs_embed(int *start_sector, int needed_sectors)
-+{
-+ int ret;
-+ init_btrfs_info();
-+ init_btrfs_volatile_dev_cache();
-+
-+ ret = btrfs_find_super(BTRFS_VOLATILE_DEV_CACHE, NULL, NULL);
-+ if (ret)
-+ return 0;
-+ ret = btrfs_uptodate_super_copy(BTRFS_FS_INFO);
-+ if (ret)
-+ return 0;
-+ *start_sector = 1; /* reserve first sector for stage1 */
-+ return needed_sectors <=
-+ ((BTRFS_SUPER_INFO_OFFSET >> SECTOR_BITS) - 1);
-+}
-+#endif /* FSYS_BTRFS */
-+
-+/*
-+ Local variables:
-+ c-indentation-style: "K&R"
-+ mode-name: "LC"
-+ c-basic-offset: 8
-+ tab-width: 8
-+ fill-column: 80
-+ scroll-step: 1
-+ End:
-+*/
-diff -up grub-upstream.wip/stage2/Makefile.am.btrfs
grub-upstream.wip/stage2/Makefile.am
---- grub-upstream.wip/stage2/Makefile.am.btrfs 2012-03-20 05:06:49.000000000
+0000
-+++ grub-upstream.wip/stage2/Makefile.am 2012-03-20 05:07:09.000000000
+0000
-@@ -17,13 +17,13 @@ INCLUDES = -I$(top_srcdir)/stage1
- noinst_LIBRARIES = libgrub.a
- libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
- disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ffs.c fsys_iso9660.c \
-- fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
-+ fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_btrfs.c fsys_ufs2.c \
- fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c stage2.c \
- terminfo.c tparm.c graphics.c
- libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
- -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
- -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
-- -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
-+ -DFSYS_BTRFS=1 -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
- -DUSE_MD5_PASSWORDS=1 -DSUPPORT_SERIAL=1 -DSUPPORT_HERCULES=1
-
- # Stage 2 and Stage 1.5's.
-@@ -34,24 +34,26 @@ EXTRA_PROGRAMS = nbloader.exec pxeloader
- if DISKLESS_SUPPORT
- pkglib_DATA = stage2 stage2_eltorito e2fs_stage1_5 fat_stage1_5 \
- ffs_stage1_5 iso9660_stage1_5 jfs_stage1_5 minix_stage1_5 \
-- reiserfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 xfs_stage1_5 \
-- nbgrub pxegrub
-+ reiserfs_stage1_5 btrfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 \
-+ xfs_stage1_5 nbgrub pxegrub
- noinst_DATA = pre_stage2 start start_eltorito nbloader pxeloader diskless
- noinst_PROGRAMS = pre_stage2.exec start.exec start_eltorito.exec \
- e2fs_stage1_5.exec fat_stage1_5.exec ffs_stage1_5.exec \
- iso9660_stage1_5.exec jfs_stage1_5.exec minix_stage1_5.exec \
-- reiserfs_stage1_5.exec ufs2_stage1_5.exec vstafs_stage1_5.exec \
-- xfs_stage1_5.exec nbloader.exec pxeloader.exec diskless.exec
-+ reiserfs_stage1_5.exec btrfs_stage1_5.exec ufs2_stage1_5.exec \
-+ vstafs_stage1_5.exec xfs_stage1_5.exec nbloader.exec \
-+ pxeloader.exec diskless.exec
- else
- pkglib_DATA = stage2 stage2_eltorito e2fs_stage1_5 fat_stage1_5 \
- ffs_stage1_5 iso9660_stage1_5 jfs_stage1_5 minix_stage1_5 \
-- reiserfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 xfs_stage1_5
-+ reiserfs_stage1_5 btrfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 \
-+ xfs_stage1_5
- noinst_DATA = pre_stage2 start start_eltorito
- noinst_PROGRAMS = pre_stage2.exec start.exec start_eltorito.exec \
- e2fs_stage1_5.exec fat_stage1_5.exec ffs_stage1_5.exec \
- iso9660_stage1_5.exec jfs_stage1_5.exec minix_stage1_5.exec \
-- reiserfs_stage1_5.exec ufs2_stage1_5.exec vstafs_stage1_5.exec \
-- xfs_stage1_5.exec
-+ reiserfs_stage1_5.exec btrfs_stage1_5.exec ufs2_stage1_5.exec \
-+ vstafs_stage1_5.exec xfs_stage1_5.exec
- endif
- MOSTLYCLEANFILES = $(noinst_PROGRAMS)
-
-@@ -95,15 +97,17 @@ STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DN
- pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \
- cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
- fsys_fat.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
-- fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c gunzip.c \
-- hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c \
-- graphics.c
-+ fsys_reiserfs.c fsys_btrfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c \
-+ gunzip.c hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c \
-+ tparm.c graphics.c
- pre_stage2_exec_CFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_LDFLAGS = $(PRE_STAGE2_LINK)
-
- if NETBOOT_SUPPORT
--pre_stage2_exec_LDADD = ../netboot/libdrivers.a
-+pre_stage2_exec_LDADD = ../netboot/libdrivers.a -lgcc
-+else
-+pre_stage2_exec_LDADD = -lgcc
- endif
-
- if DISKLESS_SUPPORT
-@@ -197,6 +201,16 @@ reiserfs_stage1_5_exec_CCASFLAGS = $(STA
- -DNO_BLOCK_FILES=1
- reiserfs_stage1_5_exec_LDFLAGS = $(STAGE1_5_LINK)
-
-+# For btrfs_stage1_5 target.
-+btrfs_stage1_5_exec_SOURCES = start.S asm.S common.c char_io.c \
-+ disk_io.c stage1_5.c fsys_btrfs.c bios.c
-+btrfs_stage1_5_exec_CFLAGS = $(STAGE1_5_COMPILE) -DFSYS_BTRFS=1 \
-+ -DNO_BLOCK_FILES=1
-+btrfs_stage1_5_exec_CCASFLAGS = $(STAGE1_5_COMPILE) -DFSYS_BTRFS=1 \
-+ -DNO_BLOCK_FILES=1
-+btrfs_stage1_5_exec_LDFLAGS = $(STAGE1_5_LINK)
-+btrfs_stage1_5_exec_LDADD = -lgcc
-+
- # For vstafs_stage1_5 target.
- vstafs_stage1_5_exec_SOURCES = start.S asm.S common.c char_io.c \
- disk_io.c stage1_5.c fsys_vstafs.c bios.c
-@@ -240,7 +254,7 @@ diskless_exec_CFLAGS = $(STAGE2_COMPILE)
- diskless_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS) \
- -DSUPPORT_DISKLESS=1
- diskless_exec_LDFLAGS = $(PRE_STAGE2_LINK)
--diskless_exec_LDADD = ../netboot/libdrivers.a
-+diskless_exec_LDADD = ../netboot/libdrivers.a -lgcc
-
- diskless_size.h: diskless
- -rm -f $@
-diff -up grub-upstream.wip/stage2/shared.h.btrfs
grub-upstream.wip/stage2/shared.h
---- grub-upstream.wip/stage2/shared.h.btrfs 2012-03-20 05:06:49.000000000
+0000
-+++ grub-upstream.wip/stage2/shared.h 2012-03-20 05:07:09.000000000 +0000
-@@ -207,11 +207,12 @@ extern char *grub_scratch_mem;
- #define STAGE2_ID_FAT_STAGE1_5 3
- #define STAGE2_ID_MINIX_STAGE1_5 4
- #define STAGE2_ID_REISERFS_STAGE1_5 5
--#define STAGE2_ID_VSTAFS_STAGE1_5 6
--#define STAGE2_ID_JFS_STAGE1_5 7
--#define STAGE2_ID_XFS_STAGE1_5 8
--#define STAGE2_ID_ISO9660_STAGE1_5 9
--#define STAGE2_ID_UFS2_STAGE1_5 10
-+#define STAGE2_ID_BTRFS_STAGE1_5 6
-+#define STAGE2_ID_VSTAFS_STAGE1_5 7
-+#define STAGE2_ID_JFS_STAGE1_5 8
-+#define STAGE2_ID_XFS_STAGE1_5 9
-+#define STAGE2_ID_ISO9660_STAGE1_5 10
-+#define STAGE2_ID_UFS2_STAGE1_5 11
-
- #ifndef STAGE1_5
- # define STAGE2_ID STAGE2_ID_STAGE2
-@@ -226,6 +227,8 @@ extern char *grub_scratch_mem;
- # define STAGE2_ID STAGE2_ID_MINIX_STAGE1_5
- # elif defined(FSYS_REISERFS)
- # define STAGE2_ID STAGE2_ID_REISERFS_STAGE1_5
-+# elif defined(FSYS_BTRFS)
-+# define STAGE2_ID STAGE2_ID_BTRFS_STAGE1_5
- # elif defined(FSYS_VSTAFS)
- # define STAGE2_ID STAGE2_ID_VSTAFS_STAGE1_5
- # elif defined(FSYS_JFS)
diff --git a/stubdom/grub.patches/70compiler_warnings.diff
b/stubdom/grub.patches/70compiler_warnings.diff
deleted file mode 100644
index 15181fcfaa..0000000000
--- a/stubdom/grub.patches/70compiler_warnings.diff
+++ /dev/null
@@ -1,45 +0,0 @@
-[ 1436s] ../grub-upstream/netboot/fsys_tftp.c:213: warning: operation on
'block' may be undefined
-[ 1437s] ../grub-upstream/netboot/main.c:444: warning: operation on 'block'
may be undefined
-
-[ 1234s] E: xen sequence-point ../grub-upstream/netboot/fsys_tftp.c:213
-[ 1234s] E: xen sequence-point ../grub-upstream/netboot/main.c:444
-
----
- netboot/fsys_tftp.c | 5 ++++-
- netboot/main.c | 5 ++++-
- 2 files changed, 8 insertions(+), 2 deletions(-)
-
-Index: grub-0.97/netboot/fsys_tftp.c
-===================================================================
---- grub-0.97.orig/netboot/fsys_tftp.c
-+++ grub-0.97/netboot/fsys_tftp.c
-@@ -209,8 +209,11 @@ buf_fill (int abort)
- break;
-
- if ((block || bcounter) && (block != prevblock + (unsigned short) 1))
-+ {
-+ block = prevblock;
- /* Block order should be continuous */
-- tp.u.ack.block = htons (block = prevblock);
-+ tp.u.ack.block = htons (block);
-+ }
-
- /* Should be continuous. */
- tp.opcode = abort ? htons (TFTP_ERROR) : htons (TFTP_ACK);
-Index: grub-0.97/netboot/main.c
-===================================================================
---- grub-0.97.orig/netboot/main.c
-+++ grub-0.97/netboot/main.c
-@@ -440,8 +440,11 @@ tftp (const char *name, int (*fnc) (unsi
- break;
-
- if ((block || bcounter) && (block != prevblock + 1))
-+ {
-+ block = prevblock;
- /* Block order should be continuous */
-- tp.u.ack.block = htons (block = prevblock);
-+ tp.u.ack.block = htons (block);
-+ }
-
- /* Should be continuous. */
- tp.opcode = htons (TFTP_ACK);
diff --git a/stubdom/grub.patches/99minios b/stubdom/grub.patches/99minios
deleted file mode 100644
index d9b19138fd..0000000000
--- a/stubdom/grub.patches/99minios
+++ /dev/null
@@ -1,1570 +0,0 @@
-Index: grub/stage2/builtins.c
-===================================================================
---- grub.orig/stage2/builtins.c 2008-06-16 15:18:14.649009000 +0100
-+++ grub/stage2/builtins.c 2008-06-16 15:18:14.719009000 +0100
-@@ -45,8 +45,10 @@
- #ifdef GRUB_UTIL
- # include <device.h>
- #else /* ! GRUB_UTIL */
-+#ifndef __MINIOS
- # include <apic.h>
- # include <smp-imps.h>
-+#endif
- #endif /* ! GRUB_UTIL */
-
- #ifdef USE_MD5_PASSWORDS
-@@ -246,11 +248,13 @@
- boot_func (char *arg, int flags)
- {
- struct term_entry *prev_term = current_term;
-+#ifndef __MINIOS__
- /* Clear the int15 handler if we can boot the kernel successfully.
- This assumes that the boot code never fails only if KERNEL_TYPE is
- not KERNEL_TYPE_NONE. Is this assumption is bad? */
- if (kernel_type != KERNEL_TYPE_NONE)
- unset_int15_handler ();
-+#endif
-
- /* if our terminal needed initialization, we should shut it down
- * before booting the kernel, but we want to save what it was so
-@@ -261,13 +265,21 @@
- current_term = term_table; /* assumption: console is first */
- }
-
-+#ifndef __MINIOS__
- #ifdef SUPPORT_NETBOOT
- /* Shut down the networking. */
- cleanup_net ();
- #endif
-+#endif
-
- switch (kernel_type)
- {
-+#ifdef __MINIOS__
-+ case KERNEL_TYPE_PV:
-+ /* Paravirtualized */
-+ pv_boot();
-+ break;
-+#else
- case KERNEL_TYPE_FREEBSD:
- case KERNEL_TYPE_NETBSD:
- /* *BSD */
-@@ -319,6 +331,7 @@
- multi_boot ((int) entry_addr, (int) &mbi);
- break;
-
-+#endif
- default:
- errnum = ERR_BOOT_COMMAND;
- return 1;
-@@ -1123,6 +1136,7 @@
- };
-
-
-+#ifndef __MINIOS__
- /* displayapm */
- static int
- displayapm_func (char *arg, int flags)
-@@ -1163,8 +1177,10 @@
- "displayapm",
- "Display APM BIOS information."
- };
-+#endif
-
-
-+#ifndef __MINIOS__
- /* displaymem */
- static int
- displaymem_func (char *arg, int flags)
-@@ -1218,6 +1234,7 @@
- "Display what GRUB thinks the system address space map of the"
- " machine is, including all regions of physical RAM installed."
- };
-+#endif
-
-
- /* dump FROM TO */
-@@ -1280,6 +1297,7 @@
- #endif /* GRUB_UTIL */
-
-
-+#ifndef __MINIOS__
- static char embed_info[32];
- /* embed */
- /* Embed a Stage 1.5 in the first cylinder after MBR or in the
-@@ -1413,6 +1431,7 @@
- " is a drive, or in the \"bootloader\" area if DEVICE is a FFS partition."
- " Print the number of sectors which STAGE1_5 occupies if successful."
- };
-+#endif
-
-
- /* fallback */
-@@ -1956,6 +1975,7 @@
- #endif /* SUPPORT_NETBOOT */
-
-
-+#ifndef __MINIOS__
- /* impsprobe */
- static int
- impsprobe_func (char *arg, int flags)
-@@ -1982,6 +2002,7 @@
- " configuration table and boot the various CPUs which are found into"
- " a tight loop."
- };
-+#endif
-
-
- /* initrd */
-@@ -1992,6 +2013,7 @@
- {
- case KERNEL_TYPE_LINUX:
- case KERNEL_TYPE_BIG_LINUX:
-+ case KERNEL_TYPE_PV:
- if (! load_initrd (arg))
- return 1;
- break;
-@@ -2015,6 +2037,7 @@
- };
-
-
-+#ifndef __MINIOS__
- /* install */
- static int
- install_func (char *arg, int flags)
-@@ -2555,8 +2578,10 @@
- " for LBA mode. If the option `--stage2' is specified, rewrite the Stage"
- " 2 via your OS's filesystem instead of the raw device."
- };
-+#endif
-
-
-+#ifndef __MINIOS__
- /* ioprobe */
- static int
- ioprobe_func (char *arg, int flags)
-@@ -2598,6 +2623,7 @@
- "ioprobe DRIVE",
- "Probe I/O ports used for the drive DRIVE."
- };
-+#endif
-
- /* print */
- static int
-@@ -2910,6 +2910,7 @@
- switch (kernel_type)
- {
- case KERNEL_TYPE_MULTIBOOT:
-+ case KERNEL_TYPE_PV:
- if (mb_cmdline + len + 1 > (char *) MB_CMDLINE_BUF + MB_CMDLINE_BUFLEN)
- {
- errnum = ERR_WONT_FIT;
-@@ -3776,6 +3802,7 @@
- };
-
-
-+#ifndef __MINIOS__
- #ifdef SUPPORT_SERIAL
- /* serial */
- static int
-@@ -3927,8 +3954,10 @@
- " default values are COM1, 9600, 8N1."
- };
- #endif /* SUPPORT_SERIAL */
-+#endif
-
-
-+#ifndef __MINIOS__
- /* setkey */
- struct keysym
- {
-@@ -4174,8 +4203,10 @@
- " is a digit), and delete. If no argument is specified, reset key"
- " mappings."
- };
-+#endif
-
-
-+#ifndef __MINIOS__
- /* setup */
- static int
- setup_func (char *arg, int flags)
-@@ -4484,6 +4515,7 @@
- " partition where GRUB images reside, specify the option `--stage2'"
- " to tell GRUB the file name under your OS."
- };
-+#endif
-
-
- #if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES) ||
defined(SUPPORT_GRAPHICS)
-@@ -4788,6 +4820,7 @@
- #endif /* SUPPORT_SERIAL */
-
-
-+#ifndef __MINIOS__
- /* testload */
- static int
- testload_func (char *arg, int flags)
-@@ -4874,8 +4907,10 @@
- " consistent offset error. If this test succeeds, then a good next"
- " step is to try loading a kernel."
- };
-+#endif
-
-
-+#ifndef __MINIOS__
- /* testvbe MODE */
- static int
- testvbe_func (char *arg, int flags)
-@@ -4979,6 +5014,7 @@
- "testvbe MODE",
- "Test the VBE mode MODE. Hit any key to return."
- };
-+#endif
-
-
- #ifdef SUPPORT_NETBOOT
-@@ -5075,6 +5111,7 @@
- };
-
-
-+#ifndef __MINIOS__
- /* uppermem */
- static int
- uppermem_func (char *arg, int flags)
-@@ -5095,8 +5132,10 @@
- "Force GRUB to assume that only KBYTES kilobytes of upper memory are"
- " installed. Any system address range maps are discarded."
- };
-+#endif
-
-
-+#ifndef __MINIOS__
- /* vbeprobe */
- static int
- vbeprobe_func (char *arg, int flags)
-@@ -5203,6 +5242,7 @@
- "Probe VBE information. If the mode number MODE is specified, show only"
- " the information about only the mode."
- };
-+#endif
-
-
- /* The table of builtin commands. Sorted in dictionary order. */
-@@ -5233,12 +5273,16 @@
- #ifdef SUPPORT_NETBOOT
- &builtin_dhcp,
- #endif /* SUPPORT_NETBOOT */
-+#ifndef __MINIOS__
- &builtin_displayapm,
- &builtin_displaymem,
-+#endif
- #ifdef GRUB_UTIL
- &builtin_dump,
- #endif /* GRUB_UTIL */
-+#ifndef __MINIOS__
- &builtin_embed,
-+#endif
- &builtin_fallback,
- &builtin_find,
- #ifdef SUPPORT_GRAPHICS
-@@ -5253,10 +5297,14 @@
- #ifdef SUPPORT_NETBOOT
- &builtin_ifconfig,
- #endif /* SUPPORT_NETBOOT */
-+#ifndef __MINIOS__
- &builtin_impsprobe,
-+#endif
- &builtin_initrd,
-+#ifndef __MINIOS__
- &builtin_install,
- &builtin_ioprobe,
-+#endif
- &builtin_kernel,
- &builtin_lock,
- &builtin_makeactive,
-@@ -5283,11 +5331,13 @@
- &builtin_root,
- &builtin_rootnoverify,
- &builtin_savedefault,
-+#ifndef __MINIOS__
- #ifdef SUPPORT_SERIAL
- &builtin_serial,
- #endif /* SUPPORT_SERIAL */
- &builtin_setkey,
- &builtin_setup,
-+#endif
- #ifdef SUPPORT_GRAPHICS
- &builtin_shade,
- &builtin_splashimage,
-@@ -5298,16 +5348,20 @@
- #ifdef SUPPORT_SERIAL
- &builtin_terminfo,
- #endif /* SUPPORT_SERIAL */
-+#ifndef __MINIOS__
- &builtin_testload,
- &builtin_testvbe,
-+#endif
- #ifdef SUPPORT_NETBOOT
- &builtin_tftpserver,
- #endif /* SUPPORT_NETBOOT */
- &builtin_timeout,
- &builtin_title,
- &builtin_unhide,
-+#ifndef __MINIOS__
- &builtin_uppermem,
- &builtin_vbeprobe,
-+#endif
- #ifdef SUPPORT_GRAPHICS
- &builtin_viewport,
- #endif
-Index: grub/stage2/char_io.c
-===================================================================
---- grub.orig/stage2/char_io.c 2008-06-16 15:18:14.516009000 +0100
-+++ grub/stage2/char_io.c 2008-06-16 15:18:14.726009000 +0100
-@@ -20,6 +20,7 @@
-
- #include <shared.h>
- #include <term.h>
-+#include <stdarg.h>
-
- #ifdef SUPPORT_HERCULES
- # include <hercules.h>
-@@ -36,6 +37,7 @@
- #ifndef STAGE1_5
- struct term_entry term_table[] =
- {
-+#ifdef SUPPORT_CONSOLE
- {
- "console",
- 0,
-@@ -52,6 +54,7 @@
- 0,
- 0
- },
-+#endif
- #ifdef SUPPORT_SERIAL
- {
- "serial",
-@@ -131,9 +134,9 @@
- }
-
- char *
--convert_to_ascii (char *buf, int c,...)
-+convert_to_ascii (char *buf, int c, int _num)
- {
-- unsigned long num = *((&c) + 1), mult = 10;
-+ unsigned long num = _num, mult = 10;
- char *ptr = buf;
-
- #ifndef STAGE1_5
-@@ -182,11 +185,11 @@
- void
- grub_printf (const char *format,...)
- {
-- int *dataptr = (int *) &format;
-+ va_list ap;
- char c, str[16];
--
-- dataptr++;
-
-+ va_start(ap, format);
-+
- while ((c = *(format++)) != 0)
- {
- if (c != '%')
-@@ -200,21 +203,32 @@
- case 'X':
- #endif
- case 'u':
-- *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
-+ {
-+ unsigned i = va_arg(ap, unsigned);
-+ *convert_to_ascii (str, c, i) = 0;
- grub_putstr (str);
- break;
-+ }
-
- #ifndef STAGE1_5
- case 'c':
-- grub_putchar ((*(dataptr++)) & 0xff);
-+ {
-+ int c = va_arg(ap, int);
-+ grub_putchar (c & 0xff);
- break;
-+ }
-
- case 's':
-- grub_putstr ((char *) *(dataptr++));
-+ {
-+ char *s = va_arg(ap, char*);
-+ grub_putstr (s);
- break;
-+ }
- #endif
- }
- }
-+
-+ va_end(ap);
- }
-
- #ifndef STAGE1_5
-@@ -223,11 +237,11 @@
- {
- /* XXX hohmuth
- ugly hack -- should unify with printf() */
-- int *dataptr = (int *) &format;
-+ va_list ap;
- char c, *ptr, str[16];
- char *bp = buffer;
-
-- dataptr++;
-+ va_start(ap, format);
-
- while ((c = *format++) != 0)
- {
-@@ -237,20 +251,27 @@
- switch (c = *(format++))
- {
- case 'd': case 'u': case 'x':
-- *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
-+ {
-+ unsigned i = va_arg(ap, unsigned);
-+ *convert_to_ascii (str, c, i) = 0;
-
- ptr = str;
-
- while (*ptr)
- *bp++ = *(ptr++); /* putchar(*(ptr++)); */
- break;
-+ }
-
-- case 'c': *bp++ = (*(dataptr++))&0xff;
-+ case 'c':
-+ {
-+ int c = va_arg(ap, int);
-+ *bp++ = c&0xff;
- /* putchar((*(dataptr++))&0xff); */
- break;
-+ }
-
- case 's':
-- ptr = (char *) (*(dataptr++));
-+ ptr = va_arg(ap, char *);
-
- while ((c = *ptr++) != 0)
- *bp++ = c; /* putchar(c); */
-@@ -258,6 +279,8 @@
- }
- }
-
-+ va_end(ap);
-+
- *bp = 0;
- return bp - buffer;
- }
-@@ -1263,12 +1286,14 @@
- return ! errnum;
- #endif /* GRUB_UTIL */
-
-+#ifndef __MINIOS__
- if ((addr < RAW_ADDR (0x1000))
- || (addr < RAW_ADDR (0x100000)
- && RAW_ADDR (mbi.mem_lower * 1024) < (addr + len))
- || (addr >= RAW_ADDR (0x100000)
- && RAW_ADDR (mbi.mem_upper * 1024) < ((addr - 0x100000) + len)))
- errnum = ERR_WONT_FIT;
-+#endif
-
- return ! errnum;
- }
-@@ -1342,7 +1367,7 @@
- }
- #endif /* ! STAGE1_5 */
-
--#ifndef GRUB_UTIL
-+#if !defined(GRUB_UTIL) && !defined(__MINIOS__)
- # undef memcpy
- /* GCC emits references to memcpy() for struct copies etc. */
- void *memcpy (void *dest, const void *src, int n) __attribute__ ((alias
("grub_memmove")));
-Index: grub/stage2/disk_io.c
-===================================================================
---- grub.orig/stage2/disk_io.c 2008-06-16 15:18:03.327932000 +0100
-+++ grub/stage2/disk_io.c 2008-06-16 15:18:14.733009000 +0100
-@@ -130,7 +130,14 @@
- static inline unsigned long
- log2 (unsigned long word)
- {
-- asm volatile ("bsfl %1,%0"
-+ asm volatile ("bsf"
-+#ifdef __i386__
-+ "l"
-+#endif
-+#ifdef __x86_64__
-+ "q"
-+#endif
-+ " %1,%0"
- : "=r" (word)
- : "r" (word));
- return word;
-Index: grub/stage2/fsys_fat.c
-===================================================================
---- grub.orig/stage2/fsys_fat.c 2008-06-16 15:18:03.337934000 +0100
-+++ grub/stage2/fsys_fat.c 2008-06-16 15:18:14.737009000 +0100
-@@ -57,7 +57,14 @@
- static __inline__ unsigned long
- log2 (unsigned long word)
- {
-- __asm__ ("bsfl %1,%0"
-+ __asm__ ("bsf"
-+#ifdef __i386__
-+ "l"
-+#endif
-+#ifdef __x86_64__
-+ "q"
-+#endif
-+ " %1,%0"
- : "=r" (word)
- : "r" (word));
- return word;
-Index: grub/stage2/pc_slice.h
-===================================================================
---- grub.orig/stage2/pc_slice.h 2008-06-16 15:18:03.347932000 +0100
-+++ grub/stage2/pc_slice.h 2008-06-16 15:18:14.746009000 +0100
-@@ -38,50 +38,50 @@
- */
-
- #define PC_MBR_CHECK_SIG(mbr_ptr) \
-- ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) \
-+ ( *( (unsigned short *) (((long) mbr_ptr) + PC_MBR_SIG_OFFSET) ) \
- == PC_MBR_SIGNATURE )
-
- #define PC_MBR_SIG(mbr_ptr) \
-- ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) )
-+ ( *( (unsigned short *) (((long) mbr_ptr) + PC_MBR_SIG_OFFSET) ) )
-
- #define PC_SLICE_FLAG(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET \
- + (part << 4)) ) )
-
- #define PC_SLICE_HEAD(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 1 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 1 \
- + (part << 4)) ) )
-
- #define PC_SLICE_SEC(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 2 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 2 \
- + (part << 4)) ) )
-
- #define PC_SLICE_CYL(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 3 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 3 \
- + (part << 4)) ) )
-
- #define PC_SLICE_TYPE(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 4 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 4 \
- + (part << 4)) ) )
-
- #define PC_SLICE_EHEAD(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 5 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 5 \
- + (part << 4)) ) )
-
- #define PC_SLICE_ESEC(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 6 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 6 \
- + (part << 4)) ) )
-
- #define PC_SLICE_ECYL(mbr_ptr, part) \
-- ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 7 \
-+ ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 7 \
- + (part << 4)) ) )
-
- #define PC_SLICE_START(mbr_ptr, part) \
-- ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 8 \
-+ ( *( (unsigned long *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 8 \
- + (part << 4)) ) )
-
- #define PC_SLICE_LENGTH(mbr_ptr, part) \
-- ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 12 \
-+ ( *( (unsigned long *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 12 \
- + (part << 4)) ) )
-
-
-Index: grub/stage2/shared.h
-===================================================================
---- grub.orig/stage2/shared.h 2008-06-16 15:18:14.537009000 +0100
-+++ grub/stage2/shared.h 2008-06-17 14:25:08.443906000 +0100
-@@ -39,6 +39,10 @@
- extern char *grub_scratch_mem;
- # define RAW_ADDR(x) ((x) + (int) grub_scratch_mem)
- # define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4)
-+#elif defined(__MINIOS__)
-+extern char grub_scratch_mem[];
-+# define RAW_ADDR(x) ((x) + (int) grub_scratch_mem)
-+# define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4)
- #else
- # define RAW_ADDR(x) (x)
- # define RAW_SEG(x) (x)
-@@ -707,7 +711,9 @@
-
- /* Halt the system, using APM if possible. If NO_APM is true, don't use
- APM even if it is available. */
-+#ifndef __MINIOS__
- void grub_halt (int no_apm) __attribute__ ((noreturn));
-+#endif
-
- /* Copy MAP to the drive map and set up int13_handler. */
- void set_int13_handler (unsigned short *map);
-@@ -857,7 +863,8 @@
- KERNEL_TYPE_BIG_LINUX, /* Big Linux. */
- KERNEL_TYPE_FREEBSD, /* FreeBSD. */
- KERNEL_TYPE_NETBSD, /* NetBSD. */
-- KERNEL_TYPE_CHAINLOADER /* Chainloader. */
-+ KERNEL_TYPE_CHAINLOADER, /* Chainloader. */
-+ KERNEL_TYPE_PV /* Paravirtualized. */
- }
- kernel_t;
-
-@@ -890,7 +897,7 @@
- int grub_strlen (const char *str);
- char *grub_strcpy (char *dest, const char *src);
-
--#ifndef GRUB_UTIL
-+#if !defined(GRUB_UTIL) && !defined(__MINIOS__)
- typedef unsigned long grub_jmp_buf[6];
- #else
- /* In the grub shell, use the libc jmp_buf instead. */
-@@ -898,7 +905,7 @@
- # define grub_jmp_buf jmp_buf
- #endif
-
--#ifdef GRUB_UTIL
-+#if defined(GRUB_UTIL) || defined(__MINIOS__)
- # define grub_setjmp setjmp
- # define grub_longjmp longjmp
- #else /* ! GRUB_UTIL */
-@@ -914,7 +921,7 @@
- /* misc */
- void init_page (void);
- void print_error (void);
--char *convert_to_ascii (char *buf, int c, ...);
-+char *convert_to_ascii (char *buf, int c, int num);
- int get_cmdline (char *prompt, char *cmdline, int maxlen,
- int echo_char, int history);
- int substring (const char *s1, const char *s2);
-Index: grub/netboot/etherboot.h
-===================================================================
---- grub.orig/netboot/etherboot.h 2008-06-16 15:18:03.446934000 +0100
-+++ grub/netboot/etherboot.h 2008-06-16 15:18:14.760009000 +0100
-@@ -246,7 +246,7 @@
-
- typedef struct
- {
-- unsigned long s_addr;
-+ unsigned int s_addr;
- }
- in_addr;
-
-@@ -302,7 +302,7 @@
- char bp_htype;
- char bp_hlen;
- char bp_hops;
-- unsigned long bp_xid;
-+ unsigned int bp_xid;
- unsigned short bp_secs;
- unsigned short unused;
- in_addr bp_ciaddr;
-@@ -411,25 +411,25 @@
-
- struct
- {
-- long id;
-- long type;
-- long rpcvers;
-- long prog;
-- long vers;
-- long proc;
-- long data[1];
-+ int id;
-+ int type;
-+ int rpcvers;
-+ int prog;
-+ int vers;
-+ int proc;
-+ int data[1];
- }
- call;
-
- struct
- {
-- long id;
-- long type;
-- long rstatus;
-- long verifier;
-- long v2;
-- long astatus;
-- long data[1];
-+ int id;
-+ int type;
-+ int rstatus;
-+ int verifier;
-+ int v2;
-+ int astatus;
-+ int data[1];
- }
- reply;
- }
-@@ -517,7 +517,9 @@
-
- /* misc.c */
- extern void twiddle (void);
-+#ifndef __MINIOS__
- extern void sleep (int secs);
-+#endif
- extern int getdec (char **s);
- extern void etherboot_printf (const char *, ...);
- extern int etherboot_sprintf (char *, const char *, ...);
-Index: grub/stage2/common.c
-===================================================================
---- grub.orig/stage2/common.c 2008-06-16 15:18:03.366934000 +0100
-+++ grub/stage2/common.c 2008-06-16 15:18:14.764009000 +0100
-@@ -137,6 +137,7 @@
- }
- #endif /* ! STAGE1_5 */
-
-+#ifndef __MINIOS__
- /* This queries for BIOS information. */
- void
- init_bios_info (void)
-@@ -335,3 +336,4 @@
- /* Start main routine here. */
- cmain ();
- }
-+#endif
-Index: grub/stage2/serial.c
-===================================================================
---- grub.orig/stage2/serial.c 2008-06-16 15:18:03.376934000 +0100
-+++ grub/stage2/serial.c 2008-06-16 15:18:14.769009000 +0100
-@@ -37,7 +37,7 @@
-
- /* Hardware-dependent definitions. */
-
--#ifndef GRUB_UTIL
-+#if !defined(GRUB_UTIL) && !defined(__MINIOS__)
- /* The structure for speed vs. divisor. */
- struct divisor
- {
-@@ -222,6 +222,8 @@
- {('3' | ('~' << 8)), 4},
- {('5' | ('~' << 8)), 7},
- {('6' | ('~' << 8)), 3},
-+ {('7' | ('~' << 8)), 1},
-+ {('8' | ('~' << 8)), 5},
- };
-
- /* The buffer must start with ``ESC [''. */
-Index: grub/stage2/tparm.c
-===================================================================
---- grub.orig/stage2/tparm.c 2008-06-16 15:18:03.390933000 +0100
-+++ grub/stage2/tparm.c 2008-06-16 15:18:14.774010000 +0100
-@@ -48,6 +48,7 @@
- #include "shared.h"
-
- #include "tparm.h"
-+#include <stdarg.h>
-
- /*
- * Common/troublesome character definitions
-@@ -320,7 +321,7 @@
- #define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
-
- static inline char *
--tparam_internal(const char *string, int *dataptr)
-+tparam_internal(const char *string, va_list ap)
- {
- #define NUM_VARS 26
- char *p_is_s[9];
-@@ -461,9 +462,9 @@
- * a char* and an int may not be the same size on the stack.
- */
- if (p_is_s[i] != 0) {
-- p_is_s[i] = (char *)(*(dataptr++));
-+ p_is_s[i] = va_arg(ap, char *);
- } else {
-- param[i] = (int)(*(dataptr++));
-+ param[i] = va_arg(ap, int);
- }
- }
-
-@@ -716,11 +717,13 @@
- grub_tparm(const char *string,...)
- {
- char *result;
-- int *dataptr = (int *) &string;
-+ va_list ap;
-
-- dataptr++;
-+ va_start(ap, string);
-
-- result = tparam_internal(string, dataptr);
-+ result = tparam_internal(string, ap);
-+
-+ va_end(ap);
-
- return result;
- }
-Index: grub/stage2/fsys_iso9660.c
-===================================================================
---- grub.orig/stage2/fsys_iso9660.c 2008-06-16 15:18:03.400933000 +0100
-+++ grub/stage2/fsys_iso9660.c 2008-06-16 15:18:14.779009000 +0100
-@@ -59,7 +59,14 @@
- static inline unsigned long
- log2 (unsigned long word)
- {
-- asm volatile ("bsfl %1,%0"
-+ asm volatile ("bsf"
-+#ifdef __i386__
-+ "l"
-+#endif
-+#ifdef __x86_64__
-+ "q"
-+#endif
-+ " %1,%0"
- : "=r" (word)
- : "r" (word));
- return word;
-Index: grub/stage2/fsys_reiserfs.c
-===================================================================
---- grub.orig/stage2/fsys_reiserfs.c 2008-06-16 15:18:03.410933000 +0100
-+++ grub/stage2/fsys_reiserfs.c 2008-06-20 18:33:52.002100000 +0100
-@@ -224,8 +224,8 @@
-
- struct disk_child
- {
-- unsigned long dc_block_number; /* Disk child's block
number. */
-- unsigned short dc_size; /* Disk child's
used space. */
-+ __u32 dc_block_number; /* Disk child's block number. */
-+ __u16 dc_size; /* Disk child's used space. */
- };
-
- #define DC_SIZE (sizeof (struct disk_child))
-@@ -369,7 +369,14 @@
- static __inline__ unsigned long
- log2 (unsigned long word)
- {
-- __asm__ ("bsfl %1,%0"
-+ __asm__ ("bsf"
-+#ifdef __i386__
-+ "l"
-+#endif
-+#ifdef __x86_64__
-+ "q"
-+#endif
-+ " %1,%0"
- : "=r" (word)
- : "r" (word));
- return word;
-Index: grub/netboot/misc.c
-===================================================================
---- grub.orig/netboot/misc.c 2008-06-16 15:18:03.456934000 +0100
-+++ grub/netboot/misc.c 2008-06-16 15:18:14.790009000 +0100
-@@ -21,7 +21,9 @@
-
- #define GRUB 1
- #include <etherboot.h>
-+#include <stdarg.h>
-
-+#ifndef __MINIOS__
- void
- sleep (int secs)
- {
-@@ -30,6 +32,7 @@
- while (currticks () < tmo)
- ;
- }
-+#endif
-
- void
- twiddle (void)
-@@ -71,7 +74,7 @@
- Note: width specification not supported
- **************************************************************************/
- static int
--etherboot_vsprintf (char *buf, const char *fmt, const int *dp)
-+etherboot_vsprintf (char *buf, const char *fmt, va_list ap)
- {
- char *p, *s;
-
-@@ -86,7 +89,7 @@
-
- if (*++fmt == 's')
- {
-- for (p = (char *) *dp++; *p != '\0'; p++)
-+ for (p = va_arg(ap, char *); *p != '\0'; p++)
- buf ? *s++ = *p : grub_putchar (*p);
- }
- else
-@@ -121,11 +124,9 @@
- if ((*fmt | 0x20) == 'x')
- {
- /* With x86 gcc, sizeof(long) == sizeof(int) */
-- const long *lp = (const long *) dp;
-- long h = *lp++;
-+ long h = va_arg(ap, int);
- int ncase = (*fmt & 0x20);
-
-- dp = (const int *) lp;
- if (alt)
- {
- *q++ = '0';
-@@ -136,7 +137,7 @@
- }
- else if (*fmt == 'd')
- {
-- int i = *dp++;
-+ int i = va_arg(ap, int);
- char *r;
-
- if (i < 0)
-@@ -171,10 +172,8 @@
- unsigned char c[4];
- }
- u;
-- const long *lp = (const long *) dp;
-
-- u.l = *lp++;
-- dp = (const int *) lp;
-+ u.l = va_arg(ap, int);
-
- for (r = &u.c[0]; r < &u.c[4]; ++r)
- q += etherboot_sprintf (q, "%d.", *r);
-@@ -184,7 +183,7 @@
- else if (*fmt == '!')
- {
- char *r;
-- p = (char *) *dp++;
-+ p = va_arg(ap, char *);
-
- for (r = p + ETH_ALEN; p < r; ++p)
- q += etherboot_sprintf (q, "%hhX:", *p);
-@@ -192,7 +191,7 @@
- --q;
- }
- else if (*fmt == 'c')
-- *q++ = *dp++;
-+ *q++ = va_arg(ap, int);
- else
- *q++ = *fmt;
-
-@@ -211,13 +210,21 @@
- int
- etherboot_sprintf (char *buf, const char *fmt, ...)
- {
-- return etherboot_vsprintf (buf, fmt, ((const int *) &fmt) + 1);
-+ va_list ap;
-+ int ret;
-+ va_start(ap, fmt);
-+ ret = etherboot_vsprintf (buf, fmt, ap);
-+ va_end(ap);
-+ return ret;
- }
-
- void
- etherboot_printf (const char *fmt, ...)
- {
-- (void) etherboot_vsprintf (0, fmt, ((const int *) &fmt) + 1);
-+ va_list ap;
-+ va_start(ap, fmt);
-+ etherboot_vsprintf (0, fmt, ap);
-+ va_end(ap);
- }
-
- int
-Index: grub/netboot/main.c
-===================================================================
---- grub.orig/netboot/main.c 2008-06-16 15:18:03.470932000 +0100
-+++ grub/netboot/main.c 2008-06-16 15:18:14.797009000 +0100
-@@ -55,7 +55,7 @@
- static int vendorext_isvalid;
- static unsigned long netmask;
- static struct bootpd_t bootp_data;
--static unsigned long xid;
-+static unsigned int xid;
-
- #define BOOTP_DATA_ADDR (&bootp_data)
-
-@@ -778,7 +778,7 @@
-
- arpreply = (struct arprequest *) &nic.packet[ETH_HLEN];
-
-- if (arpreply->opcode == htons (ARP_REPLY)
-+ if (arpreply->opcode == htons (ARP_REPLY) && ptr
- && ! grub_memcmp (arpreply->sipaddr, ptr, sizeof (in_addr))
- && type == AWAIT_ARP)
- {
-@@ -827,7 +827,7 @@
- {
- arpreply = (struct arprequest *) &nic.packet[ETH_HLEN];
-
-- if (arpreply->opcode == htons (RARP_REPLY)
-+ if (arpreply->opcode == htons (RARP_REPLY) && ptr
- && ! grub_memcmp (arpreply->thwaddr, ptr, ETH_ALEN))
- {
- grub_memmove ((char *) arptable[ARP_SERVER].node,
-@@ -1135,7 +1135,7 @@
- long
- rfc2131_sleep_interval (int base, int exp)
- {
-- static long seed = 0;
-+ static unsigned seed = 0;
- long q;
- unsigned long tmo;
-
-Index: grub/stage2/graphics.c
-===================================================================
---- grub.orig/stage2/graphics.c 2008-06-16 15:18:14.524009000 +0100
-+++ grub/stage2/graphics.c 2008-06-17 14:29:05.204328000 +0100
-@@ -30,7 +30,29 @@
- #include <shared.h>
- #include <graphics.h>
-
-+#ifdef __MINIOS__
-+#include <stdint.h>
-+typedef uint8_t Bit8u;
-+#include <vgafonts.h>
-+#include <fbfront.h>
-+#include <malloc.h>
-+#define set_int1c_handler() (void)0
-+#define unset_int1c_handler() (void)0
-+static uint32_t *VIDEOMEM;
-+static struct fbfront_dev *fb_dev;
-+static uint32_t palette[17];
-+short cursorX, cursorY;
-+/* TODO: blink */
-+uint32_t cursorBuf32[16*8];
-+#define WIDTH 640
-+#define HEIGHT 480
-+#define DEPTH 32
-+#define RAMSIZE (WIDTH * HEIGHT * (DEPTH / 8))
-+#else
-+#define fbfront_update(dev, x, y, w, h) (void)0
- int saved_videomode;
-+#endif
-+
- unsigned char *font8x16;
-
- int graphics_inited = 0;
-@@ -38,11 +60,15 @@
-
- int shade = 1, no_cursor = 0;
-
-+#ifdef __MINIOS__
-+uint32_t VSHADOW[RAMSIZE];
-+#else
- #define VSHADOW VSHADOW1
- unsigned char VSHADOW1[38400];
- unsigned char VSHADOW2[38400];
- unsigned char VSHADOW4[38400];
- unsigned char VSHADOW8[38400];
-+#endif
-
- /* define the default viewable area */
- int view_x0 = 0;
-@@ -129,6 +155,8 @@
- count_lines = k;
-
- no_scroll = 0;
-+
-+ fbfront_update(fb_dev, view_x0 * 8, view_y0 * 16, (view_x1 - view_x0) *
8, (view_y1 - view_y0) * 16);
- }
-
- /* Set the splash image */
-@@ -154,17 +182,29 @@
- int graphics_init()
- {
- if (!graphics_inited) {
-+#ifdef __MINIOS__
-+ VIDEOMEM = memalign(PAGE_SIZE, RAMSIZE);
-+ if (!(fb_dev = fb_open(VIDEOMEM, WIDTH, HEIGHT, DEPTH))) {
-+ free(VIDEOMEM);
-+ return 0;
-+ }
-+#else
- saved_videomode = set_videomode(0x12);
- if (get_videomode() != 0x12) {
- set_videomode(saved_videomode);
- return 0;
- }
-+#endif
- graphics_inited = 1;
- }
- else
- return 1;
-
-+#ifdef __MINIOS__
-+ font8x16 = vgafont16;
-+#else
- font8x16 = (unsigned char*)graphics_get_font();
-+#endif
-
- /* make sure that the highlight color is set correctly */
- graphics_highlight_color = ((graphics_normal_color >> 4) |
-@@ -176,7 +216,11 @@
- grub_printf("Failed to read splash image (%s)\n", splashimage);
- grub_printf("Press any key to continue...");
- getkey();
-+#ifdef __MINIOS__
-+ fb_close();
-+#else
- set_videomode(saved_videomode);
-+#endif
- graphics_inited = 0;
- return 0;
- }
-@@ -190,8 +234,13 @@
- void graphics_end(void)
- {
- if (graphics_inited) {
-+#ifdef __MINIOS__
-+ fb_close();
-+ free(VIDEOMEM);
-+#else
- unset_int1c_handler();
- set_videomode(saved_videomode);
-+#endif
- graphics_inited = 0;
- no_cursor = 0;
- }
-@@ -204,15 +253,19 @@
- graphics_cursor(0);
-
- if (ch == '\n') {
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- if (fonty + 1 < view_y1)
- graphics_setxy(fontx, fonty + 1);
- else
- graphics_scroll();
- graphics_cursor(1);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- return;
- } else if (ch == '\r') {
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- graphics_setxy(view_x0, fonty);
- graphics_cursor(1);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- return;
- }
-
-@@ -224,6 +277,7 @@
- text[fonty * 80 + fontx] |= 0x100;
-
- graphics_cursor(0);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-
- if ((fontx + 1) >= view_x1) {
- graphics_setxy(view_x0, fonty);
-@@ -232,13 +286,16 @@
- else
- graphics_scroll();
- graphics_cursor(1);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- do_more ();
- graphics_cursor(0);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- } else {
- graphics_setxy(fontx + 1, fonty);
- }
-
- graphics_cursor(1);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- }
-
- /* get the current location of the cursor */
-@@ -248,10 +305,12 @@
-
- void graphics_gotoxy(int x, int y) {
- graphics_cursor(0);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-
- graphics_setxy(x, y);
-
- graphics_cursor(1);
-+ fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- }
-
- void graphics_cls(void) {
-@@ -262,15 +321,21 @@
- graphics_gotoxy(view_x0, view_y0);
-
- mem = (unsigned char*)VIDEOMEM;
-+#ifndef __MINIOS__
- s1 = (unsigned char*)VSHADOW1;
- s2 = (unsigned char*)VSHADOW2;
- s4 = (unsigned char*)VSHADOW4;
- s8 = (unsigned char*)VSHADOW8;
-+#endif
-
- for (i = 0; i < 80 * 30; i++)
- text[i] = ' ';
- graphics_cursor(1);
-
-+#ifdef __MINIOS__
-+ memcpy(mem, VSHADOW, RAMSIZE);
-+ fbfront_update(fb_dev, 0, 0, 640, 480);
-+#else
- BitMask(0xff);
-
- /* plane 1 */
-@@ -290,6 +355,7 @@
- grub_memcpy(mem, s8, 38400);
-
- MapMask(15);
-+#endif
-
- if (no_cursor) {
- no_cursor = 0;
-@@ -337,6 +403,11 @@
- return 0;
- }
-
-+void graphics_set_palette(int idx, int red, int green, int blue)
-+{
-+ palette[idx] = (red << (16 + 2)) | (green << (8 + 2)) | (blue << 2);
-+}
-+
- /* Read in the splashscreen image and set the palette up appropriately.
- * Format of splashscreen is an xpm (can be gzipped) with 16 colors and
- * 640x480. */
-@@ -413,18 +484,19 @@
- }
-
- if (len == 6 && idx < 15) {
-- int r = ((hex(buf[0]) << 4) | hex(buf[1])) >> 2;
-- int g = ((hex(buf[2]) << 4) | hex(buf[3])) >> 2;
-- int b = ((hex(buf[4]) << 4) | hex(buf[5])) >> 2;
-+ int r = ((hex(buf[0]) << 4) | hex(buf[1]));
-+ int g = ((hex(buf[2]) << 4) | hex(buf[3]));
-+ int b = ((hex(buf[4]) << 4) | hex(buf[5]));
-
- pal[idx] = base;
-- graphics_set_palette(idx, r, g, b);
-+ graphics_set_palette(idx, r / 4, g / 4, b / 4);
- ++idx;
- }
- }
-
- x = y = len = 0;
-
-+#ifndef __MINIOS__
- s1 = (unsigned char*)VSHADOW1;
- s2 = (unsigned char*)VSHADOW2;
- s4 = (unsigned char*)VSHADOW4;
-@@ -432,6 +504,7 @@
-
- for (i = 0; i < 38400; i++)
- s1[i] = s2[i] = s4[i] = s8[i] = 0;
-+#endif
-
- /* parse xpm data */
- while (y < height) {
-@@ -451,6 +524,9 @@
- break;
- }
-
-+#ifdef __MINIOS__
-+ VSHADOW[x + y * 640] = palette[i];
-+#else
- mask = 0x80 >> (x & 7);
- if (c & 1)
- s1[len + (x >> 3)] |= mask;
-@@ -460,6 +536,7 @@
- s4[len + (x >> 3)] |= mask;
- if (c & 8)
- s8[len + (x >> 3)] |= mask;
-+#endif
-
- if (++x >= 640) {
- x = 0;
-@@ -494,7 +571,13 @@
- }
-
- void graphics_cursor(int set) {
-- unsigned char *pat, *mem, *ptr, chr[16 << 2];
-+ unsigned char *pat;
-+#ifdef __MINIOS__
-+ uint32_t *mem, *ptr, chr[16 * 8];
-+ int j;
-+#else
-+ unsigned char *mem, *ptr, chr[16 << 2];
-+#endif
- int i, ch, invert, offset;
-
- if (set && (no_cursor || no_scroll))
-@@ -505,71 +588,127 @@
- invert = (text[fonty * 80 + fontx] & 0xff00) != 0;
- pat = font8x16 + (ch << 4);
-
-- mem = (unsigned char*)VIDEOMEM + offset;
-+ mem = (unsigned char*)VIDEOMEM + offset
-+#ifdef __MINIOS__
-+ * 8 * 4
-+#endif
-+ ;
-
- if (!set) {
- for (i = 0; i < 16; i++) {
- unsigned char mask = pat[i];
-
- if (!invert) {
-+#ifdef __MINIOS__
-+ memcpy(chr + i * 8, VSHADOW + offset * 8, 8 * 4);
-+#else
- chr[i ] = ((unsigned char*)VSHADOW1)[offset];
- chr[16 + i] = ((unsigned char*)VSHADOW2)[offset];
- chr[32 + i] = ((unsigned char*)VSHADOW4)[offset];
- chr[48 + i] = ((unsigned char*)VSHADOW8)[offset];
-+#endif
-
- if (shade) {
- if (ch == DISP_VERT || ch == DISP_LL ||
- ch == DISP_UR || ch == DISP_LR) {
- unsigned char pmask = ~(pat[i] >> 1);
-
-+#ifdef __MINIOS__
-+ for (j = 0; j < 8; j++)
-+ if (!(pmask & (1U << j)))
-+ chr[i * 8 + (7 - j)] = palette[0];
-+#else
- chr[i ] &= pmask;
- chr[16 + i] &= pmask;
- chr[32 + i] &= pmask;
- chr[48 + i] &= pmask;
-+#endif
- }
- if (i > 0 && ch != DISP_VERT) {
- unsigned char pmask = ~(pat[i - 1] >> 1);
-
-+#ifdef __MINIOS__
-+ for (j = 0; j < 8; j++)
-+ if (!(pmask & (1U << j)))
-+ chr[i * 8 + (7 - j)] = palette[0];
-+#else
- chr[i ] &= pmask;
- chr[16 + i] &= pmask;
- chr[32 + i] &= pmask;
- chr[48 + i] &= pmask;
-+#endif
- if (ch == DISP_HORIZ || ch == DISP_UR || ch ==
DISP_LR) {
- pmask = ~pat[i - 1];
-
-+#ifdef __MINIOS__
-+ for (j = 0; j < 8; j++)
-+ if (!(pmask & (1U << j)))
-+ chr[i * 8 + (7 - j)] = palette[0];
-+#else
- chr[i ] &= pmask;
- chr[16 + i] &= pmask;
- chr[32 + i] &= pmask;
- chr[48 + i] &= pmask;
-+#endif
- }
- }
- }
-+#ifdef __MINIOS__
-+ for (j = 0; j < 8; j++)
-+ if (mask & (1U << j))
-+ chr[i * 8 + (7 - j)] = palette[15];
-+#else
- chr[i ] |= mask;
- chr[16 + i] |= mask;
- chr[32 + i] |= mask;
- chr[48 + i] |= mask;
-+#endif
-
- offset += 80;
- }
- else {
-+#ifdef __MINIOS__
-+ for (j = 0; j < 8; j++)
-+ if (mask & (1U << j))
-+ chr[i * 8 + (7 - j)] = palette[15];
-+ else
-+ chr[i * 8 + (7 - j)] = palette[0];
-+#else
- chr[i ] = mask;
- chr[16 + i] = mask;
- chr[32 + i] = mask;
- chr[48 + i] = mask;
-+#endif
- }
- }
- }
- else {
-+#ifdef __MINIOS__
-+ ptr = mem;
-+ for (i = 0; i < 16; i++, ptr += 80 * 8)
-+ for (j = 0; j < 8; j++) {
-+ if (pat[i] & (1U << (7 - j)))
-+ cursorBuf32[i * 8 + j] = ptr[j] = palette[0];
-+ else
-+ cursorBuf32[i * 8 + j] = ptr[j] = palette[15];
-+ }
-+#else
- MapMask(15);
- ptr = mem;
- for (i = 0; i < 16; i++, ptr += 80) {
- cursorBuf[i] = pat[i];
- *ptr = ~pat[i];
- }
-+#endif
- return;
- }
-
- offset = 0;
-+#ifdef __MINIOS__
-+ ptr = mem;
-+ for (j = 0; j < 16; j++, ptr += 80 * 8)
-+ memcpy(ptr, chr + j * 8 + offset * 8, 8 * 4);
-+#else
- for (i = 1; i < 16; i <<= 1, offset += 16) {
- int j;
-
-@@ -580,6 +719,7 @@
- }
-
- MapMask(15);
-+#endif
- }
-
- #endif /* SUPPORT_GRAPHICS */
-Index: grub/stage2/graphics.h
-===================================================================
---- grub.orig/stage2/graphics.h 2008-06-16 15:18:14.527010000 +0100
-+++ grub/stage2/graphics.h 2008-06-16 15:18:14.805010000 +0100
-@@ -21,8 +21,10 @@
- #ifndef GRAPHICS_H
- #define GRAPHICS_H
-
-+#ifndef __MINIOS__
- /* magic constant */
- #define VIDEOMEM 0xA0000
-+#endif
-
- /* function prototypes */
- char *graphics_get_splash(void);
-Index: grub/stage2/stage2.c
-===================================================================
---- grub.orig/stage2/stage2.c 2008-06-17 11:06:47.873523000 +0100
-+++ grub/stage2/stage2.c 2008-06-17 11:07:05.225628000 +0100
-@@ -31,10 +31,10 @@
- #if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
-
- # if defined(PRESET_MENU_STRING)
--static const char *preset_menu = PRESET_MENU_STRING;
-+const char *preset_menu = PRESET_MENU_STRING;
- # elif defined(SUPPORT_DISKLESS)
- /* Execute the command "bootp" automatically. */
--static const char *preset_menu = "bootp\n";
-+const char *preset_menu = "bootp\n";
- # endif /* SUPPORT_DISKLESS */
-
- static int preset_menu_offset;
-Index: grub/stage2/fsys_xfs.c
-===================================================================
-RCS file: /sources/grub/grub/stage2/fsys_xfs.c,v
-retrieving revision 1.5
-diff -u -p -r1.5 fsys_xfs.c
---- grub/stage2/fsys_xfs.c 8 May 2005 02:18:14 -0000 1.5
-+++ grub/stage2/fsys_xfs.c 10 Jul 2008 13:09:50 -0000
-@@ -101,7 +101,7 @@ static inline __const__ xfs_uint16_t
- le16 (xfs_uint16_t x)
- {
- __asm__("xchgb %b0,%h0" \
-- : "=q" (x) \
-+ : "=Q" (x) \
- : "0" (x)); \
- return x;
- }
-@@ -109,9 +109,9 @@ le16 (xfs_uint16_t x)
- static inline __const__ xfs_uint32_t
- le32 (xfs_uint32_t x)
- {
--#if 0
-+#if 1
- /* 386 doesn't have bswap. */
-- __asm__("bswap %0" : "=r" (x) : "0" (x));
-+ __asm__("bswapl %k0" : "=r" (x) : "0" (x));
- #else
- /* This is slower but this works on all x86 architectures. */
- __asm__("xchgb %b0, %h0" \
---- grub.orig/stage2/gunzip.c 2010-03-07 23:03:34.000000000 +0100
-+++ grub/stage2/gunzip.c 2010-03-07 23:05:36.000000000 +0100
-@@ -141,7 +141,7 @@
- static int gzip_filemax;
- static int gzip_fsmax;
- static int saved_filepos;
--static unsigned long gzip_crc;
-+static unsigned int gzip_crc;
-
- /* internal extra variables for use of inflate code */
- static int block_type;
-@@ -157,7 +157,7 @@
- * Linear allocator.
- */
-
--static unsigned long linalloc_topaddr;
-+static unsigned int linalloc_topaddr;
-
- static void *
- linalloc (int size)
-@@ -253,7 +253,7 @@
-
- typedef unsigned char uch;
- typedef unsigned short ush;
--typedef unsigned long ulg;
-+typedef unsigned int ulg;
-
- /*
- * Window Size
-@@ -316,8 +316,8 @@
- return 0;
- }
-
-- gzip_crc = *((unsigned long *) buf);
-- gzip_fsmax = gzip_filemax = *((unsigned long *) (buf + 4));
-+ gzip_crc = *((unsigned int *) buf);
-+ gzip_fsmax = gzip_filemax = *((unsigned int *) (buf + 4));
-
- initialize_tables ();
-
-diff -ur grub.orig/stage2/fsys_iso9660.c grub-upstream/stage2/fsys_iso9660.c
---- grub.orig/stage2/fsys_iso9660.c 2010-03-07 23:39:00.000000000 +0100
-+++ grub/stage2/fsys_iso9660.c 2010-03-07 23:39:56.000000000 +0100
-@@ -43,7 +43,7 @@
-
- /* iso fs inode data in memory */
- struct iso_inode_info {
-- unsigned long file_start;
-+ unsigned int file_start;
- };
-
- #define ISO_SUPER \
-@@ -88,12 +88,12 @@
- if (byte_len <= 0)
- return 1;
-
-- sector += (byte_offset >> sector_size_lg2);
-- byte_offset &= (buf_geom.sector_size - 1);
- asm volatile ("shl%L0 %1,%0"
- : "=r"(sector)
- : "Ic"((int8_t)(ISO_SECTOR_BITS - sector_size_lg2)),
- "0"(sector));
-+ sector += (byte_offset >> sector_size_lg2);
-+ byte_offset &= (buf_geom.sector_size - 1);
-
- #if !defined(STAGE1_5)
- if (disk_read_hook && debug)
diff --git a/stubdom/grub/Makefile b/stubdom/grub/Makefile
deleted file mode 100644
index 7397661c9b..0000000000
--- a/stubdom/grub/Makefile
+++ /dev/null
@@ -1,88 +0,0 @@
-XEN_ROOT = $(CURDIR)/../..
-
-include $(XEN_ROOT)/Config.mk
-vpath %.c ../grub-upstream
-
-BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
-
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/guest/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/include -I.
-DEF_CPPFLAGS += -I../grub-upstream/stage1
-DEF_CPPFLAGS += -I../grub-upstream/stage2
-DEF_CPPFLAGS += -I../grub-upstream/netboot
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/firmware/vgabios
-DEF_CPPFLAGS += -DWITHOUT_LIBC_STUBS
-DEF_CPPFLAGS += -DSUPPORT_NETBOOT
-DEF_CPPFLAGS += -DSUPPORT_GRAPHICS
-DEF_CPPFLAGS += -DSUPPORT_SERIAL
-DEF_CPPFLAGS += -DPRESET_MENU_STRING='""'
-DEF_CPPFLAGS += -DPACKAGE='"grubdom"' -DVERSION='"0.97"'
-
-all: $(OBJ_DIR)/main.a
-
-STAGE2_SOURCES=builtins.c char_io.c cmdline.c common.c console.c disk_io.c
graphics.c gunzip.c md5.c serial.c stage2.c terminfo.c tparm.c
-
-NETBOOT_SOURCES=fsys_tftp.c main.c misc.c
-CPPFLAGS += -DFSYS_TFTP=1
-
-STAGE2_SOURCES+=fsys_ext2fs.c
-CPPFLAGS += -DFSYS_EXT2FS=1
-
-STAGE2_SOURCES+=fsys_fat.c
-CPPFLAGS += -DFSYS_FAT=1
-
-STAGE2_SOURCES+=fsys_ffs.c
-CPPFLAGS += -DFSYS_FFS=1
-
-STAGE2_SOURCES+=fsys_iso9660.c
-CPPFLAGS += -DFSYS_ISO9660=1
-
-STAGE2_SOURCES+=fsys_jfs.c
-CPPFLAGS += -DFSYS_JFS=1
-
-STAGE2_SOURCES+=fsys_minix.c
-CPPFLAGS += -DFSYS_MINIX=1
-
-STAGE2_SOURCES+=fsys_reiserfs.c
-CPPFLAGS += -DFSYS_REISERFS=1
-
-STAGE2_SOURCES+=fsys_ufs2.c
-CPPFLAGS += -DFSYS_UFS2=1
-
-STAGE2_SOURCES+=fsys_vstafs.c
-CPPFLAGS += -DFSYS_VSTAFS=1
-
-STAGE2_SOURCES+=fsys_xfs.c
-CPPFLAGS += -DFSYS_XFS=1
-
-STAGE2_SOURCES:=$(addprefix stage2/,$(STAGE2_SOURCES))
-NETBOOT_SOURCES:=$(addprefix netboot/,$(NETBOOT_SOURCES))
-
-$(BOOT): DEF_CPPFLAGS+=-D__ASSEMBLY__
-
-PV_GRUB_SOURCES = kexec.c mini-os.c
-PV_GRUB_SOURCES += ../polarssl-$(XEN_TARGET_ARCH)/library/sha1.o
-
-SOURCES = $(NETBOOT_SOURCES) $(STAGE2_SOURCES) $(PV_GRUB_SOURCES)
-
-OBJS = $(addprefix $(OBJ_DIR)/,$(SOURCES:.c=.o))
-
-$(OBJ_DIR)/dirs:
- mkdir -p $(OBJ_DIR)/netboot $(OBJ_DIR)/stage2
- touch $@
-
-$(OBJS): $(OBJ_DIR)/dirs
-
-$(OBJ_DIR)/main.a: $(BOOT) $(OBJS)
- $(AR) cr $@ $^
-
-$(OBJ_DIR)/%.o: %.c
- $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
-
-$(OBJ_DIR)/%.o: %.S
- $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
-
-clean:
- rm -fr dirs *.a *.o stage2 netboot
diff --git a/stubdom/grub/boot-x86_32.S b/stubdom/grub/boot-x86_32.S
deleted file mode 100644
index c95fd30dd3..0000000000
--- a/stubdom/grub/boot-x86_32.S
+++ /dev/null
@@ -1,112 +0,0 @@
-#include <os.h>
-#include <arch_limits.h>
-#include <xen/arch-x86_32.h>
-
-/* For simplicity, we keep all of this into just one data page */
-.data
-.globl _boot_page
-_boot_page:
- .align __PAGE_SIZE
-
-/*
- * The following data is initialized from C code
- */
-
-/* Pte of this page */
-.globl _boot_page_entry
-_boot_page_entry:
-_boot_page_entry_lo:
- .long 0
-_boot_page_entry_hi:
- .long 0
-
-/* mmuext_op structure */
-/* Set new page directory */
-_boot_mmuext:
- /* Op # */
- .long MMUEXT_NEW_BASEPTR
-
- /* MFN of target page table directory */
-.globl _boot_pdmfn
-_boot_pdmfn:
- .long 0
-
- /* Unused */
- .long 0
-
-/* Unpin old page directory */
- /* Op # */
- .long MMUEXT_UNPIN_TABLE
-
- /* MFN of old page table directory */
-.globl _boot_oldpdmfn
-_boot_oldpdmfn:
- .long 0
-
- /* Unused */
- .long 0
-
-/* Target stack address, also target virtual address of this page */
-.globl _boot_stack
-_boot_stack:
- .long 0
- .long __KERNEL_SS
-.globl _boot_target
-_boot_target:
- .long 0
-
-/* Target start info */
-.globl _boot_start_info
-_boot_start_info:
- .long 0
-
-/* Target start address */
-.globl _boot_start
-_boot_start:
- .long 0
-
-/*
- * Boot target OS, does not return
- */
-.globl _boot
-_boot:
- /* Project ourselves at the target place. */
- movl _boot_target, %ebx
- movl %ebx, %ebp /* also keep it in ebp for relative addressing
*/
- movl _boot_page_entry_lo, %ecx
- movl _boot_page_entry_hi, %edx
- movl $2, %esi /* UVMF_INVLPG */
- movl $__HYPERVISOR_update_va_mapping, %eax
- int $0x82
- testl %eax, %eax
- jz 0f
- ud2
-
-0:
- /* Go there. */
- movl $(0f - _boot_page), %eax
- movl _boot_target, %ebx
- addl %ebx, %eax
- jmpl *%eax
-0:
-
- /* Load target page table and unpin old page table. */
- /* We shouldn't have any problem since in the new page table our page
is
- mapped at the same place. */
- leal (_boot_mmuext-_boot_page)(%ebp), %ebx
- movl $2, %ecx
- xorl %edx, %edx
- movl $0x7FF0, %esi /* DOMID_SELF */
- movl $__HYPERVISOR_mmuext_op, %eax
- int $0x82
- testl %eax, %eax
- jns 0f
- ud2
-
-0:
- /* Initialize registers. */
- lss (_boot_stack-_boot_page)(%ebp), %esp
- movl (_boot_start_info-_boot_page)(%ebp), %esi
-
- /* Jump! */
- jmpl *(_boot_start-_boot_page)(%ebp)
diff --git a/stubdom/grub/boot-x86_64.S b/stubdom/grub/boot-x86_64.S
deleted file mode 100644
index 2eae6c3437..0000000000
--- a/stubdom/grub/boot-x86_64.S
+++ /dev/null
@@ -1,108 +0,0 @@
-#include <os.h>
-#include <arch_limits.h>
-#include <xen/arch-x86_64.h>
-
-/* For simplicity, we keep all of this into just one data page */
-.data
-.globl _boot_page
-_boot_page:
- .align __PAGE_SIZE
-
-/*
- * The following data is initialized from C code
- */
-
-/* Pte of this page */
-.globl _boot_page_entry
-_boot_page_entry:
- .quad 0
-
-/* mmuext_op structure */
-/* Set new page directory */
-_boot_mmuext:
- /* Op # */
- .long MMUEXT_NEW_BASEPTR
- .long 0 /* pad */
-
- /* MFN of target page table directory */
-.globl _boot_pdmfn
-_boot_pdmfn:
- .quad 0
-
- /* Unused */
- .quad 0
-
-/* Unpin old page directory */
- /* Op # */
- .long MMUEXT_UNPIN_TABLE
- .long 0 /* pad */
-
- /* MFN of old page table directory */
-.globl _boot_oldpdmfn
-_boot_oldpdmfn:
- .quad 0
-
- /* Unused */
- .quad 0
-
-/* Target stack address, also target virtual address of this page */
-.globl _boot_stack
-_boot_stack:
- .quad 0
-.globl _boot_target
-_boot_target:
- .quad 0
-
-/* Target start info */
-.globl _boot_start_info
-_boot_start_info:
- .quad 0
-
-/* Target start address */
-.globl _boot_start
-_boot_start:
- .quad 0
-
-/*
- * Boot target OS, does not return
- */
-.globl _boot
-_boot:
- /* Project ourselves at the target place. */
- movq _boot_target, %rdi
- movq _boot_page_entry, %rsi
- movq $2, %rdx /* UVMF_INVLPG */
- movq $__HYPERVISOR_update_va_mapping, %rax
- syscall
- testq %rax, %rax
- jz 0f
- ud2
-
-0:
- /* Go there. */
- movq $(0f - _boot_page), %rax
- movq _boot_target, %rbx
- addq %rbx, %rax
- jmpq *%rax
-0:
-
- /* Load target page table and unpin old page table. */
- /* We shouldn't have any problem since in the new page table our page
is
- mapped at the same place. */
- leaq _boot_mmuext(%rip), %rdi
- movq $2, %rsi
- xorq %rdx, %rdx
- movq $0x7FF0, %r10 /* DOMID_SELF */
- movq $__HYPERVISOR_mmuext_op, %rax
- syscall
- testq %rax, %rax
- jns 0f
- ud2
-
-0:
- /* Initialize registers. */
- movq _boot_stack(%rip), %rsp
- movq _boot_start_info(%rip), %rsi
-
- /* Jump! */
- jmpq *_boot_start(%rip)
diff --git a/stubdom/grub/config.h b/stubdom/grub/config.h
deleted file mode 100644
index 15a6583999..0000000000
--- a/stubdom/grub/config.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <stdio.h>
-#undef putchar
-#include <ctype.h>
-#include <string.h>
-#include <kernel.h>
-#define debug _debug
-#define grub_halt(a) do_exit()
-#define printf grub_printf
-void kexec(void *kernel, long kernel_size, void *module, long module_size,
char *cmdline, unsigned long flags);
-struct fbfront_dev *fb_open(void *fb, int width, int height, int depth);
-void fb_close(void);
-void pv_boot (void);
diff --git a/stubdom/grub/kexec.c b/stubdom/grub/kexec.c
deleted file mode 100644
index 92646ad8cd..0000000000
--- a/stubdom/grub/kexec.c
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * This supports booting another PV kernel from Mini-OS
- *
- * The idea is to setup it using libxc, answer to day0 memory allocation
- * requests, and using a trampoline boot page to switch to the new page table.
- *
- * The procedure of the boot page is:
- * - map itself at the target position (that may overwrite some C stuff, but we
- * do not care any more)
- * - jump there
- * - switch to the target page table
- * - unpin the old page table
- * - jump to the new kernel
- *
- * Samuel Thibault <Samuel.Thibault@xxxxxxxxxxxxx>, May 2008
- */
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-
-#include <xenctrl.h>
-#include <xenguest.h>
-
-#include <kernel.h>
-#include <console.h>
-#include <os.h>
-#include <blkfront.h>
-#include <netfront.h>
-#include <fbfront.h>
-#include <tpmfront.h>
-#include <shared.h>
-#include <byteswap.h>
-
-#include "mini-os.h"
-
-#undef start_info
-
-#if 0
-#define DEBUG(fmt, ...) printk(fmt, ## __VA_ARGS__)
-#else
-#define DEBUG(fmt, ...) (void)0
-#endif
-
-/* Assembly boot page from boot.S */
-extern void _boot_page;
-extern pgentry_t _boot_page_entry;
-extern unsigned long _boot_pdmfn;
-extern unsigned long _boot_stack, _boot_target, _boot_start_info, _boot_start;
-extern xen_pfn_t _boot_oldpdmfn;
-extern void _boot(void);
-
-static unsigned long *pages;
-static unsigned long *pages_mfns;
-static xen_pfn_t *pages_moved2pfns;
-static unsigned long allocated;
-
-int pin_table(xc_interface *xc_handle, unsigned int type, unsigned long mfn,
- domid_t dom);
-
-#define TPM_TAG_RQU_COMMAND 0xC1
-#define TPM_ORD_Extend 20
-
-struct pcr_extend_cmd {
- uint16_t tag;
- uint32_t size;
- uint32_t ord;
-
- uint32_t pcr;
- unsigned char hash[20];
-} __attribute__((packed));
-
-struct pcr_extend_rsp {
- uint16_t tag;
- uint32_t size;
- uint32_t status;
-
- unsigned char hash[20];
-} __attribute__((packed));
-
-/* Not imported from polarssl's header since the prototype unhelpfully defines
- * the input as unsigned char, which causes pointer type mismatches */
-void sha1(const void *input, size_t ilen, unsigned char output[20]);
-
-/* We need mfn to appear as target_pfn, so exchange with the MFN there */
-static void do_exchange(struct xc_dom_image *dom, xen_pfn_t target_pfn,
xen_pfn_t source_mfn)
-{
- xen_pfn_t source_pfn;
- xen_pfn_t target_mfn;
-
- for (source_pfn = 0; source_pfn < start_info_ptr->nr_pages; source_pfn++)
- if (dom->pv_p2m[source_pfn] == source_mfn)
- break;
- ASSERT(source_pfn < start_info_ptr->nr_pages);
-
- target_mfn = dom->pv_p2m[target_pfn];
-
- /* Put target MFN at source PFN */
- dom->pv_p2m[source_pfn] = target_mfn;
-
- /* Put source MFN at target PFN */
- dom->pv_p2m[target_pfn] = source_mfn;
-}
-
-int kexec_allocate(struct xc_dom_image *dom)
-{
- unsigned long new_allocated = dom->pfn_alloc_end - dom->rambase_pfn;
- unsigned long i;
-
- pages = realloc(pages, new_allocated * sizeof(*pages));
- pages_mfns = realloc(pages_mfns, new_allocated * sizeof(*pages_mfns));
- pages_moved2pfns = realloc(pages_moved2pfns, new_allocated *
sizeof(*pages_moved2pfns));
- for (i = allocated; i < new_allocated; i++) {
- /* Exchange old page of PFN i with a newly allocated page. */
- xen_pfn_t old_mfn = dom->pv_p2m[i];
- xen_pfn_t new_pfn;
- xen_pfn_t new_mfn;
-
- pages[i] = alloc_page();
- memset((void*) pages[i], 0, PAGE_SIZE);
- new_pfn = PHYS_PFN(to_phys(pages[i]));
- pages_mfns[i] = new_mfn = pfn_to_mfn(new_pfn);
-
- /*
- * If PFN of newly allocated page (new_pfn) is less then currently
- * requested PFN (i) then look for relevant PFN/MFN pair. In this
- * situation dom->pv_p2m[new_pfn] no longer contains proper MFN
- * because original page with new_pfn was moved earlier
- * to different location.
- */
- for (; new_pfn < i; new_pfn = pages_moved2pfns[new_pfn]);
-
- /* Store destination PFN of currently requested page. */
- pages_moved2pfns[i] = new_pfn;
-
- /* Put old page at new PFN */
- dom->pv_p2m[new_pfn] = old_mfn;
-
- /* Put new page at PFN i */
- dom->pv_p2m[i] = new_mfn;
- }
-
- allocated = new_allocated;
-
- return 0;
-}
-
-/* Filled from mini-os command line or left as NULL */
-char *vtpm_label;
-
-static void tpm_hash2pcr(struct xc_dom_image *dom, char *cmdline)
-{
- struct tpmfront_dev* tpm = init_tpmfront(NULL);
- struct pcr_extend_rsp *resp;
- size_t resplen = 0;
- struct pcr_extend_cmd cmd;
- int rv;
-
- /*
- * If vtpm_label was specified on the command line, require a vTPM to be
- * attached and for the domain providing the vTPM to have the given
- * label.
- */
- if (vtpm_label) {
- char ctx[128];
- if (!tpm) {
- printf("No TPM found and vtpm_label specified,
aborting!\n");
- do_exit();
- }
- rv = evtchn_get_peercontext(tpm->evtchn, ctx, sizeof(ctx) - 1);
- if (rv < 0) {
- printf("Could not verify vtpm_label: %d\n", rv);
- do_exit();
- }
- ctx[127] = 0;
- rv = strcmp(ctx, vtpm_label);
- if (rv && vtpm_label[0] == '*') {
- int match_len = strlen(vtpm_label) - 1;
- int offset = strlen(ctx) - match_len;
- if (offset > 0)
- rv = strcmp(ctx + offset, vtpm_label + 1);
- }
-
- if (rv) {
- printf("Mismatched vtpm_label: '%s' != '%s'\n", ctx,
vtpm_label);
- do_exit();
- }
- } else if (!tpm) {
- return;
- }
-
- cmd.tag = bswap_16(TPM_TAG_RQU_COMMAND);
- cmd.size = bswap_32(sizeof(cmd));
- cmd.ord = bswap_32(TPM_ORD_Extend);
- cmd.pcr = bswap_32(4); // PCR #4 for kernel
- sha1(dom->kernel_blob, dom->kernel_size, cmd.hash);
-
- rv = tpmfront_cmd(tpm, (void*)&cmd, sizeof(cmd), (void*)&resp,
&resplen);
- ASSERT(rv == 0 && resp->status == 0);
-
- cmd.pcr = bswap_32(5); // PCR #5 for cmdline
- sha1(cmdline, strlen(cmdline), cmd.hash);
- rv = tpmfront_cmd(tpm, (void*)&cmd, sizeof(cmd), (void*)&resp,
&resplen);
- ASSERT(rv == 0 && resp->status == 0);
-
- cmd.pcr = bswap_32(5); // PCR #5 for initrd
- sha1(dom->modules[0].blob, dom->modules[0].size, cmd.hash);
- rv = tpmfront_cmd(tpm, (void*)&cmd, sizeof(cmd), (void*)&resp,
&resplen);
- ASSERT(rv == 0 && resp->status == 0);
-
- shutdown_tpmfront(tpm);
-}
-
-void kexec(void *kernel, long kernel_size, void *module, long module_size,
char *cmdline, unsigned long flags)
-{
- struct xc_dom_image *dom;
- int rc;
- domid_t domid = DOMID_SELF;
- xen_pfn_t pfn;
- xc_interface *xc_handle;
- unsigned long i;
- void *seg;
- xen_pfn_t boot_page_mfn = virt_to_mfn(&_boot_page);
- char features[] = "";
- struct mmu_update *m2p_updates;
- unsigned long nr_m2p_updates;
- uint64_t virt_base;
-
- DEBUG("booting with cmdline %s\n", cmdline);
- xc_handle = xc_interface_open(0,0,0);
-
- dom = xc_dom_allocate(xc_handle, cmdline, features);
- dom->allocate = kexec_allocate;
-
- /* We are using guest owned memory, therefore no limits. */
- xc_dom_kernel_max_size(dom, 0);
- xc_dom_module_max_size(dom, 0);
-
- dom->kernel_blob = kernel;
- dom->kernel_size = kernel_size;
-
- xc_dom_module_mem(dom, module, module_size, NULL);
-
- dom->flags = flags;
- dom->console_evtchn = start_info_ptr->console.domU.evtchn;
- dom->xenstore_evtchn = start_info_ptr->store_evtchn;
-
- tpm_hash2pcr(dom, cmdline);
-
- if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 ) {
- printk("xc_dom_boot_xen_init returned %d\n", rc);
- errnum = ERR_BOOT_FAILURE;
- goto out;
- }
- if ( (rc = xc_dom_parse_image(dom)) != 0 ) {
- printk("xc_dom_parse_image returned %d\n", rc);
- errnum = ERR_BOOT_FAILURE;
- goto out;
- }
-
-#ifdef __i386__
- if (strcmp(dom->guest_type, "xen-3.0-x86_32p")) {
- printk("can only boot x86 32 PAE kernels, not %s\n", dom->guest_type);
- errnum = ERR_EXEC_FORMAT;
- goto out;
- }
-#endif
-#ifdef __x86_64__
- if (strcmp(dom->guest_type, "xen-3.0-x86_64")) {
- printk("can only boot x86 64 kernels, not %s\n", dom->guest_type);
- errnum = ERR_EXEC_FORMAT;
- goto out;
- }
-#endif
-
- /* equivalent of xc_dom_mem_init */
- if (xc_dom_set_arch_hooks(dom)) {
- printk("xc_dom_set_arch_hooks failed\n");
- errnum = ERR_EXEC_FORMAT;
- goto out;
- }
- dom->total_pages = start_info_ptr->nr_pages;
-
- /* equivalent of arch_setup_meminit */
- dom->p2m_size = dom->total_pages;
-
- /* setup initial p2m */
- dom->pv_p2m = malloc(sizeof(*dom->pv_p2m) * dom->p2m_size);
-
- /* Start with our current P2M */
- for (i = 0; i < dom->p2m_size; i++)
- dom->pv_p2m[i] = pfn_to_mfn(i);
-
- if ( (rc = xc_dom_build_image(dom)) != 0 ) {
- printk("xc_dom_build_image returned %d\n", rc);
- errnum = ERR_BOOT_FAILURE;
- goto out;
- }
-
- virt_base = xc_dom_virt_base(dom);
- /* copy hypercall page */
- /* TODO: domctl instead, but requires privileges */
- if (xc_dom_virt_hypercall(dom) != -1) {
- pfn = PHYS_PFN(xc_dom_virt_hypercall(dom) - virt_base);
- memcpy((void *) pages[pfn], hypercall_page, PAGE_SIZE);
- }
-
- /* Equivalent of xc_dom_boot_image */
- dom->shared_info_mfn = PHYS_PFN(start_info_ptr->shared_info);
-
- if (!xc_dom_compat_check(dom)) {
- printk("xc_dom_compat_check failed\n");
- errnum = ERR_EXEC_FORMAT;
- goto out;
- }
-
- /* Move current console, xenstore and boot MFNs to the allocated place */
- do_exchange(dom, dom->console_pfn, start_info_ptr->console.domU.mfn);
- do_exchange(dom, dom->xenstore_pfn, start_info_ptr->store_mfn);
- DEBUG("virt base at %llx\n", virt_base);
- DEBUG("bootstack_pfn %lx\n", dom->bootstack_pfn);
- _boot_target = virt_base + PFN_PHYS(dom->bootstack_pfn);
- DEBUG("_boot_target %lx\n", _boot_target);
- do_exchange(dom, PHYS_PFN(_boot_target - virt_base),
- virt_to_mfn(&_boot_page));
-
- if ( dom->arch_hooks->setup_pgtables )
- if ( (rc = dom->arch_hooks->setup_pgtables(dom))) {
- printk("setup_pgtables returned %d\n", rc);
- errnum = ERR_BOOT_FAILURE;
- goto out;
- }
-
- /* start info page */
- if ( dom->arch_hooks->start_info )
- dom->arch_hooks->start_info(dom);
-
- xc_dom_log_memory_footprint(dom);
-
- /* Unmap libxc's projection of the boot page table */
- seg = xc_dom_seg_to_ptr(dom, &dom->pgtables_seg);
- munmap(seg, dom->pgtables_seg.vend - dom->pgtables_seg.vstart);
- seg = xc_dom_seg_to_ptr(dom, &dom->p2m_seg);
- munmap(seg, dom->p2m_seg.vend - dom->p2m_seg.vstart);
-
- /* Unmap day0 pages to avoid having a r/w mapping of the future page table
*/
- for (pfn = 0; pfn < allocated; pfn++)
- munmap((void*) pages[pfn], PAGE_SIZE);
-
- /* Pin the boot page table base */
- if ( (rc = pin_table(dom->xch,
-#ifdef __i386__
- MMUEXT_PIN_L3_TABLE,
-#endif
-#ifdef __x86_64__
- MMUEXT_PIN_L4_TABLE,
-#endif
- xc_dom_p2m(dom, dom->pgtables_seg.pfn),
- dom->guest_domid)) != 0 ) {
- printk("pin_table(%lx) returned %d\n", xc_dom_p2m(dom,
- dom->pgtables_seg.pfn), rc);
- errnum = ERR_BOOT_FAILURE;
- goto out_remap;
- }
-
- /* We populate the Mini-OS page table here so that boot.S can just call
- * update_va_mapping to project itself there. */
- need_pgt(_boot_target);
- DEBUG("day0 pages %lx\n", allocated);
- DEBUG("boot target page %lx\n", _boot_target);
- DEBUG("boot page %p\n", &_boot_page);
- DEBUG("boot page mfn %lx\n", boot_page_mfn);
- _boot_page_entry = PFN_PHYS(boot_page_mfn) | L1_PROT;
- DEBUG("boot page entry %llx\n", _boot_page_entry);
- _boot_oldpdmfn = virt_to_mfn(start_info_ptr->pt_base);
- DEBUG("boot old pd mfn %lx\n", _boot_oldpdmfn);
- DEBUG("boot pd virt %lx\n", dom->pgtables_seg.vstart);
- _boot_pdmfn = dom->pv_p2m[PHYS_PFN(dom->pgtables_seg.vstart - virt_base)];
- DEBUG("boot pd mfn %lx\n", _boot_pdmfn);
- _boot_stack = _boot_target + PAGE_SIZE;
- DEBUG("boot stack %lx\n", _boot_stack);
- _boot_start_info = virt_base + PFN_PHYS(dom->start_info_pfn);
- DEBUG("boot start info %lx\n", _boot_start_info);
- _boot_start = xc_dom_virt_entry(dom);
- DEBUG("boot start %lx\n", _boot_start);
-
- /* Keep only useful entries */
- for (nr_m2p_updates = pfn = 0; pfn < start_info_ptr->nr_pages; pfn++)
- if (dom->pv_p2m[pfn] != pfn_to_mfn(pfn))
- nr_m2p_updates++;
-
- m2p_updates = malloc(sizeof(*m2p_updates) * nr_m2p_updates);
- for (i = pfn = 0; pfn < start_info_ptr->nr_pages; pfn++)
- if (dom->pv_p2m[pfn] != pfn_to_mfn(pfn)) {
- m2p_updates[i].ptr = PFN_PHYS(dom->pv_p2m[pfn]) |
MMU_MACHPHYS_UPDATE;
- m2p_updates[i].val = pfn;
- i++;
- }
-
- for (i = 0; i < blk_nb; i++)
- shutdown_blkfront(blk_dev[i]);
- if (net_dev)
- shutdown_netfront(net_dev);
- if (kbd_dev)
- shutdown_kbdfront(kbd_dev);
- stop_kernel();
-
- /* Update M2P */
- if ((rc = HYPERVISOR_mmu_update(m2p_updates, nr_m2p_updates, NULL,
DOMID_SELF)) < 0) {
- xprintk("Could not update M2P\n");
- ASSERT(0);
- }
-
- xprintk("go!\n");
-
- /* Jump to trampoline boot page */
- _boot();
-
- ASSERT(0);
-
-out_remap:
- for (pfn = 0; pfn < allocated; pfn++)
- do_map_frames(pages[pfn], &pages_mfns[pfn], 1, 0, 0, DOMID_SELF, 0,
L1_PROT);
-out:
- xc_dom_release(dom);
- for (pfn = 0; pfn < allocated; pfn++)
- free_page((void*)pages[pfn]);
- free(pages);
- free(pages_mfns);
- pages = NULL;
- pages_mfns = NULL;
- allocated = 0;
- xc_interface_close(xc_handle );
-}
diff --git a/stubdom/grub/mini-os.c b/stubdom/grub/mini-os.c
deleted file mode 100644
index 4fc052a255..0000000000
--- a/stubdom/grub/mini-os.c
+++ /dev/null
@@ -1,771 +0,0 @@
-/*
- * Mini-OS support for GRUB.
- *
- * Samuel Thibault <Samuel.Thibault@xxxxxxxxxxxxx>, May 2008
- */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <unistd.h>
-
-#include <hypervisor.h>
-#include <blkfront.h>
-#include <netfront.h>
-#include <fbfront.h>
-#include <semaphore.h>
-
-#include <osdep.h>
-#include <shared.h>
-#include <nic.h>
-#include <etherboot.h>
-#include <terminfo.h>
-#include <term.h>
-
-#include "mini-os.h"
-
-extern const char *preset_menu;
-char config_file[DEFAULT_FILE_BUFLEN] = "(hd0,0)/boot/grub/menu.lst";
-unsigned long boot_drive = NETWORK_DRIVE;
-unsigned long install_partition = 0xFFFFFF;
-
-char version_string[] = VERSION;
-
-/* Variables from asm.S */
-int saved_entryno;
-
-/*
- * Disk
- */
-
-struct blkfront_dev **blk_dev;
-int blk_nb;
-static struct blkfront_info *blk_info;
-
-static int vbdcmp(const void *_vbd1, const void *_vbd2) {
- char *vbd1 = *(char **)_vbd1;
- char *vbd2 = *(char **)_vbd2;
- int vbdn1 = atoi(vbd1);
- int vbdn2 = atoi(vbd2);
- return vbdn1 - vbdn2;
-}
-
-void init_disk (void)
-{
- char **list;
- char *msg;
- int i;
- char *path;
-
- msg = xenbus_ls(XBT_NIL, "device/vbd", &list);
- if (msg) {
- printk("Error %s while reading list of disks\n", msg);
- free(msg);
- return;
- }
- blk_nb = 0;
- while (list[blk_nb])
- blk_nb++;
- blk_dev = malloc(blk_nb * sizeof(*blk_dev));
- blk_info = malloc(blk_nb * sizeof(*blk_info));
-
- qsort(list, blk_nb, sizeof(*list), vbdcmp);
-
- for (i = 0; i < blk_nb; i++) {
- printk("vbd %s is hd%d\n", list[i], i);
- asprintf(&path, "device/vbd/%s", list[i]);
- blk_dev[i] = init_blkfront(path, &blk_info[i]);
- free(path);
- free(list[i]);
- }
-}
-
-/* Return the geometry of DRIVE in GEOMETRY. If an error occurs, return
- non-zero, otherwise zero. */
-int get_diskinfo (int drive, struct geometry *geometry)
-{
- int i;
- if (!(drive & 0x80))
- return -1;
-
- i = drive - 0x80;
- if (i >= blk_nb)
- return -1;
-
- /* Bogus geometry */
- geometry->cylinders = 65535;
- geometry->heads = 255;
- geometry->sectors = 63;
-
- geometry->total_sectors = blk_info[i].sectors;
- geometry->sector_size = blk_info[i].sector_size;
- geometry->flags = BIOSDISK_FLAG_LBA_EXTENSION;
- if (blk_info[i].info & VDISK_CDROM)
- geometry->flags |= BIOSDISK_FLAG_CDROM;
- return 0;
-}
-
-/* Read/write NSEC sectors starting from SECTOR in DRIVE disk with GEOMETRY
- from/into SEGMENT segment. If READ is BIOSDISK_READ, then read it,
- else if READ is BIOSDISK_WRITE, then write it. If an geometry error
- occurs, return BIOSDISK_ERROR_GEOMETRY, and if other error occurs, then
- return the error number. Otherwise, return 0. */
-int
-biosdisk (int read, int drive, struct geometry *geometry,
- unsigned int sector, int nsec, int segment)
-{
- void *addr = (void *) ((unsigned long)segment << 4);
- struct blkfront_aiocb aiocb;
- int i;
-
- if (!(drive & 0x80))
- return -1;
-
- i = drive - 0x80;
- if (i >= blk_nb)
- return -1;
-
- if (sector + nsec > geometry->total_sectors)
- return -1;
-
- aiocb.aio_dev = blk_dev[i];
- aiocb.aio_buf = addr;
- aiocb.aio_nbytes = (size_t)nsec * blk_info[i].sector_size;
- aiocb.aio_offset = (off_t)sector * blk_info[i].sector_size;
- aiocb.aio_cb = NULL;
-
- blkfront_io(&aiocb, read == BIOSDISK_WRITE);
-
- return 0;
-}
-
-static int
-load_file(char *name, void **ptr, long *size)
-{
- char *buf = NULL;
- int allocated = 1 * 1024 * 1024;
- int len, filled = 0;
-
- if (!grub_open (name))
- return -1;
-
- buf = malloc(allocated);
-
- errnum = 0;
- while (1) {
- len = grub_read (buf + filled, allocated - filled);
- if (! len) {
- if (!errnum)
- break;
- grub_close ();
- return -1;
- }
- filled += len;
- if (filled < allocated)
- break;
- allocated *= 2;
- buf = realloc(buf, allocated);
- }
- grub_close ();
- *ptr = buf;
- *size = filled;
- return 0;
-}
-
-void *kernel_image, *module_image;
-long kernel_size, module_size;
-char *kernel_arg, *module_arg;
-void *multiboot_next_module;
-struct xen_multiboot_mod_list *multiboot_next_module_header;
-
-kernel_t
-load_image (char *kernel, char *arg, kernel_t suggested_type,
- unsigned long load_flags)
-{
- arg = skip_to(0, arg);
- if (kernel_image)
- free(kernel_image);
- kernel_image = NULL;
- if (load_file (kernel, &kernel_image, &kernel_size))
- return KERNEL_TYPE_NONE;
- if (kernel_arg)
- free(kernel_arg);
- kernel_arg = strdup(arg);
- return KERNEL_TYPE_PV;
-}
-
-int
-load_initrd (char *initrd)
-{
- if (module_image)
- free(module_image);
- module_image = NULL;
- multiboot_next_module = NULL;
- multiboot_next_module_header = NULL;
- load_file (initrd, &module_image, &module_size);
- return ! errnum;
-}
-
-int
-load_module (char *module, char *arg)
-{
- void *new_module, *new_module_image;
- long new_module_size, rounded_new_module_size;
-
- if (load_file (module, &new_module, &new_module_size))
- return 0;
- if (strlen(arg) >= PAGE_SIZE) {
- /* Too big module command line */
- errnum = ERR_WONT_FIT;
- return 0;
- }
- rounded_new_module_size = (new_module_size + PAGE_SIZE - 1) & PAGE_MASK;
-
- if (module_image && !multiboot_next_module_header) {
- /* Initrd already loaded, drop it */
- free(module_image);
- if (module_arg)
- free(module_arg);
- module_image = NULL;
- }
- if (!module_image)
- /* Reserve one page for the header */
- multiboot_next_module = (void*) PAGE_SIZE;
-
- /* Allocate more room for the new module plus its arg */
- new_module_image = realloc(module_image,
- (multiboot_next_module - module_image) + rounded_new_module_size +
PAGE_SIZE);
-
- /* Update pointers */
- multiboot_next_module += new_module_image - module_image;
- multiboot_next_module_header = (void*) multiboot_next_module_header +
(new_module_image - module_image);
- module_image = new_module_image;
-
- if ((void*) (multiboot_next_module_header+1) - module_image > PAGE_SIZE) {
- /* Too many modules */
- errnum = ERR_WONT_FIT;
- return 0;
- }
-
- /* Copy module */
- memcpy(multiboot_next_module, new_module, new_module_size);
- multiboot_next_module_header->mod_start = multiboot_next_module -
module_image;
- multiboot_next_module_header->mod_end =
multiboot_next_module_header->mod_start + new_module_size - 1;
- multiboot_next_module += rounded_new_module_size;
-
- /* Copy cmdline */
- strcpy(multiboot_next_module, arg);
- multiboot_next_module_header->cmdline = multiboot_next_module -
module_image;
- multiboot_next_module += PAGE_SIZE;
-
- /* Pad */
- multiboot_next_module_header->pad = 0;
-
- multiboot_next_module_header++;
-
- return 1;
-}
-
-void
-pv_boot (void)
-{
- unsigned long flags = 0;
- if (multiboot_next_module_header) {
- /* Termination entry */
- multiboot_next_module_header->mod_start = 0;
- /* Total size */
- module_size = multiboot_next_module - module_image;
- /* It's a multiboot module */
- flags |= SIF_MULTIBOOT_MOD;
- }
- kexec(kernel_image, kernel_size, module_image, module_size, kernel_arg,
flags);
-}
-
-/*
- * Network
- */
-
-struct netfront_dev *net_dev;
-
-int
-minios_probe (struct nic *nic)
-{
- char *ip;
-
- if (net_dev)
- return 1;
-
- /* Clear the ARP table. */
- grub_memset ((char *) arptable, 0,
- MAX_ARP * sizeof (struct arptable_t));
-
- net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, &ip);
- if (!net_dev)
- return 0;
-
- return 1;
-}
-
-/* reset adapter */
-static void minios_reset(struct nic *nic)
-{
- /* TODO? */
-}
-
-static void minios_disable(struct nic *nic)
-{
-}
-
-/* Wait for a frame */
-static int minios_poll(struct nic *nic)
-{
- return !! (nic->packetlen = netfront_receive(net_dev, (void*) nic->packet,
ETH_FRAME_LEN));
-}
-
-/* Transmit a frame */
-struct frame {
- uint8_t dest[ETH_ALEN];
- uint8_t src[ETH_ALEN];
- uint16_t type;
- unsigned char data[];
-};
-static void minios_transmit (struct nic *nic, const char *d, unsigned int t,
- unsigned int s, const char *p)
-{
- struct frame *frame = alloca(sizeof(*frame) + s);
-
- memcpy(frame->dest, d, ETH_ALEN);
- memcpy(frame->src, nic->node_addr, ETH_ALEN);
- frame->type = htons(t);
- memcpy(frame->data, p, s);
-
- netfront_xmit(net_dev, (void*) frame, sizeof(*frame) + s);
-}
-
-static char packet[ETH_FRAME_LEN];
-
-struct nic nic = {
- .reset = minios_reset,
- .poll = minios_poll,
- .transmit = minios_transmit,
- .disable = minios_disable,
- .flags = 0,
- .rom_info = NULL,
- .node_addr = arptable[ARP_CLIENT].node,
- .packet = packet,
- .packetlen = 0,
- .priv_data = NULL,
-};
-
-int
-eth_probe (void)
-{
- return minios_probe(&nic);
-}
-
-int
-eth_poll (void)
-{
- return minios_poll (&nic);
-}
-
-void
-eth_disable (void)
-{
- minios_disable (&nic);
-}
-
-void
-eth_transmit (const char *d, unsigned int t,
- unsigned int s, const void *p)
-{
- minios_transmit (&nic, d, t, s, p);
- if (t == IP)
- twiddle();
-}
-
-/*
- * Console
- */
-void
-serial_hw_put (int _c)
-{
- char c = _c;
- console_print(NULL, &c, 1);
-}
-
-int
-serial_hw_fetch (void)
-{
- char key;
-
- if (!xencons_ring_avail(NULL))
- return -1;
-
- read(STDIN_FILENO, &key, 1);
- switch (key) {
- case 0x7f: key = '\b'; break;
- }
- return key;
-}
-
-/*
- * PVFB
- */
-struct kbdfront_dev *kbd_dev;
-struct fbfront_dev *fb_dev;
-static union xenkbd_in_event ev;
-static int has_ev;
-int console_checkkey (void)
-{
- if (has_ev)
- return 1;
- has_ev = kbdfront_receive(kbd_dev, &ev, 1);
- return has_ev;
-}
-
-/* static QWERTY layout, that's what most PC BIOSes do anyway */
-static char linux2ascii[] = {
- [ 1 ] = 27,
- [ 2 ] = '1',
- [ 3 ] = '2',
- [ 4 ] = '3',
- [ 5 ] = '4',
- [ 6 ] = '5',
- [ 7 ] = '6',
- [ 8 ] = '7',
- [ 9 ] = '8',
- [ 10 ] = '9',
- [ 11 ] = '0',
- [ 12 ] = '-',
- [ 13 ] = '=',
- [ 14 ] = '\b',
- [ 15 ] = '\t',
- [ 16 ] = 'q',
- [ 17 ] = 'w',
- [ 18 ] = 'e',
- [ 19 ] = 'r',
- [ 20 ] = 't',
- [ 21 ] = 'y',
- [ 22 ] = 'u',
- [ 23 ] = 'i',
- [ 24 ] = 'o',
- [ 25 ] = 'p',
- [ 26 ] = '[',
- [ 27 ] = ']',
- [ 28 ] = '\n',
-
- [ 30 ] = 'a',
- [ 31 ] = 's',
- [ 32 ] = 'd',
- [ 33 ] = 'f',
- [ 34 ] = 'g',
- [ 35 ] = 'h',
- [ 36 ] = 'j',
- [ 37 ] = 'k',
- [ 38 ] = 'l',
- [ 39 ] = ';',
- [ 40 ] = '\'',
- [ 41 ] = '`',
-
- [ 43 ] = '\\',
- [ 44 ] = 'z',
- [ 45 ] = 'x',
- [ 46 ] = 'c',
- [ 47 ] = 'v',
- [ 48 ] = 'b',
- [ 49 ] = 'n',
- [ 50 ] = 'm',
- [ 51 ] = ',',
- [ 52 ] = '.',
- [ 53 ] = '/',
-
- [ 55 ] = '*',
- [ 57 ] = ' ',
-
- [ 71 ] = '7',
- [ 72 ] = '8',
- [ 73 ] = '9',
- [ 74 ] = '-',
- [ 75 ] = '4',
- [ 76 ] = '5',
- [ 77 ] = '6',
- [ 78 ] = '+',
- [ 79 ] = '1',
- [ 80 ] = '2',
- [ 81 ] = '3',
- [ 82 ] = '0',
- [ 83 ] = '.',
-
- [ 86 ] = '<',
-
- [ 96 ] = '\n',
-
- [ 98 ] = '/',
-
- [ 102 ] = 1, /* home */
- [ 103 ] = 16, /* up */
- [ 104 ] = 7, /* page up */
- [ 105 ] = 2, /* left */
- [ 106 ] = 6, /* right */
- [ 107 ] = 5, /* end */
- [ 108 ] = 14, /* down */
- [ 109 ] = 3, /* page down */
-
- [ 111 ] = 4, /* delete */
-};
-
-static char linux2ascii_shifted[] = {
- [ 1 ] = 27,
- [ 2 ] = '!',
- [ 3 ] = '@',
- [ 4 ] = '#',
- [ 5 ] = '$',
- [ 6 ] = '%',
- [ 7 ] = '^',
- [ 8 ] = '&',
- [ 9 ] = '*',
- [ 10 ] = '(',
- [ 11 ] = ')',
- [ 12 ] = '_',
- [ 13 ] = '+',
- [ 14 ] = '\b',
- [ 15 ] = '\t',
- [ 16 ] = 'Q',
- [ 17 ] = 'W',
- [ 18 ] = 'E',
- [ 19 ] = 'R',
- [ 20 ] = 'T',
- [ 21 ] = 'Y',
- [ 22 ] = 'U',
- [ 23 ] = 'I',
- [ 24 ] = 'O',
- [ 25 ] = 'P',
- [ 26 ] = '{',
- [ 27 ] = '}',
- [ 28 ] = '\n',
-
- [ 30 ] = 'A',
- [ 31 ] = 'S',
- [ 32 ] = 'D',
- [ 33 ] = 'F',
- [ 34 ] = 'G',
- [ 35 ] = 'H',
- [ 36 ] = 'J',
- [ 37 ] = 'K',
- [ 38 ] = 'L',
- [ 39 ] = ':',
- [ 40 ] = '"',
- [ 41 ] = '~',
-
- [ 43 ] = '|',
- [ 44 ] = 'Z',
- [ 45 ] = 'X',
- [ 46 ] = 'C',
- [ 47 ] = 'V',
- [ 48 ] = 'B',
- [ 49 ] = 'N',
- [ 50 ] = 'M',
- [ 51 ] = '<',
- [ 52 ] = '>',
- [ 53 ] = '?',
-
- [ 55 ] = '*',
- [ 57 ] = ' ',
-
- [ 71 ] = '7',
- [ 72 ] = '8',
- [ 73 ] = '9',
- [ 74 ] = '-',
- [ 75 ] = '4',
- [ 76 ] = '5',
- [ 77 ] = '6',
- [ 78 ] = '+',
- [ 79 ] = '1',
- [ 80 ] = '2',
- [ 81 ] = '3',
- [ 82 ] = '0',
- [ 83 ] = '.',
-
- [ 86 ] = '>',
-
- [ 96 ] = '\n',
-
- [ 98 ] = '/',
-
- [ 102 ] = 1, /* home */
- [ 103 ] = 16, /* up */
- [ 104 ] = 7, /* page up */
- [ 105 ] = 2, /* left */
- [ 106 ] = 6, /* right */
- [ 107 ] = 5, /* end */
- [ 108 ] = 14, /* down */
- [ 109 ] = 3, /* page down */
-
- [ 111 ] = 4, /* delete */
-};
-
-int console_getkey (void)
-{
- static int shift, control, alt, caps_lock;
-
- if (!has_ev)
- has_ev = kbdfront_receive(kbd_dev, &ev, 1);
- if (!has_ev)
- return 0;
-
- has_ev = 0;
- if (ev.type != XENKBD_TYPE_KEY)
- return 0;
-
- if (ev.key.keycode == 42 || ev.key.keycode == 54) {
- caps_lock = 0;
- shift = ev.key.pressed;
- return 0;
- }
- if (ev.key.keycode == 58) {
- caps_lock ^= 1;
- return 0;
- }
- if (ev.key.keycode == 29 || ev.key.keycode == 97) {
- control = ev.key.pressed;
- return 0;
- }
- if (ev.key.keycode == 56) {
- alt = ev.key.pressed;
- return 0;
- }
-
- if (!ev.key.pressed)
- return 0;
-
- if (ev.key.keycode < sizeof(linux2ascii) / sizeof(*linux2ascii)) {
- char val;
- if (shift || caps_lock)
- val = linux2ascii_shifted[ev.key.keycode];
- else
- val = linux2ascii[ev.key.keycode];
- if (control)
- val &= ~0x60;
- return val;
- }
-
- return 0;
-}
-
-static DECLARE_MUTEX_LOCKED(kbd_sem);
-static void kbd_thread(void *p)
-{
- kbd_dev = init_kbdfront(NULL, 1);
- up(&kbd_sem);
-}
-
-struct fbfront_dev *fb_open(void *fb, int width, int height, int depth)
-{
- unsigned long *mfns;
- int linesize = width * (depth / 8);
- int memsize = linesize * height;
- int numpages = (memsize + PAGE_SIZE - 1) / PAGE_SIZE;
- int i;
-
- create_thread("kbdfront", kbd_thread, &kbd_sem);
-
- mfns = malloc(numpages * sizeof(*mfns));
- for (i = 0; i < numpages; i++) {
- memset(fb + i * PAGE_SIZE, 0, PAGE_SIZE);
- mfns[i] = virtual_to_mfn(fb + i * PAGE_SIZE);
- }
- fb_dev = init_fbfront(NULL, mfns, width, height, depth, linesize,
numpages);
- free(mfns);
-
- if (!fb_dev)
- return NULL;
-
- down(&kbd_sem);
- if (!kbd_dev)
- return NULL;
-
- return fb_dev;
-}
-
-void kbd_close(void *foo)
-{
- shutdown_kbdfront(kbd_dev);
- kbd_dev = NULL;
-}
-
-void fb_close(void)
-{
- create_thread("kbdfront close", kbd_close, NULL);
- shutdown_fbfront(fb_dev);
- fb_dev = NULL;
-}
-
-/*
- * Misc
- */
-
-int getrtsecs (void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec % 10 + ((tv.tv_sec / 10) % 6) * 0x10;
-}
-
-int currticks (void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return ((tv.tv_sec * 1000000ULL + tv.tv_usec) * TICKS_PER_SEC) / 1000000;
-}
-
-void __attribute__ ((noreturn)) grub_reboot (void)
-{
- for ( ;; )
- {
- struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_reboot };
- HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
- }
-}
-
-#define SCRATCH_MEMSIZE (4 * 1024 * 1024)
-
-/* Note: not allocating it dynamically permits to make sure it lays below 4G
- * for grub's 32bit pointers to work */
-char grub_scratch_mem[SCRATCH_MEMSIZE] __attribute__((aligned(PAGE_SIZE)));
-
-int main(int argc, char **argv)
-{
- if (argc > 1 && memcmp(argv[1], "--vtpm-label=", 13) == 0) {
- vtpm_label = argv[1] + 13;
- argc--;
- argv++;
- }
-
- if (argc > 1) {
- strncpy(config_file, argv[1], sizeof(config_file) - 1);
- config_file[sizeof(config_file) - 1] = 0;
- if (!strncmp(config_file, "(nd)", 4))
- preset_menu = "dhcp";
- } else if (start_info.mod_len)
- preset_menu = (void*) start_info.mod_start;
- else
- preset_menu = "dhcp --with-configfile";
-
- mbi.drives_addr = BOOTSEC_LOCATION + (60 * 1024);
- mbi.drives_length = 0;
-
- mbi.boot_loader_name = (unsigned long) "GNU GRUB " VERSION;
- mbi.mem_lower = (start_info.nr_pages * PAGE_SIZE) / 1024;
- mbi.mem_upper = 0;
- saved_drive = boot_drive;
- saved_partition = install_partition;
-
- init_disk();
-
- /* Try to make sure the client part got launched */
- sleep(1);
- cmain();
- printk("cmain returned!\n");
-}
diff --git a/stubdom/grub/mini-os.h b/stubdom/grub/mini-os.h
deleted file mode 100644
index 9ec2bda014..0000000000
--- a/stubdom/grub/mini-os.h
+++ /dev/null
@@ -1,7 +0,0 @@
-extern int blk_nb;
-extern struct blkfront_dev **blk_dev;
-extern struct netfront_dev *net_dev;
-extern struct kbdfront_dev *kbd_dev;
-extern struct fbfront_dev *fb_dev;
-
-extern char* vtpm_label;
diff --git a/stubdom/grub/minios.cfg b/stubdom/grub/minios.cfg
deleted file mode 100644
index 5145b357e0..0000000000
--- a/stubdom/grub/minios.cfg
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG_LIBC=y
-CONFIG_LWIP=n
-CONFIG_SPARSE_BSS=n
-CONFIG_TPMFRONT=y
diff --git a/stubdom/grub/osdep.h b/stubdom/grub/osdep.h
deleted file mode 100644
index 1d3e50adbf..0000000000
--- a/stubdom/grub/osdep.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef __OSDEP_H__
-#define __OSDEP_H__
-
-#include <byteswap.h>
-#define swap32(x) bswap_32(x)
-#define swap16(x) bswap_16(x)
-
-#include <machine/endian.h>
-#if BYTE_ORDER == BIG_ENDIAN
-#define htons(x) (x)
-#define ntohs(x) (x)
-#define htonl(x) (x)
-#define ntohl(x) (x)
-#else
-#define htons(x) swap16(x)
-#define ntohs(x) swap16(x)
-#define htonl(x) swap32(x)
-#define ntohl(x) swap32(x)
-#endif
-
-typedef unsigned long Address;
-
-/* ANSI prototyping macro */
-#ifdef __STDC__
-#define P(x) x
-#else
-#define P(x) ()
-#endif
-
-#endif
--
2.54.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |