Compare commits
No commits in common. "5b43345b7d441facf2ab1a40492ec97d5e7c61c0" and "0635f1c243ccfe6ec5e8a75f93d0eb1a771c3168" have entirely different histories.
5b43345b7d
...
0635f1c243
@ -14,12 +14,8 @@ namespace VFS
|
|||||||
class Inode
|
class Inode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Directory-specific methods
|
virtual Result<Inode*> find(const char* name) const = 0;
|
||||||
virtual Result<SharedPtr<Inode>> find(const char* name) const = 0;
|
|
||||||
|
|
||||||
virtual Result<SharedPtr<Inode>> create_file(const char* name) = 0;
|
|
||||||
|
|
||||||
// Generic methods
|
|
||||||
virtual FileSystem& fs() const = 0;
|
virtual FileSystem& fs() const = 0;
|
||||||
|
|
||||||
virtual ~Inode() = default;
|
virtual ~Inode() = default;
|
||||||
@ -32,12 +28,7 @@ namespace VFS
|
|||||||
class FileInode : Inode
|
class FileInode : Inode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Result<SharedPtr<Inode>> find(const char*) const override
|
Result<Inode*> find(const char*) const override
|
||||||
{
|
|
||||||
return err(ENOTDIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<Inode>> create_file(const char*) override
|
|
||||||
{
|
{
|
||||||
return err(ENOTDIR);
|
return err(ENOTDIR);
|
||||||
}
|
}
|
||||||
@ -57,8 +48,6 @@ namespace VFS
|
|||||||
|
|
||||||
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
||||||
|
|
||||||
virtual Result<SharedPtr<Inode>> create_dir_inode() = 0;
|
|
||||||
|
|
||||||
virtual ~FileSystem() = default;
|
virtual ~FileSystem() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#include "fs/tmpfs/FileSystem.h"
|
#include "fs/tmpfs/FileSystem.h"
|
||||||
#include <luna/Alloc.h>
|
#include <luna/Alloc.h>
|
||||||
#include <luna/Ignore.h>
|
|
||||||
|
|
||||||
namespace TmpFS
|
namespace TmpFS
|
||||||
{
|
{
|
||||||
Result<SharedPtr<VFS::FileSystem>> FileSystem::create()
|
Result<SharedPtr<VFS::FileSystem>> FileSystem::create()
|
||||||
{
|
{
|
||||||
SharedPtr<FileSystem> fs = TRY(adopt_shared(new (std::nothrow) FileSystem()));
|
SharedPtr<FileSystem> fs = TRY(adopt_shared(new (std::nothrow) FileSystem()));
|
||||||
SharedPtr<VFS::Inode> root = TRY(fs->create_dir_inode());
|
SharedPtr<VFS::Inode> root = TRY(fs->create_file_inode());
|
||||||
fs->set_root(root);
|
fs->set_root(root);
|
||||||
return (SharedPtr<VFS::FileSystem>)fs;
|
return (SharedPtr<VFS::FileSystem>)fs;
|
||||||
}
|
}
|
||||||
@ -22,48 +21,8 @@ namespace TmpFS
|
|||||||
return (SharedPtr<VFS::Inode>)inode;
|
return (SharedPtr<VFS::Inode>)inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> FileSystem::create_dir_inode()
|
|
||||||
{
|
|
||||||
SharedPtr<DirInode> inode = TRY(make_shared<DirInode>());
|
|
||||||
TRY(inode->add_entry(inode, "."));
|
|
||||||
|
|
||||||
inode->set_fs(*this, {});
|
|
||||||
inode->set_inode_number(m_next_inode_number, {});
|
|
||||||
TRY(m_inodes.try_append(inode));
|
|
||||||
m_next_inode_number++;
|
|
||||||
return (SharedPtr<VFS::Inode>)inode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileSystem::set_root(SharedPtr<VFS::Inode> root)
|
void FileSystem::set_root(SharedPtr<VFS::Inode> root)
|
||||||
{
|
{
|
||||||
m_root_inode = root;
|
m_root_inode = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> DirInode::find(const char* name) const
|
|
||||||
{
|
|
||||||
for (const auto& entry : m_entries)
|
|
||||||
{
|
|
||||||
if (!strcmp(name, entry.name.chars())) return entry.inode;
|
|
||||||
}
|
|
||||||
|
|
||||||
return err(ENOENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<void> DirInode::add_entry(SharedPtr<VFS::Inode> inode, const char* name)
|
|
||||||
{
|
|
||||||
Entry entry = { inode, TRY(OwnedStringView::from_string_literal(name)) };
|
|
||||||
|
|
||||||
TRY(m_entries.try_append(move(entry)));
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> DirInode::create_file(const char* name)
|
|
||||||
{
|
|
||||||
auto inode = TRY(m_fs->create_file_inode());
|
|
||||||
|
|
||||||
TRY(add_entry(inode, name));
|
|
||||||
|
|
||||||
return inode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "fs/VFS.h"
|
#include "fs/VFS.h"
|
||||||
#include <luna/Atomic.h>
|
#include <luna/Atomic.h>
|
||||||
#include <luna/Badge.h>
|
#include <luna/Badge.h>
|
||||||
#include <luna/OwnedStringView.h>
|
|
||||||
#include <luna/Vector.h>
|
#include <luna/Vector.h>
|
||||||
|
|
||||||
namespace TmpFS
|
namespace TmpFS
|
||||||
@ -16,7 +15,6 @@ namespace TmpFS
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
|
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
|
||||||
Result<SharedPtr<VFS::Inode>> create_dir_inode() override;
|
|
||||||
|
|
||||||
static Result<SharedPtr<VFS::FileSystem>> create();
|
static Result<SharedPtr<VFS::FileSystem>> create();
|
||||||
|
|
||||||
@ -64,55 +62,4 @@ namespace TmpFS
|
|||||||
VFS::FileSystem* m_fs;
|
VFS::FileSystem* m_fs;
|
||||||
usize m_inode_number;
|
usize m_inode_number;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirInode : public VFS::Inode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DirInode() = default;
|
|
||||||
|
|
||||||
void set_fs(FileSystem& fs, Badge<FileSystem>)
|
|
||||||
{
|
|
||||||
m_fs = &fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_inode_number(usize inum, Badge<FileSystem>)
|
|
||||||
{
|
|
||||||
m_inode_number = inum;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> find(const char* name) const override;
|
|
||||||
|
|
||||||
VFS::FileSystem& fs() const override
|
|
||||||
{
|
|
||||||
return *m_fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
usize inode_number() const override
|
|
||||||
{
|
|
||||||
return m_inode_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
VFS::InodeType type() const override
|
|
||||||
{
|
|
||||||
return VFS::InodeType::Directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> create_file(const char* name) override;
|
|
||||||
|
|
||||||
Result<void> add_entry(SharedPtr<VFS::Inode> inode, const char* name);
|
|
||||||
|
|
||||||
virtual ~DirInode() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
VFS::FileSystem* m_fs;
|
|
||||||
usize m_inode_number;
|
|
||||||
|
|
||||||
struct Entry
|
|
||||||
{
|
|
||||||
SharedPtr<VFS::Inode> inode;
|
|
||||||
OwnedStringView name;
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector<Entry> m_entries;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,6 @@ Result<void> init()
|
|||||||
VFS::Inode& root_inode = VFS::root_inode();
|
VFS::Inode& root_inode = VFS::root_inode();
|
||||||
kinfoln("root inode number: %zu", root_inode.inode_number());
|
kinfoln("root inode number: %zu", root_inode.inode_number());
|
||||||
|
|
||||||
TRY(root_inode.create_file("usr"));
|
|
||||||
kinfoln("root inode's 'usr' entry inode number: %zu", TRY(root_inode.find("usr"))->inode_number());
|
|
||||||
|
|
||||||
TarStream::Entry entry;
|
TarStream::Entry entry;
|
||||||
while (TRY(g_initrd.read_next_entry(entry)))
|
while (TRY(g_initrd.read_next_entry(entry)))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user