kernel: Replace unlink() with unlinkat()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
259ea86c20
commit
02f8a50b9d
@ -3,10 +3,11 @@
|
|||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
#include <luna/PathParser.h>
|
#include <luna/PathParser.h>
|
||||||
|
|
||||||
Result<u64> sys_unlink(Registers*, SyscallArgs args)
|
Result<u64> sys_unlinkat(Registers*, SyscallArgs args)
|
||||||
{
|
{
|
||||||
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
int dirfd = (int)args[0];
|
||||||
int flags = (int)args[1];
|
auto path = TRY(MemoryManager::strdup_from_user(args[1]));
|
||||||
|
int flags = (int)args[2];
|
||||||
|
|
||||||
Thread* current = Scheduler::current();
|
Thread* current = Scheduler::current();
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ Result<u64> sys_unlink(Registers*, SyscallArgs args)
|
|||||||
|
|
||||||
if (basename.view() == ".") return err(EINVAL);
|
if (basename.view() == ".") return err(EINVAL);
|
||||||
|
|
||||||
auto inode = TRY(VFS::resolve_path(dirname.chars(), current->auth, current->current_directory));
|
auto inode = TRY(current->resolve_atfile(dirfd, dirname, false));
|
||||||
if (!VFS::can_write(inode, current->auth)) return err(EACCES);
|
if (!VFS::can_write(inode, current->auth)) return err(EACCES);
|
||||||
|
|
||||||
if (flags > 0)
|
if (flags > 0)
|
||||||
|
@ -7,4 +7,6 @@
|
|||||||
|
|
||||||
#define AT_EMPTY_PATH 1
|
#define AT_EMPTY_PATH 1
|
||||||
|
|
||||||
|
#define AT_REMOVEDIR 1
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -304,13 +304,13 @@ extern "C"
|
|||||||
|
|
||||||
int unlink(const char* path)
|
int unlink(const char* path)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_unlink, path, 0);
|
long rc = syscall(SYS_unlinkat, AT_FDCWD, path, 0);
|
||||||
__errno_return(rc, int);
|
__errno_return(rc, int);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rmdir(const char* path)
|
int rmdir(const char* path)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_unlink, path, 1);
|
long rc = syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
|
||||||
__errno_return(rc, int);
|
__errno_return(rc, int);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(openat) _e(close) _e(read) _e(getpid) _e(write) \
|
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(openat) _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(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(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown) \
|
||||||
_e(ioctl) _e(fstatat) _e(chdir) _e(getcwd) _e(unlink)
|
_e(ioctl) _e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <os/FileSystem.h>
|
#include <os/FileSystem.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -38,7 +39,7 @@ namespace os::FileSystem
|
|||||||
|
|
||||||
Result<void> remove(StringView path)
|
Result<void> remove(StringView path)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_unlink, path.chars(), 0);
|
long rc = syscall(SYS_unlinkat, AT_FDCWD, path.chars(), 0);
|
||||||
|
|
||||||
return Result<void>::from_syscall(rc);
|
return Result<void>::from_syscall(rc);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user