Compare commits
No commits in common. "0847cfcb65079dfc374a56b0cc83d9be1ba67d5f" and "0d54d0ece10cf581163cec20afb56a169740d078" have entirely different histories.
0847cfcb65
...
0d54d0ece1
@ -33,7 +33,6 @@ set(SOURCES
|
|||||||
src/sys/mkdir.cpp
|
src/sys/mkdir.cpp
|
||||||
src/sys/mknod.cpp
|
src/sys/mknod.cpp
|
||||||
src/sys/waitpid.cpp
|
src/sys/waitpid.cpp
|
||||||
src/sys/getdents.cpp
|
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/tmpfs/FileSystem.cpp
|
src/fs/tmpfs/FileSystem.cpp
|
||||||
src/fs/devices/DeviceRegistry.cpp
|
src/fs/devices/DeviceRegistry.cpp
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <luna/SharedPtr.h>
|
#include <luna/SharedPtr.h>
|
||||||
#include <luna/StaticString.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
namespace VFS
|
namespace VFS
|
||||||
@ -13,14 +12,6 @@ namespace VFS
|
|||||||
};
|
};
|
||||||
|
|
||||||
class FileSystem;
|
class FileSystem;
|
||||||
class Inode;
|
|
||||||
|
|
||||||
struct DirectoryEntry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SharedPtr<Inode> inode;
|
|
||||||
StaticString<128> name;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Inode
|
class Inode
|
||||||
{
|
{
|
||||||
@ -28,8 +19,6 @@ namespace VFS
|
|||||||
// Directory-specific methods
|
// Directory-specific methods
|
||||||
virtual Result<SharedPtr<Inode>> find(const char* name) const = 0;
|
virtual Result<SharedPtr<Inode>> find(const char* name) const = 0;
|
||||||
|
|
||||||
virtual Option<DirectoryEntry> get(usize index) const = 0;
|
|
||||||
|
|
||||||
virtual Result<SharedPtr<Inode>> create_file(const char* name) = 0;
|
virtual Result<SharedPtr<Inode>> create_file(const char* name) = 0;
|
||||||
|
|
||||||
virtual Result<SharedPtr<Inode>> create_subdirectory(const char* name) = 0;
|
virtual Result<SharedPtr<Inode>> create_subdirectory(const char* name) = 0;
|
||||||
@ -71,11 +60,6 @@ namespace VFS
|
|||||||
return err(ENOTDIR);
|
return err(ENOTDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
Option<DirectoryEntry> get(usize) const override
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<Inode>> create_file(const char*) override
|
Result<SharedPtr<Inode>> create_file(const char*) override
|
||||||
{
|
{
|
||||||
return err(ENOTDIR);
|
return err(ENOTDIR);
|
||||||
@ -112,11 +96,6 @@ namespace VFS
|
|||||||
return err(ENOTDIR);
|
return err(ENOTDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
Option<DirectoryEntry> get(usize) const override
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<SharedPtr<Inode>> create_file(const char*) override
|
Result<SharedPtr<Inode>> create_file(const char*) override
|
||||||
{
|
{
|
||||||
return err(ENOTDIR);
|
return err(ENOTDIR);
|
||||||
|
@ -63,18 +63,9 @@ namespace TmpFS
|
|||||||
return err(ENOENT);
|
return err(ENOENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
Option<VFS::DirectoryEntry> DirInode::get(usize index) const
|
|
||||||
{
|
|
||||||
if (index >= m_entries.size()) return {};
|
|
||||||
|
|
||||||
return m_entries[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<void> DirInode::add_entry(SharedPtr<VFS::Inode> inode, const char* name)
|
Result<void> DirInode::add_entry(SharedPtr<VFS::Inode> inode, const char* name)
|
||||||
{
|
{
|
||||||
if (find(name).has_value()) return err(EEXIST);
|
Entry entry { inode, name };
|
||||||
|
|
||||||
VFS::DirectoryEntry entry { inode, name };
|
|
||||||
|
|
||||||
TRY(m_entries.try_append(move(entry)));
|
TRY(m_entries.try_append(move(entry)));
|
||||||
|
|
||||||
@ -83,6 +74,8 @@ namespace TmpFS
|
|||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> DirInode::create_file(const char* name)
|
Result<SharedPtr<VFS::Inode>> DirInode::create_file(const char* name)
|
||||||
{
|
{
|
||||||
|
if (find(name).has_value()) return err(EEXIST);
|
||||||
|
|
||||||
auto inode = TRY(m_fs->create_file_inode());
|
auto inode = TRY(m_fs->create_file_inode());
|
||||||
|
|
||||||
TRY(add_entry(inode, name));
|
TRY(add_entry(inode, name));
|
||||||
@ -92,6 +85,8 @@ namespace TmpFS
|
|||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> DirInode::create_subdirectory(const char* name)
|
Result<SharedPtr<VFS::Inode>> DirInode::create_subdirectory(const char* name)
|
||||||
{
|
{
|
||||||
|
if (find(name).has_value()) return err(EEXIST);
|
||||||
|
|
||||||
auto inode = TRY(m_fs->create_dir_inode(m_self));
|
auto inode = TRY(m_fs->create_dir_inode(m_self));
|
||||||
|
|
||||||
TRY(add_entry(inode, name));
|
TRY(add_entry(inode, name));
|
||||||
|
@ -185,7 +185,6 @@ namespace TmpFS
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result<SharedPtr<VFS::Inode>> find(const char* name) const override;
|
Result<SharedPtr<VFS::Inode>> find(const char* name) const override;
|
||||||
Option<VFS::DirectoryEntry> get(usize index) const override;
|
|
||||||
|
|
||||||
Result<usize> read(u8*, usize, usize) const override
|
Result<usize> read(u8*, usize, usize) const override
|
||||||
{
|
{
|
||||||
@ -252,6 +251,12 @@ namespace TmpFS
|
|||||||
|
|
||||||
SharedPtr<VFS::Inode> m_self;
|
SharedPtr<VFS::Inode> m_self;
|
||||||
|
|
||||||
Vector<VFS::DirectoryEntry> m_entries;
|
struct Entry
|
||||||
|
{
|
||||||
|
SharedPtr<VFS::Inode> inode;
|
||||||
|
StaticString<128> name;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<Entry> m_entries;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
#include "fs/VFS.h"
|
|
||||||
#include "memory/MemoryManager.h"
|
|
||||||
#include "sys/Syscall.h"
|
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
#include <bits/getdents.h>
|
|
||||||
|
|
||||||
Result<u64> sys_getdents(Registers*, SyscallArgs args)
|
|
||||||
{
|
|
||||||
int fd = (int)args[0];
|
|
||||||
luna_dirent* ent = (luna_dirent*)args[1];
|
|
||||||
usize count = (usize)args[2];
|
|
||||||
|
|
||||||
Thread* current = Scheduler::current();
|
|
||||||
|
|
||||||
auto& descriptor = *TRY(current->resolve_fd(fd));
|
|
||||||
|
|
||||||
if (descriptor.inode->type() != VFS::InodeType::Directory) return err(ENOTDIR);
|
|
||||||
|
|
||||||
usize nwrite = 0;
|
|
||||||
while (nwrite < count)
|
|
||||||
{
|
|
||||||
auto maybe_entry = descriptor.inode->get(descriptor.offset);
|
|
||||||
if (!maybe_entry.has_value()) break;
|
|
||||||
|
|
||||||
descriptor.offset++;
|
|
||||||
|
|
||||||
auto entry = maybe_entry.release_value();
|
|
||||||
|
|
||||||
luna_dirent kent;
|
|
||||||
kent.inode = entry.inode->inode_number();
|
|
||||||
strlcpy(kent.name, entry.name.chars(), entry.name.length() + 1);
|
|
||||||
|
|
||||||
if (!MemoryManager::copy_to_user_typed(ent, &kent)) return err(EFAULT);
|
|
||||||
|
|
||||||
ent++;
|
|
||||||
nwrite++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nwrite;
|
|
||||||
}
|
|
@ -24,6 +24,8 @@ Result<u64> sys_mknod(Registers*, SyscallArgs args)
|
|||||||
|
|
||||||
auto parent = TRY(VFS::resolve_path(dirname.chars()));
|
auto parent = TRY(VFS::resolve_path(dirname.chars()));
|
||||||
|
|
||||||
|
if (parent->find(basename.chars()).has_value()) return err(EEXIST);
|
||||||
|
|
||||||
auto inode = TRY(parent->fs().create_device_inode(maj, min));
|
auto inode = TRY(parent->fs().create_device_inode(maj, min));
|
||||||
TRY(parent->add_entry(inode, basename.chars()));
|
TRY(parent->add_entry(inode, basename.chars()));
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
/* bits/getdents.h: Definitions used for the getdents() system call. */
|
|
||||||
|
|
||||||
#ifndef _BITS_GETDENTS_H
|
|
||||||
#define _BITS_GETDENTS_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
ino_t inode;
|
|
||||||
char name[129];
|
|
||||||
} luna_dirent;
|
|
||||||
|
|
||||||
#endif
|
|
@ -15,7 +15,6 @@ typedef __u16_t mode_t;
|
|||||||
typedef __u64_t useconds_t;
|
typedef __u64_t useconds_t;
|
||||||
typedef __i64_t off_t;
|
typedef __i64_t off_t;
|
||||||
typedef __u64_t dev_t;
|
typedef __u64_t dev_t;
|
||||||
typedef __u64_t ino_t;
|
|
||||||
|
|
||||||
typedef off_t fpos_t;
|
typedef off_t fpos_t;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#define enumerate_syscalls(_e) \
|
#define enumerate_syscalls(_e) \
|
||||||
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
|
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
|
||||||
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl) _e(getdents)
|
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user