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