diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-11-13 13:32:16 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-11-13 13:32:16 +0100 |
commit | 26852a83633f8323e7eb2ad9b382629a805f7ae9 (patch) | |
tree | 47055d39f76f1e9064ddea0167c686d77197ddd8 | |
parent | 10c470e95f1824eeef2b0294ce68f254fe010946 (diff) | |
download | serenity-26852a83633f8323e7eb2ad9b382629a805f7ae9.zip |
Add metadata to CoreInode.
-rw-r--r-- | Kernel/init.cpp | 20 | ||||
-rw-r--r-- | VirtualFileSystem/Ext2FileSystem.cpp | 22 | ||||
-rw-r--r-- | VirtualFileSystem/Ext2FileSystem.h | 12 | ||||
-rw-r--r-- | VirtualFileSystem/FileSystem.h | 7 | ||||
-rw-r--r-- | VirtualFileSystem/VirtualFileSystem.cpp | 6 |
5 files changed, 42 insertions, 25 deletions
diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 4fbb2b2881..ec20074560 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -29,7 +29,6 @@ #define KSYMS #define SPAWN_MULTIPLE_SHELLS //#define STRESS_TEST_SPAWNING -//#define TEST_ELF_LOADER system_t system; @@ -217,25 +216,6 @@ static void init_stage2() vfs->mount(ProcFileSystem::the(), "/proc"); -#ifdef TEST_ELF_LOADER - { - auto testExecutable = vfs->open("/bin/id"); - ASSERT(testExecutable); - auto testExecutableData = testExecutable->readEntireFile(); - ASSERT(testExecutableData); - - ExecSpace space; - space.loadELF(move(testExecutableData)); - auto* elf_entry = space.symbol_ptr("_start"); - ASSERT(elf_entry); - - typedef int (*MainFunctionPtr)(void); - kprintf("elf_entry: %p\n", elf_entry); - int rc = reinterpret_cast<MainFunctionPtr>(elf_entry)(); - kprintf("it returned %d\n", rc); - } -#endif - Vector<String> environment; environment.append("TERM=ansi"); diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index 1f2fd37c52..4af91e7a87 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -320,6 +320,28 @@ Ext2Inode::~Ext2Inode() { } +void Ext2Inode::populate_metadata() const +{ + m_metadata.inode = identifier(); + m_metadata.size = m_raw_inode.i_size; + m_metadata.mode = m_raw_inode.i_mode; + m_metadata.uid = m_raw_inode.i_uid; + m_metadata.gid = m_raw_inode.i_gid; + m_metadata.linkCount = m_raw_inode.i_links_count; + m_metadata.atime = m_raw_inode.i_atime; + m_metadata.ctime = m_raw_inode.i_ctime; + m_metadata.mtime = m_raw_inode.i_mtime; + m_metadata.dtime = m_raw_inode.i_dtime; + m_metadata.blockSize = fs().blockSize(); + m_metadata.blockCount = m_raw_inode.i_blocks; + + if (isBlockDevice(m_raw_inode.i_mode) || isCharacterDevice(m_raw_inode.i_mode)) { + unsigned dev = m_raw_inode.i_block[0]; + m_metadata.majorDevice = (dev & 0xfff00) >> 8; + m_metadata.minorDevice= (dev & 0xff) | ((dev >> 12) & 0xfff00); + } +} + RetainPtr<CoreInode> Ext2FileSystem::get_inode(InodeIdentifier inode) { ASSERT(inode.fileSystemID() == id()); diff --git a/VirtualFileSystem/Ext2FileSystem.h b/VirtualFileSystem/Ext2FileSystem.h index da1ae1a12c..d7423cca95 100644 --- a/VirtualFileSystem/Ext2FileSystem.h +++ b/VirtualFileSystem/Ext2FileSystem.h @@ -17,13 +17,16 @@ class Ext2Inode final : public CoreInode { public: virtual ~Ext2Inode() override; - virtual Unix::ssize_t read_bytes(Unix::off_t, Unix::size_t, byte* buffer, FileDescriptor*) override; - size_t size() const { return m_raw_inode.i_size; } bool is_symlink() const { return isSymbolicLink(m_raw_inode.i_mode); } private: + // ^CoreInode + virtual Unix::ssize_t read_bytes(Unix::off_t, Unix::size_t, byte* buffer, FileDescriptor*) override; + virtual void populate_metadata() const override; + Ext2FileSystem& fs(); + const Ext2FileSystem& fs() const; Ext2Inode(Ext2FileSystem&, unsigned index, const ext2_inode&); SpinLock m_lock; @@ -110,3 +113,8 @@ inline Ext2FileSystem& Ext2Inode::fs() { return static_cast<Ext2FileSystem&>(CoreInode::fs()); } + +inline const Ext2FileSystem& Ext2Inode::fs() const +{ + return static_cast<const Ext2FileSystem&>(CoreInode::fs()); +} diff --git a/VirtualFileSystem/FileSystem.h b/VirtualFileSystem/FileSystem.h index 518a713de8..25532e8935 100644 --- a/VirtualFileSystem/FileSystem.h +++ b/VirtualFileSystem/FileSystem.h @@ -23,11 +23,13 @@ class CoreInode : public Retainable<CoreInode> { public: virtual ~CoreInode(); - FileSystem& fs() const { return m_fs; } + FileSystem& fs() { return m_fs; } + const FileSystem& fs() const { return m_fs; } unsigned fsid() const; unsigned index() const { return m_index; } InodeIdentifier identifier() const { return { fsid(), index() }; } + const InodeMetadata& metadata() const { if (!m_metadata.isValid()) { populate_metadata(); } return m_metadata; } virtual Unix::ssize_t read_bytes(Unix::off_t, Unix::size_t, byte* buffer, FileDescriptor*) = 0; @@ -38,6 +40,9 @@ protected: { } + virtual void populate_metadata() const = 0; + + mutable InodeMetadata m_metadata; private: FileSystem& m_fs; unsigned m_index { 0 }; diff --git a/VirtualFileSystem/VirtualFileSystem.cpp b/VirtualFileSystem/VirtualFileSystem.cpp index 01f9959aaa..25bb8bdc29 100644 --- a/VirtualFileSystem/VirtualFileSystem.cpp +++ b/VirtualFileSystem/VirtualFileSystem.cpp @@ -77,7 +77,7 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node> vnode->inode = inode; vnode->m_core_inode = move(core_inode); - vnode->m_cachedMetadata = { }; + vnode->m_cachedMetadata = metadata; #ifdef VFS_DEBUG kprintf("makeNode: inode=%u, size=%u, mode=%o, uid=%u, gid=%u\n", inode.index(), metadata.size, metadata.mode, metadata.uid, metadata.gid); @@ -158,7 +158,7 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem) kprintf("VFS: root inode for / is not in use :(\n"); return false; } - if (!node->inode.metadata().isDirectory()) { + if (!node->metadata().isDirectory()) { kprintf("VFS: root inode for / is not a directory :(\n"); return false; } @@ -580,6 +580,8 @@ void VirtualFileSystem::Node::release() const InodeMetadata& VirtualFileSystem::Node::metadata() const { + if (m_core_inode) + return m_core_inode->metadata(); if (!m_cachedMetadata.isValid()) m_cachedMetadata = inode.metadata(); return m_cachedMetadata; |