Compare commits
No commits in common. "3618a41bcd9611f97f00e3f68e1f1af3d7e1d4dc" and "1b4f48b92c23a3bb17b131523eb93139fe988096" have entirely different histories.
3618a41bcd
...
1b4f48b92c
@ -22,4 +22,3 @@ luna_app(ls.cpp ls OFF)
|
||||
luna_app(chown.cpp chown OFF)
|
||||
luna_app(chmod.cpp chmod OFF)
|
||||
luna_app(mkdir.cpp mkdir OFF)
|
||||
luna_app(rm.cpp rm OFF)
|
||||
|
17
apps/rm.cpp
17
apps/rm.cpp
@ -1,17 +0,0 @@
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
StringView path;
|
||||
|
||||
os::ArgumentParser parser;
|
||||
parser.add_positional_argument(path, "path"_sv, true);
|
||||
parser.parse(argc, argv);
|
||||
|
||||
if (remove(path.chars()) < 0)
|
||||
{
|
||||
perror("rm");
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -36,7 +36,6 @@ set(SOURCES
|
||||
src/sys/getdents.cpp
|
||||
src/sys/stat.cpp
|
||||
src/sys/chdir.cpp
|
||||
src/sys/link.cpp
|
||||
src/fs/VFS.cpp
|
||||
src/fs/tmpfs/FileSystem.cpp
|
||||
src/fs/devices/DeviceRegistry.cpp
|
||||
|
@ -43,10 +43,6 @@ namespace VFS
|
||||
|
||||
virtual Result<void> add_entry(SharedPtr<Inode> inode, const char* name) = 0;
|
||||
|
||||
virtual Result<void> remove_entry(const char* name) = 0;
|
||||
|
||||
virtual usize entries() const = 0;
|
||||
|
||||
// File-specific methods
|
||||
virtual Result<usize> read(u8* buf, usize offset, usize length) const = 0;
|
||||
|
||||
@ -71,9 +67,6 @@ namespace VFS
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void did_link() = 0;
|
||||
virtual void did_unlink() = 0;
|
||||
|
||||
// Metadata changers
|
||||
virtual Result<void> chmod(mode_t mode) = 0;
|
||||
|
||||
@ -117,16 +110,6 @@ namespace VFS
|
||||
return err(ENOTDIR);
|
||||
}
|
||||
|
||||
Result<void> remove_entry(const char*) override
|
||||
{
|
||||
return err(ENOTDIR);
|
||||
}
|
||||
|
||||
usize entries() const override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool blocking() const override
|
||||
{
|
||||
return false;
|
||||
@ -168,16 +151,6 @@ namespace VFS
|
||||
return err(ENOTDIR);
|
||||
}
|
||||
|
||||
Result<void> remove_entry(const char*) override
|
||||
{
|
||||
return err(ENOTDIR);
|
||||
}
|
||||
|
||||
usize entries() const override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
InodeType type() const override
|
||||
{
|
||||
return InodeType::Device;
|
||||
|
@ -79,22 +79,6 @@ namespace TmpFS
|
||||
|
||||
TRY(m_entries.try_append(move(entry)));
|
||||
|
||||
inode->did_link();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> DirInode::remove_entry(const char* name)
|
||||
{
|
||||
SharedPtr<VFS::Inode> inode = TRY(find(name));
|
||||
|
||||
if (inode->type() == VFS::InodeType::Directory && inode->entries() != 2) return err(ENOTEMPTY);
|
||||
|
||||
m_entries.remove_first_matching(
|
||||
[&](const VFS::DirectoryEntry& entry) { return !strcmp(entry.name.chars(), name); });
|
||||
|
||||
inode->did_unlink();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -96,16 +96,6 @@ namespace TmpFS
|
||||
return {};
|
||||
}
|
||||
|
||||
void did_link() override
|
||||
{
|
||||
m_nlinks++;
|
||||
}
|
||||
|
||||
void did_unlink() override
|
||||
{
|
||||
m_nlinks--;
|
||||
}
|
||||
|
||||
virtual ~FileInode() = default;
|
||||
|
||||
private:
|
||||
@ -115,7 +105,6 @@ namespace TmpFS
|
||||
mode_t m_mode;
|
||||
u32 m_uid { 0 };
|
||||
u32 m_gid { 0 };
|
||||
u32 m_nlinks { 0 };
|
||||
};
|
||||
|
||||
class DeviceInode : public VFS::DeviceInode
|
||||
@ -207,16 +196,6 @@ namespace TmpFS
|
||||
return {};
|
||||
}
|
||||
|
||||
void did_link() override
|
||||
{
|
||||
m_nlinks++;
|
||||
}
|
||||
|
||||
void did_unlink() override
|
||||
{
|
||||
m_nlinks--;
|
||||
}
|
||||
|
||||
virtual ~DeviceInode() = default;
|
||||
|
||||
private:
|
||||
@ -226,7 +205,6 @@ namespace TmpFS
|
||||
mode_t m_mode;
|
||||
u32 m_uid { 0 };
|
||||
u32 m_gid { 0 };
|
||||
u32 m_nlinks { 0 };
|
||||
};
|
||||
|
||||
class DirInode : public VFS::Inode
|
||||
@ -320,23 +298,6 @@ namespace TmpFS
|
||||
return VFS::InodeType::Directory;
|
||||
}
|
||||
|
||||
void did_link() override
|
||||
{
|
||||
}
|
||||
|
||||
void did_unlink() override
|
||||
{
|
||||
m_self = {};
|
||||
m_entries.clear();
|
||||
}
|
||||
|
||||
usize entries() const override
|
||||
{
|
||||
return m_entries.size();
|
||||
}
|
||||
|
||||
Result<void> remove_entry(const char* name) override;
|
||||
|
||||
Result<SharedPtr<VFS::Inode>> create_file(const char* name) override;
|
||||
Result<SharedPtr<VFS::Inode>> create_subdirectory(const char* name) override;
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "sys/Syscall.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include <luna/PathParser.h>
|
||||
|
||||
Result<u64> sys_unlink(Registers*, SyscallArgs args)
|
||||
{
|
||||
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
||||
int flags = (int)args[1];
|
||||
|
||||
Thread* current = Scheduler::current();
|
||||
|
||||
PathParser parser = TRY(PathParser::create(path.chars()));
|
||||
|
||||
auto dirname = TRY(parser.dirname());
|
||||
auto basename = TRY(parser.basename());
|
||||
|
||||
if (basename.view() == ".") return err(EINVAL);
|
||||
|
||||
auto inode = TRY(VFS::resolve_path(dirname.chars(), current->auth, current->current_directory));
|
||||
if (!VFS::can_write(inode, current->auth)) return err(EACCES);
|
||||
|
||||
if (flags > 0)
|
||||
{
|
||||
auto child = TRY(inode->find(basename.chars()));
|
||||
if (child->type() != VFS::InodeType::Directory) return err(ENOTDIR);
|
||||
}
|
||||
|
||||
TRY(inode->remove_entry(basename.chars()));
|
||||
|
||||
return 0;
|
||||
}
|
@ -53,7 +53,7 @@ add_custom_target(libc
|
||||
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:bare_libc>
|
||||
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:luna>
|
||||
COMMAND ${CMAKE_AR} -rcs ${CMAKE_CURRENT_BINARY_DIR}/libc.a *.o
|
||||
COMMAND /usr/bin/rm *.o
|
||||
COMMAND rm *.o
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS bare_libc luna crt0
|
||||
)
|
||||
|
@ -128,9 +128,6 @@ extern "C"
|
||||
/* Write an error message to standard error. */
|
||||
void perror(const char* s);
|
||||
|
||||
/* Remove a file from the filesystem. */
|
||||
int remove(const char* path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -103,12 +103,6 @@ extern "C"
|
||||
/* Retrieve the current working directory. */
|
||||
char* getcwd(char* buf, size_t size);
|
||||
|
||||
/* Remove a name from the filesystem. */
|
||||
int unlink(const char* path);
|
||||
|
||||
/* Remove a directory from the filesystem. */
|
||||
int rmdir(const char* path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -336,12 +336,6 @@ extern "C"
|
||||
if (s && *s) fprintf(stderr, "%s: ", s);
|
||||
fprintf(stderr, "%s\n", strerror(err));
|
||||
}
|
||||
|
||||
int remove(const char* path)
|
||||
{
|
||||
// On Luna, unlink() allows removal of directories.
|
||||
return unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
void debug_log_impl(const char* format, va_list ap)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -301,16 +300,4 @@ extern "C"
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
int unlink(const char* path)
|
||||
{
|
||||
long rc = syscall(SYS_unlink, path, 0);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int rmdir(const char* path)
|
||||
{
|
||||
long rc = syscall(SYS_unlink, path, 1);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
_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(execve) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl) _e(getdents) _e(getuid) \
|
||||
_e(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown) \
|
||||
_e(ioctl) _e(stat) _e(fstat) _e(chdir) _e(getcwd) _e(unlink)
|
||||
_e(ioctl) _e(stat) _e(fstat) _e(chdir) _e(getcwd)
|
||||
|
||||
enum Syscalls
|
||||
{
|
||||
|
@ -111,7 +111,13 @@ template <typename T> class Vector
|
||||
{
|
||||
if (m_size == 0) return {};
|
||||
|
||||
return remove_at(0);
|
||||
T item = move(m_data[0]);
|
||||
|
||||
m_size--;
|
||||
|
||||
memmove(m_data, m_data + 1, m_size * sizeof(T));
|
||||
|
||||
return move(item);
|
||||
}
|
||||
|
||||
const T& operator[](usize index) const
|
||||
@ -171,41 +177,8 @@ template <typename T> class Vector
|
||||
return m_size;
|
||||
}
|
||||
|
||||
T remove_at(usize index)
|
||||
{
|
||||
check(index < m_size);
|
||||
|
||||
T item = move(m_data[index]);
|
||||
|
||||
memmove(m_data + index, m_data + (index + 1), (m_size - (index + 1)) * sizeof(T));
|
||||
|
||||
m_size--;
|
||||
|
||||
return move(item);
|
||||
}
|
||||
|
||||
template <typename Callback> Option<T> remove_first_matching(Callback callback)
|
||||
{
|
||||
Option<usize> index = {};
|
||||
|
||||
for (usize i = 0; i < m_size; i++)
|
||||
{
|
||||
if (callback(m_data[i]))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!index.has_value()) return {};
|
||||
|
||||
return remove_at(index.value());
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
for (usize i = 0; i < m_size; i++) { m_data[i].~T(); }
|
||||
|
||||
m_size = m_capacity = 0;
|
||||
free_impl(m_data);
|
||||
m_data = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user