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