From a40fe1166ab1db972a8ca0380d603c4d90eede62 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Wed, 25 Nov 2009 18:42:44 +0100 Subject: Re-organized file system stuff. --- Source/Kernel/Core/Log.ns.cpp | 5 ++++ Source/Kernel/Core/kmain.wtf.cpp | 58 +++++++++++++++++++++++++++++++++--- Source/Kernel/UserManager/Usr.ns.cpp | 26 +++++++++------- Source/Kernel/VFS/File.class.cpp | 3 +- Source/Kernel/VFS/Part.ns.cpp | 27 +++++++++++++++++ Source/Kernel/VFS/Part.ns.h | 3 ++ 6 files changed, 106 insertions(+), 16 deletions(-) (limited to 'Source/Kernel') diff --git a/Source/Kernel/Core/Log.ns.cpp b/Source/Kernel/Core/Log.ns.cpp index 1727024..c8ccd80 100644 --- a/Source/Kernel/Core/Log.ns.cpp +++ b/Source/Kernel/Core/Log.ns.cpp @@ -1,4 +1,5 @@ #include "Log.ns.h" +#include #include namespace Log { @@ -11,6 +12,10 @@ void init(u8int loglevel) { if (VFS::find("/System/Logs") == 0) VFS::createDirectory("/System/Logs"); logs[KL_PANIC] = new TextFile("/System/Logs/Panic.log", FM_APPEND); + if (!logs[KL_PANIC]->valid()) { //FS maybee not read/write, mount a ramfs + RamFS::mount(1024*1024, (DirectoryNode*)VFS::find("/System/Logs")); + logs[KL_PANIC] = new TextFile("/System/Logs/Panic.log", FM_APPEND); + } if (KL_CRITICAL <= loglevel) logs[KL_CRITICAL] = new TextFile("/System/Logs/Critical.log", FM_APPEND); if (KL_ERROR <= loglevel) logs[KL_ERROR] = new TextFile("/System/Logs/Error.log", FM_APPEND); if (KL_WARNING <= loglevel) logs[KL_WARNING] = new TextFile("/System/Logs/Warning.log", FM_APPEND); diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index bb77eeb..1d438ed 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -115,6 +115,43 @@ void selectVideoMode(SimpleVT& v) { } } +bool mountFS(multiboot_info_t* mbd, String str) { + module_t *mods = (module_t*)mbd->mods_addr; + Vector fs = str.split(":"); + DirectoryNode* root; + if (fs[0] == "/") { + root = NULL; + } else { + FSNode* n = VFS::find(fs[0]); + if (n == NULL) { + *kvt << "Mountpoint does not exist : " << fs[0] << "\n"; + return false; + } + if (n->type() != NT_DIRECTORY) { + *kvt << "Mountpoint is not a directory : " << fs[0] << "\n"; + return false; + } + root = (DirectoryNode*)n; + } + if (fs[1] == "ramfs") { + if (fs[2].toInt() >= mbd->mods_count) { + *kvt << "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); + } else { + if (fs.size() < 5) fs.push("fat"); + BlockDevice* d = Part::dev(fs[1], fs[2].toInt()); + Partition* p = Part::part(d, fs[3].toInt()); + if (fs[4] == "fat") { + FATFS::mount(p, root); + } else { + PANIC("Unknown filesystem type for root file system."); + } + } + return true; +} + void kmain(multiboot_info_t* mbd, u32int magic) { DEBUG("Entering kmain."); @@ -167,13 +204,17 @@ void kmain(multiboot_info_t* mbd, u32int magic) { //*************************************** PARSE COMMAND LINE Vector opts = kcmdline.split(" "); - String keymap = "fr", init = "/System/Applications/PaperWork.app"; + String keymap = "builtin", init = "/System/Applications/PaperWork.app"; + String root = "ramfs:0"; + Vector mount; bool enableVESA = true; for (u32int i = 0; i < opts.size(); i++) { Vector opt = opts[i].split(":"); if (opt[0] == "vesa" && opt[1] != "enabled") enableVESA = false; if (opt[0] == "keymap") keymap = opt[1]; if (opt[0] == "init") init = opt[1]; + if (opt[0] == "root") root = opts[i].substr(5); + if (opt[0] == "mount") mount.push(opts[i].substr(6)); } //*************************************** DEVICE SETUP @@ -183,14 +224,23 @@ void kmain(multiboot_info_t* mbd, u32int magic) { if (enableVESA) Dev::registerDevice(new VESADisplay()); FloppyController::detect(); - //*************************************** MOUNT ROOT FILESYSTEM + //*************************************** MOUNT FILESYSTEMS - RamFS::mount((u8int*)mods[0].mod_start, 1024 * 1024, NULL); + { // mount root filesystem + if (!mountFS(mbd, String("/:") += root)) PANIC("Cannot mount root filesystem."); + } DirectoryNode* cwd; cwd = VFS::getRootNode(); Task::currProcess()->setCwd(cwd); - FATFS::mount(Part::partitions[0], (DirectoryNode*)VFS::createDirectory("/Mount")); + // mount other filesystems + for (u32int i = 0; i < mount.size(); i++) { + mountFS(mbd, mount[i]); + } + + //FATFS::mount(Part::partitions[0], (DirectoryNode*)VFS::createDirectory("/Mount")); + + //*************************************** LOAD SYSTEM STUFF if (keymap != "builtin") { if (!Kbd::loadKeymap(keymap)) *kvt << "\nWARNING : Could not load keymap " << keymap << ", using built-in keymap instead."; diff --git a/Source/Kernel/UserManager/Usr.ns.cpp b/Source/Kernel/UserManager/Usr.ns.cpp index ecf9bae..66e159e 100644 --- a/Source/Kernel/UserManager/Usr.ns.cpp +++ b/Source/Kernel/UserManager/Usr.ns.cpp @@ -26,11 +26,13 @@ void load() { if (VFS::find("/System/Configuration/Groups")) VFS::find("/System/Configuration/Groups")->setPermissions(0600); if (VFS::find("/System/Configuration/Users")) VFS::find("/System/Configuration/Users")->setPermissions(0600); TextFile groups("/System/Configuration/Groups", FM_READ); - while (!groups.eof()) { - String s = groups.readLine(); - Vector data = s.split(":"); - if (data.size() == 2 and !(s[0] == WChar("#"))) { - m_groups = m_groups->cons(Group(data[1], data[0].toInt())); + if (groups.valid()) { + while (!groups.eof()) { + String s = groups.readLine(); + Vector data = s.split(":"); + if (data.size() == 2 and !(s[0] == WChar("#"))) { + m_groups = m_groups->cons(Group(data[1], data[0].toInt())); + } } } if (m_groups == 0) { @@ -39,12 +41,14 @@ void load() { } TextFile users("/System/Configuration/Users", FM_READ); - while (!users.eof()) { - String s = users.readLine(); - if (s == "" or s[0] == WChar("#")) continue; - Vector data = s.split(":"); - if (data.size() == 6) { - m_users = m_users->cons(User(data[1], data[4], data[5], group(data[2].toInt()), data[3], data[0].toInt())); + if (users.valid()) { + while (!users.eof()) { + String s = users.readLine(); + if (s == "" or s[0] == WChar("#")) continue; + Vector data = s.split(":"); + if (data.size() == 6) { + m_users = m_users->cons(User(data[1], data[4], data[5], group(data[2].toInt()), data[3], data[0].toInt())); + } } } if (m_users == 0) { diff --git a/Source/Kernel/VFS/File.class.cpp b/Source/Kernel/VFS/File.class.cpp index c5ddcd6..84561a5 100644 --- a/Source/Kernel/VFS/File.class.cpp +++ b/Source/Kernel/VFS/File.class.cpp @@ -33,7 +33,7 @@ bool File::open(String filename, u8int mode, FSNode* start, bool vrfyperm) { if (node == NULL){ if (mode == FM_READ) return false; node = VFS::createFile(filename, start, vrfyperm); - if (node == 0) return false; + if (node == NULL) return false; } if (node->type() != NT_FILE) return false; @@ -137,6 +137,7 @@ bool File::seek(u64int count, u8int mode) { } bool File::eof() { + if (!m_valid) return false; return m_position == m_file->getLength(); } diff --git a/Source/Kernel/VFS/Part.ns.cpp b/Source/Kernel/VFS/Part.ns.cpp index 6408dbd..7184f90 100644 --- a/Source/Kernel/VFS/Part.ns.cpp +++ b/Source/Kernel/VFS/Part.ns.cpp @@ -56,4 +56,31 @@ u32int getDeviceID(BlockDevice* dev) { return (u32int) - 1; } +BlockDevice* dev(String _class, u32int idx) { + 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)) { + if (idx == 0) { + return devices[i]; + } else { + idx--; + } + } + } + return NULL; +} + +Partition* part(BlockDevice* dev, u32int idx) { + for (u32int i = 0; i < partitions.size(); i++) { + if (partitions[i]->getDevice() == dev) { + if (idx == 0) { + return partitions[i]; + } else { + idx--; + } + } + } + return NULL; +} + } diff --git a/Source/Kernel/VFS/Part.ns.h b/Source/Kernel/VFS/Part.ns.h index 40a0fb2..4373a2d 100644 --- a/Source/Kernel/VFS/Part.ns.h +++ b/Source/Kernel/VFS/Part.ns.h @@ -13,6 +13,9 @@ namespace Part { void unregisterDevice(BlockDevice* dev); u32int getDeviceID(BlockDevice* dev); + + BlockDevice* dev(String _class, u32int idx); + Partition* part(BlockDevice* dev, u32int idx); } #endif -- cgit v1.2.3