Autogen update
[nfs-utils.git] / tools / getiversion / getiversion.c
1 /*
2  * getiversion
3  *
4  * Get version number for an inode on an ext2 file system.
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #ifdef HAVE_SYS_IOCTL_H
12 #include <sys/ioctl.h>
13 #endif
14
15 #ifdef HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18
19 #ifdef HAVE_FCNTL_H
20 #include <fcntl.h>
21 #endif
22
23 #include <stdio.h>
24 #include <sys/fs/ext2fs.h>
25
26 int
27 main(int argc, char **argv)
28 {
29         int     i, fd;
30         u_int32_t       vers;
31
32         if (argc <= 1) {
33                 fprintf(stderr, "usage: getiversion file ...\n");
34                 return 1;
35         }
36
37         for (i = 1; i < argc; i++) {
38                 if ((fd = open(argv[i], O_RDONLY)) < 0
39                  || ioctl(fd, EXT2_IOC_GETVERSION, &vers) < 0) {
40                         perror(argv[i]);
41                         continue;
42                 } else {
43                         printf("%-20s %d\n", argv[i], vers);
44                 }
45                 close(fd);
46         }
47         return 0;
48 }