xref: /haiku/src/add-ons/kernel/file_systems/netfs/headers/shared/Permissions.h (revision 5a1d355fdf2747f80f8c46e2539f844a0b813346)
1 // Permissions.h
2 
3 #ifndef NET_FS_PERMISSIONS_H
4 #define NET_FS_PERMISSIONS_H
5 
6 #include <SupportDefs.h>
7 
8 enum {
9 	// file permissions
10 	READ_PERMISSION					= 0x01,
11 	WRITE_PERMISSION				= 0x02,
12 
13 	// directory permissions
14 	READ_DIR_PERMISSION				= 0x04,
15 	WRITE_DIR_PERMISSION			= 0x08,
16 	RESOLVE_DIR_ENTRY_PERMISSION	= 0x10,
17 
18 	// share permissions
19 	MOUNT_SHARE_PERMISSION			= 0x20,
20 	QUERY_SHARE_PERMISSION			= 0x40,
21 
22 	// all permissions
23 	ALL_PERMISSIONS					= 0x7f,
24 };
25 
26 class Permissions {
27 public:
28 	inline						Permissions();
29 	inline						Permissions(uint32 permissions);
30 	inline						Permissions(const Permissions& other);
31 
32 	inline	uint32				GetPermissions() const;
33 
34 	inline	Permissions&		AddPermissions(uint32 permissions);
35 	inline	Permissions&		AddPermissions(Permissions permissions);
36 
37 	inline	bool				Implies(uint32 permissions) const;
38 
39 	inline	bool				ImpliesReadPermission() const;
40 	inline	bool				ImpliesWritePermission() const;
41 	inline	bool				ImpliesReadDirPermission() const;
42 	inline	bool				ImpliesWriteDirPermission() const;
43 	inline	bool				ImpliesResolveDirEntryPermission() const;
44 	inline	bool				ImpliesMountSharePermission() const;
45 	inline	bool				ImpliesQuerySharePermission() const;
46 
47 	inline	Permissions&		operator=(const Permissions& other);
48 	inline	bool				operator==(const Permissions& other) const;
49 	inline	bool				operator!=(const Permissions& other) const;
50 
51 private:
52 			uint32				fPermissions;
53 };
54 
55 // inline implementation
56 
57 // constructor
58 inline
Permissions()59 Permissions::Permissions()
60 	: fPermissions(0)
61 {
62 }
63 
64 // constructor
65 inline
Permissions(uint32 permissions)66 Permissions::Permissions(uint32 permissions)
67 	: fPermissions(permissions)
68 {
69 }
70 
71 // copy constructor
72 inline
Permissions(const Permissions & other)73 Permissions::Permissions(const Permissions& other)
74 	: fPermissions(other.fPermissions)
75 {
76 }
77 
78 // GetPermissions
79 inline
80 uint32
GetPermissions()81 Permissions::GetPermissions() const
82 {
83 	return fPermissions;
84 }
85 
86 // AddPermissions
87 inline
88 Permissions&
AddPermissions(uint32 permissions)89 Permissions::AddPermissions(uint32 permissions)
90 {
91 	fPermissions |= permissions;
92 	return *this;
93 }
94 
95 // AddPermissions
96 inline
97 Permissions&
AddPermissions(Permissions permissions)98 Permissions::AddPermissions(Permissions permissions)
99 {
100 	fPermissions |= permissions.fPermissions;
101 	return *this;
102 }
103 
104 // Implies
105 inline
106 bool
Implies(uint32 permissions)107 Permissions::Implies(uint32 permissions) const
108 {
109 	return ((fPermissions & permissions) == permissions);
110 }
111 
112 // ImpliesReadPermission
113 inline
114 bool
ImpliesReadPermission()115 Permissions::ImpliesReadPermission() const
116 {
117 	return Implies(READ_PERMISSION);
118 }
119 
120 // ImpliesWritePermission
121 inline
122 bool
ImpliesWritePermission()123 Permissions::ImpliesWritePermission() const
124 {
125 	return Implies(WRITE_PERMISSION);
126 }
127 
128 // ImpliesReadDirPermission
129 inline
130 bool
ImpliesReadDirPermission()131 Permissions::ImpliesReadDirPermission() const
132 {
133 	return Implies(READ_DIR_PERMISSION);
134 }
135 
136 // ImpliesWriteDirPermission
137 inline
138 bool
ImpliesWriteDirPermission()139 Permissions::ImpliesWriteDirPermission() const
140 {
141 	return Implies(WRITE_DIR_PERMISSION);
142 }
143 
144 // ImpliesResolveDirEntryPermission
145 inline
146 bool
ImpliesResolveDirEntryPermission()147 Permissions::ImpliesResolveDirEntryPermission() const
148 {
149 	return Implies(RESOLVE_DIR_ENTRY_PERMISSION);
150 }
151 
152 // ImpliesMountSharePermission
153 inline
154 bool
ImpliesMountSharePermission()155 Permissions::ImpliesMountSharePermission() const
156 {
157 	return Implies(MOUNT_SHARE_PERMISSION);
158 }
159 
160 // ImpliesQuerySharePermission
161 inline
162 bool
ImpliesQuerySharePermission()163 Permissions::ImpliesQuerySharePermission() const
164 {
165 	return Implies(QUERY_SHARE_PERMISSION);
166 }
167 
168 // =
169 inline
170 Permissions&
171 Permissions::operator=(const Permissions& other)
172 {
173 	fPermissions = other.fPermissions;
174 	return *this;
175 }
176 
177 // ==
178 inline
179 bool
180 Permissions::operator==(const Permissions& other) const
181 {
182 	return (fPermissions == other.fPermissions);
183 }
184 
185 // !=
186 inline
187 bool
188 Permissions::operator!=(const Permissions& other) const
189 {
190 	return (fPermissions != other.fPermissions);
191 }
192 
193 #endif	// NET_FS_PERMISSIONS_H
194