2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2021-07-11 01:33:27 +03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-16 03:50:16 +03:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
2021-09-07 14:39:11 +03:00
|
|
|
#include <Kernel/FileSystem/OpenFileDescription.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-07-11 01:33:27 +03:00
|
|
|
class FileBackedFileSystem : public FileSystem {
|
2022-08-20 00:03:24 +03:00
|
|
|
friend class VirtualFileSystem;
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
public:
|
2021-07-11 01:33:27 +03:00
|
|
|
virtual ~FileBackedFileSystem() override;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2020-04-06 11:54:21 +03:00
|
|
|
File& file() { return m_file_description->file(); }
|
2021-09-07 14:39:11 +03:00
|
|
|
OpenFileDescription& file_description() { return *m_file_description; }
|
2022-04-01 20:58:27 +03:00
|
|
|
File const& file() const { return m_file_description->file(); }
|
2021-09-07 14:39:11 +03:00
|
|
|
OpenFileDescription& file_description() const { return *m_file_description; }
|
2020-04-06 11:54:21 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
protected:
|
2021-09-07 14:39:11 +03:00
|
|
|
explicit FileBackedFileSystem(OpenFileDescription&);
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2022-08-20 00: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.
|
2023-07-02 15:23:53 +03:00
|
|
|
virtual ErrorOr<void> prepare_to_clear_last_mount(Inode& mount_guest_inode) override = 0;
|
2022-08-20 00:03:24 +03:00
|
|
|
|
|
|
|
virtual ErrorOr<void> initialize_while_locked() = 0;
|
|
|
|
virtual bool is_initialized_while_locked() = 0;
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
private:
|
2022-08-20 00:03:24 +03:00
|
|
|
virtual ErrorOr<void> initialize() override final;
|
2020-05-18 21:55:08 +03:00
|
|
|
virtual bool is_file_backed() const override { return true; }
|
|
|
|
|
2022-08-20 00:03:24 +03:00
|
|
|
IntrusiveListNode<FileBackedFileSystem> m_file_backed_file_system_node;
|
2023-04-07 14:49:49 +03:00
|
|
|
NonnullRefPtr<OpenFileDescription> const m_file_description;
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
}
|