1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

Kernel+LibC: Add support for mount flags

At the moment, the actual flags are ignored, but we correctly propagate them all
the way from the original mount() syscall to each custody that resides on the
mounted FS.
This commit is contained in:
Sergey Bugaev 2020-01-11 18:25:26 +03:00 committed by Andreas Kling
parent 1e6ab0ed22
commit 4566c2d811
10 changed files with 54 additions and 34 deletions

View file

@ -26,7 +26,7 @@ Custody* Custody::get_if_cached(Custody* parent, const StringView& name)
return nullptr;
}
NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const StringView& name, Inode& inode)
NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
{
if (RefPtr<Custody> cached_custody = get_if_cached(parent, name)) {
if (&cached_custody->inode() != &inode) {
@ -35,13 +35,14 @@ NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const StringView&
ASSERT(&cached_custody->inode() == &inode);
return *cached_custody;
}
return create(parent, name, inode);
return create(parent, name, inode, mount_flags);
}
Custody::Custody(Custody* parent, const StringView& name, Inode& inode)
Custody::Custody(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
: m_parent(parent)
, m_name(name)
, m_inode(inode)
, m_mount_flags(mount_flags)
{
LOCKER(all_custodies().lock());
all_custodies().resource().append(this);

View file

@ -1,10 +1,10 @@
#pragma once
#include <AK/String.h>
#include <AK/Badge.h>
#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
class Inode;
class VFS;
@ -15,10 +15,10 @@ class Custody : public RefCounted<Custody>
, public InlineLinkedListNode<Custody> {
public:
static Custody* get_if_cached(Custody* parent, const StringView& name);
static NonnullRefPtr<Custody> get_or_create(Custody* parent, const StringView& name, Inode&);
static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode)
static NonnullRefPtr<Custody> get_or_create(Custody* parent, const StringView& name, Inode&, int mount_flags);
static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
{
return adopt(*new Custody(parent, name, inode));
return adopt(*new Custody(parent, name, inode, mount_flags));
}
~Custody();
@ -33,6 +33,8 @@ public:
bool is_deleted() const { return m_deleted; }
bool is_mounted_on() const { return m_mounted_on; }
int mount_flags() const { return m_mount_flags; }
void did_delete(Badge<VFS>);
void did_mount_on(Badge<VFS>);
void did_rename(Badge<VFS>, const String& name);
@ -42,11 +44,12 @@ public:
Custody* m_prev { nullptr };
private:
Custody(Custody* parent, const StringView& name, Inode&);
Custody(Custody* parent, const StringView& name, Inode&, int mount_flags);
RefPtr<Custody> m_parent;
String m_name;
NonnullRefPtr<Inode> m_inode;
bool m_deleted { false };
bool m_mounted_on { false };
int m_mount_flags { 0 };
};

View file

@ -78,10 +78,10 @@ enum ProcFileType {
FI_PID_stack,
FI_PID_regs,
FI_PID_fds,
FI_PID_exe, // symlink
FI_PID_cwd, // symlink
FI_PID_exe, // symlink
FI_PID_cwd, // symlink
FI_PID_root, // symlink
FI_PID_fd, // directory
FI_PID_fd, // directory
__FI_PID_End,
FI_MaxStaticFileIndex,
@ -651,6 +651,7 @@ Optional<KBuffer> procfs$df(InodeIdentifier)
fs_object.add("mount_point", mount.absolute_path());
fs_object.add("block_size", fs.block_size());
fs_object.add("readonly", fs.is_readonly());
fs_object.add("mount_flags", mount.flags());
if (fs.is_disk_backed())
fs_object.add("device", static_cast<const DiskBackedFS&>(fs).device().absolute_path());

View file

@ -38,12 +38,12 @@ InodeIdentifier VFS::root_inode_id() const
return m_root_inode->identifier();
}
KResult VFS::mount(FS& file_system, Custody& mount_point)
KResult VFS::mount(FS& file_system, Custody& mount_point, int flags)
{
auto& inode = mount_point.inode();
dbg() << "VFS: Mounting " << file_system.class_name() << " at " << mount_point.absolute_path() << " (inode: " << inode.identifier() << ")";
dbg() << "VFS: Mounting " << file_system.class_name() << " at " << mount_point.absolute_path() << " (inode: " << inode.identifier() << ") with flags " << flags;
// FIXME: check that this is not already a mount point
Mount mount { file_system, &mount_point };
Mount mount { file_system, &mount_point, flags };
m_mounts.append(move(mount));
mount_point.did_mount_on({});
return KSuccess;
@ -79,7 +79,7 @@ bool VFS::mount_root(FS& file_system)
return false;
}
Mount mount { file_system, nullptr };
Mount mount { file_system, nullptr, 0 };
auto root_inode_id = mount.guest().fs()->root_inode();
auto root_inode = mount.guest().fs()->get_inode(root_inode_id);
@ -283,7 +283,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
if (!new_file)
return KResult(error);
auto new_custody = Custody::create(&parent_custody, p.basename(), *new_file);
auto new_custody = Custody::create(&parent_custody, p.basename(), *new_file, parent_custody.mount_flags());
return FileDescription::create(*new_custody);
}
@ -603,10 +603,11 @@ RefPtr<Inode> VFS::get_inode(InodeIdentifier inode_id)
return inode_id.fs()->get_inode(inode_id);
}
VFS::Mount::Mount(FS& guest_fs, Custody* host_custody)
VFS::Mount::Mount(FS& guest_fs, Custody* host_custody, int flags)
: m_guest(guest_fs.root_inode())
, m_guest_fs(guest_fs)
, m_host_custody(host_custody)
, m_flags(flags)
{
}
@ -639,7 +640,7 @@ void VFS::sync()
Custody& VFS::root_custody()
{
if (!m_root_custody)
m_root_custody = Custody::create(nullptr, "", *m_root_inode);
m_root_custody = Custody::create(nullptr, "", *m_root_inode, 0);
return *m_root_custody;
}
@ -674,6 +675,8 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
if (parent_custody)
*parent_custody = custody_chain.last();
int mount_flags = custody_chain.last().mount_flags();
for (int i = 0; i < parts.size(); ++i) {
bool inode_was_root_at_head_of_loop = current_root.inode().identifier() == crumb_id;
auto crumb_inode = get_inode(crumb_id);
@ -704,8 +707,10 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
}
return KResult(-ENOENT);
}
if (auto mount = find_mount_for_host(crumb_id))
if (auto mount = find_mount_for_host(crumb_id)) {
crumb_id = mount->guest();
mount_flags = mount->flags();
}
if (inode_was_root_at_head_of_loop && crumb_id.is_root_inode() && crumb_id != current_root.inode().identifier() && part == "..") {
auto mount = find_mount_for_guest(crumb_id);
auto dir_inode = get_inode(mount->host());
@ -715,7 +720,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
crumb_inode = get_inode(crumb_id);
ASSERT(crumb_inode);
custody_chain.append(Custody::create(&custody_chain.last(), part, *crumb_inode));
custody_chain.append(Custody::create(&custody_chain.last(), part, *crumb_inode, mount_flags));
metadata = crumb_inode->metadata();
if (metadata.is_directory()) {

View file

@ -1,12 +1,12 @@
#pragma once
#include <AK/String.h>
#include <AK/Badge.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/FileSystem/InodeMetadata.h>
@ -41,7 +41,7 @@ class VFS {
public:
class Mount {
public:
Mount(FS&, Custody* host_custody);
Mount(FS&, Custody* host_custody, int flags);
InodeIdentifier host() const;
InodeIdentifier guest() const { return m_guest; }
@ -50,11 +50,14 @@ public:
String absolute_path() const;
int flags() const { return m_flags; }
private:
InodeIdentifier m_host;
InodeIdentifier m_guest;
NonnullRefPtr<FS> m_guest_fs;
RefPtr<Custody> m_host_custody;
int m_flags;
};
static VFS& the();
@ -63,7 +66,7 @@ public:
~VFS();
bool mount_root(FS&);
KResult mount(FS&, Custody& mount_point);
KResult mount(FS&, Custody& mount_point, int flags);
KResult unmount(InodeIdentifier guest_inode_id);
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});