1 /* libguestfs - guestfish and guestmount shared option parsing
2 * Copyright (C) 2010 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);
109 /* Don't use guestfs_mount here because that will default to mount
110 * options -o sync,noatime. For more information, see guestfs(3)
111 * section "LIBGUESTFS GOTCHAS".
113 const char *options = read_only ? "ro" : "";
114 r = guestfs_mount_options (g, options, mp->device, mp->mountpoint);
116 /* Display possible mountpoints before exiting. */
117 char **fses = guestfs_list_filesystems (g);
118 if (fses == NULL || fses[0] == NULL)
121 _("%s: '%s' could not be mounted. Did you mean one of these?\n"),
122 program_name, mp->device);
124 for (i = 0; fses[i] != NULL; i += 2)
125 fprintf (stderr, "\t%s (%s)\n", fses[i], fses[i+1]);
134 free_drives (struct drv *drv)
137 free_drives (drv->next);
142 case drv_a: /* a.filename and a.format are optargs, don't free them */ break;
143 case drv_d: /* d.filename is optarg, don't free it */ break;
145 free (drv->N.filename);
146 drv->N.data_free (drv->N.data);
148 default: ; /* keep GCC happy */
154 free_mps (struct mp *mp)
159 /* The drive and mountpoint fields are not allocated
160 * from the heap, so we should not free them here.