summaryrefslogtreecommitdiff
path: root/Source/Library/Userland/Binding/FSNode.class.h
blob: 1fdc7eff635f74ac56ad3d1006f28eae53039e3f (plain) (blame)
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
#ifndef DEF_FSNODE_CLASS_H
#define DEF_FSNODE_CLASS_H

#include <Syscall/RessourceCaller.class.h>
#include <FSNode.iface.h>

class FSNode : public RessourceCaller {
	public:
	FSNode(u32int id) : RessourceCaller(id, FNIF_OBJTYPE) {}

	String getName() {
		return String::unserialize(doCall(FNIF_GETNAME));
	}
	u8int type() {
		return doCall(FNIF_TYPE);
	}
	FSNode getParent() {
		return FSNode(doCall(FNIF_GETPARENT));
	}
	u64int getLength() {
		return *((u64int*)doCall(FNIF_GETLENGTH));
	}
	u32int getUid() {
		return doCall(FNIF_GETUID);
	}
	u32int getGid() {
		return doCall(FNIF_GETGID);
	}
	u32int getPerm() {
		return doCall(FNIF_GETPERM);
	}
	String path() {
		return String::unserialize(doCall(FNIF_GETPATH));
	}
	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));
	}
};

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