1/* 2 * Copyright 2007-2008 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 * Niels Sascha Reedijk <niels.reedijk@gmail.com> 8 * Axel Dörfler <axeld@pinc-software.de> 9 * 10 * Corresponds to: 11 * /trunk/headers/os/drivers/fs_interface.h rev 21568 12 */ 13 14/*! 15 \file fs_interface.h 16 \ingroup drivers 17 \brief Provides an interface for file system modules. 18 19 See the \ref fs_modules "introduction to file system modules" for a guide on 20 how to get started with writing file system modules. 21*/ 22 23///// write_stat_mask ////// 24 25/*! 26 \enum write_stat_mask 27 \brief This mask is used in file_system_module_info::write_stat() to 28 determine which values need to be written. 29*/ 30 31/*! 32 \var write_stat_mask::FS_WRITE_STAT_MODE 33 \brief The mode parameter should be updated. 34*/ 35 36/*! 37 \var write_stat_mask::FS_WRITE_STAT_UID 38 \brief The UID field should be updated. 39*/ 40 41/*! 42 \var write_stat_mask::FS_WRITE_STAT_GID 43 \brief The GID field should be updated. 44*/ 45 46/*! 47 \var write_stat_mask::FS_WRITE_STAT_SIZE 48 \brief The size field should be updated. If the actual size is less than the 49 new provided file size, the file should be set to the new size and the 50 extra space should be filled with zeros. 51*/ 52 53/*! 54 \var write_stat_mask::FS_WRITE_STAT_ATIME 55 \brief The access time should be updated. 56*/ 57 58/*! 59 \var write_stat_mask::FS_WRITE_STAT_MTIME 60 \brief The 'last modified' field should be updated. 61*/ 62 63/*! 64 \var write_stat_mask::FS_WRITE_STAT_CRTIME 65 \brief The 'creation time' should be updated. 66*/ 67 68///// FS_WRITE_FSINFO_NAME ///// 69 70/*! 71 \def FS_WRITE_FSINFO_NAME 72 \brief Passed to file_system_module_info::write_fs_info(). 73*/ 74 75///// file_io_vec ///// 76 77/*! 78 \struct file_io_vec 79 \brief Structure that describes the io vector of a file. 80*/ 81 82/*! 83 \var off_t file_io_vec::offset 84 \brief The offset within the file. 85*/ 86 87/*! 88 \var off_t file_io_vec::length 89 \brief The length of the vector. 90*/ 91 92///// B_CURRENT_FS_API_VERSION ///// 93 94/*! 95 \def B_CURRENT_FS_API_VERSION 96 \brief Constant that defines the version of the file system API that your 97 filesystem conforms to. 98 99 The module name that exports the interface to your file system has to 100 end with this constant as in: 101 \code "file_systems/myfs" B_CURRENT_FS_API_VERSION \endcode 102*/ 103 104///// file_system_module_info ///// 105 106 107/*! 108 \struct file_system_module_info 109 \brief Kernel module interface for file systems. 110 111 See the \ref fs_modules "introduction to file system modules" for an 112 introduction to writing file systems. 113*/ 114 115/*! 116 \name Data members 117*/ 118 119//! @{ 120 121/*! 122 \var module_info file_system_module_info::info 123 \brief Your module_info object which is required for all modules. 124*/ 125 126/*! 127 \var const char *file_system_module_info::pretty_name 128 \brief A NULL-terminated string with a 'pretty' name for you file system. 129 130 Note, if a system wide disk device type constant exists for your file system, 131 it should equal this identifier. 132*/ 133 134//! @} 135 136/*! 137 \name Scanning 138*/ 139 140//! @{ 141 142/*! 143 \fn float (*file_system_module_info::identify_partition)(int fd, 144 partition_data *partition, void **cookie) 145 \brief Undocumented. TODO. 146*/ 147 148/*! 149 \fn status_t (*file_system_module_info::scan_partition)(int fd, 150 partition_data *partition, void *cookie) 151 \brief Undocumented. TODO. 152*/ 153 154/*! 155 \fn void (*file_system_module_info::free_identify_partition_cookie)( 156 partition_data *partition, void *cookie) 157 \brief Undocumented. TODO. 158*/ 159 160/*! 161 \fn void (*file_system_module_info::free_partition_content_cookie)( 162 partition_data *partition) 163 \brief Undocumented. TODO. 164*/ 165 166//! @} 167 168/*! 169 \name General Operations 170*/ 171 172//! @{ 173 174/*! 175 \fn status_t (*file_system_module_info::mount)(ino_t id, const char *device, 176 uint32 flags, const char *args, fs_volume *_fs, ino_t *_rootVnodeID) 177 \brief Mount a volume according to the specified parameters. 178 179 Invoked by the VFS when it has been requested to mount the volume. The FS is 180 supposed to perform whatever one-time initialization is necessary for the 181 volume. It is required to create a volume handle for the volume and pass it 182 back in \a _fs. Moreover it must invoke publish_vnode() for the root node 183 of the volume and pass the ID of the volume back in \a _rootVnodeID. 184 185 A disk-based FS will need to check whether \a device is not \c NULL, open 186 it, and analyze whether the device or image file actually represents a volume 187 of that FS type. 188 189 If mounting the volume fails for whatever reason, the hook must return an 190 error code other than \c B_OK. In this case all resources allocated by the 191 hook must be freed before returning. If and only if \c B_OK is returned, the 192 unmount() hook will be invoked at a later point when unmounting the volume. 193 194 \param id The ID of the volume to be mounted. It should be saved in the FS's 195 volume private data (volume handle). 196 \param device The path to the device (or image file) representing the volume 197 to be mounted. Can be \c NULL. 198 \param flags Flags: 199 - \c B_MOUNT_READ_ONLY: Mount the volume read-only. 200 \param args Null-terminated string in driver settings format, containing FS 201 specific parameters. 202 \param _fs Pointer to a pre-allocated variable the volume handle shall be 203 written to. 204 \param _rootVnodeID Pointer to a pre-allocated variable the ID of the 205 volume's root directory shall be written to. 206 \return \c B_OK if everything went fine, another error code otherwise. 207*/ 208 209/*! 210 \fn status_t (*file_system_module_info::unmount)(fs_volume fs) 211 \brief Unmounts the given volume. 212 213 Invoked by the VFS when it is asked to unmount the volume. The function must 214 free all resources associated with the mounted volume, including the volume 215 handle. Although the mount() hook called publish_vnode() for the root node 216 of the volume, unmount() must not invoke put_vnode(). 217 218 \param fs The volume handle. 219 \return \c B_OK if everything went fine, another error code otherwise. The 220 error code will be ignored, though. 221*/ 222 223/*! 224 \fn status_t (*file_system_module_info::read_fs_info)(fs_volume fs, 225 struct fs_info *info) 226 \brief Retrieves general information about the volume. 227 228 The following fields of the \c fs_info structure need to be filled in: 229 - \c flags: Flags applying to the volume, e.g. \c B_FS_IS_READONLY, 230 \c B_FS_HAS_ATTR, etc. 231 - \c block_size: The size of blocks the volume data are organized in. 232 Meaningful mainly for disk-based FSs, other FSs should use some reasonable 233 value for computing \c total_blocks and \c free_blocks. 234 - \c io_size: Preferred size of the buffers passed to read() and write(). 235 - \c total_blocks: Total number of blocks the volume contains. 236 - \c free_blocks: Number of free blocks on the volume. 237 - \c total_nodes: Maximal number of nodes the volume can contain. If there is 238 no such limitation use \c LONGLONG_MAX. 239 - \c free_nodes: Number of additional nodes the volume could contain. If 240 there is no such limitation use \c LONGLONG_MAX. 241 - \c device_name: The name of the device or image file containing the volume. 242 Non-disk-based FSs shall fill in an empty string. 243 - \c volume_name: The name of the volume. 244 245 The other values are filled in by the VFS. 246 247 \param fs The volume handle. 248 \param info Pointer to a pre-allocated variable the FS info shall be written 249 to. 250 \return \c B_OK if everything went fine, another error code otherwise. The 251 error code will be ignored, though. 252*/ 253 254/*! 255 \fn status_t (*file_system_module_info::write_fs_info)(fs_volume fs, 256 const struct fs_info *info, uint32 mask) 257 \brief Update filesystem information on the volume. 258 259 You are requested to update certain information on the volume \a fs. The 260 supplied \a info contains the new values filled in for the \a mask. 261 Currently, the only possible mask is solely the \c FS_WRITE_FSINFO_NAME, 262 which asks you to update the volume name represented by the value 263 \c volume_name in the \c fs_info struct. 264 265 \param fs The cookie your filesystem supplied to the volume that should be 266 updated. 267 \param info The structure that contains the new data. 268 \param mask The values of the \a info that need to be updated. 269 \return \c B_OK if everything went fine, if not, one of the error codes. 270*/ 271 272/*! 273 \fn status_t (*file_system_module_info::sync)(fs_volume fs) 274 \brief Synchronize the cached data with the contents of the disk. 275 276 The VFS layer sometimes wants you to synchronize any cached values with the 277 data on the device. 278 279 This currently only happens when the POSIX sync() function is invoked, for 280 example via the "sync" command line tool. 281 282 \param fs The cookie your filesystem supplied to the volume that should be 283 updated. 284*/ 285 286//! @} 287 288/*! 289 \name VNode Operations 290*/ 291 292//! @{ 293 294/*! 295 \fn status_t (*file_system_module_info::lookup)(fs_volume fs, fs_vnode dir, 296 const char *name, ino_t *_id, int *_type) 297 \brief Looks up the node a directory entry refers to. 298 299 The VFS uses this hook to resolve path names to vnodes. It is used quite 300 often and should be implemented efficiently. 301 302 If the parameter \a dir does not specify a directory, the function shall 303 fail. It shall also fail, if it is a directory, but does not contain an entry 304 with the given name \a name. Otherwise the function shall invoke get_vnode() 305 for the node the entry refers to and pass back the ID and the type of the 306 node in \a _id and \a _type respectively. 307 308 Note that a directory must contain the special entries \c "." and \c "..", 309 referring to the same directory and the parent directory respectively. 310 lookup() must resolve the nodes accordingly. \c ".." for the root directory 311 of the volume shall be resolved to the root directory itself. 312 313 \param fs The volume handle. 314 \param dir The node handle of the directory. 315 \param name The name of the directory entry. 316 \param _id Pointer to a pre-allocated variable the ID of the found node 317 shall be written to. 318 \param _type Pointer to a pre-allocated variable the type of the found node 319 shall be written to. The type is encoded as in the \c st_mode field of a 320 <tt>struct stat</tt> (bitwise anded with \c S_IFMT). 321 \retval B_OK Everything went fine. 322 \retval B_ENTRY_NOT_FOUND The given directory does not contain an entry with 323 the given name. 324*/ 325 326/*! 327 \fn status_t (*file_system_module_info::get_vnode_name)(fs_volume fs, 328 fs_vnode vnode, char *buffer, size_t bufferSize) 329 \brief Return the file name of a vnode. 330 331 Note that you don't have to implement this call if it can't be easily done; 332 it's completely optional. 333 If you don't implement it, you'll have to export a NULL pointer for this 334 function in the module definition. In this case, the VFS will find the name 335 by iterating over its parent directory. 336 337 \param fs The file system provided cookie associated with this volume. 338 \param vnode The file system provided cookie associated with this vnode. 339 \param buffer The buffer that the name can be copied into. 340 \param bufferSize The size of the buffer. 341 \retval B_OK You successfully copied the file name into the \a buffer. 342 \retval "other errors" There was some error looking up or copying the name. 343*/ 344 345/*! 346 \fn status_t (*file_system_module_info::get_vnode)(fs_volume fs, ino_t id, 347 fs_vnode *_vnode, bool reenter) 348 \brief Creates the private data handle to be associated with the node 349 referred to by \a id. 350 351 Invoked by the VFS when it creates the vnode for the respective node. 352 When the VFS no longer needs the vnode in memory (for example when 353 memory is becoming tight), it will your file_system_module_info::put_vnode(), 354 or file_system_module_info::remove_vnode() in case the vnode has been 355 marked removed. 356 357 \param fs The volume handle. 358 \param id The ID of the node. 359 \param _vnode Pointer to a pre-allocated variable the node handle shall be 360 written to. 361 \param reenter \c true if the hook invocation has been caused by the FS 362 itself, e.g. by invoking ::get_vnode(). 363 \return \c B_OK if everything went fine, another error code otherwise. 364*/ 365 366/*! 367 \fn \fn status_t (*file_system_module_info::put_vnode)(fs_volume fs, 368 fs_vnode vnode, bool reenter) 369 \brief Deletes the private data handle associated with the specified node. 370 371 Invoked by the VFS when it deletes the vnode for the respective node and the 372 node is not marked removed. 373 374 \param fs The volume handle. 375 \param vnode The node handle. 376 \param reenter \c true if the hook invocation has been caused by the FS 377 itself, e.g. by invoking ::put_vnode(). 378 \return \c B_OK if everything went fine, another error code otherwise. 379*/ 380 381/*! 382 \fn status_t (*file_system_module_info::remove_vnode)(fs_volume fs, 383 fs_vnode vnode, bool reenter) 384 \brief Deletes the private data handle associated with the specified node. 385 386 Invoked by the VFS when it deletes the vnode for the respective node and the 387 node has been marked removed by a call to remove_vnode(). 388 389 \param fs The volume handle. 390 \param vnode The node handle. 391 \param reenter \c true if the hook invocation has been caused by the FS 392 itself, e.g. by invoking ::put_vnode(). 393 \return \c B_OK if everything went fine, another error code otherwise. 394*/ 395 396//! @} 397 398/*! 399 \name VM file access 400*/ 401 402//! @{ 403 404/*! 405 \fn bool (*file_system_module_info::can_page)(fs_volume fs, fs_vnode vnode, 406 fs_cookie cookie) 407 \brief Undocumented. TODO. 408 409 TODO: In both the dos and the bfs implementations this thing simply returns 410 false... Is there anything more to it? 411 This call might be removed in the future - it's currently unused. 412*/ 413 414/*! 415 \fn status_t (*file_system_module_info::read_pages)(fs_volume fs, fs_vnode vnode, 416 fs_cookie cookie, off_t pos, const iovec *vecs, size_t count, 417 size_t *_numBytes, bool reenter) 418 \brief Undocumented. TODO. 419*/ 420 421/*! 422 \fn status_t (*file_system_module_info::write_pages)(fs_volume fs, fs_vnode vnode, 423 fs_cookie cookie, off_t pos, const iovec *vecs, size_t count, 424 size_t *_numBytes, bool reenter) 425 \brief Undocumented. TODO. 426*/ 427 428//! @} 429 430/*! 431 \name Cache File Access 432*/ 433 434//! @{ 435 436/*! 437 \fn status_t (*file_system_module_info::get_file_map)(fs_volume fs, 438 fs_vnode vnode, off_t offset, size_t size, struct file_io_vec *vecs, 439 size_t *_count) 440 \brief Fills the \a vecs with the extents of the file data stream. 441 442 This function is called only when you are using the file cache, but if you 443 use it, its implementation is mandatory. 444 445 TODO: complete me 446*/ 447 448//! @} 449 450/*! 451 \name Standard Operations 452*/ 453 454//! @{ 455 456/*! 457 \fn status_t (*file_system_module_info::ioctl)(fs_volume fs, fs_vnode vnode, 458 fs_cookie cookie, ulong op, void *buffer, size_t length) 459 \brief Perform file system specific operations. 460 461 You can implement a customized API using this call. This can be extremely 462 handy for debugging purposes. There are no obligatory operations for you to 463 implement. 464 465 If you don't want to use this feature, you don't have to implement it. 466 467 \param fs The file system provided cookie associated with this volume. 468 \param vnode The file system provided cookie associated with the vnode (if 469 applicable). 470 \param cookie The file system provided cookie associated with, for example, 471 an open file (if applicable). 472 \param op The operation code. You will have to define them yourself. 473 \param buffer A buffer (if applicable). 474 \param length The size of the buffer. 475 \return You should return any of your status codes. 476*/ 477 478/*! 479 \fn status_t (*file_system_module_info::set_flags)(fs_volume fs, 480 fs_vnode vnode, fs_cookie cookie, int flags) 481 \brief Set the open mode flags for an opened file. 482 483 This function should change the open flags for an opened file. 484 485 \param fs The file system provided cookie associated with this volume. 486 \param vnode The file system provided cookie associated with the vnode. 487 \param cookie The file system provided cookie associated with the opened 488 file. 489 \param flags The new flags. 490 \return \c B_OK if the operation succeeded, or else an error code. 491*/ 492 493/*! 494 \fn status_t (*file_system_module_info::select)(fs_volume fs, fs_vnode vnode, 495 fs_cookie cookie, uint8 event, uint32 ref, selectsync *sync) 496 \brief Selects the specified \a vnode with the specified \a events. 497 498 This function is called by the VFS whenever select() or poll() is called on 499 a file descriptor that points to your file system. 500 501 You have to check if the condition of the select() (ie. if there is data 502 available if event is B_SELECT_READ) is already satisfied, and call 503 notify_select_event() with the \a sync and \a ref arguments you retrieve 504 here. 505 506 Additionally, when a vnode is selected this way, you have to call 507 notify_select_event() whenever the condition becomes true until the 508 vnode is deselected again via file_system_module_info::deselect(). 509 510 This function is optional. If you don't export it, the default implementation 511 in the VFS will call notify_select_event() directly which will be sufficient 512 for most file systems. 513 514 Note that while select() and the corresponding deselect() are invoked by the 515 same thread, notifications are usually generated by other threads. It is 516 your responsibility to make sure that notify_select_event() is never called 517 for a selectsync object for which deselect() has already returned. This is 518 commonly done by holding the same lock when invoking notify_select_event() 519 and when removing the selectsync object from the cookie in deselect(). 520 Such a lock can be any lock, usually one that is associated with the node or 521 the volume. 522*/ 523 524/*! 525 \fn status_t (*file_system_module_info::deselect)(fs_volume fs, fs_vnode vnode, 526 fs_cookie cookie, uint8 event, selectsync *sync) 527 \brief Deselects the specified \a vnode from a previous select() call. 528 529 This function is called by the VFS whenever a select() or poll() function 530 exits that previously called file_system_module_info::select() on that 531 \a vnode. 532*/ 533 534/*! 535 \fn status_t (*file_system_module_info::fsync)(fs_volume fs, fs_vnode vnode) 536 \brief Synchronize the buffers with the on disk data. 537 538 \param fs The file system provided cookie associated with this volume. 539 \param vnode The file system provided cookie associated with the vnode. 540 \return \c B_OK if the operation succeeded, or else an error code. 541*/ 542 543/*! 544 \fn status_t (*file_system_module_info::read_symlink)(fs_volume fs, 545 fs_vnode link, char *buffer, size_t *_bufferSize) 546 \brief Read the value of a symbolic link. 547 548 If the function is successful, the symlink string shall be written to the 549 buffer. It does not need to be null-terminated. If the buffer is too small 550 to hold the complete string, only the first \c *_bufferSize bytes of the 551 string shall be written to the buffer; the buffer shall not be 552 null-terminated in this case. Furthermore the variable \a _bufferSize 553 points to shall be set to the length of the string written to the buffer, 554 not including any terminating null character (if written). 555 556 \param fs The volume handle. 557 \param link The node handle. 558 \param buffer Pointer to a pre-allocated buffer the link value shall be 559 written to. 560 \param _bufferSize Pointer to a pre-allocated variable containing the size 561 of the buffer supplied to the function. Upon successful completion the 562 hook shall store the number of bytes actually written into the buffer 563 in the variable. 564 \retval B_OK Everything went fine. 565 \retval B_BAD_VALUE \a link does not identify a symbolic link. 566*/ 567 568/*! 569 \fn status_t (*file_system_module_info::create_symlink)(fs_volume fs, 570 fs_vnode dir, const char *name, const char *path, int mode) 571 \brief Create a new symbolic link. 572 573 Your implementation should check if the user has permission to perform this 574 operation. 575 576 \param fs The file system provided cookie associated with this volume. 577 \param dir The file system provided cookie associated with the directory 578 the symbolic link should be created in. 579 \param name The name of the new symbolic link. 580 \param path The path of the original inode the symbolic link should refer to. 581 \param mode The mode that this symbolic link should be created in. (TODO 582 what exactly?) 583 \return \c B_OK if you succeeded, or an error code if you failed. 584*/ 585 586/*! 587 \fn status_t (*file_system_module_info::link)(fs_volume fs, fs_vnode dir, 588 const char *name, fs_vnode vnode) 589 \brief Create a new hard link. 590 591 You should make sure the user has the proper permissions. 592 593 The virtual file system will request the creation of symbolic links with 594 create_symlink(). 595 596 If you don't implement this function, the VFS will return \c EROFS 597 when a hard link is requested. 598 599 \param fs The file system provided cookie associated with this volume. 600 \param dir The cookie associated to the directory where the link should be 601 saved. 602 \param name The name the link should have. 603 \param vnode The vnode the new link should resolve to. 604 \retval B_OK The hard link is properly created. 605 \retval B_NOT_ALLOWED The user does not have the proper permissions. 606 \retval "other errors" Another error occured. 607*/ 608 609/*! 610 \fn status_t (*file_system_module_info::unlink)(fs_volume fs, fs_vnode dir, 611 const char *name) 612 \brief Remove a node or directory. 613 614 You should make sure the user has the proper permissions. 615 616 \param fs The file system provided cookie associated with this volume. 617 \param dir The parent directory of the node that should be removed. 618 \param name The name of the node that should be deleted. 619 \retval B_OK Removal succeeded. 620 \retval B_ENTRY_NOT_FOUND The entry does not exist. 621 \retval B_NOT_ALLOWED The user does not have the proper permissions. 622 \retval B_DIRECTORY_NOT_EMPTY The \a name refers to a directory. The virtual 623 file system expects directories to be emptied before they can be unlinked. 624 \retval "other errors" Another error occured. 625*/ 626 627/*! 628 \fn status_t (*file_system_module_info::rename)(fs_volume fs, 629 fs_vnode fromDir, const char *fromName, fs_vnode toDir, 630 const char *toName) 631 \brief Rename and/or relocate a vnode. 632 633 The virtual file system merely relays the request, so make sure the user is 634 not changing the file name to something like '.', '..' or anything starting 635 with '/'. 636 637 This also means that it if the node is a directory, that it should not be 638 moved into one of its own children. 639 640 You should also make sure the user has the proper permissions. 641 642 \param fs The file system provided cookie associated with this volume. 643 \param fromDir The cookie of the parent directory the vnode should be moved 644 from. 645 \param fromName The old name of the node. 646 \param toDir The cookie of the parent directory the vnode should be moved to. 647 \param toName The new name of the node. 648 \retval B_OK The renaming and relocating succeeded. 649 \retval B_BAD_VALUE One of the supplied parameters were invalid. 650 \retval B_NOT_ALLOWED The user does not have the proper permissions. 651 \retval "other errors" Another error condition was encountered. 652*/ 653 654/*! 655 \fn status_t (*file_system_module_info::access)(fs_volume fs, fs_vnode vnode, 656 int mode) 657 \brief Checks whether the current user is allowed to access the node in the 658 specified way. 659 660 \a mode is a bitwise combination of: 661 - \c R_OK: Read access. 662 - \c W_OK: Write access. 663 - \c X_OK: Execution. 664 665 If the current user does not have any of the access permissions represented 666 by the set bits, the function shall return \c B_NOT_ALLOWED. As a special 667 case, if the volume is read-only and write access is requested, 668 \c B_READ_ONLY_DEVICE shall be returned. If the requested access mode 669 complies with the user's access permissions, the function shall return 670 \c B_OK. 671 672 For most FSs the permissions a user has are defined by the \c st_mode, 673 \c st_uid, and \c st_gid fields of the node's stat data. As a special 674 exception, the root user (<tt>geteuid() == 0</tt>) does always have 675 read and write permissions, execution permission only when at least one of 676 the execution permission bits are set. 677 678 \param fs The volume handle. 679 \param vnode The node handle. 680 \param mode The access mode mask. 681 \retval B_OK The user has the permissions to access the node in the requested 682 way. 683 \retval B_READ_ONLY_DEVICE The volume is read-only, but the write access has 684 been requested. 685 \retval B_NOT_ALLOWED The user does not have all permissions to access the 686 node in the requested way. 687*/ 688 689/*! 690 \fn status_t (*file_system_module_info::read_stat)(fs_volume fs, 691 fs_vnode vnode, struct stat *stat) 692 \brief Retrieves the stat data for a given node. 693 694 All values of the <tt>struct stat</tt> save \c st_dev, \c st_ino, \c st_rdev, 695 and \c st_type need to be filled in. 696 697 \param fs The volume handle. 698 \param vnode The node handle. 699 \param stat Pointer to a pre-allocated variable the stat data shall be 700 written to. 701 \return \c B_OK if everything went fine, another error code otherwise. 702*/ 703 704/*! 705 \fn status_t (*file_system_module_info::write_stat)(fs_volume fs, 706 fs_vnode vnode, const struct stat *stat, uint32 statMask) 707 \brief Update the stats for a vnode. 708 709 You should make sure that the new values are valid and that the user has the 710 proper permissions to update the stats. 711 712 \param fs The file system provided cookie to the volume. 713 \param vnode The cookie to the vnode. 714 \param stat The structure with the updated values. 715 \param statMask One of the #write_stat_mask enumeration, which forms a mask 716 of which of the values in \a stat should actually be updated. 717 \retval B_OK The update succeeded. 718 \retval B_NOT_ALLOWED The user does not have the proper permissions. 719 \retval "other errors" Another error condition occured. 720*/ 721 722//! @} 723 724/*! 725 \name File Operations 726*/ 727 728//! @{ 729 730/*! 731 \fn status_t (*file_system_module_info::create)(fs_volume fs, fs_vnode dir, 732 const char *name, int openMode, int perms, fs_cookie *_cookie, 733 ino_t *_newVnodeID) 734 \brief Create a new file. 735 736 Your implementation shall check whether it is possible to create the node. 737 You will need to take the user's permissions into account. When you create 738 a new file, you will also have to open it. This means also checking the 739 permissions the user requires to open the file according to the \a mode. 740 See \link file_system_module_info::open() open() \endlink for the possible 741 values of \a mode. 742 743 \param fs The file system provided cookie associated with this volume. 744 \param dir The file system provided cookie associated with the directory 745 where the file should appear. 746 \param name The name of the new file. 747 \param openMode The mode associated to the file. 748 \param perms The permissions the new file should have. 749 \param[out] _cookie In case of success, the you can store your file system 750 data for this node in this variable. 751 \param[out] _newVnodeID In case of success, you can store the new vnode id 752 in this variable. 753 \return You should return \c B_OK if creating the new node succeeded, and if 754 you put data in both \a _cookie and \a _newVnodeID. Else you should return 755 an error code. 756*/ 757 758/*! 759 \fn status_t (*file_system_module_info::open)(fs_volume fs, fs_vnode vnode, 760 int openMode, fs_cookie *_cookie) 761 \brief Opens the given node. 762 763 The function shall check whether it is possible to open the node according to 764 the mode specified by \c openMode (also considering the user's access 765 permissions), create a node cookie, and store it in the variable 766 \a _cookie points to. 767 768 The open mode \a openMode is encoded in the same way as the parameter of the 769 POSIX function \c open(), i.e. it is either \c O_RDONLY, \c O_WRONLY, or 770 \c O_RDWR, bitwise or'ed with flags. The only relevant flags for this hook 771 are \c O_TRUNC and \c O_NONBLOCK. 772 773 \param fs The volume handle. 774 \param vnode The node handle. 775 \param openMode The open mode. 776 \param _cookie Pointer to a pre-allocated variable the node cookie shall be 777 written to. 778 \return \c B_OK if everything went fine, another error code otherwise. 779*/ 780 781/*! 782 \fn status_t (*file_system_module_info::close)(fs_volume fs, fs_vnode vnode, 783 fs_cookie cookie) 784 \brief Closes the given node cookie. 785 786 The hook is invoked, when closing the node has been requested. At this point 787 other threads might still use the cookie, i.e. still execute hooks to which 788 the cookie has been passed. If the FS supports blocking I/O operations, this 789 hook should make sure to unblock all currently blocking threads performing 790 an operation using the cookie, and mark the cookie such that no further 791 threads will block using it. 792 793 For many FSs this hook is a no-op - it's mandatory to be exported, though. 794 795 \param fs The volume handle. 796 \param vnode The node handle. 797 \param cookie The node cookie as returned by open(). 798 \return \c B_OK if everything went fine, another error code otherwise. 799*/ 800 801/*! 802 \fn status_t (*file_system_module_info::free_cookie)(fs_volume fs, 803 fs_vnode vnode, fs_cookie cookie) 804 \brief Frees the given node cookie. 805 806 The hook is invoked after close(), when no other thread uses or is going to 807 use the cookie. All resources associated with the cookie must be freed. 808 809 \param fs The volume handle. 810 \param vnode The node handle. 811 \param cookie The node cookie as returned by open(). 812 \return \c B_OK if everything went fine, another error code otherwise. 813*/ 814 815/*! 816 \fn status_t (*file_system_module_info::read)(fs_volume fs, fs_vnode vnode, 817 fs_cookie cookie, off_t pos, void *buffer, size_t *length) 818 \brief Reads data from a file. 819 820 This function should fail if 821 - the node is not a file, 822 - the cookie has not been opened for reading, 823 - \a pos is negative, or 824 - some other error occurs while trying to read the data, and no data have 825 been read at all. 826 827 The number of bytes to be read is stored in the variable pointed to by 828 \a length. If less data is available at file position \a pos, or if \a pos 829 if greater than the size of the file, only as many data as available shall 830 be read, the function shall store the number of bytes actually read into the 831 variable pointed to by \a length, and return \c B_OK. 832 833 \param fs The volume handle. 834 \param vnode The node handle. 835 \param cookie The node cookie as returned by open(). 836 \param pos The file position where to start reading data. 837 \param buffer Pointer to a pre-allocated buffer the read data shall be 838 written to. 839 \param length Pointer to a pre-allocated variable containing the size of the 840 buffer when invoked, and into which the size of the data actually read 841 shall be written. 842 \return \c B_OK if everything went fine, another error code otherwise. 843*/ 844 845/*! 846 \fn status_t (*file_system_module_info::write)(fs_volume fs, fs_vnode vnode, 847 fs_cookie cookie, off_t pos, const void *buffer, size_t *length) 848 \brief Write data to a file. 849 850 This function should fail if 851 - the node is not a file, 852 - the cookie has not been opened for writing, 853 - \a pos is negative, or 854 - some other error occurs while trying to read the data, and no data have 855 been read at all. 856 857 The number of bytes to be written is stored in the variable pointed to by 858 \a length. If not all bytes could be written, that variable must be updated 859 to reflect the amount of actually written bytes. If an error prevented 860 you from writing the full amount, an appropriate error code should be 861 returned. 862 863 \param fs The file system provided cookie associated with this volume. 864 \param vnode The file system provided cookie associated with the vnode. 865 \param cookie The file system provided cookie associated with the file. 866 \param pos The position to start writing. 867 \param buffer The buffer that contains the data that will need to be written. 868 \param length The length of the data that needs to be written. 869 \return \c B_OK if everything went fine, another error code otherwise. 870*/ 871 872//! @} 873 874/*! 875 \name Directory Operations 876*/ 877 878/*! 879 \fn status_t (*file_system_module_info::create_dir)(fs_volume fs, fs_vnode 880 parent, const char *name, int perms, ino_t *_newVnodeID) 881 \brief Create a new directory. 882 883 Your implementation should make sure that the directory actually can be 884 created in the \a parent directory. You will have to check if the user has 885 permissions to actually write to the \a parent. If not, this function should 886 fail (probably with \c B_NOT_ALLOWED, or in case of a read-only filesystem, 887 with \c B_READ_ONLY_DEVICE). If the operation succeeds, you should put the 888 new vnode id in \a _newVnodeID. 889 890 \param fs The file system provided cookie associated with this volume. 891 \param parent The file system provided cookie associated with the parent 892 node. 893 \param name The name the new directory should have. 894 \param perms The permissions the new directory should have. 895 \param[out] _newVnodeID If creating the directory succeeds, than you should 896 put the new vnode id in this variable. 897 \return If the operation succeeds and the \a _newVnodeID is populated with 898 the new vnode, then you should return \c B_OK. Else you should return with 899 an error code. 900*/ 901 902/*! 903 \fn status_t (*file_system_module_info::remove_dir)(fs_volume fs, fs_vnode 904 parent, const char *name) 905 \brief Remove a directory. 906 907 You should make sure the user has the proper permissions. You should also 908 check that the directory is empty. 909 910 \param fs The file system provided cookie associated with this volume. 911 \param parent The file system provided cookie associated with the parent 912 node. 913 \param name The \a name of the directory that needs to be removed. 914 \retval B_OK Operation succeeded. 915 \retval B_DIRECTORY_NOT_EMPTY The directory is not empty. 916 \retval B_ENTRY_NOT_FOUND There is no directory with this \a name. 917 \retval B_NOT_A_DIRECTORY The entry is not a directory. 918 \retval "other errors" Other errors occured. 919*/ 920 921/*! 922 \fn status_t (*file_system_module_info::open_dir)(fs_volume fs, fs_vnode vnode, 923 fs_cookie *_cookie) 924 \brief Opens the given directory node. 925 926 If the specified node is not a directory, or if the current user does not 927 have the permissions to read the directory, the function shall fail. 928 Otherwise it shall allocate a directory cookie and store it in the variable 929 \a _cookie points to. A subsequent read_dir() using the cookie shall start 930 reading the first entry of the directory. 931 932 \param fs The volume handle. 933 \param vnode The node handle. 934 \param _cookie Pointer to a pre-allocated variable the directory cookie shall 935 be written to. 936 \return \c B_OK if everything went fine, another error code otherwise. 937*/ 938 939/*! 940 \fn status_t (*file_system_module_info::close_dir)(fs_volume fs, 941 fs_vnode vnode, fs_cookie cookie) 942 \brief Closes the given directory cookie. 943 944 Generally the situation is similar to the one described for close(). In 945 practice it is a bit, though, since directory cookies are exclusively used 946 for directory iteration, and it normally doesn't make sense to have multiple 947 threads read the same directory concurrently. Furthermore reading a directory 948 should not block. Therefore for most FSs this hook is a no-op. 949 950 \param fs The volume handle. 951 \param vnode The node handle. 952 \param cookie The directory cookie as returned by open_dir(). 953 \return \c B_OK if everything went fine, another error code otherwise. 954*/ 955 956/*! 957 \fn status_t (*file_system_module_info::free_dir_cookie)(fs_volume fs, 958 fs_vnode vnode, fs_cookie cookie) 959 \brief Frees the given directory cookie. 960 961 The hook is invoked after close_dir(), when no other thread uses or is going 962 to use the cookie. All resources associated with the cookie must be freed. 963 964 \param fs The volume handle. 965 \param vnode The node handle. 966 \param cookie The directory cookie as returned by open_dir(). 967 \return \c B_OK if everything went fine, another error code otherwise. 968*/ 969 970/*! 971 \fn status_t (*file_system_module_info::read_dir)(fs_volume fs, fs_vnode vnode, 972 fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num) 973 \brief Reads the next one or more directory entries. 974 975 The number of entries to be read at maximum is stored in the variable \a _num 976 points to. 977 978 Per read \c dirent the following fields have to be filled in: 979 - \c d_dev: The volume ID. 980 - \c d_ino: The ID of the node the entry refers to. 981 - \c d_name: The null-terminated name of the entry. 982 - \c d_reclen: The size of the \c dirent structure in bytes, starting from 983 the beginning of the structure, counting all bytes up to and including 984 the null-termination char of the name stored in \c d_name. 985 986 If more than one entry is read, the corresponding \c dirent structures are 987 tightly packed, i.e. the second entry begins directly after the end of the 988 first one (i.e. \c d_reclen bytes after the beginning of the first one). 989 Most FSs read only one entry at a time though, even if more are requested. 990 991 When the function is invoked after the end of the directory has been reached, 992 it shall set the variable \a _num points to to \c 0 and return \c B_OK. If 993 the provided buffer is too small to contain even the single next entry, 994 \c B_BUFFER_OVERFLOW shall be returned. It shall not fail, if at least one 995 entry has been read, and the buffer is just too small to hold as many entries 996 as requested. 997 998 Note that a directory is expected to contain the special entries \c "." and 999 \c "..", referring to the same directory and the parent directory 1000 respectively. The \c dirent structure returned for the \c ".." entry of the 1001 volume's root directory shall refer to the root node itself. 1002 1003 \param fs The volume handle. 1004 \param vnode The node handle. 1005 \param cookie The directory cookie as returned by open_dir(). 1006 \param buffer Pointer to a pre-allocated buffer the directory entries shall 1007 be written to. 1008 \param bufferSize The size of \a buffer in bytes. 1009 \param _num Pointer to a pre-allocated variable, when invoked, containing the 1010 number of directory entries to be read, and into which the number of 1011 entries actually read shall be written. 1012 \return \c B_OK if everything went fine, another error code otherwise. 1013*/ 1014 1015/*! 1016 \fn status_t (*file_system_module_info::rewind_dir)(fs_volume fs, 1017 fs_vnode vnode, fs_cookie cookie) 1018 \brief Resets the directory cookie to the first entry of the directory. 1019 \param fs The volume handle. 1020 \param vnode The node handle. 1021 \param cookie The directory cookie as returned by open_dir(). 1022 \return \c B_OK if everything went fine, another error code otherwise. 1023*/ 1024 1025//! @} 1026 1027/*! 1028 \name Attribute Directory Operations 1029*/ 1030 1031//! @{ 1032 1033/*! 1034 \fn status_t (*file_system_module_info::open_attr_dir)(fs_volume fs, fs_vnode 1035 vnode, fs_cookie *_cookie) 1036 \brief Open a 'directory' of attributes for a \a vnode. 1037 1038 See \ref concepts "Generic Concepts" on directories and iterators. Basically, 1039 the VFS uses the same way of traversing through attributes as it traverses 1040 through a directory. 1041 1042 \param fs The file system provided cookie to the volume. 1043 \param vnode The vnode on which the file system wants to read the attributes. 1044 \param[out] _cookie Pointer where the file system can store a directory 1045 cookie if the attribute directory is succesfully opened. 1046 \return \c B_OK if everything went fine, another error code otherwise. 1047*/ 1048 1049/*! 1050 \fn status_t (*file_system_module_info::close_attr_dir)(fs_volume fs, 1051 fs_vnode vnode, fs_cookie cookie) 1052 \brief Close a 'directory' of attributes for a \a vnode. 1053 1054 Note that you should free the cookie in the free_attr_dir_cookie() call. 1055 1056 \param fs The file system provided cookie to the volume. 1057 \param vnode The vnode on which the 'directory' was opened. 1058 \param cookie The cookie associated with this 'directory'. 1059 \return \c B_OK if everything went fine, another error code otherwise. 1060*/ 1061 1062/*! 1063 \fn status_t (*file_system_module_info::free_attr_dir_cookie)(fs_volume fs, 1064 fs_vnode vnode, fs_cookie cookie) 1065 \brief Free the \a cookie to an attribute 'directory'. 1066 1067 \param fs The file system provided cookie to the volume. 1068 \param vnode The vnode on which the 'directory' was opened. 1069 \param cookie The cookie associated that should be freed. 1070 \return \c B_OK if everything went fine, another error code otherwise. 1071*/ 1072 1073/*! 1074 \fn status_t (*file_system_module_info::read_attr_dir)(fs_volume fs, fs_vnode 1075 vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, 1076 uint32 *_num) 1077 \brief Read the next one or more attribute directory entries. 1078 1079 This method should perform the same tasks as read_dir(), except that the '.' 1080 and '..' entries do not have to be present. 1081*/ 1082 1083/*! 1084 \fn status_t (*file_system_module_info::rewind_attr_dir)(fs_volume fs, 1085 fs_vnode vnode, fs_cookie cookie) 1086 \brief Rewind the attribute directory iterator to the first entry. 1087 1088 \param fs The file system provided cookie to the volume. 1089 \param vnode The vnode on which the 'directory' was opened. 1090 \param cookie The cookie associated with this 'directory'. 1091 \return \c B_OK if everything went fine, another error code otherwise. 1092*/ 1093 1094//! @} 1095 1096/*! 1097 \name Attribute Operations 1098*/ 1099 1100//! @{ 1101 1102/*! 1103 \fn status_t (*file_system_module_info::create_attr)(fs_volume fs, fs_vnode 1104 vnode, const char *name, uint32 type, int openMode, fs_cookie *_cookie) 1105 \brief Create a new attribute. 1106 1107 If the attribute already exists, you should open it in truncated mode. 1108 1109 \param fs The file system provided cookie to the volume. 1110 \param vnode The file system provided cookie to the vnode. 1111 \param name The name of the attribute. 1112 \param type The \c type_code of the attribute. 1113 \param openMode The openMode of the associated attribute. 1114 \param[out] _cookie A pointer where you can store an associated file system 1115 cookie. 1116 \return \c B_OK if everything went fine, another error code otherwise. 1117*/ 1118 1119/*! 1120 \fn status_t (*file_system_module_info::open_attr)(fs_volume fs, fs_vnode 1121 vnode, const char *name, int openMode, fs_cookie *_cookie) 1122 \brief Open an existing attribute. 1123 1124 \param fs The file system provided cookie to the volume. 1125 \param vnode The file system provided cookie to the vnode. 1126 \param name The name of the attribute. 1127 \param openMode The mode in which you want to open the attribute data. 1128 \param[out] _cookie A pointer where you can store an associated file system 1129 cookie. 1130 \return \c B_OK if everything went fine, another error code otherwise. 1131*/ 1132 1133/*! 1134 \fn status_t (*file_system_module_info::close_attr)(fs_volume fs, fs_vnode 1135 vnode, fs_cookie cookie) 1136 \brief Close access to an attribute. 1137 1138 Note that you should not delete the cookie yet, you should do that when the 1139 VFS calls free_attr_cookie(). 1140 1141 \param fs The file system provided cookie to the volume. 1142 \param vnode The file system provided cookie to the vnode. 1143 \param cookie The cookie you associated to this attribute. 1144 \return \c B_OK if everything went fine, another error code otherwise. 1145*/ 1146 1147/*! 1148 \fn status_t (*file_system_module_info::free_attr_cookie)(fs_volume fs, 1149 fs_vnode vnode, fs_cookie cookie) 1150 \brief Free the cookie of an attribute. 1151 1152 The VFS calls this hook when all operations on the attribute have ceased. 1153 1154 \param fs The file system provided cookie to the volume. 1155 \param vnode The file system provided cookie to the vnode. 1156 \param cookie The cookie to the attribute that should be freed. 1157 \return \c B_OK if everything went fine, another error code otherwise. 1158*/ 1159 1160/*! 1161 \fn status_t (*file_system_module_info::read_attr)(fs_volume fs, fs_vnode 1162 vnode, fs_cookie cookie, off_t pos, void *buffer, size_t *length) 1163 \brief Read attribute data associated with \a cookie. 1164 1165 Read until the \a buffer with size \a length is full, or until you are out of 1166 data, in which case you should update \a length. 1167 1168 \param fs The file system provided cookie to the volume. 1169 \param vnode The file system provided cookie to the vnode. 1170 \param cookie The cookie you associated to this attribute. 1171 \param pos The position to start reading from. 1172 \param buffer The buffer the data should be copied in. 1173 \param length The length of the buffer. Update this variable to the actual 1174 amount of bytes read. 1175 \return \c B_OK if everything went fine, another error code otherwise. 1176*/ 1177 1178/*! 1179 \fn status_t (*file_system_module_info::write_attr)(fs_volume fs, fs_vnode 1180 vnode, fs_cookie cookie, off_t pos, const void *buffer, size_t *length) 1181 \brief Write attribute data associated with \a cookie. 1182 1183 \param fs The file system provided cookie to the volume. 1184 \param vnode The file system provided cookie to the vnode. 1185 \param cookie The cookie you associated with this attribute. 1186 \param pos The position to start writing to. 1187 \param buffer The buffer the data should be copied from. 1188 \param length The size of the buffer. Update this variable to the actual 1189 amount of bytes written. 1190 \return \c B_OK if everything went fine, another error code otherwise. 1191*/ 1192 1193/*! 1194 \fn status_t (*file_system_module_info::read_attr_stat)(fs_volume fs, 1195 fs_vnode vnode, fs_cookie cookie, struct stat *stat) 1196 \brief Get the stats for an attribute. 1197 1198 \param fs The file system provided cookie to the volume. 1199 \param vnode The file system provided cookie to the vnode. 1200 \param cookie The cookie you associated with this attribute. 1201 \param stat A pointer to a stat structure you should fill. 1202 \return \c B_OK if everything went fine, another error code otherwise. 1203*/ 1204 1205/*! 1206 \fn status_t (*file_system_module_info::write_attr_stat)(fs_volume fs, 1207 fs_vnode vnode, fs_cookie cookie, const struct stat *stat, int statMask) 1208 \brief Update the stats of an attribute. 1209 1210 \param fs The file system provided cookie to the volume. 1211 \param vnode The file system provided cookie to the vnode. 1212 \param cookie The cookie you associated with this attribute. 1213 \param stat A pointer to the new stats you should write. 1214 \param statMask One or more of the values of #write_stat_mask that tell you 1215 which fields of \a stat are to be updated. 1216 \return \c B_OK if everything went fine, another error code otherwise. 1217*/ 1218 1219/*! 1220 \fn status_t (*file_system_module_info::rename_attr)(fs_volume fs, 1221 fs_vnode fromVnode, const char *fromName, fs_vnode toVnode, 1222 const char *toName) 1223 \brief Rename and/or relocate an attribute. 1224 1225 You should make sure the user has the proper permissions. 1226 1227 \param fs The file system provided cookie associated with this volume. 1228 \param fromVnode The cookie associated with the vnode the attribute currently 1229 is related to. 1230 \param fromName The old name of the attribute. 1231 \param toVnode The cookie associated with the vnode the attribute should be 1232 moved to. This can be the same as \a fromVnode, in which case it only means 1233 the attribute should be renamed. 1234 \param toName The new name of the attribute.This can be the same as 1235 \a fromName, in which case it only means the attribute should be relocated. 1236 \retval B_OK The renaming and/or relocating succeeded. 1237 \retval B_BAD_VALUE One of the supplied parameters were invalid. 1238 \retval B_NOT_ALLOWED The user does not have the proper permissions. 1239 \retval "other errors" Another error condition was encountered. 1240*/ 1241 1242/*! 1243 \fn status_t (*file_system_module_info::remove_attr)(fs_volume fs, 1244 fs_vnode vnode, const char *name) 1245 \brief Remove an attribute. 1246 1247 \param fs The file system provided cookie to the volume. 1248 \param vnode The file system provided cookie to the vnode. 1249 \param name The name of the attribute. 1250 \return \c B_OK if everything went fine, another error code otherwise. 1251*/ 1252 1253//! @} 1254 1255/*! 1256 \name Index Directory and Operation 1257*/ 1258 1259//! @{ 1260 1261/*! 1262 \fn status_t (*file_system_module_info::open_index_dir)(fs_volume fs, 1263 fs_cookie *_cookie) 1264 \brief Open the list of an indeces as a directory. 1265 1266 See \ref concepts "Generic Concepts" on directories and iterators. Basically, 1267 the VFS uses the same way of traversing through indeces as it traverses 1268 through a directory. 1269 1270 \param fs The file system provided cookie to the volume. 1271 \param[out] _cookie Pointer where the file system can store a directory 1272 cookie if the index directory is succesfully opened. 1273 \return \c B_OK if everything went fine, another error code otherwise. 1274*/ 1275 1276/*! 1277 \fn status_t (*file_system_module_info::close_index_dir)(fs_volume fs, 1278 fs_cookie cookie) 1279 \brief Close a 'directory' of indeces. 1280 1281 Note that you should free the cookie in the free_index_dir_cookie() call.: 1282 1283 \param fs The file system provided cookie to the volume. 1284 \param cookie The cookie associated with this 'directory'. 1285 \return B_OK if everything went fine, another error code otherwise. 1286*/ 1287 1288/*! 1289 \fn status_t (*file_system_module_info::free_index_dir_cookie)(fs_volume fs, 1290 fs_cookie cookie) 1291 \brief Free the \a cookie to the index 'directory'. 1292 1293 \param fs The file system provided cookie for the volume. 1294 \param cookie The cookie that should be freed. 1295 \return B_OK if everything went fine, another error code otherwise. 1296*/ 1297 1298/*! 1299 \fn status_t (*file_system_module_info::read_index_dir)(fs_volume fs, 1300 fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num) 1301 \brief Read the next one or more index entries. 1302 1303 This method should perform the same task as read_dir(), except that the '.' 1304 and the '..' entries don't have to be present. 1305*/ 1306 1307/*! 1308 \fn status_t (*file_system_module_info::rewind_index_dir)(fs_volume fs, 1309 fs_cookie cookie) 1310 \brief Reset the index directory cookie to the first entry of the directory. 1311 1312 \param fs The file system provided handle to the volume. 1313 \param cookie The directory cookie as returned by open_index_dir(). 1314 \return \c B_OK if everything went fine, another error code otherwise. 1315*/ 1316 1317/*! 1318 \fn status_t (*file_system_module_info::create_index)(fs_volume fs, 1319 const char *name, uint32 type, uint32 flags) 1320 \brief Create a new index. 1321 1322 \param fs The file system provided handle to the volume. 1323 \param name The name of the new index. 1324 \param type The type of index. BFS implements the following types: 1325 - \c B_INT32_TYPE 1326 - \c B_UINT32_TYPE 1327 - \c B_INT64_TYPE 1328 - \c B_UINT64_TYPE 1329 - \c B_FLOAT_TYPE 1330 - \c B_DOUBLE_TYPE 1331 - \c B_STRING_TYPE 1332 - \c B_MIME_STRING_TYPE 1333 \param flags There are currently no extra flags specified. This parameter can 1334 be ignored. 1335 \return You should return \c B_OK if the creation succeeded, or return an 1336 error otherwise. 1337*/ 1338 1339/*! 1340 \fn status_t (*file_system_module_info::remove_index)(fs_volume fs, 1341 const char *name) 1342 \brief Remove the index with \a name. 1343 1344 \param fs The file system provided handle to the volume. 1345 \param name The name of the index to be removed. 1346 \return You should return \c B_OK if the creation succeeded, or return an 1347 error otherwise. 1348*/ 1349 1350/*! 1351 \fn status_t (*file_system_module_info::read_index_stat)(fs_volume fs, 1352 const char *name, struct stat *stat) 1353 \brief Read the \a stat of the index with a name. 1354 1355 \param fs The file system provided handle to the volume. 1356 \param name The name of the index to be queried. 1357 \param stat A pointer to a structure where you should store the values. 1358 \return You should return \c B_OK if the creation succeeded, or return an 1359 error otherwise. 1360*/ 1361 1362//! @} 1363 1364/*! 1365 \name Query Operations 1366*/ 1367 1368//! @{ 1369 1370/*! 1371 \fn status_t (*file_system_module_info::open_query)(fs_volume fs, 1372 const char *query, uint32 flags, port_id port, uint32 token, 1373 fs_cookie *_cookie) 1374 \brief Open a query as a 'directory'. 1375 1376 TODO: query expressions should be documented and also the format for sending 1377 query updates over the port should be updated. 1378 1379 See \ref concepts "Generic Concepts" on directories and iterators. Basically, 1380 the VFS uses the same way of traversing through indeces as it traverses 1381 through a directory. 1382 1383 \param fs The file system provided cookie to the volume. 1384 \param query The string that represents a query. 1385 \param flags Either one of these flags: 1386 - \c #B_LIVE_QUERY The query is live. When a query is live, it is 1387 constantly updated using the \a port. In this case the file system should 1388 be pro-active. 1389 - \c #B_QUERY_NON_INDEXED When this parameter is provided, the query 1390 should be carried out over the whole file system. This parameter is 1391 provided with the idea that sometimes the indeces can be out of date. If 1392 the requestor for this query requires absolutely everything to be 1393 queried, it will pass this parameter. Of course, if your indeces are 1394 always up to date, you can ignore this parameter. 1395 \param port The id of the port where updates need to be sent to in case the 1396 query is live. 1397 \param token A token that should be attached to the messages sent over the 1398 \a port. 1399 \param[out] _cookie The cookie that will be used as 'directory' to traverse 1400 through the results of the query. 1401 \return You should return \c B_OK if the creation succeeded, or return an 1402 error otherwise. 1403*/ 1404 1405/*! 1406 \fn status_t (*file_system_module_info::close_query)(fs_volume fs, 1407 fs_cookie cookie) 1408 \brief Close a 'directory' of a query. 1409 1410 Note that you should free the cookie in the free_query_cookie() call. 1411 1412 \param fs The file system provided cookie to the volume. 1413 \param cookie The cookie that refers to this query. 1414 \return You should return \c B_OK if the creation succeeded, or return an 1415 error otherwise. 1416*/ 1417 1418/*! 1419 \fn status_t (*file_system_module_info::free_query_cookie)(fs_volume fs, 1420 fs_cookie cookie) 1421 \brief Free a cookie of a query. 1422 1423 \param fs The file system provided cookie to the volume. 1424 \param cookie The cookie that should be freed. 1425 \return You should return \c B_OK if the creation succeeded, or return an 1426 error otherwise. 1427*/ 1428 1429/*! 1430 \fn status_t (*file_system_module_info::read_query)(fs_volume fs, 1431 fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num) 1432 \brief Read the next one or more entries matching the query. 1433 1434 This hook function works pretty much the same way as read_dir(), with the 1435 difference that it doesn't read the entries of a directory, but the entries 1436 matching the given query. 1437 1438 \param fs The volume handle. 1439 \param cookie The query cookie as returned by open_query(). 1440 \param buffer Pointer to a pre-allocated buffer the directory entries shall 1441 be written to. 1442 \param bufferSize The size of \a buffer in bytes. 1443 \param _num Pointer to a pre-allocated variable, when invoked, containing the 1444 number of entries to be read, and into which the number of entries 1445 actually read shall be written. 1446 \return \c B_OK if everything went fine, another error code otherwise. 1447*/ 1448 1449/*! 1450 \fn status_t (*file_system_module_info::rewind_query)(fs_volume fs, 1451 fs_cookie cookie) 1452 \brief Reset the query cookie to the first entry of the results. 1453 1454 \param fs The file system provided handle to the volume. 1455 \param cookie The query cookie as returned by open_query(). 1456 \return \c B_OK if everything went fine, another error code otherwise. 1457*/ 1458 1459//! @} 1460 1461/*! 1462 \name Capability Querying 1463*/ 1464 1465//! @{ 1466 1467/*! 1468 \fn bool (*file_system_module_info::supports_defragmenting)(partition_data 1469 *partition, bool *whileMounted) 1470 \brief Undocumented. TODO. 1471*/ 1472 1473/*! 1474 \fn bool (*file_system_module_info::supports_repairing)(partition_data *partition, 1475 bool checkOnly, bool *whileMounted) 1476 \brief Undocumented. TODO. 1477*/ 1478 1479/*! 1480 \fn bool (*file_system_module_info::supports_resizing)(partition_data *partition, 1481 bool *whileMounted) 1482 \brief Undocumented. TODO. 1483*/ 1484 1485/*! 1486 \fn bool (*file_system_module_info::supports_moving)(partition_data *partition, bool *isNoOp) 1487 \brief Undocumented. TODO. 1488*/ 1489 1490/*! 1491 \fn bool (*file_system_module_info::supports_setting_content_name)(partition_data *partition, 1492 bool *whileMounted) 1493 \brief Undocumented. TODO. 1494*/ 1495 1496/*! 1497 \fn bool (*file_system_module_info::supports_setting_content_parameters)(partition_data *partition, 1498 bool *whileMounted) 1499 \brief Undocumented. TODO. 1500*/ 1501 1502/*! 1503 \fn bool (*file_system_module_info::supports_initializing)(partition_data *partition) 1504 \brief Undocumented. TODO. 1505*/ 1506 1507/*! 1508 \fn bool (*file_system_module_info::validate_resize)(partition_data *partition, off_t *size) 1509 \brief Undocumented. TODO. 1510*/ 1511 1512/*! 1513 \fn bool (*file_system_module_info::validate_move)(partition_data *partition, off_t *start) 1514 \brief Undocumented. TODO. 1515*/ 1516 1517/*! 1518 \fn bool (*file_system_module_info::validate_set_content_name)(partition_data *partition, 1519 char *name) 1520 \brief Undocumented. TODO. 1521*/ 1522 1523/*! 1524 \fn bool (*file_system_module_info::validate_set_content_parameters)(partition_data *partition, 1525 const char *parameters) 1526 \brief Undocumented. TODO. 1527*/ 1528 1529/*! 1530 \fn bool (*file_system_module_info::validate_initialize)(partition_data *partition, char *name, 1531 const char *parameters) 1532 \brief Undocumented. TODO. 1533*/ 1534 1535//! @} 1536 1537/*! 1538 \name Shadow Partition Modification 1539*/ 1540 1541//! @{ 1542 1543/*! 1544 \fn status_t (*file_system_module_info::shadow_changed)(partition_data *partition, 1545 uint32 operation) 1546 \brief Undocumented. TODO. 1547*/ 1548 1549//! @} 1550 1551/*! 1552 \name Special Operations 1553*/ 1554 1555//! @{ 1556 1557/*! 1558 \fn status_t (*file_system_module_info::defragment)(int fd, partition_id partition, 1559 disk_job_id job) 1560 \brief Undocumented. TODO. 1561*/ 1562 1563/*! 1564 \fn status_t (*file_system_module_info::repair)(int fd, partition_id partition, bool checkOnly, 1565 disk_job_id job) 1566 \brief Undocumented. TODO. 1567*/ 1568 1569/*! 1570 \fn status_t (*file_system_module_info::resize)(int fd, partition_id partition, off_t size, 1571 disk_job_id job) 1572 \brief Undocumented. TODO. 1573*/ 1574 1575/*! 1576 \fn status_t (*file_system_module_info::move)(int fd, partition_id partition, off_t offset, 1577 disk_job_id job) 1578 \brief Undocumented. TODO. 1579*/ 1580 1581/*! 1582 \fn status_t (*file_system_module_info::set_content_name)(int fd, partition_id partition, 1583 const char *name, disk_job_id job) 1584 \brief Undocumented. TODO. 1585*/ 1586 1587/*! 1588 \fn status_t (*file_system_module_info::set_content_parameters)(int fd, partition_id partition, 1589 const char *parameters, disk_job_id job) 1590 \brief Undocumented. TODO. 1591*/ 1592 1593/*! 1594 \fn status_t (*file_system_module_info::initialize)(const char *partition, const char *name, 1595 const char *parameters, disk_job_id job) 1596 \brief Undocumented. TODO. 1597*/ 1598 1599//! @} 1600 1601///// Vnode functions ///// 1602 1603/*! 1604 \fn status_t new_vnode(dev_t mountID, ino_t vnodeID, 1605 fs_vnode privateNode) 1606 \brief Create the vnode with ID \a vnodeID and associates it with the 1607 private data handle \a privateNode, but leaves is in an unpublished state. 1608 1609 The effect of the function is similar to publish_vnode(), but the vnode 1610 remains in an unpublished state, with the effect that a subsequent 1611 remove_vnode() will just delete the vnode and not invoke the file system's 1612 \link file_system_module_info::remove_vnode remove_vnode() \endlink when 1613 the final reference is put down. 1614 1615 If the vnode shall be kept, publish_vnode() has to be invoked afterwards to 1616 mark the vnode published. The combined effect is the same as only invoking 1617 publish_vnode(). 1618 1619 You'll usually use this function to secure a vnode ID from being reused 1620 while you are in the process of creating the entry. Note that this function 1621 will panic in case you call it for an existing vnode ID. 1622 1623 The function fails, if the vnode does already exist. 1624 1625 \param mountID The ID of the volume. 1626 \param vnodeID The ID of the node. 1627 \param privateNode The private data handle to be associated with the node. 1628 \return \c B_OK if everything went fine, another error code otherwise. 1629*/ 1630 1631/*! 1632 \fn status_t publish_vnode(dev_t mountID, ino_t vnodeID, 1633 fs_vnode privateNode) 1634 \brief Creates the vnode with ID \a vnodeID and associates it with the 1635 private data handle \a privateNode or just marks it published. 1636 1637 If the vnode does already exist and has been published, the function fails. 1638 If it has not been published yet (i.e. after a successful new_vnode()), the 1639 function just marks the vnode published. If the vnode did not exist at all 1640 before, it is created and published. 1641 1642 If the function is successful, the caller owns a reference to the vnode. A 1643 sequence of new_vnode() and publish_vnode() results in just one reference as 1644 well. The reference can be surrendered by calling put_vnode(). 1645 1646 This call is equivalent to the former R5 new_vnode() function. 1647 1648 \param mountID The ID of the volume. 1649 \param vnodeID The ID of the node. 1650 \param privateNode The private data handle to be associated with the node. 1651 \return \c B_OK if everything went fine, another error code otherwise. 1652*/ 1653 1654/*! 1655 \fn status_t get_vnode(dev_t mountID, ino_t vnodeID, 1656 fs_vnode *_privateNode) 1657 \brief Retrieves the private data handle for the node with the given ID. 1658 1659 If the function is successful, the caller owns a reference to the vnode. The 1660 reference can be surrendered by calling put_vnode(). 1661 1662 \param mountID The ID of the volume. 1663 \param vnodeID The ID of the node. 1664 \param _privateNode Pointer to a pre-allocated variable the private data 1665 handle shall be written to. 1666 \return \c B_OK if everything went fine, another error code otherwise. 1667*/ 1668 1669/*! 1670 \fn status_t put_vnode(dev_t mountID, ino_t vnodeID) 1671 \brief Surrenders a reference to the specified vnode. 1672 \param mountID The ID of the volume. 1673 \param vnodeID The ID of the node. 1674 \return \c B_OK if everything went fine, another error code otherwise. 1675*/ 1676 1677/*! 1678 \fn status_t remove_vnode(dev_t mountID, ino_t vnodeID) 1679 \brief Marks the specified vnode removed. 1680 1681 The caller must own a reference to the vnode or at least ensure that a 1682 reference to the vnode exists. The function does not surrender a reference, 1683 though. 1684 1685 As soon as the last reference to the vnode has been surrendered, the VFS 1686 invokes the file system's 1687 \link file_system_module_info::remove_vnode remove_vnode() \endlink 1688 hook. 1689 1690 \param mountID The ID of the volume. 1691 \param vnodeID The ID of the node. 1692 \return \c B_OK if everything went fine, another error code otherwise. 1693*/ 1694 1695/*! 1696 \fn status_t unremove_vnode(dev_t mountID, ino_t vnodeID); 1697 \brief Clears the "removed" mark of the specified vnode. 1698 1699 The caller must own a reference to the vnode or at least ensure that a 1700 reference to the vnode exists. 1701 1702 The function is usually called when the caller, who has invoked 1703 remove_vnode() before realizes that it is not possible to remove the node 1704 (e.g. due to an error). 1705 1706 \param mountID The ID of the volume. 1707 \param vnodeID The ID of the node. 1708 \return \c B_OK if everything went fine, another error code otherwise. 1709*/ 1710 1711/*! 1712 \fn status_t get_vnode_removed(dev_t mountID, ino_t vnodeID, 1713 bool* removed); 1714 \brief Returns whether the specified vnode is marked removed. 1715 1716 The caller must own a reference to the vnode or at least ensure that a 1717 reference to the vnode exists. 1718 1719 \param mountID The ID of the volume. 1720 \param vnodeID The ID of the node. 1721 \param removed Pointer to a pre-allocated variable set to \c true, if the 1722 node is marked removed, to \c false otherwise. 1723 \return \c B_OK if everything went fine, another error code otherwise. 1724*/ 1725 1726///// Notification Functions 1727 1728/*! 1729 \name Notification Functions 1730 1731 The following functions are used to implement the node monitor functionality 1732 in your file system. Whenever one of the below mentioned events occur, you 1733 have to call them. 1734 1735 The node monitor will then notify all registered listeners for the nodes 1736 that changed. 1737*/ 1738 1739/*! 1740 \fn status_t notify_entry_created(dev_t device, ino_t directory, 1741 const char *name, ino_t node) 1742 \brief Notifies listeners that a file system entry has been created. 1743*/ 1744 1745/*! 1746 \fn status_t notify_entry_removed(dev_t device, ino_t directory, 1747 const char *name, ino_t node) 1748 \brief Notifies listeners that a file system entry has been removed. 1749*/ 1750 1751/*! 1752 \fn status_t notify_entry_moved(dev_t device, ino_t fromDirectory, 1753 const char *fromName, ino_t toDirectory, 1754 const char *toName, ino_t node) 1755 \brief Notifies listeners that a file system entry has been moved to 1756 another directory. 1757*/ 1758 1759/*! 1760 \fn status_t notify_stat_changed(dev_t device, ino_t node, 1761 uint32 statFields) 1762 \brief Notifies listeners that certain \a statFields of a file system entry 1763 were updated. 1764*/ 1765 1766/*! 1767 \fn status_t notify_attribute_changed(dev_t device, ino_t node, 1768 const char *attribute, int32 cause) 1769 \brief Notifies listeners that an attribute of a file system entry has been 1770 changed. 1771*/ 1772 1773/*! 1774 \fn status_t notify_query_entry_created(port_id port, int32 token, 1775 dev_t device, ino_t directory, const char *name, 1776 ino_t node) 1777 \brief Notifies listeners that an entry has entered the result set of a live query. 1778*/ 1779 1780/*! 1781 \fn status_t notify_query_entry_removed(port_id port, int32 token, 1782 dev_t device, ino_t directory, const char *name, 1783 ino_t node) 1784 \brief Notifies listeners that an entry has left the result set of a live query. 1785*/ 1786 1787//! @} 1788