Don't write outside the requested range
[test-ssd.git] / test-ssd-write.c
index 44fdd91f486a9ed4f17a85c87de53b1162716162..ea852481e6b94f776cf8df1b983fac7293249311 100644 (file)
@@ -14,8 +14,9 @@
  *
  * Vendor         Model          Firmware   Controller     # drives tested         HW                 BIOS
  * Intel (Lenovo) SSDSC2BW180A3L LE1i       SandForce 2281 1 (3.5 Debian kernel)   Lenovo x230        G2ET90WW (2.50) 2012-20-12
- * Intel (Lenovo) SSDSC2BW180A3L LF1i       SandForce 2281 2 (3.2 Debian kernel)   Lenovo x230
+ * Intel (Lenovo) SSDSC2BW180A3L LF1i       SandForce 2281 2 (3.2 Debian kernel)   Lenovo x230        G2ET90WW (2.50) 2012-20-12
  * Intel (Lenovo) SSDSC2BW180A3L LF1i       SandForce 2281 1 (3.7.9 Arch kernel)   Lenovo x230        G2ET86WW (2.06) 2012-11-13
+ * Intel (Lenovo) SSDSC2BW180A3L LF1i       SandForce 2281 1 (3.2 Debian kernel)   Lenovo x200
  *
  * In order to narrow down the problem, we ran this test on a number of
  * other hardware configurations which don't show this problem:
@@ -28,7 +29,6 @@
  * Intel          SSDSC2CT120A3K5 ???????   SandForce 2281 1 (on HP SmartArray P212 with 3.2 kernel)
  * OCZ            OCZ-VERTEX3        2.25   SF-2281        1 (3.7.9 Arch kernel)
  * OCZ            OCZSSD2-2VTXE180G  1.37   SF-1200        1 (3.7.6 Arch kernel)
- * Intel (Lenovo) SSDSC2BW180A3L LF1i       SandForce 2281 3 (3.2 Debian kernel)   Lenovo x200
  *
  * Under Linux (Debian, Ubuntu, various kernels), after about 5 minutes,
  * we get this result:
@@ -146,13 +146,18 @@ static int rand_write(int fd, size_t len)
        uint64_t valcount;
        int ret;
 
+       if (len < BUFLEN) {
+               fprintf(stderr, "Error: File size needs to be at least %u\n", BUFLEN);
+               exit(EXIT_FAILURE);
+       }
+
        memset(buf, 0, BUFLEN);
 
        for (;;) {
                if (len > UINT32_MAX) {
-                       offset = (((size_t) rand() << 32) + (size_t) rand()) % len;
+                       offset = (((size_t) rand() << 32) + (size_t) rand()) % (len - BUFLEN);
                } else {
-                       offset = rand() % len;
+                       offset = rand() % (len - BUFLEN);
                }
 
                if ((offset >= validate_offset &&
This page took 0.023138 seconds and 4 git commands to generate.