xref: /haiku/headers/private/fs_shell/fssh_fs_interface.h (revision cfc3fa87da824bdf593eb8b817a83b6376e77935)
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, uint32_t ref,
158 				fssh_selectsync *sync);
159 	fssh_status_t (*deselect)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
160 				fssh_fs_cookie cookie, uint8_t event, fssh_selectsync *sync);
161 	fssh_status_t (*fsync)(fssh_fs_volume *volume, fssh_fs_vnode *vnode);
162 
163 	fssh_status_t (*read_symlink)(fssh_fs_volume *volume, fssh_fs_vnode *link,
164 				char *buffer, fssh_size_t *_bufferSize);
165 	fssh_status_t (*create_symlink)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
166 				const char *name, const char *path, int mode);
167 
168 	fssh_status_t (*link)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
169 				const char *name, fssh_fs_vnode *vnode);
170 	fssh_status_t (*unlink)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
171 				const char *name);
172 	fssh_status_t (*rename)(fssh_fs_volume *volume, fssh_fs_vnode *fromDir,
173 				const char *fromName, fssh_fs_vnode *toDir, const char *toName);
174 
175 	fssh_status_t (*access)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
176 				int mode);
177 	fssh_status_t (*read_stat)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
178 				struct fssh_stat *stat);
179 	fssh_status_t (*write_stat)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
180 				const struct fssh_stat *stat, uint32_t statMask);
181 
182 	/* file operations */
183 	fssh_status_t (*create)(fssh_fs_volume *volume, fssh_fs_vnode *dir,
184 				const char *name, int openMode, int perms,
185 				fssh_fs_cookie *_cookie, fssh_vnode_id *_newVnodeID);
186 	fssh_status_t (*open)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
187 				int openMode, fssh_fs_cookie *_cookie);
188 	fssh_status_t (*close)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
189 				fssh_fs_cookie cookie);
190 	fssh_status_t (*free_cookie)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
191 				fssh_fs_cookie cookie);
192 	fssh_status_t (*read)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
193 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
194 				fssh_size_t *length);
195 	fssh_status_t (*write)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
196 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
197 				fssh_size_t *length);
198 
199 	/* directory operations */
200 	fssh_status_t (*create_dir)(fssh_fs_volume *volume, fssh_fs_vnode *parent,
201 				const char *name, int perms, fssh_vnode_id *_newVnodeID);
202 	fssh_status_t (*remove_dir)(fssh_fs_volume *volume, fssh_fs_vnode *parent,
203 				const char *name);
204 	fssh_status_t (*open_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
205 				fssh_fs_cookie *_cookie);
206 	fssh_status_t (*close_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
207 				fssh_fs_cookie cookie);
208 	fssh_status_t (*free_dir_cookie)(fssh_fs_volume *volume,
209 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
210 	fssh_status_t (*read_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
211 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
212 				fssh_size_t bufferSize, uint32_t *_num);
213 	fssh_status_t (*rewind_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
214 				fssh_fs_cookie cookie);
215 
216 	/* attribute directory operations */
217 	fssh_status_t (*open_attr_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
218 				fssh_fs_cookie *_cookie);
219 	fssh_status_t (*close_attr_dir)(fssh_fs_volume *volume,
220 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
221 	fssh_status_t (*free_attr_dir_cookie)(fssh_fs_volume *volume,
222 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
223 	fssh_status_t (*read_attr_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
224 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
225 				fssh_size_t bufferSize, uint32_t *_num);
226 	fssh_status_t (*rewind_attr_dir)(fssh_fs_volume *volume,
227 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
228 
229 	/* attribute operations */
230 	fssh_status_t (*create_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
231 				const char *name, uint32_t type, int openMode,
232 				fssh_fs_cookie *_cookie);
233 	fssh_status_t (*open_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
234 				const char *name, int openMode, fssh_fs_cookie *_cookie);
235 	fssh_status_t (*close_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
236 				fssh_fs_cookie cookie);
237 	fssh_status_t (*free_attr_cookie)(fssh_fs_volume *volume,
238 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie);
239 	fssh_status_t (*read_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
240 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
241 				fssh_size_t *length);
242 	fssh_status_t (*write_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
243 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
244 				fssh_size_t *length);
245 
246 	fssh_status_t (*read_attr_stat)(fssh_fs_volume *volume,
247 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie,
248 				struct fssh_stat *stat);
249 	fssh_status_t (*write_attr_stat)(fssh_fs_volume *volume,
250 				fssh_fs_vnode *vnode, fssh_fs_cookie cookie,
251 				const struct fssh_stat *stat, int statMask);
252 	fssh_status_t (*rename_attr)(fssh_fs_volume *volume,
253 				fssh_fs_vnode *fromVnode, const char *fromName,
254 				fssh_fs_vnode *toVnode, const char *toName);
255 	fssh_status_t (*remove_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode,
256 				const char *name);
257 
258 	/* support for vnode and FS layers */
259 	fssh_status_t (*create_special_node)(fssh_fs_volume *volume,
260 				fssh_fs_vnode *dir, const char *name, fssh_fs_vnode *subVnode,
261 				fssh_mode_t mode, uint32_t flags, fssh_fs_vnode *_superVnode,
262 				fssh_ino_t *_nodeID);
263 	fssh_status_t (*get_super_vnode)(fssh_fs_volume *volume,
264 				fssh_fs_vnode *vnode, fssh_fs_volume *superVolume,
265 				fssh_fs_vnode *superVnode);
266 };
267 
268 typedef struct fssh_file_system_module_info {
269 	struct fssh_module_info	info;
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