Parcourir la source

Reinsert CD-ROM image when receiving Inquiry command

Some hosts do not issue bus reset on reboot, so this makes sure
that any ejected CD-ROMs are automatically reinserted on first
inquiry command.

This feature is enabled by default. It can be disabled in zuluscsi.ini
by setting ReinsertCDOnInquiry = 0
Petteri Aimonen il y a 2 ans
Parent
commit
249746e73f
2 fichiers modifiés avec 34 ajouts et 9 suppressions
  1. 1 0
      bluescsi.ini
  2. 33 9
      src/BlueSCSI_disk.cpp

+ 1 - 0
bluescsi.ini

@@ -30,6 +30,7 @@ MaxSyncSpeed = 10 # Set to 5 or 10 to enable synchronous SCSI mode, 0 to disable
 #HeadsPerCylinder = 255
 #RightAlignStrings = 0 # Right-align SCSI vendor / product strings, defaults on if Quirks = 1
 #PrefetchBytes = 8192 # Maximum number of bytes to prefetch after a read request, 0 to disable
+#ReinsertCDOnInquiry = 1 # Reinsert any ejected CD-ROM image on Inquiry command
 
 # Settings can be overridden for individual devices.
 [SCSI2]

+ 33 - 9
src/BlueSCSI_disk.cpp

@@ -551,6 +551,7 @@ struct image_config_t: public S2S_TargetCfg
     // For CD-ROM drive ejection
     bool ejected;
     uint8_t cdrom_events;
+    bool reinsert_on_inquiry;
 
     // Index of image, for when image on-the-fly switching is used for CD drives
     int image_index;
@@ -846,7 +847,8 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
     img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", 0, CONFIGFILE);
     img.prefetchbytes = ini_getl(section, "PrefetchBytes", img.prefetchbytes, CONFIGFILE);
-
+    img.reinsert_on_inquiry = ini_getbool(section, "ReinsertCDOnInquiry", 1, CONFIGFILE);
+    
     char tmp[32];
     memset(tmp, 0, sizeof(tmp));
     ini_gets(section, "Vendor", "", tmp, sizeof(tmp), CONFIGFILE);
@@ -1217,6 +1219,25 @@ static bool checkNextCDImage()
     return false;
 }
 
+// Reinsert any ejected CDROMs on reboot
+static void reinsertCDROM(image_config_t &img)
+{
+    if (img.image_index > 0)
+    {
+        // Multiple images for this drive, force restart from first one
+        debuglog("---- Restarting from first CD-ROM image");
+        img.image_index = 9;
+        checkNextCDImage();
+    }
+    else if (img.ejected)
+    {
+        // Reinsert the single image
+        debuglog("---- Closing CD-ROM tray");
+        img.ejected = false;
+        img.cdrom_events = 2; // New media
+    }
+}
+
 static int doTestUnitReady()
 {
     int ready = 1;
@@ -2095,6 +2116,16 @@ void scsiDiskPoll()
             image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
             checkDiskGeometryDivisible(img);
         }
+
+        // Check for Inquiry command to reinsert CD-ROMs on boot
+        if (command == 0x12)
+        {
+            image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
+            if (img.deviceType == S2S_CFG_OPTICAL && img.reinsert_on_inquiry)
+            {
+                reinsertCDROM(img);
+            }
+        }
     }
 }
 
@@ -2120,14 +2151,7 @@ void scsiDiskReset()
         image_config_t &img = g_DiskImages[i];
         if (img.deviceType == S2S_CFG_OPTICAL)
         {
-            img.ejected = false;
-            img.cdrom_events = 2; // New media
-
-            if (img.image_index > 0)
-            {
-                img.image_index = 9; // Force restart back from 0
-                checkNextCDImage();
-            }
+            reinsertCDROM(img);
         }
     }
 }