1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* libguestfs - guestfish and guestmount shared option parsing
* Copyright (C) 2010-2011 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef OPTIONS_H
#define OPTIONS_H
#ifdef HAVE_GETTEXT
#include "gettext.h"
#ifndef _
#define _(str) dgettext(PACKAGE, (str))
#endif
#ifndef N_
#define N_(str) dgettext(PACKAGE, (str))
#endif
#else
#ifndef _
#define _(str) str
#endif
#ifndef _
#define N_(str) str
#endif
#endif
#ifndef STREQ
#define STREQ(a,b) (strcmp((a),(b)) == 0)
#endif
#ifndef STRCASEEQ
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
#endif
#ifndef STRNEQ
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
#endif
#ifndef STRCASENEQ
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
#endif
#ifndef STREQLEN
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
#endif
#ifndef STRCASEEQLEN
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
#endif
#ifndef STRNEQLEN
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
#endif
#ifndef STRCASENEQLEN
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
#endif
#ifndef STRPREFIX
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
#endif
/* Provided by guestfish or guestmount. */
extern guestfs_h *g;
extern int read_only;
extern int live;
extern int verbose;
extern int inspector;
extern int keys_from_stdin;
extern int echo_keys;
extern const char *libvirt_uri;
extern const char *program_name;
/* List of drives added via -a, -d or -N options. */
struct drv {
struct drv *next;
char *device; /* Device name inside the appliance (eg. /dev/sda).
* This is filled in when we add the drives in
* add_drives. Note that guests (-d option) may
* have multiple drives, in which case this is the
* first drive, and nr_drives is the number of
* drives used.
*/
int nr_drives; /* number of drives for this guest */
enum { drv_a, drv_d, drv_N } type;
union {
struct {
char *filename; /* disk filename */
const char *format; /* format (NULL == autodetect) */
} a;
struct {
char *guest; /* guest name */
} d;
struct {
char *filename; /* disk filename (testX.img) */
void *data; /* prepared type */
void (*data_free)(void*); /* function to free 'data' */
} N;
};
};
struct mp {
struct mp *next;
char *device;
char *mountpoint;
char *options;
};
/* in config.c */
extern void parse_config (void);
/* in inspect.c */
extern void inspect_mount (void);
extern void print_inspect_prompt (void);
/* (low-level inspection functions, used by virt-inspector only) */
extern void inspect_do_decrypt (void);
extern void inspect_mount_root (const char *root);
/* in key.c */
extern char *read_key (const char *param);
/* in options.c */
extern char add_drives (struct drv *drv, char next_drive);
extern void mount_mps (struct mp *mp);
extern void free_drives (struct drv *drv);
extern void free_mps (struct mp *mp);
/* in virt.c */
extern int add_libvirt_drives (const char *guest);
#define OPTION_a \
if (access (optarg, R_OK) != 0) { \
perror (optarg); \
exit (EXIT_FAILURE); \
} \
drv = malloc (sizeof (struct drv)); \
if (!drv) { \
perror ("malloc"); \
exit (EXIT_FAILURE); \
} \
drv->type = drv_a; \
drv->device = NULL; \
drv->nr_drives = -1; \
drv->a.filename = optarg; \
drv->a.format = format; \
drv->next = drvs; \
drvs = drv
#define OPTION_c \
libvirt_uri = optarg
#define OPTION_d \
drv = malloc (sizeof (struct drv)); \
if (!drv) { \
perror ("malloc"); \
exit (EXIT_FAILURE); \
} \
drv->type = drv_d; \
drv->device = NULL; \
drv->nr_drives = -1; \
drv->d.guest = optarg; \
drv->next = drvs; \
drvs = drv
#define OPTION_i \
inspector = 1
#define OPTION_m \
mp = malloc (sizeof (struct mp)); \
if (!mp) { \
perror ("malloc"); \
exit (EXIT_FAILURE); \
} \
mp->options = NULL; \
mp->mountpoint = bad_cast ("/"); \
p = strchr (optarg, ':'); \
if (p) { \
*p = '\0'; \
p++; \
mp->mountpoint = p; \
p = strchr (p, ':'); \
if (p) { \
*p = '\0'; \
p++; \
mp->options = p; \
} \
} \
mp->device = optarg; \
mp->next = mps; \
mps = mp
#define OPTION_n \
guestfs_set_autosync (g, 0)
#define OPTION_r \
read_only = 1
#define OPTION_v \
verbose++; \
guestfs_set_verbose (g, verbose)
#define OPTION_V \
{ \
struct guestfs_version *v = guestfs_version (g); \
printf ("%s %"PRIi64".%"PRIi64".%"PRIi64"%s\n", \
program_name, \
v->major, v->minor, v->release, v->extra); \
exit (EXIT_SUCCESS); \
}
#define OPTION_w \
if (read_only) { \
fprintf (stderr, _("%s: cannot mix --ro and --rw options\n"), \
program_name); \
exit (EXIT_FAILURE); \
}
#define OPTION_x \
guestfs_set_trace (g, 1)
#endif /* OPTIONS_H */
|