summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-23 20:43:48 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-23 20:43:48 +0200
commit66630e4154b7c1c47d6223fe5a8607cd269446a0 (patch)
tree21995ed408e9ecbaba48f29ed67c91c4b0dad950 /Source
parent48de0cd029b52f64f76345b6e1fdf3cde5c58de3 (diff)
downloadMelon-66630e4154b7c1c47d6223fe5a8607cd269446a0.tar.gz
Melon-66630e4154b7c1c47d6223fe5a8607cd269446a0.zip
Some changes, and implemented rm in userland shell.
Diffstat (limited to 'Source')
-rw-r--r--Source/Applications/SampleApps/cxxdemo.cpp1
-rw-r--r--Source/Applications/Shell/Shell-fs.ns.cpp22
-rw-r--r--Source/Applications/Shell/Shell.ns.cpp3
-rw-r--r--Source/Applications/Shell/Shell.ns.h1
-rw-r--r--Source/Kernel/Shell/KernelShell-fs.class.cpp4
-rw-r--r--Source/Kernel/VFS/DirectoryNode.class.cpp2
-rw-r--r--Source/Kernel/VFS/FSNode-sc.proto.cpp12
-rw-r--r--Source/Kernel/VFS/FSNode.proto.h3
-rw-r--r--Source/Kernel/VFS/VFS.ns.cpp10
-rw-r--r--Source/Kernel/VFS/VFS.ns.h1
-rw-r--r--Source/Library/Interface/FSNode.iface.h1
-rw-r--r--Source/Library/Userland/Binding/FSNode.class.h37
-rw-r--r--Source/Library/Userland/Binding/Process.class.h5
-rw-r--r--Source/Library/Userland/Binding/Thread.class.h5
-rw-r--r--Source/Library/Userland/Binding/VirtualTerminal.class.h5
15 files changed, 87 insertions, 25 deletions
diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp
index cf297ec..b9439ce 100644
--- a/Source/Applications/SampleApps/cxxdemo.cpp
+++ b/Source/Applications/SampleApps/cxxdemo.cpp
@@ -4,6 +4,7 @@
#include <Binding/Thread.class.h>
int main() {
+ outvt << "Enter some text plz : ";
String s = invt.readLine();
outvt << s;
Thread t = Thread::get();
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);
}
diff --git a/Source/Kernel/Shell/KernelShell-fs.class.cpp b/Source/Kernel/Shell/KernelShell-fs.class.cpp
index a13ae6e..f013f1b 100644
--- a/Source/Kernel/Shell/KernelShell-fs.class.cpp
+++ b/Source/Kernel/Shell/KernelShell-fs.class.cpp
@@ -81,8 +81,8 @@ void KernelShell::rm(Vector<String>& args) {
if (args.size() == 1) *m_vt << "Error : no argument specified.\n";
for (u32int i = 1; i < args.size(); i++) {
if (!VFS::remove(args[i], m_cwd)) {
- *m_vt << "Error while removing file " << args[i] << "\n";
- }
+ *m_vt << "Error while removing file " << args[i] << "\n";
+ }
}
}
diff --git a/Source/Kernel/VFS/DirectoryNode.class.cpp b/Source/Kernel/VFS/DirectoryNode.class.cpp
index 381ff49..74c1ff8 100644
--- a/Source/Kernel/VFS/DirectoryNode.class.cpp
+++ b/Source/Kernel/VFS/DirectoryNode.class.cpp
@@ -7,12 +7,14 @@ call_t DirectoryNode::m_callTable[] = {
};
u32int DirectoryNode::getIdxChildSC(u32int idx) {
+ if (!runnable()) return (u32int) - 1;
FSNode* n = getChild(idx);
if (n != NULL) return n->resId();
return (u32int) - 1;
}
u32int DirectoryNode::getNameChildSC(u32int name) {
+ if (!runnable()) return (u32int) - 1;
String* w = (String*)name;
FSNode* n = getChild(*w);
if (n != NULL) return n->resId();
diff --git a/Source/Kernel/VFS/FSNode-sc.proto.cpp b/Source/Kernel/VFS/FSNode-sc.proto.cpp
index 1e0c4c1..e3f11db 100644
--- a/Source/Kernel/VFS/FSNode-sc.proto.cpp
+++ b/Source/Kernel/VFS/FSNode-sc.proto.cpp
@@ -14,6 +14,7 @@ call_t FSNode::m_callTable[] = {
CALL0(FNIF_GETPERM, &FSNode::getPermissions),
CALL0(FNIF_GETPATH, &FSNode::getPathSC),
CALL0(FNIF_SETCWD, &FSNode::setCwdSC),
+ CALL0(FNIF_REMOVE, &FSNode::removeSC),
CALL0(0, 0)
};
@@ -22,11 +23,13 @@ u32int FSNode::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
if (wat == FNIF_SGETCWD) return Task::currProcess()->getCwd()->resId();
if (wat == FNIF_SFIND) {
String* path = (String*)a;
+ FSNode* n;
if (b == 0) {
- return VFS::find(*path)->resId();
+ n = VFS::find(*path);
} else {
- return VFS::find(*path, Res::get<DirectoryNode>(b, FNIF_OBJTYPE))->resId();
+ n = VFS::find(*path, Res::get<DirectoryNode>(b, FNIF_OBJTYPE));
}
+ if (n != 0) return n->resId();
}
return (u32int) - 1;
}
@@ -61,6 +64,11 @@ u32int FSNode::setCwdSC() {
return 0;
}
+u32int FSNode::removeSC() {
+ if (!writable()) return 0;
+ return (VFS::remove(this) ? 1 : 0);
+}
+
bool FSNode::readable(User* user) {
if (user == 0) user = Usr::user();
if (user->getUid() == m_uid)
diff --git a/Source/Kernel/VFS/FSNode.proto.h b/Source/Kernel/VFS/FSNode.proto.h
index 6536e21..0aafc8a 100644
--- a/Source/Kernel/VFS/FSNode.proto.h
+++ b/Source/Kernel/VFS/FSNode.proto.h
@@ -17,7 +17,7 @@ class FSNode : public Ressource {
u64int m_length;
u32int m_permissions, m_uid, m_gid;
FileSystem *m_fs;
- FSNode *m_parent;
+ FSNode *m_parent;
//Syscall related
static call_t m_callTable[];
@@ -27,6 +27,7 @@ class FSNode : public Ressource {
u32int getParentSC();
u32int getPathSC();
u32int setCwdSC();
+ u32int removeSC();
bool accessible();
public:
diff --git a/Source/Kernel/VFS/VFS.ns.cpp b/Source/Kernel/VFS/VFS.ns.cpp
index 30ad2d7..2333a36 100644
--- a/Source/Kernel/VFS/VFS.ns.cpp
+++ b/Source/Kernel/VFS/VFS.ns.cpp
@@ -103,9 +103,7 @@ FSNode* createDirectory(const String& path, FSNode* start) {
}
}
-bool remove(const String& path, FSNode* start) {
- FSNode* node = find(path, start);
- if (node == NULL) return false;
+bool remove(FSNode* node) {
FSNode* parent = node->getParent();
if (parent == NULL) return false;
@@ -116,6 +114,12 @@ bool remove(const String& path, FSNode* start) {
}
}
+bool remove(const String& path, FSNode* start) {
+ FSNode* node = find(path, start);
+ if (node == NULL) return false;
+ return remove(node);
+}
+
String path(FSNode* node) {
String path;
diff --git a/Source/Kernel/VFS/VFS.ns.h b/Source/Kernel/VFS/VFS.ns.h
index 94ddad9..72b8c44 100644
--- a/Source/Kernel/VFS/VFS.ns.h
+++ b/Source/Kernel/VFS/VFS.ns.h
@@ -15,6 +15,7 @@ namespace VFS {
FSNode* find(const String& path, FSNode* start = 0);
FSNode* createFile(const String& path, FSNode* start = 0);
FSNode* createDirectory(const String& path, FSNode* start = 0);
+ bool remove(FSNode* node);
bool remove(const String& path, FSNode* start = 0); //Returns false for non-empty directories
String path(FSNode* node); //Returns complete path for a node
}
diff --git a/Source/Library/Interface/FSNode.iface.h b/Source/Library/Interface/FSNode.iface.h
index cba4621..3a5dfad 100644
--- a/Source/Library/Interface/FSNode.iface.h
+++ b/Source/Library/Interface/FSNode.iface.h
@@ -24,6 +24,7 @@ enum {
#define FNIF_GETPERM 0x16
#define FNIF_GETPATH 0x17
#define FNIF_SETCWD 0x18 //Sets node as current working directory
+#define FNIF_REMOVE 0x19
#define FNIF_GETIDXCHILD 0x20 //Get child node from index
#define FNIF_GETNAMECHILD 0x21 //Get child node from name
diff --git a/Source/Library/Userland/Binding/FSNode.class.h b/Source/Library/Userland/Binding/FSNode.class.h
index 61ac991..1fdc7ef 100644
--- a/Source/Library/Userland/Binding/FSNode.class.h
+++ b/Source/Library/Userland/Binding/FSNode.class.h
@@ -1,17 +1,11 @@
+#ifndef DEF_FSNODE_CLASS_H
+#define DEF_FSNODE_CLASS_H
+
#include <Syscall/RessourceCaller.class.h>
#include <FSNode.iface.h>
class FSNode : public RessourceCaller {
public:
- static FSNode getRoot() {
- return FSNode(sCall(FNIF_OBJTYPE, FNIF_SGETRFN));
- }
- static FSNode getCwd() {
- return FSNode(sCall(FNIF_OBJTYPE, FNIF_SGETCWD));
- }
- static FSNode find(String path) { //Finds a node starting from root node
- return FSNode(sCall(FNIF_OBJTYPE, FNIF_SFIND, (u32int)&path, 0));
- }
FSNode(u32int id) : RessourceCaller(id, FNIF_OBJTYPE) {}
String getName() {
@@ -41,13 +35,32 @@ class FSNode : public RessourceCaller {
void setCwd() {
doCall(FNIF_SETCWD);
}
+ bool remove() {
+ return doCall(FNIF_REMOVE) != 0;
+ }
FSNode getChild(u32int idx) {
return FSNode(doCall(FNIF_GETIDXCHILD, idx));
}
FSNode getChild(String name) {
return FSNode(doCall(FNIF_GETNAMECHILD, (u32int)&name));
}
- FSNode findFrom(String path) { //Search a filesystem node starting from here
- return FSNode(sCall(FNIF_OBJTYPE, FNIF_SFIND, (u32int)&path, resId()));
- }
};
+
+namespace FS {
+
+inline FSNode rootNode() {
+ return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SGETRFN));
+}
+
+inline FSNode cwdNode() {
+ return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SGETCWD));
+}
+
+inline FSNode find(String name, FSNode cwd = FSNode(0)) {
+ if (!cwd.valid()) cwd = rootNode();
+ return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SFIND, (u32int)&name, cwd.resId()));
+}
+
+}
+
+#endif
diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h
index 935bb39..ddca6be 100644
--- a/Source/Library/Userland/Binding/Process.class.h
+++ b/Source/Library/Userland/Binding/Process.class.h
@@ -1,3 +1,6 @@
+#ifndef DEF_PROCESS_CLASS_H
+#define DEF_PROCESS_CLASS_H
+
#include <Syscall/RessourceCaller.class.h>
#include <Process.iface.h>
@@ -30,3 +33,5 @@ class Process : public RessourceCaller {
return String::unserialize(doCall(PRIF_GETCMDLINE));
}
};
+
+#endif
diff --git a/Source/Library/Userland/Binding/Thread.class.h b/Source/Library/Userland/Binding/Thread.class.h
index a19c256..1588d8c 100644
--- a/Source/Library/Userland/Binding/Thread.class.h
+++ b/Source/Library/Userland/Binding/Thread.class.h
@@ -1,3 +1,6 @@
+#ifndef DEF_THREAD_CLASS_H
+#define DEF_THREAD_CLASS_H
+
#include <Syscall/RessourceCaller.class.h>
#include <Thread.iface.h>
@@ -17,3 +20,5 @@ class Thread : public RessourceCaller {
doCall(THIF_FINISH, errcode);
}
};
+
+#endif
diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h
index 06a8dd7..1bfce85 100644
--- a/Source/Library/Userland/Binding/VirtualTerminal.class.h
+++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h
@@ -1,3 +1,6 @@
+#ifndef DEF_VIRTUALTERMINAL_CLASS_H
+#define DEF_VIRTUALTERMINAL_CLASS_H
+
#include <Syscall/RessourceCaller.class.h>
#include <VirtualTerminal.iface.h>
@@ -52,3 +55,5 @@ class VirtualTerminal : public RessourceCaller {
};
extern VirtualTerminal invt, outvt;
+
+#endif