unwritten_sync: convert XFS_IOC_FREESP64 to ftruncate
[xfstests-dev.git] / src / unwritten_sync.c
index 6cdf7e8a777ee5bf45dbb9a97ac32295a4d306d9..45ac7df9709be0b5d98c0b0be68c3f0c8809d247 100644 (file)
@@ -1,3 +1,5 @@
+#include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <errno.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;
        off_t offset;
        char    *file;
        int     loops;
+       char    *dio_env;
 
        if(argc != 3) {
                fprintf(stderr, "%s <loops> <file>\n", argv[0]);
 
        if(argc != 3) {
                fprintf(stderr, "%s <loops> <file>\n", argv[0]);
@@ -53,6 +56,10 @@ main(int argc, char *argv[])
                        exit(1);
                }
 
                        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",
                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);
 
 
                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);
        }
                print_getbmapx(file, fd, 0, 0);
                close(fd);
        }