mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 16:45:08 +00:00
Kernel: Use TRY() in Inode
This commit is contained in:
parent
f20d1f0cc6
commit
b2950c67ea
1 changed files with 7 additions and 21 deletions
|
@ -49,15 +49,11 @@ KResultOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(FileDescription* descriptio
|
||||||
{
|
{
|
||||||
KBufferBuilder builder;
|
KBufferBuilder builder;
|
||||||
|
|
||||||
size_t nread;
|
|
||||||
u8 buffer[4096];
|
u8 buffer[4096];
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer);
|
auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer);
|
||||||
auto result = read_bytes(offset, sizeof(buffer), buf, description);
|
auto nread = TRY(read_bytes(offset, sizeof(buffer), buf, description));
|
||||||
if (result.is_error())
|
|
||||||
return result.error();
|
|
||||||
nread = result.value();
|
|
||||||
VERIFY(nread <= sizeof(buffer));
|
VERIFY(nread <= sizeof(buffer));
|
||||||
if (nread == 0)
|
if (nread == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -78,11 +74,7 @@ KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<C
|
||||||
// The default implementation simply treats the stored
|
// The default implementation simply treats the stored
|
||||||
// contents as a path and resolves that. That is, it
|
// contents as a path and resolves that. That is, it
|
||||||
// behaves exactly how you would expect a symlink to work.
|
// behaves exactly how you would expect a symlink to work.
|
||||||
auto contents_or = read_entire();
|
auto contents = TRY(read_entire());
|
||||||
if (contents_or.is_error())
|
|
||||||
return contents_or.error();
|
|
||||||
|
|
||||||
auto& contents = contents_or.value();
|
|
||||||
auto path = StringView(contents->data(), contents->size());
|
auto path = StringView(contents->data(), contents->size());
|
||||||
return VirtualFileSystem::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
|
return VirtualFileSystem::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
|
||||||
}
|
}
|
||||||
|
@ -324,19 +316,15 @@ KResult Inode::can_apply_flock(FileDescription const& description, flock const&
|
||||||
|
|
||||||
KResult Inode::apply_flock(Process const& process, FileDescription const& description, Userspace<flock const*> input_lock)
|
KResult Inode::apply_flock(Process const& process, FileDescription const& description, Userspace<flock const*> input_lock)
|
||||||
{
|
{
|
||||||
flock new_lock;
|
flock new_lock = {};
|
||||||
if (!copy_from_user(&new_lock, input_lock))
|
if (!copy_from_user(&new_lock, input_lock))
|
||||||
return EFAULT;
|
return EFAULT;
|
||||||
|
|
||||||
auto rc = normalize_flock(description, new_lock);
|
TRY(normalize_flock(description, new_lock));
|
||||||
if (rc.is_error())
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
MutexLocker locker(m_inode_lock);
|
MutexLocker locker(m_inode_lock);
|
||||||
|
|
||||||
rc = can_apply_flock(description, new_lock);
|
TRY(can_apply_flock(description, new_lock));
|
||||||
if (rc.is_error())
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
if (new_lock.l_type == F_UNLCK) {
|
if (new_lock.l_type == F_UNLCK) {
|
||||||
for (size_t i = 0; i < m_flocks.size(); ++i) {
|
for (size_t i = 0; i < m_flocks.size(); ++i) {
|
||||||
|
@ -354,13 +342,11 @@ KResult Inode::apply_flock(Process const& process, FileDescription const& descri
|
||||||
|
|
||||||
KResult Inode::get_flock(FileDescription const& description, Userspace<flock*> reference_lock) const
|
KResult Inode::get_flock(FileDescription const& description, Userspace<flock*> reference_lock) const
|
||||||
{
|
{
|
||||||
flock lookup;
|
flock lookup = {};
|
||||||
if (!copy_from_user(&lookup, reference_lock))
|
if (!copy_from_user(&lookup, reference_lock))
|
||||||
return EFAULT;
|
return EFAULT;
|
||||||
|
|
||||||
auto rc = normalize_flock(description, lookup);
|
TRY(normalize_flock(description, lookup));
|
||||||
if (rc.is_error())
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
|
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue