Parcourir la source

Fix problems with 256 byte sector size (#97)

The raw mapping only works when SCSI sector size is a multiple of SD card sector size.
Otherwise we must go through the SdFat code to convert smaller reads / writes.
Petteri Aimonen il y a 3 ans
Parent
commit
e1819ac981
1 fichiers modifiés avec 10 ajouts et 3 suppressions
  1. 10 3
      src/ZuluSCSI_disk.cpp

+ 10 - 3
src/ZuluSCSI_disk.cpp

@@ -68,7 +68,7 @@ public:
         m_bgnsector = m_endsector = m_cursector = 0;
     }
 
-    ImageBackingStore(const char *filename): ImageBackingStore()
+    ImageBackingStore(const char *filename, uint32_t scsi_block_size): ImageBackingStore()
     {
         if (strncasecmp(filename, "RAW:", 4) == 0)
         {
@@ -82,6 +82,12 @@ public:
                 return;
             }
 
+            if ((scsi_block_size % SD_SECTOR_SIZE) != 0)
+            {
+                azlog("SCSI block size ", (int)scsi_block_size, " is not supported for RAW partitions (must be divisible by 512 bytes)");
+                return;
+            }
+
             m_israw = true;
             m_blockdev = SD.card();
 
@@ -98,7 +104,8 @@ public:
 
             uint32_t sectorcount = m_fsfile.size() / SD_SECTOR_SIZE;
             uint32_t begin = 0, end = 0;
-            if (m_fsfile.contiguousRange(&begin, &end) && end >= begin + sectorcount)
+            if (m_fsfile.contiguousRange(&begin, &end) && end >= begin + sectorcount
+                && (scsi_block_size % SD_SECTOR_SIZE) == 0)
             {
                 // Convert to raw mapping, this avoids some unnecessary
                 // access overhead in SdFat library.
@@ -421,7 +428,7 @@ static void setDefaultDriveInfo(int target_idx)
 bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int scsi_lun, int blocksize, S2S_CFG_TYPE type)
 {
     image_config_t &img = g_DiskImages[target_idx];
-    img.file = ImageBackingStore(filename);
+    img.file = ImageBackingStore(filename, blocksize);
 
     if (img.file.isOpen())
     {