[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/8] dumpseg: support opening mounted filesystem by directory pathname



---
 bin/dumpseg.c |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/bin/dumpseg.c b/bin/dumpseg.c
index 0ee6aee..1910296 100644
--- a/bin/dumpseg.c
+++ b/bin/dumpseg.c
@@ -28,6 +28,14 @@
 #include "config.h"
 #endif	/* HAVE_CONFIG_H */
 
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif	/* HAVE_SYS_TYPES_H */
+
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif	/* HAVE_SYS_STAT_H */
+
 #include <stdio.h>
 
 #if HAVE_STDLIB_H
@@ -169,17 +177,19 @@ static void dumpseg_print_segment(struct nilfs *nilfs,
 int main(int argc, char *argv[])
 {
 	struct nilfs *nilfs;
+	struct stat statbuf;
 	__u64 segnum;
-	char *dev, *endptr, *progname;
+	char *dev, *dir, *pathname, *endptr, *progname;
 	void *seg;
 	ssize_t segsize;
-	int c, i, status;
+	int c, i, status, ret;
 	unsigned long val;
 #ifdef _GNU_SOURCE
 	int option_index;
 #endif	/* _GNU_SOURCE */
 
 	opterr = 0;
+	dev = dir = NULL;
 
 	if ((progname = strrchr(argv[0], '/')) == NULL)
 		progname = argv[0];
@@ -214,14 +224,27 @@ int main(int argc, char *argv[])
 	} else {
 		val = strtoul(argv[optind], &endptr, DUMPSEG_BASE);
 		if (*endptr == '\0')
-			dev = NULL;
+			pathname = NULL;
 		else
-			dev = argv[optind++];
+			pathname = argv[optind++];
 	}
 
-	nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RAW);
+
+	if (pathname) {
+		ret = stat(pathname, &statbuf);
+		if (ret == -1) {
+			fprintf(stderr, "%s: cannot open %s: %s\n",
+				progname, pathname, strerror(errno));
+			exit(EXIT_FAILURE);
+		}
+		if (S_ISDIR(statbuf.st_mode))
+			dir = pathname;
+		else
+			dev = pathname;
+	}
+	nilfs = nilfs_open(dev, dir, NILFS_OPEN_RAW);
 	if (nilfs == NULL) {
-		fprintf(stderr, "%s: %s: cannot open NILFS\n", progname, dev);
+		fprintf(stderr, "%s: %s: cannot open NILFS\n", progname, pathname);
 		exit(1);
 	}
 
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Linux Filesystem; Devel]     [Linux CIFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Free Online Dating]     [Linux Kernel]     [Linux SCSI]     [XFree86]

Add to Google Powered by Linux