unwritten_sync: convert XFS_IOC_FREESP64 to ftruncate
[xfstests-dev.git] / src / ext4_resize.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Test program which uses the raw ext4 resize_fs ioctl directly.
5  */
6
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <errno.h>
10 #include <unistd.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <sys/ioctl.h>
14 #include <sys/mount.h>
15
16 typedef unsigned long long __u64;
17
18 #ifndef EXT4_IOC_RESIZE_FS
19 #define EXT4_IOC_RESIZE_FS              _IOW('f', 16, __u64)
20 #endif
21
22 int main(int argc, char **argv)
23 {
24         __u64   new_size;
25         int     error, fd;
26         char    *tmp = NULL;
27
28         if (argc != 3) {
29                 fputs("insufficient arguments\n", stderr);
30                 return 1;
31         }
32         fd = open(argv[1], O_RDONLY);
33         if (!fd) {
34                 perror(argv[1]);
35                 return 1;
36         }
37
38         new_size = strtoull(argv[2], &tmp, 10);
39         if ((errno) || (*tmp != '\0')) {
40                 fprintf(stderr, "%s: invalid new size\n", argv[0]);
41                 return 1;
42         }
43
44         error = ioctl(fd, EXT4_IOC_RESIZE_FS, &new_size);
45         if (error < 0) {
46                 perror("EXT4_IOC_RESIZE_FS");
47                 return 1;
48         }
49         return 0;
50 }