xref: /haiku/headers/private/fs_shell/fssh_fs_interface.h (revision 079eccf655ba39812b421ae1b87a727d41b50354)
1 /*
2  * Copyright 2004-2008, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FSSH_FS_INTERFACE_H
6 #define _FSSH_FS_INTERFACE_H
7 
8 /*! File System Interface Layer Definition */
9 
10 
11 #include "fssh_disk_device_defs.h"
12 #include "fssh_module.h"
13 #include "fssh_os.h"
14 
15 
16 struct fssh_dirent;
17 struct fssh_fs_info;
18 struct fssh_iovec;
19 struct fssh_partition_data;
20 struct fssh_selectsync;
21 struct fssh_stat;
22 
23 typedef fssh_dev_t fssh_mount_id;
24 typedef fssh_ino_t fssh_vnode_id;
25 
26 /* the file system's private data structures */
27 typedef void *fssh_fs_cookie;
28 
29 /* additional flags passed to write_stat() */
30 #define FSSH_B_STAT_SIZE_INSECURE	0x2000
31 
32 /* passed to write_fs_info() */
33 #define	FSSH_FS_WRITE_FSINFO_NAME	0x0001
34 
35 struct fssh_file_io_vec {
36 	fssh_off_t	offset;
37 	fssh_off_t	length;
38 };
39 
40 #define	FSSH_B_CURRENT_FS_API_VERSION "/v1"
41 
42 // flags for publish_vnode() and fs_volume_ops::get_vnode()
43 #define FSSH_B_VNODE_PUBLISH_REMOVED				0x01
44 #define FSSH_B_VNODE_DONT_CREATE_SPECIAL_SUB_NODE	0x02
45 
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 typedef struct fssh_fs_volume fssh_fs_volume;
52 typedef struct fssh_fs_volume_ops fssh_fs_volume_ops;
53 typedef struct fssh_fs_vnode fssh_fs_vnode;
54 typedef struct fssh_fs_vnode_ops fssh_fs_vnode_ops;
55 
56 
57 struct fssh_fs_volume {
58 	fssh_dev_t			id;
59 	int32_t				layer;
60 	void*				private_volume;
61 	fssh_fs_volume_ops*	ops;
62 	fssh_fs_volume*		sub_volume;
63 	fssh_fs_volume*		super_volume;
64 };
65 
66 struct fssh_fs_vnode {
67 	void*				private_node;
68 	fssh_fs_vnode_ops*	ops;
69 };
70 
71 struct fssh_fs_volume_ops {
72 	fssh_status_t (*unmount)(fssh_fs_volume *volume);
73 
74 	fssh_status_t (*read_fs_info)(fssh_fs_volume *volume,
75 				struct fssh_fs_info *info);
76 	fssh_status_t (*write_fs_info)(fssh_fs_volume *volume,
77 				const struct fssh_fs_info *info, uint32_t mask);
78 	fssh_status_t (*sync)(fssh_fs_volume *volume);
79 
80 	fssh_status_t (*get_vnode)(fssh_fs_volume *volume, fssh_vnode_id id,
81 				fssh_fs_vnode *_vnode, int *_type, uint32_t *_flags,
82 				bool reenter);
83 
84 	/* index directory & index operations */
85 	fssh_status_t (*open_index_dir)(fssh_fs_volume *volume,
86 				fssh_fs_cookie *cookie);
87 	fssh_status_t (*close_index_dir)(fssh_fs_volume *volume,
88 				fssh_fs_cookie cookie);
89 	fssh_status_t (*free_index_dir_cookie)(fssh_fs_volume *volume,
90 				fssh_fs_cookie cookie);
91 	fssh_status_t (*read_index_dir)(fssh_fs_volume *volume,
92 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
93 				fssh_size_t bufferSize, uint32_t *_num);
94 	fssh_status_t (*rewind_index_dir)(fssh_fs_volume *volume,
95 				fssh_fs_cookie cookie);
96 
97 	fssh_status_t (*create_index)(fssh_fs_volume *volume, const char *name,
98 				uint32_t type, uint32_t flags);
99 	fssh_status_t (*remove_index)(fssh_fs_volume *volume, const char *name);
100 	fssh_status_t (*read_index_stat)(fssh_fs_volume *volume, const char *name,
101 				struct fssh_stat *stat);
102 
103 	/* query operations */
104 	fssh_status_t (*open_query)(fssh_fs_volume *volume, const char *query,
105 				uint32_t flags, fssh_port_id port, uint32_t token,
106 				fssh_fs_cookie *_cookie);
107 	fssh_status_t (*close_query)(fssh_fs_volume *volume, fssh_fs_cookie cookie);
108 	fssh_status_t (*free_query_cookie)(fssh_fs_volume *volume,
109 				fssh_fs_cookie cookie);
110 	fssh_status_t (*read_query)(fssh_fs_volume *volume, fssh_fs_cookie cookie,
111 				struct fssh_dirent *buffer, fssh_size_t bufferSize,
112 				uint32_t *_num);
113 	fssh_status_t (*rewind_query)(fssh_fs_volume *volume,
114 				fssh_fs_cookie cookie);
115 
116 	/* support for FS layers */
117 	fssh_status_t (*create_sub_vnode)(fssh_fs_volume *volume, fssh_ino_t id,
118 		fssh_fs_vnode *vnode);
119 	fssh_status_t (*delete_sub_vnode)(fssh_fs_volume *volume,
120 				fssh_fs_vnode *vnode);
121 };
122 
123 struct fssh_fs_vnode_ops {
124 	/* vnode operations */
125 	fssh_status_t (*lookup)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
126 				const char *name, fssh_vnode_id *_id);
127 	fssh_status_t (*get_vnode_name)(fssh_fs_volume *volume,
128 				fssh_fs_vnode *vnode, char *buffer, fssh_size_t bufferSize);
129 
130 	fssh_status_t (*put_vnode)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
131 				bool reenter);
132 	fssh_status_t (*remove_vnode)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
133 				bool reenter);
134 
135 	/* VM file access */
136 	bool (*can_page)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
137 				fssh_fs_cookie cookie);
138 	fssh_status_t (*read_pages)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
139 				fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs,
140 				fssh_size_t count, fssh_size_t *_numBytes, bool reenter);
141 	fssh_status_t (*write_pages)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
142 				fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs,
143 				fssh_size_t count, fssh_size_t *_numBytes, bool reenter);
144 
145 	/* cache file access */
146 	fssh_status_t (*get_file_map)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
147 				fssh_off_t offset, fssh_size_t size,
148 				struct fssh_file_io_vec *vecs, fssh_size_t *_count);
149 
150 	/* common operations */
151 	fssh_status_t (*ioctl)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
152 				fssh_fs_cookie cookie, fssh_ulong op, void *buffer,
153 				fssh_size_t length);
154 	fssh_status_t (*set_flags)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
155 				fssh_fs_cookie cookie, int flags);
156 	fssh_status_t (*select)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
157 				fssh_fs_cookie cookie, uint8_t event, fssh_selectsync *sync);
158 	fssh_status_t (*deselect)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
159 				fssh_fs_cookie cookie, uint8_t event, fssh_selectsync *sync);
160 	fssh_status_t (*fsync)(fssh_fs_volume *volume, fssh_fs_vnode *vnode);
161 
162 	fssh_status_t (*read_symlink)(fssh_fs_volume *volume, fssh_fs_vnode *link,
163 				char *buffer, fssh_size_t *_bufferSize);
164 	fssh_status_t (*create_symlink)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
165 				const char *name, const char *path, int mode);
166 
167 	fssh_status_t (*link)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
168 				const char *name, fssh_fs_vnode *vnode);
169 	fssh_status_t (*unlink)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
170 				const char *name);
171 	fssh_status_t (*rename)(fssh_fs_volume *volume, fssh_fs_vnode *fromDir,
172 				const char *fromName, fssh_fs_vnode *toDir, const char *toName);
173 
174 	fssh_status_t (*access)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
175 				int mode);
176 	fssh_status_t (*read_stat)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
177 				struct fssh_stat *stat);
178 	fssh_status_t (*write_stat)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
179 				const struct fssh_stat *stat, uint32_t statMask);
180 
181 	/* file operations */
182 	fssh_status_t (*create)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
183 				const char *name, int openMode, int perms,
184 				fssh_fs_cookie *_cookie, fssh_vnode_id *_newVnodeID);
185 	fssh_status_t (*open)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
186 				int openMode, fssh_fs_cookie *_cookie);
187 	fssh_status_t (*close)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
188 				fssh_fs_cookie cookie);
189 	fssh_status_t (*free_cookie)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
190 				fssh_fs_cookie cookie);
191 	fssh_status_t (*read)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
192 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
193 				fssh_size_t *length);
194 	fssh_status_t (*write)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
195 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
196 				fssh_size_t *length);
197 
198 	/* directory operations */
199 	fssh_status_t (*create_dir)(fssh_fs_volume *volume, fssh_fs_vnode *parent,
200 				const char *name, int perms, fssh_vnode_id *_newVnodeID);
201 	fssh_status_t (*remove_dir)(fssh_fs_volume *volume, fssh_fs_vnode *parent,
202 				const char *name);
203 	fssh_status_t (*open_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
204 				fssh_fs_cookie *_cookie);
205 	fssh_status_t (*close_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
206 				fssh_fs_cookie cookie);
207 	fssh_status_t (*free_dir_cookie)(fssh_fs_volume *volume,
208 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
209 	fssh_status_t (*read_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
210 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
211 				fssh_size_t bufferSize, uint32_t *_num);
212 	fssh_status_t (*rewind_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
213 				fssh_fs_cookie cookie);
214 
215 	/* attribute directory operations */
216 	fssh_status_t (*open_attr_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
217 				fssh_fs_cookie *_cookie);
218 	fssh_status_t (*close_attr_dir)(fssh_fs_volume *volume,
219 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
220 	fssh_status_t (*free_attr_dir_cookie)(fssh_fs_volume *volume,
221 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
222 	fssh_status_t (*read_attr_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
223 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
224 				fssh_size_t bufferSize, uint32_t *_num);
225 	fssh_status_t (*rewind_attr_dir)(fssh_fs_volume *volume,
226 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
227 
228 	/* attribute operations */
229 	fssh_status_t (*create_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
230 				const char *name, uint32_t type, int openMode,
231 				fssh_fs_cookie *_cookie);
232 	fssh_status_t (*open_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
233 				const char *name, int openMode, fssh_fs_cookie *_cookie);
234 	fssh_status_t (*close_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
235 				fssh_fs_cookie cookie);
236 	fssh_status_t (*free_attr_cookie)(fssh_fs_volume *volume,
237 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
238 	fssh_status_t (*read_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
239 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
240 				fssh_size_t *length);
241 	fssh_status_t (*write_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
242 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
243 				fssh_size_t *length);
244 
245 	fssh_status_t (*read_attr_stat)(fssh_fs_volume *volume,
246 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie,
247 				struct fssh_stat *stat);
248 	fssh_status_t (*write_attr_stat)(fssh_fs_volume *volume,
249 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie,
250 				const struct fssh_stat *stat, int statMask);
251 	fssh_status_t (*rename_attr)(fssh_fs_volume *volume,
252 				fssh_fs_vnode *fromVnode, const char *fromName,
253 				fssh_fs_vnode *toVnode, const char *toName);
254 	fssh_status_t (*remove_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
255 				const char *name);
256 
257 	/* support for vnode and FS layers */
258 	fssh_status_t (*create_special_node)(fssh_fs_volume *volume,
259 				fssh_fs_vnode *dir, const char *name, fssh_fs_vnode *subVnode,
260 				fssh_mode_t mode, uint32_t flags, fssh_fs_vnode *_superVnode,
261 				fssh_ino_t *_nodeID);
262 	fssh_status_t (*get_super_vnode)(fssh_fs_volume *volume,
263 				fssh_fs_vnode *vnode, fssh_fs_volume *superVolume,
264 				fssh_fs_vnode *superVnode);
265 };
266 
267 typedef struct fssh_file_system_module_info {
268 	struct fssh_module_info	info;
269 	const char*				short_name;
270 	const char*				pretty_name;
271 	uint32_t				flags;	// DDM flags
272 
273 	/* scanning (the device is write locked) */
274 	float (*identify_partition)(int fd, fssh_partition_data *partition,
275 				void **cookie);
276 	fssh_status_t (*scan_partition)(int fd, fssh_partition_data *partition,
277 				void *cookie);
278 	void (*free_identify_partition_cookie)(fssh_partition_data *partition,
279 				void *cookie);
280 	void (*free_partition_content_cookie)(fssh_partition_data *partition);
281 
282 	/* general operations */
283 	fssh_status_t (*mount)(fssh_fs_volume *volume, const char *device,
284 				uint32_t flags, const char *args, fssh_vnode_id *_rootVnodeID);
285 
286 	/* capability querying (the device is read locked) */
287 	uint32_t (*get_supported_operations)(fssh_partition_data* partition,
288 				uint32_t mask);
289 
290 	bool (*validate_resize)(fssh_partition_data *partition, fssh_off_t *size);
291 	bool (*validate_move)(fssh_partition_data *partition, fssh_off_t *start);
292 	bool (*validate_set_content_name)(fssh_partition_data *partition,
293 				char *name);
294 	bool (*validate_set_content_parameters)(fssh_partition_data *partition,
295 				const char *parameters);
296 	bool (*validate_initialize)(fssh_partition_data *partition, char *name,
297 				const char *parameters);
298 
299 	/* shadow partition modification (device is write locked) */
300 	fssh_status_t (*shadow_changed)(fssh_partition_data *partition,
301 				fssh_partition_data *child, uint32_t operation);
302 
303 	/* writing (the device is NOT locked) */
304 	fssh_status_t (*defragment)(int fd, fssh_partition_id partition,
305 				fssh_disk_job_id job);
306 	fssh_status_t (*repair)(int fd, fssh_partition_id partition, bool checkOnly,
307 				fssh_disk_job_id job);
308 	fssh_status_t (*resize)(int fd, fssh_partition_id partition,
309 				fssh_off_t size, fssh_disk_job_id job);
310 	fssh_status_t (*move)(int fd, fssh_partition_id partition,
311 				fssh_off_t offset, fssh_disk_job_id job);
312 	fssh_status_t (*set_content_name)(int fd, fssh_partition_id partition,
313 				const char *name, fssh_disk_job_id job);
314 	fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition,
315 				const char *parameters, fssh_disk_job_id job);
316 	fssh_status_t (*initialize)(int fd, fssh_partition_id partition,
317 				const char *name, const char *parameters,
318 				fssh_off_t partitionSize, fssh_disk_job_id job);
319 } fssh_file_system_module_info;
320 
321 
322 /* file system add-ons only prototypes */
323 extern fssh_status_t fssh_new_vnode(fssh_fs_volume *volume,
324 				fssh_vnode_id vnodeID, void *privateNode,
325 				fssh_fs_vnode_ops *ops);
326 extern fssh_status_t fssh_publish_vnode(fssh_fs_volume *volume,
327 				fssh_vnode_id vnodeID, void *privateNode,
328 				fssh_fs_vnode_ops *ops, int type, uint32_t flags);
329 extern fssh_status_t fssh_get_vnode(fssh_fs_volume *volume,
330 				fssh_vnode_id vnodeID, void **_privateNode);
331 extern fssh_status_t fssh_put_vnode(fssh_fs_volume *volume,
332 				fssh_vnode_id vnodeID);
333 extern fssh_status_t fssh_remove_vnode(fssh_fs_volume *volume,
334 				fssh_vnode_id vnodeID);
335 extern fssh_status_t fssh_unremove_vnode(fssh_fs_volume *volume,
336 				fssh_vnode_id vnodeID);
337 extern fssh_status_t fssh_get_vnode_removed(fssh_fs_volume *volume,
338 				fssh_vnode_id vnodeID, bool* removed);
339 
340 extern fssh_status_t fssh_read_pages(int fd, fssh_off_t pos,
341 				const struct fssh_iovec *vecs, fssh_size_t count,
342 				fssh_size_t *_numBytes, bool fsReenter);
343 extern fssh_status_t fssh_write_pages(int fd, fssh_off_t pos,
344 				const struct fssh_iovec *vecs, fssh_size_t count,
345 				fssh_size_t *_numBytes, bool fsReenter);
346 extern fssh_status_t fssh_read_file_io_vec_pages(int fd,
347 				const struct fssh_file_io_vec *fileVecs,
348 				fssh_size_t fileVecCount, const struct fssh_iovec *vecs,
349 				fssh_size_t vecCount, uint32_t *_vecIndex,
350 				fssh_size_t *_vecOffset, fssh_size_t *_bytes);
351 extern fssh_status_t fssh_write_file_io_vec_pages(int fd,
352 				const struct fssh_file_io_vec *fileVecs,
353 				fssh_size_t fileVecCount, const struct fssh_iovec *vecs,
354 				fssh_size_t vecCount, uint32_t *_vecIndex,
355 				fssh_size_t *_vecOffset, fssh_size_t *_bytes);
356 
357 extern fssh_status_t fssh_notify_entry_created(fssh_mount_id device,
358 				fssh_vnode_id directory, const char *name, fssh_vnode_id node);
359 extern fssh_status_t fssh_notify_entry_removed(fssh_mount_id device,
360 				fssh_vnode_id directory, const char *name, fssh_vnode_id node);
361 extern fssh_status_t fssh_notify_entry_moved(fssh_mount_id device,
362 				fssh_vnode_id fromDirectory, const char *fromName,
363 				fssh_vnode_id toDirectory, const char *toName,
364 				fssh_vnode_id node);
365 extern fssh_status_t fssh_notify_stat_changed(fssh_mount_id device,
366 				fssh_vnode_id node, uint32_t statFields);
367 extern fssh_status_t fssh_notify_attribute_changed(fssh_mount_id device,
368 				fssh_vnode_id node, const char *attribute, int32_t cause);
369 
370 extern fssh_status_t fssh_notify_query_entry_created(fssh_port_id port,
371 				int32_t token, fssh_mount_id device,
372 				fssh_vnode_id directory, const char *name,
373 				fssh_vnode_id node);
374 extern fssh_status_t fssh_notify_query_entry_removed(fssh_port_id port,
375 				int32_t token, fssh_mount_id device,
376 				fssh_vnode_id directory, const char *name,
377 				fssh_vnode_id node);
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 
383 #endif	/* _FSSH_FS_INTERFACE_H */
384