Path: blob/main/sys/contrib/openzfs/tests/zfs-tests/cmd/getversion.c
48529 views
// SPDX-License-Identifier: CDDL-1.01/*2* This file and its contents are supplied under the terms of the3* Common Development and Distribution License ("CDDL"), version 1.0.4* You may only use this file in accordance with the terms of version5* 1.0 of the CDDL.6*7* A full copy of the text of the CDDL should have accompanied this8* source. A copy of the CDDL is also available via the Internet at9* http://www.illumos.org/license/CDDL.10*/1112/*13* Copyright 2021 iXsystems, Inc.14*/1516/*17* FreeBSD and macOS expose file generation number through stat(2) and stat(1).18* Linux exposes it instead through an ioctl.19*/2021#include <sys/ioctl.h>22#ifdef _KERNEL23#include <sys/fcntl.h>24#else25#include <fcntl.h>26#endif27#include <linux/fs.h>28#include <err.h>29#include <stdio.h>30#include <stdlib.h>31#include <unistd.h>3233int34main(int argc, const char * const argv[])35{36if (argc != 2)37errx(EXIT_FAILURE, "usage: %s filename", argv[0]);3839int fd = open(argv[1], O_RDONLY);40if (fd == -1)41err(EXIT_FAILURE, "failed to open %s", argv[1]);4243int gen = 0;44if (ioctl(fd, FS_IOC_GETVERSION, &gen) == -1)45err(EXIT_FAILURE, "FS_IOC_GETVERSION failed");4647(void) close(fd);4849(void) printf("%d\n", gen);5051return (EXIT_SUCCESS);52}535455