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 typedef struct FSSHIORequest fssh_io_request; 30 31 /* additional flags passed to write_stat() */ 32 #define FSSH_B_STAT_SIZE_INSECURE 0x2000 33 34 /* passed to write_fs_info() */ 35 #define FSSH_FS_WRITE_FSINFO_NAME 0x0001 36 37 struct fssh_file_io_vec { 38 fssh_off_t offset; 39 fssh_off_t length; 40 }; 41 42 #define FSSH_B_CURRENT_FS_API_VERSION "/v1" 43 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 47 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 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; 57 58 59 struct fssh_fs_volume { 60 fssh_dev_t id; 61 int32_t layer; 62 void* private_volume; 63 fssh_fs_volume_ops* ops; 64 fssh_fs_volume* sub_volume; 65 fssh_fs_volume* super_volume; 66 }; 67 68 struct fssh_fs_vnode { 69 void* private_node; 70 fssh_fs_vnode_ops* ops; 71 }; 72 73 struct fssh_fs_volume_ops { 74 fssh_status_t (*unmount)(fssh_fs_volume *volume); 75 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); 81 82 fssh_status_t (*get_vnode)(fssh_fs_volume *volume, fssh_vnode_id id, 83 fssh_fs_vnode *_vnode, int *_type, uint32_t *_flags, 84 bool reenter); 85 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); 98 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); 104 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, 114 uint32_t *_num); 115 fssh_status_t (*rewind_query)(fssh_fs_volume *volume, 116 fssh_fs_cookie cookie); 117 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); 123 }; 124 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); 131 132 fssh_status_t (*put_vnode)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 133 bool reenter); 134 fssh_status_t (*remove_vnode)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 135 bool reenter); 136 137 /* VM file access */ 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); 146 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); 152 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); 157 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, 161 fssh_size_t length); 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); 169 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); 174 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, 178 const char *name); 179 fssh_status_t (*rename)(fssh_fs_volume *volume, fssh_fs_vnode *fromDir, 180 const char *fromName, fssh_fs_vnode *toDir, const char *toName); 181 182 fssh_status_t (*access)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 183 int mode); 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 189 /* file operations */ 190 fssh_status_t (*create)(fssh_fs_volume *volume, fssh_fs_vnode *dir, 191 const char *name, int openMode, int perms, 192 fssh_fs_cookie *_cookie, fssh_vnode_id *_newVnodeID); 193 fssh_status_t (*open)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 194 int openMode, fssh_fs_cookie *_cookie); 195 fssh_status_t (*close)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 196 fssh_fs_cookie cookie); 197 fssh_status_t (*free_cookie)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 198 fssh_fs_cookie cookie); 199 fssh_status_t (*read)(fssh_fs_volume *volume, 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)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 203 fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer, 204 fssh_size_t *length); 205 206 /* directory operations */ 207 fssh_status_t (*create_dir)(fssh_fs_volume *volume, fssh_fs_vnode *parent, 208 const char *name, int perms); 209 fssh_status_t (*remove_dir)(fssh_fs_volume *volume, fssh_fs_vnode *parent, 210 const char *name); 211 fssh_status_t (*open_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 212 fssh_fs_cookie *_cookie); 213 fssh_status_t (*close_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 214 fssh_fs_cookie cookie); 215 fssh_status_t (*free_dir_cookie)(fssh_fs_volume *volume, 216 fssh_fs_vnode *vnode, fssh_fs_cookie cookie); 217 fssh_status_t (*read_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 218 fssh_fs_cookie cookie, struct fssh_dirent *buffer, 219 fssh_size_t bufferSize, uint32_t *_num); 220 fssh_status_t (*rewind_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 221 fssh_fs_cookie cookie); 222 223 /* attribute directory operations */ 224 fssh_status_t (*open_attr_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 225 fssh_fs_cookie *_cookie); 226 fssh_status_t (*close_attr_dir)(fssh_fs_volume *volume, 227 fssh_fs_vnode *vnode, fssh_fs_cookie cookie); 228 fssh_status_t (*free_attr_dir_cookie)(fssh_fs_volume *volume, 229 fssh_fs_vnode *vnode, fssh_fs_cookie cookie); 230 fssh_status_t (*read_attr_dir)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 231 fssh_fs_cookie cookie, struct fssh_dirent *buffer, 232 fssh_size_t bufferSize, uint32_t *_num); 233 fssh_status_t (*rewind_attr_dir)(fssh_fs_volume *volume, 234 fssh_fs_vnode *vnode, fssh_fs_cookie cookie); 235 236 /* attribute operations */ 237 fssh_status_t (*create_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 238 const char *name, uint32_t type, int openMode, 239 fssh_fs_cookie *_cookie); 240 fssh_status_t (*open_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 241 const char *name, int openMode, fssh_fs_cookie *_cookie); 242 fssh_status_t (*close_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 243 fssh_fs_cookie cookie); 244 fssh_status_t (*free_attr_cookie)(fssh_fs_volume *volume, 245 fssh_fs_vnode *vnode, fssh_fs_cookie cookie); 246 fssh_status_t (*read_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 247 fssh_fs_cookie cookie, fssh_off_t pos, void *buffer, 248 fssh_size_t *length); 249 fssh_status_t (*write_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 250 fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer, 251 fssh_size_t *length); 252 253 fssh_status_t (*read_attr_stat)(fssh_fs_volume *volume, 254 fssh_fs_vnode *vnode, fssh_fs_cookie cookie, 255 struct fssh_stat *stat); 256 fssh_status_t (*write_attr_stat)(fssh_fs_volume *volume, 257 fssh_fs_vnode *vnode, fssh_fs_cookie cookie, 258 const struct fssh_stat *stat, int statMask); 259 fssh_status_t (*rename_attr)(fssh_fs_volume *volume, 260 fssh_fs_vnode *fromVnode, const char *fromName, 261 fssh_fs_vnode *toVnode, const char *toName); 262 fssh_status_t (*remove_attr)(fssh_fs_volume *volume, fssh_fs_vnode *vnode, 263 const char *name); 264 265 /* support for vnode and FS layers */ 266 fssh_status_t (*create_special_node)(fssh_fs_volume *volume, 267 fssh_fs_vnode *dir, const char *name, fssh_fs_vnode *subVnode, 268 fssh_mode_t mode, uint32_t flags, fssh_fs_vnode *_superVnode, 269 fssh_ino_t *_nodeID); 270 fssh_status_t (*get_super_vnode)(fssh_fs_volume *volume, 271 fssh_fs_vnode *vnode, fssh_fs_volume *superVolume, 272 fssh_fs_vnode *superVnode); 273 }; 274 275 typedef struct fssh_file_system_module_info { 276 struct fssh_module_info info; 277 const char* short_name; 278 const char* pretty_name; 279 uint32_t flags; // DDM flags 280 281 /* scanning (the device is write locked) */ 282 float (*identify_partition)(int fd, fssh_partition_data *partition, 283 void **cookie); 284 fssh_status_t (*scan_partition)(int fd, fssh_partition_data *partition, 285 void *cookie); 286 void (*free_identify_partition_cookie)(fssh_partition_data *partition, 287 void *cookie); 288 void (*free_partition_content_cookie)(fssh_partition_data *partition); 289 290 /* general operations */ 291 fssh_status_t (*mount)(fssh_fs_volume *volume, const char *device, 292 uint32_t flags, const char *args, fssh_vnode_id *_rootVnodeID); 293 294 /* capability querying (the device is read locked) */ 295 uint32_t (*get_supported_operations)(fssh_partition_data* partition, 296 uint32_t mask); 297 298 bool (*validate_resize)(fssh_partition_data *partition, fssh_off_t *size); 299 bool (*validate_move)(fssh_partition_data *partition, fssh_off_t *start); 300 bool (*validate_set_content_name)(fssh_partition_data *partition, 301 char *name); 302 bool (*validate_set_content_parameters)(fssh_partition_data *partition, 303 const char *parameters); 304 bool (*validate_initialize)(fssh_partition_data *partition, char *name, 305 const char *parameters); 306 307 /* shadow partition modification (device is write locked) */ 308 fssh_status_t (*shadow_changed)(fssh_partition_data *partition, 309 fssh_partition_data *child, uint32_t operation); 310 311 /* writing (the device is NOT locked) */ 312 fssh_status_t (*defragment)(int fd, fssh_partition_id partition, 313 fssh_disk_job_id job); 314 fssh_status_t (*repair)(int fd, fssh_partition_id partition, bool checkOnly, 315 fssh_disk_job_id job); 316 fssh_status_t (*resize)(int fd, fssh_partition_id partition, 317 fssh_off_t size, fssh_disk_job_id job); 318 fssh_status_t (*move)(int fd, fssh_partition_id partition, 319 fssh_off_t offset, fssh_disk_job_id job); 320 fssh_status_t (*set_content_name)(int fd, fssh_partition_id partition, 321 const char *name, fssh_disk_job_id job); 322 fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition, 323 const char *parameters, fssh_disk_job_id job); 324 fssh_status_t (*initialize)(int fd, fssh_partition_id partition, 325 const char *name, const char *parameters, 326 fssh_off_t partitionSize, fssh_disk_job_id job); 327 } fssh_file_system_module_info; 328 329 330 /* file system add-ons only prototypes */ 331 332 // callbacks for do_iterative_fd_io() 333 typedef fssh_status_t (*fssh_iterative_io_get_vecs)(void *cookie, 334 fssh_io_request* request, fssh_off_t offset, fssh_size_t size, 335 struct fssh_file_io_vec *vecs, fssh_size_t *_count); 336 typedef fssh_status_t (*fssh_iterative_io_finished)(void* cookie, 337 fssh_io_request* request, fssh_status_t status, 338 bool partialTransfer, fssh_size_t bytesTransferred); 339 340 extern fssh_status_t fssh_new_vnode(fssh_fs_volume *volume, 341 fssh_vnode_id vnodeID, void *privateNode, 342 fssh_fs_vnode_ops *ops); 343 extern fssh_status_t fssh_publish_vnode(fssh_fs_volume *volume, 344 fssh_vnode_id vnodeID, void *privateNode, 345 fssh_fs_vnode_ops *ops, int type, uint32_t flags); 346 extern fssh_status_t fssh_get_vnode(fssh_fs_volume *volume, 347 fssh_vnode_id vnodeID, void **_privateNode); 348 extern fssh_status_t fssh_put_vnode(fssh_fs_volume *volume, 349 fssh_vnode_id vnodeID); 350 extern fssh_status_t fssh_acquire_vnode(fssh_fs_volume *volume, 351 fssh_vnode_id vnodeID); 352 extern fssh_status_t fssh_remove_vnode(fssh_fs_volume *volume, 353 fssh_vnode_id vnodeID); 354 extern fssh_status_t fssh_unremove_vnode(fssh_fs_volume *volume, 355 fssh_vnode_id vnodeID); 356 extern fssh_status_t fssh_get_vnode_removed(fssh_fs_volume *volume, 357 fssh_vnode_id vnodeID, bool* removed); 358 extern fssh_fs_volume* fssh_volume_for_vnode(fssh_fs_vnode *vnode); 359 360 361 extern fssh_status_t fssh_read_pages(int fd, fssh_off_t pos, 362 const struct fssh_iovec *vecs, fssh_size_t count, 363 fssh_size_t *_numBytes); 364 extern fssh_status_t fssh_write_pages(int fd, fssh_off_t pos, 365 const struct fssh_iovec *vecs, fssh_size_t count, 366 fssh_size_t *_numBytes); 367 extern fssh_status_t fssh_read_file_io_vec_pages(int fd, 368 const struct fssh_file_io_vec *fileVecs, 369 fssh_size_t fileVecCount, const struct fssh_iovec *vecs, 370 fssh_size_t vecCount, uint32_t *_vecIndex, 371 fssh_size_t *_vecOffset, fssh_size_t *_bytes); 372 extern fssh_status_t fssh_write_file_io_vec_pages(int fd, 373 const struct fssh_file_io_vec *fileVecs, 374 fssh_size_t fileVecCount, const struct fssh_iovec *vecs, 375 fssh_size_t vecCount, uint32_t *_vecIndex, 376 fssh_size_t *_vecOffset, fssh_size_t *_bytes); 377 extern fssh_status_t fssh_do_fd_io(int fd, fssh_io_request *request); 378 extern fssh_status_t fssh_do_iterative_fd_io(int fd, fssh_io_request *request, 379 fssh_iterative_io_get_vecs getVecs, 380 fssh_iterative_io_finished finished, void *cookie); 381 382 extern fssh_status_t fssh_notify_entry_created(fssh_mount_id device, 383 fssh_vnode_id directory, const char *name, fssh_vnode_id node); 384 extern fssh_status_t fssh_notify_entry_removed(fssh_mount_id device, 385 fssh_vnode_id directory, const char *name, fssh_vnode_id node); 386 extern fssh_status_t fssh_notify_entry_moved(fssh_mount_id device, 387 fssh_vnode_id fromDirectory, const char *fromName, 388 fssh_vnode_id toDirectory, const char *toName, 389 fssh_vnode_id node); 390 extern fssh_status_t fssh_notify_stat_changed(fssh_mount_id device, 391 fssh_vnode_id node, uint32_t statFields); 392 extern fssh_status_t fssh_notify_attribute_changed(fssh_mount_id device, 393 fssh_vnode_id node, const char *attribute, int32_t cause); 394 395 extern fssh_status_t fssh_notify_query_entry_created(fssh_port_id port, 396 int32_t token, fssh_mount_id device, 397 fssh_vnode_id directory, const char *name, 398 fssh_vnode_id node); 399 extern fssh_status_t fssh_notify_query_entry_removed(fssh_port_id port, 400 int32_t token, fssh_mount_id device, 401 fssh_vnode_id directory, const char *name, 402 fssh_vnode_id node); 403 404 #ifdef __cplusplus 405 } 406 #endif 407 408 #endif /* _FSSH_FS_INTERFACE_H */ 409