Implement the -m/--mount as available in guestfish to override the automatic introspection and specify which partitions to mount instead. --- cat/cat.c | 45 ++++++++++++++++++++++++++++++++++++++------- cat/virt-cat.pod | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/cat/cat.c b/cat/cat.c index e86ecf3..72bf81b 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -46,6 +46,7 @@ const char *libvirt_uri = NULL; int inspector = 1; static int do_cat (int argc, char *argv[]); +static int do_cat_simple (int argc, char *argv[]); static int is_windows (guestfs_h *g, const char *root); static char *windows_path (guestfs_h *g, const char *root, const char *filename); @@ -70,6 +71,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" @@ -89,7 +92,7 @@ main (int argc, char *argv[]) enum { HELP_OPTION = CHAR_MAX + 1 }; - static const char *options = "a:c:d:vVx"; + static const char *options = "a:c:d:m:vVx"; static const struct option long_options[] = { { "add", 1, 0, 'a' }, { "connect", 1, 0, 'c' }, @@ -99,12 +102,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 r; @@ -152,6 +159,11 @@ main (int argc, char *argv[]) OPTION_d; break; + case 'm': + OPTION_m; + inspector = 0; + break; + case 'v': OPTION_v; break; @@ -214,7 +226,7 @@ main (int argc, char *argv[]) * values. */ assert (read_only == 1); - assert (inspector == 1); + assert (inspector == 1 || mps != NULL); assert (live == 0); /* User must specify at least one filename on the command line. */ @@ -225,20 +237,25 @@ main (int argc, char *argv[]) if (drvs == NULL) usage (EXIT_FAILURE); - /* Add drives, inspect and mount. Note that inspector is always true, - * and there is no -m option. - */ + /* Add drives, inspect and mount. */ add_drives (drvs, 'a'); 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); - r = do_cat (argc - optind, &argv[optind]); + if (inspector) + r = do_cat (argc - optind, &argv[optind]); + else + r = do_cat_simple (argc - optind, &argv[optind]); guestfs_close (g); @@ -283,6 +300,20 @@ do_cat (int argc, char *argv[]) } static int +do_cat_simple (int argc, char *argv[]) +{ + unsigned errors = 0; + int i; + + for (i = 0; i < argc; ++i) { + if (guestfs_download (g, argv[i], "/dev/stdout") == -1) + errors++; + } + + return errors == 0 ? 0 : -1; +} + +static int is_windows (guestfs_h *g, const char *root) { char *type; diff --git a/cat/virt-cat.pod b/cat/virt-cat.pod index 9824a83..e06a961 100644 --- a/cat/virt-cat.pod +++ b/cat/virt-cat.pod @@ -126,6 +126,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
On Mon, Jun 23, 2014 at 01:00:11PM +0200, Pino Toscano wrote:
static int +do_cat_simple (int argc, char *argv[]) +{ + unsigned errors = 0; + int i; + + for (i = 0; i < argc; ++i) { + if (guestfs_download (g, argv[i], "/dev/stdout") == -1) + errors++; + } + + return errors == 0 ? 0 : -1; +}
The problem with this function is two-fold: - It disables Windows path support if using the -m option, which seems a bit arbitrary. - It duplicates parts of the original do_cat function. What's wrong with modifying do_cat so it checks the global inspector variable? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
On Monday 23 June 2014 12:29:07 Richard W.M. Jones wrote:
On Mon, Jun 23, 2014 at 01:00:11PM +0200, Pino Toscano wrote:
static int
+do_cat_simple (int argc, char *argv[]) +{ + unsigned errors = 0; + int i; + + for (i = 0; i < argc; ++i) { + if (guestfs_download (g, argv[i], "/dev/stdout") == -1) + errors++; + } + + return errors == 0 ? 0 : -1; +}
The problem with this function is two-fold:
- It disables Windows path support if using the -m option, which seems a bit arbitrary.
I'm not sure: if I tell to mount an arbitrary partition/mountpoint, how can libguestfs detect it's from a Windows guest? The main use cases I saw for this (and the other implementations for virt-ls and virt-edit) were - handle partitions/disks which are parts of a guest (say the separate /var in another disk) - handle data-only partitions (say the ones you put backups, etc) So even if their filesystem is NTFS or something for Windows, there should be no need for handling Windows paths (with the drive letter), no?
- It duplicates parts of the original do_cat function.
What's wrong with modifying do_cat so it checks the global inspector variable?
My first version of this patch was like that, then I thought it would have been better to have inspection and no-inspection separated to avoid cluttering a single function. I can put them together if wanted. -- Pino Toscano
On Mon, Jun 23, 2014 at 03:03:24PM +0200, Pino Toscano wrote:
On Monday 23 June 2014 12:29:07 Richard W.M. Jones wrote:
On Mon, Jun 23, 2014 at 01:00:11PM +0200, Pino Toscano wrote:
static int
+do_cat_simple (int argc, char *argv[]) +{ + unsigned errors = 0; + int i; + + for (i = 0; i < argc; ++i) { + if (guestfs_download (g, argv[i], "/dev/stdout") == -1) + errors++; + } + + return errors == 0 ? 0 : -1; +}
The problem with this function is two-fold:
- It disables Windows path support if using the -m option, which seems a bit arbitrary.
I'm not sure: if I tell to mount an arbitrary partition/mountpoint, how can libguestfs detect it's from a Windows guest?
I see, that makes sense.
The main use cases I saw for this (and the other implementations for virt-ls and virt-edit) were - handle partitions/disks which are parts of a guest (say the separate /var in another disk) - handle data-only partitions (say the ones you put backups, etc)
So even if their filesystem is NTFS or something for Windows, there should be no need for handling Windows paths (with the drive letter), no?
- It duplicates parts of the original do_cat function.
What's wrong with modifying do_cat so it checks the global inspector variable?
My first version of this patch was like that, then I thought it would have been better to have inspection and no-inspection separated to avoid cluttering a single function. I can put them together if wanted.
My spidey sense starts to tingle when I see duplicated code ... Whichever is going to be simpler, but I'd still prefer to avoid duplicated code as seen in this version of the patch. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Implement the -m/--mount as available in guestfish to override the automatic introspection and specify which partitions to mount instead. --- cat/cat.c | 47 ++++++++++++++++++++++++++++++++--------------- cat/virt-cat.pod | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/cat/cat.c b/cat/cat.c index e86ecf3..def8280 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -70,6 +70,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" @@ -89,7 +91,7 @@ main (int argc, char *argv[]) enum { HELP_OPTION = CHAR_MAX + 1 }; - static const char *options = "a:c:d:vVx"; + static const char *options = "a:c:d:m:vVx"; static const struct option long_options[] = { { "add", 1, 0, 'a' }, { "connect", 1, 0, 'c' }, @@ -99,12 +101,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 r; @@ -152,6 +158,11 @@ main (int argc, char *argv[]) OPTION_d; break; + case 'm': + OPTION_m; + inspector = 0; + break; + case 'v': OPTION_v; break; @@ -214,7 +225,7 @@ main (int argc, char *argv[]) * values. */ assert (read_only == 1); - assert (inspector == 1); + assert (inspector == 1 || mps != NULL); assert (live == 0); /* User must specify at least one filename on the command line. */ @@ -225,18 +236,20 @@ main (int argc, char *argv[]) if (drvs == NULL) usage (EXIT_FAILURE); - /* Add drives, inspect and mount. Note that inspector is always true, - * and there is no -m option. - */ + /* Add drives, inspect and mount. */ add_drives (drvs, 'a'); 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); r = do_cat (argc - optind, &argv[optind]); @@ -249,19 +262,23 @@ static int do_cat (int argc, char *argv[]) { unsigned errors = 0; - int windows, i; + int windows = 0; + int i; char *root; + CLEANUP_FREE_STRING_LIST char **roots = NULL; - /* Get root mountpoint. See: fish/inspect.c:inspect_mount */ - CLEANUP_FREE_STRING_LIST char **roots = guestfs_inspect_get_roots (g); + if (inspector) { + /* Get root mountpoint. See: fish/inspect.c:inspect_mount */ + roots = guestfs_inspect_get_roots (g); - assert (roots); - assert (roots[0] != NULL); - assert (roots[1] == NULL); - root = roots[0]; + assert (roots); + assert (roots[0] != NULL); + assert (roots[1] == NULL); + root = roots[0]; - /* Windows? Special handling is required. */ - windows = is_windows (g, root); + /* Windows? Special handling is required. */ + windows = is_windows (g, root); + } for (i = 0; i < argc; ++i) { CLEANUP_FREE char *filename_to_free = NULL; diff --git a/cat/virt-cat.pod b/cat/virt-cat.pod index 9824a83..e06a961 100644 --- a/cat/virt-cat.pod +++ b/cat/virt-cat.pod @@ -126,6 +126,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
On Mon, Jun 23, 2014 at 04:04:33PM +0200, Pino Toscano wrote:
Implement the -m/--mount as available in guestfish to override the automatic introspection and specify which partitions to mount instead.
This seems btter to me, so ACK this version. BTW also the guestfs-faq page needs to be updated with a note that libguestfs >= 1.28 will allow you to run virt-cat on a non-OS image. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
participants (2)
-
Pino Toscano -
Richard W.M. Jones