Tizen 2.1 base
[external/device-mapper.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 "config.h"
32 #include "defaults.h"
33 #include "dev-cache.h"
34 #include "device.h"
35 #include "display.h"
36 #include "errors.h"
37 #include "filter.h"
38 #include "filter-composite.h"
39 #include "filter-persistent.h"
40 #include "filter-regex.h"
41 #include "metadata-exported.h"
42 #include "locking.h"
43 #include "lvm-exec.h"
44 #include "lvm-file.h"
45 #include "lvm-string.h"
46 #include "segtype.h"
47 #include "str_list.h"
48 #include "toolcontext.h"
49 #include "toollib.h"
50
51 #include <stdlib.h>
52 #include <unistd.h>
53 #include <ctype.h>
54 #include <limits.h>
55 #include <stdarg.h>
56 #include <sys/types.h>
57
58 #define CMD_LEN 256
59 #define MAX_ARGS 64
60
61 /* command functions */
62 typedef int (*command_fn) (struct cmd_context * cmd, int argc, char **argv);
63
64 #define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
65 #include "commands.h"
66 #undef xx
67
68 /* define the enums for the command line switches */
69 enum {
70 #define arg(a, b, c, d, e) a ,
71 #include "args.h"
72 #undef arg
73 };
74
75 typedef enum {
76         SIGN_NONE = 0,
77         SIGN_PLUS = 1,
78         SIGN_MINUS = 2
79 } sign_t;
80
81 typedef enum {
82         PERCENT_NONE = 0,
83         PERCENT_VG,
84         PERCENT_FREE,
85         PERCENT_LV,
86         PERCENT_PVS,
87         PERCENT_ORIGIN
88 } percent_type_t;
89
90 enum {
91         CHANGE_AY = 0,
92         CHANGE_AN = 1,
93         CHANGE_AE = 2,
94         CHANGE_ALY = 3,
95         CHANGE_ALN = 4
96 };
97
98 #define ARG_COUNTABLE 0x00000001        /* E.g. -vvvv */
99 #define ARG_GROUPABLE 0x00000002        /* E.g. --addtag */
100
101 struct arg_values {
102         unsigned count;
103         char *value;
104         int32_t i_value;
105         uint32_t ui_value;
106         int64_t i64_value;
107         uint64_t ui64_value;
108         sign_t sign;
109         percent_type_t percent;
110 /*      void *ptr; // Currently not used. */
111 };
112
113 /* a global table of possible arguments */
114 struct arg_props {
115         const char short_arg;
116         char _padding[7];
117         const char *long_arg;
118
119         int (*fn) (struct cmd_context *cmd, struct arg_values *av);
120         uint32_t flags;
121 };
122
123 struct arg_value_group_list {
124         struct dm_list list;
125         struct arg_values arg_values[0];
126 };
127
128 #define CACHE_VGMETADATA        0x00000001
129 #define PERMITTED_READ_ONLY     0x00000002
130
131 /* a register of the lvm commands */
132 struct command {
133         const char *name;
134         const char *desc;
135         const char *usage;
136         command_fn fn;
137
138         unsigned flags;
139
140         int num_args;
141         int *valid_args;
142 };
143
144 void usage(const char *name);
145
146 /* the argument verify/normalise functions */
147 int yes_no_arg(struct cmd_context *cmd, struct arg_values *av);
148 int yes_no_excl_arg(struct cmd_context *cmd, struct arg_values *av);
149 int size_kb_arg(struct cmd_context *cmd, struct arg_values *av);
150 int size_mb_arg(struct cmd_context *cmd, struct arg_values *av);
151 int int_arg(struct cmd_context *cmd, struct arg_values *av);
152 int int_arg_with_sign(struct cmd_context *cmd, struct arg_values *av);
153 int int_arg_with_sign_and_percent(struct cmd_context *cmd, struct arg_values *av);
154 int major_arg(struct cmd_context *cmd, struct arg_values *av);
155 int minor_arg(struct cmd_context *cmd, struct arg_values *av);
156 int string_arg(struct cmd_context *cmd, struct arg_values *av);
157 int tag_arg(struct cmd_context *cmd, struct arg_values *av);
158 int permission_arg(struct cmd_context *cmd, struct arg_values *av);
159 int metadatatype_arg(struct cmd_context *cmd, struct arg_values *av);
160 int units_arg(struct cmd_context *cmd, struct arg_values *av);
161 int segtype_arg(struct cmd_context *cmd, struct arg_values *av);
162 int alloc_arg(struct cmd_context *cmd, struct arg_values *av);
163 int readahead_arg(struct cmd_context *cmd, struct arg_values *av);
164 int metadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
165
166 /* we use the enums to access the switches */
167 unsigned arg_count(const struct cmd_context *cmd, int a);
168 unsigned arg_is_set(const struct cmd_context *cmd, int a);
169 const char *arg_value(struct cmd_context *cmd, int a);
170 const char *arg_str_value(struct cmd_context *cmd, int a, const char *def);
171 int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def); 
172 uint32_t arg_uint_value(struct cmd_context *cmd, int a, const uint32_t def);
173 int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def);
174 uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def);
175 const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def);
176 sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def);
177 percent_type_t arg_percent_value(struct cmd_context *cmd, int a, const percent_type_t def);
178 int arg_count_increment(struct cmd_context *cmd, int a);
179
180 unsigned grouped_arg_count(const struct arg_values *av, int a);
181 unsigned grouped_arg_is_set(const struct arg_values *av, int a);
182 const char *grouped_arg_str_value(const struct arg_values *av, int a, const char *def);
183
184 const char *command_name(struct cmd_context *cmd);
185
186 int pvmove_poll(struct cmd_context *cmd, const char *pv, unsigned background);
187 int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv, unsigned background);
188
189 #endif