mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
cb10f70394
Instead of using a raw `KBuffer` and letting each implementation to populating the specific flags on its own, we change things so we only let each FileSystem implementation to validate the flag and its value but then store it in a HashMap which its key is the flag name and the value is a special new class called `FileSystemSpecificOption` which wraps around `AK::Variant<...>`. This approach has multiple advantages over the previous: - It allows runtime inspection of what the user has set on a `MountFile` description for a specific filesystem. - It ensures accidental overriding of filesystem specific option that was already set is not possible - It removes ugly casting of a `KBuffer` contents to a strongly-typed values. Instead, a strongly-typed `AK::Variant` is used which ensures we always get a value without doing any casting. Please note that we have removed support for ASCII string-oriented flags as there were no actual use cases, and supporting such type would make `FileSystemSpecificOption` more complicated unnecessarily for now.
44 lines
1.7 KiB
C++
44 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/FileSystemSpecificOption.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<FileSystemSpecificOptions>& filesystem_specific_options() { return m_filesystem_specific_options; }
|
|
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);
|
|
|
|
int const m_flags;
|
|
FileSystemInitializer const& m_file_system_initializer;
|
|
MutexProtected<FileSystemSpecificOptions> m_filesystem_specific_options;
|
|
};
|
|
|
|
}
|