summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-22 21:02:15 +0100
committerRichard Jones <rjones@redhat.com>2009-04-22 21:02:15 +0100
commitd7ffe439e8ec5304a1a2d1eb591d348c4ab84f38 (patch)
tree9f285f3bd411265f7b1cbb975004efe254114ab9
parent35dc2f5706a957fe9a17d4bc29ad433c541d2fa0 (diff)
downloadlibguestfs-d7ffe439e8ec5304a1a2d1eb591d348c4ab84f38.tar.gz
libguestfs-d7ffe439e8ec5304a1a2d1eb591d348c4ab84f38.tar.xz
libguestfs-d7ffe439e8ec5304a1a2d1eb591d348c4ab84f38.zip
Add mount_ro, mount_options, mount_vfs. Fix small bug in OCaml generator.
-rw-r--r--daemon/mount.c33
-rwxr-xr-xsrc/generator.ml33
2 files changed, 62 insertions, 4 deletions
diff --git a/daemon/mount.c b/daemon/mount.c
index fd9c8e43..3abdabdd 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -30,7 +30,8 @@
int root_mounted = 0;
/* The "simple mount" call offers no complex options, you can just
- * mount a device on a mountpoint.
+ * mount a device on a mountpoint. The variations like mount_ro,
+ * mount_options and mount_vfs let you set progressively more things.
*
* It's tempting to try a direct mount(2) syscall, but that doesn't
* do any autodetection, so we are better off calling out to
@@ -38,7 +39,8 @@ int root_mounted = 0;
*/
int
-do_mount (const char *device, const char *mountpoint)
+do_mount_vfs (const char *options, const char *vfstype,
+ const char *device, const char *mountpoint)
{
int len, r, is_root;
char *mp;
@@ -61,8 +63,12 @@ do_mount (const char *device, const char *mountpoint)
snprintf (mp, len, "/sysroot%s", mountpoint);
- r = command (NULL, &error,
- "mount", "-o", "sync,noatime", device, mp, NULL);
+ if (vfstype)
+ r = command (NULL, &error,
+ "mount", "-o", options, "-t", vfstype, device, mp, NULL);
+ else
+ r = command (NULL, &error,
+ "mount", "-o", options, device, mp, NULL);
if (r == -1) {
reply_with_error ("mount: %s on %s: %s", device, mountpoint, error);
free (error);
@@ -75,6 +81,25 @@ do_mount (const char *device, const char *mountpoint)
return 0;
}
+int
+do_mount (const char *device, const char *mountpoint)
+{
+ return do_mount_vfs ("sync,noatime", NULL, device, mountpoint);
+}
+
+int
+do_mount_ro (const char *device, const char *mountpoint)
+{
+ return do_mount_vfs ("ro", NULL, device, mountpoint);
+}
+
+int
+do_mount_options (const char *options, const char *device,
+ const char *mountpoint)
+{
+ return do_mount_vfs (options, NULL, device, mountpoint);
+}
+
/* Again, use the external /bin/umount program, so that /etc/mtab
* is kept updated.
*/
diff --git a/src/generator.ml b/src/generator.ml
index 23738bd9..7e7976c8 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -1435,6 +1435,37 @@ it to local file C<tarball>.
To download an uncompressed tarball, use C<guestfs_tar_out>.");
+ ("mount_ro", (RErr, [String "device"; String "mountpoint"]), 73, [],
+ [InitBasicFS, TestLastFail (
+ [["umount"; "/"];
+ ["mount_ro"; "/dev/sda1"; "/"];
+ ["touch"; "/new"]]);
+ InitBasicFS, TestOutput (
+ [["write_file"; "/new"; "data"; "0"];
+ ["umount"; "/"];
+ ["mount_ro"; "/dev/sda1"; "/"];
+ ["cat"; "/new"]], "data")],
+ "mount a guest disk, read-only",
+ "\
+This is the same as the C<guestfs_mount> command, but it
+mounts the filesystem with the read-only (I<-o ro>) flag.");
+
+ ("mount_options", (RErr, [String "options"; String "device"; String "mountpoint"]), 74, [],
+ [],
+ "mount a guest disk with mount options",
+ "\
+This is the same as the C<guestfs_mount> command, but it
+allows you to set the mount options as for the
+L<mount(8)> I<-o> flag.");
+
+ ("mount_vfs", (RErr, [String "options"; String "vfstype"; String "device"; String "mountpoint"]), 75, [],
+ [],
+ "mount a guest disk with mount options and vfstype",
+ "\
+This is the same as the C<guestfs_mount> command, but it
+allows you to set both the mount options and the vfstype
+as for the L<mount(8)> I<-o> and I<-t> flags.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
@@ -4106,6 +4137,8 @@ copy_table (char * const * argv)
pr "{\n";
(match params with
+ | [p1; p2; p3; p4; p5] ->
+ pr " CAMLparam5 (%s);\n" (String.concat ", " params)
| p1 :: p2 :: p3 :: p4 :: p5 :: rest ->
pr " CAMLparam5 (%s);\n" (String.concat ", " [p1; p2; p3; p4; p5]);
pr " CAMLxparam%d (%s);\n"