Kernel: Add SYS_OPENAT
This commit is contained in:
@@ -58,6 +58,7 @@ namespace Kernel
|
||||
BAN::ErrorOr<void> setenvp(char** envp);
|
||||
|
||||
BAN::ErrorOr<int> open(BAN::StringView, int);
|
||||
BAN::ErrorOr<int> openat(int, BAN::StringView, int);
|
||||
BAN::ErrorOr<void> close(int fd);
|
||||
BAN::ErrorOr<size_t> read(int fd, void* buffer, size_t count);
|
||||
BAN::ErrorOr<size_t> write(int fd, const void* buffer, size_t count);
|
||||
|
||||
@@ -469,6 +469,22 @@ namespace Kernel
|
||||
return fd;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<int> Process::openat(int fd, BAN::StringView path, int flags)
|
||||
{
|
||||
BAN::String absolute_path;
|
||||
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
TRY(validate_fd(fd));
|
||||
TRY(absolute_path.append(open_file_description(fd).path));
|
||||
}
|
||||
|
||||
TRY(absolute_path.push_back('/'));
|
||||
TRY(absolute_path.append(path));
|
||||
|
||||
return open(absolute_path, flags);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Process::close(int fd)
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
||||
@@ -48,6 +48,14 @@ namespace Kernel
|
||||
return -res.error().get_error_code();
|
||||
return res.value();
|
||||
}
|
||||
|
||||
int sys_openat(int fd, const char* path, int oflags)
|
||||
{
|
||||
auto res = Process::current().openat(fd, path, oflags);
|
||||
if (res.is_error())
|
||||
return -res.error().get_error_code();
|
||||
return res.value();
|
||||
}
|
||||
|
||||
long sys_alloc(size_t bytes)
|
||||
{
|
||||
@@ -187,6 +195,9 @@ namespace Kernel
|
||||
case SYS_OPEN:
|
||||
ret = sys_open((const char*)arg1, (int)arg2);
|
||||
break;
|
||||
case SYS_OPENAT:
|
||||
ret = sys_openat((int)arg1, (const char*)arg2, (int)arg3);
|
||||
break;
|
||||
case SYS_ALLOC:
|
||||
ret = sys_alloc((size_t)arg1);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user