xref: /haiku/headers/private/fs_shell/fssh_fs_interface.h (revision 1b8f7f13a3dc70e0e903cb94248220b40b732204)
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 mayBlock,
100 				bool reenter);
101 	fssh_status_t (*write_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode,
102 				fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs,
103 				fssh_size_t count, fssh_size_t *_numBytes, bool mayBlock,
104 				bool reenter);
105 
106 	/* cache file access */
107 	fssh_status_t (*get_file_map)(fssh_fs_volume fs, fssh_fs_vnode vnode,
108 				fssh_off_t offset, fssh_size_t size,
109 				struct fssh_file_io_vec *vecs, fssh_size_t *_count);
110 
111 	/* common operations */
112 	fssh_status_t (*ioctl)(fssh_fs_volume fs, fssh_fs_vnode vnode,
113 				fssh_fs_cookie cookie, fssh_ulong op, void *buffer,
114 				fssh_size_t length);
115 	fssh_status_t (*set_flags)(fssh_fs_volume fs, fssh_fs_vnode vnode,
116 				fssh_fs_cookie cookie, int flags);
117 	fssh_status_t (*select)(fssh_fs_volume fs, fssh_fs_vnode vnode,
118 				fssh_fs_cookie cookie, uint8_t event, uint32_t ref,
119 				fssh_selectsync *sync);
120 	fssh_status_t (*deselect)(fssh_fs_volume fs, fssh_fs_vnode vnode,
121 				fssh_fs_cookie cookie, uint8_t event, fssh_selectsync *sync);
122 	fssh_status_t (*fsync)(fssh_fs_volume fs, fssh_fs_vnode vnode);
123 
124 	fssh_status_t (*read_symlink)(fssh_fs_volume fs, fssh_fs_vnode link,
125 				char *buffer, fssh_size_t *_bufferSize);
126 	fssh_status_t (*create_symlink)(fssh_fs_volume fs, fssh_fs_vnode dir,
127 				const char *name, const char *path, int mode);
128 
129 	fssh_status_t (*link)(fssh_fs_volume fs, fssh_fs_vnode dir,
130 				const char *name, fssh_fs_vnode vnode);
131 	fssh_status_t (*unlink)(fssh_fs_volume fs, fssh_fs_vnode dir,
132 				const char *name);
133 	fssh_status_t (*rename)(fssh_fs_volume fs, fssh_fs_vnode fromDir,
134 				const char *fromName, fssh_fs_vnode toDir, const char *toName);
135 
136 	fssh_status_t (*access)(fssh_fs_volume fs, fssh_fs_vnode vnode, int mode);
137 	fssh_status_t (*read_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
138 				struct fssh_stat *stat);
139 	fssh_status_t (*write_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
140 				const struct fssh_stat *stat, uint32_t statMask);
141 
142 	/* file operations */
143 	fssh_status_t (*create)(fssh_fs_volume fs, fssh_fs_vnode dir,
144 				const char *name, int openMode, int perms,
145 				fssh_fs_cookie *_cookie, fssh_vnode_id *_newVnodeID);
146 	fssh_status_t (*open)(fssh_fs_volume fs, fssh_fs_vnode vnode, int openMode,
147 				fssh_fs_cookie *_cookie);
148 	fssh_status_t (*close)(fssh_fs_volume fs, fssh_fs_vnode vnode,
149 				fssh_fs_cookie cookie);
150 	fssh_status_t (*free_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode,
151 				fssh_fs_cookie cookie);
152 	fssh_status_t (*read)(fssh_fs_volume fs, fssh_fs_vnode vnode,
153 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
154 				fssh_size_t *length);
155 	fssh_status_t (*write)(fssh_fs_volume fs, fssh_fs_vnode vnode,
156 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
157 				fssh_size_t *length);
158 
159 	/* directory operations */
160 	fssh_status_t (*create_dir)(fssh_fs_volume fs, fssh_fs_vnode parent,
161 				const char *name, int perms, fssh_vnode_id *_newVnodeID);
162 	fssh_status_t (*remove_dir)(fssh_fs_volume fs, fssh_fs_vnode parent,
163 				const char *name);
164 	fssh_status_t (*open_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
165 				fssh_fs_cookie *_cookie);
166 	fssh_status_t (*close_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
167 				fssh_fs_cookie cookie);
168 	fssh_status_t (*free_dir_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode,
169 				fssh_fs_cookie cookie);
170 	fssh_status_t (*read_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
171 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
172 				fssh_size_t bufferSize, uint32_t *_num);
173 	fssh_status_t (*rewind_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
174 				fssh_fs_cookie cookie);
175 
176 	/* attribute directory operations */
177 	fssh_status_t (*open_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
178 				fssh_fs_cookie *_cookie);
179 	fssh_status_t (*close_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
180 				fssh_fs_cookie cookie);
181 	fssh_status_t (*free_attr_dir_cookie)(fssh_fs_volume fs,
182 				fssh_fs_vnode vnode, fssh_fs_cookie cookie);
183 	fssh_status_t (*read_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
184 				fssh_fs_cookie cookie, struct fssh_dirent *buffer,
185 				fssh_size_t bufferSize, uint32_t *_num);
186 	fssh_status_t (*rewind_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode,
187 				fssh_fs_cookie cookie);
188 
189 	/* attribute operations */
190 	fssh_status_t (*create_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
191 				const char *name, uint32_t type, int openMode,
192 				fssh_fs_cookie *_cookie);
193 	fssh_status_t (*open_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
194 				const char *name, int openMode, fssh_fs_cookie *_cookie);
195 	fssh_status_t (*close_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
196 				fssh_fs_cookie cookie);
197 	fssh_status_t (*free_attr_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode,
198 				fssh_fs_cookie cookie);
199 	fssh_status_t (*read_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
200 				fssh_fs_cookie cookie, fssh_off_t pos, void *buffer,
201 				fssh_size_t *length);
202 	fssh_status_t (*write_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
203 				fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer,
204 				fssh_size_t *length);
205 
206 	fssh_status_t (*read_attr_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
207 				fssh_fs_cookie cookie, struct fssh_stat *stat);
208 	fssh_status_t (*write_attr_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode,
209 				fssh_fs_cookie cookie, const struct fssh_stat *stat,
210 				int statMask);
211 	fssh_status_t (*rename_attr)(fssh_fs_volume fs, fssh_fs_vnode fromVnode,
212 				const char *fromName, fssh_fs_vnode toVnode,
213 				const char *toName);
214 	fssh_status_t (*remove_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode,
215 				const char *name);
216 
217 	/* index directory & index operations */
218 	fssh_status_t (*open_index_dir)(fssh_fs_volume fs, fssh_fs_cookie *cookie);
219 	fssh_status_t (*close_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie);
220 	fssh_status_t (*free_index_dir_cookie)(fssh_fs_volume fs,
221 				fssh_fs_cookie cookie);
222 	fssh_status_t (*read_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie,
223 				struct fssh_dirent *buffer, fssh_size_t bufferSize,
224 				uint32_t *_num);
225 	fssh_status_t (*rewind_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie);
226 
227 	fssh_status_t (*create_index)(fssh_fs_volume fs, const char *name,
228 				uint32_t type, uint32_t flags);
229 	fssh_status_t (*remove_index)(fssh_fs_volume fs, const char *name);
230 	fssh_status_t (*read_index_stat)(fssh_fs_volume fs, const char *name,
231 				struct fssh_stat *stat);
232 
233 	/* query operations */
234 	fssh_status_t (*open_query)(fssh_fs_volume fs, const char *query,
235 				uint32_t flags, fssh_port_id port, uint32_t token,
236 				fssh_fs_cookie *_cookie);
237 	fssh_status_t (*close_query)(fssh_fs_volume fs, fssh_fs_cookie cookie);
238 	fssh_status_t (*free_query_cookie)(fssh_fs_volume fs,
239 				fssh_fs_cookie cookie);
240 	fssh_status_t (*read_query)(fssh_fs_volume fs, fssh_fs_cookie cookie,
241 				struct fssh_dirent *buffer, fssh_size_t bufferSize,
242 				uint32_t *_num);
243 	fssh_status_t (*rewind_query)(fssh_fs_volume fs, fssh_fs_cookie cookie);
244 
245 	/* capability querying (the device is read locked) */
246 	uint32_t (*get_supported_operations)(fssh_partition_data* partition,
247 				uint32_t mask);
248 
249 	bool (*validate_resize)(fssh_partition_data *partition, fssh_off_t *size);
250 	bool (*validate_move)(fssh_partition_data *partition, fssh_off_t *start);
251 	bool (*validate_set_content_name)(fssh_partition_data *partition,
252 				char *name);
253 	bool (*validate_set_content_parameters)(fssh_partition_data *partition,
254 				const char *parameters);
255 	bool (*validate_initialize)(fssh_partition_data *partition, char *name,
256 				const char *parameters);
257 
258 	/* shadow partition modification (device is write locked) */
259 	fssh_status_t (*shadow_changed)(fssh_partition_data *partition,
260 				fssh_partition_data *child, uint32_t operation);
261 
262 	/* writing (the device is NOT locked) */
263 	fssh_status_t (*defragment)(int fd, fssh_partition_id partition,
264 				fssh_disk_job_id job);
265 	fssh_status_t (*repair)(int fd, fssh_partition_id partition, bool checkOnly,
266 				fssh_disk_job_id job);
267 	fssh_status_t (*resize)(int fd, fssh_partition_id partition,
268 				fssh_off_t size, fssh_disk_job_id job);
269 	fssh_status_t (*move)(int fd, fssh_partition_id partition,
270 				fssh_off_t offset, fssh_disk_job_id job);
271 	fssh_status_t (*set_content_name)(int fd, fssh_partition_id partition,
272 				const char *name, fssh_disk_job_id job);
273 	fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition,
274 				const char *parameters, fssh_disk_job_id job);
275 	fssh_status_t (*initialize)(int fd, fssh_partition_id partition,
276 				const char *name, const char *parameters,
277 				fssh_off_t partitionSize, fssh_disk_job_id job);
278 } fssh_file_system_module_info;
279 
280 
281 /* file system add-ons only prototypes */
282 extern fssh_status_t fssh_new_vnode(fssh_mount_id mountID,
283 				fssh_vnode_id vnodeID, fssh_fs_vnode privateNode);
284 extern fssh_status_t fssh_publish_vnode(fssh_mount_id mountID,
285 				fssh_vnode_id vnodeID, fssh_fs_vnode privateNode);
286 extern fssh_status_t fssh_get_vnode(fssh_mount_id mountID,
287 				fssh_vnode_id vnodeID, fssh_fs_vnode *_privateNode);
288 extern fssh_status_t fssh_put_vnode(fssh_mount_id mountID,
289 				fssh_vnode_id vnodeID);
290 extern fssh_status_t fssh_remove_vnode(fssh_mount_id mountID,
291 				fssh_vnode_id vnodeID);
292 extern fssh_status_t fssh_unremove_vnode(fssh_mount_id mountID,
293 				fssh_vnode_id vnodeID);
294 extern fssh_status_t fssh_get_vnode_removed(fssh_mount_id mountID,
295 				fssh_vnode_id vnodeID, bool* removed);
296 
297 extern fssh_status_t fssh_notify_entry_created(fssh_mount_id device,
298 				fssh_vnode_id directory, const char *name, fssh_vnode_id node);
299 extern fssh_status_t fssh_notify_entry_removed(fssh_mount_id device,
300 				fssh_vnode_id directory, const char *name, fssh_vnode_id node);
301 extern fssh_status_t fssh_notify_entry_moved(fssh_mount_id device,
302 				fssh_vnode_id fromDirectory, const char *fromName,
303 				fssh_vnode_id toDirectory, const char *toName,
304 				fssh_vnode_id node);
305 extern fssh_status_t fssh_notify_stat_changed(fssh_mount_id device,
306 				fssh_vnode_id node, uint32_t statFields);
307 extern fssh_status_t fssh_notify_attribute_changed(fssh_mount_id device,
308 				fssh_vnode_id node, const char *attribute, int32_t cause);
309 
310 extern fssh_status_t fssh_notify_query_entry_created(fssh_port_id port,
311 				int32_t token, fssh_mount_id device,
312 				fssh_vnode_id directory, const char *name,
313 				fssh_vnode_id node);
314 extern fssh_status_t fssh_notify_query_entry_removed(fssh_port_id port,
315 				int32_t token, fssh_mount_id device,
316 				fssh_vnode_id directory, const char *name,
317 				fssh_vnode_id node);
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 
323 #endif	/* _FSSH_FS_INTERFACE_H */
324