mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-12 01:47:00 +02:00
Immutable mounts are mounts that can't be changed in any aspect, if the VFSRootContext that hold them is used by a process. This includes two operations on a mount: 1. Trying to remove the mount from the mount table. 2. Trying to change the flags of the mount. The condition of a VFSRootContext being held by a process or not is crucial, as the intention is to allow removal of mounts that marked as immutable if the VFSRootContext is not being used anymore (for example, if the container that was created with such context stopped). Marking mounts as immutable on the first VFS root context essentially ensures they will never be modified because there will be a process using that context (which is the "main" VFS root context in the system runtime). It should be noted that setting a mount as immutable can be done in creation time of the mount by passing the MS_IMMUTABLE flag, or by doing a remount with MS_IMMUTABLE flag.
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/RefPtr.h>
|
|
#include <Kernel/FileSystem/Custody.h>
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
#include <Kernel/FileSystem/Inode.h>
|
|
#include <Kernel/Forward.h>
|
|
#include <Kernel/Library/NonnullLockRefPtr.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class Mount {
|
|
AK_MAKE_NONCOPYABLE(Mount);
|
|
AK_MAKE_NONMOVABLE(Mount);
|
|
friend class VFSRootContext;
|
|
|
|
public:
|
|
struct Details {
|
|
NonnullRefPtr<FileSystem> guest_fs;
|
|
NonnullRefPtr<Inode> guest;
|
|
};
|
|
|
|
// NOTE: This constructor is valid for VFSRootContext root inodes (as for the "/" directory)
|
|
Mount(NonnullRefPtr<Inode> source, int flags);
|
|
|
|
Mount(NonnullRefPtr<Inode> source, NonnullRefPtr<Custody> host_custody, int flags);
|
|
|
|
RefPtr<Inode const> host() const;
|
|
RefPtr<Inode> host();
|
|
|
|
RefPtr<Custody const> host_custody() const;
|
|
RefPtr<Custody> host_custody();
|
|
|
|
Inode const& guest() const { return *m_details.guest; }
|
|
Inode& guest() { return *m_details.guest; }
|
|
|
|
FileSystem const& guest_fs() const { return *m_details.guest_fs; }
|
|
FileSystem& guest_fs() { return *m_details.guest_fs; }
|
|
|
|
ErrorOr<NonnullOwnPtr<KString>> absolute_path() const;
|
|
|
|
int flags() const
|
|
{
|
|
return m_flags.with([](auto const& current_flags) -> int { return current_flags; });
|
|
}
|
|
void set_flags(int flags);
|
|
|
|
static void delete_mount_from_list(Mount&);
|
|
|
|
bool is_immutable() const { return m_immutable.was_set(); }
|
|
|
|
Details const& details() const { return m_details; }
|
|
|
|
private:
|
|
Details const m_details;
|
|
|
|
RefPtr<Custody> const m_host_custody;
|
|
SpinlockProtected<int, LockRank::None> m_flags { 0 };
|
|
|
|
SetOnce m_immutable;
|
|
|
|
IntrusiveListNode<Mount> m_vfs_list_node;
|
|
};
|
|
|
|
}
|