fstests: Replace all __[u]intNN_t types with standard [u]intNN_t
[xfstests-dev.git] / src / randholes.c
index b43da81c1fc14c55968a4b0fa4b27d830870ee00..a16670f06547be59bca9e4bdf068d3653f635590 100644 (file)
@@ -21,7 +21,7 @@
 #include "global.h"
 
 #define        power_of_2(x)   ((x) && !((x) & ((x) - 1)))
-#define        DEFAULT_FILESIZE        ((__uint64_t) (256 * 1024 * 1024))
+#define        DEFAULT_FILESIZE        ((uint64_t) (256 * 1024 * 1024))
 #define        DEFAULT_BLOCKSIZE       512
 
 #define        SETBIT(ARRAY, N)        ((ARRAY)[(N)/8] |= (1 << ((N)%8)))
@@ -30,8 +30,8 @@
 /* Bit-vector array showing which blocks have been written */
 static unsigned char   *valid;
 
-static __uint64_t filesize;
-static __uint64_t fileoffset;
+static uint64_t filesize;
+static uint64_t fileoffset;
 
 static unsigned int blocksize;
 static int count;
@@ -54,13 +54,8 @@ static int test;
  * F_FSGETXATTR (Irix).
  *
  */
-#ifdef __sgi__ /* Irix */
-#  define xfscntl(filename, fd, cmd, arg) \
-               fcntl((fd), F_ ## cmd, (arg))
-#else  /* ! __sgi__ */
 #  define xfscntl(filename, fd, cmd, arg) \
                xfsctl((filename), (fd), XFS_IOC_ ## cmd, (arg))
-#endif /* ! __sgi__ */
 
 static void
 usage(char *progname)
@@ -77,7 +72,7 @@ usage(char *progname)
        fprintf(stderr, "\tdefault count is %d block-sized writes\n",
                (int) (DEFAULT_FILESIZE / DEFAULT_BLOCKSIZE));
        fprintf(stderr, "\tdefault write_offset is %" PRIu64 " bytes\n",
-               (__uint64_t) 0);
+               (uint64_t) 0);
        exit(1);
 }
 
@@ -179,7 +174,7 @@ findblock(void)
 }
 
 static void
-dumpblock(int *buffer, __uint64_t offset, int blocksize)
+dumpblock(int *buffer, uint64_t offset, int blocksize)
 {
        int     i;
 
@@ -195,14 +190,16 @@ dumpblock(int *buffer, __uint64_t offset, int blocksize)
 static void
 writeblks(char *fname, int fd, size_t alignment)
 {
-       __uint64_t offset;
+       uint64_t offset;
        char *buffer = NULL;
        int block;
+       int ret;
        struct flock64 fl;
 
        if (!test) {
-               if (posix_memalign((void **) &buffer, alignment, blocksize)) {
-                       perror("malloc");
+               ret = posix_memalign((void **) &buffer, alignment, blocksize);
+               if (ret) {
+                       fprintf(stderr, "posix_memalign: %s\n", strerror(ret));
                        exit(1);
                }
                memset(buffer, 0, blocksize);
@@ -229,7 +226,7 @@ writeblks(char *fname, int fd, size_t alignment)
                    exit(1);
                }
 
-               offset = (__uint64_t) block * blocksize;
+               offset = (uint64_t) block * blocksize;
                if (alloconly) {
                         if (test) continue;
                         
@@ -255,8 +252,8 @@ writeblks(char *fname, int fd, size_t alignment)
                         * into it.  We'll verify this when we read
                         * it back in again.
                         */
-                       *(__uint64_t *) buffer = fileoffset + offset;
-                       *(__uint64_t *) (buffer + 256) = fileoffset + offset;
+                       *(uint64_t *) buffer = fileoffset + offset;
+                       *(uint64_t *) (buffer + 256) = fileoffset + offset;
 
                        if (write(fd, buffer, blocksize) < blocksize) {
                                perror("write");
@@ -276,7 +273,7 @@ writeblks(char *fname, int fd, size_t alignment)
 static int
 readblks(int fd, size_t alignment)
 {
-       __uint64_t offset;
+       uint64_t offset;
        char *buffer, *tmp;
        unsigned int xfer, block, i;
         int err=0;
@@ -284,8 +281,9 @@ readblks(int fd, size_t alignment)
        if (alloconly)
                return 0;
        xfer = READ_XFER*blocksize;
-       if (posix_memalign((void **) &buffer, alignment, xfer)) {
-               perror("malloc");
+       err = posix_memalign((void **) &buffer, alignment, xfer);
+       if (err) {
+               fprintf(stderr, "posix_memalign: %s\n", strerror(err));
                exit(1);
        }
        memset(buffer, 0, xfer);
@@ -307,9 +305,9 @@ readblks(int fd, size_t alignment)
                }
                tmp = buffer;
                for (i = 0; i < READ_XFER; i++) {
-                       __uint64_t want;
-                       __uint64_t first;
-                       __uint64_t second;
+                       uint64_t want;
+                       uint64_t first;
+                       uint64_t second;
 
                        if (verbose && ((block % 100) == 0)) {
                                printf("+");
@@ -317,8 +315,8 @@ readblks(int fd, size_t alignment)
                        }
 
                        want = BITVAL(valid, block) ? offset : 0;
-                       first = *(__uint64_t *) tmp;
-                       second = *(__uint64_t *) (tmp + 256);
+                       first = *(uint64_t *) tmp;
+                       second = *(uint64_t *) (tmp + 256);
                        if (first != want || second != want) {
                                printf("mismatched data at offset=0x%" PRIx64
                                        ", expected 0x%" PRIx64
@@ -439,6 +437,7 @@ main(int argc, char *argv[])
                perror("malloc");
                return 1;
        }
+       memset(valid, 0, size);
 
        /* Lots of arguments affect how we open the file */
        oflags = test ? O_RDONLY : O_RDWR|O_CREAT;