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 /* the file system's private data structures */ 25 typedef void *fs_volume; 26 typedef void *fs_cookie; 27 typedef void *fs_vnode; 28 29 /* additional flags passed to write_stat() (see NodeMonitor.h for the others) */ 30 // NOTE: Changing the constants here or in NodeMonitor.h will break 31 // src/kits/storage/LibBeAdapter.cpp:_kern_write_stat(). 32 #define B_STAT_SIZE_INSECURE 0x2000 33 // TODO: this should be faded out once BFS supports sparse files 34 35 /* passed to write_fs_info() */ 36 #define FS_WRITE_FSINFO_NAME 0x0001 37 38 struct file_io_vec { 39 off_t offset; 40 off_t length; 41 }; 42 43 #define B_CURRENT_FS_API_VERSION "/v1" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 typedef struct file_system_module_info { 50 struct module_info info; 51 const char* pretty_name; 52 uint32 flags; // DDM flags 53 54 /* scanning (the device is write locked) */ 55 float (*identify_partition)(int fd, partition_data *partition, 56 void **cookie); 57 status_t (*scan_partition)(int fd, partition_data *partition, 58 void *cookie); 59 void (*free_identify_partition_cookie)(partition_data *partition, 60 void *cookie); 61 void (*free_partition_content_cookie)(partition_data *partition); 62 63 /* general operations */ 64 status_t (*mount)(dev_t id, const char *device, uint32 flags, 65 const char *args, fs_volume *_fs, ino_t *_rootVnodeID); 66 status_t (*unmount)(fs_volume fs); 67 68 status_t (*read_fs_info)(fs_volume fs, struct fs_info *info); 69 status_t (*write_fs_info)(fs_volume fs, const struct fs_info *info, 70 uint32 mask); 71 status_t (*sync)(fs_volume fs); 72 73 /* vnode operations */ 74 status_t (*lookup)(fs_volume fs, fs_vnode dir, const char *name, 75 ino_t *_id, int *_type); 76 status_t (*get_vnode_name)(fs_volume fs, fs_vnode vnode, char *buffer, 77 size_t bufferSize); 78 79 status_t (*get_vnode)(fs_volume fs, ino_t id, fs_vnode *_vnode, 80 bool reenter); 81 status_t (*put_vnode)(fs_volume fs, fs_vnode vnode, bool reenter); 82 status_t (*remove_vnode)(fs_volume fs, fs_vnode vnode, bool reenter); 83 84 /* VM file access */ 85 bool (*can_page)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 86 status_t (*read_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 87 off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, 88 bool reenter); 89 status_t (*write_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 90 off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, 91 bool reenter); 92 93 /* cache file access */ 94 status_t (*get_file_map)(fs_volume fs, fs_vnode vnode, off_t offset, 95 size_t size, struct file_io_vec *vecs, size_t *_count); 96 97 /* common operations */ 98 status_t (*ioctl)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, ulong op, 99 void *buffer, size_t length); 100 status_t (*set_flags)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 101 int flags); 102 status_t (*select)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 103 uint8 event, uint32 ref, selectsync *sync); 104 status_t (*deselect)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 105 uint8 event, selectsync *sync); 106 status_t (*fsync)(fs_volume fs, fs_vnode vnode); 107 108 status_t (*read_symlink)(fs_volume fs, fs_vnode link, char *buffer, 109 size_t *_bufferSize); 110 status_t (*create_symlink)(fs_volume fs, fs_vnode dir, const char *name, 111 const char *path, int mode); 112 113 status_t (*link)(fs_volume fs, fs_vnode dir, const char *name, 114 fs_vnode vnode); 115 status_t (*unlink)(fs_volume fs, fs_vnode dir, const char *name); 116 status_t (*rename)(fs_volume fs, fs_vnode fromDir, const char *fromName, 117 fs_vnode toDir, const char *toName); 118 119 status_t (*access)(fs_volume fs, fs_vnode vnode, int mode); 120 status_t (*read_stat)(fs_volume fs, fs_vnode vnode, struct stat *stat); 121 status_t (*write_stat)(fs_volume fs, fs_vnode vnode, 122 const struct stat *stat, uint32 statMask); 123 124 /* file operations */ 125 status_t (*create)(fs_volume fs, fs_vnode dir, const char *name, 126 int openMode, int perms, fs_cookie *_cookie, 127 ino_t *_newVnodeID); 128 status_t (*open)(fs_volume fs, fs_vnode vnode, int openMode, 129 fs_cookie *_cookie); 130 status_t (*close)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 131 status_t (*free_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 132 status_t (*read)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos, 133 void *buffer, size_t *length); 134 status_t (*write)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos, 135 const void *buffer, size_t *length); 136 137 /* directory operations */ 138 status_t (*create_dir)(fs_volume fs, fs_vnode parent, const char *name, 139 int perms, ino_t *_newVnodeID); 140 status_t (*remove_dir)(fs_volume fs, fs_vnode parent, const char *name); 141 status_t (*open_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie); 142 status_t (*close_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 143 status_t (*free_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 144 status_t (*read_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 145 struct dirent *buffer, size_t bufferSize, uint32 *_num); 146 status_t (*rewind_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 147 148 /* attribute directory operations */ 149 status_t (*open_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie); 150 status_t (*close_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 151 status_t (*free_attr_dir_cookie)(fs_volume fs, fs_vnode vnode, 152 fs_cookie cookie); 153 status_t (*read_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 154 struct dirent *buffer, size_t bufferSize, uint32 *_num); 155 status_t (*rewind_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 156 157 /* attribute operations */ 158 status_t (*create_attr)(fs_volume fs, fs_vnode vnode, const char *name, 159 uint32 type, int openMode, fs_cookie *_cookie); 160 status_t (*open_attr)(fs_volume fs, fs_vnode vnode, const char *name, 161 int openMode, fs_cookie *_cookie); 162 status_t (*close_attr)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); 163 status_t (*free_attr_cookie)(fs_volume fs, fs_vnode vnode, 164 fs_cookie cookie); 165 status_t (*read_attr)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 166 off_t pos, void *buffer, size_t *length); 167 status_t (*write_attr)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 168 off_t pos, const void *buffer, size_t *length); 169 170 status_t (*read_attr_stat)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 171 struct stat *stat); 172 status_t (*write_attr_stat)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, 173 const struct stat *stat, int statMask); 174 status_t (*rename_attr)(fs_volume fs, fs_vnode fromVnode, 175 const char *fromName, fs_vnode toVnode, const char *toName); 176 status_t (*remove_attr)(fs_volume fs, fs_vnode vnode, const char *name); 177 178 /* index directory & index operations */ 179 status_t (*open_index_dir)(fs_volume fs, fs_cookie *cookie); 180 status_t (*close_index_dir)(fs_volume fs, fs_cookie cookie); 181 status_t (*free_index_dir_cookie)(fs_volume fs, fs_cookie cookie); 182 status_t (*read_index_dir)(fs_volume fs, fs_cookie cookie, 183 struct dirent *buffer, size_t bufferSize, uint32 *_num); 184 status_t (*rewind_index_dir)(fs_volume fs, fs_cookie cookie); 185 186 status_t (*create_index)(fs_volume fs, const char *name, uint32 type, 187 uint32 flags); 188 status_t (*remove_index)(fs_volume fs, const char *name); 189 status_t (*read_index_stat)(fs_volume fs, const char *name, 190 struct stat *stat); 191 192 /* query operations */ 193 status_t (*open_query)(fs_volume fs, const char *query, uint32 flags, 194 port_id port, uint32 token, fs_cookie *_cookie); 195 status_t (*close_query)(fs_volume fs, fs_cookie cookie); 196 status_t (*free_query_cookie)(fs_volume fs, fs_cookie cookie); 197 status_t (*read_query)(fs_volume fs, fs_cookie cookie, 198 struct dirent *buffer, size_t bufferSize, uint32 *_num); 199 status_t (*rewind_query)(fs_volume fs, fs_cookie cookie); 200 201 /* capability querying (the device is read locked) */ 202 uint32 (*get_supported_operations)(partition_data* partition, uint32 mask); 203 204 bool (*validate_resize)(partition_data *partition, off_t *size); 205 bool (*validate_move)(partition_data *partition, off_t *start); 206 bool (*validate_set_content_name)(partition_data *partition, 207 char *name); 208 bool (*validate_set_content_parameters)(partition_data *partition, 209 const char *parameters); 210 bool (*validate_initialize)(partition_data *partition, char *name, 211 const char *parameters); 212 213 /* shadow partition modification (device is write locked) */ 214 status_t (*shadow_changed)(partition_data *partition, 215 partition_data *child, uint32 operation); 216 217 /* writing (the device is NOT locked) */ 218 status_t (*defragment)(int fd, partition_id partition, 219 disk_job_id job); 220 status_t (*repair)(int fd, partition_id partition, bool checkOnly, 221 disk_job_id job); 222 status_t (*resize)(int fd, partition_id partition, off_t size, 223 disk_job_id job); 224 status_t (*move)(int fd, partition_id partition, off_t offset, 225 disk_job_id job); 226 status_t (*set_content_name)(int fd, partition_id partition, 227 const char *name, disk_job_id job); 228 status_t (*set_content_parameters)(int fd, partition_id partition, 229 const char *parameters, disk_job_id job); 230 status_t (*initialize)(int fd, partition_id partition, const char *name, 231 const char *parameters, off_t partitionSize, disk_job_id job); 232 } file_system_module_info; 233 234 235 /* file system add-ons only prototypes */ 236 extern status_t new_vnode(dev_t mountID, ino_t vnodeID, 237 fs_vnode privateNode); 238 extern status_t publish_vnode(dev_t mountID, ino_t vnodeID, 239 fs_vnode privateNode); 240 extern status_t get_vnode(dev_t mountID, ino_t vnodeID, 241 fs_vnode *_privateNode); 242 extern status_t put_vnode(dev_t mountID, ino_t vnodeID); 243 extern status_t remove_vnode(dev_t mountID, ino_t vnodeID); 244 extern status_t unremove_vnode(dev_t mountID, ino_t vnodeID); 245 extern status_t get_vnode_removed(dev_t mountID, ino_t vnodeID, 246 bool* removed); 247 extern status_t read_pages(int fd, off_t pos, const struct iovec *vecs, 248 size_t count, size_t *_numBytes, bool fsReenter); 249 extern status_t write_pages(int fd, off_t pos, const struct iovec *vecs, 250 size_t count, size_t *_numBytes, bool fsReenter); 251 extern status_t read_file_io_vec_pages(int fd, 252 const struct file_io_vec *fileVecs, size_t fileVecCount, 253 const struct iovec *vecs, size_t vecCount, 254 uint32 *_vecIndex, size_t *_vecOffset, size_t *_bytes); 255 extern status_t write_file_io_vec_pages(int fd, 256 const struct file_io_vec *fileVecs, size_t fileVecCount, 257 const struct iovec *vecs, size_t vecCount, 258 uint32 *_vecIndex, size_t *_vecOffset, size_t *_bytes); 259 260 // Deprecated! Will disappear soon! 261 extern status_t notify_listener(int op, dev_t device, ino_t parentNode, 262 ino_t toParentNode, ino_t node, const char *name); 263 264 extern status_t notify_entry_created(dev_t device, ino_t directory, 265 const char *name, ino_t node); 266 extern status_t notify_entry_removed(dev_t device, ino_t directory, 267 const char *name, ino_t node); 268 extern status_t notify_entry_moved(dev_t device, ino_t fromDirectory, 269 const char *fromName, ino_t toDirectory, 270 const char *toName, ino_t node); 271 extern status_t notify_stat_changed(dev_t device, ino_t node, 272 uint32 statFields); 273 extern status_t notify_attribute_changed(dev_t device, ino_t node, 274 const char *attribute, int32 cause); 275 276 extern status_t notify_query_entry_created(port_id port, int32 token, 277 dev_t device, ino_t directory, const char *name, 278 ino_t node); 279 extern status_t notify_query_entry_removed(port_id port, int32 token, 280 dev_t device, ino_t directory, const char *name, 281 ino_t node); 282 283 #ifdef __cplusplus 284 } 285 #endif 286 287 #endif /* _FS_INTERFACE_H */ 288