summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-23 21:06:23 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-23 21:06:23 +0200
commit5dd48c50c0cf7793a5dafa6be769c8a3f8b9ab60 (patch)
tree75ee8e14bf7684394a6a663c90b5c26dc5246702 /Source
parent66630e4154b7c1c47d6223fe5a8607cd269446a0 (diff)
downloadMelon-5dd48c50c0cf7793a5dafa6be769c8a3f8b9ab60.tar.gz
Melon-5dd48c50c0cf7793a5dafa6be769c8a3f8b9ab60.zip
Added some screenshots (\o/) and implemented mkdir in userland.
Diffstat (limited to 'Source')
-rw-r--r--Source/Applications/Shell/Shell-fs.ns.cpp14
-rw-r--r--Source/Applications/Shell/Shell.ns.cpp1
-rw-r--r--Source/Applications/Shell/Shell.ns.h1
-rw-r--r--Source/Kernel/Ressources/Texts/Info.txt5
-rw-r--r--Source/Kernel/VFS/FSNode-sc.proto.cpp13
-rw-r--r--Source/Kernel/VFS/VFS.ns.cpp31
-rw-r--r--Source/Kernel/VFS/VFS.ns.h1
-rw-r--r--Source/Library/Interface/FSNode.iface.h9
-rw-r--r--Source/Library/Userland/Binding/FSNode.class.h5
9 files changed, 75 insertions, 5 deletions
diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.ns.cpp
index 5e6ae4f..b7e585a 100644
--- a/Source/Applications/Shell/Shell-fs.ns.cpp
+++ b/Source/Applications/Shell/Shell-fs.ns.cpp
@@ -15,8 +15,13 @@ void ls(Vector<String>& args) {
d = n;
}
if (d.valid()) outvt << "Contents of directory " << d.path() << " :\n";
+ if (!d.valid()) return;
for (u32int i = 0; i < d.getLength(); i++) {
FSNode n = d.getChild(i);
+ if (!n.valid()) {
+ outvt << " [inacessible file]\n"; //This is a file we are not supposed to be able to read
+ continue;
+ }
String perm = "rwxrwxrwx";
u32int p = n.getPerm();
for (u32int i = 0; i < 9; i++) {
@@ -63,4 +68,13 @@ void rm(Vector<String>& args) {
}
}
+void mkdir(Vector<String>& args) {
+ if (args.size() == 1) outvt << "No directory to create.\n";
+ for (u32int i = 1; i < args.size(); i++) {
+ if (!FS::mkdir(args[i], cwd).valid()) {
+ outvt << "Error while creating directory " << args[i] << "\n";
+ }
+ }
+}
+
}
diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.ns.cpp
index 1f8acae..fe8c5f9 100644
--- a/Source/Applications/Shell/Shell.ns.cpp
+++ b/Source/Applications/Shell/Shell.ns.cpp
@@ -15,6 +15,7 @@ u32int run() {
{"cd", cd},
{"pwd", pwd},
{"rm", rm},
+ {"mkdir", mkdir},
{"", 0}
};
diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h
index 5cf4509..56fdb46 100644
--- a/Source/Applications/Shell/Shell.ns.h
+++ b/Source/Applications/Shell/Shell.ns.h
@@ -11,4 +11,5 @@ namespace Shell {
extern void cd(Vector<String>& args);
extern void pwd(Vector<String>& args);
extern void rm(Vector<String>& args);
+ extern void mkdir(Vector<String>& args);
}
diff --git a/Source/Kernel/Ressources/Texts/Info.txt b/Source/Kernel/Ressources/Texts/Info.txt
deleted file mode 100644
index 56016a2..0000000
--- a/Source/Kernel/Ressources/Texts/Info.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-These files were just added here for fun.
-
-Oh, you wanted to know what the wf command meant ?
-Simple : it means Write File. Type 'wf filename' and then enter the
-file's contents, ending with <CR>.<CR>
diff --git a/Source/Kernel/VFS/FSNode-sc.proto.cpp b/Source/Kernel/VFS/FSNode-sc.proto.cpp
index e3f11db..279303b 100644
--- a/Source/Kernel/VFS/FSNode-sc.proto.cpp
+++ b/Source/Kernel/VFS/FSNode-sc.proto.cpp
@@ -31,6 +31,16 @@ u32int FSNode::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
}
if (n != 0) return n->resId();
}
+ if (wat == FNIF_SMKDIR) {
+ String* path = (String*)a;
+ FSNode* n;
+ if (b == 0) {
+ n = VFS::mkdir(*path);
+ } else {
+ n = VFS::mkdir(*path, Res::get<DirectoryNode>(b, FNIF_OBJTYPE));
+ }
+ if (n != 0) return n->resId();
+ }
return (u32int) - 1;
}
@@ -70,6 +80,7 @@ u32int FSNode::removeSC() {
}
bool FSNode::readable(User* user) {
+ if (ISROOT) return true;
if (user == 0) user = Usr::user();
if (user->getUid() == m_uid)
return ((m_permissions >> 6) & 4) != 0;
@@ -79,6 +90,7 @@ bool FSNode::readable(User* user) {
}
bool FSNode::writable(User* user) {
+ if (ISROOT) return true;
if (user == 0) user = Usr::user();
if (user->getUid() == m_uid)
return ((m_permissions >> 6) & 2) != 0;
@@ -88,6 +100,7 @@ bool FSNode::writable(User* user) {
}
bool FSNode::runnable(User* user) {
+ if (ISROOT) return true;
if (user == 0) user = Usr::user();
if (user->getUid() == m_uid)
return ((m_permissions >> 6) & 1) != 0;
diff --git a/Source/Kernel/VFS/VFS.ns.cpp b/Source/Kernel/VFS/VFS.ns.cpp
index 2333a36..fdfc265 100644
--- a/Source/Kernel/VFS/VFS.ns.cpp
+++ b/Source/Kernel/VFS/VFS.ns.cpp
@@ -103,6 +103,37 @@ FSNode* createDirectory(const String& path, FSNode* start) {
}
}
+//Same as createDirectory but checks for parent directory permissions for current process
+FSNode* mkdir(const String& path, FSNode* start) {
+ if (find(path, start) != NULL) return NULL; //Something already has that name.
+ if (start == 0) start = rootNode;
+
+ Vector<String> p = path.split("/");
+ String name = p.back();
+ p.pop();
+
+ FSNode* node = start;
+ if (!path.empty()) {
+ if (p[0].empty()) node = rootNode;
+ for (u32int i = 0; i < p.size(); i++) {
+ if (p[i] == "..") {
+ node = node->getParent();
+ } else if (!p[i].empty() and p[i] != ".") {
+ if (node->type() == NT_DIRECTORY) {
+ node = ((DirectoryNode*)node)->getChild(p[i]);
+ } else {
+ node = NULL;
+ }
+ }
+ if (node == NULL) return node;
+ }
+ }
+
+ if (node->type() == NT_DIRECTORY)
+ if (node->writable()) return ((DirectoryNode*)node)->createDirectory(name);
+ return NULL;
+}
+
bool remove(FSNode* node) {
FSNode* parent = node->getParent();
if (parent == NULL) return false;
diff --git a/Source/Kernel/VFS/VFS.ns.h b/Source/Kernel/VFS/VFS.ns.h
index 72b8c44..63229bf 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);
+ FSNode* mkdir(const String& path, FSNode* start = 0); //Same as createDirectory, except it checks for parent directory writablilty by current process
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 3a5dfad..e6c45d3 100644
--- a/Source/Library/Interface/FSNode.iface.h
+++ b/Source/Library/Interface/FSNode.iface.h
@@ -1,6 +1,14 @@
#ifndef DEF_FSNODE_IFACE_H
#define DEF_FSNODE_IFACE_H
+/*
+ * The FSNode interface handles all this :
+ * - Navigating in the filesystem
+ * - Listing contents of directories
+ * - Creating/removing/truncating files and directories
+ * - Getting/Setting current working directory (CWD)
+ */
+
enum {
NT_FILE = 1,
NT_DIRECTORY = 2,
@@ -14,6 +22,7 @@ enum {
#define FNIF_SGETRFN 0
#define FNIF_SGETCWD 1 //Get current working directory
#define FNIF_SFIND 2 //Find a node following a path from a node
+#define FNIF_SMKDIR 3 //Makes a directory
#define FNIF_GETNAME 0x10
#define FNIF_TYPE 0x11
diff --git a/Source/Library/Userland/Binding/FSNode.class.h b/Source/Library/Userland/Binding/FSNode.class.h
index 1fdc7ef..6a860ea 100644
--- a/Source/Library/Userland/Binding/FSNode.class.h
+++ b/Source/Library/Userland/Binding/FSNode.class.h
@@ -61,6 +61,11 @@ inline FSNode find(String name, FSNode cwd = FSNode(0)) {
return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SFIND, (u32int)&name, cwd.resId()));
}
+inline FSNode mkdir(String name, FSNode cwd = FSNode(0)) {
+ if (!cwd.valid()) cwd = rootNode();
+ return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SMKDIR, (u32int)&name, cwd.resId()));
+}
+
}
#endif