]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2002-04-06 Yoshinori K. Okuji <okuji@enbug.org>
authorokuji <okuji@localhost>
Sat, 6 Apr 2002 12:15:13 +0000 (12:15 +0000)
committerokuji <okuji@localhost>
Sat, 6 Apr 2002 12:15:13 +0000 (12:15 +0000)
* stage2/builtins.c [GRUB_UTIL] (dump_func): New function.
[GRUB_UTIL] (builtin_dump): New variable.
(builtin_table) [GRUB_UTIL]: Added a pointer to BUILTIN_DUMP.
* util/grub-install.in: Make sure that GRUB reads the same
images as the host operating system by comparing the result of
running the command "dump" with the contents of the OS file.

ChangeLog
NEWS
docs/grub-install.8
stage2/builtins.c
util/grub-install.in

index e19dcaa9af27f87bf205baf5f951f0e87471a5e9..a62cd2d16779a0cf65c7136e47a231ab7da0b3c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2002-04-06  Yoshinori K. Okuji  <okuji@enbug.org>
+
+       * stage2/builtins.c [GRUB_UTIL] (dump_func): New function.
+       [GRUB_UTIL] (builtin_dump): New variable.
+       (builtin_table) [GRUB_UTIL]: Added a pointer to BUILTIN_DUMP.
+       * util/grub-install.in: Make sure that GRUB reads the same
+       images as the host operating system by comparing the result of
+       running the command "dump" with the contents of the OS file.
+       
 2002-04-04  Yoshinori K. Okuji  <okuji@enbug.org>
 
        * stage2/builtins.c (setup_func): Don't embed a drive number, if
diff --git a/NEWS b/NEWS
index 68105444fb4984008ac0e6b8e44b29666d69302e..b92ec73cf67851f6a796514b2ce3bf787e089ad1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,9 @@ New in 0.92:
 * A fallback entry is executed immediately after a default entry,
   without prompting a user's intervention, as the manual has ever been
   saying.
+* The utility ``grub-install'' makes sure that GRUB images have been
+  written to a physical disk completely. To assist this feature, a new
+  command "dump" is added.
 
 New in 0.91 - 2002-01-21:
 * Support for Linux DAC960 is added.
index ad304071fc5cda55feb8895df1283fefc0ea2ec2..d8c8b26df6f995c1eca57cb591813ab258ede455 100644 (file)
@@ -1,5 +1,5 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
-.TH GRUB-INSTALL "8" "March 2002" "grub-install (GNU GRUB 0.92)" FSF
+.TH GRUB-INSTALL "8" "April 2002" "grub-install (GNU GRUB 0.92)" FSF
 .SH NAME
 grub-install \- install GRUB on your drive
 .SH SYNOPSIS
index 0792f9388f3aff0264320fbecc08bae24d22a291..8425f573850ef1cc32136a18922a28de594de22a 100644 (file)
@@ -973,6 +973,66 @@ static struct builtin builtin_displaymem =
   " machine is, including all regions of physical RAM installed."
 };
 
+\f
+/* dump FROM TO */
+#ifdef GRUB_UTIL
+static int
+dump_func (char *arg, int flags)
+{
+  char *from, *to;
+  FILE *fp;
+  char c;
+  
+  from = arg;
+  to = skip_to (0, arg);
+  if (! *from || ! *to)
+    {
+      errnum = ERR_BAD_ARGUMENT;
+      return 1;
+    }
+
+  nul_terminate (from);
+  nul_terminate (to);
+  
+  if (! grub_open (from))
+    return 1;
+
+  fp = fopen (to, "w");
+  if (! fp)
+    {
+      errnum = ERR_WRITE;
+      return 1;
+    }
+
+  while (grub_read (&c, 1))
+    if (fputc (c, fp) == EOF)
+      {
+       errnum = ERR_WRITE;
+       fclose (fp);
+       return 1;
+      }
+
+  if (fclose (fp) == EOF)
+    {
+      errnum = ERR_WRITE;
+      return 1;
+    }
+
+  grub_close ();
+  return 0;
+}
+
+static struct builtin builtin_dump =
+  {
+    "dump",
+    dump_func,
+    BUILTIN_CMDLINE,
+    "dump FROM TO",
+    "Dump the contents of the file FROM to the file TO. FROM must be"
+    " a GRUB file and TO must be an OS file."
+  };
+#endif /* GRUB_UTIL */
+
 \f
 static char embed_info[32];
 /* embed */
