diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-23 17:28:25 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-23 17:28:25 +0200 |
commit | f0556ed7f051fb101dc68752526696365bf79a11 (patch) | |
tree | 61345fbadbf76c6f12b36b48a9dfadd744f6cbbd /Source/Kernel/VFS | |
parent | df179c18baab4b5d85a283924fb23dfee7ea7fdb (diff) | |
download | Melon-f0556ed7f051fb101dc68752526696365bf79a11.tar.gz Melon-f0556ed7f051fb101dc68752526696365bf79a11.zip |
More work on syscalls and shell
Diffstat (limited to 'Source/Kernel/VFS')
-rw-r--r-- | Source/Kernel/VFS/FSNode-sc.proto.cpp | 40 | ||||
-rw-r--r-- | Source/Kernel/VFS/FSNode.proto.h | 16 |
2 files changed, 49 insertions, 7 deletions
diff --git a/Source/Kernel/VFS/FSNode-sc.proto.cpp b/Source/Kernel/VFS/FSNode-sc.proto.cpp index 9e485e1..fdea85f 100644 --- a/Source/Kernel/VFS/FSNode-sc.proto.cpp +++ b/Source/Kernel/VFS/FSNode-sc.proto.cpp @@ -1,11 +1,16 @@ #include "FSNode.proto.h" #include <VFS/VFS.ns.h> +#include <UserManager/Usr.ns.h> call_t FSNode::m_callTable[] = { CALL0(FNIF_GETNAME, &FSNode::getNameSC), CALL0(FNIF_TYPE, &FSNode::typeSC), CALL0(FNIF_GETPARENT, &FSNode::getParentSC), CALL0(FNIF_GETLENGTH, &FSNode::getLengthSC), + CALL0(FNIF_GETUID, &FSNode::getUid), + CALL0(FNIF_GETGID, &FSNode::getGid), + CALL0(FNIF_GETPERM, &FSNode::getPermissions), + CALL0(FNIF_GETPATH, &FSNode::getPathSC), CALL0(0, 0) }; @@ -32,3 +37,38 @@ u32int FSNode::getParentSC() { if (m_parent != 0) return m_parent->resId(); return (u32int) - 1; } + +u32int FSNode::getPathSC() { + return VFS::path(this).serialize(); +} + +bool FSNode::readable(User* user) { + if (user == 0) user = Usr::user(); + if (user->getUid() == m_uid) + return ((m_permissions >> 6) & 4) != 0; + if (user->isInGroup(m_gid)) + return ((m_permissions >> 3) & 4) != 0; + return (m_permissions & 4) != 0; +} + +bool FSNode::writable(User* user) { + if (user == 0) user = Usr::user(); + if (user->getUid() == m_uid) + return ((m_permissions >> 6) & 2) != 0; + if (user->isInGroup(m_gid)) + return ((m_permissions >> 3) & 2) != 0; + return (m_permissions & 2) != 0; +} + +bool FSNode::runnable(User* user) { + if (user == 0) user = Usr::user(); + if (user->getUid() == m_uid) + return ((m_permissions >> 6) & 1) != 0; + if (user->isInGroup(m_gid)) + return ((m_permissions >> 3) & 1) != 0; + return (m_permissions & 1) != 0; +} + +bool FSNode::accessible() { + return readable(); +} diff --git a/Source/Kernel/VFS/FSNode.proto.h b/Source/Kernel/VFS/FSNode.proto.h index b648141..8b6974a 100644 --- a/Source/Kernel/VFS/FSNode.proto.h +++ b/Source/Kernel/VFS/FSNode.proto.h @@ -3,18 +3,13 @@ #include <common.h> #include <String.class.h> + class FSNode; #include <VFS/FileSystem.proto.h> #include <SyscallManager/Ressource.class.h> #include <FSNode.iface.h> - -enum { - NT_FILE = 1, - NT_DIRECTORY = 2, - NT_SYMLINK = 3, - NT_MOUNTPOINT = 4 -}; +#include <UserManager/User.class.h> class FSNode : public Ressource { protected: @@ -30,6 +25,8 @@ class FSNode : public Ressource { u32int getLengthSC(); u32int typeSC(); u32int getParentSC(); + u32int getPathSC(); + bool accessible(); public: static u32int scall(u8int, u32int, u32int, u32int, u32int); @@ -52,6 +49,11 @@ class FSNode : public Ressource { FileSystem *getFS() { return m_fs; } FSNode* getParent() { return m_parent; } + //Helper functions + bool readable(User* user = 0); + bool writable(User* user = 0); + bool runnable(User* user = 0); + public: bool setName(String name) { bool b = m_fs->setName(this, name); |