#define MODULE "vfs" #include "fs/VFS.h" #include "log/Log.h" #include "std/string.h" static VFS::Node* vfs_root; ssize_t VFS::read(Node* node, size_t offset, size_t length, char* buffer) { if (!node) { kwarnln("read() failed: trying to read from nullptr"); return -1; } if (!node->read_func) { kwarnln("read() failed: the chosen node doesn't support reading"); return -1; } kdbgln("read(): node %s (inode %ld), offset %zd, %zd bytes, into %p", node->name, node->inode, offset, length, (void*)buffer); return node->read_func(node, offset, length, buffer); } VFS::Node* VFS::open(const char* filename) { if (!vfs_root) { kwarnln("open() failed: root not mounted"); return 0; } if (!vfs_root->find_func) { kwarnln("open() failed: root doesn't support finding files"); return 0; } kinfoln("open(): opening %s", filename); return vfs_root->find_func(vfs_root, filename); } void VFS::mount_root(Node* root) { if (!root) { kwarnln("mount_root() failed: attempted to mount nullptr"); return; } if (vfs_root) { kwarnln("mount_root() failed: root filesystem already mounted"); return; } kinfoln("mounting node '%s' as vfs root", root->name); vfs_root = root; } VFS::Node* VFS::root() { return vfs_root; }