]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
pretty boot menu entry for cdrom drives
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 21 Sep 2018 07:35:03 +0000 (09:35 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Fri, 5 Oct 2018 11:28:27 +0000 (13:28 +0200)
Show the volume label of bootable cdroms.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
src/boot.c
src/cdrom.c
src/util.h

index ff705fd47f1f22b77320c1bbcee355768fa4371a..9f82f3ca0c3e038e175c13d38656011819fc255a 100644 (file)
@@ -395,6 +395,16 @@ boot_add_hd(struct drive_s *drive, const char *desc, int prio)
 void
 boot_add_cd(struct drive_s *drive, const char *desc, int prio)
 {
+    if (GET_GLOBAL(PlatformRunningOn) & PF_QEMU) {
+        // We want short boot times.  But on physical hardware even
+        // the test unit ready can take several seconds.  So do media
+        // access on qemu only, where we know it will be fast.
+        char *extra = cdrom_media_info(drive);
+        if (extra) {
+            desc = znprintf(MAXDESCSIZE, "%s (%s)", desc, extra);
+            free(extra);
+        }
+    }
     bootentry_add(IPL_TYPE_CDROM, defPrio(prio, DefaultCDPrio)
                   , (u32)drive, desc);
 }
index 828fb3b8428c2c5666c642f9e92e680863a4835e..577d69d8125b96be77d0c1430dbab87cd2e858b6 100644 (file)
@@ -274,3 +274,49 @@ cdrom_boot(struct drive_s *drive)
 
     return 0;
 }
+
+// check if media is present and the drive is bootable.
+// in case it is return the volume label.
+char*
+cdrom_media_info(struct drive_s *drive)
+{
+    ASSERT32FLAT();
+
+    struct disk_op_s dop;
+    memset(&dop, 0, sizeof(dop));
+    dop.drive_fl = drive;
+
+    int ret = scsi_is_ready(&dop);
+    if (ret)
+        return NULL;
+
+    // Read the Boot Record Volume Descriptor
+    u8 buffer[CDROM_SECTOR_SIZE];
+    dop.command = CMD_READ;
+    dop.lba = 0x11;
+    dop.count = 1;
+    dop.buf_fl = buffer;
+    ret = process_op(&dop);
+    if (ret)
+        return NULL;
+
+    // Is it bootable?
+    if (buffer[0])
+        return NULL;
+    if (strcmp((char*)&buffer[1], "CD001\001EL TORITO SPECIFICATION") != 0)
+        return NULL;
+
+    // Read the Primary Volume Descriptor
+    dop.command = CMD_READ;
+    dop.lba = 0x10;
+    dop.count = 1;
+    dop.buf_fl = buffer;
+    ret = process_op(&dop);
+    if (ret)
+        return NULL;
+
+    // Read volume id, trim trailing spaces
+    char *volume = znprintf(30, "%s", buffer + 40);
+    nullTrailingSpace(volume);
+    return volume;
+}
index 7a23b518fcabd95c91e7b578e6182a47b3716e61..6dd080f673b2eec549b2b74c8a4e9f8b9c9ab0d9 100644 (file)
@@ -50,6 +50,7 @@ struct disk_op_s;
 int cdemu_process_op(struct disk_op_s *op);
 void cdrom_prepboot(void);
 int cdrom_boot(struct drive_s *drive_g);
+char *cdrom_media_info(struct drive_s *drive_g);
 
 // clock.c
 void clock_setup(void);