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-09-06 10:34:26 -03:00
|
|
|
#include <AK/String.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>
|
2019-06-21 13:58:45 -03:00
|
|
|
#include <AK/RefCounted.h>
|
2019-08-11 10:56:39 -03:00
|
|
|
#include <AK/RefPtr.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
|
|
|
|
2019-07-03 16:17:35 -03:00
|
|
|
static const 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;
|
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; }
|
|
|
|
|
|
2019-08-11 10:56:39 -03:00
|
|
|
virtual KResult prepare_to_unmount() const { return KSuccess; }
|
|
|
|
|
|
2019-09-10 16:04:27 -03:00
|
|
|
// FIXME: This data structure is very clunky and unpleasant. Replace it with something nicer.
|
2018-10-10 06:53:07 -03:00
|
|
|
struct DirectoryEntry {
|
2019-07-03 16:17:35 -03:00
|
|
|
DirectoryEntry(const char* name, InodeIdentifier, u8 file_type);
|
|
|
|
|
DirectoryEntry(const char* name, int name_length, InodeIdentifier, u8 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-07-03 16:17:35 -03:00
|
|
|
u8 file_type { 0 };
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) = 0;
|
|
|
|
|
virtual RefPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) = 0;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
virtual RefPtr<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
|
|
|
|
2019-08-11 05:09:36 -03:00
|
|
|
int block_size() const { return m_block_size; }
|
|
|
|
|
|
2019-08-17 06:17:36 -03:00
|
|
|
virtual bool is_disk_backed() const { return false; }
|
|
|
|
|
|
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-08-11 05:09:36 -03:00
|
|
|
void set_block_size(int);
|
|
|
|
|
|
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 };
|
2019-08-11 05:09:36 -03:00
|
|
|
int m_block_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
|
|
|
}
|
|
|
|
|
|
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<>
|
2019-06-29 14:14:03 -03:00
|
|
|
struct Traits<InodeIdentifier> : public GenericTraits<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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|