Implement the -m/--mount as available in guestfish to override the
automatic introspection and specify which partitions to mount instead.
---
edit/edit.c | 38 +++++++++++++++++++++++++++++++++-----
edit/virt-edit.pod | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/edit/edit.c b/edit/edit.c
index 07790be..7a2603c 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -53,6 +53,7 @@ static const char *backup_extension = NULL;
static const char *perl_expr = NULL;
static void edit_files (int argc, char *argv[]);
+static void edit_files_simple (int argc, char *argv[]);
static void edit (const char *filename, const char *root);
static char *edit_interactively (const char *tmpfile);
static char *edit_non_interactively (const char *tmpfile);
@@ -84,6 +85,8 @@ usage (int status)
" --format[=raw|..] Force disk format for -a option\n"
" --help Display brief help\n"
" --keys-from-stdin Read passphrases from stdin\n"
+ " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
+ " Mount dev on mnt (if omitted, /)\n"
" -v|--verbose Verbose messages\n"
" -V|--version Display version and exit\n"
" -x Trace libguestfs API calls\n"
@@ -106,7 +109,7 @@ main (int argc, char *argv[])
enum { HELP_OPTION = CHAR_MAX + 1 };
- static const char *options = "a:b:c:d:e:vVx";
+ static const char *options = "a:b:c:d:e:m:vVx";
static const struct option long_options[] = {
{ "add", 1, 0, 'a' },
{ "backup", 1, 0, 'b' },
@@ -119,12 +122,16 @@ main (int argc, char *argv[])
{ "help", 0, 0, HELP_OPTION },
{ "keys-from-stdin", 0, 0, 0 },
{ "long-options", 0, 0, 0 },
+ { "mount", 1, 0, 'm' },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
};
struct drv *drvs = NULL;
struct drv *drv;
+ struct mp *mps = NULL;
+ struct mp *mp;
+ char *p;
const char *format = NULL;
int c;
int option_index;
@@ -189,6 +196,11 @@ main (int argc, char *argv[])
perl_expr = optarg;
break;
+ case 'm':
+ OPTION_m;
+ inspector = 0;
+ break;
+
case 'v':
OPTION_v;
break;
@@ -251,7 +263,7 @@ main (int argc, char *argv[])
* values.
*/
assert (read_only == 0);
- assert (inspector == 1);
+ assert (inspector == 1 || mps != NULL);
assert (live == 0);
/* User must specify at least one filename on the command line. */
@@ -268,12 +280,19 @@ main (int argc, char *argv[])
if (guestfs_launch (g) == -1)
exit (EXIT_FAILURE);
- inspect_mount ();
+ if (mps != NULL)
+ mount_mps (mps);
+ else
+ inspect_mount ();
/* Free up data structures, no longer needed after this point. */
free_drives (drvs);
+ free_mps (mps);
- edit_files (argc - optind, &argv[optind]);
+ if (inspector)
+ edit_files (argc - optind, &argv[optind]);
+ else
+ edit_files_simple (argc - optind, &argv[optind]);
/* Cleanly unmount the disks after editing. */
if (guestfs_shutdown (g) == -1)
@@ -304,6 +323,15 @@ edit_files (int argc, char *argv[])
}
static void
+edit_files_simple (int argc, char *argv[])
+{
+ int i;
+
+ for (i = 0; i < argc; ++i)
+ edit (argv[i], NULL);
+}
+
+static void
edit (const char *filename, const char *root)
{
CLEANUP_FREE char *filename_to_free = NULL;
@@ -318,7 +346,7 @@ edit (const char *filename, const char *root)
CLEANUP_FREE char *backupname = NULL;
/* Windows? Special handling is required. */
- if (is_windows (g, root))
+ if (root != NULL && is_windows (g, root))
filename = filename_to_free = windows_path (g, root, filename);
/* Download the file to a temporary. */
diff --git a/edit/virt-edit.pod b/edit/virt-edit.pod
index 4c5ae71..ff72d71 100644
--- a/edit/virt-edit.pod
+++ b/edit/virt-edit.pod
@@ -164,6 +164,42 @@ security problem with malicious guests (CVE-2010-3851).
Read key or passphrase parameters from stdin. The default is
to try to read passphrases from the user by opening C</dev/tty>.
+=item B<-m dev[:mountpoint[:options[:fstype]]]>
+
+=item B<--mount dev[:mountpoint[:options[:fstype]]]>
+
+Mount the named partition or logical volume on the given mountpoint.
+
+If the mountpoint is omitted, it defaults to C</>.
+
+Specifying any mountpoint disables the inspection of the guest and
+the mount of its root and all of its mountpoints, so make sure
+to mount all the mountpoints needed to work with the filenames
+gives as arguments.
+
+If you don't know what filesystems a disk image contains, you can
+either run guestfish without this option, then list the partitions,
+filesystems and LVs available (see L</list-partitions>,
+L</list-filesystems> and L</lvs> commands), or you can use the
+L<virt-filesystems(1)> program.
+
+The third (and rarely used) part of the mount parameter is the list of
+mount options used to mount the underlying filesystem. If this is not
+given, then the mount options are either the empty string or C<ro>
+(the latter if the I<--ro> flag is used). By specifying the mount
+options, you override this default choice. Probably the only time you
+would use this is to enable ACLs and/or extended attributes if the
+filesystem can support them:
+
+ -m /dev/sda1:/:acl,user_xattr
+
+Using this flag is equivalent to using the C<mount-options> command.
+
+The fourth part of the parameter is the filesystem driver to use, such
+as C<ext3> or C<ntfs>. This is rarely needed, but can be useful if
+multiple drivers are valid for a filesystem (eg: C<ext2> and C<ext3>),
+or if libguestfs misidentifies a filesystem.
+
=item B<-v>
=item B<--verbose>
--
1.9.3