unwritten_sync: convert XFS_IOC_FREESP64 to ftruncate
[xfstests-dev.git] / src / unwritten_sync.c
index 454eba066a04bd4bb0046e5813bf8a66fc88ad37..45ac7df9709be0b5d98c0b0be68c3f0c8809d247 100644 (file)
@@ -1,3 +1,5 @@
+#include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -27,6 +29,7 @@ main(int argc, char *argv[])
        off_t offset;
        char    *file;
        int     loops;
+       char    *dio_env;
 
        if(argc != 3) {
                fprintf(stderr, "%s <loops> <file>\n", argv[0]);
@@ -53,6 +56,10 @@ main(int argc, char *argv[])
                        exit(1);
                }
 
+               dio_env = getenv("XFS_DIO_MIN");
+               if (dio_env)
+                       dio.d_mem = dio.d_miniosz = atoi(dio_env);
+
                if ((dio.d_miniosz > IO_SIZE) || (dio.d_maxiosz < IO_SIZE)) {
                        fprintf(stderr, "Test won't work - iosize out of range"
                                " (dio.d_miniosz=%d, dio.d_maxiosz=%d)\n",
@@ -85,10 +92,11 @@ main(int argc, char *argv[])
 
                print_getbmapx(file, fd, 0, 0);
 
-               flock.l_whence = 0;
-               flock.l_start= 0;
-               flock.l_len = 0;
-               xfsctl(file, fd, XFS_IOC_FREESP64, &flock);
+               if (ftruncate(fd, 0)) {
+                       perror("ftruncate");
+                       exit(1);
+               }
+
                print_getbmapx(file, fd, 0, 0);
                close(fd);
        }
@@ -136,7 +144,9 @@ again:
                }
                if (bmapx[x].bmv_oflags & 1) {
                        fprintf(stderr, "FOUND ONE %lld %lld %x\n",
-                               bmapx[x].bmv_offset, bmapx[x].bmv_length,bmapx[x].bmv_oflags);
+                               (long long) bmapx[x].bmv_offset,
+                               (long long) bmapx[x].bmv_length,
+                               bmapx[x].bmv_oflags);
                        foundone = 1;
                        foundany = 1;
                }