summaryrefslogtreecommitdiff
path: root/src/bulkstat_null_ocount.c
blob: b8f8fd39f990d9361754171c5389cbf87473b953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2019 Oracle.  All Rights Reserved.
 * Author: Darrick J. Wong <darrick.wong@oracle.com>
 *
 * Ensure the kernel returns the new lastip even when ocount is null.
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <xfs/xfs.h>

static void die(const char *tag)
{
	perror(tag);
	exit(1);
}

int main(int argc, char *argv[])
{
	struct xfs_bstat	bstat;
	__u64			last;
	struct xfs_fsop_bulkreq bulkreq = {
		.lastip		= &last,
		.icount		= 1,
		.ubuffer	= &bstat,
		.ocount		= NULL,
	};
	int ret;
	int fd;

	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		die(argv[1]);

	last = 0;
	ret = ioctl(fd, XFS_IOC_FSINUMBERS, &bulkreq);
	if (ret)
		die("inumbers");

	if (last == 0)
		printf("inumbers last = %llu\n", (unsigned long long)last);

	last = 0;
	ret = ioctl(fd, XFS_IOC_FSBULKSTAT, &bulkreq);
	if (ret)
		die("bulkstat");

	if (last == 0)
		printf("bulkstat last = %llu\n", (unsigned long long)last);

	ret = close(fd);
	if (ret)
		die("close");

	return 0;
}