1 /* libguestfs - guestfish and guestmount shared option parsing
2 * Copyright (C) 2010-2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #define _(str) dgettext(PACKAGE, (str))
28 #define N_(str) dgettext(PACKAGE, (str))
40 #define STREQ(a,b) (strcmp((a),(b)) == 0)
43 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
46 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
49 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
52 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
55 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
58 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
61 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
64 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
67 /* Provided by guestfish or guestmount. */
73 extern int keys_from_stdin;
75 extern const char *libvirt_uri;
76 extern const char *program_name;
78 /* List of drives added via -a, -d or -N options. */
82 char *device; /* Device name inside the appliance (eg. /dev/sda).
83 * This is filled in when we add the drives in
84 * add_drives. Note that guests (-d option) may
85 * have multiple drives, in which case this is the
86 * first drive, and nr_drives is the number of
89 int nr_drives; /* number of drives for this guest */
91 enum { drv_a, drv_d, drv_N } type;
94 char *filename; /* disk filename */
95 const char *format; /* format (NULL == autodetect) */
98 char *guest; /* guest name */
101 char *filename; /* disk filename (testX.img) */
102 void *data; /* prepared type */
103 void (*data_free)(void*); /* function to free 'data' */
116 extern void parse_config (void);
119 extern void inspect_mount (void);
120 extern void print_inspect_prompt (void);
121 /* (low-level inspection functions, used by virt-inspector only) */
122 extern void inspect_do_decrypt (void);
123 extern void inspect_mount_root (const char *root);
126 extern char *read_key (const char *param);
129 extern char add_drives (struct drv *drv, char next_drive);
130 extern void mount_mps (struct mp *mp);
131 extern void free_drives (struct drv *drv);
132 extern void free_mps (struct mp *mp);
135 extern int add_libvirt_drives (const char *guest);
138 if (access (optarg, R_OK) != 0) { \
140 exit (EXIT_FAILURE); \
142 drv = malloc (sizeof (struct drv)); \
145 exit (EXIT_FAILURE); \
148 drv->device = NULL; \
149 drv->nr_drives = -1; \
150 drv->a.filename = optarg; \
151 drv->a.format = format; \
159 drv = malloc (sizeof (struct drv)); \
162 exit (EXIT_FAILURE); \
165 drv->device = NULL; \
166 drv->nr_drives = -1; \
167 drv->d.guest = optarg; \
175 mp = malloc (sizeof (struct mp)); \
178 exit (EXIT_FAILURE); \
180 mp->options = NULL; \
181 mp->mountpoint = bad_cast ("/"); \
182 p = strchr (optarg, ':'); \
186 mp->mountpoint = p; \
187 p = strchr (p, ':'); \
194 mp->device = optarg; \
199 guestfs_set_autosync (g, 0)
206 guestfs_set_verbose (g, verbose)
210 struct guestfs_version *v = guestfs_version (g); \
211 printf ("%s %"PRIi64".%"PRIi64".%"PRIi64"%s\n", \
213 v->major, v->minor, v->release, v->extra); \
214 exit (EXIT_SUCCESS); \
219 fprintf (stderr, _("%s: cannot mix --ro and --rw options\n"), \
221 exit (EXIT_FAILURE); \
225 guestfs_set_trace (g, 1)
227 #endif /* OPTIONS_H */