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>
master
David Sterba 2015-01-19 13:30:06 +01:00
parent ca7b429f26
commit ecbf1339a6
8 changed files with 107 additions and 98 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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) {

View File

@ -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++;

View File

@ -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':

View File

@ -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)

40
mkfs.c
View File

@ -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)