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