1 /* File System Interface Layer Definition 2 * 3 * Copyright 2004-2006, Haiku Inc. All Rights Reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _FSSH_FS_INTERFACE_H 7 #define _FSSH_FS_INTERFACE_H 8 9 10 #include "fssh_disk_device_defs.h" 11 #include "fssh_module.h" 12 #include "fssh_os.h" 13 14 15 struct fssh_dirent; 16 struct fssh_fs_info; 17 struct fssh_iovec; 18 struct fssh_partition_data; 19 struct fssh_selectsync; 20 struct fssh_stat; 21 22 typedef fssh_dev_t fssh_mount_id; 23 typedef fssh_ino_t fssh_vnode_id; 24 25 /* the file system's private data structures */ 26 typedef void *fssh_fs_volume; 27 typedef void *fssh_fs_cookie; 28 typedef void *fssh_fs_vnode; 29 30 /* passed to write_stat() */ 31 enum fssh_write_stat_mask { 32 FSSH_FS_WRITE_STAT_MODE = 0x0001, 33 FSSH_FS_WRITE_STAT_UID = 0x0002, 34 FSSH_FS_WRITE_STAT_GID = 0x0004, 35 FSSH_FS_WRITE_STAT_SIZE = 0x0008, 36 FSSH_FS_WRITE_STAT_ATIME = 0x0010, 37 FSSH_FS_WRITE_STAT_MTIME = 0x0020, 38 FSSH_FS_WRITE_STAT_CRTIME = 0x0040 39 }; 40 41 /* passed to write_fs_info() */ 42 #define FSSH_FS_WRITE_FSINFO_NAME 0x0001 43 44 struct fssh_file_io_vec { 45 fssh_off_t offset; 46 fssh_off_t length; 47 }; 48 49 #define FSSH_B_CURRENT_FS_API_VERSION "/v1" 50 51 #ifdef __cplusplus 52 extern "C" { 53 #endif 54 55 typedef struct fssh_file_system_module_info { 56 struct fssh_module_info info; 57 const char* pretty_name; 58 uint32_t flags; // DDM flags 59 60 /* scanning (the device is write locked) */ 61 float (*identify_partition)(int fd, fssh_partition_data *partition, 62 void **cookie); 63 fssh_status_t (*scan_partition)(int fd, fssh_partition_data *partition, 64 void *cookie); 65 void (*free_identify_partition_cookie)(fssh_partition_data *partition, 66 void *cookie); 67 void (*free_partition_content_cookie)(fssh_partition_data *partition); 68 69 /* general operations */ 70 fssh_status_t (*mount)(fssh_mount_id id, const char *device, uint32_t flags, 71 const char *args, fssh_fs_volume *_fs, 72 fssh_vnode_id *_rootVnodeID); 73 fssh_status_t (*unmount)(fssh_fs_volume fs); 74 75 fssh_status_t (*read_fs_info)(fssh_fs_volume fs, struct fssh_fs_info *info); 76 fssh_status_t (*write_fs_info)(fssh_fs_volume fs, 77 const struct fssh_fs_info *info, uint32_t mask); 78 fssh_status_t (*sync)(fssh_fs_volume fs); 79 80 /* vnode operations */ 81 fssh_status_t (*lookup)(fssh_fs_volume fs, fssh_fs_vnode dir, 82 const char *name, fssh_vnode_id *_id, int *_type); 83 fssh_status_t (*get_vnode_name)(fssh_fs_volume fs, fssh_fs_vnode vnode, 84 char *buffer, fssh_size_t bufferSize); 85 86 fssh_status_t (*get_vnode)(fssh_fs_volume fs, fssh_vnode_id id, 87 fssh_fs_vnode *_vnode, bool reenter); 88 fssh_status_t (*put_vnode)(fssh_fs_volume fs, fssh_fs_vnode vnode, 89 bool reenter); 90 fssh_status_t (*remove_vnode)(fssh_fs_volume fs, fssh_fs_vnode vnode, 91 bool reenter); 92 93 /* VM file access */ 94 bool (*can_page)(fssh_fs_volume fs, fssh_fs_vnode vnode, 95 fssh_fs_cookie cookie); 96 fssh_status_t (*read_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode, 97 fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs, 98 fssh_size_t count, fssh_size_t *_numBytes, bool reenter); 99 fssh_status_t (*write_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode, 100 fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs, 101 fssh_size_t count, fssh_size_t *_numBytes, bool reenter); 102 103 /* cache file access */ 104 fssh_status_t (*get_file_map)(fssh_fs_volume fs, fssh_fs_vnode vnode, 105 fssh_off_t offset, fssh_size_t size, 106 struct fssh_file_io_vec *vecs, fssh_size_t *_count); 107 108 /* common operations */ 109 fssh_status_t (*ioctl)(fssh_fs_volume fs, fssh_fs_vnode vnode, 110 fssh_fs_cookie cookie, fssh_ulong op, void *buffer, 111 fssh_size_t length); 112 fssh_status_t (*set_flags)(fssh_fs_volume fs, fssh_fs_vnode vnode, 113 fssh_fs_cookie cookie, int flags); 114 fssh_status_t (*select)(fssh_fs_volume fs, fssh_fs_vnode vnode, 115 fssh_fs_cookie cookie, uint8_t event, uint32_t ref, 116 fssh_selectsync *sync); 117 fssh_status_t (*deselect)(fssh_fs_volume fs, fssh_fs_vnode vnode, 118 fssh_fs_cookie cookie, uint8_t event, fssh_selectsync *sync); 119 fssh_status_t (*fsync)(fssh_fs_volume fs, fssh_fs_vnode vnode); 120 121 fssh_status_t (*read_symlink)(fssh_fs_volume fs, fssh_fs_vnode link, 122 char *buffer, fssh_size_t *_bufferSize); 123 fssh_status_t (*create_symlink)(fssh_fs_volume fs, fssh_fs_vnode dir, 124 const char *name, const char *path, int mode); 125 126 fssh_status_t (*link)(fssh_fs_volume fs, fssh_fs_vnode dir, 127 const char *name, fssh_fs_vnode vnode); 128 fssh_status_t (*unlink)(fssh_fs_volume fs, fssh_fs_vnode dir, 129 const char *name); 130 fssh_status_t (*rename)(fssh_fs_volume fs, fssh_fs_vnode fromDir, 131 const char *fromName, fssh_fs_vnode toDir, const char *toName); 132 133 fssh_status_t (*access)(fssh_fs_volume fs, fssh_fs_vnode vnode, int mode); 134 fssh_status_t (*read_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode, 135 struct fssh_stat *stat); 136 fssh_status_t (*write_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode, 137 const struct fssh_stat *stat, uint32_t statMask); 138 139 /* file operations */ 140 fssh_status_t (*create)(fssh_fs_volume fs, fssh_fs_vnode dir, 141 const char *name, int openMode, int perms, 142 fssh_fs_cookie *_cookie, fssh_vnode_id *_newVnodeID); 143 fssh_status_t (*open)(fssh_fs_volume fs, fssh_fs_vnode vnode, int openMode, 144 fssh_fs_cookie *_cookie); 145 fssh_status_t (*close)(fssh_fs_volume fs, fssh_fs_vnode vnode, 146 fssh_fs_cookie cookie); 147 fssh_status_t (*free_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode, 148 fssh_fs_cookie cookie); 149 fssh_status_t (*read)(fssh_fs_volume fs, fssh_fs_vnode vnode, 150 fssh_fs_cookie cookie, fssh_off_t pos, void *buffer, 151 fssh_size_t *length); 152 fssh_status_t (*write)(fssh_fs_volume fs, fssh_fs_vnode vnode, 153 fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer, 154 fssh_size_t *length); 155 156 /* directory operations */ 157 fssh_status_t (*create_dir)(fssh_fs_volume fs, fssh_fs_vnode parent, 158 const char *name, int perms, fssh_vnode_id *_newVnodeID); 159 fssh_status_t (*remove_dir)(fssh_fs_volume fs, fssh_fs_vnode parent, 160 const char *name); 161 fssh_status_t (*open_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 162 fssh_fs_cookie *_cookie); 163 fssh_status_t (*close_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 164 fssh_fs_cookie cookie); 165 fssh_status_t (*free_dir_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode, 166 fssh_fs_cookie cookie); 167 fssh_status_t (*read_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 168 fssh_fs_cookie cookie, struct fssh_dirent *buffer, 169 fssh_size_t bufferSize, uint32_t *_num); 170 fssh_status_t (*rewind_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 171 fssh_fs_cookie cookie); 172 173 /* attribute directory operations */ 174 fssh_status_t (*open_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 175 fssh_fs_cookie *_cookie); 176 fssh_status_t (*close_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 177 fssh_fs_cookie cookie); 178 fssh_status_t (*free_attr_dir_cookie)(fssh_fs_volume fs, 179 fssh_fs_vnode vnode, fssh_fs_cookie cookie); 180 fssh_status_t (*read_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 181 fssh_fs_cookie cookie, struct fssh_dirent *buffer, 182 fssh_size_t bufferSize, uint32_t *_num); 183 fssh_status_t (*rewind_attr_dir)(fssh_fs_volume fs, fssh_fs_vnode vnode, 184 fssh_fs_cookie cookie); 185 186 /* attribute operations */ 187 fssh_status_t (*create_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode, 188 const char *name, uint32_t type, int openMode, 189 fssh_fs_cookie *_cookie); 190 fssh_status_t (*open_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode, 191 const char *name, int openMode, fssh_fs_cookie *_cookie); 192 fssh_status_t (*close_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode, 193 fssh_fs_cookie cookie); 194 fssh_status_t (*free_attr_cookie)(fssh_fs_volume fs, fssh_fs_vnode vnode, 195 fssh_fs_cookie cookie); 196 fssh_status_t (*read_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode, 197 fssh_fs_cookie cookie, fssh_off_t pos, void *buffer, 198 fssh_size_t *length); 199 fssh_status_t (*write_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode, 200 fssh_fs_cookie cookie, fssh_off_t pos, const void *buffer, 201 fssh_size_t *length); 202 203 fssh_status_t (*read_attr_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode, 204 fssh_fs_cookie cookie, struct fssh_stat *stat); 205 fssh_status_t (*write_attr_stat)(fssh_fs_volume fs, fssh_fs_vnode vnode, 206 fssh_fs_cookie cookie, const struct fssh_stat *stat, 207 int statMask); 208 fssh_status_t (*rename_attr)(fssh_fs_volume fs, fssh_fs_vnode fromVnode, 209 const char *fromName, fssh_fs_vnode toVnode, 210 const char *toName); 211 fssh_status_t (*remove_attr)(fssh_fs_volume fs, fssh_fs_vnode vnode, 212 const char *name); 213 214 /* index directory & index operations */ 215 fssh_status_t (*open_index_dir)(fssh_fs_volume fs, fssh_fs_cookie *cookie); 216 fssh_status_t (*close_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie); 217 fssh_status_t (*free_index_dir_cookie)(fssh_fs_volume fs, 218 fssh_fs_cookie cookie); 219 fssh_status_t (*read_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie, 220 struct fssh_dirent *buffer, fssh_size_t bufferSize, 221 uint32_t *_num); 222 fssh_status_t (*rewind_index_dir)(fssh_fs_volume fs, fssh_fs_cookie cookie); 223 224 fssh_status_t (*create_index)(fssh_fs_volume fs, const char *name, 225 uint32_t type, uint32_t flags); 226 fssh_status_t (*remove_index)(fssh_fs_volume fs, const char *name); 227 fssh_status_t (*read_index_stat)(fssh_fs_volume fs, const char *name, 228 struct fssh_stat *stat); 229 230 /* query operations */ 231 fssh_status_t (*open_query)(fssh_fs_volume fs, const char *query, 232 uint32_t flags, fssh_port_id port, uint32_t token, 233 fssh_fs_cookie *_cookie); 234 fssh_status_t (*close_query)(fssh_fs_volume fs, fssh_fs_cookie cookie); 235 fssh_status_t (*free_query_cookie)(fssh_fs_volume fs, 236 fssh_fs_cookie cookie); 237 fssh_status_t (*read_query)(fssh_fs_volume fs, fssh_fs_cookie cookie, 238 struct fssh_dirent *buffer, fssh_size_t bufferSize, 239 uint32_t *_num); 240 fssh_status_t (*rewind_query)(fssh_fs_volume fs, fssh_fs_cookie cookie); 241 242 /* capability querying (the device is read locked) */ 243 uint32_t (*get_supported_operations)(fssh_partition_data* partition, 244 uint32_t mask); 245 246 bool (*validate_resize)(fssh_partition_data *partition, fssh_off_t *size); 247 bool (*validate_move)(fssh_partition_data *partition, fssh_off_t *start); 248 bool (*validate_set_content_name)(fssh_partition_data *partition, 249 char *name); 250 bool (*validate_set_content_parameters)(fssh_partition_data *partition, 251 const char *parameters); 252 bool (*validate_initialize)(fssh_partition_data *partition, char *name, 253 const char *parameters); 254 255 /* shadow partition modification (device is write locked) */ 256 fssh_status_t (*shadow_changed)(fssh_partition_data *partition, 257 uint32_t operation); 258 259 /* writing (the device is NOT locked) */ 260 fssh_status_t (*defragment)(int fd, fssh_partition_id partition, 261 fssh_disk_job_id job); 262 fssh_status_t (*repair)(int fd, fssh_partition_id partition, bool checkOnly, 263 fssh_disk_job_id job); 264 fssh_status_t (*resize)(int fd, fssh_partition_id partition, 265 fssh_off_t size, fssh_disk_job_id job); 266 fssh_status_t (*move)(int fd, fssh_partition_id partition, 267 fssh_off_t offset, fssh_disk_job_id job); 268 fssh_status_t (*set_content_name)(int fd, fssh_partition_id partition, 269 const char *name, fssh_disk_job_id job); 270 fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition, 271 const char *parameters, fssh_disk_job_id job); 272 fssh_status_t (*initialize)(int fd, fssh_partition_id partition, 273 const char *name, const char *parameters, fssh_disk_job_id job); 274 } fssh_file_system_module_info; 275 276 277 /* file system add-ons only prototypes */ 278 extern fssh_status_t fssh_new_vnode(fssh_mount_id mountID, 279 fssh_vnode_id vnodeID, fssh_fs_vnode privateNode); 280 extern fssh_status_t fssh_publish_vnode(fssh_mount_id mountID, 281 fssh_vnode_id vnodeID, fssh_fs_vnode privateNode); 282 extern fssh_status_t fssh_get_vnode(fssh_mount_id mountID, 283 fssh_vnode_id vnodeID, fssh_fs_vnode *_privateNode); 284 extern fssh_status_t fssh_put_vnode(fssh_mount_id mountID, 285 fssh_vnode_id vnodeID); 286 extern fssh_status_t fssh_remove_vnode(fssh_mount_id mountID, 287 fssh_vnode_id vnodeID); 288 extern fssh_status_t fssh_unremove_vnode(fssh_mount_id mountID, 289 fssh_vnode_id vnodeID); 290 extern fssh_status_t fssh_get_vnode_removed(fssh_mount_id mountID, 291 fssh_vnode_id vnodeID, bool* removed); 292 293 extern fssh_status_t fssh_notify_entry_created(fssh_mount_id device, 294 fssh_vnode_id directory, const char *name, fssh_vnode_id node); 295 extern fssh_status_t fssh_notify_entry_removed(fssh_mount_id device, 296 fssh_vnode_id directory, const char *name, fssh_vnode_id node); 297 extern fssh_status_t fssh_notify_entry_moved(fssh_mount_id device, 298 fssh_vnode_id fromDirectory, const char *fromName, 299 fssh_vnode_id toDirectory, const char *toName, 300 fssh_vnode_id node); 301 extern fssh_status_t fssh_notify_stat_changed(fssh_mount_id device, 302 fssh_vnode_id node, uint32_t statFields); 303 extern fssh_status_t fssh_notify_attribute_changed(fssh_mount_id device, 304 fssh_vnode_id node, const char *attribute, int32_t cause); 305 306 extern fssh_status_t fssh_notify_query_entry_created(fssh_port_id port, 307 int32_t token, fssh_mount_id device, 308 fssh_vnode_id directory, const char *name, 309 fssh_vnode_id node); 310 extern fssh_status_t fssh_notify_query_entry_removed(fssh_port_id port, 311 int32_t token, fssh_mount_id device, 312 fssh_vnode_id directory, const char *name, 313 fssh_vnode_id node); 314 315 #ifdef __cplusplus 316 } 317 #endif 318 319 #endif /* _FSSH_FS_INTERFACE_H */ 320