summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-18 18:01:42 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-18 18:26:54 +0200
commit6ad2d31952db5d4b06157deec0d19250d35992e8 (patch)
tree797d67ac071081f0d11061c93bda8355d5ce233b /Kernel
parent108263314af7198c2751c0db098f613e4718751a (diff)
downloadserenity-6ad2d31952db5d4b06157deec0d19250d35992e8.zip
Ext2FS: Stop using FS::DirectoryEntry
We were only using this as a temporary helper object while constructing directories. Create a simpler Ext2FSDirectoryEntry instead for this.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp28
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.h3
2 files changed, 19 insertions, 12 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 08e04e153a..ce9dd8e58e 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -45,6 +45,12 @@ static const size_t max_link_count = 65535;
static const size_t max_block_size = 4096;
static const ssize_t max_inline_symlink_length = 60;
+struct Ext2FSDirectoryEntry {
+ String name;
+ InodeIdentifier inode;
+ u8 file_type { 0 };
+};
+
static u8 to_ext2_file_type(mode_t mode)
{
if (is_regular_file(mode))
@@ -880,13 +886,13 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntr
return KSuccess;
}
-bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
+bool Ext2FSInode::write_directory(const Vector<Ext2FSDirectoryEntry>& entries)
{
LOCKER(m_lock);
int directory_size = 0;
for (auto& entry : entries)
- directory_size += EXT2_DIR_REC_LEN(entry.name_length);
+ directory_size += EXT2_DIR_REC_LEN(entry.name.length());
auto block_size = fs().block_size();
@@ -903,7 +909,7 @@ bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
for (size_t i = 0; i < entries.size(); ++i) {
auto& entry = entries[i];
- int record_length = EXT2_DIR_REC_LEN(entry.name_length);
+ int record_length = EXT2_DIR_REC_LEN(entry.name.length());
if (i == entries.size() - 1)
record_length += occupied_size - directory_size;
@@ -917,11 +923,11 @@ bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
stream << u32(entry.inode.index());
stream << u16(record_length);
- stream << u8(entry.name_length);
+ stream << u8(entry.name.length());
stream << u8(entry.file_type);
stream << entry.name;
- int padding = record_length - entry.name_length - 8;
+ int padding = record_length - entry.name.length() - 8;
for (int j = 0; j < padding; ++j)
stream << u8(0);
}
@@ -954,14 +960,14 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
dbg() << "Ext2FSInode::add_child(): Adding inode " << child.index() << " with name '" << name << "' and mode " << mode << " to directory " << index();
#endif
- Vector<FS::DirectoryEntry> entries;
+ Vector<Ext2FSDirectoryEntry> entries;
bool name_already_exists = false;
KResult result = traverse_as_directory([&](auto& entry) {
if (name == entry.name) {
name_already_exists = true;
return false;
}
- entries.append({ entry.name.characters_without_null_termination(), entry.name.length(), entry.inode, entry.file_type });
+ entries.append({ entry.name, entry.inode, entry.file_type });
return true;
});
@@ -977,7 +983,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
if (result.is_error())
return result;
- entries.empend(name.characters_without_null_termination(), name.length(), child.identifier(), to_ext2_file_type(mode));
+ entries.empend(name, child.identifier(), to_ext2_file_type(mode));
bool success = write_directory(entries);
if (success)
m_lookup_cache.set(name, child.index());
@@ -1005,10 +1011,10 @@ KResult Ext2FSInode::remove_child(const StringView& name)
dbg() << "Ext2FSInode::remove_child(): Removing '" << name << "' in directory " << index();
#endif
- Vector<FS::DirectoryEntry> entries;
+ Vector<Ext2FSDirectoryEntry> entries;
KResult result = traverse_as_directory([&](auto& entry) {
if (name != entry.name)
- entries.append({ entry.name.characters_without_null_termination(), entry.name.length(), entry.inode, entry.file_type });
+ entries.append({ entry.name, entry.inode, entry.file_type });
return true;
});
if (result.is_error())
@@ -1364,7 +1370,7 @@ KResult Ext2FS::create_directory(InodeIdentifier parent_id, const String& name,
dbg() << "Ext2FS: create_directory: created new directory named '" << name << "' with inode " << inode->identifier();
#endif
- Vector<DirectoryEntry> entries;
+ Vector<Ext2FSDirectoryEntry> entries;
entries.empend(".", inode->identifier(), EXT2_FT_DIR);
entries.empend("..", parent_id, EXT2_FT_DIR);
diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h
index 5790e380c4..3de9029676 100644
--- a/Kernel/FileSystem/Ext2FileSystem.h
+++ b/Kernel/FileSystem/Ext2FileSystem.h
@@ -41,6 +41,7 @@ struct ext2_super_block;
namespace Kernel {
class Ext2FS;
+struct Ext2FSDirectoryEntry;
class Ext2FSInode final : public Inode {
friend class Ext2FS;
@@ -76,7 +77,7 @@ private:
virtual KResult chown(uid_t, gid_t) override;
virtual KResult truncate(u64) override;
- bool write_directory(const Vector<FS::DirectoryEntry>&);
+ bool write_directory(const Vector<Ext2FSDirectoryEntry>&);
void populate_lookup_cache() const;
KResult resize(u64);