@@ -4528,6 +4588,9 @@ struct builtin *builtin_table[] =
 #endif /* SUPPORT_NETBOOT */
   &builtin_displayapm,
   &builtin_displaymem,
+#ifdef GRUB_UTIL
+  &builtin_dump,
+#endif /* GRUB_UTIL */
   &builtin_embed,
   &builtin_fallback,
   &builtin_find,
index a04d8bf5eac682026905dd9dde5c59e7aa856c58..e3fef53208d1b23c535ef254051513faa2af8862 100644 (file)
@@ -1,7 +1,7 @@
 #! /bin/sh
 
 # Install GRUB on your drive.
-#   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+#   Copyright (C) 1999,2000,2001,2002 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ pkgdatadir=${datadir}/${PACKAGE}/${host_cpu}-${host_vendor}
 
 grub_shell=${sbindir}/grub
 log_file=/tmp/grub-install.log.$$
+img_file=/tmp/grub-install.img.$$
 rootdir=
 grub_prefix=/boot/grub
 
@@ -41,11 +42,14 @@ debug=no
 
 # look for secure tempfile creation wrappers on this platform
 if test -x /bin/tempfile; then
-    mkstemp="/bin/tempfile --prefix=grub"
+    mklog="/bin/tempfile --prefix=grub"
+    mkimg="/bin/tempfile --prefix=grub"
 elif test -x /bin/mktemp; then
-    mkstemp="/bin/mktemp /tmp/grub-install.log.XXXXXX"
+    mklog="/bin/mktemp /tmp/grub-install.log.XXXXXX"
+    mkimg="/bin/mktemp /tmp/grub-install.img.XXXXXX"
 else
-    mkstemp=""
+    mklog=""
+    mkimg=""
 fi
 
 # Usage: usage
@@ -306,7 +310,7 @@ if test -f "$device_map"; then
     :
 else
     # Create a safe temporary file.
-    test -n "$mkstemp" && log_file=`$mkstemp`
+    test -n "$mklog" && log_file=`$mklog`
 
     $grub_shell --batch --device-map=$device_map <<EOF >$log_file
 quit
@@ -375,8 +379,37 @@ for file in \
     cp -f $file ${grubdir} || exit 1
 done
 
+# Make sure that GRUB reads the same images as the host OS.
+test -n "$mkimg" && img_file=`$mkimg`
+test -n "$mklog" && log_file=`$mklog`
+
+for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
+    count=5
+    tmp=`echo $file | sed "s|^${grubdir}|${grub_prefix}|"`
+    while test $count -gt 0; do
+       $grub_shell --batch --device-map=$device_map <<EOF >$log_file
+dump ${root_drive}${tmp} ${img_file}
+quit
+EOF
+       if grep "Error [0-9]*: " $log_file >/dev/null; then
+           :
+       elif cmp $file $img_file >/dev/null; then
+           break
+       fi
+       sleep 1
+       count=`expr $count - 1`    
+    done
+    if test $count -eq 0; then
+       echo "The file $file not read correctly." 1>&2
+       exit 1
+    fi
+done
+
+rm -f $img_file
+rm -f $log_file
+
 # Create a safe temporary file.
-test -n "$mkstemp" && log_file=`$mkstemp`
+test -n "$mklog" && log_file=`$mklog`
 
 # Now perform the installation.
 $grub_shell --batch --device-map=$device_map <<EOF >$log_file