Преглед изворни кода

Merge pull request #440 from ZuluSCSI/fix/write-log-file-in-raw-mode

Do not open and write to a log file in raw mode
Alex Perez пре 1 година
родитељ
комит
3544386f3b

+ 3 - 0
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp

@@ -34,6 +34,7 @@
 #include <ZuluSCSI_audio.h>
 
 extern SdFs SD;
+extern bool g_rawdrive_active;
 
 extern "C" {
 
@@ -544,6 +545,8 @@ void platform_log(const char *s)
 
 void platform_emergency_log_save()
 {
+    if (g_rawdrive_active)
+        return;
 #ifdef ZULUSCSI_HARDWARE_CONFIG
     if (g_hw_config.is_active())
         return;

+ 5 - 0
lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform.cpp

@@ -32,6 +32,8 @@
 #include <assert.h>
 #include "usb_serial.h"
 
+extern bool g_rawdrive_active;
+
 extern "C" {
 
 const char *g_platform_name = PLATFORM_NAME;
@@ -348,6 +350,9 @@ void platform_log(const char *s)
 
 void platform_emergency_log_save()
 {
+    if (g_rawdrive_active)
+        return;
+
     platform_set_sd_callback(NULL, NULL);
 
     SD.begin(SD_CONFIG_CRASH);

+ 4 - 0
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp

@@ -54,6 +54,8 @@ extern "C" {
 #  include "audio.h"
 #endif // ENABLE_AUDIO_OUTPUT
 
+extern bool g_rawdrive_active;
+
 extern "C" {
 
 const char *g_platform_name = PLATFORM_NAME;
@@ -406,6 +408,8 @@ extern uint32_t __StackTop;
 
 void platform_emergency_log_save()
 {
+    if (g_rawdrive_active)
+        return;
     platform_set_sd_callback(NULL, NULL);
     SD.begin(SD_CONFIG_CRASH);
     FsFile crashfile = SD.open(CRASHFILE, O_WRONLY | O_CREAT | O_TRUNC);

+ 29 - 18
src/ImageBackingStore.cpp

@@ -31,9 +31,13 @@
 #include <string.h>
 #include <assert.h>
 
+extern bool g_rawdrive_active;
+
 ImageBackingStore::ImageBackingStore()
 {
+    m_iscontiguous = false;
     m_israw = false;
+    g_rawdrive_active = m_israw;
     m_isrom = false;
     m_isreadonly_attr = false;
     m_blockdev = nullptr;
@@ -60,7 +64,9 @@ ImageBackingStore::ImageBackingStore(const char *filename, uint32_t scsi_block_s
             return;
         }
 
+        m_iscontiguous = true;
         m_israw = true;
+        g_rawdrive_active = m_israw;
         m_blockdev = SD.card();
 
         uint32_t sectorCount = SD.card()->sectorCount();
@@ -103,7 +109,7 @@ ImageBackingStore::ImageBackingStore(const char *filename, uint32_t scsi_block_s
             // access overhead in SdFat library.
             // If non-aligned offsets are later requested, it automatically falls
             // back to SdFat access mode.
-            m_israw = true;
+            m_iscontiguous = true;
             m_blockdev = SD.card();
             m_bgnsector = begin;
 
@@ -128,7 +134,7 @@ ImageBackingStore::ImageBackingStore(const char *filename, uint32_t scsi_block_s
 
 bool ImageBackingStore::isOpen()
 {
-    if (m_israw)
+    if (m_iscontiguous)
         return (m_blockdev != NULL);
     else if (m_isrom)
         return (m_romhdr.imagesize > 0);
@@ -141,20 +147,25 @@ bool ImageBackingStore::isWritable()
     return !m_isrom && !m_isreadonly_attr;
 }
 
+bool ImageBackingStore::isRaw()
+{
+    return m_israw;
+}
+
 bool ImageBackingStore::isRom()
 {
     return m_isrom;
 }
 
 
-bool ImageBackingStore::isRaw()
+bool ImageBackingStore::isContiguous()
 {
-    return m_israw;
+    return m_iscontiguous;
 }
 
 bool ImageBackingStore::close()
 {
-    if (m_israw)
+    if (m_iscontiguous)
     {
         m_blockdev = nullptr;
         return true;
@@ -172,7 +183,7 @@ bool ImageBackingStore::close()
 
 uint64_t ImageBackingStore::size()
 {
-    if (m_israw && m_blockdev)
+    if (m_iscontiguous && m_blockdev)
     {
         return (uint64_t)(m_endsector - m_bgnsector + 1) * SD_SECTOR_SIZE;
     }
@@ -188,7 +199,7 @@ uint64_t ImageBackingStore::size()
 
 bool ImageBackingStore::contiguousRange(uint32_t* bgnSector, uint32_t* endSector)
 {
-    if (m_israw && m_blockdev)
+    if (m_iscontiguous && m_blockdev)
     {
         *bgnSector = m_bgnsector;
         *endSector = m_endsector;
@@ -210,13 +221,13 @@ bool ImageBackingStore::seek(uint64_t pos)
 {
     uint32_t sectornum = pos / SD_SECTOR_SIZE;
 
-    if (m_israw && (uint64_t)sectornum * SD_SECTOR_SIZE != pos)
+    if (m_iscontiguous && (uint64_t)sectornum * SD_SECTOR_SIZE != pos)
     {
         dbgmsg("---- Unaligned access to image, falling back to SdFat access mode");
-        m_israw = false;
+        m_iscontiguous = false;
     }
 
-    if (m_israw)
+    if (m_iscontiguous)
     {
         m_cursector = m_bgnsector + sectornum;
         return (m_cursector <= m_endsector);
@@ -237,13 +248,13 @@ bool ImageBackingStore::seek(uint64_t pos)
 ssize_t ImageBackingStore::read(void* buf, size_t count)
 {
     uint32_t sectorcount = count / SD_SECTOR_SIZE;
-    if (m_israw && (uint64_t)sectorcount * SD_SECTOR_SIZE != count)
+    if (m_iscontiguous && (uint64_t)sectorcount * SD_SECTOR_SIZE != count)
     {
         dbgmsg("---- Unaligned access to image, falling back to SdFat access mode");
-        m_israw = false;
+        m_iscontiguous = false;
     }
 
-    if (m_israw && m_blockdev)
+    if (m_iscontiguous && m_blockdev)
     {
         if (m_blockdev->readSectors(m_cursector, (uint8_t*)buf, sectorcount))
         {
@@ -279,13 +290,13 @@ ssize_t ImageBackingStore::read(void* buf, size_t count)
 ssize_t ImageBackingStore::write(const void* buf, size_t count)
 {
     uint32_t sectorcount = count / SD_SECTOR_SIZE;
-    if (m_israw && (uint64_t)sectorcount * SD_SECTOR_SIZE != count)
+    if (m_iscontiguous && (uint64_t)sectorcount * SD_SECTOR_SIZE != count)
     {
         dbgmsg("---- Unaligned access to image, falling back to SdFat access mode");
-        m_israw = false;
+        m_iscontiguous = false;
     }
 
-    if (m_israw && m_blockdev)
+    if (m_iscontiguous && m_blockdev)
     {
         if (m_blockdev->writeSectors(m_cursector, (const uint8_t*)buf, sectorcount))
         {
@@ -315,7 +326,7 @@ ssize_t ImageBackingStore::write(const void* buf, size_t count)
 
 void ImageBackingStore::flush()
 {
-    if (!m_israw && !m_isrom && !m_isreadonly_attr)
+    if (!m_iscontiguous && !m_isrom && !m_isreadonly_attr)
     {
         m_fsfile.flush();
     }
@@ -323,7 +334,7 @@ void ImageBackingStore::flush()
 
 uint64_t ImageBackingStore::position()
 {
-    if (!m_israw && !m_isrom)
+    if (!m_iscontiguous && !m_isrom)
     {
         return m_fsfile.curPosition();
     }

+ 6 - 2
src/ImageBackingStore.h

@@ -68,11 +68,14 @@ public:
     // Can the image be written?
     bool isWritable();
 
+    // Is this in Raw mode? by passing the file system
+    bool isRaw();
+
     // Is this internal ROM drive in microcontroller flash?
     bool isRom();
 
-    // Is this backed by raw passthrough
-    bool isRaw();
+    // Is this a contigious block on the SD card? Allowing less overhead
+    bool isContiguous();
 
     // Close the image so that .isOpen() will return false.
     bool close();
@@ -103,6 +106,7 @@ public:
     size_t getFilename(char* buf, size_t buflen);
 
 protected:
+    bool m_iscontiguous;
     bool m_israw;
     bool m_isrom;
     bool m_isreadonly_attr;

+ 4 - 0
src/ZuluSCSI.cpp

@@ -62,6 +62,7 @@
 
 SdFs SD;
 FsFile g_logfile;
+bool g_rawdrive_active;
 static bool g_romdrive_active;
 static bool g_sdcard_present;
 
@@ -139,6 +140,9 @@ void init_logfile()
     return;
 #endif
 
+  if (g_rawdrive_active)
+    return;
+
   static bool first_open_after_boot = true;
 
   bool truncate = first_open_after_boot;

+ 1 - 1
src/ZuluSCSI_config.h

@@ -28,7 +28,7 @@
 #include <ZuluSCSI_platform.h>
 
 // Use variables for version number
-#define FW_VER_NUM      "24.07.17"
+#define FW_VER_NUM      "24.07.22"
 #define FW_VER_SUFFIX   "devel"
 #define ZULU_FW_VERSION FW_VER_NUM "-" FW_VER_SUFFIX
 #define INQUIRY_NAME  PLATFORM_NAME " v" ZULU_FW_VERSION