xref: /haiku/headers/private/userlandfs/private/FSCapabilities.h (revision 899e0ef82b5624ace2ccfa5f5a58c8ebee54aaef)
1 /*
2  * Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef USERLAND_FS_FS_CAPABILITIES_H
6 #define USERLAND_FS_FS_CAPABILITIES_H
7 
8 #include <string.h>
9 #include <stdio.h>
10 
11 #include <bitset>
12 
13 #include "Debug.h"
14 
15 enum client_fs_type {
16 	CLIENT_FS_BEOS_KERNEL = 0,
17 	CLIENT_FS_HAIKU_KERNEL,
18 	CLIENT_FS_FUSE
19 };
20 
21 // FS capabilities
22 enum {
23 	// FS operations
24 	FS_CAPABILITY_MOUNT	= 0,
25 
26 	FS_CAPABILITY_COUNT
27 };
28 
29 // Volume capabilities
30 enum {
31 	// general operations
32 	FS_VOLUME_CAPABILITY_UNMOUNT,
33 
34 	FS_VOLUME_CAPABILITY_READ_FS_INFO,
35 	FS_VOLUME_CAPABILITY_WRITE_FS_INFO,
36 	FS_VOLUME_CAPABILITY_SYNC,
37 
38 	FS_VOLUME_CAPABILITY_GET_VNODE,
39 
40 	// index directory & index operations
41 	FS_VOLUME_CAPABILITY_OPEN_INDEX_DIR,
42 	FS_VOLUME_CAPABILITY_CLOSE_INDEX_DIR,
43 	FS_VOLUME_CAPABILITY_FREE_INDEX_DIR_COOKIE,
44 	FS_VOLUME_CAPABILITY_READ_INDEX_DIR,
45 	FS_VOLUME_CAPABILITY_REWIND_INDEX_DIR,
46 
47 	FS_VOLUME_CAPABILITY_CREATE_INDEX,
48 	FS_VOLUME_CAPABILITY_REMOVE_INDEX,
49 	FS_VOLUME_CAPABILITY_READ_INDEX_STAT,
50 
51 	// query operations
52 	FS_VOLUME_CAPABILITY_OPEN_QUERY,
53 	FS_VOLUME_CAPABILITY_CLOSE_QUERY,
54 	FS_VOLUME_CAPABILITY_FREE_QUERY_COOKIE,
55 	FS_VOLUME_CAPABILITY_READ_QUERY,
56 	FS_VOLUME_CAPABILITY_REWIND_QUERY,
57 
58 	// support for FS layers
59 	FS_VOLUME_CAPABILITY_ALL_LAYERS_MOUNTED,
60 	FS_VOLUME_CAPABILITY_CREATE_SUB_VNODE,
61 	FS_VOLUME_CAPABILITY_DELETE_SUB_VNODE,
62 
63 	FS_VOLUME_CAPABILITY_COUNT
64 };
65 
66 // VNode capabilities
67 enum {
68 	// vnode operations
69 	FS_VNODE_CAPABILITY_LOOKUP,
70 	FS_VNODE_CAPABILITY_GET_VNODE_NAME,
71 
72 	FS_VNODE_CAPABILITY_PUT_VNODE,
73 	FS_VNODE_CAPABILITY_REMOVE_VNODE,
74 
75 	// VM file access
76 	FS_VNODE_CAPABILITY_CAN_PAGE,
77 	FS_VNODE_CAPABILITY_READ_PAGES,
78 	FS_VNODE_CAPABILITY_WRITE_PAGES,
79 
80 	// asynchronous I/O
81 	FS_VNODE_CAPABILITY_IO,
82 	FS_VNODE_CAPABILITY_CANCEL_IO,
83 
84 	// cache file access
85 	FS_VNODE_CAPABILITY_GET_FILE_MAP,
86 
87 	// common operations
88 	FS_VNODE_CAPABILITY_IOCTL,
89 	FS_VNODE_CAPABILITY_SET_FLAGS,
90 	FS_VNODE_CAPABILITY_SELECT,
91 	FS_VNODE_CAPABILITY_DESELECT,
92 	FS_VNODE_CAPABILITY_FSYNC,
93 
94 	FS_VNODE_CAPABILITY_READ_SYMLINK,
95 	FS_VNODE_CAPABILITY_CREATE_SYMLINK,
96 
97 	FS_VNODE_CAPABILITY_LINK,
98 	FS_VNODE_CAPABILITY_UNLINK,
99 	FS_VNODE_CAPABILITY_RENAME,
100 
101 	FS_VNODE_CAPABILITY_ACCESS,
102 	FS_VNODE_CAPABILITY_READ_STAT,
103 	FS_VNODE_CAPABILITY_WRITE_STAT,
104 
105 	// file operations
106 	FS_VNODE_CAPABILITY_CREATE,
107 	FS_VNODE_CAPABILITY_OPEN,
108 	FS_VNODE_CAPABILITY_CLOSE,
109 	FS_VNODE_CAPABILITY_FREE_COOKIE,
110 	FS_VNODE_CAPABILITY_READ,
111 	FS_VNODE_CAPABILITY_WRITE,
112 
113 	// directory operations
114 	FS_VNODE_CAPABILITY_CREATE_DIR,
115 	FS_VNODE_CAPABILITY_REMOVE_DIR,
116 	FS_VNODE_CAPABILITY_OPEN_DIR,
117 	FS_VNODE_CAPABILITY_CLOSE_DIR,
118 	FS_VNODE_CAPABILITY_FREE_DIR_COOKIE,
119 	FS_VNODE_CAPABILITY_READ_DIR,
120 	FS_VNODE_CAPABILITY_REWIND_DIR,
121 
122 	// attribute directory operations
123 	FS_VNODE_CAPABILITY_OPEN_ATTR_DIR,
124 	FS_VNODE_CAPABILITY_CLOSE_ATTR_DIR,
125 	FS_VNODE_CAPABILITY_FREE_ATTR_DIR_COOKIE,
126 	FS_VNODE_CAPABILITY_READ_ATTR_DIR,
127 	FS_VNODE_CAPABILITY_REWIND_ATTR_DIR,
128 
129 	// attribute operations
130 	FS_VNODE_CAPABILITY_CREATE_ATTR,
131 	FS_VNODE_CAPABILITY_OPEN_ATTR,
132 	FS_VNODE_CAPABILITY_CLOSE_ATTR,
133 	FS_VNODE_CAPABILITY_FREE_ATTR_COOKIE,
134 	FS_VNODE_CAPABILITY_READ_ATTR,
135 	FS_VNODE_CAPABILITY_WRITE_ATTR,
136 
137 	FS_VNODE_CAPABILITY_READ_ATTR_STAT,
138 	FS_VNODE_CAPABILITY_WRITE_ATTR_STAT,
139 	FS_VNODE_CAPABILITY_RENAME_ATTR,
140 	FS_VNODE_CAPABILITY_REMOVE_ATTR,
141 
142 	// support for node and FS layers
143 	FS_VNODE_CAPABILITY_CREATE_SPECIAL_NODE,
144 	FS_VNODE_CAPABILITY_GET_SUPER_VNODE,
145 
146 	FS_VNODE_CAPABILITY_COUNT
147 };
148 
149 namespace UserlandFSUtil {
150 
151 template<const int CapabilityCount>
152 struct FSCapabilitiesBase {
153 			std::bitset<CapabilityCount>	capabilities;
154 
155 	inline	void				ClearAll();
156 
157 	inline	void				Set(uint32 capability, bool set = true);
158 	inline	void				Clear(uint32 capability);
159 	inline	bool				Get(uint32 capability) const;
160 
161 	inline	uint32				GetHashCode() const;
162 
163 	inline	bool				operator==(
164 									const FSCapabilitiesBase<CapabilityCount>&
165 										other) const;
166 
167 	inline	void				Dump() const;
168 };
169 
170 
171 // ClearAll
172 template<const int CapabilityCount>
173 inline void
ClearAll()174 FSCapabilitiesBase<CapabilityCount>::ClearAll()
175 {
176 	capabilities.reset();
177 }
178 
179 
180 // Set
181 template<const int CapabilityCount>
182 inline void
Set(uint32 capability,bool set)183 FSCapabilitiesBase<CapabilityCount>::Set(uint32 capability, bool set)
184 {
185 	if (capability >= CapabilityCount)
186 		return;
187 
188 	capabilities.set(capability, set);
189 }
190 
191 
192 // Clear
193 template<const int CapabilityCount>
194 inline void
Clear(uint32 capability)195 FSCapabilitiesBase<CapabilityCount>::Clear(uint32 capability)
196 {
197 	if (capability >= CapabilityCount)
198 		return;
199 
200 	capabilities.reset(capability);
201 }
202 
203 
204 // Get
205 template<const int CapabilityCount>
206 inline bool
Get(uint32 capability)207 FSCapabilitiesBase<CapabilityCount>::Get(uint32 capability) const
208 {
209 	if (capability >= CapabilityCount)
210 		return false;
211 
212 	return capabilities.test(capability);
213 }
214 
215 
216 // GetHashCode
217 template<const int CapabilityCount>
218 inline uint32
GetHashCode()219 FSCapabilitiesBase<CapabilityCount>::GetHashCode() const
220 {
221 	uint32 hash = 0;
222 	for (int i = 0; i < CapabilityCount; i++)
223 		hash ^= capabilities.test(i) << (i % 32);
224 	return hash;
225 }
226 
227 
228 // ==
229 template<const int CapabilityCount>
230 inline bool
231 FSCapabilitiesBase<CapabilityCount>::operator==(
232 	const FSCapabilitiesBase<CapabilityCount>& other) const
233 {
234 	return capabilities == other.capabilities;
235 }
236 
237 
238 // Dump
239 template<const int CapabilityCount>
240 inline void
Dump()241 FSCapabilitiesBase<CapabilityCount>::Dump() const
242 {
243 	D(
244 		PRINT(("FSCapabilities[%s]\n", capabilities.to_string().c_str()));
245 	)
246 }
247 
248 
249 typedef FSCapabilitiesBase<FS_CAPABILITY_COUNT>			FSCapabilities;
250 typedef FSCapabilitiesBase<FS_VOLUME_CAPABILITY_COUNT>	FSVolumeCapabilities;
251 typedef FSCapabilitiesBase<FS_VNODE_CAPABILITY_COUNT>	FSVNodeCapabilities;
252 
253 }	// namespace UserlandFSUtil
254 
255 using UserlandFSUtil::FSCapabilities;
256 using UserlandFSUtil::FSVolumeCapabilities;
257 using UserlandFSUtil::FSVNodeCapabilities;
258 
259 #endif	// USERLAND_FS_FS_CAPABILITIES_H
260