xfstests: fix some warnings
[xfstests-dev.git] / ltp / fsx.c
index 50250bf5eee8f3803c2751347f5bef3c0b495b8d..1167d728922c12feeb4cafc0bd70835359add00b 100644 (file)
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -9,6 +9,8 @@
  *     Rewritten 8/98 by Conrad Minshall.
  *
  *     Small changes to work under Linux -- davej.
+ *
+ *     Checks for mmap last-page zero fill.
  */
 
 #include "global.h"
@@ -298,7 +300,7 @@ save_buffer(char *buffer, off_t bufferlength, int fd)
                if (size_by_seek == (off_t)-1)
                        prterr("save_buffer: lseek eof");
                else if (bufferlength > size_by_seek) {
-                       warn("save_buffer: .fsxgood file too short... will save 0x%qx bytes instead of 0x%qx\n", (unsigned long long)size_by_seek,
+                       warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
                             (unsigned long long)bufferlength);
                        bufferlength = size_by_seek;
                }
@@ -313,7 +315,7 @@ save_buffer(char *buffer, off_t bufferlength, int fd)
                if (byteswritten == -1)
                        prterr("save_buffer write");
                else
-                       warn("save_buffer: short write, 0x%x bytes instead of 0x%qx\n",
+                       warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
                             (unsigned)byteswritten,
                             (unsigned long long)bufferlength);
        }
@@ -350,7 +352,7 @@ check_buffers(unsigned offset, unsigned size)
        unsigned op = 0;
        unsigned bad = 0;
 
-       if (bcmp(good_buf + offset, temp_buf, size) != 0) {
+       if (memcmp(good_buf + offset, temp_buf, size) != 0) {
                prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
                    offset, size, fname);
                prt("OFFSET\tGOOD\tBAD\tRANGE\n");
@@ -397,7 +399,7 @@ check_size(void)
        }
        size_by_seek = lseek(fd, (off_t)0, SEEK_END);
        if (file_size != statbuf.st_size || file_size != size_by_seek) {
-               prt("Size error: expected 0x%qx stat 0x%qx seek 0x%qx\n",
+               prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
                    (unsigned long long)file_size,
                    (unsigned long long)statbuf.st_size,
                    (unsigned long long)size_by_seek);
@@ -503,6 +505,33 @@ doread(unsigned offset, unsigned size)
 }
 
 
+void
+check_eofpage(char *s, unsigned offset, char *p, int size)
+{
+       unsigned long last_page, should_be_zero;
+
+       if (offset + size <= (file_size & ~page_mask))
+               return;
+       /*
+        * we landed in the last page of the file
+        * test to make sure the VM system provided 0's 
+        * beyond the true end of the file mapping
+        * (as required by mmap def in 1996 posix 1003.1)
+        */
+       last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask;
+
+       for (should_be_zero = last_page + (file_size & page_mask);
+            should_be_zero < last_page + page_size;
+            should_be_zero++)
+               if (*(char *)should_be_zero) {
+                       prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
+                           s, file_size - 1, should_be_zero & page_mask,
+                           short_at(should_be_zero));
+                       report_failure(205);
+               }
+}
+
+
 void
 domapread(unsigned offset, unsigned size)
 {
@@ -547,6 +576,9 @@ domapread(unsigned offset, unsigned size)
                report_failure(190);
        }
        memcpy(temp_buf, p + pg_offset, size);
+
+       check_eofpage("Read", offset, p, size);
+
        if (munmap(p, map_size) != 0) {
                prterr("domapread: munmap");
                report_failure(191);
@@ -589,7 +621,7 @@ dowrite(unsigned offset, unsigned size)
        gendata(original_buf, good_buf, offset, size);
        if (file_size < offset + size) {
                if (file_size < offset)
-                       bzero(good_buf + file_size, offset - file_size);
+                       memset(good_buf + file_size, '\0', offset - file_size);
                file_size = offset + size;
                if (lite) {
                        warn("Lite file size bug in fsx!");
@@ -656,7 +688,7 @@ domapwrite(unsigned offset, unsigned size)
        gendata(original_buf, good_buf, offset, size);
        if (file_size < offset + size) {
                if (file_size < offset)
-                       bzero(good_buf + file_size, offset - file_size);
+                       memset(good_buf + file_size, '\0', offset - file_size);
                file_size = offset + size;
                if (lite) {
                        warn("Lite file size bug in fsx!");
@@ -696,6 +728,9 @@ domapwrite(unsigned offset, unsigned size)
                prterr("domapwrite: msync");
                report_failure(203);
        }
+
+       check_eofpage("Write", offset, p, size);
+
        if (munmap(p, map_size) != 0) {
                prterr("domapwrite: munmap");
                report_failure(204);
@@ -718,7 +753,7 @@ dotruncate(unsigned size)
        log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
 
        if (size > file_size)
-               bzero(good_buf + file_size, size - file_size);
+               memset(good_buf + file_size, '\0', size - file_size);
        file_size = size;
 
        if (testcalls <= simulatedopcount)
@@ -750,12 +785,12 @@ writefileimage()
                if (iret == -1)
                        prterr("writefileimage: write");
                else
-                       prt("short write: 0x%x bytes instead of 0x%qx\n",
+                       prt("short write: 0x%x bytes instead of 0x%llx\n",
                            iret, (unsigned long long)file_size);
                report_failure(172);
        }
        if (lite ? 0 : ftruncate(fd, file_size) == -1) {
-               prt("ftruncate2: %qx\n", (unsigned long long)file_size);
+               prt("ftruncate2: %llx\n", (unsigned long long)file_size);
                prterr("writefileimage: ftruncate");
                report_failure(173);
        }
@@ -1003,7 +1038,7 @@ __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
                        fprintf(stderr, "bad io length: %lu instead of %u\n",
                                        res, len);
                else {
-                       fprintf(stderr, "errcode=%d\n", -res);
+                       fprintf(stderr, "errcode=%ld\n", -res);
                        fprintf(stderr, "aio_rw: async io failed: %s\n",
                                        strerror(-res));
                        ret = res;
@@ -1274,10 +1309,10 @@ main(int argc, char **argv)
                original_buf[i] = random() % 256;
        good_buf = (char *) malloc(maxfilelen + writebdy);
        good_buf = round_up(good_buf, writebdy, 0);
-       bzero(good_buf, maxfilelen);
+       memset(good_buf, '\0', maxfilelen);
        temp_buf = (char *) malloc(maxoplen + readbdy);
        temp_buf = round_up(temp_buf, readbdy, 0);
-       bzero(temp_buf, maxoplen);
+       memset(temp_buf, '\0', maxoplen);
        if (lite) {     /* zero entire existing file */
                ssize_t written;