1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#ifndef DEF_FSNODE_PROTO_H
#define DEF_FSNODE_PROTO_H
#include <common.h>
#include <String.class.h>
class FSNode;
#include <VFS/FileSystem.proto.h>
#include <SyscallManager/Ressource.class.h>
#include <FSNode.iface.h>
#include <UserManager/User.class.h>
class FSNode : public Ressource {
protected:
String m_name;
u64int m_length;
u32int m_permissions, m_uid, m_gid;
FileSystem *m_fs;
FSNode *m_parent;
//Syscall related
static call_t m_callTable[];
u32int getNameSC();
u32int getLengthSC();
u32int typeSC();
u32int getParentSC();
u32int getPathSC();
u32int setCwdSC();
u32int removeSC();
bool accessible();
public:
static u32int scall(u8int, u32int, u32int, u32int, u32int);
FSNode(String name, FileSystem* fs, FSNode* parent, u64int length = 0, u32int permissions = 0777,
u32int uid = 0, u32int gid = 0) :
Ressource(FNIF_OBJTYPE, m_callTable), m_name(name), m_length(length), m_permissions(permissions),
m_uid(uid), m_gid(gid), m_fs(fs), m_parent(parent) {}
virtual ~FSNode() {}
virtual u8int type() = 0;
virtual bool removable() = 0; //True for files, false for non-empty directories, true otherwise
virtual bool used() { return false; } //True if file is read/written from/to
const String& getName() { return m_name; }
u64int getLength() { return m_length; }
u32int getPermissions() { return m_permissions; }
u32int getUid() { return m_uid; }
u32int getGid() { return m_gid; }
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);
if (b) m_name = name;
return b;
}
bool setPermissions(u32int permissions) {
bool b = m_fs->setPermissions(this, permissions);
if (b) m_permissions = permissions;
return b;
}
bool setUid(u32int uid) {
bool b = m_fs->setUid(this, uid);
if (b) m_uid = uid;
return b;
}
bool setGid(u32int gid) {
bool b = m_fs->setGid(this, gid);
if (b) m_gid = gid;
return b;
}
bool setParent(FSNode* parent) {
bool b = m_fs->setParent(this, parent); //FSSetParent is only expected to move files/directories in the same filesystem
if (b) m_parent = parent;
return b;
}
};
#endif
|