Don't write outside the requested range
[test-ssd.git] / test-ssd-write.c
index 2bce0fc8f65b3e68046e3194b008f13d040cd498..ea852481e6b94f776cf8df1b983fac7293249311 100644 (file)
@@ -8,19 +8,27 @@
  * Compile with:
  * gcc -O2 -Wall -o test-ssd-write test-ssd-write.c
  *
- * Hard disks known to stop responding with this program (requires a
+ * Hard disk setups known to stop responding with this program (requires a
  * warm machine reboot to get the drive to respond, as soft reset is not
  * enough):
  *
- * Vendor         Model          Firmware   Controller     # drives tested
- * Intel (Lenovo) SSDSC2BW180A3L LE1i       SandForce 2281 1
- * Intel (Lenovo) SSDSC2BW180A3L LF1i       SandForce 2281 2
+ * 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        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
  *
- * We ensured that the problem is not coming from other parts by running
- * this test on other SSD drives, which don't show this problem:
+ * In order to narrow down the problem, we ran this test on a number of
+ * other hardware configurations which don't show this problem:
  * 
- * Vendor         Model          Firmware   Controller     # drives tested
+ * Vendor         Model          Firmware   Controller     # drives tested         HW                 BIOS
  * Intel          SSDSA2M160G2GC 2CV102HD   Intel          1
+ * Intel          SSDSA2CW300G310 ???????   Intel          1 (over USB on 3.8 kernel)
+ * Intel          SSDSA2CT040G3  4PC10302   Intel          1 (3.2 kernel)
+ * Intel          SSDSA2CT040G3  4PC10362   Intel          1 (3.2 kernel)
+ * 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)
  *
  * Under Linux (Debian, Ubuntu, various kernels), after about 5 minutes,
  * we get this result:
@@ -71,7 +79,7 @@
 #include <string.h>
 
 enum write_mode {
-       WRITE_RANDOM,
+       WRITE_RANDOM = 0,
        WRITE_ZEROES,
 };
 
@@ -138,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 &&
@@ -236,17 +249,6 @@ int main(int argc, char **argv)
        printf("Creating file %s of length %zu, random seed %u\n", argv[1], len,
                seed);
 
-       if (strcmp(argv[4], "-r") == 0) {
-               printf("Generating random data\n");
-               write_mode = WRITE_RANDOM;
-       } else if (strcmp(argv[4], "-z") == 0) {
-               printf("Filling with zeroes (compressible pattern)\n");
-               write_mode = WRITE_ZEROES;
-       } else {
-               printf("Invalid argument %s\n", argv[4]);
-               exit(EXIT_FAILURE);
-       }
-
        for (i = 4; i < argc; i++) {
                if (strcmp(argv[i], "-z") == 0) {
                        write_mode = WRITE_ZEROES;
@@ -255,19 +257,22 @@ int main(int argc, char **argv)
                }
        }
 
-       if (verify_mode) {
-               printf("Verification mode activated.\n");
-       }
-
        switch (write_mode) {
        case WRITE_RANDOM:
+               printf("Generating random data\n");
+               break;
        case WRITE_ZEROES:
+               printf("Filling with zeroes (compressible pattern)\n");
                break;
        default:
                printf("Unsupported write-mode\n");
                exit(EXIT_FAILURE);
        }
 
+       if (verify_mode) {
+               printf("Verification mode activated.\n");
+       }
+
        /* Grow file */
        pos = lseek(fd, len - 1, SEEK_SET);
        if (pos < 0) {
This page took 0.023217 seconds and 4 git commands to generate.