From 4b4e0baa1390061c8de437d50069a0e4475521ff Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Sat, 7 Oct 2023 11:38:51 -0500 Subject: [PATCH] initiator: don't start imaging if there's not enough space on the sd card --- src/BlueSCSI_initiator.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/BlueSCSI_initiator.cpp b/src/BlueSCSI_initiator.cpp index 58431dbe..0ea7453b 100644 --- a/src/BlueSCSI_initiator.cpp +++ b/src/BlueSCSI_initiator.cpp @@ -157,6 +157,7 @@ void scsiInitiatorMainLoop() scsiInquiry(g_initiator_state.target_id, inquiry_data); LED_OFF(); + uint64_t total_bytes = 0; if (readcapok) { log("SCSI ID ", g_initiator_state.target_id, @@ -165,7 +166,7 @@ void scsiInitiatorMainLoop() 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; log("Drive total size is ", (int)(total_bytes / (1024 * 1024)), " MiB"); if (total_bytes >= 0xFFFFFFFF && SD.fatType() != FAT_TYPE_EXFAT) { @@ -208,6 +209,14 @@ void scsiInitiatorMainLoop() strncpy(filename, filename_format, sizeof(filename) - 1); filename[2] += g_initiator_state.target_id; + uint64_t sd_card_free_bytes = (uint64_t)SD.vol()->freeClusterCount() * SD.vol()->bytesPerCluster(); + if(sd_card_free_bytes < total_bytes) + { + log("SD Card only has ", (int)(sd_card_free_bytes / (1024 * 1024)), " MiB - not enough free space to image this drive!"); + g_initiator_state.imaging = false; + return; + } + while(SD.exists(filename)) { filename[3] = lun++ + '0';