New API: remount: Allow rw flag to be adjusted on mounted filesystem.

This commit is contained in:
Richard W.M. Jones
2013-05-31 14:36:08 +01:00
parent 697b0f89fe
commit 2019d0e9c7
5 changed files with 63 additions and 3 deletions

View File

@@ -451,6 +451,41 @@ do_mount_loop (const char *file, const char *mountpoint)
return 0;
}
/* Takes optional arguments, consult optargs_bitmask. */
int
do_remount (const char *mountpoint, int rw)
{
CLEANUP_FREE char *mp = NULL, *err = NULL;
const char *options;
int r;
/* In future we'll allow other flags / parameters to be adjusted.
* For now we just have to check rw was passed, but in future it
* will genuinely be an optional argument.
*/
if (!(optargs_bitmask & GUESTFS_REMOUNT_RW_BITMASK)) {
reply_with_error ("parameter 'rw' must be specified");
return -1;
}
options = rw ? "remount,rw" : "remount,ro";
mp = sysroot_path (mountpoint);
if (!mp) {
reply_with_perror ("malloc");
return -1;
}
/* XXX Do we need to check the mountpoint exists? */
r = command (NULL, &err, str_mount, "-o", options, mp, NULL);
if (r == -1) {
reply_with_error ("%s: %s: %s", mountpoint, options, err);
return -1;
}
return 0;
}
/* Specialized calls mkmountpoint and rmmountpoint are really
* variations on mkdir and rmdir which do no checking of the
* is_root_mounted() flag.

View File

@@ -11185,6 +11185,28 @@ is useful when you don't want to preserve permissions, because
the target filesystem does not support it (primarily when
writing to DOS FAT filesystems)." };
{ defaults with
name = "remount";
style = RErr, [Pathname "mountpoint"], [OBool "rw"];
proc_nr = Some 402;
tests = [
InitScratchFS, Always, TestLastFail (
[["remount"; "/"; "false"];
["write"; "/remount1"; "data"]]);
InitScratchFS, Always, TestRun (
[["remount"; "/"; "false"];
["remount"; "/"; "true"];
["write"; "/remount2"; "data"]])
];
shortdesc = "remount a filesystem with different options";
longdesc = "\
This call allows you to change the C<rw> (readonly/read-write)
flag on an already mounted filesystem at C<mountpoint>,
converting a readonly filesystem to be read-write, or vice-versa.
Note that at the moment you must supply the \"optional\" C<rw>
parameter. In future we may allow other flags to be adjusted." };
]
(* Non-API meta-commands available only in guestfish.

View File

@@ -84,7 +84,8 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-xfs_repair.h \
include/guestfs-gobject/optargs-mke2fs.h \
include/guestfs-gobject/optargs-mktemp.h \
include/guestfs-gobject/optargs-syslinux.h
include/guestfs-gobject/optargs-syslinux.h \
include/guestfs-gobject/optargs-remount.h
guestfs_gobject_sources= \
src/session.c \
@@ -150,4 +151,5 @@ guestfs_gobject_sources= \
src/optargs-xfs_repair.c \
src/optargs-mke2fs.c \
src/optargs-mktemp.c \
src/optargs-syslinux.c
src/optargs-syslinux.c \
src/optargs-remount.c

View File

@@ -176,6 +176,7 @@ gobject/src/optargs-mount_local.c
gobject/src/optargs-ntfsclone_out.c
gobject/src/optargs-ntfsfix.c
gobject/src/optargs-ntfsresize.c
gobject/src/optargs-remount.c
gobject/src/optargs-rsync.c
gobject/src/optargs-rsync_in.c
gobject/src/optargs-rsync_out.c

View File

@@ -1 +1 @@
401
402