diff options
Diffstat (limited to 'Source/Applications/Shell')
-rw-r--r-- | Source/Applications/Shell/Shell-fs.ns.cpp | 22 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.ns.cpp | 3 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.ns.h | 1 |
3 files changed, 21 insertions, 5 deletions
diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.ns.cpp index 33bc94e..5e6ae4f 100644 --- a/Source/Applications/Shell/Shell-fs.ns.cpp +++ b/Source/Applications/Shell/Shell-fs.ns.cpp @@ -5,7 +5,7 @@ namespace Shell { void ls(Vector<String>& args) { FSNode d = cwd; if (args.size() == 2) { - FSNode n = cwd.findFrom(args[1]); + FSNode n = FS::find(args[1], cwd); d = FSNode(0); if (!n.valid()) outvt << "No such directory : " << args[1] << "\n"; @@ -17,12 +17,17 @@ void ls(Vector<String>& args) { if (d.valid()) outvt << "Contents of directory " << d.path() << " :\n"; for (u32int i = 0; i < d.getLength(); i++) { FSNode n = d.getChild(i); + String perm = "rwxrwxrwx"; + u32int p = n.getPerm(); + for (u32int i = 0; i < 9; i++) { + if (((p >> i) & 1) == 0) perm[9 - i] = "-"; + } if (n.type() == NT_FILE) { - outvt << " - FILE\t" << n.getName(); + outvt << " FILE " << perm << " " << n.getName(); outvt.setCsrCol(30); outvt << (s32int)n.getLength() << " bytes.\n"; } else if (n.type() == NT_DIRECTORY) { - outvt << " - DIR\t" << n.getName() << "/"; + outvt << " DIR " << perm << " " << n.getName() << "/"; outvt.setCsrCol(30); outvt << (s32int)n.getLength() << " items.\n"; } @@ -33,7 +38,7 @@ void cd(Vector<String>& args) { if (args.size() != 2) { outvt << "Invalid argument count.\n"; } else { - FSNode ncwd = cwd.findFrom(args[1]); + FSNode ncwd = FS::find(args[1], cwd); if (!ncwd.valid()) { outvt << "No such directory : " << args[1] << "\n"; } else if (ncwd.type() == NT_DIRECTORY) { @@ -49,4 +54,13 @@ void pwd(Vector<String>& args) { outvt << "Current directory : " << cwd.path() << "\n"; } +void rm(Vector<String>& args) { + if (args.size() == 1) outvt << "No file to remove.\n"; + for (u32int i = 1; i < args.size(); i++) { + if (!FS::find(args[i], cwd).remove()) { + outvt << "Error while removing file " << args[i] << "\n"; + } + } +} + } diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.ns.cpp index 4afc6b7..1f8acae 100644 --- a/Source/Applications/Shell/Shell.ns.cpp +++ b/Source/Applications/Shell/Shell.ns.cpp @@ -14,10 +14,11 @@ u32int run() { {"ls", ls}, {"cd", cd}, {"pwd", pwd}, + {"rm", rm}, {"", 0} }; - cwd = FSNode::getCwd(); + cwd = FS::cwdNode(); while (1) { outvt << "{" << cwd.getName() << "}: "; String s = invt.readLine(); diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h index 8d7067a..5cf4509 100644 --- a/Source/Applications/Shell/Shell.ns.h +++ b/Source/Applications/Shell/Shell.ns.h @@ -10,4 +10,5 @@ namespace Shell { extern void ls(Vector<String>& args); extern void cd(Vector<String>& args); extern void pwd(Vector<String>& args); + extern void rm(Vector<String>& args); } |