diff options
author | Charles Duffy <cduffy@messageone.com> | 2009-06-02 11:30:26 -0500 |
---|---|---|
committer | Richard Jones <rjones@trick.home.annexia.org> | 2009-06-02 19:16:34 +0100 |
commit | d1da506d35e3c14b0bbe5397d73994fe082bc831 (patch) | |
tree | 7cf171da47df4b89f5c18d45751da5a57e4f0ec2 /fish/fish.c | |
parent | 76711b7e918f6dc504d3b5e11c6cac5ee11cc34f (diff) | |
download | libguestfs-d1da506d35e3c14b0bbe5397d73994fe082bc831.tar.gz libguestfs-d1da506d35e3c14b0bbe5397d73994fe082bc831.tar.xz libguestfs-d1da506d35e3c14b0bbe5397d73994fe082bc831.zip |
use add_drive_ro for --mount parameters from guestfish when called with --ro
To prevent writes (such as ext3 journal replay) from occuring even when --ro is
passed, guestfish should use add_drive_ro() for any drives specified on the
command line with --add if --ro is also passed.
As we need to look through the entire command line for --ro before adding any
drives, we move the add process out of the argument-parsing loop and into its
own function, patterned off mount_mps().
Signed-off-by: Charles Duffy <charles_duffy@dell.com>
Diffstat (limited to 'fish/fish.c')
-rw-r--r-- | fish/fish.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/fish/fish.c b/fish/fish.c index 18d3880d..96c1a816 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -45,6 +45,12 @@ struct mp { char *mountpoint; }; +struct drv { + struct drv *next; + char *filename; +}; + +static void add_drives (struct drv *drv); static void mount_mps (struct mp *mp); static void interactive (void); static void shell_script (void); @@ -119,6 +125,8 @@ main (int argc, char *argv[]) { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } }; + struct drv *drvs = NULL; + struct drv *drv; struct mp *mps = NULL; struct mp *mp; char *p; @@ -160,8 +168,14 @@ main (int argc, char *argv[]) perror (optarg); exit (1); } - if (guestfs_add_drive (g, optarg) == -1) - exit (1); + drv = malloc (sizeof (struct drv)); + if (!drv) { + perror ("malloc"); + exit (1); + } + drv->filename = optarg; + drv->next = drvs; + drvs = drv; break; case 'h': @@ -218,6 +232,9 @@ main (int argc, char *argv[]) } } + /* If we've got drives to add, add them now. */ + add_drives (drvs); + /* If we've got mountpoints, we must launch the guest and mount them. */ if (mps != NULL) { if (launch (g) == -1) exit (1); @@ -277,6 +294,22 @@ mount_mps (struct mp *mp) } static void +add_drives (struct drv *drv) +{ + int r; + + if (drv) { + add_drives (drv->next); + if (!read_only) + r = guestfs_add_drive (g, drv->filename); + else + r = guestfs_add_drive_ro (g, drv->filename); + if (r == -1) + exit (1); + } +} + +static void interactive (void) { script (1); |