]> git.decadent.org.uk Git - nfs-utils.git/blob - tools/getiversion/getiversion.c
e9cb391eee73db305b5dce574dc53c38a2f5e185
[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 #include "config.h"
8
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <stdio.h>
13 #include <sys/fs/ext2fs.h>
14
15 int
16 main(int argc, char **argv)
17 {
18         int     i, fd;
19         u_int32_t       vers;
20
21         if (argc <= 1) {
22                 fprintf(stderr, "usage: getiversion file ...\n");
23                 return 1;
24         }
25
26         for (i = 1; i < argc; i++) {
27                 if ((fd = open(argv[i], O_RDONLY)) < 0
28                  || ioctl(fd, EXT2_IOC_GETVERSION, &vers) < 0) {
29                         perror(argv[i]);
30                         continue;
31                 } else {
32                         printf("%-20s %d\n", argv[i], vers);
33                 }
34                 close(fd);
35         }
36         return 0;
37 }