2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-07-10 19:33:27 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-15 21:50:16 -03:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
2021-09-07 08:39:11 -03:00
|
|
|
#include <Kernel/FileSystem/OpenFileDescription.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-07-10 19:33:27 -03:00
|
|
|
class FileBackedFileSystem : public FileSystem {
|
2022-08-19 18:03:24 -03:00
|
|
|
friend class VirtualFileSystem;
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
public:
|
2021-07-10 19:33:27 -03:00
|
|
|
virtual ~FileBackedFileSystem() override;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-04-06 05:54:21 -03:00
|
|
|
File& file() { return m_file_description->file(); }
|
2021-09-07 08:39:11 -03:00
|
|
|
OpenFileDescription& file_description() { return *m_file_description; }
|
2022-04-01 14:58:27 -03:00
|
|
|
File const& file() const { return m_file_description->file(); }
|
2021-09-07 08:39:11 -03:00
|
|
|
OpenFileDescription& file_description() const { return *m_file_description; }
|
2020-04-06 05:54:21 -03:00
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
protected:
|
2021-09-07 08:39:11 -03:00
|
|
|
explicit FileBackedFileSystem(OpenFileDescription&);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2022-08-19 18:03:24 -03:00
|
|
|
// Note: We require all FileBackedFileSystem to implement something that actually
|
|
|
|
|
// takes into account the fact that we will clean the last mount of the filesystem,
|
|
|
|
|
// therefore, removing the file system with it from the Kernel memory.
|
|
|
|
|
virtual ErrorOr<void> prepare_to_clear_last_mount() override = 0;
|
|
|
|
|
|
|
|
|
|
virtual ErrorOr<void> initialize_while_locked() = 0;
|
|
|
|
|
virtual bool is_initialized_while_locked() = 0;
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
private:
|
2022-08-19 18:03:24 -03:00
|
|
|
virtual ErrorOr<void> initialize() override final;
|
2020-05-18 15:55:08 -03:00
|
|
|
virtual bool is_file_backed() const override { return true; }
|
|
|
|
|
|
2022-08-19 18:03:24 -03:00
|
|
|
IntrusiveListNode<FileBackedFileSystem> m_file_backed_file_system_node;
|
2023-04-07 08:49:49 -03:00
|
|
|
NonnullRefPtr<OpenFileDescription> const m_file_description;
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
2020-02-15 21:27:42 -03:00
|
|
|
}
|