summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-01-19 13:30:06 +0100
committerDavid Sterba <dsterba@suse.cz>2015-01-19 13:30:06 +0100
commitecbf1339a63e99a8ef7d5ddc334e38a39f291d3d (patch)
tree0483487c6fa237ac649c4bd0414bb564a7111925
parentca7b429f263ab19acf606846dd560be7e8519302 (diff)
btrfs-progs: cleanup, move getop long options close to their use
Move long_option defintions just before getopt_long everywhere. Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--btrfs-corrupt-block.c44
-rw-r--r--btrfs-map-logical.c20
-rw-r--r--cmds-check.c28
-rw-r--r--cmds-qgroup.c11
-rw-r--r--cmds-receive.c18
-rw-r--r--cmds-restore.c23
-rw-r--r--cmds-subvolume.c21
-rw-r--r--mkfs.c40
8 files changed, 107 insertions, 98 deletions
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index b477e878..91ff220a 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -845,27 +845,6 @@ out:
return ret;
}
-static struct option long_options[] = {
- /* { "byte-count", 1, NULL, 'b' }, */
- { "logical", 1, NULL, 'l' },
- { "copy", 1, NULL, 'c' },
- { "bytes", 1, NULL, 'b' },
- { "extent-record", 0, NULL, 'e' },
- { "extent-tree", 0, NULL, 'E' },
- { "keys", 0, NULL, 'k' },
- { "chunk-record", 0, NULL, 'u' },
- { "chunk-tree", 0, NULL, 'U' },
- { "inode", 1, NULL, 'i'},
- { "file-extent", 1, NULL, 'x'},
- { "metadata-block", 1, NULL, 'm'},
- { "field", 1, NULL, 'f'},
- { "key", 1, NULL, 'K'},
- { "item", 0, NULL, 'I'},
- { "dir-item", 0, NULL, 'D'},
- { "delete", 0, NULL, 'd'},
- { 0, 0, 0, 0}
-};
-
/* corrupt item using NO cow.
* Because chunk recover will recover based on whole partition scaning,
* If using COW, chunk recover will use the old item to recover,
@@ -1018,7 +997,6 @@ int main(int ac, char **av)
/* chunk offset can be 0,so change to (u64)-1 */
u64 logical = (u64)-1;
int ret = 0;
- int option_index = 0;
u64 copy = 0;
u64 bytes = 4096;
int extent_rec = 0;
@@ -1040,6 +1018,28 @@ int main(int ac, char **av)
while(1) {
int c;
+ int option_index = 0;
+ static struct option long_options[] = {
+ /* { "byte-count", 1, NULL, 'b' }, */
+ { "logical", 1, NULL, 'l' },
+ { "copy", 1, NULL, 'c' },
+ { "bytes", 1, NULL, 'b' },
+ { "extent-record", 0, NULL, 'e' },
+ { "extent-tree", 0, NULL, 'E' },
+ { "keys", 0, NULL, 'k' },
+ { "chunk-record", 0, NULL, 'u' },
+ { "chunk-tree", 0, NULL, 'U' },
+ { "inode", 1, NULL, 'i'},
+ { "file-extent", 1, NULL, 'x'},
+ { "metadata-block", 1, NULL, 'm'},
+ { "field", 1, NULL, 'f'},
+ { "key", 1, NULL, 'K'},
+ { "item", 0, NULL, 'I'},
+ { "dir-item", 0, NULL, 'D'},
+ { "delete", 0, NULL, 'd'},
+ { 0, 0, 0, 0}
+ };
+
c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDd", long_options,
&option_index);
if (c < 0)
diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c
index 47d1104d..a9e66bf3 100644
--- a/btrfs-map-logical.c
+++ b/btrfs-map-logical.c
@@ -112,15 +112,6 @@ static void print_usage(void)
exit(1);
}
-static struct option long_options[] = {
- /* { "byte-count", 1, NULL, 'b' }, */
- { "logical", 1, NULL, 'l' },
- { "copy", 1, NULL, 'c' },
- { "output", 1, NULL, 'o' },
- { "bytes", 1, NULL, 'b' },
- { NULL, 0, NULL, 0}
-};
-
int main(int ac, char **av)
{
struct cache_tree root_cache;
@@ -130,13 +121,22 @@ int main(int ac, char **av)
char *output_file = NULL;
u64 logical = 0;
int ret = 0;
- int option_index = 0;
u64 copy = 0;
u64 bytes = 0;
int out_fd = 0;
while(1) {
int c;
+ int option_index = 0;
+ static struct option long_options[] = {
+ /* { "byte-count", 1, NULL, 'b' }, */
+ { "logical", 1, NULL, 'l' },
+ { "copy", 1, NULL, 'c' },
+ { "output", 1, NULL, 'o' },
+ { "bytes", 1, NULL, 'b' },
+ { NULL, 0, NULL, 0}
+ };
+
c = getopt_long(ac, av, "l:c:o:b:", long_options,
&option_index);
if (c < 0)
diff --git a/cmds-check.c b/cmds-check.c
index f06e0295..befee98a 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -8403,19 +8403,6 @@ out:
return bad_roots;
}
-static struct option long_options[] = {
- { "super", 1, NULL, 's' },
- { "repair", 0, NULL, 0 },
- { "init-csum-tree", 0, NULL, 0 },
- { "init-extent-tree", 0, NULL, 0 },
- { "check-data-csum", 0, NULL, 0 },
- { "backup", 0, NULL, 0 },
- { "subvol-extents", 1, NULL, 'E' },
- { "qgroup-report", 0, NULL, 'Q' },
- { "tree-root", 1, NULL, 'r' },
- { NULL, 0, NULL, 0}
-};
-
const char * const cmd_check_usage[] = {
"btrfs check [options] <device>",
"Check an unmounted btrfs filesystem.",
@@ -8443,13 +8430,26 @@ int cmd_check(int argc, char **argv)
char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
int ret;
u64 num;
- int option_index = 0;
int init_csum_tree = 0;
int qgroup_report = 0;
enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_EXCLUSIVE;
while(1) {
int c;
+ int option_index = 0;
+ static struct option long_options[] = {
+ { "super", 1, NULL, 's' },
+ { "repair", 0, NULL, 0 },
+ { "init-csum-tree", 0, NULL, 0 },
+ { "init-extent-tree", 0, NULL, 0 },
+ { "check-data-csum", 0, NULL, 0 },
+ { "backup", 0, NULL, 0 },
+ { "subvol-extents", 1, NULL, 'E' },
+ { "qgroup-report", 0, NULL, 'Q' },
+ { "tree-root", 1, NULL, 'r' },
+ { NULL, 0, NULL, 0}
+ };
+
c = getopt_long(argc, argv, "as:br:", long_options,
&option_index);
if (c < 0)
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 957fbc95..1d2993c4 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -231,7 +231,6 @@ static int cmd_qgroup_show(int argc, char **argv)
int fd;
int e;
DIR *dirstream = NULL;
- int c;
u64 qgroupid;
int filter_flag = 0;
@@ -239,15 +238,17 @@ static int cmd_qgroup_show(int argc, char **argv)
struct btrfs_qgroup_filter_set *filter_set;
filter_set = btrfs_qgroup_alloc_filter_set();
comparer_set = btrfs_qgroup_alloc_comparer_set();
- struct option long_options[] = {
- {"sort", 1, NULL, 'S'},
- {0, 0, 0, 0}
- };
optind = 1;
while (1) {
+ int c;
+ struct option long_options[] = {
+ {"sort", 1, NULL, 'S'},
+ {0, 0, 0, 0}
+ };
c = getopt_long(argc, argv, "pcreFf",
long_options, NULL);
+
if (c < 0)
break;
switch (c) {
diff --git a/cmds-receive.c b/cmds-receive.c
index f269adec..bffc7dc7 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -922,14 +922,8 @@ out:
return ret;
}
-static const struct option long_opts[] = {
- { "max-errors", 1, NULL, 'E' },
- { NULL, 0, NULL, 0 }
-};
-
int cmd_receive(int argc, char **argv)
{
- int c;
char *tomnt = NULL;
char *fromfile = NULL;
struct btrfs_receive r;
@@ -942,7 +936,17 @@ int cmd_receive(int argc, char **argv)
r.write_fd = -1;
r.dest_dir_fd = -1;
- while ((c = getopt_long(argc, argv, "evf:", long_opts, NULL)) != -1) {
+ while (1) {
+ int c;
+ static const struct option long_opts[] = {
+ { "max-errors", 1, NULL, 'E' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ c = getopt_long(argc, argv, "evf:", long_opts, NULL);
+ if (c < 0)
+ break;
+
switch (c) {
case 'v':
g_verbose++;
diff --git a/cmds-restore.c b/cmds-restore.c
index 859deaf3..795332db 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1122,12 +1122,6 @@ out:
return ret;
}
-static struct option long_options[] = {
- { "path-regex", 1, NULL, 256},
- { "dry-run", 0, NULL, 'D'},
- { NULL, 0, NULL, 0}
-};
-
const char * const cmd_restore_usage[] = {
"btrfs restore [options] <device> <path> | -l <device>",
"Try to restore files from a damaged filesystem (unmounted)",
@@ -1162,8 +1156,6 @@ int cmd_restore(int argc, char **argv)
u64 root_objectid = 0;
int len;
int ret;
- int opt;
- int option_index = 0;
int super_mirror = 0;
int find_dir = 0;
int list_roots = 0;
@@ -1172,8 +1164,19 @@ int cmd_restore(int argc, char **argv)
regex_t match_reg, *mreg = NULL;
char reg_err[256];
- while ((opt = getopt_long(argc, argv, "sxviot:u:df:r:lDc", long_options,
- &option_index)) != -1) {
+ while (1) {
+ int opt;
+ int option_index = 0;
+ static struct option long_options[] = {
+ { "path-regex", 1, NULL, 256},
+ { "dry-run", 0, NULL, 'D'},
+ { NULL, 0, NULL, 0}
+ };
+
+ opt = getopt_long(argc, argv, "sxviot:u:df:r:lDc", long_options,
+ &option_index);
+ if (opt < 0)
+ break;
switch (opt) {
case 's':
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 3895d116..97293fd6 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -219,15 +219,15 @@ static int cmd_subvol_delete(int argc, char **argv)
DIR *dirstream = NULL;
int verbose = 0;
int commit_mode = 0;
- struct option long_options[] = {
- {"commit-after", no_argument, NULL, 'c'}, /* commit mode 1 */
- {"commit-each", no_argument, NULL, 'C'}, /* commit mode 2 */
- {NULL, 0, NULL, 0}
- };
optind = 1;
while (1) {
int c;
+ struct option long_options[] = {
+ {"commit-after", no_argument, NULL, 'c'}, /* commit mode 1 */
+ {"commit-each", no_argument, NULL, 'C'}, /* commit mode 2 */
+ {NULL, 0, NULL, 0}
+ };
c = getopt_long(argc, argv, "cC", long_options, NULL);
if (c < 0)
@@ -391,15 +391,10 @@ static int cmd_subvol_list(int argc, char **argv)
int fd = -1;
u64 top_id;
int ret = -1, uerr = 0;
- int c;
char *subvol;
int is_tab_result = 0;
int is_list_all = 0;
int is_only_in_path = 0;
- struct option long_options[] = {
- {"sort", 1, NULL, 'S'},
- {NULL, 0, NULL, 0}
- };
DIR *dirstream = NULL;
filter_set = btrfs_list_alloc_filter_set();
@@ -407,6 +402,12 @@ static int cmd_subvol_list(int argc, char **argv)
optind = 1;
while(1) {
+ int c;
+ struct option long_options[] = {
+ {"sort", 1, NULL, 'S'},
+ {NULL, 0, NULL, 0}
+ };
+
c = getopt_long(argc, argv,
"acdgopqsurRG:C:t", long_options, NULL);
if (c < 0)
diff --git a/mkfs.c b/mkfs.c
index 98a1eddd..fc7bf845 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -340,25 +340,6 @@ static char *parse_label(char *input)
return strdup(input);
}
-static struct option long_options[] = {
- { "alloc-start", 1, NULL, 'A'},
- { "byte-count", 1, NULL, 'b' },
- { "force", 0, NULL, 'f' },
- { "leafsize", 1, NULL, 'l' },
- { "label", 1, NULL, 'L'},
- { "metadata", 1, NULL, 'm' },
- { "mixed", 0, NULL, 'M' },
- { "nodesize", 1, NULL, 'n' },
- { "sectorsize", 1, NULL, 's' },
- { "data", 1, NULL, 'd' },
- { "version", 0, NULL, 'V' },
- { "rootdir", 1, NULL, 'r' },
- { "nodiscard", 0, NULL, 'K' },
- { "features", 1, NULL, 'O' },
- { "uuid", required_argument, NULL, 'U' },
- { NULL, 0, NULL, 0}
-};
-
static int add_directory_items(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
ino_t parent_inum, const char *name,
@@ -1258,7 +1239,6 @@ int main(int ac, char **av)
u32 nodesize = leafsize;
u32 stripesize = 4096;
int zero_end = 1;
- int option_index = 0;
int fd;
int ret;
int i;
@@ -1283,6 +1263,26 @@ int main(int ac, char **av)
while(1) {
int c;
+ int option_index = 0;
+ static struct option long_options[] = {
+ { "alloc-start", 1, NULL, 'A'},
+ { "byte-count", 1, NULL, 'b' },
+ { "force", 0, NULL, 'f' },
+ { "leafsize", 1, NULL, 'l' },
+ { "label", 1, NULL, 'L'},
+ { "metadata", 1, NULL, 'm' },
+ { "mixed", 0, NULL, 'M' },
+ { "nodesize", 1, NULL, 'n' },
+ { "sectorsize", 1, NULL, 's' },
+ { "data", 1, NULL, 'd' },
+ { "version", 0, NULL, 'V' },
+ { "rootdir", 1, NULL, 'r' },
+ { "nodiscard", 0, NULL, 'K' },
+ { "features", 1, NULL, 'O' },
+ { "uuid", required_argument, NULL, 'U' },
+ { NULL, 0, NULL, 0}
+ };
+
c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:U:VMK",
long_options, &option_index);
if (c < 0)