1 /* 2 * Copyright 2004-2008, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _FS_INTERFACE_H 6 #define _FS_INTERFACE_H 7 8 /*! File System Interface Layer Definition */ 9 10 11 #include <OS.h> 12 #include <Select.h> 13 #include <module.h> 14 #include <disk_device_manager.h> 15 16 #include <sys/uio.h> 17 18 19 struct dirent; 20 struct stat; 21 struct fs_info; 22 struct select_sync; 23 24 typedef struct IORequest io_request; 25 26 27 /* additional flags passed to write_stat() (see NodeMonitor.h for the others) */ 28 // NOTE: Changing the constants here or in NodeMonitor.h will break 29 // src/kits/storage/LibBeAdapter.cpp:_kern_write_stat(). 30 #define B_STAT_SIZE_INSECURE 0x2000 31 // TODO: this should be faded out once BFS supports sparse files 32 33 /* passed to write_fs_info() */ 34 #define FS_WRITE_FSINFO_NAME 0x0001 35 36 struct file_io_vec { 37 off_t offset; 38 off_t length; 39 }; 40 41 #define B_CURRENT_FS_API_VERSION "/v1" 42 43 // flags for publish_vnode() and fs_volume_ops::get_vnode() 44 #define B_VNODE_PUBLISH_REMOVED 0x01 45 #define B_VNODE_DONT_CREATE_SPECIAL_SUB_NODE 0x02 46 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 typedef struct fs_volume fs_volume; 53 typedef struct fs_volume_ops fs_volume_ops; 54 typedef struct fs_vnode fs_vnode; 55 typedef struct fs_vnode_ops fs_vnode_ops; 56 57 58 struct fs_volume { 59 dev_t id; 60 partition_id partition; 61 int32 layer; 62 void* private_volume; 63 fs_volume_ops* ops; 64 fs_volume* sub_volume; 65 fs_volume* super_volume; 66 }; 67 68 struct fs_vnode { 69 void* private_node; 70 fs_vnode_ops* ops; 71 }; 72 73 struct fs_volume_ops { 74 status_t (*unmount)(fs_volume *volume); 75 76 status_t (*read_fs_info)(fs_volume *volume, struct fs_info *info); 77 status_t (*write_fs_info)(fs_volume *volume, const struct fs_info *info, 78 uint32 mask); 79 status_t (*sync)(fs_volume *volume); 80 81 status_t (*get_vnode)(fs_volume *volume, ino_t id, fs_vnode *vnode, 82 int *_type, uint32 *_flags, bool reenter); 83 84 /* index directory & index operations */ 85 status_t (*open_index_dir)(fs_volume *volume, void **cookie); 86 status_t (*close_index_dir)(fs_volume *volume, void *cookie); 87 status_t (*free_index_dir_cookie)(fs_volume *volume, void *cookie); 88 status_t (*read_index_dir)(fs_volume *volume, void *cookie, 89 struct dirent *buffer, size_t bufferSize, uint32 *_num); 90 status_t (*rewind_index_dir)(fs_volume *volume, void *cookie); 91 92 status_t (*create_index)(fs_volume *volume, const char *name, uint32 type, 93 uint32 flags); 94 status_t (*remove_index)(fs_volume *volume, const char *name); 95 status_t (*read_index_stat)(fs_volume *volume, const char *name, 96 struct stat *stat); 97 98 /* query operations */ 99 status_t (*open_query)(fs_volume *volume, const char *query, uint32 flags, 100 port_id port, uint32 token, void **_cookie); 101 status_t (*close_query)(fs_volume *volume, void *cookie); 102 status_t (*free_query_cookie)(fs_volume *volume, void *cookie); 103 status_t (*read_query)(fs_volume *volume, void *cookie, 104 struct dirent *buffer, size_t bufferSize, uint32 *_num); 105 status_t (*rewind_query)(fs_volume *volume, void *cookie); 106 107 /* support for FS layers */ 108 status_t (*create_sub_vnode)(fs_volume *volume, ino_t id, fs_vnode *vnode); 109 status_t (*delete_sub_vnode)(fs_volume *volume, fs_vnode *vnode); 110 }; 111 112 struct fs_vnode_ops { 113 /* vnode operations */ 114 status_t (*lookup)(fs_volume *volume, fs_vnode *dir, const char *name, 115 ino_t *_id); 116 status_t (*get_vnode_name)(fs_volume *volume, fs_vnode *vnode, char *buffer, 117 size_t bufferSize); 118 119 status_t (*put_vnode)(fs_volume *volume, fs_vnode *vnode, bool reenter); 120 status_t (*remove_vnode)(fs_volume *volume, fs_vnode *vnode, bool reenter); 121 122 /* VM file access */ 123 bool (*can_page)(fs_volume *volume, fs_vnode *vnode, void *cookie); 124 status_t (*read_pages)(fs_volume *volume, fs_vnode *vnode, void *cookie, 125 off_t pos, const iovec *vecs, size_t count, size_t *_numBytes); 126 status_t (*write_pages)(fs_volume *volume, fs_vnode *vnode, 127 void *cookie, off_t pos, const iovec *vecs, size_t count, 128 size_t *_numBytes); 129 130 /* asynchronous I/O */ 131 status_t (*io)(fs_volume *volume, fs_vnode *vnode, void *cookie, 132 io_request *request); 133 status_t (*cancel_io)(fs_volume *volume, fs_vnode *vnode, void *cookie, 134 io_request *request); 135 136 /* cache file access */ 137 status_t (*get_file_map)(fs_volume *volume, fs_vnode *vnode, off_t offset, 138 size_t size, struct file_io_vec *vecs, size_t *_count); 139 140 /* common operations */ 141 status_t (*ioctl)(fs_volume *volume, fs_vnode *vnode, void *cookie, 142 ulong op, void *buffer, size_t length); 143 status_t (*set_flags)(fs_volume *volume, fs_vnode *vnode, void *cookie, 144 int flags); 145 status_t (*select)(fs_volume *volume, fs_vnode *vnode, void *cookie, 146 uint8 event, selectsync *sync); 147 status_t (*deselect)(fs_volume *volume, fs_vnode *vnode, void *cookie, 148 uint8 event, selectsync *sync); 149 status_t (*fsync)(fs_volume *volume, fs_vnode *vnode); 150 151 status_t (*read_symlink)(fs_volume *volume, fs_vnode *link, char *buffer, 152 size_t *_bufferSize); 153 status_t (*create_symlink)(fs_volume *volume, fs_vnode *dir, 154 const char *name, const char *path, int mode); 155 156 status_t (*link)(fs_volume *volume, fs_vnode *dir, const char *name, 157 fs_vnode *vnode); 158 status_t (*unlink)(fs_volume *volume, fs_vnode *dir, const char *name); 159 status_t (*rename)(fs_volume *volume, fs_vnode *fromDir, 160 const char *fromName, fs_vnode *toDir, const char *toName); 161 162 status_t (*access)(fs_volume *volume, fs_vnode *vnode, int mode); 163 status_t (*read_stat)(fs_volume *volume, fs_vnode *vnode, 164 struct stat *stat); 165 status_t (*write_stat)(fs_volume *volume, fs_vnode *vnode, 166 const struct stat *stat, uint32 statMask); 167 168 /* file operations */ 169 status_t (*create)(fs_volume *volume, fs_vnode *dir, const char *name, 170 int openMode, int perms, void **_cookie, 171 ino_t *_newVnodeID); 172 status_t (*open)(fs_volume *volume, fs_vnode *vnode, int openMode, 173 void **_cookie); 174 status_t (*close)(fs_volume *volume, fs_vnode *vnode, void *cookie); 175 status_t (*free_cookie)(fs_volume *volume, fs_vnode *vnode, 176 void *cookie); 177 status_t (*read)(fs_volume *volume, fs_vnode *vnode, void *cookie, 178 off_t pos, void *buffer, size_t *length); 179 status_t (*write)(fs_volume *volume, fs_vnode *vnode, void *cookie, 180 off_t pos, const void *buffer, size_t *length); 181 182 /* directory operations */ 183 status_t (*create_dir)(fs_volume *volume, fs_vnode *parent, 184 const char *name, int perms, ino_t *_newVnodeID); 185 status_t (*remove_dir)(fs_volume *volume, fs_vnode *parent, 186 const char *name); 187 status_t (*open_dir)(fs_volume *volume, fs_vnode *vnode, 188 void **_cookie); 189 status_t (*close_dir)(fs_volume *volume, fs_vnode *vnode, void *cookie); 190 status_t (*free_dir_cookie)(fs_volume *volume, fs_vnode *vnode, 191 void *cookie); 192 status_t (*read_dir)(fs_volume *volume, fs_vnode *vnode, void *cookie, 193 struct dirent *buffer, size_t bufferSize, uint32 *_num); 194 status_t (*rewind_dir)(fs_volume *volume, fs_vnode *vnode, 195 void *cookie); 196 197 /* attribute directory operations */ 198 status_t (*open_attr_dir)(fs_volume *volume, fs_vnode *vnode, 199 void **_cookie); 200 status_t (*close_attr_dir)(fs_volume *volume, fs_vnode *vnode, 201 void *cookie); 202 status_t (*free_attr_dir_cookie)(fs_volume *volume, fs_vnode *vnode, 203 void *cookie); 204 status_t (*read_attr_dir)(fs_volume *volume, fs_vnode *vnode, 205 void *cookie, struct dirent *buffer, size_t bufferSize, 206 uint32 *_num); 207 status_t (*rewind_attr_dir)(fs_volume *volume, fs_vnode *vnode, 208 void *cookie); 209 210 /* attribute operations */ 211 status_t (*create_attr)(fs_volume *volume, fs_vnode *vnode, 212 const char *name, uint32 type, int openMode, 213 void **_cookie); 214 status_t (*open_attr)(fs_volume *volume, fs_vnode *vnode, const char *name, 215 int openMode, void **_cookie); 216 status_t (*close_attr)(fs_volume *volume, fs_vnode *vnode, 217 void *cookie); 218 status_t (*free_attr_cookie)(fs_volume *volume, fs_vnode *vnode, 219 void *cookie); 220 status_t (*read_attr)(fs_volume *volume, fs_vnode *vnode, void *cookie, 221 off_t pos, void *buffer, size_t *length); 222 status_t (*write_attr)(fs_volume *volume, fs_vnode *vnode, void *cookie, 223 off_t pos, const void *buffer, size_t *length); 224 225 status_t (*read_attr_stat)(fs_volume *volume, fs_vnode *vnode, 226 void *cookie, struct stat *stat); 227 status_t (*write_attr_stat)(fs_volume *volume, fs_vnode *vnode, 228 void *cookie, const struct stat *stat, int statMask); 229 status_t (*rename_attr)(fs_volume *volume, fs_vnode *fromVnode, 230 const char *fromName, fs_vnode *toVnode, const char *toName); 231 status_t (*remove_attr)(fs_volume *volume, fs_vnode *vnode, 232 const char *name); 233 234 /* support for node and FS layers */ 235 status_t (*create_special_node)(fs_volume *volume, fs_vnode *dir, 236 const char *name, fs_vnode *subVnode, mode_t mode, uint32 flags, 237 fs_vnode *_superVnode, ino_t *_nodeID); 238 status_t (*get_super_vnode)(fs_volume *volume, fs_vnode *vnode, 239 fs_volume *superVolume, fs_vnode *superVnode); 240 }; 241 242 typedef struct file_system_module_info { 243 struct module_info info; 244 const char* short_name; 245 const char* pretty_name; 246 uint32 flags; // DDM flags 247 248 /* scanning (the device is write locked) */ 249 float (*identify_partition)(int fd, partition_data *partition, 250 void **cookie); 251 status_t (*scan_partition)(int fd, partition_data *partition, 252 void *cookie); 253 void (*free_identify_partition_cookie)(partition_data *partition, 254 void *cookie); 255 void (*free_partition_content_cookie)(partition_data *partition); 256 257 /* general operations */ 258 status_t (*mount)(fs_volume *volume, const char *device, uint32 flags, 259 const char *args, ino_t *_rootVnodeID); 260 261 /* capability querying (the device is read locked) */ 262 uint32 (*get_supported_operations)(partition_data* partition, uint32 mask); 263 264 bool (*validate_resize)(partition_data *partition, off_t *size); 265 bool (*validate_move)(partition_data *partition, off_t *start); 266 bool (*validate_set_content_name)(partition_data *partition, 267 char *name); 268 bool (*validate_set_content_parameters)(partition_data *partition, 269 const char *parameters); 270 bool (*validate_initialize)(partition_data *partition, char *name, 271 const char *parameters); 272 273 /* shadow partition modification (device is write locked) */ 274 status_t (*shadow_changed)(partition_data *partition, 275 partition_data *child, uint32 operation); 276 277 /* writing (the device is NOT locked) */ 278 status_t (*defragment)(int fd, partition_id partition, 279 disk_job_id job); 280 status_t (*repair)(int fd, partition_id partition, bool checkOnly, 281 disk_job_id job); 282 status_t (*resize)(int fd, partition_id partition, off_t size, 283 disk_job_id job); 284 status_t (*move)(int fd, partition_id partition, off_t offset, 285 disk_job_id job); 286 status_t (*set_content_name)(int fd, partition_id partition, 287 const char *name, disk_job_id job); 288 status_t (*set_content_parameters)(int fd, partition_id partition, 289 const char *parameters, disk_job_id job); 290 status_t (*initialize)(int fd, partition_id partition, const char *name, 291 const char *parameters, off_t partitionSize, disk_job_id job); 292 } file_system_module_info; 293 294 295 /* file system add-ons only prototypes */ 296 297 // callbacks for do_iterative_fd_io() 298 typedef status_t (*iterative_io_get_vecs)(void *cookie, io_request* request, 299 off_t offset, size_t size, struct file_io_vec *vecs, 300 size_t *_count); 301 typedef status_t (*iterative_io_finished)(void* cookie, io_request* request, 302 status_t status, bool partialTransfer, size_t bytesTransferred); 303 304 extern status_t new_vnode(fs_volume *volume, ino_t vnodeID, void *privateNode, 305 fs_vnode_ops *ops); 306 extern status_t publish_vnode(fs_volume *volume, ino_t vnodeID, 307 void *privateNode, fs_vnode_ops *ops, int type, 308 uint32 flags); 309 extern status_t get_vnode(fs_volume *volume, ino_t vnodeID, 310 void **_privateNode); 311 extern status_t put_vnode(fs_volume *volume, ino_t vnodeID); 312 extern status_t acquire_vnode(fs_volume *volume, ino_t vnodeID); 313 extern status_t remove_vnode(fs_volume *volume, ino_t vnodeID); 314 extern status_t unremove_vnode(fs_volume *volume, ino_t vnodeID); 315 extern status_t get_vnode_removed(fs_volume *volume, ino_t vnodeID, 316 bool *removed); 317 extern fs_volume* volume_for_vnode(fs_vnode *vnode); 318 319 extern status_t read_pages(int fd, off_t pos, const struct iovec *vecs, 320 size_t count, size_t *_numBytes); 321 extern status_t write_pages(int fd, off_t pos, const struct iovec *vecs, 322 size_t count, size_t *_numBytes); 323 extern status_t read_file_io_vec_pages(int fd, 324 const struct file_io_vec *fileVecs, size_t fileVecCount, 325 const struct iovec *vecs, size_t vecCount, 326 uint32 *_vecIndex, size_t *_vecOffset, size_t *_bytes); 327 extern status_t write_file_io_vec_pages(int fd, 328 const struct file_io_vec *fileVecs, size_t fileVecCount, 329 const struct iovec *vecs, size_t vecCount, 330 uint32 *_vecIndex, size_t *_vecOffset, size_t *_bytes); 331 extern status_t do_fd_io(int fd, io_request *request); 332 extern status_t do_iterative_fd_io(int fd, io_request *request, 333 iterative_io_get_vecs getVecs, 334 iterative_io_finished finished, void *cookie); 335 336 extern status_t notify_entry_created(dev_t device, ino_t directory, 337 const char *name, ino_t node); 338 extern status_t notify_entry_removed(dev_t device, ino_t directory, 339 const char *name, ino_t node); 340 extern status_t notify_entry_moved(dev_t device, ino_t fromDirectory, 341 const char *fromName, ino_t toDirectory, 342 const char *toName, ino_t node); 343 extern status_t notify_stat_changed(dev_t device, ino_t node, 344 uint32 statFields); 345 extern status_t notify_attribute_changed(dev_t device, ino_t node, 346 const char *attribute, int32 cause); 347 348 extern status_t notify_query_entry_created(port_id port, int32 token, 349 dev_t device, ino_t directory, const char *name, 350 ino_t node); 351 extern status_t notify_query_entry_removed(port_id port, int32 token, 352 dev_t device, ino_t directory, const char *name, 353 ino_t node); 354 355 #ifdef __cplusplus 356 } 357 #endif 358 359 #endif /* _FS_INTERFACE_H */ 360