Compare commits
No commits in common. "cb4246b98df40e0ce729dda42d726c436bcb7902" and "89958fbc74c70004a56b201fa017f0a88bdf7912" have entirely different histories.
cb4246b98d
...
89958fbc74
@ -27,8 +27,6 @@ set(SOURCES
|
|||||||
src/sys/clock_gettime.cpp
|
src/sys/clock_gettime.cpp
|
||||||
src/sys/allocate_memory.cpp
|
src/sys/allocate_memory.cpp
|
||||||
src/sys/usleep.cpp
|
src/sys/usleep.cpp
|
||||||
src/fs/VFS.cpp
|
|
||||||
src/fs/tmpfs/FileSystem.cpp
|
|
||||||
src/InitRD.cpp
|
src/InitRD.cpp
|
||||||
src/ELF.cpp
|
src/ELF.cpp
|
||||||
)
|
)
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#include "fs/VFS.h"
|
|
||||||
|
|
||||||
namespace VFS
|
|
||||||
{
|
|
||||||
SharedPtr<FileSystem> root_fs;
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#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;
|
|
||||||
|
|
||||||
InodeType type;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileSystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual Inode& root() const = 0;
|
|
||||||
|
|
||||||
virtual ~FileSystem() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern SharedPtr<FileSystem> root_fs;
|
|
||||||
|
|
||||||
Result<Inode*> resolve_path(const char* path);
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
#include "fs/tmpfs/FileSystem.h"
|
|
||||||
#include <luna/Alloc.h>
|
|
||||||
|
|
||||||
namespace TmpFS
|
|
||||||
{
|
|
||||||
Result<SharedPtr<VFS::FileSystem>> FileSystem::create()
|
|
||||||
{
|
|
||||||
SharedPtr<Inode> root = TRY(make_shared<Inode>());
|
|
||||||
SharedPtr<FileSystem> fs = TRY(adopt_shared(new (std::nothrow) FileSystem()));
|
|
||||||
root->set_fs(*fs, {});
|
|
||||||
TRY(fs->set_root(root));
|
|
||||||
return (SharedPtr<VFS::FileSystem>)fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSystem::FileSystem()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<void> FileSystem::set_root(SharedPtr<VFS::Inode> root)
|
|
||||||
{
|
|
||||||
m_root_inode = root;
|
|
||||||
return m_inodes.try_append(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
Inode::Inode()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Inode::set_fs(FileSystem& fs, Badge<FileSystem>)
|
|
||||||
{
|
|
||||||
m_fs = &fs;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "fs/VFS.h"
|
|
||||||
#include <luna/Badge.h>
|
|
||||||
#include <luna/Vector.h>
|
|
||||||
|
|
||||||
namespace TmpFS
|
|
||||||
{
|
|
||||||
class FileSystem : public VFS::FileSystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
VFS::Inode& root() const override
|
|
||||||
{
|
|
||||||
return *m_root_inode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Result<SharedPtr<VFS::FileSystem>> create();
|
|
||||||
|
|
||||||
virtual ~FileSystem() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FileSystem();
|
|
||||||
|
|
||||||
Result<void> set_root(SharedPtr<VFS::Inode> root);
|
|
||||||
|
|
||||||
SharedPtr<VFS::Inode> m_root_inode;
|
|
||||||
Vector<SharedPtr<VFS::Inode>> m_inodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Inode : public VFS::Inode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Inode();
|
|
||||||
|
|
||||||
void set_fs(FileSystem& fs, Badge<FileSystem>);
|
|
||||||
|
|
||||||
Result<VFS::Inode*> find(const char*) const override
|
|
||||||
{
|
|
||||||
return err(ENOTSUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
VFS::FileSystem& fs() const override
|
|
||||||
{
|
|
||||||
return *m_fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~Inode() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
VFS::FileSystem* m_fs;
|
|
||||||
};
|
|
||||||
}
|
|
@ -7,7 +7,6 @@
|
|||||||
#include "arch/Timer.h"
|
#include "arch/Timer.h"
|
||||||
#include "boot/Init.h"
|
#include "boot/Init.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "fs/tmpfs/FileSystem.h"
|
|
||||||
#include "memory/Heap.h"
|
#include "memory/Heap.h"
|
||||||
#include "memory/KernelVM.h"
|
#include "memory/KernelVM.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
@ -56,8 +55,6 @@ Result<void> init()
|
|||||||
Thread::init();
|
Thread::init();
|
||||||
Scheduler::init();
|
Scheduler::init();
|
||||||
|
|
||||||
VFS::root_fs = TRY(TmpFS::FileSystem::create());
|
|
||||||
|
|
||||||
TarStream::Entry entry;
|
TarStream::Entry entry;
|
||||||
while (TRY(g_initrd.read_next_entry(entry)))
|
while (TRY(g_initrd.read_next_entry(entry)))
|
||||||
{
|
{
|
||||||
|
@ -117,17 +117,12 @@ template <typename T, class... Args> Result<SharedPtr<T>> make_shared(Args... ar
|
|||||||
return SharedPtr<T> { ptr, ref_count };
|
return SharedPtr<T> { ptr, ref_count };
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: ptr is deleted if any of the adopt_shared* functions fail to construct a SharedPtr.
|
|
||||||
template <typename T> Result<SharedPtr<T>> adopt_shared(T* ptr)
|
template <typename T> Result<SharedPtr<T>> adopt_shared(T* ptr)
|
||||||
{
|
{
|
||||||
using RefCount = __detail::RefCount;
|
using RefCount = __detail::RefCount;
|
||||||
|
|
||||||
auto guard = make_scope_guard([ptr] { delete ptr; });
|
|
||||||
|
|
||||||
RefCount* const ref_count = TRY(make<RefCount>());
|
RefCount* const ref_count = TRY(make<RefCount>());
|
||||||
|
|
||||||
guard.deactivate();
|
|
||||||
|
|
||||||
return SharedPtr<T> { ptr, ref_count };
|
return SharedPtr<T> { ptr, ref_count };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +138,13 @@ template <typename T> Result<SharedPtr<T>> adopt_shared_from_owned(OwnedPtr<T>&&
|
|||||||
T* ptr = other.m_ptr;
|
T* ptr = other.m_ptr;
|
||||||
other.m_ptr = nullptr;
|
other.m_ptr = nullptr;
|
||||||
|
|
||||||
|
// FIXME: Should the pointee magically vanish on failure? Or go back into the OwnedPtr, even though it's been
|
||||||
|
// moved...
|
||||||
|
auto guard = make_scope_guard([&] { delete ptr; });
|
||||||
|
|
||||||
const SharedPtr<T> shared_ptr = TRY(adopt_shared(ptr));
|
const SharedPtr<T> shared_ptr = TRY(adopt_shared(ptr));
|
||||||
|
|
||||||
|
guard.deactivate();
|
||||||
|
|
||||||
return shared_ptr;
|
return shared_ptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user