Kaynağa Gözat

Merge pull request #83 from ZuluSCSI/fix_image_reported_size

Limit drive capacity to actual file size (#80)
Alex Perez 3 yıl önce
ebeveyn
işleme
d8a0718dfb
1 değiştirilmiş dosya ile 18 ekleme ve 2 silme
  1. 18 2
      src/ZuluSCSI_disk.cpp

+ 18 - 2
src/ZuluSCSI_disk.cpp

@@ -96,15 +96,31 @@ public:
         {
             m_fsfile = SD.open(filename, O_RDWR);
 
+            uint32_t sectorcount = m_fsfile.size() / SD_SECTOR_SIZE;
             uint32_t begin = 0, end = 0;
-            if (m_fsfile.contiguousRange(&begin, &end))
+            if (m_fsfile.contiguousRange(&begin, &end) && end >= begin + sectorcount)
             {
                 // Convert to raw mapping, this avoids some unnecessary
                 // access overhead in SdFat library.
                 m_israw = true;
                 m_blockdev = SD.card();
                 m_bgnsector = begin;
-                m_endsector = end;
+
+                if (end != begin + sectorcount)
+                {
+                    uint32_t allocsize = end - begin + 1;
+                    azlog("---- NOTE: File ", filename, " has FAT allocated size of ", (int)allocsize, " sectors and file size of ", (int)sectorcount, " sectors");
+                    azlog("---- Due to issue #80 in ZuluSCSI version 1.0.8 and 1.0.9 the allocated size was mistakenly reported to SCSI controller.");
+                    azlog("---- If the drive was formatted using those versions, you may have problems accessing it with newer firmware.");
+                    azlog("---- The old behavior can be restored with setting  [SCSI] UseFATAllocSize = 1 in " CONFIGFILE);
+
+                    if (ini_getbool("SCSI", "UseFATAllocSize", 0, CONFIGFILE))
+                    {
+                        sectorcount = allocsize;
+                    }
+                }
+
+                m_endsector = begin + sectorcount - 1;
                 m_fsfile.close();
             }
         }