Kernel/LibC: Implement realpath

realpath is implemented as a syscall. This is not really required but it
was the easiest way to get it working as there is already path
canonicalization at kernel level.
This commit is contained in:
2024-06-25 19:29:08 +03:00
parent 3c57e05a65
commit af4b138094
4 changed files with 36 additions and 0 deletions

View File

@@ -149,6 +149,8 @@ namespace Kernel
BAN::ErrorOr<long> sys_fstatat(int fd, const char* path, struct stat* buf, int flag);
BAN::ErrorOr<long> sys_stat(const char* path, struct stat* buf, int flag);
BAN::ErrorOr<long> sys_realpath(const char* path, char* buffer);
BAN::ErrorOr<long> sys_sync(bool should_block);
static BAN::ErrorOr<long> clean_poweroff(int command);

View File

@@ -1238,6 +1238,22 @@ namespace Kernel
return 0;
}
BAN::ErrorOr<long> Process::sys_realpath(const char* path, char* buffer)
{
LockGuard _(m_process_lock);
TRY(validate_string_access(path));
TRY(validate_pointer_access(buffer, PATH_MAX));
auto absolute_path = TRY(absolute_path_of(path));
auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, O_SEARCH));
if (file.canonical_path.size() >= PATH_MAX)
return BAN::Error::from_errno(ENAMETOOLONG);
strcpy(buffer, file.canonical_path.data());
return file.canonical_path.size();
}
BAN::ErrorOr<long> Process::sys_sync(bool should_block)
{
DevFileSystem::get().initiate_sync(should_block);