cat: add -m option

Implement the -m/--mount as available in guestfish to override the
automatic introspection and specify which partitions to mount instead.
This commit is contained in:
Pino Toscano
2014-06-23 15:54:00 +02:00
parent aad3c467fb
commit de5e7331af
2 changed files with 68 additions and 15 deletions

View File

@@ -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;

View File

@@ -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>