diff --git a/kernel/src/sys/link.cpp b/kernel/src/sys/link.cpp index ccbc8919..0a5d6768 100644 --- a/kernel/src/sys/link.cpp +++ b/kernel/src/sys/link.cpp @@ -3,10 +3,11 @@ #include "thread/Scheduler.h" #include -Result sys_unlink(Registers*, SyscallArgs args) +Result sys_unlinkat(Registers*, SyscallArgs args) { - auto path = TRY(MemoryManager::strdup_from_user(args[0])); - int flags = (int)args[1]; + int dirfd = (int)args[0]; + auto path = TRY(MemoryManager::strdup_from_user(args[1])); + int flags = (int)args[2]; Thread* current = Scheduler::current(); @@ -17,7 +18,7 @@ Result sys_unlink(Registers*, SyscallArgs args) 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 (flags > 0) diff --git a/libc/include/bits/atfile.h b/libc/include/bits/atfile.h index 0393b0e1..a7f9ce7e 100644 --- a/libc/include/bits/atfile.h +++ b/libc/include/bits/atfile.h @@ -7,4 +7,6 @@ #define AT_EMPTY_PATH 1 +#define AT_REMOVEDIR 1 + #endif diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 8521a7f2..a6c61ead 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -304,13 +304,13 @@ extern "C" 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); } 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); } } diff --git a/libluna/include/luna/Syscall.h b/libluna/include/luna/Syscall.h index 9c42c71d..18834c7f 100644 --- a/libluna/include/luna/Syscall.h +++ b/libluna/include/luna/Syscall.h @@ -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(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(fstatat) _e(chdir) _e(getcwd) _e(unlink) + _e(ioctl) _e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) enum Syscalls { diff --git a/libos/src/FileSystem.cpp b/libos/src/FileSystem.cpp index af379645..2ea1939c 100644 --- a/libos/src/FileSystem.cpp +++ b/libos/src/FileSystem.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,7 @@ namespace os::FileSystem Result remove(StringView path) { - long rc = syscall(SYS_unlink, path.chars(), 0); + long rc = syscall(SYS_unlinkat, AT_FDCWD, path.chars(), 0); return Result::from_syscall(rc); }