diff options
Diffstat (limited to 'Source/Kernel/VFS')
-rw-r--r-- | Source/Kernel/VFS/DirectoryNode.class.cpp | 2 | ||||
-rw-r--r-- | Source/Kernel/VFS/FileSystem.proto.h | 2 | ||||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.cpp | 5 | ||||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.h | 2 | ||||
-rw-r--r-- | Source/Kernel/VFS/VFS.ns.cpp | 75 | ||||
-rw-r--r-- | Source/Kernel/VFS/VFS.ns.h | 6 |
6 files changed, 90 insertions, 2 deletions
diff --git a/Source/Kernel/VFS/DirectoryNode.class.cpp b/Source/Kernel/VFS/DirectoryNode.class.cpp index 7da6fe6..55365f0 100644 --- a/Source/Kernel/VFS/DirectoryNode.class.cpp +++ b/Source/Kernel/VFS/DirectoryNode.class.cpp @@ -12,7 +12,7 @@ DirectoryNode::~DirectoryNode() { delete m_children[i]; } } - if (m_name == "/") ((DirectoryNode*)(m_parent))->unmount(); + if (m_name == "/" && m_parent != NULL) ((DirectoryNode*)(m_parent))->unmount(); } u32int DirectoryNode::getIdxChildSC(u32int idx) { diff --git a/Source/Kernel/VFS/FileSystem.proto.h b/Source/Kernel/VFS/FileSystem.proto.h index 93b37f8..9216219 100644 --- a/Source/Kernel/VFS/FileSystem.proto.h +++ b/Source/Kernel/VFS/FileSystem.proto.h @@ -26,6 +26,8 @@ class FileSystem { bool isWritable() { return m_isWritable; } DirectoryNode* getRootNode() { return m_rootNode; } + virtual String getDevDescription() = 0; + //Must be implemented by the filesystem virtual bool setName(FSNode* node, String name) = 0; virtual bool setPermissions(FSNode* node, u32int permissions) = 0; diff --git a/Source/Kernel/VFS/Part.ns.cpp b/Source/Kernel/VFS/Part.ns.cpp index 7184f90..1bd6a8e 100644 --- a/Source/Kernel/VFS/Part.ns.cpp +++ b/Source/Kernel/VFS/Part.ns.cpp @@ -57,6 +57,7 @@ u32int getDeviceID(BlockDevice* dev) { } BlockDevice* dev(String _class, u32int idx) { + if (_class.empty()) _class = "block"; for (u32int i = 0; i < devices.size(); i++) { String devclass = devices[i]->getClass(); if (devclass == _class or (devclass.size() > _class.size() and devclass.substr(0, _class.size()) == _class)) { @@ -83,4 +84,8 @@ Partition* part(BlockDevice* dev, u32int idx) { return NULL; } +String partIdentifier(Partition* p) { + return String("d") += String::number(getDeviceID(p->getDevice())) += String("p") += String::number(p->getPartNumber()); +} + } diff --git a/Source/Kernel/VFS/Part.ns.h b/Source/Kernel/VFS/Part.ns.h index 4373a2d..992f6f3 100644 --- a/Source/Kernel/VFS/Part.ns.h +++ b/Source/Kernel/VFS/Part.ns.h @@ -16,6 +16,8 @@ namespace Part { BlockDevice* dev(String _class, u32int idx); Partition* part(BlockDevice* dev, u32int idx); + + String partIdentifier(Partition* p); //Simply to help recognize the partition } #endif diff --git a/Source/Kernel/VFS/VFS.ns.cpp b/Source/Kernel/VFS/VFS.ns.cpp index 5ebb697..6a5fe4e 100644 --- a/Source/Kernel/VFS/VFS.ns.cpp +++ b/Source/Kernel/VFS/VFS.ns.cpp @@ -1,6 +1,19 @@ #include "VFS.ns.h" #include <VFS/FileNode.class.h> #include <Vector.class.h> +#include <VTManager/VirtualTerminal.proto.h> + +#include <VFS/Part.ns.h> +#include <FileSystems/RamFS/RamFS.class.h> +#include <FileSystems/FAT/FATFS.class.h> + +struct local_fs_t { + const char* name; + mount_callback_t cb; +} fileSystems[] = { + {"fat", FATFS::mount}, + {0, 0} +}; FileSystem::~FileSystem() { delete m_rootNode; } @@ -37,6 +50,68 @@ bool unmount(FileSystem* fs) { return true; } +bool mount(String str, VirtualTerminal* vt, multiboot_info_t *mbd) { + Vector<String> fs = str.split(":"); + DirectoryNode* root; + if (fs[0] == "/") { + root = NULL; + } else { + FSNode* n = VFS::find(fs[0]); + if (n == NULL) { + *vt << "Mountpoint does not exist : " << fs[0] << "\n"; + return false; + } + if (n->type() != NT_DIRECTORY) { + *vt << "Mountpoint is not a directory : " << fs[0] << "\n"; + return false; + } + root = (DirectoryNode*)n; + } + if (fs[1] == "ramfs") { + if (fs.size() > 2) { + if (mbd != 0) { + module_t *mods = (module_t*)mbd->mods_addr; + if (fs[2].toInt() >= mbd->mods_count) { + *vt << "Invalid module number for filesystem to mount on " << fs[0] << "\n"; + return false; + } + RamFS::mount((u8int*)mods[fs[2].toInt()].mod_start, 1024 * 1024, root); + return true; + } else { + *vt << "Cannot mount kernel modules outside of kernel command line.\n"; + return false; + } + } else { + RamFS::mount(1024 * 1024, root); + return true; + } + } else { + if (fs.size() < 4) { + *vt << "Syntax: <mountpoint>:[<dev_class>]:<dev_id>:<part_id>[:<fs_type>[:[ro|rw]]]\n"; + return false; + } + if (fs[1] == "") fs[1] = "block"; + if (fs.size() < 5) fs.push(""); + if (fs.size() < 6) fs.push("ro"); //By default, mount file systems read-only + BlockDevice* d = Part::dev(fs[1], fs[2].toInt()); + Partition* p = Part::part(d, fs[3].toInt()); + for (u32int i = 0; fileSystems[i].cb != 0; i++) { + if (fs[4] == fileSystems[i].name or fs[4] == "") { + if (fileSystems[i].cb(p, root, (fs[5] == "rw")) != NULL) { + return true; + } else if (fs[4] != "") { + *vt << "Could not mount filesystem on " << fs[0] << "\n"; + if (root == NULL) PANIC("Error while mounting root filesystem."); + return false; + } + } + } + *vt << "Unknown filesystem type for filesystem to mount on " << fs[0] << "\n"; + if (root == NULL) PANIC("Unknown filesystem type for root file system."); + return false; + } +} + FSNode* find(const String& path, FSNode* start) { if (start == 0) start = rootNode; diff --git a/Source/Kernel/VFS/VFS.ns.h b/Source/Kernel/VFS/VFS.ns.h index 21a1e77..eede728 100644 --- a/Source/Kernel/VFS/VFS.ns.h +++ b/Source/Kernel/VFS/VFS.ns.h @@ -1,11 +1,13 @@ #ifndef DEF_VFS_NS_H #define DEF_VFS_NS_H +#include <Core/multiboot.wtf.h> + #include <VFS/DirectoryNode.class.h> #include <VFS/FileSystem.proto.h> #include <Vector.class.h> -typedef FileSystem* (* mount_callback_t)(Partition* partition); +typedef FileSystem* (* mount_callback_t)(Partition* partition, DirectoryNode* mountpoint, bool readwrite); namespace VFS { extern Vector<FileSystem*> filesystems; @@ -18,6 +20,8 @@ namespace VFS { void unregisterFilesystem(FileSystem* fs); bool unmount(FileSystem* fs); + bool mount(String str, VirtualTerminal* logvt, multiboot_info_t* mbd = 0); + FSNode* find(const String& path, FSNode* start = 0); FSNode* createFile(const String& path, FSNode* start = 0, bool vrfyperm = false); FSNode* createDirectory(const String& path, FSNode* start = 0, bool vrfyperm = false); |