2018-10-10 12:53:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-16 12:21:49 +03:00
|
|
|
#include "DiskDevice.h"
|
2018-10-10 12:53:07 +03:00
|
|
|
#include "InodeIdentifier.h"
|
|
|
|
#include "InodeMetadata.h"
|
2018-10-14 22:19:27 +03:00
|
|
|
#include "Limits.h"
|
2018-10-14 23:57:41 +03:00
|
|
|
#include "UnixTypes.h"
|
2018-10-10 12:53:07 +03:00
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/Retainable.h>
|
|
|
|
#include <AK/RetainPtr.h>
|
|
|
|
#include <AK/String.h>
|
2018-10-17 11:55:43 +03:00
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <AK/kstdio.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
static const dword mepoch = 476763780;
|
|
|
|
|
2018-10-27 01:14:24 +03:00
|
|
|
class FileHandle;
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
class FileSystem : public Retainable<FileSystem> {
|
|
|
|
public:
|
2018-10-19 12:20:49 +03:00
|
|
|
static void initializeGlobals();
|
2018-10-10 12:53:07 +03:00
|
|
|
virtual ~FileSystem();
|
|
|
|
|
|
|
|
dword id() const { return m_id; }
|
|
|
|
static FileSystem* fromID(dword);
|
|
|
|
|
|
|
|
virtual bool initialize() = 0;
|
|
|
|
virtual const char* className() const = 0;
|
|
|
|
virtual InodeIdentifier rootInode() const = 0;
|
|
|
|
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0;
|
|
|
|
virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0;
|
|
|
|
|
2018-10-27 01:14:24 +03:00
|
|
|
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle*) const = 0;
|
2018-10-14 22:19:27 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
struct DirectoryEntry {
|
|
|
|
String name;
|
|
|
|
InodeIdentifier inode;
|
|
|
|
byte fileType { 0 };
|
|
|
|
};
|
2018-10-17 11:55:43 +03:00
|
|
|
virtual bool enumerateDirectoryInode(InodeIdentifier, Function<bool(const DirectoryEntry&)>) const = 0;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
virtual bool setModificationTime(InodeIdentifier, dword timestamp) = 0;
|
2018-10-16 01:35:03 +03:00
|
|
|
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) = 0;
|
|
|
|
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) = 0;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2018-10-15 01:16:14 +03:00
|
|
|
InodeIdentifier childOfDirectoryInodeWithName(InodeIdentifier, const String& name) const;
|
2018-10-27 01:14:24 +03:00
|
|
|
ByteBuffer readEntireInode(InodeIdentifier, FileHandle* = nullptr) const;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FileSystem();
|
|
|
|
|
|
|
|
private:
|
|
|
|
dword m_id { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
inline FileSystem* InodeIdentifier::fileSystem()
|
|
|
|
{
|
|
|
|
return FileSystem::fromID(m_fileSystemID);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const FileSystem* InodeIdentifier::fileSystem() const
|
|
|
|
{
|
|
|
|
return FileSystem::fromID(m_fileSystemID);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline InodeMetadata InodeIdentifier::metadata() const
|
|
|
|
{
|
|
|
|
if (!isValid())
|
|
|
|
return InodeMetadata();
|
|
|
|
return fileSystem()->inodeMetadata(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool InodeIdentifier::isRootInode() const
|
|
|
|
{
|
|
|
|
return (*this) == fileSystem()->rootInode();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Traits<InodeIdentifier> {
|
|
|
|
// FIXME: This is a shitty hash.
|
|
|
|
static unsigned hash(const InodeIdentifier& inode) { return Traits<unsigned>::hash(inode.fileSystemID()) + Traits<unsigned>::hash(inode.index()); }
|
2018-10-17 11:55:43 +03:00
|
|
|
static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fileSystemID(), inode.index()); }
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|