kernel/ext2: Allow reading up to 4 MB of data from files
This is done by scanning the singly indirect pointer of the inode.
This commit is contained in:
parent
00d625a697
commit
fe7a03e43b
@ -28,7 +28,7 @@ namespace Ext2
|
||||
if (offset % block_size)
|
||||
{
|
||||
usize block_offset = (offset % block_size);
|
||||
usize block = find_block(offset / block_size);
|
||||
usize block = TRY(find_block(offset / block_size));
|
||||
usize size_to_read = block_size - block_offset;
|
||||
if (size_to_read > to_read) size_to_read = to_read;
|
||||
|
||||
@ -44,7 +44,7 @@ namespace Ext2
|
||||
|
||||
while (to_read >= block_size)
|
||||
{
|
||||
usize block = find_block(offset / block_size);
|
||||
usize block = TRY(find_block(offset / block_size));
|
||||
|
||||
usize host_offset = block * block_size;
|
||||
|
||||
@ -58,7 +58,7 @@ namespace Ext2
|
||||
|
||||
if (to_read > 0)
|
||||
{
|
||||
usize block = find_block(offset / block_size);
|
||||
usize block = TRY(find_block(offset / block_size));
|
||||
|
||||
usize host_offset = block * block_size;
|
||||
|
||||
@ -69,11 +69,26 @@ namespace Ext2
|
||||
return length;
|
||||
}
|
||||
|
||||
usize Inode::find_block(usize index) const
|
||||
Result<usize> Inode::find_block(usize index) const
|
||||
{
|
||||
expect(index < 12, "ext2: Finding blocks in the indirect pointers is not yet supported");
|
||||
if (index < 12) return m_raw_inode.direct_pointers[index];
|
||||
|
||||
return m_raw_inode.direct_pointers[index];
|
||||
usize block_index = (index - 12) * sizeof(u32);
|
||||
if (block_index >= m_fs->m_block_size)
|
||||
{
|
||||
fail("ext2: Finding blocks beyond the singly indirect pointer block is not yet supported");
|
||||
}
|
||||
|
||||
usize block_size = m_fs->m_block_size;
|
||||
|
||||
if (m_singly_indirect_block.is_empty())
|
||||
{
|
||||
TRY(m_singly_indirect_block.try_resize(block_size));
|
||||
TRY(m_fs->m_host_device->read(m_singly_indirect_block.data(), m_raw_inode.singly_indirect_ptr * block_size,
|
||||
block_size));
|
||||
}
|
||||
|
||||
return *reinterpret_cast<u32*>(&m_singly_indirect_block.data()[block_index]);
|
||||
}
|
||||
|
||||
Result<void> Inode::lazy_initialize_dir() const
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "fs/ext2/FileSystem.h"
|
||||
#include <luna/Buffer.h>
|
||||
#include <luna/String.h>
|
||||
|
||||
#define EXT2_FIFO 0x1000
|
||||
@ -141,12 +142,14 @@ namespace Ext2
|
||||
FileSystem* m_fs;
|
||||
ino_t m_inum;
|
||||
|
||||
mutable Buffer m_singly_indirect_block;
|
||||
|
||||
String m_link;
|
||||
|
||||
mutable Vector<VFS::DirectoryEntry> m_entries;
|
||||
mutable bool m_dir_already_lazily_initialized { false };
|
||||
|
||||
usize find_block(usize index) const;
|
||||
Result<usize> find_block(usize index) const;
|
||||
|
||||
friend class FileSystem;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user