2 * Copyright 2004-2016, Haiku Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _FSSH_FS_INTERFACE_H
6 #define _FSSH_FS_INTERFACE_H
8 /*! File System Interface Layer Definition */
11 #include "fssh_disk_device_defs.h"
12 #include "fssh_module.h"
19 struct fssh_partition_data
;
20 struct fssh_selectsync
;
23 typedef fssh_dev_t fssh_mount_id
;
24 typedef fssh_ino_t fssh_vnode_id
;
26 /* the file system's private data structures */
27 typedef void *fssh_fs_cookie
;
29 typedef struct FSSHIORequest fssh_io_request
;
31 /* additional flags passed to write_stat() */
32 #define FSSH_B_STAT_SIZE_INSECURE 0x2000
34 /* passed to write_fs_info() */
35 #define FSSH_FS_WRITE_FSINFO_NAME 0x0001
37 struct fssh_file_io_vec
{
42 #define FSSH_B_CURRENT_FS_API_VERSION "/v1"
44 // flags for publish_vnode() and fs_volume_ops::get_vnode()
45 #define FSSH_B_VNODE_PUBLISH_REMOVED 0x01
46 #define FSSH_B_VNODE_DONT_CREATE_SPECIAL_SUB_NODE 0x02
53 typedef struct fssh_fs_volume fssh_fs_volume
;
54 typedef struct fssh_fs_volume_ops fssh_fs_volume_ops
;
55 typedef struct fssh_fs_vnode fssh_fs_vnode
;
56 typedef struct fssh_fs_vnode_ops fssh_fs_vnode_ops
;
59 struct fssh_fs_volume
{
63 fssh_fs_volume_ops
* ops
;
64 fssh_fs_volume
* sub_volume
;
65 fssh_fs_volume
* super_volume
;
68 struct fssh_fs_vnode
{
70 fssh_fs_vnode_ops
* ops
;
73 struct fssh_fs_volume_ops
{
74 fssh_status_t (*unmount
)(fssh_fs_volume
*volume
);
76 fssh_status_t (*read_fs_info
)(fssh_fs_volume
*volume
,
77 struct fssh_fs_info
*info
);
78 fssh_status_t (*write_fs_info
)(fssh_fs_volume
*volume
,
79 const struct fssh_fs_info
*info
, uint32_t mask
);
80 fssh_status_t (*sync
)(fssh_fs_volume
*volume
);
82 fssh_status_t (*get_vnode
)(fssh_fs_volume
*volume
, fssh_vnode_id id
,
83 fssh_fs_vnode
*_vnode
, int *_type
, uint32_t *_flags
,
86 /* index directory & index operations */
87 fssh_status_t (*open_index_dir
)(fssh_fs_volume
*volume
,
88 fssh_fs_cookie
*cookie
);
89 fssh_status_t (*close_index_dir
)(fssh_fs_volume
*volume
,
90 fssh_fs_cookie cookie
);
91 fssh_status_t (*free_index_dir_cookie
)(fssh_fs_volume
*volume
,
92 fssh_fs_cookie cookie
);
93 fssh_status_t (*read_index_dir
)(fssh_fs_volume
*volume
,
94 fssh_fs_cookie cookie
, struct fssh_dirent
*buffer
,
95 fssh_size_t bufferSize
, uint32_t *_num
);
96 fssh_status_t (*rewind_index_dir
)(fssh_fs_volume
*volume
,
97 fssh_fs_cookie cookie
);
99 fssh_status_t (*create_index
)(fssh_fs_volume
*volume
, const char *name
,
100 uint32_t type
, uint32_t flags
);
101 fssh_status_t (*remove_index
)(fssh_fs_volume
*volume
, const char *name
);
102 fssh_status_t (*read_index_stat
)(fssh_fs_volume
*volume
, const char *name
,
103 struct fssh_stat
*stat
);
105 /* query operations */
106 fssh_status_t (*open_query
)(fssh_fs_volume
*volume
, const char *query
,
107 uint32_t flags
, fssh_port_id port
, uint32_t token
,
108 fssh_fs_cookie
*_cookie
);
109 fssh_status_t (*close_query
)(fssh_fs_volume
*volume
, fssh_fs_cookie cookie
);
110 fssh_status_t (*free_query_cookie
)(fssh_fs_volume
*volume
,
111 fssh_fs_cookie cookie
);
112 fssh_status_t (*read_query
)(fssh_fs_volume
*volume
, fssh_fs_cookie cookie
,
113 struct fssh_dirent
*buffer
, fssh_size_t bufferSize
,
115 fssh_status_t (*rewind_query
)(fssh_fs_volume
*volume
,
116 fssh_fs_cookie cookie
);
118 /* support for FS layers */
119 fssh_status_t (*create_sub_vnode
)(fssh_fs_volume
*volume
, fssh_ino_t id
,
120 fssh_fs_vnode
*vnode
);
121 fssh_status_t (*delete_sub_vnode
)(fssh_fs_volume
*volume
,
122 fssh_fs_vnode
*vnode
);
125 struct fssh_fs_vnode_ops
{
126 /* vnode operations */
127 fssh_status_t (*lookup
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*dir
,
128 const char *name
, fssh_vnode_id
*_id
);
129 fssh_status_t (*get_vnode_name
)(fssh_fs_volume
*volume
,
130 fssh_fs_vnode
*vnode
, char *buffer
, fssh_size_t bufferSize
);
132 fssh_status_t (*put_vnode
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
134 fssh_status_t (*remove_vnode
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
138 bool (*can_page
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
139 fssh_fs_cookie cookie
);
140 fssh_status_t (*read_pages
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
141 fssh_fs_cookie cookie
, fssh_off_t pos
, const fssh_iovec
*vecs
,
142 fssh_size_t count
, fssh_size_t
*_numBytes
);
143 fssh_status_t (*write_pages
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
144 fssh_fs_cookie cookie
, fssh_off_t pos
, const fssh_iovec
*vecs
,
145 fssh_size_t count
, fssh_size_t
*_numBytes
);
147 /* asynchronous I/O */
148 fssh_status_t (*io
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
149 void *cookie
, fssh_io_request
*request
);
150 fssh_status_t (*cancel_io
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
151 void *cookie
, fssh_io_request
*request
);
153 /* cache file access */
154 fssh_status_t (*get_file_map
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
155 fssh_off_t offset
, fssh_size_t size
,
156 struct fssh_file_io_vec
*vecs
, fssh_size_t
*_count
);
158 /* common operations */
159 fssh_status_t (*ioctl
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
160 fssh_fs_cookie cookie
, uint32_t op
, void *buffer
,
162 fssh_status_t (*set_flags
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
163 fssh_fs_cookie cookie
, int flags
);
164 fssh_status_t (*select
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
165 fssh_fs_cookie cookie
, uint8_t event
, fssh_selectsync
*sync
);
166 fssh_status_t (*deselect
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
167 fssh_fs_cookie cookie
, uint8_t event
, fssh_selectsync
*sync
);
168 fssh_status_t (*fsync
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
);
170 fssh_status_t (*read_symlink
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*link
,
171 char *buffer
, fssh_size_t
*_bufferSize
);
172 fssh_status_t (*create_symlink
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*dir
,
173 const char *name
, const char *path
, int mode
);
175 fssh_status_t (*link
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*dir
,
176 const char *name
, fssh_fs_vnode
*vnode
);
177 fssh_status_t (*unlink
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*dir
,
179 fssh_status_t (*rename
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*fromDir
,
180 const char *fromName
, fssh_fs_vnode
*toDir
, const char *toName
);
182 fssh_status_t (*access
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
184 fssh_status_t (*read_stat
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
185 struct fssh_stat
*stat
);
186 fssh_status_t (*write_stat
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
187 const struct fssh_stat
*stat
, uint32_t statMask
);
188 fssh_status_t (*preallocate
)(fssh_fs_volume
* volume
, fssh_fs_vnode
* vnode
,
189 fssh_off_t pos
, fssh_off_t length
);
191 /* file operations */
192 fssh_status_t (*create
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*dir
,
193 const char *name
, int openMode
, int perms
,
194 fssh_fs_cookie
*_cookie
, fssh_vnode_id
*_newVnodeID
);
195 fssh_status_t (*open
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
196 int openMode
, fssh_fs_cookie
*_cookie
);
197 fssh_status_t (*close
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
198 fssh_fs_cookie cookie
);
199 fssh_status_t (*free_cookie
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
200 fssh_fs_cookie cookie
);
201 fssh_status_t (*read
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
202 fssh_fs_cookie cookie
, fssh_off_t pos
, void *buffer
,
203 fssh_size_t
*length
);
204 fssh_status_t (*write
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
205 fssh_fs_cookie cookie
, fssh_off_t pos
, const void *buffer
,
206 fssh_size_t
*length
);
208 /* directory operations */
209 fssh_status_t (*create_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*parent
,
210 const char *name
, int perms
);
211 fssh_status_t (*remove_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*parent
,
213 fssh_status_t (*open_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
214 fssh_fs_cookie
*_cookie
);
215 fssh_status_t (*close_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
216 fssh_fs_cookie cookie
);
217 fssh_status_t (*free_dir_cookie
)(fssh_fs_volume
*volume
,
218 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
);
219 fssh_status_t (*read_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
220 fssh_fs_cookie cookie
, struct fssh_dirent
*buffer
,
221 fssh_size_t bufferSize
, uint32_t *_num
);
222 fssh_status_t (*rewind_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
223 fssh_fs_cookie cookie
);
225 /* attribute directory operations */
226 fssh_status_t (*open_attr_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
227 fssh_fs_cookie
*_cookie
);
228 fssh_status_t (*close_attr_dir
)(fssh_fs_volume
*volume
,
229 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
);
230 fssh_status_t (*free_attr_dir_cookie
)(fssh_fs_volume
*volume
,
231 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
);
232 fssh_status_t (*read_attr_dir
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
233 fssh_fs_cookie cookie
, struct fssh_dirent
*buffer
,
234 fssh_size_t bufferSize
, uint32_t *_num
);
235 fssh_status_t (*rewind_attr_dir
)(fssh_fs_volume
*volume
,
236 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
);
238 /* attribute operations */
239 fssh_status_t (*create_attr
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
240 const char *name
, uint32_t type
, int openMode
,
241 fssh_fs_cookie
*_cookie
);
242 fssh_status_t (*open_attr
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
243 const char *name
, int openMode
, fssh_fs_cookie
*_cookie
);
244 fssh_status_t (*close_attr
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
245 fssh_fs_cookie cookie
);
246 fssh_status_t (*free_attr_cookie
)(fssh_fs_volume
*volume
,
247 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
);
248 fssh_status_t (*read_attr
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
249 fssh_fs_cookie cookie
, fssh_off_t pos
, void *buffer
,
250 fssh_size_t
*length
);
251 fssh_status_t (*write_attr
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
252 fssh_fs_cookie cookie
, fssh_off_t pos
, const void *buffer
,
253 fssh_size_t
*length
);
255 fssh_status_t (*read_attr_stat
)(fssh_fs_volume
*volume
,
256 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
,
257 struct fssh_stat
*stat
);
258 fssh_status_t (*write_attr_stat
)(fssh_fs_volume
*volume
,
259 fssh_fs_vnode
*vnode
, fssh_fs_cookie cookie
,
260 const struct fssh_stat
*stat
, int statMask
);
261 fssh_status_t (*rename_attr
)(fssh_fs_volume
*volume
,
262 fssh_fs_vnode
*fromVnode
, const char *fromName
,
263 fssh_fs_vnode
*toVnode
, const char *toName
);
264 fssh_status_t (*remove_attr
)(fssh_fs_volume
*volume
, fssh_fs_vnode
*vnode
,
267 /* support for vnode and FS layers */
268 fssh_status_t (*create_special_node
)(fssh_fs_volume
*volume
,
269 fssh_fs_vnode
*dir
, const char *name
, fssh_fs_vnode
*subVnode
,
270 fssh_mode_t mode
, uint32_t flags
, fssh_fs_vnode
*_superVnode
,
271 fssh_ino_t
*_nodeID
);
272 fssh_status_t (*get_super_vnode
)(fssh_fs_volume
*volume
,
273 fssh_fs_vnode
*vnode
, fssh_fs_volume
*superVolume
,
274 fssh_fs_vnode
*superVnode
);
277 typedef struct fssh_file_system_module_info
{
278 struct fssh_module_info info
;
279 const char* short_name
;
280 const char* pretty_name
;
281 uint32_t flags
; // DDM flags
283 /* scanning (the device is write locked) */
284 float (*identify_partition
)(int fd
, fssh_partition_data
*partition
,
286 fssh_status_t (*scan_partition
)(int fd
, fssh_partition_data
*partition
,
288 void (*free_identify_partition_cookie
)(fssh_partition_data
*partition
,
290 void (*free_partition_content_cookie
)(fssh_partition_data
*partition
);
292 /* general operations */
293 fssh_status_t (*mount
)(fssh_fs_volume
*volume
, const char *device
,
294 uint32_t flags
, const char *args
, fssh_vnode_id
*_rootVnodeID
);
296 /* capability querying (the device is read locked) */
297 uint32_t (*get_supported_operations
)(fssh_partition_data
* partition
,
300 bool (*validate_resize
)(fssh_partition_data
*partition
, fssh_off_t
*size
);
301 bool (*validate_move
)(fssh_partition_data
*partition
, fssh_off_t
*start
);
302 bool (*validate_set_content_name
)(fssh_partition_data
*partition
,
304 bool (*validate_set_content_parameters
)(fssh_partition_data
*partition
,
305 const char *parameters
);
306 bool (*validate_initialize
)(fssh_partition_data
*partition
, char *name
,
307 const char *parameters
);
309 /* shadow partition modification (device is write locked) */
310 fssh_status_t (*shadow_changed
)(fssh_partition_data
*partition
,
311 fssh_partition_data
*child
, uint32_t operation
);
313 /* writing (the device is NOT locked) */
314 fssh_status_t (*defragment
)(int fd
, fssh_partition_id partition
,
315 fssh_disk_job_id job
);
316 fssh_status_t (*repair
)(int fd
, fssh_partition_id partition
, bool checkOnly
,
317 fssh_disk_job_id job
);
318 fssh_status_t (*resize
)(int fd
, fssh_partition_id partition
,
319 fssh_off_t size
, fssh_disk_job_id job
);
320 fssh_status_t (*move
)(int fd
, fssh_partition_id partition
,
321 fssh_off_t offset
, fssh_disk_job_id job
);
322 fssh_status_t (*set_content_name
)(int fd
, fssh_partition_id partition
,
323 const char *name
, fssh_disk_job_id job
);
324 fssh_status_t (*set_content_parameters
)(int fd
, fssh_partition_id partition
,
325 const char *parameters
, fssh_disk_job_id job
);
326 fssh_status_t (*initialize
)(int fd
, fssh_partition_id partition
,
327 const char *name
, const char *parameters
,
328 fssh_off_t partitionSize
, fssh_disk_job_id job
);
329 fssh_status_t (*uninitialize
)(int fd
, fssh_partition_id partition
,
330 fssh_off_t partitionSize
, uint32_t blockSize
,
331 fssh_disk_job_id job
);
332 } fssh_file_system_module_info
;
335 /* file system add-ons only prototypes */
337 // callbacks for do_iterative_fd_io()
338 typedef fssh_status_t (*fssh_iterative_io_get_vecs
)(void *cookie
,
339 fssh_io_request
* request
, fssh_off_t offset
, fssh_size_t size
,
340 struct fssh_file_io_vec
*vecs
, fssh_size_t
*_count
);
341 typedef fssh_status_t (*fssh_iterative_io_finished
)(void* cookie
,
342 fssh_io_request
* request
, fssh_status_t status
,
343 bool partialTransfer
, fssh_size_t bytesTransferred
);
345 extern fssh_status_t
fssh_new_vnode(fssh_fs_volume
*volume
,
346 fssh_vnode_id vnodeID
, void *privateNode
,
347 fssh_fs_vnode_ops
*ops
);
348 extern fssh_status_t
fssh_publish_vnode(fssh_fs_volume
*volume
,
349 fssh_vnode_id vnodeID
, void *privateNode
,
350 fssh_fs_vnode_ops
*ops
, int type
, uint32_t flags
);
351 extern fssh_status_t
fssh_get_vnode(fssh_fs_volume
*volume
,
352 fssh_vnode_id vnodeID
, void **_privateNode
);
353 extern fssh_status_t
fssh_put_vnode(fssh_fs_volume
*volume
,
354 fssh_vnode_id vnodeID
);
355 extern fssh_status_t
fssh_acquire_vnode(fssh_fs_volume
*volume
,
356 fssh_vnode_id vnodeID
);
357 extern fssh_status_t
fssh_remove_vnode(fssh_fs_volume
*volume
,
358 fssh_vnode_id vnodeID
);
359 extern fssh_status_t
fssh_unremove_vnode(fssh_fs_volume
*volume
,
360 fssh_vnode_id vnodeID
);
361 extern fssh_status_t
fssh_get_vnode_removed(fssh_fs_volume
*volume
,
362 fssh_vnode_id vnodeID
, bool* removed
);
363 extern fssh_fs_volume
* fssh_volume_for_vnode(fssh_fs_vnode
*vnode
);
364 extern fssh_status_t
fssh_check_access_permissions(int accessMode
,
365 fssh_mode_t mode
, fssh_gid_t nodeGroupID
,
366 fssh_uid_t nodeUserID
);
368 extern fssh_status_t
fssh_read_pages(int fd
, fssh_off_t pos
,
369 const struct fssh_iovec
*vecs
, fssh_size_t count
,
370 fssh_size_t
*_numBytes
);
371 extern fssh_status_t
fssh_write_pages(int fd
, fssh_off_t pos
,
372 const struct fssh_iovec
*vecs
, fssh_size_t count
,
373 fssh_size_t
*_numBytes
);
374 extern fssh_status_t
fssh_read_file_io_vec_pages(int fd
,
375 const struct fssh_file_io_vec
*fileVecs
,
376 fssh_size_t fileVecCount
, const struct fssh_iovec
*vecs
,
377 fssh_size_t vecCount
, uint32_t *_vecIndex
,
378 fssh_size_t
*_vecOffset
, fssh_size_t
*_bytes
);
379 extern fssh_status_t
fssh_write_file_io_vec_pages(int fd
,
380 const struct fssh_file_io_vec
*fileVecs
,
381 fssh_size_t fileVecCount
, const struct fssh_iovec
*vecs
,
382 fssh_size_t vecCount
, uint32_t *_vecIndex
,
383 fssh_size_t
*_vecOffset
, fssh_size_t
*_bytes
);
384 extern fssh_status_t
fssh_do_fd_io(int fd
, fssh_io_request
*request
);
385 extern fssh_status_t
fssh_do_iterative_fd_io(int fd
, fssh_io_request
*request
,
386 fssh_iterative_io_get_vecs getVecs
,
387 fssh_iterative_io_finished finished
, void *cookie
);
389 extern fssh_status_t
fssh_notify_entry_created(fssh_mount_id device
,
390 fssh_vnode_id directory
, const char *name
, fssh_vnode_id node
);
391 extern fssh_status_t
fssh_notify_entry_removed(fssh_mount_id device
,
392 fssh_vnode_id directory
, const char *name
, fssh_vnode_id node
);
393 extern fssh_status_t
fssh_notify_entry_moved(fssh_mount_id device
,
394 fssh_vnode_id fromDirectory
, const char *fromName
,
395 fssh_vnode_id toDirectory
, const char *toName
,
397 extern fssh_status_t
fssh_notify_stat_changed(fssh_mount_id device
,
398 fssh_vnode_id dir
, fssh_vnode_id node
, uint32_t statFields
);
399 extern fssh_status_t
fssh_notify_attribute_changed(fssh_mount_id device
,
400 fssh_vnode_id dir
, fssh_vnode_id node
, const char *attribute
,
403 extern fssh_status_t
fssh_notify_query_entry_created(fssh_port_id port
,
404 int32_t token
, fssh_mount_id device
,
405 fssh_vnode_id directory
, const char *name
,
407 extern fssh_status_t
fssh_notify_query_entry_removed(fssh_port_id port
,
408 int32_t token
, fssh_mount_id device
,
409 fssh_vnode_id directory
, const char *name
,
411 extern fssh_status_t
fssh_notify_query_attr_changed(fssh_port_id port
,
412 int32_t token
, fssh_mount_id device
,
413 fssh_vnode_id directory
, const char *name
,
420 #endif /* _FSSH_FS_INTERFACE_H */