diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-10-01 11:36:24 +0000 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-11 19:55:37 -0700 |
commit | eb5389e933bec98735e71c3bab3706841647af48 (patch) | |
tree | fb76f67326b57891e7ed4531c0a582a04157405b | |
parent | 6445a706cf9a6be799b9fc8ae7b724ebc450b55b (diff) | |
download | serenity-eb5389e933bec98735e71c3bab3706841647af48.zip |
Kernel+LibC+LibCore: Implement `mkdirat(2)`
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/mkdir.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibC/stat.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibC/sys/stat.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 2 |
5 files changed, 12 insertions, 5 deletions
diff --git a/Kernel/Process.h b/Kernel/Process.h index 3147965db3..cc1410d9e0 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -374,7 +374,7 @@ public: ErrorOr<FlatPtr> sys$access(Userspace<char const*> pathname, size_t path_length, int mode); ErrorOr<FlatPtr> sys$fcntl(int fd, int cmd, uintptr_t extra_arg); ErrorOr<FlatPtr> sys$ioctl(int fd, unsigned request, FlatPtr arg); - ErrorOr<FlatPtr> sys$mkdir(Userspace<char const*> pathname, size_t path_length, mode_t mode); + ErrorOr<FlatPtr> sys$mkdir(int dirfd, Userspace<char const*> pathname, size_t path_length, mode_t mode); ErrorOr<FlatPtr> sys$times(Userspace<tms*>); ErrorOr<FlatPtr> sys$utime(Userspace<char const*> pathname, size_t path_length, Userspace<const struct utimbuf*>); ErrorOr<FlatPtr> sys$utimensat(Userspace<Syscall::SC_utimensat_params const*>); diff --git a/Kernel/Syscalls/mkdir.cpp b/Kernel/Syscalls/mkdir.cpp index 7cd0de8cbd..e614316c8b 100644 --- a/Kernel/Syscalls/mkdir.cpp +++ b/Kernel/Syscalls/mkdir.cpp @@ -10,12 +10,12 @@ namespace Kernel { -ErrorOr<FlatPtr> Process::sys$mkdir(Userspace<char const*> user_path, size_t path_length, mode_t mode) +ErrorOr<FlatPtr> Process::sys$mkdir(int dirfd, Userspace<char const*> user_path, size_t path_length, mode_t mode) { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::cpath)); auto path = TRY(get_syscall_path_argument(user_path, path_length)); - TRY(VirtualFileSystem::the().mkdir(credentials(), path->view(), mode & ~umask(), current_directory())); + TRY(VirtualFileSystem::the().mkdir(credentials(), path->view(), mode & ~umask(), TRY(custody_for_dirfd(dirfd)))); return 0; } } diff --git a/Userland/Libraries/LibC/stat.cpp b/Userland/Libraries/LibC/stat.cpp index d1ce13ea90..10c95b1d26 100644 --- a/Userland/Libraries/LibC/stat.cpp +++ b/Userland/Libraries/LibC/stat.cpp @@ -24,11 +24,17 @@ mode_t umask(mode_t mask) // https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html int mkdir(char const* pathname, mode_t mode) { + return mkdirat(AT_FDCWD, pathname, mode); +} + +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdirat.html +int mkdirat(int dirfd, char const* pathname, mode_t mode) +{ if (!pathname) { errno = EFAULT; return -1; } - int rc = syscall(SC_mkdir, pathname, strlen(pathname), mode); + int rc = syscall(SC_mkdir, dirfd, pathname, strlen(pathname), mode); __RETURN_WITH_ERRNO(rc, rc, -1); } diff --git a/Userland/Libraries/LibC/sys/stat.h b/Userland/Libraries/LibC/sys/stat.h index 16b8a2c2e8..e9a4e9b030 100644 --- a/Userland/Libraries/LibC/sys/stat.h +++ b/Userland/Libraries/LibC/sys/stat.h @@ -18,6 +18,7 @@ int chmod(char const* pathname, mode_t); int fchmodat(int fd, char const* path, mode_t mode, int flag); int fchmod(int fd, mode_t); int mkdir(char const* pathname, mode_t); +int mkdirat(int dirfd, char const* pathname, mode_t); int mkfifo(char const* pathname, mode_t); int fstat(int fd, struct stat* statbuf); int lstat(char const* path, struct stat* statbuf); diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index e4576c4f63..11c8ea9b02 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -857,7 +857,7 @@ ErrorOr<void> mkdir(StringView path, mode_t mode) if (path.is_null()) return Error::from_errno(EFAULT); #ifdef AK_OS_SERENITY - int rc = syscall(SC_mkdir, path.characters_without_null_termination(), path.length(), mode); + int rc = syscall(SC_mkdir, AT_FDCWD, path.characters_without_null_termination(), path.length(), mode); HANDLE_SYSCALL_RETURN_VALUE("mkdir", rc, {}); #else DeprecatedString path_string = path; |