btrfs: Add new test for qgroup assign functionality
[xfstests-dev.git] / src / bulkstat_null_ocount.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2019 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  *
6  * Ensure the kernel returns the new lastip even when ocount is null.
7  */
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <sys/ioctl.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <fcntl.h>
15 #include <xfs/xfs.h>
16
17 static void die(const char *tag)
18 {
19         perror(tag);
20         exit(1);
21 }
22
23 int main(int argc, char *argv[])
24 {
25         struct xfs_bstat        bstat;
26         __u64                   last;
27         struct xfs_fsop_bulkreq bulkreq = {
28                 .lastip         = &last,
29                 .icount         = 1,
30                 .ubuffer        = &bstat,
31                 .ocount         = NULL,
32         };
33         int ret;
34         int fd;
35
36         fd = open(argv[1], O_RDONLY);
37         if (fd < 0)
38                 die(argv[1]);
39
40         last = 0;
41         ret = ioctl(fd, XFS_IOC_FSINUMBERS, &bulkreq);
42         if (ret)
43                 die("inumbers");
44
45         if (last == 0)
46                 printf("inumbers last = %llu\n", (unsigned long long)last);
47
48         last = 0;
49         ret = ioctl(fd, XFS_IOC_FSBULKSTAT, &bulkreq);
50         if (ret)
51                 die("bulkstat");
52
53         if (last == 0)
54                 printf("bulkstat last = %llu\n", (unsigned long long)last);
55
56         ret = close(fd);
57         if (ret)
58                 die("close");
59
60         return 0;
61 }