mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
Kernel: Use TRY() in sys$open()
This commit is contained in:
parent
b01e4b171d
commit
4483110990
1 changed files with 6 additions and 14 deletions
|
@ -39,16 +39,11 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
|
||||||
// Ignore everything except permission bits.
|
// Ignore everything except permission bits.
|
||||||
mode &= 0777;
|
mode &= 0777;
|
||||||
|
|
||||||
auto path = get_syscall_path_argument(params.path);
|
auto path = TRY(get_syscall_path_argument(params.path));
|
||||||
if (path.is_error())
|
|
||||||
return path.error();
|
|
||||||
|
|
||||||
dbgln_if(IO_DEBUG, "sys$open(dirfd={}, path='{}', options={}, mode={})", dirfd, path.value()->view(), options, mode);
|
dbgln_if(IO_DEBUG, "sys$open(dirfd={}, path='{}', options={}, mode={})", dirfd, path->view(), options, mode);
|
||||||
|
|
||||||
auto fd_or_error = m_fds.allocate();
|
auto fd_allocation = TRY(m_fds.allocate());
|
||||||
if (fd_or_error.is_error())
|
|
||||||
return fd_or_error.error();
|
|
||||||
auto new_fd = fd_or_error.release_value();
|
|
||||||
RefPtr<Custody> base;
|
RefPtr<Custody> base;
|
||||||
if (dirfd == AT_FDCWD) {
|
if (dirfd == AT_FDCWD) {
|
||||||
base = current_directory();
|
base = current_directory();
|
||||||
|
@ -63,17 +58,14 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
|
||||||
base = base_description->custody();
|
base = base_description->custody();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = VirtualFileSystem::the().open(path.value()->view(), options, mode & ~umask(), *base);
|
auto description = TRY(VirtualFileSystem::the().open(path->view(), options, mode & ~umask(), *base));
|
||||||
if (result.is_error())
|
|
||||||
return result.error();
|
|
||||||
auto description = result.value();
|
|
||||||
|
|
||||||
if (description->inode() && description->inode()->socket())
|
if (description->inode() && description->inode()->socket())
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
|
|
||||||
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||||
m_fds[new_fd.fd].set(move(description), fd_flags);
|
m_fds[fd_allocation.fd].set(move(description), fd_flags);
|
||||||
return new_fd.fd;
|
return fd_allocation.fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<FlatPtr> Process::sys$close(int fd)
|
KResultOr<FlatPtr> Process::sys$close(int fd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue