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
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b54a7f3a80
commit
354ffd033c
@ -28,6 +28,8 @@ namespace VFS
|
||||
|
||||
virtual Result<void> truncate(usize size) = 0;
|
||||
|
||||
virtual usize size() = 0;
|
||||
|
||||
// Generic methods
|
||||
virtual FileSystem& fs() const = 0;
|
||||
|
||||
|
@ -129,4 +129,9 @@ namespace TmpFS
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
usize FileInode::size()
|
||||
{
|
||||
return m_data_buffer.size();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user