Преглед на файлове

Skip imaging target if not enough free space

Check the SD card has enough free space for the target image. If it
doesn't skip imaging the target in future checks so the log file
isn't spammed.

Modified version of
https://github.com/BlueSCSI/BlueSCSI-v2/commit/586207e80c9c28b5c1b8d251ab30c1355242930c

Co-authored-by: Eric Helgeson <erichelgeson@gmail.com>
Morio преди 2 години
родител
ревизия
e3c9f69e28
променени са 1 файла, в които са добавени 12 реда и са изтрити 2 реда
  1. 12 2
      src/ZuluSCSI_initiator.cpp

+ 12 - 2
src/ZuluSCSI_initiator.cpp

@@ -187,15 +187,16 @@ void scsiInitiatorMainLoop()
                 scsiInquiry(g_initiator_state.target_id, inquiry_data);
             LED_OFF();
 
+            uint64_t total_bytes = 0;
             if (readcapok)
             {
-                logmsg("SCSI id ", g_initiator_state.target_id,
+                logmsg("SCSI ID ", g_initiator_state.target_id,
                     " capacity ", (int)g_initiator_state.sectorcount,
                     " sectors x ", (int)g_initiator_state.sectorsize, " bytes");
 
                 g_initiator_state.sectorcount_all = g_initiator_state.sectorcount;
 
-                uint64_t total_bytes = (uint64_t)g_initiator_state.sectorcount * g_initiator_state.sectorsize;
+                total_bytes = (uint64_t)g_initiator_state.sectorcount * g_initiator_state.sectorsize;
                 logmsg("Drive total size is ", (int)(total_bytes / (1024 * 1024)), " MiB");
                 if (total_bytes >= 0xFFFFFFFF && SD.fatType() != FAT_TYPE_EXFAT)
                 {
@@ -306,6 +307,15 @@ void scsiInitiatorMainLoop()
                     return;
                 }
 
+                uint64_t sd_card_free_bytes = (uint64_t)SD.vol()->freeClusterCount() * SD.vol()->bytesPerCluster();
+                if (sd_card_free_bytes < total_bytes)
+                {
+                    logmsg("SD Card only has ", (int)(sd_card_free_bytes / (1024 * 1024)),
+                           " MiB - not enough free space to image SCSI ID ", g_initiator_state.target_id);
+                    g_initiator_state.drives_imaged = 1 << g_initiator_state.target_id;
+                    return;
+                }
+
                 g_initiator_state.target_file = SD.open(filename, O_RDWR | O_CREAT | O_TRUNC);
                 if (!g_initiator_state.target_file.isOpen())
                 {