diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index 38b6e82b4e..cb4ea0db6d 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -425,35 +425,32 @@ bool Ext2FSInode::traverse_as_directory(Functioni_mode)); + ASSERT(is_directory()); //#ifdef EXT2_DEBUG - dbgprintf("Ext2FS: Adding inode %u with name '%s' to directory %u\n", child, name.characters(), parent); + dbgprintf("Ext2FS: Adding inode %u with name '%s' to directory %u\n", child_id.index(), name.characters(), index()); //#endif - Vector entries; - bool nameAlreadyExists = false; - auto directory = get_inode({ id(), parent }); - directory->traverse_as_directory([&] (auto& entry) { + Vector entries; + bool name_already_exists = false; + traverse_as_directory([&] (auto& entry) { if (!strcmp(entry.name, name.characters())) { - nameAlreadyExists = true; + name_already_exists = true; return false; } entries.append(entry); return true; }); - if (nameAlreadyExists) { - kprintf("Ext2FS: Name '%s' already exists in directory inode %u\n", name.characters(), parent); + if (name_already_exists) { + kprintf("Ext2FS: Name '%s' already exists in directory inode %u\n", name.characters(), index()); error = -EEXIST; return false; } - entries.append({ name.characters(), name.length(), { id(), child }, fileType }); - return write_directory_inode(parent, move(entries)); + entries.append({ name.characters(), name.length(), child_id, file_type }); + return fs().write_directory_inode(index(), move(entries)); } bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector&& entries) @@ -847,23 +844,24 @@ RetainPtr Ext2FS::create_directory(InodeIdentifier parent_id, const Strin return inode; } -RetainPtr Ext2FS::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size, int& error) +RetainPtr Ext2FS::create_inode(InodeIdentifier parent_id, const String& name, Unix::mode_t mode, unsigned size, int& error) { - ASSERT(parentInode.fsid() == id()); + ASSERT(parent_id.fsid() == id()); + auto parent_inode = get_inode(parent_id); - dbgprintf("Ext2FS: Adding inode '%s' (mode %u) to parent directory %u:\n", name.characters(), mode, parentInode.index()); + dbgprintf("Ext2FS: Adding inode '%s' (mode %u) to parent directory %u:\n", name.characters(), mode, parent_inode->identifier().index()); // NOTE: This doesn't commit the inode allocation just yet! auto inode_id = allocate_inode(0, 0); if (!inode_id) { - kprintf("Ext2FS: createInode: allocateInode failed\n"); + kprintf("Ext2FS: createInode: allocate_inode failed\n"); error = -ENOSPC; return { }; } auto blocks = allocate_blocks(group_index_from_inode(inode_id), ceilDiv(size, blockSize())); if (blocks.is_empty()) { - kprintf("Ext2FS: createInode: allocateBlocks failed\n"); + kprintf("Ext2FS: createInode: allocate_blocks failed\n"); error = -ENOSPC; return { }; } @@ -885,7 +883,7 @@ RetainPtr Ext2FS::create_inode(InodeIdentifier parentInode, const String& fileType = EXT2_FT_SYMLINK; // Try adding it to the directory first, in case the name is already in use. - bool success = add_inode_to_directory(parentInode.index(), inode_id, name, fileType, error); + bool success = parent_inode->add_child({ id(), inode_id }, name, fileType, error); if (!success) return { }; diff --git a/VirtualFileSystem/Ext2FileSystem.h b/VirtualFileSystem/Ext2FileSystem.h index 429834408a..1c7b3dca3f 100644 --- a/VirtualFileSystem/Ext2FileSystem.h +++ b/VirtualFileSystem/Ext2FileSystem.h @@ -29,6 +29,7 @@ private: virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; virtual bool write(const ByteBuffer&) override; + virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; void populate_lookup_cache(); diff --git a/VirtualFileSystem/FileSystem.h b/VirtualFileSystem/FileSystem.h index dcc8a4ddda..5bd7635417 100644 --- a/VirtualFileSystem/FileSystem.h +++ b/VirtualFileSystem/FileSystem.h @@ -82,6 +82,7 @@ public: virtual InodeIdentifier lookup(const String& name) = 0; virtual String reverse_lookup(InodeIdentifier) = 0; virtual bool write(const ByteBuffer&) = 0; + virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) = 0; bool is_metadata_dirty() const { return m_metadata_dirty; } diff --git a/VirtualFileSystem/SyntheticFileSystem.cpp b/VirtualFileSystem/SyntheticFileSystem.cpp index 63994345aa..9be7277684 100644 --- a/VirtualFileSystem/SyntheticFileSystem.cpp +++ b/VirtualFileSystem/SyntheticFileSystem.cpp @@ -263,3 +263,13 @@ bool SynthFSInode::write(const ByteBuffer&) ASSERT_NOT_REACHED(); return false; } + +bool SynthFSInode::add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) +{ + (void) child_id; + (void) name; + (void) file_type; + (void) error; + ASSERT_NOT_REACHED(); + return false; +} diff --git a/VirtualFileSystem/SyntheticFileSystem.h b/VirtualFileSystem/SyntheticFileSystem.h index 020e9e14eb..27062b31ca 100644 --- a/VirtualFileSystem/SyntheticFileSystem.h +++ b/VirtualFileSystem/SyntheticFileSystem.h @@ -53,6 +53,7 @@ private: virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; virtual bool write(const ByteBuffer&) override; + virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; SynthFS& fs(); const SynthFS& fs() const;