X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fmount.c;h=b0cb496e0d8fb6acf226054830115bb1701bbc4e;hb=0bfadd6908aa9d6a15990541d61bc3cf8600e54b;hp=071ca9627b671b5a089ab93b2508bf878972182c;hpb=2df2f2854ed2d1f9857ef3c5aaca29810cf3c506;p=libguestfs.git diff --git a/daemon/mount.c b/daemon/mount.c index 071ca96..b0cb496 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -39,8 +39,8 @@ int root_mounted = 0; */ int -do_mount_vfs (const char *options, const char *vfstype, - const char *device, const char *mountpoint) +do_mount_vfs (char *options, char *vfstype, + char *device, char *mountpoint) { int len, r, is_root; char *mp; @@ -71,6 +71,7 @@ do_mount_vfs (const char *options, const char *vfstype, else r = command (NULL, &error, "mount", "-o", options, device, mp, NULL); + free (mp); if (r == -1) { reply_with_error ("mount: %s on %s: %s", device, mountpoint, error); free (error); @@ -84,20 +85,20 @@ do_mount_vfs (const char *options, const char *vfstype, } int -do_mount (const char *device, const char *mountpoint) +do_mount (char *device, char *mountpoint) { return do_mount_vfs ("sync,noatime", NULL, device, mountpoint); } int -do_mount_ro (const char *device, const char *mountpoint) +do_mount_ro (char *device, char *mountpoint) { return do_mount_vfs ("ro", NULL, device, mountpoint); } int -do_mount_options (const char *options, const char *device, - const char *mountpoint) +do_mount_options (char *options, char *device, + char *mountpoint) { return do_mount_vfs (options, NULL, device, mountpoint); } @@ -106,7 +107,7 @@ do_mount_options (const char *options, const char *device, * is kept updated. */ int -do_umount (const char *pathordevice) +do_umount (char *pathordevice) { int len, freeit = 0, r; char *buf; @@ -277,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; +}