Compare commits
No commits in common. "6fbf97292a04b3d7701184d0c8f1a57af4de09ee" and "ff770b73288ad07f88cd3a0965a40e6fddc784ad" have entirely different histories.
6fbf97292a
...
ff770b7328
@ -1,6 +1,4 @@
|
|||||||
#include "fs/VFS.h"
|
#include "fs/VFS.h"
|
||||||
#include "Log.h"
|
|
||||||
#include <luna/PathParser.h>
|
|
||||||
|
|
||||||
namespace VFS
|
namespace VFS
|
||||||
{
|
{
|
||||||
@ -8,31 +6,6 @@ namespace VFS
|
|||||||
|
|
||||||
Inode& root_inode()
|
Inode& root_inode()
|
||||||
{
|
{
|
||||||
return *root_fs->root_inode();
|
return root_fs->root_inode();
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<Inode>> resolve_path(const char* path)
|
|
||||||
{
|
|
||||||
auto parser = TRY(PathParser::create(path));
|
|
||||||
|
|
||||||
kdbgln("vfs: trying to resolve path %s", path);
|
|
||||||
|
|
||||||
SharedPtr<Inode> current_inode;
|
|
||||||
|
|
||||||
if (parser.is_absolute()) { current_inode = root_fs->root_inode(); }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
kwarnln("vfs: cannot resolve path '%s', as relative paths are not supported yet", path);
|
|
||||||
return err(ENOTSUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* section;
|
|
||||||
while (parser.next().try_set_value(section))
|
|
||||||
{
|
|
||||||
kdbgln("vfs: searching for entry '%s' in inode %zu", section, current_inode->inode_number());
|
|
||||||
current_inode = TRY(current_inode->find(section));
|
|
||||||
}
|
|
||||||
|
|
||||||
return current_inode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace VFS
|
|||||||
class FileSystem
|
class FileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual SharedPtr<Inode> root_inode() const = 0;
|
virtual Inode& root_inode() const = 0;
|
||||||
|
|
||||||
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ namespace VFS
|
|||||||
|
|
||||||
extern SharedPtr<FileSystem> root_fs;
|
extern SharedPtr<FileSystem> root_fs;
|
||||||
|
|
||||||
Result<SharedPtr<Inode>> resolve_path(const char* path);
|
Result<Inode*> resolve_path(const char* path);
|
||||||
|
|
||||||
Inode& root_inode();
|
Inode& root_inode();
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ namespace TmpFS
|
|||||||
class FileSystem : public VFS::FileSystem
|
class FileSystem : public VFS::FileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SharedPtr<VFS::Inode> root_inode() const override
|
VFS::Inode& root_inode() const override
|
||||||
{
|
{
|
||||||
return m_root_inode;
|
return *m_root_inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
|
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
|
||||||
|
@ -71,10 +71,6 @@ static Result<void> try_init_vfs()
|
|||||||
|
|
||||||
kinfoln("etc inode's 'passwd' entry inode number: %zu", TRY(etc.find("passwd"))->inode_number());
|
kinfoln("etc inode's 'passwd' entry inode number: %zu", TRY(etc.find("passwd"))->inode_number());
|
||||||
|
|
||||||
auto& passwd = *TRY(VFS::resolve_path("/etc/passwd"));
|
|
||||||
|
|
||||||
kinfoln("/etc/passwd's inode number: %zu", passwd.inode_number());
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ set(FREESTANDING_SOURCES
|
|||||||
src/DebugLog.cpp
|
src/DebugLog.cpp
|
||||||
src/Heap.cpp
|
src/Heap.cpp
|
||||||
src/Spinlock.cpp
|
src/Spinlock.cpp
|
||||||
src/PathParser.cpp
|
|
||||||
src/UBSAN.cpp
|
src/UBSAN.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,11 +13,6 @@ extern "C"
|
|||||||
|
|
||||||
int strcmp(const char* a, const char* b);
|
int strcmp(const char* a, const char* b);
|
||||||
|
|
||||||
usize strspn(const char* str, const char* accept);
|
|
||||||
usize strcspn(const char* str, const char* reject);
|
|
||||||
|
|
||||||
char* strtok(char* str, const char* delim);
|
|
||||||
|
|
||||||
usize wcslen(const wchar_t* str);
|
usize wcslen(const wchar_t* str);
|
||||||
|
|
||||||
char* strdup(const char* str);
|
char* strdup(const char* str);
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <luna/CString.h>
|
|
||||||
#include <luna/Heap.h>
|
|
||||||
|
|
||||||
class PathParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Result<PathParser> create(const char* path);
|
|
||||||
|
|
||||||
PathParser(PathParser&& other);
|
|
||||||
PathParser(const PathParser&) = delete;
|
|
||||||
|
|
||||||
~PathParser();
|
|
||||||
|
|
||||||
bool is_absolute() const
|
|
||||||
{
|
|
||||||
return *m_original == '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
Option<const char*> next();
|
|
||||||
|
|
||||||
private:
|
|
||||||
PathParser(const char* original, char* copy);
|
|
||||||
|
|
||||||
const char* m_original { nullptr };
|
|
||||||
char* m_copy { nullptr };
|
|
||||||
bool m_already_called_next { false };
|
|
||||||
};
|
|
@ -136,71 +136,4 @@ extern "C"
|
|||||||
dest[copy_len] = 0;
|
dest[copy_len] = 0;
|
||||||
return src_len;
|
return src_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
usize strcspn(const char* str, const char* reject)
|
|
||||||
{
|
|
||||||
const char* s = str;
|
|
||||||
while (*s)
|
|
||||||
{
|
|
||||||
const char* rp = reject;
|
|
||||||
while (*rp)
|
|
||||||
{
|
|
||||||
if (*s == *rp) return (usize)(s - str);
|
|
||||||
rp++;
|
|
||||||
}
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
return (usize)(s - str);
|
|
||||||
}
|
|
||||||
|
|
||||||
usize strspn(const char* str, const char* accept)
|
|
||||||
{
|
|
||||||
const char* s = str;
|
|
||||||
while (*s)
|
|
||||||
{
|
|
||||||
const char* ap = accept;
|
|
||||||
bool match = false;
|
|
||||||
while (*ap)
|
|
||||||
{
|
|
||||||
if (*s == *ap)
|
|
||||||
{
|
|
||||||
match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ap++;
|
|
||||||
}
|
|
||||||
if (!match) return (usize)(s - str);
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
return (usize)(s - str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* strtok(char* str, const char* delim)
|
|
||||||
{
|
|
||||||
static char* s = nullptr;
|
|
||||||
if (str) s = str;
|
|
||||||
if (!s) return nullptr;
|
|
||||||
|
|
||||||
if (*s)
|
|
||||||
{
|
|
||||||
usize skip = strspn(s, delim);
|
|
||||||
s += skip;
|
|
||||||
|
|
||||||
if (*s == 0) return nullptr;
|
|
||||||
|
|
||||||
usize use = strcspn(s, delim);
|
|
||||||
char* result = s;
|
|
||||||
|
|
||||||
if (s[use] != 0)
|
|
||||||
{
|
|
||||||
s[use] = 0;
|
|
||||||
s += (use + 1);
|
|
||||||
}
|
|
||||||
else { s = nullptr; }
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
#include <luna/PathParser.h>
|
|
||||||
|
|
||||||
Result<PathParser> PathParser::create(const char* path)
|
|
||||||
{
|
|
||||||
char* copy = strdup(path);
|
|
||||||
if (!copy) return err(ENOMEM);
|
|
||||||
|
|
||||||
return PathParser { path, copy };
|
|
||||||
}
|
|
||||||
|
|
||||||
PathParser::PathParser(const char* original, char* copy) : m_original(original), m_copy(copy)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PathParser::PathParser(PathParser&& other) : m_original(other.m_original), m_copy(other.m_copy)
|
|
||||||
{
|
|
||||||
other.m_copy = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
PathParser::~PathParser()
|
|
||||||
{
|
|
||||||
if (m_copy) free_impl(m_copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
Option<const char*> PathParser::next()
|
|
||||||
{
|
|
||||||
char* result = strtok(m_already_called_next ? nullptr : m_copy, "/");
|
|
||||||
m_already_called_next = true;
|
|
||||||
|
|
||||||
if (!result) return {};
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -6,8 +6,8 @@ source $(dirname $0)/env.sh
|
|||||||
cd $LUNA_ROOT
|
cd $LUNA_ROOT
|
||||||
|
|
||||||
SOURCES=($(find kernel/src -type f | grep -v "\.asm" | grep -v "bootboot.h"))
|
SOURCES=($(find kernel/src -type f | grep -v "\.asm" | grep -v "bootboot.h"))
|
||||||
SOURCES+=($(find libluna/src -type f))
|
SOURCES+=($(find luna/src -type f))
|
||||||
SOURCES+=($(find libluna/include/luna -type f | grep -v "Types.h"))
|
SOURCES+=($(find luna/include/luna -type f | grep -v "Types.h"))
|
||||||
|
|
||||||
for f in ${SOURCES[@]}
|
for f in ${SOURCES[@]}
|
||||||
do
|
do
|
||||||
|
Loading…
Reference in New Issue
Block a user