
This device is a block device that allows a user to effectively treat an Inode as a block device. The static construction method is given an OpenFileDescription reference but validates that: - The description has a valid custody (so it's not some arbitrary file). Failing this requirement will yield EINVAL. - The description custody points to an Inode which is a regular file, as we only support (seekable) regular files. Failing this requirement will yield ENOTSUP. LoopDevice can be used to mount a regular file on the filesystem like other supported types of (physical) block devices.
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
|
* Copyright (c) 2022-2024, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
#include <Kernel/FileSystem/Inode.h>
|
|
#include <Kernel/Forward.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class RAMFS final : public FileSystem {
|
|
friend class RAMFSInode;
|
|
|
|
public:
|
|
virtual ~RAMFS() override;
|
|
static ErrorOr<NonnullRefPtr<FileSystem>> try_create(ReadonlyBytes);
|
|
virtual ErrorOr<void> initialize() override;
|
|
|
|
virtual StringView class_name() const override { return "RAMFS"sv; }
|
|
|
|
virtual bool supports_watchers() const override { return true; }
|
|
virtual bool supports_backing_loop_devices() const override { return true; }
|
|
|
|
virtual Inode& root_inode() override;
|
|
|
|
virtual u8 internal_file_type_to_directory_entry_type(DirectoryEntryView const& entry) const override;
|
|
|
|
private:
|
|
RAMFS();
|
|
|
|
RefPtr<RAMFSInode> m_root_inode;
|
|
|
|
// NOTE: We start by assigning InodeIndex of 2, because 0 is invalid and 1
|
|
// is reserved for the root directory inode.
|
|
unsigned m_next_inode_index { 2 };
|
|
unsigned next_inode_index();
|
|
};
|
|
|
|
}
|