From 1c880f34f13e51aae9704449603f74680e442cf6 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 25 Jan 2017 16:35:00 +0100 Subject: [PATCH] btrfs-progs: move help defines to own header Signed-off-by: David Sterba --- btrfs-corrupt-block.c | 1 + btrfs-debug-tree.c | 1 + btrfs-find-root.c | 1 + btrfs-map-logical.c | 1 + btrfs-select-super.c | 1 + btrfs-zero-log.c | 1 + btrfs.c | 1 + btrfstune.c | 1 + cmds-balance.c | 1 + cmds-check.c | 1 + cmds-device.c | 1 + cmds-fi-du.c | 1 + cmds-fi-usage.c | 1 + cmds-filesystem.c | 1 + cmds-inspect-dump-super.c | 1 + cmds-inspect-dump-tree.c | 1 + cmds-inspect-tree-stats.c | 1 + cmds-inspect.c | 1 + cmds-property.c | 1 + cmds-qgroup.c | 1 + cmds-quota.c | 1 + cmds-receive.c | 1 + cmds-replace.c | 2 +- cmds-rescue.c | 1 + cmds-restore.c | 1 + cmds-scrub.c | 1 + cmds-send.c | 1 + cmds-subvolume.c | 1 + commands.h | 11 ------ convert/main.c | 1 + help.c | 1 + help.h | 79 +++++++++++++++++++++++++++++++++++++++ image/main.c | 1 + mkfs/main.c | 1 + utils.c | 1 + utils.h | 47 ----------------------- 36 files changed, 112 insertions(+), 59 deletions(-) create mode 100644 help.h diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 0e1eb524..94259aa7 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -31,6 +31,7 @@ #include "transaction.h" #include "list.h" #include "utils.h" +#include "help.h" #define FIELD_BUF_LEN 80 diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c index a645b406..5caae602 100644 --- a/btrfs-debug-tree.c +++ b/btrfs-debug-tree.c @@ -21,6 +21,7 @@ #include "utils.h" #include "commands.h" #include "cmds-inspect-dump-tree.h" +#include "help.h" int main(int argc, char **argv) { diff --git a/btrfs-find-root.c b/btrfs-find-root.c index 66e64037..e2d2e70c 100644 --- a/btrfs-find-root.c +++ b/btrfs-find-root.c @@ -35,6 +35,7 @@ #include "crc32c.h" #include "extent-cache.h" #include "find-root.h" +#include "help.h" static void find_root_usage(void) { diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c index bcbf2d90..e856b698 100644 --- a/btrfs-map-logical.c +++ b/btrfs-map-logical.c @@ -29,6 +29,7 @@ #include "transaction.h" #include "list.h" #include "utils.h" +#include "help.h" #define BUFFER_SIZE SZ_64K diff --git a/btrfs-select-super.c b/btrfs-select-super.c index 7e96dc0b..0a899966 100644 --- a/btrfs-select-super.c +++ b/btrfs-select-super.c @@ -29,6 +29,7 @@ #include "transaction.h" #include "list.h" #include "utils.h" +#include "help.h" static void print_usage(void) { diff --git a/btrfs-zero-log.c b/btrfs-zero-log.c index 44293998..697026aa 100644 --- a/btrfs-zero-log.c +++ b/btrfs-zero-log.c @@ -24,6 +24,7 @@ #include "disk-io.h" #include "transaction.h" #include "utils.h" +#include "help.h" __attribute__((noreturn)) static void print_usage(void) { diff --git a/btrfs.c b/btrfs.c index 11923786..9214ae6e 100644 --- a/btrfs.c +++ b/btrfs.c @@ -22,6 +22,7 @@ #include "crc32c.h" #include "commands.h" #include "utils.h" +#include "help.h" static const char * const btrfs_cmd_group_usage[] = { "btrfs [--help] [--version] [...] []", diff --git a/btrfstune.c b/btrfstune.c index e8e3d00a..257bac44 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -32,6 +32,7 @@ #include "transaction.h" #include "utils.h" #include "volumes.h" +#include "help.h" static char *device; static int force = 0; diff --git a/cmds-balance.c b/cmds-balance.c index f17345ed..7d3767a8 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -32,6 +32,7 @@ #include "commands.h" #include "utils.h" +#include "help.h" static const char * const balance_cmd_group_usage[] = { "btrfs balance [options] ", diff --git a/cmds-check.c b/cmds-check.c index 37e5ff18..84e1d99b 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -42,6 +42,7 @@ #include "backref.h" #include "ulist.h" #include "hash.h" +#include "help.h" enum task_position { TASK_EXTENTS, diff --git a/cmds-device.c b/cmds-device.c index de62cd42..58f7dee1 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -32,6 +32,7 @@ #include "cmds-fi-usage.h" #include "commands.h" +#include "help.h" static const char * const device_cmd_group_usage[] = { "btrfs device []", diff --git a/cmds-fi-du.c b/cmds-fi-du.c index 2fc11945..ef43259d 100644 --- a/cmds-fi-du.c +++ b/cmds-fi-du.c @@ -40,6 +40,7 @@ #include "rbtree.h" #include "interval_tree_generic.h" +#include "help.h" static int summarize = 0; static unsigned unit_mode = UNITS_RAW; diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c index 394de0c2..e7436842 100644 --- a/cmds-fi-usage.c +++ b/cmds-fi-usage.c @@ -31,6 +31,7 @@ #include "commands.h" #include "version.h" +#include "help.h" /* * Add the chunk info to the chunk_info list diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 7174891a..e2e41e91 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -38,6 +38,7 @@ #include "list_sort.h" #include "disk-io.h" #include "cmds-fi-du.h" +#include "help.h" /* * for btrfs fi show, we maintain a hash of fsids we've already printed. diff --git a/cmds-inspect-dump-super.c b/cmds-inspect-dump-super.c index ba0d708e..318d6e6b 100644 --- a/cmds-inspect-dump-super.c +++ b/cmds-inspect-dump-super.c @@ -34,6 +34,7 @@ #include "commands.h" #include "crc32c.h" #include "cmds-inspect-dump-super.h" +#include "help.h" static int check_csum_sblock(void *sb, int csum_size) { diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c index df7be617..6c6c0e5c 100644 --- a/cmds-inspect-dump-tree.c +++ b/cmds-inspect-dump-tree.c @@ -32,6 +32,7 @@ #include "commands.h" #include "utils.h" #include "cmds-inspect-dump-tree.h" +#include "help.h" static void print_extents(struct btrfs_root *root, struct extent_buffer *eb) { diff --git a/cmds-inspect-tree-stats.c b/cmds-inspect-tree-stats.c index 0e2786c9..58dd29e1 100644 --- a/cmds-inspect-tree-stats.c +++ b/cmds-inspect-tree-stats.c @@ -36,6 +36,7 @@ #include "utils.h" #include "commands.h" #include "cmds-inspect-tree-stats.h" +#include "help.h" static int verbose = 0; static int no_pretty = 0; diff --git a/cmds-inspect.c b/cmds-inspect.c index ac3da618..58b59560 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -34,6 +34,7 @@ #include "cmds-inspect-dump-tree.h" #include "cmds-inspect-dump-super.h" #include "cmds-inspect-tree-stats.h" +#include "help.h" static const char * const inspect_cmd_group_usage[] = { "btrfs inspect-internal ", diff --git a/cmds-property.c b/cmds-property.c index 854bff56..9ae12460 100644 --- a/cmds-property.c +++ b/cmds-property.c @@ -26,6 +26,7 @@ #include "props.h" #include "ctree.h" #include "utils.h" +#include "help.h" static const char * const property_cmd_group_usage[] = { "btrfs property get/set/list [-t ] [] [value]", diff --git a/cmds-qgroup.c b/cmds-qgroup.c index f4503fd9..38382ea9 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -26,6 +26,7 @@ #include "commands.h" #include "qgroup.h" #include "utils.h" +#include "help.h" static const char * const qgroup_cmd_group_usage[] = { "btrfs qgroup [options] ", diff --git a/cmds-quota.c b/cmds-quota.c index f9b422dc..15bd4b93 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -24,6 +24,7 @@ #include "commands.h" #include "utils.h" +#include "help.h" static const char * const quota_cmd_group_usage[] = { "btrfs quota [options] ", diff --git a/cmds-receive.c b/cmds-receive.c index 166d37dc..df86c03f 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -50,6 +50,7 @@ #include "send-stream.h" #include "send-utils.h" #include "send-dump.h" +#include "help.h" static int g_verbose = 0; diff --git a/cmds-replace.c b/cmds-replace.c index 9345da23..ee7938cd 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -37,7 +37,7 @@ #include "disk-io.h" #include "commands.h" - +#include "help.h" static int print_replace_status(int fd, const char *path, int once); static char *time2string(char *buf, size_t s, __u64 t); diff --git a/cmds-rescue.c b/cmds-rescue.c index f597997b..7e7344ee 100644 --- a/cmds-rescue.c +++ b/cmds-rescue.c @@ -24,6 +24,7 @@ #include "disk-io.h" #include "commands.h" #include "utils.h" +#include "help.h" static const char * const rescue_cmd_group_usage[] = { "btrfs rescue [options] ", diff --git a/cmds-restore.c b/cmds-restore.c index bdd35bd7..c327cef0 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -42,6 +42,7 @@ #include "volumes.h" #include "utils.h" #include "commands.h" +#include "help.h" static char fs_name[PATH_MAX]; static char path_name[PATH_MAX]; diff --git a/cmds-scrub.c b/cmds-scrub.c index 292a5dfd..5388fdcf 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -44,6 +44,7 @@ #include "disk-io.h" #include "commands.h" +#include "help.h" static const char * const scrub_cmd_group_usage[] = { "btrfs scrub [options] |", diff --git a/cmds-send.c b/cmds-send.c index 6c0a3dc3..c5ecdaa1 100644 --- a/cmds-send.c +++ b/cmds-send.c @@ -43,6 +43,7 @@ #include "send.h" #include "send-utils.h" +#include "help.h" #define SEND_BUFFER_SIZE SZ_64K diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 7384de45..674a3a51 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -37,6 +37,7 @@ #include "utils.h" #include "btrfs-list.h" #include "utils.h" +#include "help.h" static int is_subvolume_cleaned(int fd, u64 subvolid) { diff --git a/commands.h b/commands.h index 94229c11..e719c491 100644 --- a/commands.h +++ b/commands.h @@ -71,19 +71,8 @@ int prefixcmp(const char *str, const char *prefix); int handle_command_group(const struct cmd_group *grp, int argc, char **argv); -/* help.c */ extern const char * const generic_cmd_help_usage[]; -void usage(const char * const *usagestr) __attribute__((noreturn)); -void usage_command(const struct cmd_struct *cmd, int full, int err); -void usage_command_group(const struct cmd_group *grp, int all, int err); -void usage_command_group_short(const struct cmd_group *grp); - -void help_unknown_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn)); -void help_ambiguous_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn)); - -void help_command_group(const struct cmd_group *grp, int argc, char **argv); - extern const struct cmd_group subvolume_cmd_group; extern const struct cmd_group filesystem_cmd_group; extern const struct cmd_group balance_cmd_group; diff --git a/convert/main.c b/convert/main.c index 8d9f29fa..fa05485a 100644 --- a/convert/main.c +++ b/convert/main.c @@ -37,6 +37,7 @@ #include "crc32c.h" #include "utils.h" #include "task-utils.h" +#include "help.h" #if BTRFSCONVERT_EXT2 #include diff --git a/help.c b/help.c index 5573f0f9..3060059f 100644 --- a/help.c +++ b/help.c @@ -21,6 +21,7 @@ #include "commands.h" #include "utils.h" +#include "help.h" #define USAGE_SHORT 1U #define USAGE_LONG 2U diff --git a/help.h b/help.h new file mode 100644 index 00000000..7458e745 --- /dev/null +++ b/help.h @@ -0,0 +1,79 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef __BTRFS_HELP_H__ +#define __BTRFS_HELP_H__ + +#define GETOPT_VAL_SI 256 +#define GETOPT_VAL_IEC 257 +#define GETOPT_VAL_RAW 258 +#define GETOPT_VAL_HUMAN_READABLE 259 +#define GETOPT_VAL_KBYTES 260 +#define GETOPT_VAL_MBYTES 261 +#define GETOPT_VAL_GBYTES 262 +#define GETOPT_VAL_TBYTES 263 + +#define GETOPT_VAL_HELP 270 + +#define ARGV0_BUF_SIZE PATH_MAX + +#define HELPINFO_UNITS_LONG \ + "--raw raw numbers in bytes", \ + "--human-readable human friendly numbers, base 1024 (default)", \ + "--iec use 1024 as a base (KiB, MiB, GiB, TiB)", \ + "--si use 1000 as a base (kB, MB, GB, TB)", \ + "--kbytes show sizes in KiB, or kB with --si", \ + "--mbytes show sizes in MiB, or MB with --si", \ + "--gbytes show sizes in GiB, or GB with --si", \ + "--tbytes show sizes in TiB, or TB with --si" + +#define HELPINFO_UNITS_SHORT_LONG \ + "-b|--raw raw numbers in bytes", \ + "-h|--human-readable", \ + " human friendly numbers, base 1024 (default)", \ + "-H human friendly numbers, base 1000", \ + "--iec use 1024 as a base (KiB, MiB, GiB, TiB)", \ + "--si use 1000 as a base (kB, MB, GB, TB)", \ + "-k|--kbytes show sizes in KiB, or kB with --si", \ + "-m|--mbytes show sizes in MiB, or MB with --si", \ + "-g|--gbytes show sizes in GiB, or GB with --si", \ + "-t|--tbytes show sizes in TiB, or TB with --si" + +struct cmd_struct; +struct cmd_group; + +void usage(const char * const *usagestr) __attribute__((noreturn)); +void usage_command(const struct cmd_struct *cmd, int full, int err); +void usage_command_group(const struct cmd_group *grp, int all, int err); +void usage_command_group_short(const struct cmd_group *grp); + +void help_unknown_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn)); +void help_ambiguous_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn)); + +void help_command_group(const struct cmd_group *grp, int argc, char **argv); + +int check_argc_exact(int nargs, int expected); +int check_argc_min(int nargs, int expected); +int check_argc_max(int nargs, int expected); +void clean_args_no_options(int argc, char *argv[], const char * const *usage); +void clean_args_no_options_relaxed(int argc, char *argv[], + const char * const *usagestr); + +void fixup_argv0(char **argv, const char *token); +void set_argv0(char **argv); +const char *get_argv0_buf(void); + +#endif diff --git a/image/main.c b/image/main.c index 0158844b..1f761ad9 100644 --- a/image/main.c +++ b/image/main.c @@ -35,6 +35,7 @@ #include "utils.h" #include "volumes.h" #include "extent_io.h" +#include "help.h" #define HEADER_MAGIC 0xbd5c25e27295668bULL #define MAX_PENDING_SIZE (256 * 1024) diff --git a/mkfs/main.c b/mkfs/main.c index 72834c9c..770039f2 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -43,6 +43,7 @@ #include "transaction.h" #include "utils.h" #include "list_sort.h" +#include "help.h" static u64 index_cnt = 2; static int verbose = 1; diff --git a/utils.c b/utils.c index b4f667e5..47d3be91 100644 --- a/utils.c +++ b/utils.c @@ -51,6 +51,7 @@ #include "volumes.h" #include "ioctl.h" #include "commands.h" +#include "help.h" #ifndef BLKDISCARD #define BLKDISCARD _IO(0x12,119) diff --git a/utils.h b/utils.h index ebe01a6a..c4abe465 100644 --- a/utils.h +++ b/utils.h @@ -64,26 +64,6 @@ #define BTRFS_UUID_UNPARSED_SIZE 37 -#define ARGV0_BUF_SIZE PATH_MAX - -#define GETOPT_VAL_SI 256 -#define GETOPT_VAL_IEC 257 -#define GETOPT_VAL_RAW 258 -#define GETOPT_VAL_HUMAN_READABLE 259 -#define GETOPT_VAL_KBYTES 260 -#define GETOPT_VAL_MBYTES 261 -#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); - -void fixup_argv0(char **argv, const char *token); -void set_argv0(char **argv); - /* * Output modes of size */ @@ -286,34 +266,7 @@ static inline u64 div_factor(u64 num, int factor) int btrfs_tree_search2_ioctl_supported(int fd); int btrfs_check_nodesize(u32 nodesize, u32 sectorsize, u64 features); -const char *get_argv0_buf(void); - -#define HELPINFO_UNITS_LONG \ - "--raw raw numbers in bytes", \ - "--human-readable human friendly numbers, base 1024 (default)", \ - "--iec use 1024 as a base (KiB, MiB, GiB, TiB)", \ - "--si use 1000 as a base (kB, MB, GB, TB)", \ - "--kbytes show sizes in KiB, or kB with --si", \ - "--mbytes show sizes in MiB, or MB with --si", \ - "--gbytes show sizes in GiB, or GB with --si", \ - "--tbytes show sizes in TiB, or TB with --si" - -#define HELPINFO_UNITS_SHORT_LONG \ - "-b|--raw raw numbers in bytes", \ - "-h|--human-readable", \ - " human friendly numbers, base 1024 (default)", \ - "-H human friendly numbers, base 1000", \ - "--iec use 1024 as a base (KiB, MiB, GiB, TiB)", \ - "--si use 1000 as a base (kB, MB, GB, TB)", \ - "-k|--kbytes show sizes in KiB, or kB with --si", \ - "-m|--mbytes show sizes in MiB, or MB with --si", \ - "-g|--gbytes show sizes in GiB, or GB with --si", \ - "-t|--tbytes show sizes in TiB, or TB with --si" - unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode); -void clean_args_no_options(int argc, char *argv[], const char * const *usage); -void clean_args_no_options_relaxed(int argc, char *argv[], - const char * const *usagestr); int string_is_numerical(const char *str); #if DEBUG_VERBOSE_ERROR