Kernel+LibC+LibCore: Implement mknodat(2)
This commit is contained in:
parent
05cf1327ed
commit
4574a8c334
Notes:
sideshowbarker
2024-07-17 00:25:35 +09:00
Author: https://github.com/implicitfield Commit: https://github.com/SerenityOS/serenity/commit/4574a8c334 Pull-request: https://github.com/SerenityOS/serenity/pull/23099 Reviewed-by: https://github.com/timschumi ✅
5 changed files with 11 additions and 3 deletions
|
@ -417,6 +417,7 @@ struct SC_mknod_params {
|
|||
StringArgument path;
|
||||
u16 mode;
|
||||
dev_t dev;
|
||||
int dirfd;
|
||||
};
|
||||
|
||||
struct SC_symlink_params {
|
||||
|
|
|
@ -20,7 +20,7 @@ ErrorOr<FlatPtr> Process::sys$mknod(Userspace<Syscall::SC_mknod_params const*> u
|
|||
if (!credentials->is_superuser() && !is_regular_file(params.mode) && !is_fifo(params.mode) && !is_socket(params.mode))
|
||||
return EPERM;
|
||||
auto path = TRY(get_syscall_path_argument(params.path));
|
||||
TRY(VirtualFileSystem::the().mknod(credentials, path->view(), params.mode & ~umask(), params.dev, current_directory()));
|
||||
TRY(VirtualFileSystem::the().mknod(credentials, path->view(), params.mode & ~umask(), params.dev, TRY(custody_for_dirfd(params.dirfd))));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -828,12 +828,18 @@ int faccessat(int dirfd, char const* pathname, int mode, int flags)
|
|||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html
|
||||
int mknod(char const* pathname, mode_t mode, dev_t dev)
|
||||
{
|
||||
return mknodat(AT_FDCWD, pathname, mode, dev);
|
||||
}
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknodat.html
|
||||
int mknodat(int dirfd, char const* pathname, mode_t mode, dev_t dev)
|
||||
{
|
||||
if (!pathname) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
Syscall::SC_mknod_params params { { pathname, strlen(pathname) }, mode, dev };
|
||||
Syscall::SC_mknod_params params { { pathname, strlen(pathname) }, mode, dev, dirfd };
|
||||
int rc = syscall(SC_mknod, ¶ms);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ int access(char const* pathname, int mode);
|
|||
int faccessat(int dirfd, char const* pathname, int mode, int flags);
|
||||
int isatty(int fd);
|
||||
int mknod(char const* pathname, mode_t, dev_t);
|
||||
int mknodat(int dirfd, char const* pathname, mode_t, dev_t);
|
||||
long fpathconf(int fd, int name);
|
||||
long pathconf(char const* path, int name);
|
||||
char* getlogin(void);
|
||||
|
|
|
@ -1622,7 +1622,7 @@ ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev)
|
|||
return Error::from_syscall("mknod"sv, -EFAULT);
|
||||
|
||||
#ifdef AK_OS_SERENITY
|
||||
Syscall::SC_mknod_params params { { pathname.characters_without_null_termination(), pathname.length() }, mode, dev };
|
||||
Syscall::SC_mknod_params params { { pathname.characters_without_null_termination(), pathname.length() }, mode, dev, AT_FDCWD };
|
||||
int rc = syscall(SC_mknod, ¶ms);
|
||||
HANDLE_SYSCALL_RETURN_VALUE("mknod", rc, {});
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue