tests: fix uClibc for getversion.c
[zfs.git] / tests / zfs-tests / cmd / getversion.c
blob3626d1e968a3161719d5e75d8631f67a7e4b2742
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2021 iXsystems, Inc.
17 * FreeBSD and macOS expose file generation number through stat(2) and stat(1).
18 * Linux exposes it instead through an ioctl.
21 #include <sys/ioctl.h>
22 #ifdef _KERNEL
23 #include <sys/fcntl.h>
24 #else
25 #include <fcntl.h>
26 #endif
27 #include <linux/fs.h>
28 #include <err.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
33 int
34 main(int argc, const char * const argv[])
36 if (argc != 2)
37 errx(EXIT_FAILURE, "usage: %s filename", argv[0]);
39 int fd = open(argv[1], O_RDONLY);
40 if (fd == -1)
41 err(EXIT_FAILURE, "failed to open %s", argv[1]);
43 int gen = 0;
44 if (ioctl(fd, FS_IOC_GETVERSION, &gen) == -1)
45 err(EXIT_FAILURE, "FS_IOC_GETVERSION failed");
47 (void) close(fd);
49 (void) printf("%d\n", gen);
51 return (EXIT_SUCCESS);