Fix for writes with sector sizes larger than 512 bytes
[SCSI2SD-V6.git] / src / firmware / disk.c
index 45b18aa0cf86bbd65bf4468972a971961983cdb0..43c58e5565f1e725e39306f4a1a9e980cbcf86f3 100755 (executable)
@@ -893,11 +893,21 @@ void scsiDiskPoll()
                 // use sg_dd from sg_utils3 tools to test.\r
 \r
                 uint32_t rem = totalSDSectors - i;\r
-                uint32_t sectors = rem < maxSectors ? rem : maxSectors;\r
+                uint32_t sectors;\r
+                if (rem <= maxSectors)\r
+                {\r
+                    sectors = rem;\r
+                }\r
+                else\r
+                {\r
+                    sectors = maxSectors;\r
+                    while (sectors % sdPerScsi) sectors--;\r
+                }\r
+                \r
 \r
                 if (useSlowDataCount)\r
                 {\r
-                    scsiSetDataCount(sectors * bytesPerSector);\r
+                    scsiSetDataCount((sectors / sdPerScsi) * bytesPerSector);\r
                 }\r
 \r
                 for (int scsiSector = i; scsiSector < i + sectors; ++scsiSector)\r