From 66630e4154b7c1c47d6223fe5a8607cd269446a0 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 23 Oct 2009 20:43:48 +0200 Subject: Some changes, and implemented rm in userland shell. --- Source/Kernel/VFS/DirectoryNode.class.cpp | 2 ++ Source/Kernel/VFS/FSNode-sc.proto.cpp | 12 ++++++++++-- Source/Kernel/VFS/FSNode.proto.h | 3 ++- Source/Kernel/VFS/VFS.ns.cpp | 10 +++++++--- Source/Kernel/VFS/VFS.ns.h | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) (limited to 'Source/Kernel/VFS') 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(b, FNIF_OBJTYPE))->resId(); + n = VFS::find(*path, Res::get(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 } -- cgit v1.2.3