diff options
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 4 | ||||
-rw-r--r-- | Source/Kernel/DeviceManager/Dev.ns.cpp | 14 | ||||
-rw-r--r-- | Source/Kernel/DeviceManager/Dev.ns.h | 1 | ||||
-rw-r--r-- | Source/Kernel/DeviceManager/Kbd.ns.cpp | 4 | ||||
-rw-r--r-- | Source/Kernel/FileSystems/RamFS/RamFS.class.cpp | 47 | ||||
-rw-r--r-- | Source/Kernel/FileSystems/RamFS/RamFS.class.h | 9 | ||||
-rwxr-xr-x | Source/Kernel/Melon.ke | bin | 159305 -> 159686 bytes | |||
-rw-r--r-- | Source/Kernel/VFS/DirectoryNode.class.cpp | 12 | ||||
-rw-r--r-- | Source/Kernel/VFS/DirectoryNode.class.h | 9 | ||||
-rw-r--r-- | Source/Kernel/VFS/File.class.h | 7 | ||||
-rw-r--r-- | Source/Kernel/VFS/FileNode.class.h | 1 | ||||
-rw-r--r-- | Source/Kernel/VFS/FileSystem.proto.h | 2 |
12 files changed, 90 insertions, 20 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 6ccc71e..0f22189 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -74,7 +74,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) { melonLogoVT->map(1); //Create a VT for logging what kernel does - SimpleVT *kvt = new ScrollableVT(15, 76, 100, KVT_FGCOLOR, KVT_BGCOLOR); + SimpleVT *kvt = new ScrollableVT(15, 76, 200, KVT_FGCOLOR, KVT_BGCOLOR); kvt->map(melonLogoLines + 2); INFO(kvt); *kvt << "Lower ram : " << (s32int)mbd->mem_lower << "k, upper : " << (s32int)mbd->mem_upper << "k.\n"; @@ -103,7 +103,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Task::initialize(String((char*)mbd->cmdline), kvt); OK(kvt); PROCESSING(kvt, "Mounting first module as ramfs on root directory..."); - FileSystem* fs = new RamFS((u8int*)mods[0].mod_start, 1024 * 1024); + FileSystem* fs = RamFS::mount((u8int*)mods[0].mod_start, 1024 * 1024, NULL); DirectoryNode* cwd; cwd = fs->getRootNode(); VFS::setRootNode(cwd); OK(kvt); diff --git a/Source/Kernel/DeviceManager/Dev.ns.cpp b/Source/Kernel/DeviceManager/Dev.ns.cpp index b2f8a70..3afc267 100644 --- a/Source/Kernel/DeviceManager/Dev.ns.cpp +++ b/Source/Kernel/DeviceManager/Dev.ns.cpp @@ -48,4 +48,18 @@ Vector<Device*> findDevices(String _class) { return ret; } +Device* findDevice(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; +} + } diff --git a/Source/Kernel/DeviceManager/Dev.ns.h b/Source/Kernel/DeviceManager/Dev.ns.h index 389fe3e..7dda56b 100644 --- a/Source/Kernel/DeviceManager/Dev.ns.h +++ b/Source/Kernel/DeviceManager/Dev.ns.h @@ -13,6 +13,7 @@ namespace Dev { bool requestIRQ(Device* dev, int irq); Vector<Device*> findDevices(String _class = ""); + Device* findDevice(String _class = "", u32int idx = 0); } #endif diff --git a/Source/Kernel/DeviceManager/Kbd.ns.cpp b/Source/Kernel/DeviceManager/Kbd.ns.cpp index df419b7..3db0d34 100644 --- a/Source/Kernel/DeviceManager/Kbd.ns.cpp +++ b/Source/Kernel/DeviceManager/Kbd.ns.cpp @@ -69,7 +69,9 @@ bool loadKeymap(String lang) { File f(file, FM_READ); if (!f.valid()) return false; - f.read(sizeof(melon_keymap_t), (u8int*)&km); + if (!f.read<melon_keymap_t> (&km)) { + Log::log(KL_WARNING, String("Kbd.ns : keymap badly loaded : ") += file); + } keymapNormal = km.normal; if (km.shift[0x10] != 0) keymapShift = km.shift; else keymapShift = keymapNormal; diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp index ca8dd21..a224bf8 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp @@ -2,18 +2,29 @@ #include <VFS/DirectoryNode.class.h> #include "RamFileNode.class.h" -RamFS::RamFS(u32int maxSize) { - m_maxSize = maxSize; - m_usedSize = 0; - m_isWritable = true; - m_rootNode = new DirectoryNode("/", this, NULL); +RamFS::RamFS() { } -RamFS::RamFS(u8int *ptr, u32int maxSize, bool writable) { - m_maxSize = maxSize; - m_usedSize = 0; - m_isWritable = true; - m_rootNode = new DirectoryNode("/", this, NULL); +RamFS::~RamFS() { + delete m_rootNode; +} + +RamFS* RamFS::mount(u32int maxSize, DirectoryNode* mountpoint) { + RamFS* rfs = new RamFS(); + rfs->m_maxSize = maxSize; + rfs->m_usedSize = 0; + rfs->m_isWritable = true; + rfs->m_rootNode = new DirectoryNode("/", rfs, mountpoint); + return rfs; +} + +RamFS* RamFS::mount(u8int *ptr, u32int maxSize, DirectoryNode* mountpoint, bool writable) { + RamFS* rfs = new RamFS(); + + rfs->m_maxSize = maxSize; + rfs->m_usedSize = 0; + rfs->m_isWritable = true; + rfs->m_rootNode = new DirectoryNode("/", rfs, mountpoint); union { u8int* c; @@ -22,7 +33,11 @@ RamFS::RamFS(u8int *ptr, u32int maxSize, bool writable) { } curr; curr.c = ptr; - if (curr.i->magic != INITRD_MAGIC) return; + if (curr.i->magic != INITRD_MAGIC) { + delete rfs; + return NULL; + } + u32int files = curr.i->files; curr.i++; //Increment pointer of size of initrd header for (u32int i = 0; i < files; i++) { @@ -32,12 +47,12 @@ RamFS::RamFS(u8int *ptr, u32int maxSize, bool writable) { String name((const char*)(curr.c)); curr.c += h.name_length + 1; //Increment pointer of length of name - //Find out a vector conaining parent directories, and set name to the effective file name + //Find out a vector containing parent directories, and set name to the effective file name if (name[0] == WChar("/")) name = name.substr(1, name.size() - 1); //Find node for parent directory String mname = ""; - DirectoryNode* parent = m_rootNode; + DirectoryNode* parent = rfs->m_rootNode; for (u32int i = 0; i < name.size(); i++) { if (name[i] == WChar("/")) { FSNode* n = parent->getChild(mname); @@ -61,6 +76,12 @@ RamFS::RamFS(u8int *ptr, u32int maxSize, bool writable) { } } } + + return rfs; +} + +bool RamFS::unmount() { + return m_rootNode->unmountable(); } bool RamFS::setName(FSNode* node, String name) { return true; } diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h index 0a3f0c4..1d60796 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.h +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.h @@ -17,12 +17,17 @@ struct initrd_file_header { class RamFS : public FileSystem { private: + ~RamFS(); + RamFS(const RamFS& other); + RamFS(); + bool unmount(); //TO BE USED ONLY BY VFS::UNMOUNT (when will exist...) + u32int m_maxSize; u32int m_usedSize; public: - RamFS(u32int maxSize); //Creates an empty RAM file system - RamFS(u8int* ptr, u32int maxSize, bool writable = true); //Creates a RAM file system from data loaded in memory. format to be defined + static RamFS* mount(u32int maxSize, DirectoryNode* mountpoint); //Creates an empty RAM file system + static RamFS* mount(u8int* ptr, u32int maxSize, DirectoryNode* mountpoint, bool writable = true); //Creates a RAM file system from data loaded in memory. format to be defined bool setName(FSNode* node, String name); bool setPermissions(FSNode* node, u32int permissions); diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke Binary files differindex 703a9c3..3cd9a6c 100755 --- a/Source/Kernel/Melon.ke +++ b/Source/Kernel/Melon.ke diff --git a/Source/Kernel/VFS/DirectoryNode.class.cpp b/Source/Kernel/VFS/DirectoryNode.class.cpp index 415899c..0c58ca1 100644 --- a/Source/Kernel/VFS/DirectoryNode.class.cpp +++ b/Source/Kernel/VFS/DirectoryNode.class.cpp @@ -7,6 +7,18 @@ bool DirectoryNode::removable() { return m_children.empty(); } +bool DirectoryNode::unmountable() { + if (!m_contentLoaded) return true; + for (u32int i = 0; i < m_children.size(); i++) { + if (m_children[i]->type() == NT_DIRECTORY) { + if (!((DirectoryNode*)m_children[i])->unmountable()) return false; + } else { + if (!m_children[i]->removable()) return false; + } + } + return true; +} + bool DirectoryNode::loadContent() { if (m_contentLoaded) return true; bool b = m_fs->loadContents(this); diff --git a/Source/Kernel/VFS/DirectoryNode.class.h b/Source/Kernel/VFS/DirectoryNode.class.h index 5de523e..2130458 100644 --- a/Source/Kernel/VFS/DirectoryNode.class.h +++ b/Source/Kernel/VFS/DirectoryNode.class.h @@ -13,12 +13,19 @@ class DirectoryNode : public FSNode { DirectoryNode(String name, FileSystem* fs, FSNode* parent, u32int permissions = 0777, u32int uid = 0, u32int gid = 0) : FSNode(name, fs, parent, 0, permissions, uid, gid), m_children(), m_contentLoaded(false) {} - virtual ~DirectoryNode() {} + virtual ~DirectoryNode() { + if (m_contentLoaded) { + for (u32int i = 0; i < m_children.size(); i++) { + delete m_children[i]; + } + } + } Vector<FSNode*> &getChildren() { return m_children; } //MUST BE USED ONLY BY FILESYSTEMS u8int type() { return NT_DIRECTORY; } bool removable(); + bool unmountable(); bool loadContent(); FSNode* getChild(u32int index); diff --git a/Source/Kernel/VFS/File.class.h b/Source/Kernel/VFS/File.class.h index ef82a70..7831fb5 100644 --- a/Source/Kernel/VFS/File.class.h +++ b/Source/Kernel/VFS/File.class.h @@ -38,6 +38,13 @@ class File { u32int read(ByteArray &data); //Fills ByteArray at its current length or shrinks it if we can't read enough bool write(ByteArray &data); + template <typename T> bool read(T* elem) { + return (read(sizeof(T), (u8int*)elem) == sizeof(T)); + } + template <typename T> bool write(T* elem) { + return write(sizeof(T), (u8int*)elem); + } + bool seek(u64int count, u8int mode); u64int position() { return m_position; } u64int length() { return m_file->getLength(); } diff --git a/Source/Kernel/VFS/FileNode.class.h b/Source/Kernel/VFS/FileNode.class.h index ac170ae..7ab617f 100644 --- a/Source/Kernel/VFS/FileNode.class.h +++ b/Source/Kernel/VFS/FileNode.class.h @@ -21,7 +21,6 @@ class FileNode : public FSNode { bool used() { return (m_readers != 0 or m_writers != 0); } bool writable() { return m_fs->isWritable(); } - //protected: u32int read(u64int position, u32int max_length, u8int *data) { return m_fs->read(this, position, max_length, data); } diff --git a/Source/Kernel/VFS/FileSystem.proto.h b/Source/Kernel/VFS/FileSystem.proto.h index 2f768a7..5aec434 100644 --- a/Source/Kernel/VFS/FileSystem.proto.h +++ b/Source/Kernel/VFS/FileSystem.proto.h @@ -13,6 +13,8 @@ class FileSystem { DirectoryNode* m_rootNode; public: + bool unmount(); + bool isWritable() { return m_isWritable; } DirectoryNode* getRootNode() { return m_rootNode; } |