mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Add metadata to CoreInode.
This commit is contained in:
parent
10c470e95f
commit
26852a8363
5 changed files with 42 additions and 25 deletions
|
@ -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");
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue