diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-06-29 16:03:54 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-06-29 16:03:54 +0100 |
commit | a548d51b703f5385797594a37287f4532af289a2 (patch) | |
tree | cc8a77bda99f9a3f8ec6160c6d3592958e72884e | |
parent | 25ebdcd50685c4364fc852feca201f8335d47b52 (diff) | |
download | libguestfs-a548d51b703f5385797594a37287f4532af289a2.tar.gz libguestfs-a548d51b703f5385797594a37287f4532af289a2.tar.xz libguestfs-a548d51b703f5385797594a37287f4532af289a2.zip |
Add mount-loop command (RHBZ#508668).
Loop device mounts don't work for the generic 'mount' commands
because the first parameter should be a file not a device.
We want to separate out files parameters from device parameters
in the long term, so this adds a new mount-loop command for this
purpose.
-rw-r--r-- | daemon/mount.c | 44 | ||||
-rwxr-xr-x | src/generator.ml | 8 |
2 files changed, 52 insertions, 0 deletions
diff --git a/daemon/mount.c b/daemon/mount.c index 67b548ef..b0cb496e 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -278,3 +278,47 @@ do_umount_all (void) return 0; } + +/* Mount using the loopback device. You can't use the generic + * do_mount call for this because the first parameter isn't a + * device. + */ +int +do_mount_loop (char *file, char *mountpoint) +{ + int len, r; + char *buf, *mp; + char *error; + + NEED_ROOT (-1); + ABS_PATH (file, -1); + + /* We have to prefix /sysroot on both the filename and the mountpoint. */ + len = strlen (mountpoint) + 9; + mp = malloc (len); + if (!mp) { + reply_with_perror ("malloc"); + return -1; + } + snprintf (mp, len, "/sysroot%s", mountpoint); + + len = strlen (file) + 9; + buf = malloc (len); + if (!file) { + reply_with_perror ("malloc"); + free (mp); + return -1; + } + snprintf (buf, len, "/sysroot%s", file); + + r = command (NULL, &error, "mount", "-o", "loop", buf, mp, NULL); + free (mp); + free (buf); + if (r == -1) { + reply_with_error ("mount: %s on %s: %s", file, mountpoint, error); + free (error); + return -1; + } + + return 0; +} diff --git a/src/generator.ml b/src/generator.ml index 2dfc8cb3..27a75868 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2615,6 +2615,14 @@ Old Linux kernels (2.4 and earlier) used a compressed ext2 filesystem as initrd. We I<only> support the newer initramfs format (compressed cpio files)."); + ("mount_loop", (RErr, [String "file"; String "mountpoint"]), 129, [], + [], + "mount a file using the loop device", + "\ +This command lets you mount C<file> (a filesystem image +in a file) on a mount point. It is entirely equivalent to +the command C<mount -o loop file mountpoint>."); + ] let all_functions = non_daemon_functions @ daemon_functions |