xref: /haiku/headers/private/fs_shell/fssh_fs_interface.h (revision 93a78ecaa45114d68952d08c4778f073515102f2)
1 /* File System Interface Layer Definition
2  *
3  * Copyright 2004-2006, Haiku Inc. All Rights Reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _FSSH_FS_INTERFACE_H
7 #define _FSSH_FS_INTERFACE_H
8 
9 
10 #include "fssh_disk_device_defs.h"
11 #include "fssh_module.h"
12 #include "fssh_os.h"
13 
14 
15 struct fssh_dirent;
16 struct fssh_fs_info;
17 struct fssh_iovec;
18 struct fssh_partition_data;
19 struct fssh_selectsync;
20 struct fssh_stat;
21 
22 typedef fssh_dev_t fssh_mount_id;
23 typedef fssh_ino_t fssh_vnode_id;
24 
25 /* the file system's private data structures */
26 typedef void *fssh_fs_volume;
27 typedef void *fssh_fs_cookie;
28 typedef void *fssh_fs_vnode;
29 
30 /* passed to write_stat() */
31 enum fssh_write_stat_mask {
32 	FSSH_FS_WRITE_STAT_MODE		= 0x0001,
33 	FSSH_FS_WRITE_STAT_UID		= 0x0002,
34 	FSSH_FS_WRITE_STAT_GID		= 0x0004,
35 	FSSH_FS_WRITE_STAT_SIZE		= 0x0008,
36 	FSSH_FS_WRITE_STAT_ATIME	= 0x0010,
37 	FSSH_FS_WRITE_STAT_MTIME	= 0x0020,
38 	FSSH_FS_WRITE_STAT_CRTIME	= 0x0040
39 };
40 
41 /* passed to write_fs_info() */
42 #define	FSSH_FS_WRITE_FSINFO_NAME	0x0001
43 
44 struct fssh_file_io_vec {
45 	fssh_off_t	offset;
46 	fssh_off_t	length;
47 };
48 
49 #define	FSSH_B_CURRENT_FS_API_VERSION "/v1"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 typedef struct fssh_file_system_module_info {
56 	struct fssh_module_info	info;
57 	const char				*pretty_name;
58 
59 	/* scanning (the device is write locked) */
60 	float (*identify_partition)(int fd, fssh_partition_data *partition,
61 				void **cookie);
62 	fssh_status_t (*scan_partition)(int fd, fssh_partition_data *partition,
63 				void *cookie);
64 	void (*free_identify_partition_cookie)(fssh_partition_data *partition,
65 				void *cookie);
66 	void (*free_partition_content_cookie)(fssh_partition_data *partition);
67 
68 	/* general operations */
69 	fssh_status_t (*mount)(fssh_mount_id id, const char *device, uint32_t flags,
70 				const char *args, fssh_fs_volume *_fs,
71 				fssh_vnode_id *_rootVnodeID);
72 	fssh_status_t (*unmount)(fssh_fs_volume fs);
73 
74 	fssh_status_t (*read_fs_info)(fssh_fs_volume fs, struct fssh_fs_info *info);
75 	fssh_status_t (*write_fs_info)(fssh_fs_volume fs,
76 				const struct fssh_fs_info *info, uint32_t mask);
77 	fssh_status_t (*sync)(fssh_fs_volume fs);
78 
79 	/* vnode operations */
80 	fssh_status_t (*lookup)(fssh_fs_volume fs, fssh_fs_vnode dir,
81 				const char *name, fssh_vnode_id *_id, int *_type);
82 	fssh_status_t (*get_vnode_name)(fssh_fs_volume fs, fssh_fs_vnode vnode,
83 				char *buffer, fssh_size_t bufferSize);
84 
85 	fssh_status_t (*get_vnode)(fssh_fs_volume fs, fssh_vnode_id id,
86 				fssh_fs_vnode *_vnode, bool reenter);
87 	fssh_status_t (*put_vnode)(fssh_fs_volume fs, fssh_fs_vnode vnode,
88 				bool reenter);
89 	fssh_status_t (*remove_vnode)(fssh_fs_volume fs, fssh_fs_vnode vnode,
90 				bool reenter);
91 
92 	/* VM file access */
93 	bool (*can_page)(fssh_fs_volume fs, fssh_fs_vnode vnode,
94 				fssh_fs_cookie cookie);
95 	fssh_status_t (*read_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode,
96 				fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs,
97 				fssh_size_t count, fssh_size_t *_numBytes, bool reenter);
98 	fssh_status_t (*write_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode,
99 				fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs,
100 				fssh_size_t count, fssh_size_t *_numBytes, bool reenter);
101 
102 	/* cache file access */
103 	fssh_status_t (*get_file_map)(fssh_fs_volume fs, fssh_fs_vnode vnode,
104 				fssh_off_t offset, fssh_size_t size,
105 				struct fssh_file_io_vec *vecs, fssh_size_t *_count);
106 
107 	/* common operations */
108 	fssh_status_t (*ioctl)(fssh_fs_volume fs, fssh_fs_vnode vnode,
109 				fssh_fs_cookie cookie, fssh_ulong op, void *buffer,
110 				fssh_size_t length);
111 	fssh_status_t (*set_flags)(fssh_fs_volume fs, fssh_fs_vnode vnode,
112 				fssh_fs_cookie cookie, int flags);
113 	fssh_status_t (*select)(fssh_fs_volume fs, fssh_fs_vnode vnode,
114 				fssh_fs_cookie cookie, uint8_t event, uint32_t ref,
115 				fssh_selectsync *sync);
116 	fssh_status_t (*deselect)(fssh_fs_volume fs, fssh_fs_vnode vnode,
117 				fssh_fs_cookie cookie, uint8_t event, fssh_selectsync *sync);
118 	fssh_status_t (*fsync)(fssh_fs_volume fs, fssh_fs_vnode vnode);
119 
120 	fssh_status_t (*read_symlink)(fssh_fs_volume fs, fssh_fs_vnode link,
121 				char *buffer, fssh_size_t *_bufferSize);
122 	fssh_status_t (*create_symlink)(fssh_fs_volume fs, fssh_fs_vnode dir,
123 				const char *name, const char *path, int mode);
124 
125 	fssh_status_t (*link)(fssh_fs_volume fs, fssh_fs_vnode dir,
126 				const char *name, fssh_fs_vnode vnode);
127 	fssh_status_t (*unlink)(fssh_fs_volume fs, fssh_fs_vnode dir,
128 				const char *name);
129 	fssh_status_t (*rename)(fssh_fs_volume fs, fssh_fs_vnode fromDir,
130 				const char *fromName, fssh_fs_vnode toDir, const char *toName);
131 
132 	fssh_status_t (*access)(fssh_fs_volume fs, fssh_fs_vnode vnode, int mode);
133 	fssh_status_t (*read_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
134 				struct fssh_stat *stat);
135 	fssh_status_t (*write_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
136 				const struct fssh_stat *stat, uint32_t statMask);
137 
138 	/* file operations */
139 	fssh_status_t (*create)(fssh_fs_volume fs, fssh_fs_vnode dir,
140 				const char *name, int openMode, int perms,
141 				fssh_fs_cookie *_cookie, fssh_vnode_id *_newVnodeID);
142 	fssh_status_t (*open)(fssh_fs_volume fs, fssh_fs_vnode vnode, int openMode,
143 				fssh_fs_cookie *_cookie);
144 	fssh_status_t (*close)(fssh_fs_volume fs, fssh_fs_vnode vnode,
145 				fssh_fs_cookie cookie);
146 	fssh_status_t (*free_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode,
147 				fssh_fs_cookie cookie);
148 	fssh_status_t (*read)(fssh_fs_volume fs, fssh_fs_vnode vnode,
149 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
150 				fssh_size_t *length);
151 	fssh_status_t (*write)(fssh_fs_volume fs, fssh_fs_vnode vnode,
152 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
153 				fssh_size_t *length);
154 
155 	/* directory operations */
156 	fssh_status_t (*create_dir)(fssh_fs_volume fs, fssh_fs_vnode parent,
157 				const char *name, int perms, fssh_vnode_id *_newVnodeID);
158 	fssh_status_t (*remove_dir)(fssh_fs_volume fs, fssh_fs_vnode parent,
159 				const char *name);
160 	fssh_status_t (*open_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
161 				fssh_fs_cookie *_cookie);
162 	fssh_status_t (*close_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
163 				fssh_fs_cookie cookie);
164 	fssh_status_t (*free_dir_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode,
165 				fssh_fs_cookie cookie);
166 	fssh_status_t (*read_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
167 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
168 				fssh_size_t bufferSize, uint32_t *_num);
169 	fssh_status_t (*rewind_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
170 				fssh_fs_cookie cookie);
171 
172 	/* attribute directory operations */
173 	fssh_status_t (*open_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
174 				fssh_fs_cookie *_cookie);
175 	fssh_status_t (*close_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
176 				fssh_fs_cookie cookie);
177 	fssh_status_t (*free_attr_dir_cookie)(fssh_fs_volume fs,
178 				fssh_fs_vnode vnode, fssh_fs_cookie cookie);
179 	fssh_status_t (*read_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
180 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
181 				fssh_size_t bufferSize, uint32_t *_num);
182 	fssh_status_t (*rewind_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
183 				fssh_fs_cookie cookie);
184 
185 	/* attribute operations */
186 	fssh_status_t (*create_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
187 				const char *name, uint32_t type, int openMode,
188 				fssh_fs_cookie *_cookie);
189 	fssh_status_t (*open_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
190 				const char *name, int openMode, fssh_fs_cookie *_cookie);
191 	fssh_status_t (*close_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
192 				fssh_fs_cookie cookie);
193 	fssh_status_t (*free_attr_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode,
194 				fssh_fs_cookie cookie);
195 	fssh_status_t (*read_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
196 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
197 				fssh_size_t *length);
198 	fssh_status_t (*write_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
199 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
200 				fssh_size_t *length);
201 
202 	fssh_status_t (*read_attr_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
203 				fssh_fs_cookie cookie, struct fssh_stat *stat);
204 	fssh_status_t (*write_attr_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
205 				fssh_fs_cookie cookie, const struct fssh_stat *stat,
206 				int statMask);
207 	fssh_status_t (*rename_attr)(fssh_fs_volume fs, fssh_fs_vnode fromVnode,
208 				const char *fromName, fssh_fs_vnode toVnode,
209 				const char *toName);
210 	fssh_status_t (*remove_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
211 				const char *name);
212 
213 	/* index directory & index operations */
214 	fssh_status_t (*open_index_dir)(fssh_fs_volume fs, fssh_fs_cookie *cookie);
215 	fssh_status_t (*close_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie);
216 	fssh_status_t (*free_index_dir_cookie)(fssh_fs_volume fs,
217 				fssh_fs_cookie cookie);
218 	fssh_status_t (*read_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie,
219 				struct fssh_dirent *buffer, fssh_size_t bufferSize,
220 				uint32_t *_num);
221 	fssh_status_t (*rewind_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie);
222 
223 	fssh_status_t (*create_index)(fssh_fs_volume fs, const char *name,
224 				uint32_t type, uint32_t flags);
225 	fssh_status_t (*remove_index)(fssh_fs_volume fs, const char *name);
226 	fssh_status_t (*read_index_stat)(fssh_fs_volume fs, const char *name,
227 				struct fssh_stat *stat);
228 
229 	/* query operations */
230 	fssh_status_t (*open_query)(fssh_fs_volume fs, const char *query,
231 				uint32_t flags, fssh_port_id port, uint32_t token,
232 				fssh_fs_cookie *_cookie);
233 	fssh_status_t (*close_query)(fssh_fs_volume fs, fssh_fs_cookie cookie);
234 	fssh_status_t (*free_query_cookie)(fssh_fs_volume fs,
235 				fssh_fs_cookie cookie);
236 	fssh_status_t (*read_query)(fssh_fs_volume fs, fssh_fs_cookie cookie,
237 				struct fssh_dirent *buffer, fssh_size_t bufferSize,
238 				uint32_t *_num);
239 	fssh_status_t (*rewind_query)(fssh_fs_volume fs, fssh_fs_cookie cookie);
240 
241 	/* capability querying (the device is read locked) */
242 	// ToDo: this will probably be combined to a single call
243 	bool (*supports_defragmenting)(fssh_partition_data *partition,
244 				bool *whileMounted);
245 	bool (*supports_repairing)(fssh_partition_data *partition,
246 				bool checkOnly, bool *whileMounted);
247 	bool (*supports_resizing)(fssh_partition_data *partition,
248 				bool *whileMounted);
249 	bool (*supports_moving)(fssh_partition_data *partition, bool *isNoOp);
250 	bool (*supports_setting_content_name)(fssh_partition_data *partition,
251 				bool *whileMounted);
252 	bool (*supports_setting_content_parameters)(fssh_partition_data *partition,
253 				bool *whileMounted);
254 	bool (*supports_initializing)(fssh_partition_data *partition);
255 
256 	bool (*validate_resize)(fssh_partition_data *partition, fssh_off_t *size);
257 	bool (*validate_move)(fssh_partition_data *partition, fssh_off_t *start);
258 	bool (*validate_set_content_name)(fssh_partition_data *partition,
259 				char *name);
260 	bool (*validate_set_content_parameters)(fssh_partition_data *partition,
261 				const char *parameters);
262 	bool (*validate_initialize)(fssh_partition_data *partition, char *name,
263 				const char *parameters);
264 
265 	/* shadow partition modification (device is write locked) */
266 	fssh_status_t (*shadow_changed)(fssh_partition_data *partition,
267 				uint32_t operation);
268 
269 	/* writing (the device is NOT locked) */
270 	fssh_status_t (*defragment)(int fd, fssh_partition_id partition,
271 				fssh_disk_job_id job);
272 	fssh_status_t (*repair)(int fd, fssh_partition_id partition, bool checkOnly,
273 				fssh_disk_job_id job);
274 	fssh_status_t (*resize)(int fd, fssh_partition_id partition,
275 				fssh_off_t size, fssh_disk_job_id job);
276 	fssh_status_t (*move)(int fd, fssh_partition_id partition,
277 				fssh_off_t offset, fssh_disk_job_id job);
278 	fssh_status_t (*set_content_name)(int fd, fssh_partition_id partition,
279 				const char *name, fssh_disk_job_id job);
280 	fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition,
281 				const char *parameters, fssh_disk_job_id job);
282 	fssh_status_t (*initialize)(const char *partition, const char *name,
283 				const char *parameters, fssh_disk_job_id job);
284 		// This is pretty close to how the hook in R5 looked. Save the job ID,
285 		// of course and that the parameters were given as (void*, size_t) pair.
286 } fssh_file_system_module_info;
287 
288 
289 /* file system add-ons only prototypes */
290 extern fssh_status_t fssh_new_vnode(fssh_mount_id mountID,
291 				fssh_vnode_id vnodeID, fssh_fs_vnode privateNode);
292 extern fssh_status_t fssh_publish_vnode(fssh_mount_id mountID,
293 				fssh_vnode_id vnodeID, fssh_fs_vnode privateNode);
294 extern fssh_status_t fssh_get_vnode(fssh_mount_id mountID,
295 				fssh_vnode_id vnodeID, fssh_fs_vnode *_privateNode);
296 extern fssh_status_t fssh_put_vnode(fssh_mount_id mountID,
297 				fssh_vnode_id vnodeID);
298 extern fssh_status_t fssh_remove_vnode(fssh_mount_id mountID,
299 				fssh_vnode_id vnodeID);
300 extern fssh_status_t fssh_unremove_vnode(fssh_mount_id mountID,
301 				fssh_vnode_id vnodeID);
302 extern fssh_status_t fssh_get_vnode_removed(fssh_mount_id mountID,
303 				fssh_vnode_id vnodeID, bool* removed);
304 
305 extern fssh_status_t fssh_notify_entry_created(fssh_mount_id device,
306 				fssh_vnode_id directory, const char *name, fssh_vnode_id node);
307 extern fssh_status_t fssh_notify_entry_removed(fssh_mount_id device,
308 				fssh_vnode_id directory, const char *name, fssh_vnode_id node);
309 extern fssh_status_t fssh_notify_entry_moved(fssh_mount_id device,
310 				fssh_vnode_id fromDirectory, const char *fromName,
311 				fssh_vnode_id toDirectory, const char *toName,
312 				fssh_vnode_id node);
313 extern fssh_status_t fssh_notify_stat_changed(fssh_mount_id device,
314 				fssh_vnode_id node, uint32_t statFields);
315 extern fssh_status_t fssh_notify_attribute_changed(fssh_mount_id device,
316 				fssh_vnode_id node, const char *attribute, int32_t cause);
317 
318 extern fssh_status_t fssh_notify_query_entry_created(fssh_port_id port,
319 				int32_t token, fssh_mount_id device,
320 				fssh_vnode_id directory, const char *name,
321 				fssh_vnode_id node);
322 extern fssh_status_t fssh_notify_query_entry_removed(fssh_port_id port,
323 				int32_t token, fssh_mount_id device,
324 				fssh_vnode_id directory, const char *name,
325 				fssh_vnode_id node);
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 
331 #endif	/* _FSSH_FS_INTERFACE_H */
332