summaryrefslogtreecommitdiff
path: root/btrfs-find-root.c
diff options
context:
space:
mode:
Diffstat (limited to 'btrfs-find-root.c')
-rw-r--r--btrfs-find-root.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index 9e56c81d..1cb3085d 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -22,6 +22,8 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <zlib.h>
+#include <getopt.h>
+
#include "kerncompat.h"
#include "ctree.h"
#include "disk-io.h"
@@ -142,15 +144,23 @@ int main(int argc, char **argv)
struct btrfs_find_root_filter filter = {0};
struct cache_tree result;
struct cache_extent *found;
- int opt;
int ret;
/* Default to search root tree */
filter.objectid = BTRFS_ROOT_TREE_OBJECTID;
filter.match_gen = (u64)-1;
filter.match_level = (u8)-1;
- while ((opt = getopt(argc, argv, "al:o:g:")) != -1) {
- switch(opt) {
+ while (1) {
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
+ { NULL, 0, NULL, 0 }
+ };
+ int c = getopt_long(argc, argv, "al:o:g:", long_options, NULL);
+
+ if (c < 0)
+ break;
+
+ switch (c) {
case 'a':
filter.search_all = 1;
break;
@@ -163,9 +173,10 @@ int main(int argc, char **argv)
case 'l':
filter.level = arg_strtou64(optarg);
break;
+ case GETOPT_VAL_HELP:
default:
usage();
- exit(1);
+ exit(c != GETOPT_VAL_HELP);
}
}