mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
Kernel+LibC+LibCore+UE: Implement fchmodat(2)
This function is an extended version of `chmod(2)` that lets one control whether to dereference symlinks, and specify a file descriptor to a directory that will be used as the base for relative paths.
This commit is contained in:
parent
5f71925aa4
commit
182016d7c0
10 changed files with 64 additions and 14 deletions
|
@ -478,6 +478,13 @@ struct SC_statvfs_params {
|
|||
struct statvfs* buf;
|
||||
};
|
||||
|
||||
struct SC_chmod_params {
|
||||
int dirfd;
|
||||
StringArgument path;
|
||||
u16 mode;
|
||||
int follow_symlinks;
|
||||
};
|
||||
|
||||
void initialize();
|
||||
int sync();
|
||||
|
||||
|
|
|
@ -434,9 +434,9 @@ ErrorOr<void> VirtualFileSystem::chmod(Custody& custody, mode_t mode)
|
|||
return inode.chmod(mode);
|
||||
}
|
||||
|
||||
ErrorOr<void> VirtualFileSystem::chmod(StringView path, mode_t mode, Custody& base)
|
||||
ErrorOr<void> VirtualFileSystem::chmod(StringView path, mode_t mode, Custody& base, int options)
|
||||
{
|
||||
auto custody = TRY(resolve_path(path, base));
|
||||
auto custody = TRY(resolve_path(path, base, nullptr, options));
|
||||
return chmod(custody, mode);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
ErrorOr<void> unlink(StringView path, Custody& base);
|
||||
ErrorOr<void> symlink(StringView target, StringView linkpath, Custody& base);
|
||||
ErrorOr<void> rmdir(StringView path, Custody& base);
|
||||
ErrorOr<void> chmod(StringView path, mode_t, Custody& base);
|
||||
ErrorOr<void> chmod(StringView path, mode_t, Custody& base, int options = 0);
|
||||
ErrorOr<void> chmod(Custody&, mode_t);
|
||||
ErrorOr<void> chown(StringView path, UserID, GroupID, Custody& base, int options);
|
||||
ErrorOr<void> chown(Custody&, UserID, GroupID);
|
||||
|
|
|
@ -359,7 +359,7 @@ public:
|
|||
ErrorOr<FlatPtr> sys$rmdir(Userspace<const char*> pathname, size_t path_length);
|
||||
ErrorOr<FlatPtr> sys$mount(Userspace<const Syscall::SC_mount_params*>);
|
||||
ErrorOr<FlatPtr> sys$umount(Userspace<const char*> mountpoint, size_t mountpoint_length);
|
||||
ErrorOr<FlatPtr> sys$chmod(Userspace<const char*> pathname, size_t path_length, mode_t);
|
||||
ErrorOr<FlatPtr> sys$chmod(Userspace<Syscall::SC_chmod_params const*>);
|
||||
ErrorOr<FlatPtr> sys$fchmod(int fd, mode_t);
|
||||
ErrorOr<FlatPtr> sys$chown(Userspace<const Syscall::SC_chown_params*>);
|
||||
ErrorOr<FlatPtr> sys$fchown(int fd, UserID, GroupID);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Daniel Bertalan <dani@danielbertalan.dev>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -10,12 +11,24 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t path_length, mode_t mode)
|
||||
ErrorOr<FlatPtr> Process::sys$chmod(Userspace<Syscall::SC_chmod_params const*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||
TRY(require_promise(Pledge::fattr));
|
||||
auto path = TRY(get_syscall_path_argument(user_path, path_length));
|
||||
TRY(VirtualFileSystem::the().chmod(path->view(), mode, current_directory()));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
auto path = TRY(get_syscall_path_argument(params.path));
|
||||
|
||||
RefPtr<Custody> base;
|
||||
if (params.dirfd == AT_FDCWD) {
|
||||
base = current_directory();
|
||||
} else {
|
||||
auto base_description = TRY(fds().open_file_description(params.dirfd));
|
||||
if (!base_description->custody())
|
||||
return EINVAL;
|
||||
base = base_description->custody();
|
||||
}
|
||||
|
||||
TRY(VirtualFileSystem::the().chmod(path->view(), params.mode, *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue