mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
Ext2FS: Shrink Ext2FSDirectoryEntry from 16 to 12 bytes
The way we read/write directories is very inefficient, and this doesn't solve any of that. It does however reduce memory usage of directory entry vectors by 25% which has nice immediate benefits.
This commit is contained in:
parent
cef73f2010
commit
a280cdf9ba
2 changed files with 9 additions and 8 deletions
|
@ -46,7 +46,7 @@ static const ssize_t max_inline_symlink_length = 60;
|
||||||
|
|
||||||
struct Ext2FSDirectoryEntry {
|
struct Ext2FSDirectoryEntry {
|
||||||
String name;
|
String name;
|
||||||
InodeIdentifier inode;
|
Ext2FS::InodeIndex inode_index { 0 };
|
||||||
u8 file_type { 0 };
|
u8 file_type { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1020,7 +1020,7 @@ KResult Ext2FSInode::write_directory(const Vector<Ext2FSDirectoryEntry>& entries
|
||||||
dbgln("* Inode: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry.inode.index(), u16(entry.name.length()), u16(record_length), u8(entry.file_type), entry.name);
|
dbgln("* Inode: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry.inode.index(), u16(entry.name.length()), u16(record_length), u8(entry.file_type), entry.name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
stream << u32(entry.inode.index());
|
stream << u32(entry.inode_index);
|
||||||
stream << u16(record_length);
|
stream << u16(record_length);
|
||||||
stream << u8(entry.name.length());
|
stream << u8(entry.name.length());
|
||||||
stream << u8(entry.file_type);
|
stream << u8(entry.file_type);
|
||||||
|
@ -1069,7 +1069,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
|
||||||
name_already_exists = true;
|
name_already_exists = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
entries.append({ entry.name, entry.inode, entry.file_type });
|
entries.append({ entry.name, entry.inode.index(), entry.file_type });
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1085,7 +1085,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
entries.empend(name, child.identifier(), to_ext2_file_type(mode));
|
entries.empend(name, child.index(), to_ext2_file_type(mode));
|
||||||
result = write_directory(entries);
|
result = write_directory(entries);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
|
@ -1117,7 +1117,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
|
||||||
Vector<Ext2FSDirectoryEntry> entries;
|
Vector<Ext2FSDirectoryEntry> entries;
|
||||||
KResult result = traverse_as_directory([&](auto& entry) {
|
KResult result = traverse_as_directory([&](auto& entry) {
|
||||||
if (name != entry.name)
|
if (name != entry.name)
|
||||||
entries.append({ entry.name, entry.inode, entry.file_type });
|
entries.append({ entry.name, entry.inode.index(), entry.file_type });
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
|
@ -1444,8 +1444,8 @@ KResult Ext2FS::create_directory(Ext2FSInode& parent_inode, const String& name,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Vector<Ext2FSDirectoryEntry> entries;
|
Vector<Ext2FSDirectoryEntry> entries;
|
||||||
entries.empend(".", inode->identifier(), static_cast<u8>(EXT2_FT_DIR));
|
entries.empend(".", inode->index(), static_cast<u8>(EXT2_FT_DIR));
|
||||||
entries.empend("..", parent_inode.identifier(), static_cast<u8>(EXT2_FT_DIR));
|
entries.empend("..", parent_inode.index(), static_cast<u8>(EXT2_FT_DIR));
|
||||||
|
|
||||||
auto result = static_cast<Ext2FSInode&>(*inode).write_directory(entries);
|
auto result = static_cast<Ext2FSInode&>(*inode).write_directory(entries);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
|
|
|
@ -98,6 +98,8 @@ class Ext2FS final : public BlockBasedFS {
|
||||||
friend class Ext2FSInode;
|
friend class Ext2FSInode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using InodeIndex = u32;
|
||||||
|
|
||||||
static NonnullRefPtr<Ext2FS> create(FileDescription&);
|
static NonnullRefPtr<Ext2FS> create(FileDescription&);
|
||||||
|
|
||||||
virtual ~Ext2FS() override;
|
virtual ~Ext2FS() override;
|
||||||
|
@ -117,7 +119,6 @@ public:
|
||||||
private:
|
private:
|
||||||
typedef unsigned BlockIndex;
|
typedef unsigned BlockIndex;
|
||||||
typedef unsigned GroupIndex;
|
typedef unsigned GroupIndex;
|
||||||
typedef unsigned InodeIndex;
|
|
||||||
explicit Ext2FS(FileDescription&);
|
explicit Ext2FS(FileDescription&);
|
||||||
|
|
||||||
const ext2_super_block& super_block() const { return m_super_block; }
|
const ext2_super_block& super_block() const { return m_super_block; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue