1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:27:35 +00:00

A pass of style/naming cleanup in VFS.

This commit is contained in:
Andreas Kling 2018-11-15 15:10:12 +01:00
parent 457a5df7d5
commit 396a32835b
12 changed files with 120 additions and 120 deletions

View file

@ -214,15 +214,15 @@ ByteBuffer procfs$regions()
ByteBuffer procfs$mounts() ByteBuffer procfs$mounts()
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
auto buffer = ByteBuffer::createUninitialized(VFS::the().mountCount() * 80); auto buffer = ByteBuffer::createUninitialized(VFS::the().mount_count() * 80);
char* ptr = (char*)buffer.pointer(); char* ptr = (char*)buffer.pointer();
VFS::the().forEachMount([&ptr] (auto& mount) { VFS::the().for_each_mount([&ptr] (auto& mount) {
auto& fs = mount.fileSystem(); auto& fs = mount.fileSystem();
ptr += ksprintf(ptr, "%s @ ", fs.className()); ptr += ksprintf(ptr, "%s @ ", fs.className());
if (!mount.host().isValid()) if (!mount.host().isValid())
ptr += ksprintf(ptr, "/\n", fs.className()); ptr += ksprintf(ptr, "/\n", fs.className());
else 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()); buffer.trim(ptr - (char*)buffer.pointer());
return buffer; return buffer;
@ -331,9 +331,9 @@ ByteBuffer procfs$summary()
ByteBuffer procfs$vnodes() ByteBuffer procfs$vnodes()
{ {
auto& vfs = VFS::the(); 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(); 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]; auto& vnode = vfs.m_nodes[i];
// FIXME: Retain the vnode while inspecting it. // FIXME: Retain the vnode while inspecting it.
if (!vnode.inUse()) if (!vnode.inUse())
@ -347,7 +347,7 @@ ByteBuffer procfs$vnodes()
path = static_cast<const TTY*>(dev)->ttyName(); 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'; *ptr = '\0';
buffer.trim(ptr - (char*)buffer.pointer()); buffer.trim(ptr - (char*)buffer.pointer());

View file

@ -176,29 +176,29 @@ static void init_stage2()
auto vfs = make<VFS>(); auto vfs = make<VFS>();
auto dev_zero = make<ZeroDevice>(); auto dev_zero = make<ZeroDevice>();
vfs->registerCharacterDevice(*dev_zero); vfs->register_character_device(*dev_zero);
auto dev_null = make<NullDevice>(); auto dev_null = make<NullDevice>();
vfs->registerCharacterDevice(*dev_null); vfs->register_character_device(*dev_null);
auto dev_full = make<FullDevice>(); auto dev_full = make<FullDevice>();
vfs->registerCharacterDevice(*dev_full); vfs->register_character_device(*dev_full);
auto dev_random = make<RandomDevice>(); 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->register_character_device(*tty0);
vfs->registerCharacterDevice(*tty1); vfs->register_character_device(*tty1);
vfs->registerCharacterDevice(*tty2); vfs->register_character_device(*tty2);
vfs->registerCharacterDevice(*tty3); vfs->register_character_device(*tty3);
auto dev_hd0 = IDEDiskDevice::create(); auto dev_hd0 = IDEDiskDevice::create();
auto e2fs = Ext2FileSystem::create(dev_hd0.copyRef()); auto e2fs = Ext2FileSystem::create(dev_hd0.copyRef());
e2fs->initialize(); e2fs->initialize();
vfs->mountRoot(e2fs.copyRef()); vfs->mount_root(e2fs.copyRef());
#ifdef KSYMS #ifdef KSYMS
{ {
@ -267,7 +267,7 @@ void init()
MemoryManager::initialize(); MemoryManager::initialize();
VFS::initializeGlobals(); VFS::initialize_globals();
StringImpl::initializeGlobals(); StringImpl::initializeGlobals();
PIT::initialize(); PIT::initialize();

View file

@ -220,7 +220,7 @@ auto Ext2FileSystem::lookupExt2Inode(unsigned inode) const -> CachedExt2Inode
InodeMetadata Ext2FileSystem::inodeMetadata(InodeIdentifier inode) const InodeMetadata Ext2FileSystem::inodeMetadata(InodeIdentifier inode) const
{ {
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
auto e2inode = lookupExt2Inode(inode.index()); auto e2inode = lookupExt2Inode(inode.index());
if (!e2inode) if (!e2inode)
@ -344,7 +344,7 @@ void Ext2Inode::populate_metadata() const
RetainPtr<CoreInode> Ext2FileSystem::get_inode(InodeIdentifier inode) const RetainPtr<CoreInode> Ext2FileSystem::get_inode(InodeIdentifier inode) const
{ {
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
{ {
LOCKER(m_inode_cache_lock); LOCKER(m_inode_cache_lock);
auto it = m_inode_cache.find(inode.index()); 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 Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const
{ {
ASSERT(offset >= 0); ASSERT(offset >= 0);
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
auto e2inode = lookupExt2Inode(inode.index()); auto e2inode = lookupExt2Inode(inode.index());
if (!e2inode) { if (!e2inode) {
@ -503,7 +503,7 @@ Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t
bool Ext2FileSystem::writeInode(InodeIdentifier inode, const ByteBuffer& data) bool Ext2FileSystem::writeInode(InodeIdentifier inode, const ByteBuffer& data)
{ {
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
auto e2inode = lookupExt2Inode(inode.index()); auto e2inode = lookupExt2Inode(inode.index());
if (!e2inode) { 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 bool Ext2FileSystem::enumerateDirectoryInode(InodeIdentifier inode, Function<bool(const DirectoryEntry&)> callback) const
{ {
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
ASSERT(isDirectoryInode(inode.index())); ASSERT(isDirectoryInode(inode.index()));
#ifdef EXT2_DEBUG #ifdef EXT2_DEBUG
@ -780,7 +780,7 @@ bool Ext2FileSystem::modifyLinkCount(InodeIndex inode, int delta)
bool Ext2FileSystem::setModificationTime(InodeIdentifier inode, dword timestamp) bool Ext2FileSystem::setModificationTime(InodeIdentifier inode, dword timestamp)
{ {
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
auto e2inode = lookupExt2Inode(inode.index()); auto e2inode = lookupExt2Inode(inode.index());
if (!e2inode) 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) InodeIdentifier Ext2FileSystem::makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode)
{ {
ASSERT(parentInode.fileSystemID() == id()); ASSERT(parentInode.fsid() == id());
ASSERT(isDirectoryInode(parentInode.index())); ASSERT(isDirectoryInode(parentInode.index()));
// Fix up the mode to definitely be a directory. // 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) 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())); ASSERT(isDirectoryInode(parentInode.index()));
//#ifdef EXT2_DEBUG //#ifdef EXT2_DEBUG
@ -1119,7 +1119,7 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S
return { id(), inode }; 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); auto inode = get_inode(inode_id);
ASSERT(inode); ASSERT(inode);

View file

@ -75,7 +75,7 @@ private:
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override; 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 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 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; virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
bool isDirectoryInode(unsigned) const; bool isDirectoryInode(unsigned) const;

View file

@ -37,7 +37,7 @@ FileSystem* FileSystem::fromID(dword id)
return nullptr; 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; InodeIdentifier foundInode;
enumerateDirectoryInode(inode, [&] (const DirectoryEntry& entry) { enumerateDirectoryInode(inode, [&] (const DirectoryEntry& entry) {
@ -50,7 +50,7 @@ InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode,
return foundInode; return foundInode;
} }
String FileSystem::nameOfChildInDirectory(InodeIdentifier parent, InodeIdentifier child) const String FileSystem::name_of_child_in_directory(InodeIdentifier parent, InodeIdentifier child) const
{ {
String name; String name;
bool success = enumerateDirectoryInode(parent, [&] (auto& entry) { bool success = enumerateDirectoryInode(parent, [&] (auto& entry) {
@ -98,7 +98,7 @@ ByteBuffer CoreInode::read_entire(FileDescriptor* descriptor)
ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode, FileDescriptor* handle) const ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode, FileDescriptor* handle) const
{ {
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
auto metadata = inodeMetadata(inode); auto metadata = inodeMetadata(inode);
if (!metadata.isValid()) { if (!metadata.isValid()) {

View file

@ -49,13 +49,13 @@ public:
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) = 0; 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 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; 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; 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: protected:
FileSystem(); FileSystem();
@ -133,8 +133,8 @@ namespace AK {
template<> template<>
struct Traits<InodeIdentifier> { struct Traits<InodeIdentifier> {
// FIXME: This is a shitty hash. // FIXME: This is a shitty hash.
static unsigned hash(const InodeIdentifier& inode) { return Traits<unsigned>::hash(inode.fileSystemID()) + Traits<unsigned>::hash(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.fileSystemID(), inode.index()); } static void dump(const InodeIdentifier& inode) { kprintf("%02u:%08u", inode.fsid(), inode.index()); }
}; };
} }

View file

@ -17,7 +17,7 @@ public:
bool isValid() const { return m_fileSystemID != 0 && m_index != 0; } 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; } dword index() const { return m_index; }
FileSystem* fileSystem(); FileSystem* fileSystem();

View file

@ -134,7 +134,7 @@ InodeIdentifier SyntheticFileSystem::rootInode() const
bool SyntheticFileSystem::enumerateDirectoryInode(InodeIdentifier inode, Function<bool(const DirectoryEntry&)> callback) const bool SyntheticFileSystem::enumerateDirectoryInode(InodeIdentifier inode, Function<bool(const DirectoryEntry&)> callback) const
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
#ifdef SYNTHFS_DEBUG #ifdef SYNTHFS_DEBUG
kprintf("synthfs: enumerateDirectoryInode %u\n", inode.index()); kprintf("synthfs: enumerateDirectoryInode %u\n", inode.index());
#endif #endif
@ -161,7 +161,7 @@ bool SyntheticFileSystem::enumerateDirectoryInode(InodeIdentifier inode, Functio
InodeMetadata SyntheticFileSystem::inodeMetadata(InodeIdentifier inode) const InodeMetadata SyntheticFileSystem::inodeMetadata(InodeIdentifier inode) const
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
ASSERT(inode.fileSystemID() == id()); ASSERT(inode.fsid() == id());
#ifdef SYNTHFS_DEBUG #ifdef SYNTHFS_DEBUG
kprintf("SynthFS: inodeMetadata(%u)\n", inode.index()); kprintf("SynthFS: inodeMetadata(%u)\n", inode.index());
#endif #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 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 #ifdef SYNTHFS_DEBUG
kprintf("SynthFS: readInode %u\n", inode.index()); kprintf("SynthFS: readInode %u\n", inode.index());
#endif #endif
@ -245,7 +245,7 @@ auto SyntheticFileSystem::generateInodeIndex() -> InodeIndex
return m_nextInodeIndex++; 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()); auto it = m_inodes.find(inode.index());
if (it == m_inodes.end()) if (it == m_inodes.end())

View file

@ -21,7 +21,7 @@ public:
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override; 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 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 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; virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
protected: protected:

View file

@ -22,7 +22,7 @@ VFS& VFS::the()
return *s_the; return *s_the;
} }
void VFS::initializeGlobals() void VFS::initialize_globals()
{ {
s_the = nullptr; s_the = nullptr;
FileSystem::initializeGlobals(); FileSystem::initializeGlobals();
@ -34,17 +34,17 @@ VFS::VFS()
kprintf("VFS: Constructing VFS\n"); kprintf("VFS: Constructing VFS\n");
#endif #endif
s_the = this; s_the = this;
m_maxNodeCount = 16; m_max_vnode_count = 16;
m_nodes = reinterpret_cast<Vnode*>(kmalloc(sizeof(Vnode) * maxNodeCount())); m_nodes = reinterpret_cast<Vnode*>(kmalloc(sizeof(Vnode) * max_vnode_count()));
memset(m_nodes, 0, sizeof(Vnode) * maxNodeCount()); memset(m_nodes, 0, sizeof(Vnode) * max_vnode_count());
for (unsigned i = 0; i < m_maxNodeCount; ++i) for (unsigned i = 0; i < m_max_vnode_count; ++i)
m_nodeFreeList.append(&m_nodes[i]); m_vnode_freelist.append(&m_nodes[i]);
} }
VFS::~VFS() 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? // FIXME: m_nodes is never freed. Does it matter though?
} }
@ -62,8 +62,8 @@ auto VFS::makeNode(InodeIdentifier inode) -> RetainPtr<Vnode>
CharacterDevice* characterDevice = nullptr; CharacterDevice* characterDevice = nullptr;
if (metadata.isCharacterDevice()) { if (metadata.isCharacterDevice()) {
auto it = m_characterDevices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice)); auto it = m_character_devices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice));
if (it != m_characterDevices.end()) { if (it != m_character_devices.end()) {
characterDevice = (*it).value; characterDevice = (*it).value;
} else { } else {
kprintf("VFS: makeNode() no such character device %u,%u\n", metadata.majorDevice, metadata.minorDevice); 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); ASSERT(fileSystem);
int error; int error;
auto inode = resolvePath(path, error); auto inode = resolve_path(path, error);
if (!inode.isValid()) { if (!inode.isValid()) {
kprintf("VFS: mount can't resolve mount point '%s'\n", path.characters()); kprintf("VFS: mount can't resolve mount point '%s'\n", path.characters());
return false; return false;
@ -146,10 +146,10 @@ bool VFS::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
return true; return true;
} }
bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem) bool VFS::mount_root(RetainPtr<FileSystem>&& fileSystem)
{ {
if (m_rootNode) { if (m_root_vnode) {
kprintf("VFS: mountRoot can't mount another root\n"); kprintf("VFS: mount_root can't mount another root\n");
return false; return false;
} }
@ -165,11 +165,11 @@ bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
return false; return false;
} }
m_rootNode = move(node); m_root_vnode = move(node);
kprintf("VFS: mounted root on %s{%p}\n", kprintf("VFS: mounted root on %s{%p}\n",
m_rootNode->fileSystem()->className(), m_root_vnode->fileSystem()->className(),
m_rootNode->fileSystem()); m_root_vnode->fileSystem());
m_mounts.append(move(mount)); m_mounts.append(move(mount));
return true; return true;
@ -177,11 +177,11 @@ bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
auto VFS::allocateNode() -> RetainPtr<Vnode> auto VFS::allocateNode() -> RetainPtr<Vnode>
{ {
if (m_nodeFreeList.isEmpty()) { if (m_vnode_freelist.isEmpty()) {
kprintf("VFS: allocateNode has no nodes left\n"); kprintf("VFS: allocateNode has no nodes left\n");
return nullptr; return nullptr;
} }
auto* node = m_nodeFreeList.takeLast(); auto* node = m_vnode_freelist.takeLast();
ASSERT(node->retainCount == 0); ASSERT(node->retainCount == 0);
node->retainCount = 1; node->retainCount = 1;
node->m_vfs = this; node->m_vfs = this;
@ -205,7 +205,7 @@ void VFS::freeNode(Vnode* node)
} }
node->m_vfs = nullptr; node->m_vfs = nullptr;
node->m_vmo = nullptr; node->m_vmo = nullptr;
m_nodeFreeList.append(move(node)); m_vnode_freelist.append(move(node));
} }
#ifndef SERENITY #ifndef SERENITY
@ -220,7 +220,7 @@ bool VFS::isDirectory(const String& path, InodeIdentifier base)
} }
#endif #endif
auto VFS::findMountForHost(InodeIdentifier inode) -> Mount* auto VFS::find_mount_for_host(InodeIdentifier inode) -> Mount*
{ {
for (auto& mount : m_mounts) { for (auto& mount : m_mounts) {
if (mount->host() == inode) if (mount->host() == inode)
@ -229,7 +229,7 @@ auto VFS::findMountForHost(InodeIdentifier inode) -> Mount*
return nullptr; return nullptr;
} }
auto VFS::findMountForGuest(InodeIdentifier inode) -> Mount* auto VFS::find_mount_for_guest(InodeIdentifier inode) -> Mount*
{ {
for (auto& mount : m_mounts) { for (auto& mount : m_mounts) {
if (mount->guest() == inode) if (mount->guest() == inode)
@ -240,7 +240,7 @@ auto VFS::findMountForGuest(InodeIdentifier inode) -> Mount*
bool VFS::is_vfs_root(InodeIdentifier inode) const 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) 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) { directoryInode.fileSystem()->enumerateDirectoryInode(directoryInode, [&] (const FileSystem::DirectoryEntry& entry) {
InodeIdentifier resolvedInode; InodeIdentifier resolvedInode;
if (auto mount = findMountForHost(entry.inode)) if (auto mount = find_mount_for_host(entry.inode))
resolvedInode = mount->guest(); resolvedInode = mount->guest();
else else
resolvedInode = entry.inode; resolvedInode = entry.inode;
if (directoryInode.isRootInode() && !is_vfs_root(directoryInode) && !strcmp(entry.name, "..")) { 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); ASSERT(mount);
resolvedInode = mount->host(); resolvedInode = mount->host();
} }
@ -273,7 +273,7 @@ void VFS::listDirectory(const String& path, InodeIdentifier base)
if (!directoryInode.isValid()) if (!directoryInode.isValid())
return; 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) { enumerateDirectoryInode(directoryInode, [&] (const FileSystem::DirectoryEntry& entry) {
const char* nameColorBegin = ""; const char* nameColorBegin = "";
const char* nameColorEnd = ""; const char* nameColorEnd = "";
@ -295,7 +295,7 @@ void VFS::listDirectory(const String& path, InodeIdentifier base)
nameColorEnd = "\033[0m"; nameColorEnd = "\033[0m";
} }
kprintf("%02u:%08u ", kprintf("%02u:%08u ",
metadata.inode.fileSystemID(), metadata.inode.fsid(),
metadata.inode.index()); metadata.inode.index());
if (metadata.isDirectory()) if (metadata.isDirectory())
@ -395,7 +395,7 @@ void VFS::listDirectoryRecursively(const String& path, InodeIdentifier base)
bool VFS::touch(const String& path) bool VFS::touch(const String& path)
{ {
int error; int error;
auto inode = resolvePath(path, error); auto inode = resolve_path(path, error);
if (!inode.isValid()) if (!inode.isValid())
return false; return false;
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr)); 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) 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()) if (!inode.isValid())
return nullptr; return nullptr;
auto vnode = getOrCreateNode(inode); 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! // FIXME: Do the real thing, not just this fake thing!
(void) path; (void) path;
(void) base; (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; 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! // FIXME: Do the real thing, not just this fake thing!
(void) path; (void) path;
(void) base; (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; return nullptr;
} }
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error) InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
{ {
auto symlinkContents = symlinkInode.readEntireFile(); auto symlink_contents = symlinkInode.readEntireFile();
if (!symlinkContents) if (!symlink_contents)
return { }; return { };
auto linkee = String((const char*)symlinkContents.pointer(), symlinkContents.size()); auto linkee = String((const char*)symlink_contents.pointer(), symlink_contents.size());
#ifdef VFS_DEBUG #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 #endif
return resolvePath(linkee, error, base); return resolve_path(linkee, error, base);
} }
RetainPtr<CoreInode> VFS::get_inode(InodeIdentifier inode_id) RetainPtr<CoreInode> VFS::get_inode(InodeIdentifier inode_id)
@ -464,37 +464,37 @@ String VFS::absolute_path(CoreInode& core_inode)
int error; int error;
Vector<InodeIdentifier> lineage; Vector<InodeIdentifier> lineage;
RetainPtr<CoreInode> inode = &core_inode; RetainPtr<CoreInode> inode = &core_inode;
while (inode->identifier() != m_rootNode->inode) { while (inode->identifier() != m_root_vnode->inode) {
if (auto* mount = findMountForGuest(inode->identifier())) if (auto* mount = find_mount_for_guest(inode->identifier()))
lineage.append(mount->host()); lineage.append(mount->host());
else else
lineage.append(inode->identifier()); lineage.append(inode->identifier());
InodeIdentifier parent_id; InodeIdentifier parent_id;
if (inode->is_directory()) { if (inode->is_directory()) {
parent_id = resolvePath("..", error, inode->identifier()); parent_id = resolve_path("..", error, inode->identifier());
} else { } else {
parent_id = inode->fs().findParentOfInode(inode->identifier()); parent_id = inode->fs().find_parent_of_inode(inode->identifier());
} }
ASSERT(parent_id.isValid()); ASSERT(parent_id.isValid());
inode = get_inode(parent_id); inode = get_inode(parent_id);
} }
if (lineage.isEmpty()) if (lineage.isEmpty())
return "/"; return "/";
lineage.append(m_rootNode->inode); lineage.append(m_root_vnode->inode);
StringBuilder builder; StringBuilder builder;
for (size_t i = lineage.size() - 1; i >= 1; --i) { for (size_t i = lineage.size() - 1; i >= 1; --i) {
auto& child = lineage[i - 1]; auto& child = lineage[i - 1];
auto parent = lineage[i]; auto parent = lineage[i];
if (auto* mount = findMountForHost(parent)) if (auto* mount = find_mount_for_host(parent))
parent = mount->guest(); parent = mount->guest();
builder.append('/'); builder.append('/');
builder.append(parent.fileSystem()->nameOfChildInDirectory(parent, child)); builder.append(parent.fileSystem()->name_of_child_in_directory(parent, child));
} }
return builder.build(); 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()) if (path.isEmpty())
return { }; return { };
@ -503,12 +503,12 @@ InodeIdentifier VFS::resolvePath(const String& path, int& error, InodeIdentifier
InodeIdentifier inode; InodeIdentifier inode;
if (path[0] == '/') if (path[0] == '/')
inode = m_rootNode->inode; inode = m_root_vnode->inode;
else else
inode = base.isValid() ? base : m_rootNode->inode; inode = base.isValid() ? base : m_root_vnode->inode;
for (unsigned i = 0; i < parts.size(); ++i) { 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]; auto& part = parts[i];
if (part.isEmpty()) if (part.isEmpty())
break; break;
@ -522,36 +522,36 @@ InodeIdentifier VFS::resolvePath(const String& path, int& error, InodeIdentifier
} }
if (!metadata.isDirectory()) { if (!metadata.isDirectory()) {
#ifdef VFS_DEBUG #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 #endif
error = -EIO; error = -EIO;
return { }; return { };
} }
auto parent = inode; auto parent = inode;
inode = inode.fileSystem()->childOfDirectoryInodeWithName(inode, part); inode = inode.fileSystem()->child_of_directory_inode_with_name(inode, part);
if (!inode.isValid()) { if (!inode.isValid()) {
#ifdef VFS_DEBUG #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 #endif
error = -ENOENT; error = -ENOENT;
return { }; return { };
} }
#ifdef VFS_DEBUG #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 #endif
if (auto mount = findMountForHost(inode)) { if (auto mount = find_mount_for_host(inode)) {
#ifdef VFS_DEBUG #ifdef VFS_DEBUG
kprintf(" -- is host\n"); kprintf(" -- is host\n");
#endif #endif
inode = mount->guest(); 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 #ifdef VFS_DEBUG
kprintf(" -- is guest\n"); kprintf(" -- is guest\n");
#endif #endif
auto mount = findMountForGuest(inode); auto mount = find_mount_for_guest(inode);
inode = mount->host(); inode = mount->host();
inode = inode.fileSystem()->childOfDirectoryInodeWithName(inode, ".."); inode = inode.fileSystem()->child_of_directory_inode_with_name(inode, "..");
} }
metadata = inode.metadata(); metadata = inode.metadata();
if (metadata.isSymbolicLink()) { 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) { for (auto& mount : m_mounts) {
callback(*mount); callback(*mount);

View file

@ -76,7 +76,7 @@ class VFS {
AK_MAKE_ETERNAL AK_MAKE_ETERNAL
friend ByteBuffer procfs$vnodes(); friend ByteBuffer procfs$vnodes();
public: public:
static void initializeGlobals(); static void initialize_globals();
class Mount { class Mount {
public: public:
@ -104,13 +104,13 @@ public:
void listDirectoryRecursively(const String& path, InodeIdentifier base); void listDirectoryRecursively(const String& path, InodeIdentifier base);
#endif #endif
unsigned maxNodeCount() const { return m_maxNodeCount; } unsigned max_vnode_count() const { return m_max_vnode_count; }
unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); } unsigned allocated_vnode_count() const { return m_max_vnode_count - m_vnode_freelist.size(); }
Vnode* root() { return m_rootNode.ptr(); } Vnode* root() { return m_root_vnode.ptr(); }
const Vnode* root() const { return m_rootNode.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); bool mount(RetainPtr<FileSystem>&&, const String& path);
RetainPtr<FileDescriptor> open(CharacterDevice&, int options); RetainPtr<FileDescriptor> open(CharacterDevice&, int options);
@ -120,10 +120,10 @@ public:
bool touch(const String&path); bool touch(const String&path);
void registerCharacterDevice(CharacterDevice&); void register_character_device(CharacterDevice&);
size_t mountCount() const { return m_mounts.size(); } size_t mount_count() const { return m_mounts.size(); }
void forEachMount(Function<void(const Mount&)>) const; void for_each_mount(Function<void(const Mount&)>) const;
String absolute_path(CoreInode&); String absolute_path(CoreInode&);
@ -137,7 +137,7 @@ private:
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>); void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
InodeIdentifier resolve_path(const String& path, int& error, CoreInode& base, int options = 0); 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); InodeIdentifier resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
RetainPtr<Vnode> allocateNode(); RetainPtr<Vnode> allocateNode();
@ -148,21 +148,21 @@ private:
RetainPtr<Vnode> getOrCreateNode(InodeIdentifier); RetainPtr<Vnode> getOrCreateNode(InodeIdentifier);
RetainPtr<Vnode> getOrCreateNode(CharacterDevice&); RetainPtr<Vnode> getOrCreateNode(CharacterDevice&);
Mount* findMountForHost(InodeIdentifier); Mount* find_mount_for_host(InodeIdentifier);
Mount* findMountForGuest(InodeIdentifier); Mount* find_mount_for_guest(InodeIdentifier);
HashMap<InodeIdentifier, Vnode*> m_inode2vnode; HashMap<InodeIdentifier, Vnode*> m_inode2vnode;
HashMap<dword, Vnode*> m_device2vnode; HashMap<dword, Vnode*> m_device2vnode;
Vector<OwnPtr<Mount>> m_mounts; Vector<OwnPtr<Mount>> m_mounts;
unsigned m_maxNodeCount { 0 }; unsigned m_max_vnode_count { 0 };
Vnode* m_nodes { nullptr }; 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;
}; };

View file

@ -22,23 +22,23 @@ int main(int c, char** v)
if (c >= 2) if (c >= 2)
filename = v[1]; filename = v[1];
VFS::initializeGlobals(); VFS::initialize_globals();
VFS vfs; VFS vfs;
auto zero = make<ZeroDevice>(); auto zero = make<ZeroDevice>();
vfs.registerCharacterDevice(*zero); vfs.register_character_device(*zero);
auto null = make<NullDevice>(); auto null = make<NullDevice>();
vfs.registerCharacterDevice(*null); vfs.register_character_device(*null);
auto full = make<FullDevice>(); auto full = make<FullDevice>();
vfs.registerCharacterDevice(*full); vfs.register_character_device(*full);
auto random = make<RandomDevice>(); 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"); printf("Failed to mount root :(\n");
return 1; return 1;
} }