2023-02-03 21:18:52 +00:00
|
|
|
#pragma once
|
|
|
|
#include <luna/SharedPtr.h>
|
|
|
|
|
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
enum class InodeType
|
|
|
|
{
|
|
|
|
RegularFile,
|
|
|
|
Directory
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileSystem;
|
|
|
|
|
|
|
|
class Inode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual Result<Inode*> find(const char* name) const = 0;
|
|
|
|
|
|
|
|
virtual FileSystem& fs() const = 0;
|
|
|
|
|
|
|
|
virtual ~Inode() = default;
|
|
|
|
|
2023-02-25 16:54:01 +00:00
|
|
|
virtual InodeType type() const = 0;
|
2023-02-25 17:03:11 +00:00
|
|
|
|
|
|
|
virtual usize inode_number() const = 0;
|
2023-02-25 16:54:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileInode : Inode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Result<Inode*> find(const char*) const override
|
|
|
|
{
|
|
|
|
return err(ENOTDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
InodeType type() const override
|
|
|
|
{
|
|
|
|
return InodeType::RegularFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FileInode() = default;
|
2023-02-03 21:18:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileSystem
|
|
|
|
{
|
|
|
|
public:
|
2023-02-25 17:05:25 +00:00
|
|
|
virtual Inode& root_inode() const = 0;
|
2023-02-03 21:18:52 +00:00
|
|
|
|
2023-02-25 17:03:11 +00:00
|
|
|
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
|
|
|
|
2023-02-03 21:18:52 +00:00
|
|
|
virtual ~FileSystem() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern SharedPtr<FileSystem> root_fs;
|
|
|
|
|
|
|
|
Result<Inode*> resolve_path(const char* path);
|
2023-02-25 17:05:25 +00:00
|
|
|
|
|
|
|
Inode& root_inode();
|
2023-02-03 21:18:52 +00:00
|
|
|
}
|