summaryrefslogtreecommitdiffstats
path: root/tools/getiversion/getiversion.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/getiversion/getiversion.c')
-rw-r--r--tools/getiversion/getiversion.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/getiversion/getiversion.c b/tools/getiversion/getiversion.c
new file mode 100644
index 0000000..e9cb391
--- /dev/null
+++ b/tools/getiversion/getiversion.c
@@ -0,0 +1,37 @@
+/*
+ * getiversion
+ *
+ * Get version number for an inode on an ext2 file system.
+ */
+
+#include "config.h"
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/fs/ext2fs.h>
+
+int
+main(int argc, char **argv)
+{
+ int i, fd;
+ u_int32_t vers;
+
+ if (argc <= 1) {
+ fprintf(stderr, "usage: getiversion file ...\n");
+ return 1;
+ }
+
+ for (i = 1; i < argc; i++) {
+ if ((fd = open(argv[i], O_RDONLY)) < 0
+ || ioctl(fd, EXT2_IOC_GETVERSION, &vers) < 0) {
+ perror(argv[i]);
+ continue;
+ } else {
+ printf("%-20s %d\n", argv[i], vers);
+ }
+ close(fd);
+ }
+ return 0;
+}