Fix for writes with sector sizes larger than 512 bytes
authorMichael McMaster <michael@codesrc.com>
Tue, 12 Oct 2021 11:44:51 +0000 (21:44 +1000)
committerMichael McMaster <michael@codesrc.com>
Tue, 12 Oct 2021 11:44:51 +0000 (21:44 +1000)
CHANGELOG
src/firmware/config.c
src/firmware/disk.c

index 9b37972e140edcd946db78b9a763f119cf12a272..7971604fef619f3688785dbc0952aba6c14cf9be 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+?               6.4.13
+    - Fix SCSI writes with sector sizes larger than 512.
+
+
 20210810        6.4.12
     - Fix USB disconnect issue when no SD card is installed.
 
index 2efb7ff21bc7d943d66f307d10a2277a5fad9a3c..451ad623a4037bcaa542292c8803706be4d26db1 100755 (executable)
@@ -36,7 +36,7 @@
 \r
 #include <string.h>\r
 \r
-static const uint16_t FIRMWARE_VERSION = 0x064C;\r
+static const uint16_t FIRMWARE_VERSION = 0x064D;\r
 \r
 // Optional static config\r
 extern uint8_t* __fixed_config;\r
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