Hi,

This patch lets the grub utility operate on a floppy image in the
filesystem as if it were the disk.  Let me know if it needs more work.

Thanks
-John

--- grub-0.5.92/grub/main.c~    Mon Jul 26 07:04:07 1999
+++ grub-0.5.92/grub/main.c     Wed Sep 22 03:41:59 1999
@@ -36,6 +36,7 @@
 int use_curses = 1;
 int verbose = 0;
 int read_only = 0;
+char *fake_fd0 = 0;
 static int default_boot_drive;
 static int default_install_partition;
 static char *default_config_file;
@@ -51,6 +52,7 @@
 #define OPT_BATCH -10
 #define OPT_VERBOSE -11
 #define OPT_READ_ONLY -12
+#define OPT_FAKE_FD0 -13
 #define OPTSTRING ""
 
 static struct option longopts[] =
@@ -66,6 +68,7 @@
   {"batch", no_argument, 0, OPT_BATCH},
   {"verbose", no_argument, 0, OPT_VERBOSE},
   {"read-only", no_argument, 0, OPT_READ_ONLY},
+  {"fake-fd0", required_argument, 0, OPT_FAKE_FD0},
   {0},
 };
 
@@ -90,6 +93,7 @@
     --no-config-file         do not use the config file\n\
     --no-curses              do not use curses\n\
     --read-only              do not write anything to devices\n\
+    --fake-fd0=FILE          i/o operations on \"(fd0)\" really affect FILE\n\
     --verbose                print verbose messages\n\
     --version                print version information and exit\n\
 \n\
@@ -188,7 +192,11 @@
        case OPT_VERBOSE:
          verbose = 1;
          break;
-         
+
+       case OPT_FAKE_FD0:
+         fake_fd0 = optarg;
+         break;
+
        default:
          usage (1);
        }
--- grub-0.5.92/grub/asmstub.c~ Tue Jul 13 16:39:44 1999
+++ grub-0.5.92/grub/asmstub.c  Wed Sep 22 03:25:55 1999
@@ -132,7 +132,10 @@
   memset (device_map, 0, NUM_DISKS * sizeof (char *));
 
   /* Floppies.  */
-  device_map[0] = strdup ("/dev/fd0");
+  if (fake_fd0)
+    device_map[0] = strdup (fake_fd0);
+  else
+    device_map[0] = strdup ("/dev/fd0");
 #ifndef __linux__
   /* FIXME: leave linux out for now /dev/fd1 blocks for long time
      if there is no second floppy ?  */
@@ -576,7 +579,10 @@
        {
 #ifdef __linux__
          struct hd_geometry hdg;
-         if (! ioctl (disks[drive].flags, HDIO_GETGEO, &hdg))
+         /* Ask the kernel for the drive geometry, but only if it's
+            a real device. */
+         if (! (drive == 0 && fake_fd0)
+             && ! ioctl (disks[drive].flags, HDIO_GETGEO, &hdg))
            {
              /* Got the geometry, so save it. */
              disks[drive].cylinders = hdg.cylinders;
--- grub-0.5.92/stage2/shared.h~        Tue Jul 13 11:46:28 1999
+++ grub-0.5.92/stage2/shared.h Wed Sep 22 03:28:09 1999
@@ -312,6 +312,8 @@
 extern int verbose;
 /* The flag for read-only.  */
 extern int read_only;
+/* Name of the fd0 image file, or 0 if fd0 is really /dev/fd0.  */
+extern char *fake_fd0;
 #endif
 
 #ifndef STAGE1_5
--- grub-0.5.92/docs/grub.texi~ Mon Jul 26 18:58:10 1999
+++ grub-0.5.92/docs/grub.texi  Wed Sep 22 04:08:05 1999
@@ -1235,6 +1235,12 @@
 @item --read-only
 Disable writing to any disk.
 
+@item --fake-fd0=@var{file}
+Pretend that @var{file} is the first floppy device (@samp{/dev/fd0}).
+This lets you operate on a floppy image in the filesystem as if it were
+the physical floppy disk.  In GRUB commands, @samp{fd0} will refer to
+the image @var{file} instead of the disk.
+
 @item --hold
 Wait until a debegger will attach. This option is useful when you want
 to debug the startup code.

Reply via email to