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.
29 add_drives (struct drv *drv, char next_drive)
32 struct guestfs_add_drive_opts_argv ad_optargs;
34 if (next_drive > 'z') {
36 _("%s: too many drives added on the command line\n"),
42 next_drive = add_drives (drv->next, next_drive);
44 if (asprintf (&drv->device, "/dev/sd%c", next_drive) == -1) {
51 ad_optargs.bitmask = 0;
53 ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
54 ad_optargs.readonly = 1;
57 ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
58 ad_optargs.format = drv->a.format;
60 r = guestfs_add_drive_opts_argv (g, drv->a.filename, &ad_optargs);
69 r = add_libvirt_drives (drv->d.guest);
78 /* guestfs_add_drive (ie. autodetecting) should be safe here
79 * since we have just created the prepared disk. At the moment
80 * it will always be "raw" but in a theoretical future we might
81 * create other formats.
83 /* -N option is not affected by --ro */
84 r = guestfs_add_drive (g, drv->N.filename);
92 default: /* keep GCC happy */
100 /* List is built in reverse order, so mount them in reverse order. */
102 mount_mps (struct mp *mp)
107 mount_mps (mp->next);
111 options = mp->options;
117 /* Don't use guestfs_mount here because that will default to mount
118 * options -o sync,noatime. For more information, see guestfs(3)
119 * section "LIBGUESTFS GOTCHAS".
121 r = guestfs_mount_options (g, options, mp->device, mp->mountpoint);
123 /* Display possible mountpoints before exiting. */
124 char **fses = guestfs_list_filesystems (g);
125 if (fses == NULL || fses[0] == NULL)
128 _("%s: '%s' could not be mounted. Did you mean one of these?\n"),
129 program_name, mp->device);
131 for (i = 0; fses[i] != NULL; i += 2)
132 fprintf (stderr, "\t%s (%s)\n", fses[i], fses[i+1]);
141 free_drives (struct drv *drv)
144 free_drives (drv->next);
149 case drv_a: /* a.filename and a.format are optargs, don't free them */ break;
150 case drv_d: /* d.filename is optarg, don't free it */ break;
152 free (drv->N.filename);
153 drv->N.data_free (drv->N.data);
155 default: ; /* keep GCC happy */
161 free_mps (struct mp *mp)
166 /* The drive and mountpoint fields are not allocated
167 * from the heap, so we should not free them here.