]> sourceware.org Git - lvm2.git/blob - tools/tools.h
Reinstate accidentally-deleted line.
[lvm2.git] / tools / tools.h
1 /*
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 *
5 * This file is part of LVM2.
6 *
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
10 *
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 */
15
16 #ifndef _LVM_TOOLS_H
17 #define _LVM_TOOLS_H
18
19 #define _GNU_SOURCE
20 #define _FILE_OFFSET_BITS 64
21
22 #include "configure.h"
23 #include <assert.h>
24 #include "libdevmapper.h"
25
26 #include "lvm-types.h"
27 #include "lvm-logging.h"
28 #include "activate.h"
29 #include "archiver.h"
30 #include "lvmcache.h"
31 #include "lvmetad.h"
32 #include "config.h"
33 #include "defaults.h"
34 #include "dev-cache.h"
35 #include "device.h"
36 #include "display.h"
37 #include "errors.h"
38 #include "filter.h"
39 #include "filter-composite.h"
40 #include "filter-persistent.h"
41 #include "filter-regex.h"
42 #include "metadata-exported.h"
43 #include "locking.h"
44 #include "lvm-exec.h"
45 #include "lvm-file.h"
46 #include "lvm-string.h"
47 #include "segtype.h"
48 #include "str_list.h"
49 #include "toolcontext.h"
50 #include "toollib.h"
51
52 #include <stdlib.h>
53 #include <unistd.h>
54 #include <ctype.h>
55 #include <limits.h>
56 #include <stdarg.h>
57 #include <sys/types.h>
58
59 #define CMD_LEN 256
60 #define MAX_ARGS 64
61
62 /* command functions */
63 typedef int (*command_fn) (struct cmd_context * cmd, int argc, char **argv);
64
65 #define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
66 #include "commands.h"
67 #undef xx
68
69 /* define the enums for the command line switches */
70 enum {
71 #define arg(a, b, c, d, e) a ,
72 #include "args.h"
73 #undef arg
74 };
75
76 typedef enum {
77 SIGN_NONE = 0,
78 SIGN_PLUS = 1,
79 SIGN_MINUS = 2
80 } sign_t;
81
82 typedef enum {
83 PERCENT_NONE = 0,
84 PERCENT_VG,
85 PERCENT_FREE,
86 PERCENT_LV,
87 PERCENT_PVS,
88 PERCENT_ORIGIN
89 } percent_type_t;
90
91 #define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
92 #define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
93
94 struct arg_values {
95 unsigned count;
96 char *value;
97 int32_t i_value;
98 uint32_t ui_value;
99 int64_t i64_value;
100 uint64_t ui64_value;
101 sign_t sign;
102 percent_type_t percent;
103 /* void *ptr; // Currently not used. */
104 };
105
106 /* a global table of possible arguments */
107 struct arg_props {
108 const char short_arg;
109 char _padding[7];
110 const char *long_arg;
111
112 int (*fn) (struct cmd_context *cmd, struct arg_values *av);
113 uint32_t flags;
114 };
115
116 struct arg_value_group_list {
117 struct dm_list list;
118 struct arg_values arg_values[0];
119 };
120
121 #define CACHE_VGMETADATA 0x00000001
122 #define PERMITTED_READ_ONLY 0x00000002
123
124 /* a register of the lvm commands */
125 struct command {
126 const char *name;
127 const char *desc;
128 const char *usage;
129 command_fn fn;
130
131 unsigned flags;
132
133 int num_args;
134 int *valid_args;
135 };
136
137 void usage(const char *name);
138
139 /* the argument verify/normalise functions */
140 int yes_no_arg(struct cmd_context *cmd, struct arg_values *av);
141 int yes_no_excl_arg(struct cmd_context *cmd, struct arg_values *av);
142 int size_kb_arg(struct cmd_context *cmd, struct arg_values *av);
143 int size_mb_arg(struct cmd_context *cmd, struct arg_values *av);
144 int int_arg(struct cmd_context *cmd, struct arg_values *av);
145 int int_arg_with_sign(struct cmd_context *cmd, struct arg_values *av);
146 int int_arg_with_sign_and_percent(struct cmd_context *cmd, struct arg_values *av);
147 int major_arg(struct cmd_context *cmd, struct arg_values *av);
148 int minor_arg(struct cmd_context *cmd, struct arg_values *av);
149 int string_arg(struct cmd_context *cmd, struct arg_values *av);
150 int tag_arg(struct cmd_context *cmd, struct arg_values *av);
151 int permission_arg(struct cmd_context *cmd, struct arg_values *av);
152 int metadatatype_arg(struct cmd_context *cmd, struct arg_values *av);
153 int units_arg(struct cmd_context *cmd, struct arg_values *av);
154 int segtype_arg(struct cmd_context *cmd, struct arg_values *av);
155 int alloc_arg(struct cmd_context *cmd, struct arg_values *av);
156 int readahead_arg(struct cmd_context *cmd, struct arg_values *av);
157 int metadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
158
159 /* we use the enums to access the switches */
160 unsigned arg_count(const struct cmd_context *cmd, int a);
161 unsigned arg_is_set(const struct cmd_context *cmd, int a);
162 const char *arg_value(struct cmd_context *cmd, int a);
163 const char *arg_str_value(struct cmd_context *cmd, int a, const char *def);
164 int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def);
165 uint32_t arg_uint_value(struct cmd_context *cmd, int a, const uint32_t def);
166 int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def);
167 uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def);
168 const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def);
169 sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def);
170 percent_type_t arg_percent_value(struct cmd_context *cmd, int a, const percent_type_t def);
171 int arg_count_increment(struct cmd_context *cmd, int a);
172
173 unsigned grouped_arg_count(const struct arg_values *av, int a);
174 unsigned grouped_arg_is_set(const struct arg_values *av, int a);
175 const char *grouped_arg_str_value(const struct arg_values *av, int a, const char *def);
176
177 const char *command_name(struct cmd_context *cmd);
178
179 int pvmove_poll(struct cmd_context *cmd, const char *pv, unsigned background);
180 int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv, unsigned background);
181
182 int mirror_remove_missing(struct cmd_context *cmd,
183 struct logical_volume *lv, int force);
184
185 uint32_t percent_of_extents(uint32_t percents, uint32_t count, int roundup);
186 #endif
This page took 0.043907 seconds and 5 git commands to generate.