ladybird/Kernel/FileSystem/MountFile.h
Liav A 23a7ccf607 Kernel+LibCore+LibC: Split the mount syscall into multiple syscalls
This is a preparation before we can create a usable mechanism to use
filesystem-specific mount flags.
To keep some compatibility with userland code, LibC and LibCore mount
functions are kept being usable, but now instead of doing an "atomic"
syscall, they do multiple syscalls to perform the complete procedure of
mounting a filesystem.

The FileBackedFileSystem IntrusiveList in the VFS code is now changed to
be protected by a Mutex, because when we mount a new filesystem, we need
to check if a filesystem is already created for a given source_fd so we
do a scan for that OpenFileDescription in that list. If we fail to find
an already-created filesystem we create a new one and register it in the
list if we successfully mounted it. We use a Mutex because we might need
to initiate disk access during the filesystem creation, which will take
other mutexes in other parts of the kernel, therefore making it not
possible to take a spinlock while doing this.
2023-07-02 01:04:51 +02:00

43 lines
1.7 KiB
C++

/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/FileSystem/File.h>
#include <Kernel/FileSystem/Initializer.h>
#include <Kernel/Locking/MutexProtected.h>
namespace Kernel {
class MountFile final : public File {
public:
static ErrorOr<NonnullLockRefPtr<MountFile>> create(FileSystemInitializer const&, int flags);
virtual ~MountFile() override;
virtual bool can_read(OpenFileDescription const&, u64) const override { return true; }
virtual bool can_write(OpenFileDescription const&, u64) const override { return true; }
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override { return ENOTSUP; }
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
virtual StringView class_name() const override { return "MountFile"sv; }
int mount_flags() const { return m_flags; }
MutexProtected<OwnPtr<KBuffer>>& mount_file_system_specific_data() { return m_mount_specific_data; }
FileSystemInitializer const& file_system_initializer() const { return m_file_system_initializer; }
private:
virtual bool is_mount_file() const override { return true; }
MountFile(FileSystemInitializer const&, int flags, NonnullOwnPtr<KBuffer>);
int const m_flags;
FileSystemInitializer const& m_file_system_initializer;
MutexProtected<OwnPtr<KBuffer>> m_mount_specific_data;
};
}