VFS: Add a size() method to inodes to implement seeking to the end of a file
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-12 14:49:21 +01:00
parent b54a7f3a80
commit 354ffd033c
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 16 additions and 2 deletions

View File

@ -28,6 +28,8 @@ namespace VFS
virtual Result<void> truncate(usize size) = 0;
virtual usize size() = 0;
// Generic methods
virtual FileSystem& fs() const = 0;

View File

@ -129,4 +129,9 @@ namespace TmpFS
return {};
}
usize FileInode::size()
{
return m_data_buffer.size();
}
}

View File

@ -65,6 +65,8 @@ namespace TmpFS
Result<void> truncate(usize size) override;
usize size() override;
virtual ~FileInode() = default;
private:
@ -110,6 +112,11 @@ namespace TmpFS
return err(EISDIR);
}
usize size() override
{
return 0;
}
VFS::FileSystem& fs() const override
{
return *m_fs;

View File

@ -42,7 +42,7 @@ Result<u64> sys_write(Registers*, SyscallArgs args)
if (!descriptor.is_writable()) return err(EBADF);
if (descriptor.should_append()) todo();
if (descriptor.should_append()) descriptor.offset = descriptor.inode->size();
usize nwritten = TRY(descriptor.inode->write(buf, descriptor.offset, size));
@ -67,7 +67,7 @@ Result<u64> sys_lseek(Registers*, SyscallArgs args)
{
case SEEK_SET: new_offset = offset; break;
case SEEK_CUR: new_offset = TRY(safe_add((long)descriptor.offset, offset)); break;
case SEEK_END: todo();
case SEEK_END: new_offset = TRY(safe_add((long)descriptor.inode->size(), offset)); break;
default: return err(EINVAL);
}