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