diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index 7b4762c740..11b24a8cc5 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -208,7 +208,7 @@ Region* MemoryManager::region_from_laddr(Process& process, LinearAddress laddr) if (region->contains(laddr)) return region.ptr(); } - kprintf("%s(%u) Couldn't find region for L%x (CR3=%x)\n", process.name().characters(), process.pid(), laddr.get()); + kprintf("%s(%u) Couldn't find region for L%x (CR3=%x)\n", process.name().characters(), process.pid(), laddr.get(), process.page_directory().cr3()); return nullptr; } diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index 59c9fdc8fa..bd46f56de0 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -440,7 +440,7 @@ ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, size_t count, byte* buffer, byte* out = buffer; #ifdef EXT2_DEBUG - kprintf("Ext2FS: Reading %u bytes %d bytes into inode %u:%u to %p\n", count, offset, identifier().fsid(), identifier().index(), buffer); + kprintf("Ext2FS: Reading up to %u bytes %d bytes into inode %u:%u to %p\n", count, offset, identifier().fsid(), identifier().index(), buffer); //kprintf("ok let's do it, read(%u, %u) -> blocks %u thru %u, oifb: %u\n", offset, count, first_block_logical_index, last_block_logical_index, offset_into_first_block); #endif @@ -500,7 +500,7 @@ ssize_t Ext2FSInode::write_bytes(Unix::off_t offset, size_t count, const byte* d const byte* in = data; #ifdef EXT2_DEBUG - dbgprintf("Ext2FS::write_bytes: Writing %u bytes %d bytes into inode %u:%u from %p\n", count, offset, fsid(), index(), data); + dbgprintf("Ext2FSInode::write_bytes: Writing %u bytes %d bytes into inode %u:%u from %p\n", count, offset, fsid(), index(), data); #endif auto buffer_block = ByteBuffer::create_uninitialized(block_size); @@ -539,61 +539,16 @@ ssize_t Ext2FSInode::write_bytes(Unix::off_t offset, size_t count, const byte* d m_raw_inode.i_size = new_size; m_raw_inode.i_blocks = block_list.size() * (block_size / 512); + fs().write_ext2_inode(index(), m_raw_inode); #ifdef EXT2_DEBUG dbgprintf("Ext2FSInode::write_bytes: after write, i_size=%u, i_blocks=%u (%u blocks in list)\n", m_raw_inode.i_size, m_raw_inode.i_blocks, block_list.size()); #endif - flush_metadata(); // NOTE: Make sure the cached block list is up to date! m_block_list = move(block_list); return nwritten; } -bool Ext2FSInode::write(const ByteBuffer& data) -{ - // FIXME: Lock this Inode during write. Inode should have a common locking mechanism. - // FIXME: Support writing to symlink inodes. - ASSERT(!is_symlink()); - - unsigned blocks_needed_before = ceilDiv(size(), fs().blockSize()); - unsigned blocks_needed_after = ceilDiv((unsigned)data.size(), fs().blockSize()); - - - auto block_list = fs().block_list_for_inode(m_raw_inode); - if (blocks_needed_after > blocks_needed_before) { - auto new_blocks = fs().allocate_blocks(fs().group_index_from_inode(index()), blocks_needed_after - blocks_needed_before); - for (auto new_block_index : new_blocks) - fs().set_block_allocation_state(fs().group_index_from_inode(index()), new_block_index, true); - block_list.append(move(new_blocks)); - } else if (blocks_needed_after < blocks_needed_before) { - // FIXME: Implement block list shrinking! - ASSERT_NOT_REACHED(); - } - - auto padded_block = ByteBuffer::create_uninitialized(fs().blockSize()); - for (unsigned i = 0; i < block_list.size(); ++i) { - auto section = data.slice(i * fs().blockSize(), fs().blockSize()); - bool success; - dbgprintf("Ext2FS: write section = %p (%u)\n", section.pointer(), section.size()); - if (section.size() == fs().blockSize()) - success = fs().writeBlock(block_list[i], section); - else { - memcpy(padded_block.pointer(), section.pointer(), section.size()); - memset(padded_block.pointer() + section.size(), 0, fs().blockSize() - section.size()); - success = fs().writeBlock(block_list[i], padded_block); - } - ASSERT(success); - } - - bool success = fs().write_block_list_for_inode(index(), m_raw_inode, block_list); - ASSERT(success); - - m_raw_inode.i_size = data.size(); - set_metadata_dirty(true); - - return true; -} - bool Ext2FSInode::traverse_as_directory(Function callback) { ASSERT(metadata().isDirectory()); @@ -609,7 +564,7 @@ bool Ext2FSInode::traverse_as_directory(Functioninode != 0) { #ifdef EXT2_DEBUG - kprintf("Ext2Inode::traverse_as_directory: %u, name_len: %u, rec_len: %u, file_type: %u, name: %s\n", entry->inode, entry->name_len, entry->rec_len, entry->file_type, entry->name); + kprintf("Ext2Inode::traverse_as_directory: %u, name_len: %u, rec_len: %u, file_type: %u, name: %s\n", entry->inode, entry->name_len, entry->rec_len, entry->file_type, String(entry->name, entry->name_len).characters()); #endif if (!callback({ entry->name, entry->name_len, { fsid(), entry->inode }, entry->file_type })) break; @@ -754,7 +709,7 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vectorwrite(directoryData); + return get_inode({ id(), directoryInode })->write_bytes(0, directoryData.size(), directoryData.pointer(), nullptr); } unsigned Ext2FS::inodes_per_block() const @@ -1100,7 +1055,7 @@ RetainPtr Ext2FS::create_inode(InodeIdentifier parent_id, const String& n 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); + auto inode_id = allocate_inode(0, size); if (!inode_id) { kprintf("Ext2FS: create_inode: allocate_inode failed\n"); error = -ENOSPC; diff --git a/VirtualFileSystem/Ext2FileSystem.h b/VirtualFileSystem/Ext2FileSystem.h index a9819588ee..ce2344ab82 100644 --- a/VirtualFileSystem/Ext2FileSystem.h +++ b/VirtualFileSystem/Ext2FileSystem.h @@ -32,7 +32,6 @@ private: virtual InodeIdentifier lookup(const String& name) override; virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; - virtual bool write(const ByteBuffer&) override; virtual ssize_t write_bytes(Unix::off_t, size_t, const byte* data, FileDescriptor*) override; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; virtual bool remove_child(const String& name, int& error) override; diff --git a/VirtualFileSystem/FileSystem.h b/VirtualFileSystem/FileSystem.h index 1dd0fee94f..21a64decbb 100644 --- a/VirtualFileSystem/FileSystem.h +++ b/VirtualFileSystem/FileSystem.h @@ -83,7 +83,6 @@ public: virtual bool traverse_as_directory(Function) = 0; virtual InodeIdentifier lookup(const String& name) = 0; virtual String reverse_lookup(InodeIdentifier) = 0; - virtual bool write(const ByteBuffer&) = 0; virtual ssize_t write_bytes(Unix::off_t, size_t, const byte* data, FileDescriptor*) = 0; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) = 0; virtual bool remove_child(const String& name, int& error) = 0; diff --git a/VirtualFileSystem/SyntheticFileSystem.cpp b/VirtualFileSystem/SyntheticFileSystem.cpp index 95558236c9..18192467e5 100644 --- a/VirtualFileSystem/SyntheticFileSystem.cpp +++ b/VirtualFileSystem/SyntheticFileSystem.cpp @@ -273,13 +273,6 @@ void SynthFSInode::flush_metadata() { } -bool SynthFSInode::write(const ByteBuffer& data) -{ - if (!m_write_callback) - return 0; // FIXME: -EPERM? - return m_write_callback(*this, data); -} - ssize_t SynthFSInode::write_bytes(Unix::off_t offset, size_t size, const byte* buffer, FileDescriptor*) { if (!m_write_callback) diff --git a/VirtualFileSystem/SyntheticFileSystem.h b/VirtualFileSystem/SyntheticFileSystem.h index daefa3cf46..a0ad26e87b 100644 --- a/VirtualFileSystem/SyntheticFileSystem.h +++ b/VirtualFileSystem/SyntheticFileSystem.h @@ -60,7 +60,6 @@ private: virtual InodeIdentifier lookup(const String& name) override; virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; - virtual bool write(const ByteBuffer&) override; virtual ssize_t write_bytes(Unix::off_t, size_t, const byte* buffer, FileDescriptor*) override; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; virtual bool remove_child(const String& name, int& error) override;