2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
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
|
|
|
|
|
|
2019-06-21 13:58:45 -03:00
|
|
|
#include <AK/RefCounted.h>
|
2019-08-11 10:56:39 -03:00
|
|
|
#include <AK/RefPtr.h>
|
2020-01-28 16:42:27 -03:00
|
|
|
#include <AK/String.h>
|
2020-08-18 07:41:27 -03:00
|
|
|
#include <AK/StringView.h>
|
2020-01-28 16:42:27 -03:00
|
|
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
2019-02-25 16:47:56 -03:00
|
|
|
#include <Kernel/KResult.h>
|
2019-05-28 06:53:16 -03:00
|
|
|
#include <Kernel/Lock.h>
|
2020-01-28 16:42:27 -03:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2020-09-12 00:11:07 -03:00
|
|
|
#include <Kernel/UserOrKernelBuffer.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-05-19 11:35:09 -03:00
|
|
|
static constexpr u32 mepoch = 476763780;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-12-19 18:18:28 -02:00
|
|
|
class Inode;
|
2019-06-07 04:36:51 -03:00
|
|
|
class FileDescription;
|
2019-02-14 12:55:19 -02:00
|
|
|
class LocalSocket;
|
2019-01-16 09:57:07 -02:00
|
|
|
class VMObject;
|
2018-10-26 19:14:24 -03:00
|
|
|
|
2019-06-21 10:29:31 -03:00
|
|
|
class FS : public RefCounted<FS> {
|
2019-02-28 17:51:59 -03:00
|
|
|
friend class Inode;
|
2019-05-28 06:53:16 -03:00
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
public:
|
2018-11-15 14:13:10 -02:00
|
|
|
virtual ~FS();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-01-23 02:38:54 -02:00
|
|
|
unsigned fsid() const { return m_fsid; }
|
2019-07-03 16:17:35 -03:00
|
|
|
static FS* from_fsid(u32);
|
2018-12-19 21:39:29 -02:00
|
|
|
static void sync();
|
2019-06-16 06:49:39 -03:00
|
|
|
static void lock_all();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
|
|
|
|
virtual bool initialize() = 0;
|
2018-11-15 12:36:35 -02:00
|
|
|
virtual const char* class_name() const = 0;
|
2020-06-24 17:35:56 -03:00
|
|
|
virtual NonnullRefPtr<Inode> root_inode() const = 0;
|
2019-12-15 15:33:39 -03:00
|
|
|
virtual bool supports_watchers() const { return false; }
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-12-19 18:56:45 -02:00
|
|
|
bool is_readonly() const { return m_readonly; }
|
|
|
|
|
|
2019-02-21 10:48:00 -03:00
|
|
|
virtual unsigned total_block_count() const { return 0; }
|
|
|
|
|
virtual unsigned free_block_count() const { return 0; }
|
|
|
|
|
virtual unsigned total_inode_count() const { return 0; }
|
|
|
|
|
virtual unsigned free_inode_count() const { return 0; }
|
|
|
|
|
|
2019-08-11 10:56:39 -03:00
|
|
|
virtual KResult prepare_to_unmount() const { return KSuccess; }
|
|
|
|
|
|
2020-08-18 07:41:27 -03:00
|
|
|
struct DirectoryEntryView {
|
|
|
|
|
DirectoryEntryView(const StringView& name, InodeIdentifier, u8 file_type);
|
|
|
|
|
|
|
|
|
|
StringView name;
|
|
|
|
|
InodeIdentifier inode;
|
|
|
|
|
u8 file_type { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-18 04:49:51 -03:00
|
|
|
virtual void flush_writes() { }
|
2019-04-25 17:05:53 -03:00
|
|
|
|
2020-05-18 15:46:47 -03:00
|
|
|
size_t block_size() const { return m_block_size; }
|
2021-05-18 16:04:52 -03:00
|
|
|
size_t fragment_size() const { return m_fragment_size; }
|
2019-08-11 05:09:36 -03:00
|
|
|
|
2020-04-06 05:54:21 -03:00
|
|
|
virtual bool is_file_backed() const { return false; }
|
2019-08-17 06:17:36 -03:00
|
|
|
|
2020-08-29 15:25:01 -03:00
|
|
|
// Converts file types that are used internally by the filesystem to DT_* types
|
|
|
|
|
virtual u8 internal_file_type_to_directory_entry_type(const DirectoryEntryView& entry) const { return entry.file_type; }
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
protected:
|
2018-11-15 14:13:10 -02:00
|
|
|
FS();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-05-18 15:46:47 -03:00
|
|
|
void set_block_size(size_t);
|
2021-05-18 16:04:52 -03:00
|
|
|
void set_fragment_size(size_t);
|
2019-08-11 05:09:36 -03:00
|
|
|
|
2019-05-01 22:28:20 -03:00
|
|
|
mutable Lock m_lock { "FS" };
|
2019-02-28 17:51:59 -03:00
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
private:
|
2019-01-23 02:38:54 -02:00
|
|
|
unsigned m_fsid { 0 };
|
2020-05-18 15:46:47 -03:00
|
|
|
size_t m_block_size { 0 };
|
2021-05-18 16:04:52 -03:00
|
|
|
size_t m_fragment_size { 0 };
|
2018-12-19 18:56:45 -02:00
|
|
|
bool m_readonly { false };
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|
2018-12-02 21:20:00 -02:00
|
|
|
inline FS* InodeIdentifier::fs()
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-02 21:20:00 -02:00
|
|
|
return FS::from_fsid(m_fsid);
|
2018-10-10 06:53:07 -03:00
|
|
|
}
|
|
|
|
|
|
2018-12-02 21:20:00 -02:00
|
|
|
inline const FS* InodeIdentifier::fs() const
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-02 21:20:00 -02:00
|
|
|
return FS::from_fsid(m_fsid);
|
2018-10-10 06:53:07 -03:00
|
|
|
}
|
|
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
}
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
|
|
template<>
|
2020-02-15 21:27:42 -03:00
|
|
|
struct Traits<Kernel::InodeIdentifier> : public GenericTraits<Kernel::InodeIdentifier> {
|
2021-02-12 05:18:47 -03:00
|
|
|
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index().value()); }
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|