kernel/ext2: Implement Inode::read()
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
62ac42ffc3
commit
765df906fb
@ -81,6 +81,8 @@ namespace Ext2
|
|||||||
static_assert(sizeof(BlockGroupDescriptor) == 32);
|
static_assert(sizeof(BlockGroupDescriptor) == 32);
|
||||||
static_assert(sizeof(RawInode) == 128);
|
static_assert(sizeof(RawInode) == 128);
|
||||||
|
|
||||||
|
class Inode;
|
||||||
|
|
||||||
class FileSystem : public VFS::FileSystem
|
class FileSystem : public VFS::FileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -149,5 +151,7 @@ namespace Ext2
|
|||||||
HashMap<ino_t, SharedPtr<VFS::Inode>> m_inode_cache;
|
HashMap<ino_t, SharedPtr<VFS::Inode>> m_inode_cache;
|
||||||
|
|
||||||
HashMap<u32, BlockGroupDescriptor> m_block_group_descriptor_cache;
|
HashMap<u32, BlockGroupDescriptor> m_block_group_descriptor_cache;
|
||||||
|
|
||||||
|
friend class Inode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,64 @@ namespace Ext2
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<usize> Inode::read(u8* /*buf*/, usize /*offset*/, usize /*length*/) const
|
Result<usize> Inode::read(u8* buf, usize offset, usize length) const
|
||||||
{
|
{
|
||||||
fail("FIXME: Ext2::Inode::read()");
|
if (length == 0) return 0;
|
||||||
|
|
||||||
|
if (offset > size()) return 0;
|
||||||
|
if (offset + length > size()) length = size() - offset;
|
||||||
|
|
||||||
|
const usize block_size = m_fs->m_block_size;
|
||||||
|
|
||||||
|
usize to_read = length;
|
||||||
|
|
||||||
|
if (offset % block_size)
|
||||||
|
{
|
||||||
|
usize block_offset = (offset % block_size);
|
||||||
|
usize block = find_block(offset / block_size);
|
||||||
|
usize size_to_read = block_size - block_offset;
|
||||||
|
|
||||||
|
usize host_offset = (block * block_size) + block_offset;
|
||||||
|
|
||||||
|
// FIXME: Cache this data.
|
||||||
|
TRY(m_fs->m_host_device->read(buf, host_offset, size_to_read));
|
||||||
|
|
||||||
|
to_read -= size_to_read;
|
||||||
|
buf += size_to_read;
|
||||||
|
offset += size_to_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (to_read >= block_size)
|
||||||
|
{
|
||||||
|
usize block = find_block(offset / block_size);
|
||||||
|
|
||||||
|
usize host_offset = block * block_size;
|
||||||
|
|
||||||
|
// FIXME: Cache this data.
|
||||||
|
TRY(m_fs->m_host_device->read(buf, host_offset, block_size));
|
||||||
|
|
||||||
|
to_read -= block_size;
|
||||||
|
buf += block_size;
|
||||||
|
offset += block_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to_read > 0)
|
||||||
|
{
|
||||||
|
usize block = find_block(offset / block_size);
|
||||||
|
|
||||||
|
usize host_offset = block * block_size;
|
||||||
|
|
||||||
|
// FIXME: Cache this data.
|
||||||
|
TRY(m_fs->m_host_device->read(buf, host_offset, to_read));
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
usize Inode::find_block(usize index) const
|
||||||
|
{
|
||||||
|
expect(index < 12, "ext2: Finding blocks in the indirect pointers is not yet supported");
|
||||||
|
|
||||||
|
return m_raw_inode.direct_pointers[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,8 @@ namespace Ext2
|
|||||||
FileSystem* m_fs;
|
FileSystem* m_fs;
|
||||||
ino_t m_inum;
|
ino_t m_inum;
|
||||||
|
|
||||||
|
usize find_block(usize index) const;
|
||||||
|
|
||||||
friend class FileSystem;
|
friend class FileSystem;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user