1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:38:13 +00:00

Kernel+LibC+LibCore: Implement renameat(2)

Now with the ability to specify different bases for the old and new
paths.
This commit is contained in:
sin-ack 2022-10-01 11:42:25 +00:00 committed by Andrew Kaster
parent eb5389e933
commit d5fbdf1866
7 changed files with 17 additions and 6 deletions

View file

@ -418,7 +418,9 @@ struct SC_symlink_params {
};
struct SC_rename_params {
int olddirfd;
StringArgument old_path;
int newdirfd;
StringArgument new_path;
};

View file

@ -577,14 +577,14 @@ ErrorOr<void> VirtualFileSystem::chmod(Credentials const& credentials, StringVie
return chmod(credentials, custody, mode);
}
ErrorOr<void> VirtualFileSystem::rename(Credentials const& credentials, StringView old_path, StringView new_path, Custody& base)
ErrorOr<void> VirtualFileSystem::rename(Credentials const& credentials, Custody& old_base, StringView old_path, Custody& new_base, StringView new_path)
{
RefPtr<Custody> old_parent_custody;
auto old_custody = TRY(resolve_path(credentials, old_path, base, &old_parent_custody, O_NOFOLLOW_NOERROR));
auto old_custody = TRY(resolve_path(credentials, old_path, old_base, &old_parent_custody, O_NOFOLLOW_NOERROR));
auto& old_inode = old_custody->inode();
RefPtr<Custody> new_parent_custody;
auto new_custody_or_error = resolve_path(credentials, new_path, base, &new_parent_custody);
auto new_custody_or_error = resolve_path(credentials, new_path, new_base, &new_parent_custody);
if (new_custody_or_error.is_error()) {
if (new_custody_or_error.error().code() != ENOENT || !new_parent_custody)
return new_custody_or_error.release_error();

View file

@ -67,7 +67,7 @@ public:
ErrorOr<InodeMetadata> lookup_metadata(Credentials const&, StringView path, Custody& base, int options = 0);
ErrorOr<void> utime(Credentials const&, StringView path, Custody& base, time_t atime, time_t mtime);
ErrorOr<void> utimensat(Credentials const&, StringView path, Custody& base, timespec const& atime, timespec const& mtime, int options = 0);
ErrorOr<void> rename(Credentials const&, StringView oldpath, StringView newpath, Custody& base);
ErrorOr<void> rename(Credentials const&, Custody& old_base, StringView oldpath, Custody& new_base, StringView newpath);
ErrorOr<void> mknod(Credentials const&, StringView path, mode_t, dev_t, Custody& base);
ErrorOr<NonnullRefPtr<Custody>> open_directory(Credentials const&, StringView path, Custody& base);

View file

@ -17,7 +17,7 @@ ErrorOr<FlatPtr> Process::sys$rename(Userspace<Syscall::SC_rename_params const*>
auto params = TRY(copy_typed_from_user(user_params));
auto old_path = TRY(get_syscall_path_argument(params.old_path));
auto new_path = TRY(get_syscall_path_argument(params.new_path));
TRY(VirtualFileSystem::the().rename(credentials(), old_path->view(), new_path->view(), current_directory()));
TRY(VirtualFileSystem::the().rename(credentials(), TRY(custody_for_dirfd(params.olddirfd)), old_path->view(), TRY(custody_for_dirfd(params.newdirfd)), new_path->view()));
return 0;
}