mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
A pass of style/naming cleanup in VFS.
This commit is contained in:
parent
457a5df7d5
commit
396a32835b
Notes:
sideshowbarker
2024-07-19 16:10:37 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/396a32835b4
12 changed files with 120 additions and 120 deletions
|
@ -214,15 +214,15 @@ ByteBuffer procfs$regions()
|
|||
ByteBuffer procfs$mounts()
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto buffer = ByteBuffer::createUninitialized(VFS::the().mountCount() * 80);
|
||||
auto buffer = ByteBuffer::createUninitialized(VFS::the().mount_count() * 80);
|
||||
char* ptr = (char*)buffer.pointer();
|
||||
VFS::the().forEachMount([&ptr] (auto& mount) {
|
||||
VFS::the().for_each_mount([&ptr] (auto& mount) {
|
||||
auto& fs = mount.fileSystem();
|
||||
ptr += ksprintf(ptr, "%s @ ", fs.className());
|
||||
if (!mount.host().isValid())
|
||||
ptr += ksprintf(ptr, "/\n", fs.className());
|
||||
else
|
||||
ptr += ksprintf(ptr, "%u:%u\n", mount.host().fileSystemID(), mount.host().index());
|
||||
ptr += ksprintf(ptr, "%u:%u\n", mount.host().fsid(), mount.host().index());
|
||||
});
|
||||
buffer.trim(ptr - (char*)buffer.pointer());
|
||||
return buffer;
|
||||
|
@ -331,9 +331,9 @@ ByteBuffer procfs$summary()
|
|||
ByteBuffer procfs$vnodes()
|
||||
{
|
||||
auto& vfs = VFS::the();
|
||||
auto buffer = ByteBuffer::createUninitialized(vfs.m_maxNodeCount * 256);
|
||||
auto buffer = ByteBuffer::createUninitialized(vfs.m_max_vnode_count * 256);
|
||||
char* ptr = (char*)buffer.pointer();
|
||||
for (size_t i = 0; i < vfs.m_maxNodeCount; ++i) {
|
||||
for (size_t i = 0; i < vfs.m_max_vnode_count; ++i) {
|
||||
auto& vnode = vfs.m_nodes[i];
|
||||
// FIXME: Retain the vnode while inspecting it.
|
||||
if (!vnode.inUse())
|
||||
|
@ -347,7 +347,7 @@ ByteBuffer procfs$vnodes()
|
|||
path = static_cast<const TTY*>(dev)->ttyName();
|
||||
}
|
||||
}
|
||||
ptr += ksprintf(ptr, "vnode %03u: %02u:%08u (%u) %s\n", i, vnode.inode.fileSystemID(), vnode.inode.index(), vnode.retain_count(), path.characters());
|
||||
ptr += ksprintf(ptr, "vnode %03u: %02u:%08u (%u) %s\n", i, vnode.inode.fsid(), vnode.inode.index(), vnode.retain_count(), path.characters());
|
||||
}
|
||||
*ptr = '\0';
|
||||
buffer.trim(ptr - (char*)buffer.pointer());
|
||||
|
|
|
@ -176,29 +176,29 @@ static void init_stage2()
|
|||
auto vfs = make<VFS>();
|
||||
|
||||
auto dev_zero = make<ZeroDevice>();
|
||||
vfs->registerCharacterDevice(*dev_zero);
|
||||
vfs->register_character_device(*dev_zero);
|
||||
|
||||
auto dev_null = make<NullDevice>();
|
||||
vfs->registerCharacterDevice(*dev_null);
|
||||
vfs->register_character_device(*dev_null);
|
||||
|
||||
auto dev_full = make<FullDevice>();
|
||||
vfs->registerCharacterDevice(*dev_full);
|
||||
vfs->register_character_device(*dev_full);
|
||||
|
||||
auto dev_random = make<RandomDevice>();
|
||||
vfs->registerCharacterDevice(*dev_random);
|
||||
vfs->register_character_device(*dev_random);
|
||||
|
||||
vfs->registerCharacterDevice(*keyboard);
|
||||
vfs->register_character_device(*keyboard);
|
||||
|
||||
vfs->registerCharacterDevice(*tty0);
|
||||
vfs->registerCharacterDevice(*tty1);
|
||||
vfs->registerCharacterDevice(*tty2);
|
||||
vfs->registerCharacterDevice(*tty3);
|
||||
vfs->register_character_device(*tty0);
|
||||
vfs->register_character_device(*tty1);
|
||||
vfs->register_character_device(*tty2);
|
||||
vfs->register_character_device(*tty3);
|
||||
|
||||
auto dev_hd0 = IDEDiskDevice::create();
|
||||
auto e2fs = Ext2FileSystem::create(dev_hd0.copyRef());
|
||||
e2fs->initialize();
|
||||
|
||||
vfs->mountRoot(e2fs.copyRef());
|
||||
vfs->mount_root(e2fs.copyRef());
|
||||
|
||||
#ifdef KSYMS
|
||||
{
|
||||
|
@ -267,7 +267,7 @@ void init()
|
|||
|
||||
MemoryManager::initialize();
|
||||
|
||||
VFS::initializeGlobals();
|
||||
VFS::initialize_globals();
|
||||
StringImpl::initializeGlobals();
|
||||
|
||||
PIT::initialize();
|
||||
|
|
|
@ -220,7 +220,7 @@ auto Ext2FileSystem::lookupExt2Inode(unsigned inode) const -> CachedExt2Inode
|
|||
|
||||
InodeMetadata Ext2FileSystem::inodeMetadata(InodeIdentifier inode) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
if (!e2inode)
|
||||
|
@ -344,7 +344,7 @@ void Ext2Inode::populate_metadata() const
|
|||
|
||||
RetainPtr<CoreInode> Ext2FileSystem::get_inode(InodeIdentifier inode) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
{
|
||||
LOCKER(m_inode_cache_lock);
|
||||
auto it = m_inode_cache.find(inode.index());
|
||||
|
@ -428,7 +428,7 @@ Unix::ssize_t Ext2Inode::read_bytes(Unix::off_t offset, Unix::size_t count, byte
|
|||
Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const
|
||||
{
|
||||
ASSERT(offset >= 0);
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
if (!e2inode) {
|
||||
|
@ -503,7 +503,7 @@ Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t
|
|||
|
||||
bool Ext2FileSystem::writeInode(InodeIdentifier inode, const ByteBuffer& data)
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
if (!e2inode) {
|
||||
|
@ -563,7 +563,7 @@ bool Ext2Inode::traverse_as_directory(Function<bool(const FileSystem::DirectoryE
|
|||
|
||||
bool Ext2FileSystem::enumerateDirectoryInode(InodeIdentifier inode, Function<bool(const DirectoryEntry&)> callback) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(inode.index()));
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -780,7 +780,7 @@ bool Ext2FileSystem::modifyLinkCount(InodeIndex inode, int delta)
|
|||
|
||||
bool Ext2FileSystem::setModificationTime(InodeIdentifier inode, dword timestamp)
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
if (!e2inode)
|
||||
|
@ -993,7 +993,7 @@ bool Ext2FileSystem::setBlockAllocationState(GroupIndex group, BlockIndex bi, bo
|
|||
|
||||
InodeIdentifier Ext2FileSystem::makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode)
|
||||
{
|
||||
ASSERT(parentInode.fileSystemID() == id());
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(parentInode.index()));
|
||||
|
||||
// Fix up the mode to definitely be a directory.
|
||||
|
@ -1032,7 +1032,7 @@ InodeIdentifier Ext2FileSystem::makeDirectory(InodeIdentifier parentInode, const
|
|||
|
||||
InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size)
|
||||
{
|
||||
ASSERT(parentInode.fileSystemID() == id());
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(parentInode.index()));
|
||||
|
||||
//#ifdef EXT2_DEBUG
|
||||
|
@ -1119,7 +1119,7 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S
|
|||
return { id(), inode };
|
||||
}
|
||||
|
||||
InodeIdentifier Ext2FileSystem::findParentOfInode(InodeIdentifier inode_id) const
|
||||
InodeIdentifier Ext2FileSystem::find_parent_of_inode(InodeIdentifier inode_id) const
|
||||
{
|
||||
auto inode = get_inode(inode_id);
|
||||
ASSERT(inode);
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual InodeIdentifier findParentOfInode(InodeIdentifier) const override;
|
||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
bool isDirectoryInode(unsigned) const;
|
||||
|
|
|
@ -37,7 +37,7 @@ FileSystem* FileSystem::fromID(dword id)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode, const String& name) const
|
||||
InodeIdentifier FileSystem::child_of_directory_inode_with_name(InodeIdentifier inode, const String& name) const
|
||||
{
|
||||
InodeIdentifier foundInode;
|
||||
enumerateDirectoryInode(inode, [&] (const DirectoryEntry& entry) {
|
||||
|
@ -50,7 +50,7 @@ InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode,
|
|||
return foundInode;
|
||||
}
|
||||
|
||||
String FileSystem::nameOfChildInDirectory(InodeIdentifier parent, InodeIdentifier child) const
|
||||
String FileSystem::name_of_child_in_directory(InodeIdentifier parent, InodeIdentifier child) const
|
||||
{
|
||||
String name;
|
||||
bool success = enumerateDirectoryInode(parent, [&] (auto& entry) {
|
||||
|
@ -98,7 +98,7 @@ ByteBuffer CoreInode::read_entire(FileDescriptor* descriptor)
|
|||
|
||||
ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode, FileDescriptor* handle) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto metadata = inodeMetadata(inode);
|
||||
if (!metadata.isValid()) {
|
||||
|
|
|
@ -49,13 +49,13 @@ public:
|
|||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) = 0;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) = 0;
|
||||
|
||||
virtual InodeIdentifier findParentOfInode(InodeIdentifier) const = 0;
|
||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const = 0;
|
||||
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const = 0;
|
||||
|
||||
InodeIdentifier childOfDirectoryInodeWithName(InodeIdentifier, const String& name) const;
|
||||
InodeIdentifier child_of_directory_inode_with_name(InodeIdentifier, const String& name) const;
|
||||
ByteBuffer readEntireInode(InodeIdentifier, FileDescriptor* = nullptr) const;
|
||||
String nameOfChildInDirectory(InodeIdentifier parent, InodeIdentifier child) const;
|
||||
String name_of_child_in_directory(InodeIdentifier parent, InodeIdentifier child) const;
|
||||
|
||||
protected:
|
||||
FileSystem();
|
||||
|
@ -133,8 +133,8 @@ namespace AK {
|
|||
template<>
|
||||
struct Traits<InodeIdentifier> {
|
||||
// FIXME: This is a shitty hash.
|
||||
static unsigned hash(const InodeIdentifier& inode) { return Traits<unsigned>::hash(inode.fileSystemID()) + Traits<unsigned>::hash(inode.index()); }
|
||||
static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fileSystemID(), inode.index()); }
|
||||
static unsigned hash(const InodeIdentifier& inode) { return Traits<unsigned>::hash(inode.fsid()) + Traits<unsigned>::hash(inode.index()); }
|
||||
static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fsid(), inode.index()); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
bool isValid() const { return m_fileSystemID != 0 && m_index != 0; }
|
||||
|
||||
dword fileSystemID() const { return m_fileSystemID; }
|
||||
dword fsid() const { return m_fileSystemID; }
|
||||
dword index() const { return m_index; }
|
||||
|
||||
FileSystem* fileSystem();
|
||||
|
|
|
@ -134,7 +134,7 @@ InodeIdentifier SyntheticFileSystem::rootInode() const
|
|||
bool SyntheticFileSystem::enumerateDirectoryInode(InodeIdentifier inode, Function<bool(const DirectoryEntry&)> callback) const
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
#ifdef SYNTHFS_DEBUG
|
||||
kprintf("synthfs: enumerateDirectoryInode %u\n", inode.index());
|
||||
#endif
|
||||
|
@ -161,7 +161,7 @@ bool SyntheticFileSystem::enumerateDirectoryInode(InodeIdentifier inode, Functio
|
|||
InodeMetadata SyntheticFileSystem::inodeMetadata(InodeIdentifier inode) const
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
#ifdef SYNTHFS_DEBUG
|
||||
kprintf("SynthFS: inodeMetadata(%u)\n", inode.index());
|
||||
#endif
|
||||
|
@ -197,7 +197,7 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&)
|
|||
|
||||
Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor* handle) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
ASSERT(inode.fsid() == id());
|
||||
#ifdef SYNTHFS_DEBUG
|
||||
kprintf("SynthFS: readInode %u\n", inode.index());
|
||||
#endif
|
||||
|
@ -245,7 +245,7 @@ auto SyntheticFileSystem::generateInodeIndex() -> InodeIndex
|
|||
return m_nextInodeIndex++;
|
||||
}
|
||||
|
||||
InodeIdentifier SyntheticFileSystem::findParentOfInode(InodeIdentifier inode) const
|
||||
InodeIdentifier SyntheticFileSystem::find_parent_of_inode(InodeIdentifier inode) const
|
||||
{
|
||||
auto it = m_inodes.find(inode.index());
|
||||
if (it == m_inodes.end())
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual InodeIdentifier findParentOfInode(InodeIdentifier) const override;
|
||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -22,7 +22,7 @@ VFS& VFS::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
void VFS::initializeGlobals()
|
||||
void VFS::initialize_globals()
|
||||
{
|
||||
s_the = nullptr;
|
||||
FileSystem::initializeGlobals();
|
||||
|
@ -34,17 +34,17 @@ VFS::VFS()
|
|||
kprintf("VFS: Constructing VFS\n");
|
||||
#endif
|
||||
s_the = this;
|
||||
m_maxNodeCount = 16;
|
||||
m_nodes = reinterpret_cast<Vnode*>(kmalloc(sizeof(Vnode) * maxNodeCount()));
|
||||
memset(m_nodes, 0, sizeof(Vnode) * maxNodeCount());
|
||||
m_max_vnode_count = 16;
|
||||
m_nodes = reinterpret_cast<Vnode*>(kmalloc(sizeof(Vnode) * max_vnode_count()));
|
||||
memset(m_nodes, 0, sizeof(Vnode) * max_vnode_count());
|
||||
|
||||
for (unsigned i = 0; i < m_maxNodeCount; ++i)
|
||||
m_nodeFreeList.append(&m_nodes[i]);
|
||||
for (unsigned i = 0; i < m_max_vnode_count; ++i)
|
||||
m_vnode_freelist.append(&m_nodes[i]);
|
||||
}
|
||||
|
||||
VFS::~VFS()
|
||||
{
|
||||
kprintf("VFS: ~VirtualFileSystem with %u nodes allocated\n", allocatedNodeCount());
|
||||
kprintf("VFS: ~VirtualFileSystem with %u nodes allocated\n", allocated_vnode_count());
|
||||
// FIXME: m_nodes is never freed. Does it matter though?
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ auto VFS::makeNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
|||
|
||||
CharacterDevice* characterDevice = nullptr;
|
||||
if (metadata.isCharacterDevice()) {
|
||||
auto it = m_characterDevices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice));
|
||||
if (it != m_characterDevices.end()) {
|
||||
auto it = m_character_devices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice));
|
||||
if (it != m_character_devices.end()) {
|
||||
characterDevice = (*it).value;
|
||||
} else {
|
||||
kprintf("VFS: makeNode() no such character device %u,%u\n", metadata.majorDevice, metadata.minorDevice);
|
||||
|
@ -133,7 +133,7 @@ bool VFS::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
|||
{
|
||||
ASSERT(fileSystem);
|
||||
int error;
|
||||
auto inode = resolvePath(path, error);
|
||||
auto inode = resolve_path(path, error);
|
||||
if (!inode.isValid()) {
|
||||
kprintf("VFS: mount can't resolve mount point '%s'\n", path.characters());
|
||||
return false;
|
||||
|
@ -146,10 +146,10 @@ bool VFS::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
||||
bool VFS::mount_root(RetainPtr<FileSystem>&& fileSystem)
|
||||
{
|
||||
if (m_rootNode) {
|
||||
kprintf("VFS: mountRoot can't mount another root\n");
|
||||
if (m_root_vnode) {
|
||||
kprintf("VFS: mount_root can't mount another root\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -165,11 +165,11 @@ bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
return false;
|
||||
}
|
||||
|
||||
m_rootNode = move(node);
|
||||
m_root_vnode = move(node);
|
||||
|
||||
kprintf("VFS: mounted root on %s{%p}\n",
|
||||
m_rootNode->fileSystem()->className(),
|
||||
m_rootNode->fileSystem());
|
||||
m_root_vnode->fileSystem()->className(),
|
||||
m_root_vnode->fileSystem());
|
||||
|
||||
m_mounts.append(move(mount));
|
||||
return true;
|
||||
|
@ -177,11 +177,11 @@ bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
|
||||
auto VFS::allocateNode() -> RetainPtr<Vnode>
|
||||
{
|
||||
if (m_nodeFreeList.isEmpty()) {
|
||||
if (m_vnode_freelist.isEmpty()) {
|
||||
kprintf("VFS: allocateNode has no nodes left\n");
|
||||
return nullptr;
|
||||
}
|
||||
auto* node = m_nodeFreeList.takeLast();
|
||||
auto* node = m_vnode_freelist.takeLast();
|
||||
ASSERT(node->retainCount == 0);
|
||||
node->retainCount = 1;
|
||||
node->m_vfs = this;
|
||||
|
@ -205,7 +205,7 @@ void VFS::freeNode(Vnode* node)
|
|||
}
|
||||
node->m_vfs = nullptr;
|
||||
node->m_vmo = nullptr;
|
||||
m_nodeFreeList.append(move(node));
|
||||
m_vnode_freelist.append(move(node));
|
||||
}
|
||||
|
||||
#ifndef SERENITY
|
||||
|
@ -220,7 +220,7 @@ bool VFS::isDirectory(const String& path, InodeIdentifier base)
|
|||
}
|
||||
#endif
|
||||
|
||||
auto VFS::findMountForHost(InodeIdentifier inode) -> Mount*
|
||||
auto VFS::find_mount_for_host(InodeIdentifier inode) -> Mount*
|
||||
{
|
||||
for (auto& mount : m_mounts) {
|
||||
if (mount->host() == inode)
|
||||
|
@ -229,7 +229,7 @@ auto VFS::findMountForHost(InodeIdentifier inode) -> Mount*
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto VFS::findMountForGuest(InodeIdentifier inode) -> Mount*
|
||||
auto VFS::find_mount_for_guest(InodeIdentifier inode) -> Mount*
|
||||
{
|
||||
for (auto& mount : m_mounts) {
|
||||
if (mount->guest() == inode)
|
||||
|
@ -240,7 +240,7 @@ auto VFS::findMountForGuest(InodeIdentifier inode) -> Mount*
|
|||
|
||||
bool VFS::is_vfs_root(InodeIdentifier inode) const
|
||||
{
|
||||
return inode == m_rootNode->inode;
|
||||
return inode == m_root_vnode->inode;
|
||||
}
|
||||
|
||||
void VFS::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(const FileSystem::DirectoryEntry&)> callback)
|
||||
|
@ -250,13 +250,13 @@ void VFS::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(
|
|||
|
||||
directoryInode.fileSystem()->enumerateDirectoryInode(directoryInode, [&] (const FileSystem::DirectoryEntry& entry) {
|
||||
InodeIdentifier resolvedInode;
|
||||
if (auto mount = findMountForHost(entry.inode))
|
||||
if (auto mount = find_mount_for_host(entry.inode))
|
||||
resolvedInode = mount->guest();
|
||||
else
|
||||
resolvedInode = entry.inode;
|
||||
|
||||
if (directoryInode.isRootInode() && !is_vfs_root(directoryInode) && !strcmp(entry.name, "..")) {
|
||||
auto mount = findMountForGuest(entry.inode);
|
||||
auto mount = find_mount_for_guest(entry.inode);
|
||||
ASSERT(mount);
|
||||
resolvedInode = mount->host();
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ void VFS::listDirectory(const String& path, InodeIdentifier base)
|
|||
if (!directoryInode.isValid())
|
||||
return;
|
||||
|
||||
kprintf("VFS: ls %s -> %s %02u:%08u\n", path.characters(), directoryInode.fileSystem()->className(), directoryInode.fileSystemID(), directoryInode.index());
|
||||
kprintf("VFS: ls %s -> %s %02u:%08u\n", path.characters(), directoryInode.fileSystem()->className(), directoryInode.fsid(), directoryInode.index());
|
||||
enumerateDirectoryInode(directoryInode, [&] (const FileSystem::DirectoryEntry& entry) {
|
||||
const char* nameColorBegin = "";
|
||||
const char* nameColorEnd = "";
|
||||
|
@ -295,7 +295,7 @@ void VFS::listDirectory(const String& path, InodeIdentifier base)
|
|||
nameColorEnd = "\033[0m";
|
||||
}
|
||||
kprintf("%02u:%08u ",
|
||||
metadata.inode.fileSystemID(),
|
||||
metadata.inode.fsid(),
|
||||
metadata.inode.index());
|
||||
|
||||
if (metadata.isDirectory())
|
||||
|
@ -395,7 +395,7 @@ void VFS::listDirectoryRecursively(const String& path, InodeIdentifier base)
|
|||
bool VFS::touch(const String& path)
|
||||
{
|
||||
int error;
|
||||
auto inode = resolvePath(path, error);
|
||||
auto inode = resolve_path(path, error);
|
||||
if (!inode.isValid())
|
||||
return false;
|
||||
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
||||
|
@ -413,7 +413,7 @@ RetainPtr<FileDescriptor> VFS::open(CharacterDevice& device, int options)
|
|||
|
||||
RetainPtr<FileDescriptor> VFS::open(const String& path, int& error, int options, InodeIdentifier base)
|
||||
{
|
||||
auto inode = resolvePath(path, error, base, options);
|
||||
auto inode = resolve_path(path, error, base, options);
|
||||
if (!inode.isValid())
|
||||
return nullptr;
|
||||
auto vnode = getOrCreateNode(inode);
|
||||
|
@ -427,7 +427,7 @@ RetainPtr<FileDescriptor> VFS::create(const String& path, InodeIdentifier base)
|
|||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
(void) base;
|
||||
m_rootNode->fileSystem()->createInode(m_rootNode->fileSystem()->rootInode(), "empty", 0100644, 0);
|
||||
m_root_vnode->fileSystem()->createInode(m_root_vnode->fileSystem()->rootInode(), "empty", 0100644, 0);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -436,20 +436,20 @@ RetainPtr<FileDescriptor> VFS::mkdir(const String& path, InodeIdentifier base)
|
|||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
(void) base;
|
||||
m_rootNode->fileSystem()->makeDirectory(m_rootNode->fileSystem()->rootInode(), "mydir", 0400755);
|
||||
m_root_vnode->fileSystem()->makeDirectory(m_root_vnode->fileSystem()->rootInode(), "mydir", 0400755);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||
{
|
||||
auto symlinkContents = symlinkInode.readEntireFile();
|
||||
if (!symlinkContents)
|
||||
auto symlink_contents = symlinkInode.readEntireFile();
|
||||
if (!symlink_contents)
|
||||
return { };
|
||||
auto linkee = String((const char*)symlinkContents.pointer(), symlinkContents.size());
|
||||
auto linkee = String((const char*)symlink_contents.pointer(), symlink_contents.size());
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("linkee (%s)(%u) from %u:%u\n", linkee.characters(), linkee.length(), base.fileSystemID(), base.index());
|
||||
kprintf("linkee (%s)(%u) from %u:%u\n", linkee.characters(), linkee.length(), base.fsid(), base.index());
|
||||
#endif
|
||||
return resolvePath(linkee, error, base);
|
||||
return resolve_path(linkee, error, base);
|
||||
}
|
||||
|
||||
RetainPtr<CoreInode> VFS::get_inode(InodeIdentifier inode_id)
|
||||
|
@ -464,37 +464,37 @@ String VFS::absolute_path(CoreInode& core_inode)
|
|||
int error;
|
||||
Vector<InodeIdentifier> lineage;
|
||||
RetainPtr<CoreInode> inode = &core_inode;
|
||||
while (inode->identifier() != m_rootNode->inode) {
|
||||
if (auto* mount = findMountForGuest(inode->identifier()))
|
||||
while (inode->identifier() != m_root_vnode->inode) {
|
||||
if (auto* mount = find_mount_for_guest(inode->identifier()))
|
||||
lineage.append(mount->host());
|
||||
else
|
||||
lineage.append(inode->identifier());
|
||||
|
||||
InodeIdentifier parent_id;
|
||||
if (inode->is_directory()) {
|
||||
parent_id = resolvePath("..", error, inode->identifier());
|
||||
parent_id = resolve_path("..", error, inode->identifier());
|
||||
} else {
|
||||
parent_id = inode->fs().findParentOfInode(inode->identifier());
|
||||
parent_id = inode->fs().find_parent_of_inode(inode->identifier());
|
||||
}
|
||||
ASSERT(parent_id.isValid());
|
||||
inode = get_inode(parent_id);
|
||||
}
|
||||
if (lineage.isEmpty())
|
||||
return "/";
|
||||
lineage.append(m_rootNode->inode);
|
||||
lineage.append(m_root_vnode->inode);
|
||||
StringBuilder builder;
|
||||
for (size_t i = lineage.size() - 1; i >= 1; --i) {
|
||||
auto& child = lineage[i - 1];
|
||||
auto parent = lineage[i];
|
||||
if (auto* mount = findMountForHost(parent))
|
||||
if (auto* mount = find_mount_for_host(parent))
|
||||
parent = mount->guest();
|
||||
builder.append('/');
|
||||
builder.append(parent.fileSystem()->nameOfChildInDirectory(parent, child));
|
||||
builder.append(parent.fileSystem()->name_of_child_in_directory(parent, child));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
InodeIdentifier VFS::resolvePath(const String& path, int& error, InodeIdentifier base, int options)
|
||||
InodeIdentifier VFS::resolve_path(const String& path, int& error, InodeIdentifier base, int options)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
return { };
|
||||
|
@ -503,12 +503,12 @@ InodeIdentifier VFS::resolvePath(const String& path, int& error, InodeIdentifier
|
|||
InodeIdentifier inode;
|
||||
|
||||
if (path[0] == '/')
|
||||
inode = m_rootNode->inode;
|
||||
inode = m_root_vnode->inode;
|
||||
else
|
||||
inode = base.isValid() ? base : m_rootNode->inode;
|
||||
inode = base.isValid() ? base : m_root_vnode->inode;
|
||||
|
||||
for (unsigned i = 0; i < parts.size(); ++i) {
|
||||
bool wasRootInodeAtHeadOfLoop = inode.isRootInode();
|
||||
bool inode_was_root_at_head_of_loop = inode.isRootInode();
|
||||
auto& part = parts[i];
|
||||
if (part.isEmpty())
|
||||
break;
|
||||
|
@ -522,36 +522,36 @@ InodeIdentifier VFS::resolvePath(const String& path, int& error, InodeIdentifier
|
|||
}
|
||||
if (!metadata.isDirectory()) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("parent of <%s> not directory, it's inode %u:%u / %u:%u, mode: %u, size: %u\n", part.characters(), inode.fileSystemID(), inode.index(), metadata.inode.fileSystemID(), metadata.inode.index(), metadata.mode, metadata.size);
|
||||
kprintf("parent of <%s> not directory, it's inode %u:%u / %u:%u, mode: %u, size: %u\n", part.characters(), inode.fsid(), inode.index(), metadata.inode.fsid(), metadata.inode.index(), metadata.mode, metadata.size);
|
||||
#endif
|
||||
error = -EIO;
|
||||
return { };
|
||||
}
|
||||
auto parent = inode;
|
||||
inode = inode.fileSystem()->childOfDirectoryInodeWithName(inode, part);
|
||||
inode = inode.fileSystem()->child_of_directory_inode_with_name(inode, part);
|
||||
if (!inode.isValid()) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("child <%s>(%u) not found in directory, %02u:%08u\n", part.characters(), part.length(), parent.fileSystemID(), parent.index());
|
||||
kprintf("child <%s>(%u) not found in directory, %02u:%08u\n", part.characters(), part.length(), parent.fsid(), parent.index());
|
||||
#endif
|
||||
error = -ENOENT;
|
||||
return { };
|
||||
}
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("<%s> %u:%u\n", part.characters(), inode.fileSystemID(), inode.index());
|
||||
kprintf("<%s> %u:%u\n", part.characters(), inode.fsid(), inode.index());
|
||||
#endif
|
||||
if (auto mount = findMountForHost(inode)) {
|
||||
if (auto mount = find_mount_for_host(inode)) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf(" -- is host\n");
|
||||
#endif
|
||||
inode = mount->guest();
|
||||
}
|
||||
if (wasRootInodeAtHeadOfLoop && inode.isRootInode() && !is_vfs_root(inode) && part == "..") {
|
||||
if (inode_was_root_at_head_of_loop && inode.isRootInode() && !is_vfs_root(inode) && part == "..") {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf(" -- is guest\n");
|
||||
#endif
|
||||
auto mount = findMountForGuest(inode);
|
||||
auto mount = find_mount_for_guest(inode);
|
||||
inode = mount->host();
|
||||
inode = inode.fileSystem()->childOfDirectoryInodeWithName(inode, "..");
|
||||
inode = inode.fileSystem()->child_of_directory_inode_with_name(inode, "..");
|
||||
}
|
||||
metadata = inode.metadata();
|
||||
if (metadata.isSymbolicLink()) {
|
||||
|
@ -605,12 +605,12 @@ VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
|||
{
|
||||
}
|
||||
|
||||
void VFS::registerCharacterDevice(CharacterDevice& device)
|
||||
void VFS::register_character_device(CharacterDevice& device)
|
||||
{
|
||||
m_characterDevices.set(encodedDevice(device.major(), device.minor()), &device);
|
||||
m_character_devices.set(encodedDevice(device.major(), device.minor()), &device);
|
||||
}
|
||||
|
||||
void VFS::forEachMount(Function<void(const Mount&)> callback) const
|
||||
void VFS::for_each_mount(Function<void(const Mount&)> callback) const
|
||||
{
|
||||
for (auto& mount : m_mounts) {
|
||||
callback(*mount);
|
||||
|
|
|
@ -76,7 +76,7 @@ class VFS {
|
|||
AK_MAKE_ETERNAL
|
||||
friend ByteBuffer procfs$vnodes();
|
||||
public:
|
||||
static void initializeGlobals();
|
||||
static void initialize_globals();
|
||||
|
||||
class Mount {
|
||||
public:
|
||||
|
@ -104,13 +104,13 @@ public:
|
|||
void listDirectoryRecursively(const String& path, InodeIdentifier base);
|
||||
#endif
|
||||
|
||||
unsigned maxNodeCount() const { return m_maxNodeCount; }
|
||||
unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); }
|
||||
unsigned max_vnode_count() const { return m_max_vnode_count; }
|
||||
unsigned allocated_vnode_count() const { return m_max_vnode_count - m_vnode_freelist.size(); }
|
||||
|
||||
Vnode* root() { return m_rootNode.ptr(); }
|
||||
const Vnode* root() const { return m_rootNode.ptr(); }
|
||||
Vnode* root() { return m_root_vnode.ptr(); }
|
||||
const Vnode* root() const { return m_root_vnode.ptr(); }
|
||||
|
||||
bool mountRoot(RetainPtr<FileSystem>&&);
|
||||
bool mount_root(RetainPtr<FileSystem>&&);
|
||||
bool mount(RetainPtr<FileSystem>&&, const String& path);
|
||||
|
||||
RetainPtr<FileDescriptor> open(CharacterDevice&, int options);
|
||||
|
@ -120,10 +120,10 @@ public:
|
|||
|
||||
bool touch(const String&path);
|
||||
|
||||
void registerCharacterDevice(CharacterDevice&);
|
||||
void register_character_device(CharacterDevice&);
|
||||
|
||||
size_t mountCount() const { return m_mounts.size(); }
|
||||
void forEachMount(Function<void(const Mount&)>) const;
|
||||
size_t mount_count() const { return m_mounts.size(); }
|
||||
void for_each_mount(Function<void(const Mount&)>) const;
|
||||
|
||||
String absolute_path(CoreInode&);
|
||||
|
||||
|
@ -137,7 +137,7 @@ private:
|
|||
|
||||
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
|
||||
InodeIdentifier resolve_path(const String& path, int& error, CoreInode& base, int options = 0);
|
||||
InodeIdentifier resolvePath(const String& path, int& error, InodeIdentifier base = InodeIdentifier(), int options = 0);
|
||||
InodeIdentifier resolve_path(const String& path, int& error, InodeIdentifier base = InodeIdentifier(), int options = 0);
|
||||
InodeIdentifier resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
|
||||
|
||||
RetainPtr<Vnode> allocateNode();
|
||||
|
@ -148,21 +148,21 @@ private:
|
|||
RetainPtr<Vnode> getOrCreateNode(InodeIdentifier);
|
||||
RetainPtr<Vnode> getOrCreateNode(CharacterDevice&);
|
||||
|
||||
Mount* findMountForHost(InodeIdentifier);
|
||||
Mount* findMountForGuest(InodeIdentifier);
|
||||
Mount* find_mount_for_host(InodeIdentifier);
|
||||
Mount* find_mount_for_guest(InodeIdentifier);
|
||||
|
||||
HashMap<InodeIdentifier, Vnode*> m_inode2vnode;
|
||||
HashMap<dword, Vnode*> m_device2vnode;
|
||||
|
||||
Vector<OwnPtr<Mount>> m_mounts;
|
||||
|
||||
unsigned m_maxNodeCount { 0 };
|
||||
unsigned m_max_vnode_count { 0 };
|
||||
Vnode* m_nodes { nullptr };
|
||||
|
||||
Vector<Vnode*> m_nodeFreeList;
|
||||
Vector<Vnode*> m_vnode_freelist;
|
||||
|
||||
RetainPtr<Vnode> m_rootNode;
|
||||
RetainPtr<Vnode> m_root_vnode;
|
||||
|
||||
HashMap<dword, CharacterDevice*> m_characterDevices;
|
||||
HashMap<dword, CharacterDevice*> m_character_devices;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,23 +22,23 @@ int main(int c, char** v)
|
|||
if (c >= 2)
|
||||
filename = v[1];
|
||||
|
||||
VFS::initializeGlobals();
|
||||
VFS::initialize_globals();
|
||||
|
||||
VFS vfs;
|
||||
|
||||
auto zero = make<ZeroDevice>();
|
||||
vfs.registerCharacterDevice(*zero);
|
||||
vfs.register_character_device(*zero);
|
||||
|
||||
auto null = make<NullDevice>();
|
||||
vfs.registerCharacterDevice(*null);
|
||||
vfs.register_character_device(*null);
|
||||
|
||||
auto full = make<FullDevice>();
|
||||
vfs.registerCharacterDevice(*full);
|
||||
vfs.register_character_device(*full);
|
||||
|
||||
auto random = make<RandomDevice>();
|
||||
vfs.registerCharacterDevice(*random);
|
||||
vfs.register_character_device(*random);
|
||||
|
||||
if (!vfs.mountRoot(makeFileSystem(filename))) {
|
||||
if (!vfs.mount_root(makeFileSystem(filename))) {
|
||||
printf("Failed to mount root :(\n");
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue