Hello, Josip!

> On Wed, Dec 15, 1999 at 06:13:11PM +0900, OKUJI Yoshinori wrote:
> > > grub> root (hd0,<pressed-TAB>
> > > Error: Partition table invalid or corrupt
> > 
> >   Did you really see this error message? If a device could not be
> > opened, "Selected disk does not exist" should have happened instead.
> 
> Yes, that is the exact message. Copied and pasted from another tty.

I believe that you had a CD in the CD-ROM drive at that time. GRUB checks
if it can read all the devices that _may_ be hard disks. It could not read
the hard drive, but it could read the CD-ROM. Most (if not all) CD's have
no partition table. They just have one filesystem, usually ISO-9660.

Probably GRUB should check if the device is CD-ROM and exclude it from the
list.

The attached patch enables this check on Linux. HDIO_GETGEO works for hard
drives and floppies (the later can be considered as a bug!), but not for
CD-ROM's. Better suggestions are welcome. I prefer not to rely on bugs.

BTW, I don't quite understand what's the point in calling check_device for
floppies. Maybe another function should be written for checking for floppy
drives on systems where it can be done? It should determine whether the
drive exists, no matter is the medium inserted or not. If it's not
possible for that system, trust the user (flags --no-floppy and
--probe-second-floppy)

ChangeLog:
        * grub/asmstub.c (check_device): use low-level I/O for the device
        in question.
        [__linux__]: fail if the drive geometry cannot be determined

Pavel Roskin
Index: grub/asmstub.c
--- grub/asmstub.c      Fri Nov 19 12:41:24 1999
+++ grub/asmstub.c      Wed Dec 15 21:36:38 1999
@@ -491,10 +491,13 @@
 check_device (const char *device)
 {
   char buf[512];
-  FILE *fp;
+  int fd;
+#ifdef __linux__
+  struct hd_geometry hdg;
+#endif /* __linux__ */
 
-  fp = fopen (device, "r");
-  if (! fp)
+  fd = open (device, O_RDONLY);
+  if (fd == -1)
     {
       switch (errno)
        {
@@ -518,14 +521,19 @@
       return 0;
     }
 
+#ifdef __linux__
+  if (ioctl (fd, HDIO_GETGEO, &hdg))
+    return 0;
+#endif /* __linux__ */
+
   /* Attempt to read the first sector.  */
-  if (fread (buf, 1, 512, fp) != 512)
+  if (read (fd, buf, 512) != 512)
     {
-      fclose (fp);
+      close (fd);
       return 0;
     }
 
-  fclose (fp);
+  close (fd);
   return 1;
 }
 

Reply via email to