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