2018-10-10 12:53:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "InodeIdentifier.h"
|
|
|
|
#include "InodeMetadata.h"
|
2018-10-14 23:57:41 +03:00
|
|
|
#include "UnixTypes.h"
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <AK/AKString.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <AK/Function.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/RetainPtr.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <AK/Retainable.h>
|
2019-02-08 18:40:48 +03:00
|
|
|
#include <AK/WeakPtr.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <AK/kstdio.h>
|
|
|
|
#include <Kernel/Devices/DiskDevice.h>
|
2019-02-25 22:47:56 +03:00
|
|
|
#include <Kernel/KResult.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <Kernel/Lock.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
static const dword mepoch = 476763780;
|
|
|
|
|
2018-12-19 23:18:28 +03:00
|
|
|
class Inode;
|
2019-06-07 10:36:51 +03:00
|
|
|
class FileDescription;
|
2019-02-14 17:55:19 +03:00
|
|
|
class LocalSocket;
|
2019-01-16 14:57:07 +03:00
|
|
|
class VMObject;
|
2018-10-27 01:14:24 +03:00
|
|
|
|
2019-06-21 16:29:31 +03:00
|
|
|
class FS : public RefCounted<FS> {
|
2019-02-28 23:51:59 +03:00
|
|
|
friend class Inode;
|
2019-05-28 12:53:16 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
public:
|
2018-11-15 19:13:10 +03:00
|
|
|
virtual ~FS();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2019-01-23 07:38:54 +03:00
|
|
|
unsigned fsid() const { return m_fsid; }
|
2018-12-03 02:20:00 +03:00
|
|
|
static FS* from_fsid(dword);
|
2018-12-20 02:39:29 +03:00
|
|
|
static void sync();
|
2019-06-16 12:49:39 +03:00
|
|
|
static void lock_all();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
virtual bool initialize() = 0;
|
2018-11-15 17:36:35 +03:00
|
|
|
virtual const char* class_name() const = 0;
|
2018-12-03 02:20:00 +03:00
|
|
|
virtual InodeIdentifier root_inode() const = 0;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2018-12-19 23:56:45 +03:00
|
|
|
bool is_readonly() const { return m_readonly; }
|
|
|
|
|
2019-02-21 16: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; }
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
struct DirectoryEntry {
|
2019-01-31 19:31:23 +03:00
|
|
|
DirectoryEntry(const char* name, InodeIdentifier, byte file_type);
|
2019-04-23 14:00:53 +03:00
|
|
|
DirectoryEntry(const char* name, int name_length, InodeIdentifier, byte file_type);
|
2018-11-13 02:17:30 +03:00
|
|
|
char name[256];
|
2019-02-26 00:06:55 +03:00
|
|
|
int name_length { 0 };
|
2018-10-10 12:53:07 +03:00
|
|
|
InodeIdentifier inode;
|
2019-01-31 19:31:23 +03:00
|
|
|
byte file_type { 0 };
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
2019-05-03 23:59:58 +03:00
|
|
|
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) = 0;
|
2019-01-23 08:53:01 +03:00
|
|
|
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) = 0;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2018-12-19 23:18:28 +03:00
|
|
|
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const = 0;
|
2018-11-13 15:02:39 +03:00
|
|
|
|
2019-05-28 12:53:16 +03:00
|
|
|
virtual void flush_writes() {}
|
2019-04-25 23:05:53 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
protected:
|
2018-11-15 19:13:10 +03:00
|
|
|
FS();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2019-05-02 04:28:20 +03:00
|
|
|
mutable Lock m_lock { "FS" };
|
2019-02-28 23:51:59 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
private:
|
2019-01-23 07:38:54 +03:00
|
|
|
unsigned m_fsid { 0 };
|
2018-12-19 23:56:45 +03:00
|
|
|
bool m_readonly { false };
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
2018-12-03 02:20:00 +03:00
|
|
|
inline FS* InodeIdentifier::fs()
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2018-12-03 02:20:00 +03:00
|
|
|
return FS::from_fsid(m_fsid);
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-03 02:20:00 +03:00
|
|
|
inline const FS* InodeIdentifier::fs() const
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2018-12-03 02:20:00 +03:00
|
|
|
return FS::from_fsid(m_fsid);
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-03 02:20:00 +03:00
|
|
|
inline bool InodeIdentifier::is_root_inode() const
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2018-12-03 02:20:00 +03:00
|
|
|
return (*this) == fs()->root_inode();
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Traits<InodeIdentifier> {
|
2019-02-10 22:07:14 +03:00
|
|
|
static unsigned hash(const InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); }
|
2018-11-15 17:10:12 +03:00
|
|
|
static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fsid(), inode.index()); }
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|