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