mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 07:18:51 +00:00
Lots of hacking to make a very simple "ls" utility.
I added a dead-simple malloc that only allows allocations < 4096 bytes. It just forwards the request to mmap() every time. I also added simplified versions of opendir() and readdir().
This commit is contained in:
parent
0c5bbac86e
commit
bca4b71bfa
Notes:
sideshowbarker
2024-07-19 18:39:29 +09:00
Author: https://github.com/awesomekling
Commit: bca4b71bfa
19 changed files with 277 additions and 67 deletions
|
@ -78,6 +78,7 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
|||
fileSystem->retain();
|
||||
|
||||
vnode->inode = inode;
|
||||
vnode->m_cachedMetadata = { };
|
||||
|
||||
#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);
|
||||
|
@ -85,6 +86,7 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
|||
|
||||
m_inode2vnode.set(inode, vnode.ptr());
|
||||
vnode->m_characterDevice = characterDevice;
|
||||
|
||||
return vnode;
|
||||
}
|
||||
|
||||
|
@ -151,7 +153,7 @@ auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
|||
auto* node = m_nodeFreeList.takeLast();
|
||||
ASSERT(node->retainCount == 0);
|
||||
node->retainCount = 1;
|
||||
node->vfs = this;
|
||||
node->m_vfs = this;
|
||||
return adopt(*node);
|
||||
}
|
||||
|
||||
|
@ -198,8 +200,7 @@ bool VirtualFileSystem::isRoot(InodeIdentifier inode) const
|
|||
return inode == m_rootNode->inode;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode, F func)
|
||||
void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(const FileSystem::DirectoryEntry&)> callback)
|
||||
{
|
||||
if (!directoryInode.isValid())
|
||||
return;
|
||||
|
@ -216,7 +217,7 @@ void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode,
|
|||
ASSERT(mount);
|
||||
resolvedInode = mount->host();
|
||||
}
|
||||
func({ entry.name, resolvedInode });
|
||||
callback({ entry.name, resolvedInode });
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -340,6 +341,7 @@ void VirtualFileSystem::listDirectoryRecursively(const String& path)
|
|||
} else {
|
||||
kprintf("%s/%s\n", path.characters(), entry.name.characters());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -467,10 +469,17 @@ void VirtualFileSystem::Node::release()
|
|||
{
|
||||
ASSERT(retainCount);
|
||||
if (--retainCount == 0) {
|
||||
vfs->freeNode(this);
|
||||
m_vfs->freeNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
const InodeMetadata& VirtualFileSystem::Node::metadata() const
|
||||
{
|
||||
if (!m_cachedMetadata.isValid())
|
||||
m_cachedMetadata = inode.metadata();
|
||||
return m_cachedMetadata;
|
||||
}
|
||||
|
||||
VirtualFileSystem::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
||||
: m_host(host)
|
||||
, m_guest(guestFileSystem->rootInode())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue