{ "label", required_argument, NULL, 'l' },
{ "copy-label", no_argument, NULL, 'L' },
{ "nodesize", required_argument, NULL, 'N' },
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
{ NULL, 0, NULL, 0 }
};
int c = getopt_long(argc, argv, "dinN:rl:LpO:", long_options, NULL);
case GETOPT_VAL_NO_PROGRESS:
progress = 0;
break;
+ case GETOPT_VAL_HELP:
default:
print_usage();
- return 1;
+ return c != GETOPT_VAL_HELP;
}
}
argc = argc - optind;
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
+
#include "kerncompat.h"
#include "ctree.h"
#include "volumes.h"
return eb;
}
-static void print_usage(void)
+static void print_usage(int ret)
{
fprintf(stderr, "usage: btrfs-corrupt-block [options] device\n");
fprintf(stderr, "\t-l Logical extent to be corrupted\n");
fprintf(stderr, "\t-C Delete a csum for the specified bytenr. When "
"used with -b it'll delete that many bytes, otherwise it's "
"just sectorsize\n");
- exit(1);
+ exit(ret);
}
static void corrupt_keys(struct btrfs_trans_handle *trans,
{ "delete", no_argument, NULL, 'd'},
{ "root", no_argument, NULL, 'r'},
{ "csum", required_argument, NULL, 'C'},
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
{ NULL, 0, NULL, 0 }
};
if (ret != 3) {
fprintf(stderr, "error reading key "
"%d\n", errno);
- print_usage();
+ print_usage(1);
}
break;
case 'D':
case 'C':
csum_bytenr = arg_strtou64(optarg);
break;
+ case GETOPT_VAL_HELP:
default:
- print_usage();
+ print_usage(c != GETOPT_VAL_HELP);
}
}
set_argv0(av);
ac = ac - optind;
if (check_argc_min(ac, 1))
- print_usage();
+ print_usage(1);
dev = av[optind];
radix_tree_init();
struct btrfs_trans_handle *trans;
if (logical == (u64)-1)
- print_usage();
+ print_usage(1);
trans = btrfs_start_transaction(root, 1);
ret = corrupt_extent (trans, root, logical, 0);
btrfs_commit_transaction(trans, root);
int del;
if (logical == (u64)-1)
- print_usage();
+ print_usage(1);
del = rand() % 3;
path = btrfs_alloc_path();
if (!path) {
struct btrfs_trans_handle *trans;
if (!strlen(field))
- print_usage();
+ print_usage(1);
trans = btrfs_start_transaction(root, 1);
if (file_extent == (u64)-1) {
}
if (metadata_block) {
if (!strlen(field))
- print_usage();
+ print_usage(1);
ret = corrupt_metadata_block(root, metadata_block, field);
goto out_close;
}
if (corrupt_di) {
if (!key.objectid || !strlen(field))
- print_usage();
+ print_usage(1);
ret = corrupt_dir_item(root, &key, field);
goto out_close;
}
}
if (corrupt_item) {
if (!key.objectid)
- print_usage();
+ print_usage(1);
ret = corrupt_btrfs_item(root, &key, field);
}
if (delete) {
struct btrfs_root *target = root;
if (!key.objectid)
- print_usage();
+ print_usage(1);
if (root_objectid) {
struct btrfs_key root_key;
if (IS_ERR(target)) {
fprintf(stderr, "Couldn't find root %llu\n",
(unsigned long long)root_objectid);
- print_usage();
+ print_usage(1);
}
}
ret = delete_item(target, &key);
}
if (key.objectid || key.offset || key.type) {
if (!strlen(field))
- print_usage();
+ print_usage(1);
ret = corrupt_key(root, &key, field);
goto out_close;
}
* inode and we're screwed.
*/
if (file_extent != (u64)-1)
- print_usage();
+ print_usage(1);
if (logical == (u64)-1)
- print_usage();
+ print_usage(1);
if (bytes == 0)
bytes = root->sectorsize;
#include <stdlib.h>
#include <unistd.h>
#include <uuid/uuid.h>
+#include <getopt.h>
+
#include "kerncompat.h"
#include "radix-tree.h"
#include "ctree.h"
#include "transaction.h"
#include "utils.h"
-static int print_usage(void)
+static int print_usage(int ret)
{
fprintf(stderr, "usage: btrfs-debug-tree [-e] [-d] [-r] [-R] [-u]\n");
fprintf(stderr, " [-b block_num ] device\n");
fprintf(stderr,
"\t-t tree_id : print only the tree with the given id\n");
fprintf(stderr, "%s\n", PACKAGE_STRING);
- exit(1);
+ exit(ret);
}
static void print_extents(struct btrfs_root *root, struct extent_buffer *eb)
while(1) {
int c;
- c = getopt(ac, av, "deb:rRut:");
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
+ { NULL, 0, NULL, 0 }
+ };
+
+ c = getopt_long(ac, av, "deb:rRut:", long_options, NULL);
if (c < 0)
break;
switch(c) {
case 't':
tree_id = arg_strtou64(optarg);
break;
+ case GETOPT_VAL_HELP:
default:
- print_usage();
+ print_usage(c != GETOPT_VAL_HELP);
}
}
set_argv0(av);
ac = ac - optind;
if (check_argc_exact(ac, 1))
- print_usage();
+ print_usage(1);
ret = check_arg_type(av[optind]);
if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
#include <fcntl.h>
#include <sys/stat.h>
#include <zlib.h>
+#include <getopt.h>
+
#include "kerncompat.h"
#include "ctree.h"
#include "disk-io.h"
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;
case 'l':
filter.level = arg_strtou64(optarg);
break;
+ case GETOPT_VAL_HELP:
default:
usage();
- exit(1);
+ exit(c != GETOPT_VAL_HELP);
}
}
#include <unistd.h>
#include <dirent.h>
#include <zlib.h>
+#include <getopt.h>
+
#include "kerncompat.h"
#include "crc32c.h"
#include "ctree.h"
struct btrfs_fs_info *info;
};
-static void print_usage(void) __attribute__((noreturn));
static int search_for_chunk_blocks(struct mdrestore_struct *mdres,
u64 search, u64 cluster_bytenr);
static struct extent_buffer *alloc_dummy_eb(u64 bytenr, u32 size);
return 0;
}
-static void print_usage(void)
+static void print_usage(int ret)
{
fprintf(stderr, "usage: btrfs-image [options] source target\n");
fprintf(stderr, "\t-r \trestore metadump image\n");
fprintf(stderr, "\n");
fprintf(stderr, "\tIn the dump mode, source is the btrfs device and target is the output file (use '-' for stdout).\n");
fprintf(stderr, "\tIn the restore mode, source is the dumped image and target is the btrfs device/file.\n");
- exit(1);
+ exit(ret);
}
int main(int argc, char *argv[])
FILE *out;
while (1) {
- int c = getopt(argc, argv, "rc:t:oswm");
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
+ { NULL, 0, NULL, 0 }
+ };
+ int c = getopt_long(argc, argv, "rc:t:oswm", long_options, NULL);
if (c < 0)
break;
switch (c) {
case 't':
num_threads = arg_strtou64(optarg);
if (num_threads > 32)
- print_usage();
+ print_usage(1);
break;
case 'c':
compress_level = arg_strtou64(optarg);
if (compress_level > 9)
- print_usage();
+ print_usage(1);
break;
case 'o':
old_restore = 1;
create = 0;
multi_devices = 1;
break;
+ case GETOPT_VAL_HELP:
default:
- print_usage();
+ print_usage(c != GETOPT_VAL_HELP);
}
}
argc = argc - optind;
set_argv0(argv);
if (check_argc_min(argc, 2))
- print_usage();
+ print_usage(1);
dev_cnt = argc - 1;
}
if (usage_error)
- print_usage();
+ print_usage(1);
source = argv[optind];
target = argv[optind + 1];
#include <unistd.h>
#include <dirent.h>
#include <uuid/uuid.h>
+#include <getopt.h>
#include "kerncompat.h"
#include "ctree.h"
optind = 1;
while(1) {
- int c = getopt(argc, argv, "S:rxfuU:n");
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
+ { NULL, 0, NULL, 0 }
+ };
+ int c = getopt_long(argc, argv, "S:rxfuU:n", long_options, NULL);
+
if (c < 0)
break;
switch(c) {
ctree_flags |= OPEN_CTREE_IGNORE_FSID_MISMATCH;
random_fsid = 1;
break;
+ case GETOPT_VAL_HELP:
default:
print_usage();
- return 1;
+ return c != GETOPT_VAL_HELP;
}
}
return 0;
}
-
-static void print_usage(void) __attribute__((noreturn));
-static void print_usage(void)
+static void print_usage(int ret)
{
fprintf(stderr, "usage: mkfs.btrfs [options] dev [ dev ... ]\n");
fprintf(stderr, "options:\n");
fprintf(stderr, "\t-q|--quiet no messages except errors\n");
fprintf(stderr, "\t-V|--version print the mkfs.btrfs version and exit\n");
fprintf(stderr, "%s\n", PACKAGE_STRING);
- exit(1);
+ exit(ret);
}
static void print_version(void) __attribute__((noreturn));
return 0;
} else {
fprintf(stderr, "Unknown profile %s\n", s);
- print_usage();
}
/* not reached */
return 0;
{ "features", required_argument, NULL, 'O' },
{ "uuid", required_argument, NULL, 'U' },
{ "quiet", 0, NULL, 'q' },
+ { "help", no_argument, NULL, GETOPT_VAL_HELP },
{ NULL, 0, NULL, 0}
};
case 'q':
verbose = 0;
break;
+ case GETOPT_VAL_HELP:
default:
- print_usage();
+ print_usage(c != GETOPT_VAL_HELP);
}
}
sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE));
saved_optind = optind;
dev_cnt = ac - optind;
if (dev_cnt == 0)
- print_usage();
+ print_usage(1);
if (source_dir_set && dev_cnt > 1) {
fprintf(stderr,
#define GETOPT_VAL_GBYTES 262
#define GETOPT_VAL_TBYTES 263
+#define GETOPT_VAL_HELP 270
+
int check_argc_exact(int nargs, int expected);
int check_argc_min(int nargs, int expected);
int check_argc_max(int nargs, int expected);