[Libguestfs] [PATCH 1/7] mount: Add mount_vfs_nochroot

Matthew Booth mbooth at redhat.com
Tue Feb 12 11:04:20 UTC 2013


This internal function allows mounting a mountable outside /sysroot.
---
 daemon/daemon.h |  6 ++++++
 daemon/mount.c  | 14 +++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/daemon/daemon.h b/daemon/daemon.h
index 67adec0..d343dfd 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -65,6 +65,12 @@ extern int xread (int sock, void *buf, size_t len)
 
 extern char *mountable_to_string (const mountable_t *mountable);
 
+/*-- in mount.c --*/
+
+extern int mount_vfs_nochroot (const char *options, const char *vfstype,
+                               const mountable_t *mountable,
+                               const char *mp, const char *user_mp);
+
 /* Growable strings buffer. */
 struct stringsbuf {
   char **argv;
diff --git a/daemon/mount.c b/daemon/mount.c
index 7e1199f..452b938 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -126,9 +126,7 @@ int
 do_mount_vfs (const char *options, const char *vfstype,
               const mountable_t *mountable, const char *mountpoint)
 {
-  int r;
   CLEANUP_FREE char *mp = NULL;
-  CLEANUP_FREE char *error = NULL;
   struct stat statbuf;
 
   ABS_PATH (mountpoint, , return -1);
@@ -149,6 +147,14 @@ do_mount_vfs (const char *options, const char *vfstype,
     return -1;
   }
 
+  return mount_vfs_nochroot (options, vfstype, mountable, mp, mountpoint);
+}
+
+int
+mount_vfs_nochroot (const char *options, const char *vfstype,
+                    const mountable_t *mountable,
+                    const char *mp, const char *user_mp)
+{
   CLEANUP_FREE char *options_plus = NULL;
   const char *device = mountable->device;
   if (mountable->type == MOUNTABLE_BTRFSVOL) {
@@ -169,6 +175,8 @@ do_mount_vfs (const char *options, const char *vfstype,
     }
   }
 
+  CLEANUP_FREE char *error = NULL;
+  int r;
   if (vfstype)
     r = command (NULL, &error,
                  str_mount, "-o", options_plus ? options_plus : options,
@@ -179,7 +187,7 @@ do_mount_vfs (const char *options, const char *vfstype,
                  device, mp, NULL);
   if (r == -1) {
     reply_with_error ("%s on %s (options: '%s'): %s",
-                      device, mountpoint, options, error);
+                      device, user_mp, options, error);
     return -1;
   }
 
-- 
1.8.1.2




More information about the Libguestfs mailing list