summaryrefslogtreecommitdiff
path: root/Source/Kernel/Shell
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/Shell')
-rw-r--r--Source/Kernel/Shell/KernelShell-fs.class.cpp18
-rw-r--r--Source/Kernel/Shell/KernelShell-sys.class.cpp41
-rw-r--r--Source/Kernel/Shell/KernelShell.class.cpp28
-rw-r--r--Source/Kernel/Shell/KernelShell.class.h3
4 files changed, 89 insertions, 1 deletions
diff --git a/Source/Kernel/Shell/KernelShell-fs.class.cpp b/Source/Kernel/Shell/KernelShell-fs.class.cpp
index fa2078d..c389d45 100644
--- a/Source/Kernel/Shell/KernelShell-fs.class.cpp
+++ b/Source/Kernel/Shell/KernelShell-fs.class.cpp
@@ -125,3 +125,21 @@ void KernelShell::run(Vector<String>& args) {
}
}
}
+
+void KernelShell::hexdump(Vector<String>& args) {
+ if (args.size() == 1) {
+ *m_vt << "No file to hexdump.\n";
+ } else {
+ for (u32int i = 1; i < args.size(); i++) {
+ File f(args[i], FM_READ, m_cwd);
+ if (f.valid()) {
+ u8int *buff = (u8int*)Mem::alloc(f.length());
+ f.read(f.length(), buff);
+ m_vt->hexDump(buff, f.length());
+ Mem::free(buff);
+ } else {
+ *m_vt << "Error reading from file " << args[i] << "\n";
+ }
+ }
+ }
+}
diff --git a/Source/Kernel/Shell/KernelShell-sys.class.cpp b/Source/Kernel/Shell/KernelShell-sys.class.cpp
index 6243b0f..da5378b 100644
--- a/Source/Kernel/Shell/KernelShell-sys.class.cpp
+++ b/Source/Kernel/Shell/KernelShell-sys.class.cpp
@@ -4,6 +4,8 @@
#include <MemoryManager/Mem.ns.h>
#include <MemoryManager/PhysMem.ns.h>
#include <VFS/Part.ns.h>
+#include <VFS/VFS.ns.h>
+#include <FileSystems/RamFS/RamFS.class.h>
void KernelShell::devices(Vector<String>& args) {
Vector<Device*> dev = Dev::findDevices();
@@ -58,3 +60,42 @@ void KernelShell::part(Vector<String>& args) {
}
}
}
+
+void KernelShell::mount(Vector<String>& args) {
+ if (args.size() == 1) {
+ for (u32int i = 0; i < VFS::filesystems.size(); i++) {
+ *m_vt << VFS::filesystems[i]->getIdentifier() << "\n";
+ }
+ } else if (args.size() == 2) {
+ if (args[1] == "help") {
+ *m_vt << "Usage: mount [help|<options>]\n" <<
+ "Options formats :\n" <<
+ " - <mountpoint>:ramfs\n" <<
+ " - <mountpoint>:[<dev_class>]:<dev_number>:<part_number>[:<type>[:[ro|rw]]]\n" <<
+ "You can have a list of available block devices and partitions by typing 'part'.\n";
+ } else {
+ if (VFS::mount(args[1], m_vt)) *m_vt << "Ok, filesystem mounted.\n";
+ }
+ } else {
+ *m_vt << "Usage: mount [<device> <mountpoint>\n";
+ }
+}
+
+void KernelShell::readblock(Vector<String>& args) {
+ if (args.size() == 3) {
+ Vector<Device*> devcs = Dev::findDevices("block");
+ u32int id = args[1].toInt(), block = args[2].toInt();
+ if (id < devcs.size()) {
+ BlockDevice* bdev = (BlockDevice*)devcs[id];
+ *m_vt << "Block " << block << " from device " << bdev->getName() << " (" << bdev->getClass() << ")\n";
+ u8int* buff = (u8int*)Mem::alloc(bdev->blockSize());
+ bdev->readBlocks(block, 1, buff);
+ m_vt->hexDump(buff, 32);
+ Mem::free(buff);
+ } else {
+ *m_vt << "Block device #" << id << " does not exist.\n";
+ }
+ } else {
+ *m_vt << "Usage: readblock <dev id> <block id>\n";
+ }
+}
diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp
index d62d822..71a717a 100644
--- a/Source/Kernel/Shell/KernelShell.class.cpp
+++ b/Source/Kernel/Shell/KernelShell.class.cpp
@@ -3,8 +3,8 @@
#include <DeviceManager/Kbd.ns.h>
#include <SimpleList.class.h>
#include <MemoryManager/PhysMem.ns.h>
-#include <VFS/VFS.ns.h>
#include <TaskManager/Task.ns.h>
+#include <VFS/VFS.ns.h>
u32int KernelShell::m_instances = 0;
@@ -60,6 +60,9 @@ u32int KernelShell::run() {
{"free", &KernelShell::free},
{"uptime", &KernelShell::uptime},
{"part", &KernelShell::part},
+ {"readblock", &KernelShell::readblock},
+ {"mount", &KernelShell::mount},
+ {"hexdump", &KernelShell::hexdump},
{0, 0}
};
@@ -81,6 +84,9 @@ u32int KernelShell::run() {
*m_vt << " - free shows memory usage (frames and kheap)\n";
*m_vt << " - uptime shows seconds since boot\n";
*m_vt << " - part shows all detected block devs and partitions\n";
+ *m_vt << " - mount shows mounted devices or mounts a ramfs\n";
+ *m_vt << " - readblock reads a block from a block device and dumps it\n";
+ *m_vt << " - hexdump shows a hexadecimal dump of a file\n";
*m_vt << " - Standard UNIX commands : ls cd cat pwd rm mkdir wf\n";
*m_vt << " - Scroll up with shift+pgup !\n";
} else if (tokens[0] == "reboot") {
@@ -92,6 +98,26 @@ u32int KernelShell::run() {
} else if (tokens[0] == "exit") {
if (tokens.size() == 1) return 0;
return tokens[1].toInt();
+ } else if (tokens[0] == "unmount") {
+ if (tokens.size() == 2) {
+ FSNode* n = VFS::find(tokens[1], m_cwd);
+ bool ok = false;
+ if (n == 0) {
+ ok = false;
+ } else {
+ String p = VFS::path(n);
+ for (u32int i = 0; i < VFS::filesystems.size(); i++) {
+ if (VFS::path(VFS::filesystems[i]->getRootNode()) == p) {
+ ok = VFS::unmount(VFS::filesystems[i]);
+ break;
+ }
+ }
+ }
+ if (ok) *m_vt << "Ok, filesystem unmounted.\n";
+ else *m_vt << "Error.\n";
+ } else {
+ *m_vt << "Usage: unmount <mountpoint>\n";
+ }
} else if (tokens[0] != "" or tokens.size() != 1) {
u32int i = 0;
bool found = false;
diff --git a/Source/Kernel/Shell/KernelShell.class.h b/Source/Kernel/Shell/KernelShell.class.h
index e7549c2..9655def 100644
--- a/Source/Kernel/Shell/KernelShell.class.h
+++ b/Source/Kernel/Shell/KernelShell.class.h
@@ -27,6 +27,7 @@ class KernelShell {
void rm(Vector<String>& args);
void wf(Vector<String>& args);
void run(Vector<String>& args);
+ void hexdump(Vector<String>& args);
//in KernelShell-sys
void devices(Vector<String>& args);
@@ -34,6 +35,8 @@ class KernelShell {
void free(Vector<String>& args);
void uptime(Vector<String>& args);
void part(Vector<String>& args);
+ void readblock(Vector<String>& args);
+ void mount(Vector<String>& args);
void setup(DirectoryNode* cwd, VirtualTerminal *vt);