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