Kernel+LibC+LibCore: Implement mknodat(2)

This commit is contained in:
implicitfield 2024-04-29 21:01:08 +04:00 committed by Tim Schumacher
parent 05cf1327ed
commit 4574a8c334
5 changed files with 11 additions and 3 deletions

View file

@ -417,6 +417,7 @@ struct SC_mknod_params {
StringArgument path;
u16 mode;
dev_t dev;
int dirfd;
};
struct SC_symlink_params {

View file

@ -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;
}

View file

@ -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, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}

View file

@ -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);

View file

@ -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, &params);
HANDLE_SYSCALL_RETURN_VALUE("mknod", rc, {});
#else