Compare commits
72 Commits
26623f8a0d
...
3a13017ede
Author | SHA1 | Date | |
---|---|---|---|
3a13017ede | |||
4a85f03d02 | |||
fb40f5c9b2 | |||
47db5da419 | |||
64e8f30f02 | |||
b5b90f13f7 | |||
562cbb3cc3 | |||
903e363254 | |||
248aedee72 | |||
46c67c1e7f | |||
c20e4bad05 | |||
241e11de0d | |||
99f1263fba | |||
1550c1ffc5 | |||
bab456591e | |||
6fec9aa158 | |||
dc1d8a9b38 | |||
c8cfee514e | |||
c161a86893 | |||
3af8301dec | |||
496715c3a6 | |||
3c93266dd8 | |||
a022dd2d07 | |||
3072641362 | |||
93a5826b5b | |||
6116f57876 | |||
344f299bd7 | |||
bc22430ec5 | |||
b39a6f5c00 | |||
e12a02d63f | |||
8fa4bb854b | |||
ff9be2f4e7 | |||
4d7db20d6f | |||
306966183e | |||
01b74c0a8c | |||
af18824f29 | |||
a23f0b93d2 | |||
77d33ca737 | |||
4dae2c8571 | |||
9a9e9a7efe | |||
d3a4054e5b | |||
a3979caf2e | |||
8c4fbdb30d | |||
70fed7e27f | |||
f26ba66801 | |||
15b5b5cc4d | |||
1281989a8a | |||
95c5eeeb0d | |||
f0265a347d | |||
328aa16656 | |||
3cdc8e818a | |||
d49f59500b | |||
bb2fe8a9d7 | |||
be54a2e663 | |||
857d0011b3 | |||
7bb7f63587 | |||
99148870fc | |||
a5089ab9ee | |||
ff03cc189c | |||
2dc9236aaf | |||
a08dbbc33f | |||
670d8d9445 | |||
9c35a0acde | |||
a1089da945 | |||
da879bc2b4 | |||
54af27ceaa | |||
1fbafe3f3a | |||
9007c40dd7 | |||
d29de852cf | |||
b2e12127f3 | |||
09fab9d96d | |||
c7f4cb4868 |
@ -503,17 +503,11 @@ namespace ATA
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
u8 buf[8];
|
if (m_identify_data.big_lba) m_is_lba48 = true;
|
||||||
memcpy(buf, &m_identify_words[100], 8);
|
|
||||||
|
|
||||||
m_block_count = *reinterpret_cast<u64*>(buf);
|
if (m_is_lba48) m_block_count = m_identify_data.sectors_48;
|
||||||
|
else
|
||||||
if (!m_block_count)
|
m_block_count = m_identify_data.sectors_28;
|
||||||
{
|
|
||||||
memcpy(buf, &m_identify_words[60], 4);
|
|
||||||
m_block_count = *reinterpret_cast<u32*>(buf);
|
|
||||||
}
|
|
||||||
else { m_is_lba48 = true; }
|
|
||||||
|
|
||||||
// FIXME: Should we check for CHS?
|
// FIXME: Should we check for CHS?
|
||||||
|
|
||||||
|
@ -7,13 +7,6 @@ namespace Ext2
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<void> Inode::prepare_buffer() const
|
|
||||||
{
|
|
||||||
if (!m_block_buffer.is_empty()) return {};
|
|
||||||
return m_block_buffer.try_resize(m_fs->m_block_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: This code seems awfully similar to BlockDevice::read(). Can this be merged with it in some way?
|
|
||||||
Result<usize> Inode::read(u8* buf, usize offset, usize length) const
|
Result<usize> Inode::read(u8* buf, usize offset, usize length) const
|
||||||
{
|
{
|
||||||
if (length == 0) return 0;
|
if (length == 0) return 0;
|
||||||
@ -73,47 +66,22 @@ namespace Ext2
|
|||||||
{
|
{
|
||||||
if (index < 12) return m_raw_inode.direct_pointers[index];
|
if (index < 12) return m_raw_inode.direct_pointers[index];
|
||||||
|
|
||||||
const usize block_size = m_fs->m_block_size;
|
usize block_index = (index - 12) * sizeof(u32);
|
||||||
const usize blocks_per_indirect_block = block_size / sizeof(u32);
|
if (block_index >= m_fs->m_block_size)
|
||||||
|
|
||||||
index -= 12;
|
|
||||||
|
|
||||||
TRY(prepare_buffer());
|
|
||||||
|
|
||||||
// Singly indirect block
|
|
||||||
if (index < blocks_per_indirect_block)
|
|
||||||
{
|
{
|
||||||
TRY(m_fs->m_host_device->read(m_block_buffer.data(), m_raw_inode.singly_indirect_ptr * block_size,
|
fail("ext2: Finding blocks beyond the singly indirect pointer block is not yet supported");
|
||||||
block_size));
|
|
||||||
return ((u32*)m_block_buffer.data())[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index -= blocks_per_indirect_block;
|
usize block_size = m_fs->m_block_size;
|
||||||
|
|
||||||
// Doubly indirect block
|
if (m_singly_indirect_block.is_empty())
|
||||||
if (index < blocks_per_indirect_block * blocks_per_indirect_block)
|
|
||||||
{
|
{
|
||||||
TRY(m_fs->m_host_device->read(m_block_buffer.data(), m_raw_inode.doubly_indirect_ptr * block_size,
|
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));
|
block_size));
|
||||||
const u32 block = ((u32*)m_block_buffer.data())[index / blocks_per_indirect_block];
|
|
||||||
|
|
||||||
TRY(m_fs->m_host_device->read(m_block_buffer.data(), block * block_size, block_size));
|
|
||||||
return ((u32*)m_block_buffer.data())[index % blocks_per_indirect_block];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index -= blocks_per_indirect_block * blocks_per_indirect_block;
|
return *reinterpret_cast<u32*>(&m_singly_indirect_block.data()[block_index]);
|
||||||
|
|
||||||
check(index < blocks_per_indirect_block * blocks_per_indirect_block * blocks_per_indirect_block);
|
|
||||||
|
|
||||||
// Triply indirect block
|
|
||||||
TRY(m_fs->m_host_device->read(m_block_buffer.data(), m_raw_inode.triply_indirect_ptr * block_size, block_size));
|
|
||||||
u32 block = ((u32*)m_block_buffer.data())[index / (blocks_per_indirect_block * blocks_per_indirect_block)];
|
|
||||||
|
|
||||||
TRY(m_fs->m_host_device->read(m_block_buffer.data(), block * block_size, block_size));
|
|
||||||
block = ((u32*)m_block_buffer.data())[(index / blocks_per_indirect_block) % blocks_per_indirect_block];
|
|
||||||
|
|
||||||
TRY(m_fs->m_host_device->read(m_block_buffer.data(), block * block_size, block_size));
|
|
||||||
return ((u32*)m_block_buffer.data())[index % blocks_per_indirect_block];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<void> Inode::lazy_initialize_dir() const
|
Result<void> Inode::lazy_initialize_dir() const
|
||||||
|
@ -115,7 +115,7 @@ namespace Ext2
|
|||||||
FileSystem* m_fs;
|
FileSystem* m_fs;
|
||||||
ino_t m_inum;
|
ino_t m_inum;
|
||||||
|
|
||||||
mutable Buffer m_block_buffer;
|
mutable Buffer m_singly_indirect_block;
|
||||||
|
|
||||||
String m_link;
|
String m_link;
|
||||||
|
|
||||||
@ -123,7 +123,6 @@ namespace Ext2
|
|||||||
mutable bool m_dir_already_lazily_initialized { false };
|
mutable bool m_dir_already_lazily_initialized { false };
|
||||||
|
|
||||||
Result<usize> find_block(usize index) const;
|
Result<usize> find_block(usize index) const;
|
||||||
Result<void> prepare_buffer() const;
|
|
||||||
|
|
||||||
friend class FileSystem;
|
friend class FileSystem;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user