2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "InodeIdentifier.h"
|
|
|
|
|
#include "InodeMetadata.h"
|
2018-10-14 17:57:41 -03:00
|
|
|
#include "UnixTypes.h"
|
2019-05-28 06:53:16 -03:00
|
|
|
#include <AK/AKString.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2019-05-28 06:53:16 -03:00
|
|
|
#include <AK/Function.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <AK/RetainPtr.h>
|
2019-05-28 06:53:16 -03:00
|
|
|
#include <AK/Retainable.h>
|
2019-02-08 13:40:48 -02:00
|
|
|
#include <AK/WeakPtr.h>
|
2019-05-28 06:53:16 -03:00
|
|
|
#include <AK/kstdio.h>
|
|
|
|
|
#include <Kernel/Devices/DiskDevice.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>
|
2018-10-10 06:53:07 -03:00
|
|
|
|
|
|
|
|
static const dword mepoch = 476763780;
|
|
|
|
|
|
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
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
class FS : public Retainable<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; }
|
2018-12-02 21:20:00 -02:00
|
|
|
static FS* from_fsid(dword);
|
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;
|
2018-12-02 21:20:00 -02:00
|
|
|
virtual InodeIdentifier root_inode() const = 0;
|
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; }
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
struct DirectoryEntry {
|
2019-01-31 14:31:23 -02:00
|
|
|
DirectoryEntry(const char* name, InodeIdentifier, byte file_type);
|
2019-04-23 08:00:53 -03:00
|
|
|
DirectoryEntry(const char* name, int name_length, InodeIdentifier, byte file_type);
|
2018-11-12 21:17:30 -02:00
|
|
|
char name[256];
|
2019-02-25 18:06:55 -03:00
|
|
|
int name_length { 0 };
|
2018-10-10 06:53:07 -03:00
|
|
|
InodeIdentifier inode;
|
2019-01-31 14:31:23 -02:00
|
|
|
byte file_type { 0 };
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|
2019-05-03 17: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 03:53:01 -02:00
|
|
|
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) = 0;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-12-19 18:18:28 -02:00
|
|
|
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const = 0;
|
2018-11-13 10:02:39 -02:00
|
|
|
|
2019-05-28 06:53:16 -03:00
|
|
|
virtual void flush_writes() {}
|
2019-04-25 17:05:53 -03:00
|
|
|
|
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
|
|
|
|
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 };
|
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
|
|
|
}
|
|
|
|
|
|
2018-12-02 21:20:00 -02:00
|
|
|
inline bool InodeIdentifier::is_root_inode() const
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-02 21:20:00 -02:00
|
|
|
return (*this) == fs()->root_inode();
|
2018-10-10 06:53:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct Traits<InodeIdentifier> {
|
2019-02-10 17:07:14 -02:00
|
|
|
static unsigned hash(const InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); }
|
2018-11-15 12:10:12 -02:00
|
|
|
static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fsid(), inode.index()); }
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|