From 6332f2561890edd654eafaeb58db16a131573319 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Mon, 14 Sep 2009 18:00:33 +0200 Subject: Added a few commands to kernel shell (rm && mkdir). Also fixed a bug in VFS::remove. --- Source/Kernel/Core/kmain.wtf.cpp | 36 +++++++++++++++++++++-------- Source/Kernel/Melon.ke | Bin 145145 -> 149241 bytes Source/Kernel/MemoryManager/PhysMem.ns.cpp | 3 ++- Source/Kernel/Ressources/Info.txt | 6 +++++ Source/Kernel/Ressources/Welcome.txt | 6 ++--- Source/Kernel/VFS/DirectoryNode.class.cpp | 1 + Source/Kernel/VFS/VFS.ns.cpp | 4 +++- 7 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 Source/Kernel/Ressources/Info.txt (limited to 'Source/Kernel') diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index aef98e3..78347d7 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -111,31 +111,29 @@ void kmain(multiboot_info_t* mbd, u32int magic) { PROCESSING(kvt, "Detecting floppy drives..."); FloppyController::detect(); OK(kvt); + PROCESSING(kvt, "Mounting first module as ramfs on root directory..."); FileSystem* fs = new RamFS((u8int*)mods[0].mod_start, 1024 * 1024); DirectoryNode* cwd; cwd = fs->getRootNode(); - VFS::setRootNode(cwd); + VFS::setRootNode(cwd); OK(kvt); asm volatile("sti"); while(1) { - kvt->setColor(0); - *kvt << "[" << cwd->getName() << "]# "; kvt->setColor(8); + *kvt << "[" << cwd->getName() << "]# "; + kvt->setColor(1); Vector tokens = kvt->readLine().split(" "); kvt->setColor(0); if (tokens[0] == "help") { *kvt << " - Command list for integrated kernel shell:\n"; *kvt << " - help shows this help screen\n"; *kvt << " - reboot reboots your computer\n"; - *kvt << " - ls [] shows contents of a directory\n"; - *kvt << " - cd goes to directory \n"; - *kvt << " - cat shows contents of file \n"; - *kvt << " - pwd prints current directory\n"; *kvt << " - devices shows all detected devices on your computer\n"; *kvt << " - free shows memory usage (physical frames and kernel heap)\n"; *kvt << " - uptime shows seconds since boot\n"; *kvt << " - part shows all detected block devices and partitions\n"; + *kvt << " - Commands you should know how to use : ls, cd, cat, pwd, rm, mkdir, wf\n"; } else if (tokens[0] == "reboot") { Sys::reboot(); } else if (tokens[0] == "ls") { @@ -159,7 +157,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) { kvt->setCursorCol(30); *kvt << (s32int)f->getLength() << " bytes.\n"; } else if (n->type() == NT_DIRECTORY) { - *kvt << " - DIR\t" << n->getName(); + *kvt << " - DIR\t" << n->getName() << "/"; kvt->setCursorCol(30); *kvt << (s32int)n->getLength() << " items.\n"; } @@ -181,9 +179,9 @@ void kmain(multiboot_info_t* mbd, u32int magic) { for (u32int i = 1; i < tokens.size(); i++) { FSNode* n = VFS::find(tokens[i], cwd); if (n == NULL) { - *kvt << "No such file : " << tokens[1] << "\n"; + *kvt << "No such file : " << tokens[i] << "\n"; } else if (n->type() != NT_FILE) { - *kvt << "Not a file : " << tokens[1] << "\n"; + *kvt << "Not a file : " << tokens[i] << "\n"; } else { FileNode* f = (FileNode*) n; u8int *buff = (u8int*)Mem::kalloc(f->getLength() + 1); @@ -195,6 +193,24 @@ void kmain(multiboot_info_t* mbd, u32int magic) { } } else if (tokens[0] == "pwd") { *kvt << "Current location : " << VFS::path(cwd) << "\n"; + } else if (tokens[0] == "rm") { + if (tokens.size() == 1) *kvt << "No argument specified. I suppose that means I'll have to erase everything.\n"; + for (u32int i = 1; i < tokens.size(); i++) { + if (!VFS::remove(tokens[i], cwd)) { + *kvt << "Error while removing file " << tokens[i] << "\n"; + } + } + } else if (tokens[0] == "mkdir") { + if (tokens.size() > 1) { + for (u32int i = 1; i < tokens.size(); i++) { + if (VFS::createDirectory(tokens[i], cwd) == NULL) + *kvt << "Error while creating directory" << tokens[i] << "\n"; + } + } else { + *kvt << "No argument specified. WTF???\n"; + } + } else if (tokens[0] == "wf") { + *kvt << "Sorry, this command isn't implemented yet.\n"; } else if (tokens[0] == "devices") { Vector dev = Dev::findDevices(); *kvt << " - Detected devices :\n"; diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke index 3ec26f0..bdc10a5 100755 Binary files a/Source/Kernel/Melon.ke and b/Source/Kernel/Melon.ke differ diff --git a/Source/Kernel/MemoryManager/PhysMem.ns.cpp b/Source/Kernel/MemoryManager/PhysMem.ns.cpp index a9bfd35..19323a7 100644 --- a/Source/Kernel/MemoryManager/PhysMem.ns.cpp +++ b/Source/Kernel/MemoryManager/PhysMem.ns.cpp @@ -63,7 +63,8 @@ void freeFrame(page_t *page) { if (page->frame == 0) { return; } else { - frames->clearBit(page->frame / 0x1000); + if (page->frame >= 0x100) //First 1M are reserved (system) + frames->clearBit(page->frame / 0x1000); page->frame = 0; } } diff --git a/Source/Kernel/Ressources/Info.txt b/Source/Kernel/Ressources/Info.txt new file mode 100644 index 0000000..2b86198 --- /dev/null +++ b/Source/Kernel/Ressources/Info.txt @@ -0,0 +1,6 @@ +These files were just added here for fun. + +Oh, you wanted to know what the wf command meant ? +Simple : it means Write File. When it will exist, it will prompt you for +the textual contents of the file given as an argument. Not very exciting, +but it might be useful one day. diff --git a/Source/Kernel/Ressources/Welcome.txt b/Source/Kernel/Ressources/Welcome.txt index 9af0942..882a4a7 100644 --- a/Source/Kernel/Ressources/Welcome.txt +++ b/Source/Kernel/Ressources/Welcome.txt @@ -1,12 +1,12 @@ EN : -Welcome on this Melon live-floppy ! For the moment, the project isn't very +Welcome to this Melon live-floppy ! For the moment, the project isn't very advanced, but if you can read this text, it's already because of a lot of -great efforts I'v made for developping this. +great efforts I'v made in Melon's developpment. FR : Bienvenue sur cette live-disquette de Melon ! Pour l'instant, le projet n'est pas très avancé, mais si vous pouvez lire ce texte, c'est déjà grâce -à un grand travail de ma part dans le développement. +à un grand travail de ma part dans le développement de Melon. ES : [I can't speak Spanish properly, sorry] diff --git a/Source/Kernel/VFS/DirectoryNode.class.cpp b/Source/Kernel/VFS/DirectoryNode.class.cpp index 95d2245..415899c 100644 --- a/Source/Kernel/VFS/DirectoryNode.class.cpp +++ b/Source/Kernel/VFS/DirectoryNode.class.cpp @@ -71,6 +71,7 @@ bool DirectoryNode::remove(FSNode* child) { //Remove node from our children list m_children[idx] = m_children.back(); m_children.pop(); + m_length--; delete child; diff --git a/Source/Kernel/VFS/VFS.ns.cpp b/Source/Kernel/VFS/VFS.ns.cpp index 6db791a..30ad2d7 100644 --- a/Source/Kernel/VFS/VFS.ns.cpp +++ b/Source/Kernel/VFS/VFS.ns.cpp @@ -40,6 +40,7 @@ FSNode* find(const String& path, FSNode* start) { } FSNode* createFile(const String& path, FSNode* start) { + if (find(path, start) != NULL) return NULL; //Something already has that name. if (start == 0) start = rootNode; Vector p = path.split("/"); @@ -71,6 +72,7 @@ FSNode* createFile(const String& path, FSNode* start) { } FSNode* createDirectory(const String& path, FSNode* start) { + if (find(path, start) != NULL) return NULL; //Something already has that name. if (start == 0) start = rootNode; Vector p = path.split("/"); @@ -102,7 +104,7 @@ FSNode* createDirectory(const String& path, FSNode* start) { } bool remove(const String& path, FSNode* start) { - FSNode* node =find(path, start); + FSNode* node = find(path, start); if (node == NULL) return false; FSNode* parent = node->getParent(); if (parent == NULL) return false; -- cgit v1.2.3