1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:47:46 +00:00

Kernel+Userland: Support remounting filesystems :^)

This makes it possible to change flags of a mount after the fact, with the
caveats outlined in the man page.
This commit is contained in:
Sergey Bugaev 2020-05-28 21:12:13 +03:00 committed by Andreas Kling
parent d395b93b15
commit 3847d00727
8 changed files with 58 additions and 0 deletions

View file

@ -91,6 +91,20 @@ KResult VFS::bind_mount(Custody& source, Custody& mount_point, int flags)
return KSuccess;
}
KResult VFS::remount(Custody& mount_point, int new_flags)
{
LOCKER(m_lock);
dbg() << "VFS: Remounting " << mount_point.absolute_path();
Mount* mount = find_mount_for_guest(mount_point.inode().identifier());
if (!mount)
return KResult(-ENODEV);
mount->set_flags(new_flags);
return KSuccess;
}
KResult VFS::unmount(InodeIdentifier guest_inode_id)
{
LOCKER(m_lock);

View file

@ -66,6 +66,7 @@ public:
String absolute_path() const;
int flags() const { return m_flags; }
void set_flags(int flags) { m_flags = flags; }
private:
InodeIdentifier m_host;
@ -83,6 +84,7 @@ public:
bool mount_root(FS&);
KResult mount(FS&, Custody& mount_point, int flags);
KResult bind_mount(Custody& source, Custody& mount_point, int flags);
KResult remount(Custody& mount_point, int new_flags);
KResult unmount(InodeIdentifier guest_inode_id);
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});

View file

@ -4103,6 +4103,11 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params)
auto& target_custody = custody_or_error.value();
if (params.flags & MS_REMOUNT) {
// We're not creating a new mount, we're updating an existing one!
return VFS::the().remount(target_custody, params.flags & ~MS_REMOUNT);
}
if (params.flags & MS_BIND) {
// We're doing a bind mount.
if (description.is_null())

View file

@ -53,6 +53,7 @@
#define MS_NOSUID (1 << 2)
#define MS_BIND (1 << 3)
#define MS_RDONLY (1 << 4)
#define MS_REMOUNT (1 << 5)
#define PERF_EVENT_MALLOC 1
#define PERF_EVENT_FREE 2