1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

Kernel: Improvements to Custody absolute path serialization

- Renamed try_create_absolute_path() => try_serialize_absolute_path()
- Use KResultOr and TRY() to propagate errors
- Don't call this when it's only for debug logging
This commit is contained in:
Andreas Kling 2021-09-06 12:24:36 +02:00
parent f173f73f10
commit cda2b9e71c
6 changed files with 21 additions and 33 deletions

View file

@ -40,14 +40,10 @@ KResultOr<FlatPtr> Process::sys$getcwd(Userspace<char*> buffer, size_t size)
if (size > NumericLimits<ssize_t>::max())
return EINVAL;
auto maybe_path = current_directory().try_create_absolute_path();
if (!maybe_path)
return ENOMEM;
auto& path = *maybe_path;
size_t ideal_size = path.length() + 1;
auto path = TRY(current_directory().try_serialize_absolute_path());
size_t ideal_size = path->length() + 1;
auto size_to_copy = min(ideal_size, size);
TRY(copy_to_user(buffer, path.characters(), size_to_copy));
TRY(copy_to_user(buffer, path->characters(), size_to_copy));
// Note: we return the whole size here, not the copied size.
return ideal_size;
}

View file

@ -19,10 +19,7 @@ KResultOr<FlatPtr> Process::sys$realpath(Userspace<const Syscall::SC_realpath_pa
auto path = TRY(get_syscall_path_argument(params.path));
auto custody = TRY(VirtualFileSystem::the().resolve_path(path->view(), current_directory()));
auto absolute_path = custody->try_create_absolute_path();
if (!absolute_path)
return ENOMEM;
auto absolute_path = TRY(custody->try_serialize_absolute_path());
size_t ideal_size = absolute_path->length() + 1;
auto size_to_copy = min(ideal_size, params.buffer.size);

View file

@ -83,13 +83,9 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
OwnPtr<KString> new_unveiled_path;
auto custody_or_error = VirtualFileSystem::the().resolve_path_without_veil(path->view(), VirtualFileSystem::the().root_custody(), &parent_custody);
if (!custody_or_error.is_error()) {
new_unveiled_path = custody_or_error.value()->try_create_absolute_path();
if (!new_unveiled_path)
return ENOMEM;
new_unveiled_path = TRY(custody_or_error.value()->try_serialize_absolute_path());
} else if (custody_or_error.error() == ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) {
auto parent_custody_path = parent_custody->try_create_absolute_path();
if (!parent_custody_path)
return ENOMEM;
auto parent_custody_path = TRY(parent_custody->try_serialize_absolute_path());
new_unveiled_path = KLexicalPath::try_join(parent_custody_path->view(), KLexicalPath::basename(path->view()));
if (!new_unveiled_path)
return ENOMEM;