---
bin/rmcp.c | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/bin/rmcp.c b/bin/rmcp.c
index 9b72f9d..91ddf60 100644
--- a/bin/rmcp.c
+++ b/bin/rmcp.c
@@ -27,6 +27,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
@@ -129,9 +137,10 @@ static int rmcp_remove_range(struct nilfs *nilfs,
int main(int argc, char *argv[])
{
- char *dev;
+ char *dev, *dir, *pathname;
struct nilfs *nilfs;
struct nilfs_cpstat cpstat;
+ struct stat statbuf;
nilfs_cno_t start, end, oldest;
size_t nsnapshots, nss, ndel;
int c, status, ret;
@@ -140,6 +149,7 @@ int main(int argc, char *argv[])
#endif /* _GNU_SOURCE */
opterr = 0;
+ dev = dir = NULL;
if ((progname = strrchr(argv[0], '/')) == NULL)
progname = argv[0];
else
@@ -179,24 +189,36 @@ int main(int argc, char *argv[])
fprintf(stderr, "%s: too few arguments\n", progname);
exit(1);
} else if (optind == argc - 1) {
- dev = NULL;
+ pathname = NULL;
} else {
if (nilfs_parse_cno_range(argv[optind], &start, &end,
RMCP_BASE) < 0)
- dev = argv[optind++];
+ pathname = argv[optind++];
else
- dev = NULL;
+ pathname = NULL;
}
- nilfs = nilfs_open(dev, NULL, NILFS_OPEN_RDWR);
+ 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_RDWR);
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);
}
if (nilfs_get_cpstat(nilfs, &cpstat) < 0) {
fprintf(stderr, "%s: %s: cannot get checkpoint status: %s\n",
- progname, dev, strerror(errno));
+ progname, pathname, strerror(errno));
exit(1);
}
--
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html