#define MODULE "vfs" #include "fs/VFS.h" #include "log/Log.h" static VFS::Node* vfs_root; int32_t VFS::read(Node* node, uint32_t offset, uint32_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; } 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; } 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; }