Btrfs-progs: add btrfs send/receive commands
[platform/upstream/btrfs-progs.git] / commands.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public
4  * License v2 as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9  * General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the
13  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14  * Boston, MA 021110-1307, USA.
15  */
16
17 #define ARGV0_BUF_SIZE  64
18
19 struct cmd_struct {
20         const char *token;
21         int (*fn)(int, char **);
22
23         /*
24          * Usage strings
25          *
26          * A NULL-terminated array of the following format:
27          *
28          *   usagestr[0] - one-line synopsis (required)
29          *   usagestr[1] - one-line short description (required)
30          *   usagestr[2..m] - a long (possibly multi-line) description
31          *                    (optional)
32          *   usagestr[m + 1] - an empty line separator (required if at least one
33          *                     option string is given, not needed otherwise)
34          *   usagestr[m + 2..n] - option strings, one option per line
35          *                        (optional)
36          *   usagestr[n + 1] - NULL terminator
37          *
38          * Options (if present) should always (even if there is no long
39          * description) be prepended with an empty line.  Supplied strings are
40          * indented but otherwise printed as-is, no automatic wrapping is done.
41          *
42          * Grep for cmd_*_usage[] for examples.
43          */
44         const char * const *usagestr;
45
46         /* should be NULL if token is not a subgroup */
47         const struct cmd_group *next;
48
49         /* if true don't list this token in help listings */
50         int hidden;
51 };
52
53 struct cmd_group {
54         const char * const *usagestr;
55         const char *infostr;
56
57         const struct cmd_struct commands[];
58 };
59
60 /* btrfs.c */
61 int prefixcmp(const char *str, const char *prefix);
62
63 int check_argc_exact(int nargs, int expected);
64 int check_argc_min(int nargs, int expected);
65 int check_argc_max(int nargs, int expected);
66
67 int handle_command_group(const struct cmd_group *grp, int argc,
68                          char **argv);
69
70 /* help.c */
71 extern const char * const generic_cmd_help_usage[];
72
73 void usage(const char * const *usagestr);
74 void usage_command(const struct cmd_struct *cmd, int full, int err);
75 void usage_command_group(const struct cmd_group *grp, int all, int err);
76
77 void help_unknown_token(const char *arg, const struct cmd_group *grp);
78 void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
79
80 void help_command_group(const struct cmd_group *grp, int argc, char **argv);
81
82 /* common.c */
83 int open_file_or_dir(const char *fname);
84
85 extern const struct cmd_group subvolume_cmd_group;
86 extern const struct cmd_group filesystem_cmd_group;
87 extern const struct cmd_group balance_cmd_group;
88 extern const struct cmd_group device_cmd_group;
89 extern const struct cmd_group scrub_cmd_group;
90 extern const struct cmd_group inspect_cmd_group;
91 extern const struct cmd_group send_cmd_group;
92 extern const struct cmd_group receive_cmd_group;
93
94 int cmd_subvolume(int argc, char **argv);
95 int cmd_filesystem(int argc, char **argv);
96 int cmd_balance(int argc, char **argv);
97 int cmd_device(int argc, char **argv);
98 int cmd_scrub(int argc, char **argv);
99 int cmd_inspect(int argc, char **argv);
100 int cmd_send(int argc, char **argv);
101 int cmd_receive(int argc, char **argv);