This patch allows the user to do something like:
     /sbin/grub --root='(hd0,1)'
Further it prints the current root is the `root' command is given
     without parameters.

KR
--
Klaus Reichl @ HOME     email: [EMAIL PROTECTED] 

ChangeLog:
        * stage2/builtins.c (root_func): If root is given without
        argument, print the current root.
        * docs/user-ref.texi (Command-line-specific commands): Document
        it. 

        * grub/asmstub.c (root_device): New variable.
        * stage2/shared.h: ditto.

        * grub/main.c (OPT_ROOT): New option.
        (longopts): --root
        (usage): document.
        (main): setup

        * stage2/stage2.c (cmain) [GRUB_UTIL]: In grub shell, check if a
        root has been given, and set it up.

Patch:
diff -ru --exclude-from=exclude.grub grub-99-11-06/docs/user-ref.texi 
grub/docs/user-ref.texi
--- grub-99-11-06/docs/user-ref.texi    Sat Nov  6 17:11:41 1999
+++ grub/docs/user-ref.texi     Sat Nov  6 21:17:18 1999
@@ -921,8 +921,8 @@
 hex format.
 @end deffn
 
-@deffn Command root device [hdbias]
-Set the current @dfn{root device} to the device @var{device}, then
+@deffn Command root [device [hdbias]]
+Print or set the current @dfn{root device} to the device @var{device}, then
 attempt to mount it to get the partition size (for passing the partition
 descriptor in @code{ES:ESI}, used by some chain-loaded boot loaders), the
 BSD drive-type (for booting BSD kernels using their native boot format),
diff -ru --exclude-from=exclude.grub grub-99-11-06/grub/asmstub.c grub/grub/asmstub.c
--- grub-99-11-06/grub/asmstub.c        Sat Nov  6 17:11:42 1999
+++ grub/grub/asmstub.c Sat Nov  6 21:35:58 1999
@@ -83,6 +83,7 @@
 unsigned long boot_drive = 0;
 char version_string[] = VERSION;
 char config_file[128] = "/boot/grub/menu.lst"; /* FIXME: arbitrary */
+char root_device[128];
 
 /* Emulation requirements. */
 char *grub_scratch_mem = 0;
diff -ru --exclude-from=exclude.grub grub-99-11-06/grub/main.c grub/grub/main.c
--- grub-99-11-06/grub/main.c   Thu Oct 14 01:02:03 1999
+++ grub/grub/main.c    Sat Nov  6 20:32:20 1999
@@ -58,6 +58,7 @@
 #define OPT_PROBE_SECOND_FLOPPY -13
 #define OPT_NO_FLOPPY -14
 #define OPT_DEVICE_MAP -15
+#define OPT_ROOT -16       
 #define OPTSTRING ""
 
 static struct option longopts[] =
@@ -74,6 +75,7 @@
   {"no-floppy", no_argument, 0, OPT_NO_FLOPPY},
   {"probe-second-floppy", no_argument, 0, OPT_PROBE_SECOND_FLOPPY},
   {"read-only", no_argument, 0, OPT_READ_ONLY},
+  {"root", required_argument, 0, OPT_ROOT},
   {"verbose", no_argument, 0, OPT_VERBOSE},
   {"version", no_argument, 0, OPT_VERSION},
   {0},
@@ -103,6 +105,7 @@
     --no-floppy              do not probe any floppy drive\n\
     --probe-second-floppy    probe the second floppy drive\n\
     --read-only              do not write anything to devices\n\
+    --root=DEVICE            set boot_drive and install_partition from root\n\
     --verbose                print verbose messages\n\
     --version                print version information and exit\n\
 \n\
@@ -179,6 +182,11 @@
              perror ("strtoul");
              exit (1);
            }
+         break;
+
+       case OPT_ROOT:
+         strncpy (root_device, optarg, 127);
+         root_device[127] = '\0';
          break;
 
        case OPT_NO_CONFIG_FILE:
diff -ru --exclude-from=exclude.grub grub-99-11-06/stage2/builtins.c 
grub/stage2/builtins.c
--- grub-99-11-06/stage2/builtins.c     Sat Nov  6 17:11:46 1999
+++ grub/stage2/builtins.c      Sat Nov  6 20:58:09 1999
@@ -1849,6 +1849,35 @@
   char *biasptr;
   char *next;
 
+  /* If arg is empty just print current value */
+  if (!arg[0])
+    {
+      /* check if drive/partition is plausible */
+      if (!open_partition ())
+       grub_printf (" Current drive 0x%x, current partition 0x%x\n",
+                    current_drive, current_partition);
+      else
+       {
+         grub_printf (" root=(");
+         if (current_drive == 0x20)
+           grub_printf ("nd");
+         else if (current_drive >= 0x80)
+           {
+             grub_printf ("hd%d,%d", 
+                          current_drive - 0x80,
+                          /* XXX: Is this correct in any case? */
+                          current_partition >> 16);
+           }
+         else
+           {
+             grub_printf ("fd%d", current_drive);
+           }
+         grub_printf (")\n");
+       }
+
+      return 0;
+    }
+
   /* Call set_device to get the drive and the partition in ARG.  */
   next = set_device (arg);
   if (! next)
diff -ru --exclude-from=exclude.grub grub-99-11-06/stage2/shared.h grub/stage2/shared.h
--- grub-99-11-06/stage2/shared.h       Sat Nov  6 17:11:47 1999
+++ grub/stage2/shared.h        Sat Nov  6 20:42:15 1999
@@ -430,6 +430,8 @@
 extern char **device_map;
 /* The filename which stores the information about a device map.  */
 extern char *device_map_file;
+/* The root device specified by the user */
+extern char root_device[];
 /* The array of geometries.  */
 extern struct geometry *disks;
 /* Check if DEVICE can be read. If an error occurs, return zero,
diff -ru --exclude-from=exclude.grub grub-99-11-06/stage2/stage2.c grub/stage2/stage2.c
--- grub-99-11-06/stage2/stage2.c       Fri Oct 29 06:33:04 1999
+++ grub/stage2/stage2.c        Sat Nov  6 20:44:23 1999
@@ -583,6 +583,24 @@
   /* Initialize the kill buffer.  */
   *kill = 0;
   
+#ifdef GRUB_UTIL
+  /* Setup possible root given by user */
+  if (root_device[0]) 
+  {
+    struct builtin *builtin;
+
+    builtin = find_command ("root");
+    if ((builtin->func) (root_device, BUILTIN_CMDLINE))
+      {
+       extern int sleep (int secs); /* XXX */
+       
+       grub_printf ("\nError: %s\n", err_list[errnum]);
+       /* How to tell the user, that something goes wrong here? */ 
+       sleep (2);
+      }
+  }
+#endif
+
   /* Never return.  */
   for (;;)
     {

Reply via email to