]> www.infradead.org Git - mtd-utils.git/commitdiff
integck.c: rework file_check_data to immediately dump the buffer containing the errors
authorElie De Brauwer <eliedebrauwer@gmail.com>
Fri, 1 Mar 2013 18:37:38 +0000 (19:37 +0100)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 11 Mar 2013 08:36:02 +0000 (10:36 +0200)
See my problem description int the previous commit, the point is that integck
in file_check_data reads a buffer, and then checks if the data is correct,  it
will do a seek(0), and reread from the same fd. The point is that in the
scenario I observed integck failed (due to a buffer mismatch) but the it saved
(and what was in flash) was actually correct. So I modified this function to
dump the buffers to stderr at the moment an error is found.

Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
tests/fs-tests/integrity/integck.c

index 2c6ffea7601848a7d7e7d7979679aca379954e7b..5ea36427681a90aa63f439184f3ec2dcbb940531 100644 (file)
@@ -1502,7 +1502,8 @@ static void file_check_data(struct file_info *file, int fd,
 {
        size_t remains, block, i;
        off_t r;
-       char buf[IO_BUFFER_SIZE];
+       unsigned char read_buf[IO_BUFFER_SIZE];
+       unsigned char check_buf[IO_BUFFER_SIZE];
        unsigned int seed = w->random_seed;
 
        if (args.power_cut_mode && !file->clean)
@@ -1517,17 +1518,28 @@ static void file_check_data(struct file_info *file, int fd,
                        block = IO_BUFFER_SIZE;
                else
                        block = remains;
-               CHECK(read(fd, buf, block) == block);
-               for (i = 0; i < block; ++i) {
-                       char c = (char)rand_r(&seed);
-                       if (buf[i] != c) {
-                               errmsg("file_check_data failed at %zu checking "
-                                      "data at %llu size %zu", w->size - remains + i,
-                                       (unsigned long long)w->offset, w->size);
-                               file_info_display(file);
-                               save_file(fd, file);
-                       }
-                       CHECK(buf[i] == c);
+               CHECK(read(fd, read_buf, block) == block);
+               for (i = 0; i < block; ++i)
+                       check_buf[i] = (char)rand_r(&seed);
+
+               if (memcmp(check_buf, read_buf, block) != 0) {
+                       errmsg("file_check_data failed, dumping "
+                               "data at offset %llu size %zu",
+                               (unsigned long long)w->offset, w->size);
+
+                       fprintf (stderr, "Read data:\n");
+                       for (r = 0; r < block; ++r)
+                               fprintf(stderr, "%02x%c",
+                                       read_buf[r], ((r+1)%16)?' ':'\n');
+                       fprintf(stderr, "\nExpected data:\n");
+                       for (r = 0; r < block; ++r)
+                               fprintf(stderr, "%02x%c",
+                                       check_buf[r], ((r+1)%16)?' ':'\n');
+                       fprintf(stderr, " \n");
+
+                       file_info_display(file);
+                       save_file(fd, file);
+                       CHECK(0);
                }
                remains -= block;
        }