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 shall be set to the length of the symlink contents, even if the entire 965 contents did not fit in the provided \a buffer. 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 length of the symlink contents. 974 \retval B_OK Everything went fine. 975 \retval B_BAD_VALUE \a link does not identify a symbolic link. 976*/ 977 978/*! 979 \fn status_t (*fs_vnode_ops::create_symlink)(fs_volume *volume, 980 fs_vnode *dir, const char *name, const char *path, int mode) 981 \brief Create a new symbolic link. 982 983 \param volume The volume object. 984 \param dir The node object for the directory the symbolic link should be 985 created in. 986 \param name The name of the new symbolic link. 987 \param path The path the symbolic link should refer to. 988 \param mode The permissions for the newly created symbolic link. 989 \return \c B_OK if you succeeded, or an error code if you failed. 990*/ 991 992/*! 993 \fn status_t (*fs_vnode_ops::link)(fs_volume *volume, fs_vnode *dir, 994 const char *name, fs_vnode *vnode) 995 \brief Create a new hard link. 996 997 The virtual file system will request the creation of symbolic links with 998 create_symlink(). 999 1000 If you don't implement this function, the VFS will return \c EROFS 1001 when a hard link is requested. So, if you don't support hard links implement 1002 this hook and return an appropriate error code. 1003 1004 \param volume The volume object. 1005 \param dir The node object for the directory where the link should be 1006 created. 1007 \param name The name the link should have. 1008 \param vnode The vnode the new link should resolve to. 1009 \retval B_OK The hard link is properly created. 1010 \retval B_NOT_ALLOWED The user does not have the proper permissions. 1011 \retval "other errors" Another error occured. 1012*/ 1013 1014/*! 1015 \fn status_t (*fs_vnode_ops::unlink)(fs_volume *volume, fs_vnode *dir, 1016 const char *name) 1017 \brief Remove a non-directory entry. 1018 1019 Remove an entry that does refer to a non-directory node. For removing 1020 directories the remove_dir() hook is used. If invoked on a directory, this 1021 hook shall fail. 1022 1023 \param volume The volume object. 1024 \param dir The node object for the directory containing the entry to be 1025 removed. 1026 \param name The name of the entry that should be removed. 1027 \retval B_OK Removal succeeded. 1028 \retval B_ENTRY_NOT_FOUND The entry does not exist. 1029 \retval B_NOT_ALLOWED The user does not have the proper permissions. 1030 \retval B_IS_A_DIRECTORY The entry refers to a directory. 1031 \retval "other errors" Another error occured. 1032*/ 1033 1034/*! 1035 \fn status_t (*fs_vnode_ops::rename)(fs_volume *volume, fs_vnode *fromDir, 1036 const char *fromName, fs_vnode *toDir, const char *toName) 1037 \brief Rename and/or relocate an entry. 1038 1039 The virtual file system merely relays the request, so make sure the user is 1040 not changing the file name to something like '.', '..' or anything starting 1041 with '/'. 1042 1043 This also means that it if the entry refers to a directory, that it should 1044 not be moved into one of its own children. 1045 1046 \param volume The volume object. 1047 \param fromDir The node object for the parent directory the entry should be 1048 moved from. 1049 \param fromName The old entry name. 1050 \param toDir The node object for the parent directory the entry should be 1051 moved to. 1052 \param toName The new entry name. 1053 \retval B_OK The renaming and relocating succeeded. 1054 \retval B_BAD_VALUE One of the supplied parameters were invalid. 1055 \retval B_NOT_ALLOWED The user does not have the proper permissions. 1056 \retval "other errors" Another error condition was encountered. 1057*/ 1058 1059/*! 1060 \fn status_t (*fs_vnode_ops::access)(fs_volume *volume, fs_vnode *vnode, 1061 int mode) 1062 \brief Checks whether the current user is allowed to access the node in the 1063 specified way. 1064 1065 \a mode is a bitwise combination of: 1066 - \c R_OK: Read access. 1067 - \c W_OK: Write access. 1068 - \c X_OK: Execution. 1069 1070 If the current user does not have any of the access permissions represented 1071 by the set bits, the function shall return \c B_NOT_ALLOWED. As a special 1072 case, if the volume is read-only and write access is requested, 1073 \c B_READ_ONLY_DEVICE shall be returned. If the requested access mode 1074 complies with the user's access permissions, the function shall return 1075 \c B_OK. 1076 1077 For most FSs the permissions a user has are defined by the \c st_mode, 1078 \c st_uid, and \c st_gid fields of the node's stat data. As a special 1079 exception, the root user (<tt>geteuid() == 0</tt>) does always have 1080 read and write permissions, execution permission only when at least one of 1081 the execution permission bits are set. 1082 1083 \param volume The volume object. 1084 \param vnode The node object. 1085 \param mode The access mode mask. 1086 \retval B_OK The user has the permissions to access the node in the 1087 requested way. 1088 \retval B_READ_ONLY_DEVICE The volume is read-only, but the write access has 1089 been requested. 1090 \retval B_NOT_ALLOWED The user does not have all permissions to access the 1091 node in the requested way. 1092*/ 1093 1094/*! 1095 \fn status_t (*fs_vnode_ops::read_stat)(fs_volume *volume, fs_vnode *vnode, 1096 struct stat *stat) 1097 \brief Retrieves the stat data for a given node. 1098 1099 All values of the <tt>struct stat</tt> save \c st_dev, \c st_ino, 1100 \c st_rdev, and \c st_type need to be filled in. 1101 1102 \param volume The volume object. 1103 \param vnode The node object. 1104 \param stat Pointer to a pre-allocated variable the stat data shall be 1105 written to. 1106 \return \c B_OK if everything went fine, another error code otherwise. 1107*/ 1108 1109/*! 1110 \fn status_t (*fs_vnode_ops::write_stat)(fs_volume *volume, fs_vnode *vnode, 1111 const struct stat *stat, uint32 statMask) 1112 \brief Update the stats for a vnode. 1113 1114 You should make sure that the new values are valid. 1115 1116 \param volume The volume object. 1117 \param vnode The node object. 1118 \param stat The structure with the updated values. 1119 \param statMask A bitwise combination of one or more of the following, 1120 specifying which stat field shall be set: 1121 - B_STAT_MODE: Set the node permissions. 1122 - B_STAT_UID: Set the owning user. 1123 - B_STAT_GID: Set the owner group. 1124 - B_STAT_SIZE: Set the size of the file. If enlarged, the file is 1125 padded. Normally with zero bytes, but with unspecified data, if 1126 B_STAT_SIZE_INSECURE is specified, too. 1127 - B_STAT_SIZE_INSECURE: Modifier for B_STAT_SIZE: When enlarging the 1128 file padding can be done with arbitrary data. 1129 - B_STAT_ACCESS_TIME: Set the access time. 1130 - B_STAT_MODIFICATION_TIME: Set the modification time. 1131 - B_STAT_CREATION_TIME: Set the creation time. 1132 - B_STAT_CHANGE_TIME: Set the change time. 1133 \retval B_OK The update succeeded. 1134 \retval B_NOT_ALLOWED The user does not have the proper permissions. 1135 \retval "other errors" Another error condition occured. 1136*/ 1137 1138//! @} 1139 1140/*! 1141 \name File Operations 1142*/ 1143 1144//! @{ 1145 1146/*! 1147 \fn status_t (*fs_vnode_ops::create)(fs_volume *volume, fs_vnode *dir, 1148 const char *name, int openMode, int perms, void **_cookie, 1149 ino_t *_newVnodeID) 1150 \brief Creates and opens a new file. 1151 1152 The hook is similar to \link fs_vnode_ops::open() open() \endlink, with the 1153 difference that, if an entry with the name \a name does not already exist 1154 in the given directory, a new file with that name is created first. 1155 If the entry does already exist and \a openMode specifies the \c O_EXCL 1156 flag, the function shall fail with \c B_FILE_EXISTS (aka \c EEXIST). 1157 1158 \param volume The volume object. 1159 \param dir The node object for the directory where the file should appear. 1160 \param name The name of the new file. 1161 \param openMode The mode associated to the file. 1162 \param perms The permissions the new file should have. 1163 \param[out] _cookie In case of success, the storage where you can put your 1164 FS specific cookie for the open node. 1165 \param[out] _newVnodeID In case of success, you can store the new vnode id 1166 in this variable. 1167 \return If opening the node succeeded (after creating it first, if 1168 necessary), \c B_OK shall be returned and \a _cookie and \a _newVnodeID 1169 shall be set. Otherwise an error code shall be returned. 1170*/ 1171 1172/*! 1173 \fn status_t (*fs_vnode_ops::open)(fs_volume *volume, fs_vnode *vnode, 1174 int openMode, void **_cookie) 1175 \brief Opens the given node. 1176 1177 The hook is invoked whenever a file is opened (e.g. via the open() POSIX 1178 function). 1179 1180 The hook can create a node cookie, and store it in the variable 1181 \a _cookie points to. The cookie will be passed to all hooks that operate 1182 on open files. 1183 1184 The open mode \a openMode is encoded in the same way as the parameter of the 1185 POSIX function \c open(), i.e. it is either \c O_RDONLY, \c O_WRONLY, or 1186 \c O_RDWR, bitwise or'ed with flags. The only relevant flags for this hook 1187 are \c O_TRUNC and \c O_NONBLOCK. You will normally want to store the open 1188 mode in the file cookie, since you'll have to check in read() and write() 1189 whether the the respective operation is allowed by the open mode. 1190 1191 \param volume The volume object. 1192 \param vnode The node object. 1193 \param openMode The open mode. 1194 \param _cookie Pointer to a pre-allocated variable the node cookie shall be 1195 written to. 1196 \return \c B_OK if everything went fine, another error code otherwise. 1197*/ 1198 1199/*! 1200 \fn status_t (*fs_vnode_ops::close)(fs_volume *volume, fs_vnode *vnode, 1201 void *cookie) 1202 \brief Closes the given node cookie. 1203 1204 The hook is invoked, when closing the node has been requested. At this point 1205 other threads might still use the cookie, i.e. still execute hooks to which 1206 the cookie has been passed. If the FS supports blocking I/O operations, this 1207 hook should make sure to unblock all currently blocking threads performing 1208 an operation using the cookie, and mark the cookie such that no further 1209 threads will block using it. 1210 1211 For many FSs this hook is a no-op -- it's mandatory to be exported, though. 1212 1213 \param volume The volume object. 1214 \param vnode The node object. 1215 \param cookie The node cookie as returned by open(). 1216 \return \c B_OK if everything went fine, another error code otherwise. 1217*/ 1218 1219/*! 1220 \fn status_t (*fs_vnode_ops::free_cookie)(fs_volume *volume, 1221 fs_vnode *vnode, void *cookie) 1222 \brief Frees the given node cookie. 1223 1224 The hook is invoked after close(), when no other thread uses or is going to 1225 use the cookie. All resources associated with the cookie must be freed. 1226 1227 \param volume The volume object. 1228 \param vnode The node object. 1229 \param cookie The node cookie as returned by open(). 1230 \return \c B_OK if everything went fine, another error code otherwise. 1231*/ 1232 1233/*! 1234 \fn status_t (*fs_vnode_ops::read)(fs_volume *volume, fs_vnode *vnode, 1235 void *cookie, off_t pos, void *buffer, size_t *length) 1236 \brief Reads data from a file. 1237 1238 This function should fail if 1239 - the node is not a file, 1240 - the cookie has not been opened for reading, 1241 - \a pos is negative, or 1242 - some other error occurs while trying to read the data, and no data have 1243 been read at all. 1244 1245 The number of bytes to be read is stored in the variable pointed to by 1246 \a length. If less data is available at file position \a pos, or if \a pos 1247 if greater than the size of the file, only as many data as available shall 1248 be read, the function shall store the number of bytes actually read into the 1249 variable pointed to by \a length, and return \c B_OK. 1250 1251 \param volume The volume object. 1252 \param vnode The node object. 1253 \param cookie The node cookie as returned by open(). 1254 \param pos The file position where to start reading data. 1255 \param buffer Pointer to a pre-allocated buffer the read data shall be 1256 written to. 1257 \param length Pointer to a pre-allocated variable containing the size of the 1258 buffer when invoked, and into which the size of the data actually read 1259 shall be written. 1260 \return \c B_OK if everything went fine, another error code otherwise. 1261*/ 1262 1263/*! 1264 \fn status_t (*fs_vnode_ops::write)(fs_volume *volume, fs_vnode *vnode, 1265 void *cookie, off_t pos, const void *buffer, size_t *length) 1266 \brief Write data to a file. 1267 1268 This function should fail if 1269 - the node is not a file, 1270 - the cookie has not been opened for writing, 1271 - \a pos is negative, or 1272 - some other error occurs while trying to write the data, and no data have 1273 been written at all. 1274 1275 The number of bytes to be written is stored in the variable pointed to by 1276 \a length. If not all bytes could be written, that variable must be updated 1277 to reflect the amount of actually written bytes. If any bytes have been 1278 written, the function shall not fail, if an error prevents you from 1279 writing the full amount. Only when the error prevented you from writing 1280 any data at all an error shall be returned. 1281 1282 \param volume The volume object. 1283 \param vnode The node object. 1284 \param cookie The file system provided cookie associated with the file. 1285 \param pos The position to start writing. 1286 \param buffer The buffer that contains the data that will need to be 1287 written. 1288 \param length The length of the data that needs to be written. 1289 \return \c B_OK if everything went fine, another error code otherwise. 1290*/ 1291 1292//! @} 1293 1294/*! 1295 \name Directory Operations 1296*/ 1297 1298//! @{ 1299 1300/*! 1301 \fn status_t (*fs_vnode_ops::create_dir)(fs_volume *volume, 1302 fs_vnode *parent, const char *name, int perms) 1303 \brief Create a new directory. 1304 1305 \param volume The volume object. 1306 \param parent The node object for the directory in which to create the new 1307 directory. 1308 \param name The name the new directory should have. 1309 \param perms The permissions the new directory should have. 1310 \return \c B_OK if the directory was created successfully, an error code 1311 otherwise. 1312*/ 1313 1314/*! 1315 \fn status_t (*fs_vnode_ops::remove_dir)(fs_volume *volume, 1316 fs_vnode *parent, const char *name) 1317 \brief Remove a directory. 1318 1319 The function shall fail, if the entry does not refer to a directory, or if 1320 it refers to a directory that is not empty. 1321 1322 \param volume The volume object. 1323 \param parent The node object for the parent directory containing the 1324 directory to be removed. 1325 \param name The \a name of the directory that needs to be removed. 1326 \retval B_OK Operation succeeded. 1327 \retval B_ENTRY_NOT_FOUND There is no entry with this \a name. 1328 \retval B_NOT_A_DIRECTORY The entry is not a directory. 1329 \retval B_DIRECTORY_NOT_EMPTY The directory is not empty. The virtual 1330 file system expects directories to be emptied before they can be 1331 removed. 1332 \retval "other errors" Other errors occured. 1333*/ 1334 1335/*! 1336 \fn status_t (*fs_vnode_ops::open_dir)(fs_volume *volume, fs_vnode *vnode, 1337 void **_cookie) 1338 \brief Opens the given directory node. 1339 1340 If the specified node is not a directory, the function shall fail. 1341 Otherwise it shall allocate a directory cookie and store it in the variable 1342 \a _cookie points to. A subsequent read_dir() using the cookie shall start 1343 reading the first entry of the directory. 1344 1345 \param volume The volume object. 1346 \param vnode The node object. 1347 \param _cookie Pointer to a pre-allocated variable the directory cookie 1348 shall be written to. 1349 \return \c B_OK if everything went fine, another error code otherwise. 1350*/ 1351 1352/*! 1353 \fn status_t (*fs_vnode_ops::close_dir)(fs_volume *volume, fs_vnode *vnode, 1354 void *cookie) 1355 \brief Closes the given directory cookie. 1356 1357 Generally the situation is similar to the one described for close(). In 1358 practice it is a bit different, though, since directory cookies are 1359 exclusively used for directory iteration, and it normally doesn't make sense 1360 to have multiple threads read the same directory concurrently. Furthermore 1361 usually reading a directory will not block. Therefore for most FSs this hook 1362 is a no-op. 1363 1364 \param volume The volume object. 1365 \param vnode The node object. 1366 \param cookie The directory cookie as returned by open_dir(). 1367 \return \c B_OK if everything went fine, another error code otherwise. 1368*/ 1369 1370/*! 1371 \fn status_t (*fs_vnode_ops::free_dir_cookie)(fs_volume *volume, 1372 fs_vnode *vnode, void *cookie) 1373 \brief Frees the given directory cookie. 1374 1375 The hook is invoked after close_dir(), when no other thread uses or is going 1376 to use the cookie. All resources associated with the cookie must be freed. 1377 1378 \param volume The volume object. 1379 \param vnode The node object. 1380 \param cookie The directory cookie as returned by open_dir(). 1381 \return \c B_OK if everything went fine, another error code otherwise. 1382*/ 1383 1384/*! 1385 \fn status_t (*fs_vnode_ops::read_dir)(fs_volume *volume, fs_vnode *vnode, 1386 void *cookie, struct dirent *buffer, size_t bufferSize, 1387 uint32 *_num) 1388 \brief Reads the next one or more directory entries. 1389 1390 The number of entries to be read at maximum is stored in the variable 1391 \a _num points to. 1392 1393 Per read \c dirent the following fields have to be filled in: 1394 - \c d_dev: The volume ID. 1395 - \c d_ino: The ID of the node the entry refers to. 1396 - \c d_name: The null-terminated name of the entry. 1397 - \c d_reclen: The size of the \c dirent structure in bytes, starting from 1398 the beginning of the structure, counting all bytes up to and including 1399 the null-termination char of the name stored in \c d_name. 1400 1401 If more than one entry is read, the corresponding \c dirent structures are 1402 tightly packed, i.e. the second entry can begin directly after the end of 1403 the first one (i.e. \c d_reclen bytes after the beginning of the first one). 1404 The file system should make sure that the dirents are 8-byte aligned, i.e. 1405 when another entry follows, \c d_reclen of the previous one should be 1406 aligned. A FS doesn't have to read more than one entry at a time, but it is 1407 recommended to support that for performance reasons. 1408 1409 When the function is invoked after the end of the directory has been 1410 reached, it shall set the variable \a _num points to to \c 0 and return 1411 \c B_OK. If the provided buffer is too small to contain even the single next 1412 entry, \c B_BUFFER_OVERFLOW shall be returned. It shall not fail, if at 1413 least one entry has been read, and the buffer is just too small to hold as 1414 many entries as requested. 1415 1416 Note that a directory is expected to contain the special entries \c "." and 1417 \c "..", referring to the same directory and the parent directory 1418 respectively. The \c dirent structure returned for the \c ".." entry of the 1419 volume's root directory shall refer to the root node itself. 1420 1421 \param volume The volume object. 1422 \param vnode The node object. 1423 \param cookie The directory cookie as returned by open_dir(). 1424 \param buffer Pointer to a pre-allocated buffer the directory entries shall 1425 be written to. 1426 \param bufferSize The size of \a buffer in bytes. 1427 \param _num Pointer to a pre-allocated variable, when invoked, containing 1428 the number of directory entries to be read, and into which the number of 1429 entries actually read shall be written. 1430 \return \c B_OK if everything went fine, another error code otherwise. 1431*/ 1432 1433/*! 1434 \fn status_t (*fs_vnode_ops::rewind_dir)(fs_volume *volume, fs_vnode *vnode, 1435 void *cookie) 1436 \brief Resets the directory cookie to the first entry of the directory. 1437 \param volume The volume object. 1438 \param vnode The node object. 1439 \param cookie The directory cookie as returned by open_dir(). 1440 \return \c B_OK if everything went fine, another error code otherwise. 1441*/ 1442 1443//! @} 1444 1445/*! 1446 \name Attribute Directory Operations 1447*/ 1448 1449//! @{ 1450 1451/*! 1452 \fn status_t (*fs_vnode_ops::open_attr_dir)(fs_volume *volume, 1453 fs_vnode *vnode, void **_cookie) 1454 \brief Open a 'directory' of attributes for a \a vnode. 1455 1456 See \ref concepts "Generic Concepts" on directories and iterators. 1457 Basically, the VFS uses the same way of traversing through attributes as it 1458 traverses through a directory. 1459 1460 \param volume The volume object. 1461 \param vnode The node object. 1462 \param[out] _cookie Pointer where the file system can store a directory 1463 cookie if the attribute directory is succesfully opened. 1464 \return \c B_OK if everything went fine, another error code otherwise. 1465*/ 1466 1467/*! 1468 \fn status_t (*fs_vnode_ops::close_attr_dir)(fs_volume *volume, 1469 fs_vnode *vnode, void *cookie) 1470 \brief Close a 'directory' of attributes for a \a vnode. 1471 1472 Note that you should free the cookie in the free_attr_dir_cookie() call. 1473 1474 \param volume The volume object. 1475 \param vnode The node object. 1476 \param cookie The cookie associated with this 'directory'. 1477 \return \c B_OK if everything went fine, another error code otherwise. 1478*/ 1479 1480/*! 1481 \fn status_t (*fs_vnode_ops::free_attr_dir_cookie)(fs_volume *volume, 1482 fs_vnode *vnode, void *cookie) 1483 \brief Free the \a cookie to an attribute 'directory'. 1484 1485 \param volume The volume object. 1486 \param vnode The node object. 1487 \param cookie The cookie associated that should be freed. 1488 \return \c B_OK if everything went fine, another error code otherwise. 1489*/ 1490 1491/*! 1492 \fn status_t (*fs_vnode_ops::read_attr_dir)(fs_volume *volume, 1493 fs_vnode *vnode, void *cookie, struct dirent *buffer, 1494 size_t bufferSize, uint32 *_num) 1495 \brief Read the next one or more attribute directory entries. 1496 1497 This method should perform the same tasks as read_dir(), except that the '.' 1498 and '..' entries do not have to be present. Also, only the \c d_name and 1499 \c d_reclen fields have to be filled in. 1500*/ 1501 1502/*! 1503 \fn status_t (*fs_vnode_ops::rewind_attr_dir)(fs_volume *volume, 1504 fs_vnode *vnode, void *cookie) 1505 \brief Rewind the attribute directory iterator to the first entry. 1506 1507 \param volume The volume object. 1508 \param vnode The node object. 1509 \param cookie The cookie associated with this 'directory'. 1510 \return \c B_OK if everything went fine, another error code otherwise. 1511*/ 1512 1513//! @} 1514 1515/*! 1516 \name Attribute Operations 1517*/ 1518 1519//! @{ 1520 1521/*! 1522 \fn status_t (*fs_vnode_ops::create_attr)(fs_volume *volume, 1523 fs_vnode *vnode, const char *name, uint32 type, int openMode, 1524 void **_cookie) 1525 \brief Create a new attribute. 1526 1527 If the attribute already exists, you should open it in truncated mode. 1528 1529 \param volume The volume object. 1530 \param vnode The node object. 1531 \param name The name of the attribute. 1532 \param type The \c type_code of the attribute. 1533 \param openMode The openMode of the associated attribute. 1534 \param[out] _cookie A pointer where you can store an associated file system 1535 cookie. 1536 \return \c B_OK if everything went fine, another error code otherwise. 1537*/ 1538 1539/*! 1540 \fn status_t (*fs_vnode_ops::open_attr)(fs_volume *volume, fs_vnode *vnode, 1541 const char *name, int openMode, void **_cookie) 1542 \brief Open an existing attribute. 1543 1544 \param volume The volume object. 1545 \param vnode The node object. 1546 \param name The name of the attribute. 1547 \param openMode The mode in which you want to open the attribute data. 1548 \param[out] _cookie A pointer where you can store an associated file system 1549 cookie. 1550 \return \c B_OK if everything went fine, another error code otherwise. 1551*/ 1552 1553/*! 1554 \fn status_t (*fs_vnode_ops::close_attr)(fs_volume *volume, fs_vnode *vnode, 1555 void *cookie) 1556 \brief Close access to an attribute. 1557 1558 Note that you should not delete the cookie yet, you should do that when the 1559 VFS calls free_attr_cookie(). 1560 1561 \param volume The volume object. 1562 \param vnode The node object. 1563 \param cookie The cookie you associated with this attribute. 1564 \return \c B_OK if everything went fine, another error code otherwise. 1565*/ 1566 1567/*! 1568 \fn status_t (*fs_vnode_ops::free_attr_cookie)(fs_volume *volume, 1569 fs_vnode *vnode, void *cookie) 1570 \brief Free the cookie of an attribute. 1571 1572 The VFS calls this hook when all operations on the attribute have ceased. 1573 1574 \param volume The volume object. 1575 \param vnode The node object. 1576 \param cookie The cookie to the attribute that should be freed. 1577 \return \c B_OK if everything went fine, another error code otherwise. 1578*/ 1579 1580/*! 1581 \fn status_t (*fs_vnode_ops::read_attr)(fs_volume *volume, fs_vnode *vnode, 1582 void *cookie, off_t pos, void *buffer, size_t *length) 1583 \brief Read attribute data. 1584 1585 Read until the \a buffer with size \a length is full, or until you are out 1586 of data, in which case you should update \a length. 1587 1588 \param volume The volume object. 1589 \param vnode The node object. 1590 \param cookie The cookie you associated with this attribute. 1591 \param pos The position to start reading from. 1592 \param buffer The buffer the data should be copied in. 1593 \param length The length of the buffer. Update this variable to the actual 1594 amount of bytes read. 1595 \return \c B_OK if everything went fine, another error code otherwise. 1596*/ 1597 1598/*! 1599 \fn status_t (*fs_vnode_ops::write_attr)(fs_volume *volume, fs_vnode *vnode, 1600 void *cookie, off_t pos, const void *buffer, size_t *length) 1601 \brief Write attribute data. 1602 1603 \param volume The volume object. 1604 \param vnode The node object. 1605 \param cookie The cookie you associated with this attribute. 1606 \param pos The position to start writing to. 1607 \param buffer The buffer the data should be copied from. 1608 \param length The size of the buffer. Update this variable to the actual 1609 amount of bytes written. 1610 \return \c B_OK if everything went fine, another error code otherwise. 1611*/ 1612 1613/*! 1614 \fn status_t (*fs_vnode_ops::read_attr_stat)(fs_volume *volume, 1615 fs_vnode *vnode, void *cookie, struct stat *stat) 1616 \brief Get the stats for an attribute. 1617 1618 Only the \c st_size and \c st_type fields need to be filled in. 1619 1620 \param volume The volume object. 1621 \param vnode The node object. 1622 \param cookie The cookie you associated with this attribute. 1623 \param stat A pointer to a stat structure you should fill. 1624 \return \c B_OK if everything went fine, another error code otherwise. 1625*/ 1626 1627/*! 1628 \fn status_t (*fs_vnode_ops::write_attr_stat)(fs_volume *volume, 1629 fs_vnode *vnode, void *cookie, const struct stat *stat, 1630 int statMask) 1631 \brief Update the stats of an attribute. 1632 1633 Currently on the attribute size (B_STAT_SIZE) can be set. 1634 1635 \param volume The volume object. 1636 \param vnode The node object. 1637 \param cookie The cookie you associated with this attribute. 1638 \param stat A pointer to the new stats you should write. 1639 \param statMask One or more of the values of write_stat_mask that tell you 1640 which fields of \a stat are to be updated. 1641 \return \c B_OK if everything went fine, another error code otherwise. 1642*/ 1643 1644/*! 1645 \fn status_t (*fs_vnode_ops::rename_attr)(fs_volume *volume, 1646 fs_vnode *fromVnode, const char *fromName, fs_vnode *toVnode, 1647 const char *toName) 1648 \brief Rename and/or relocate an attribute. 1649 1650 Currently there's no userland or kernel API moving an attribute from one 1651 node to another. So this hook is to allowed to only support the case where 1652 \a fromVnode and \a toVnode are equal and fail otherwise. 1653 1654 \param volume The volume object. 1655 \param fromVnode The node object for the vnode the attribute currently 1656 belongs to. 1657 \param fromName The old name of the attribute. 1658 \param toVnode The node object for the vnode the attribute should be 1659 moved to. This can be the same as \a fromVnode, in which case it only 1660 means the attribute should be renamed. 1661 \param toName The new name of the attribute. This can be the same as 1662 \a fromName, in which case it only means the attribute should be 1663 relocated. 1664 \retval B_OK The renaming and/or relocating succeeded. 1665 \retval B_BAD_VALUE One of the supplied parameters were invalid. 1666 \retval B_NOT_ALLOWED The user does not have the proper permissions. 1667 \retval "other errors" Another error condition was encountered. 1668*/ 1669 1670/*! 1671 \fn status_t (*fs_vnode_ops::remove_attr)(fs_volume *volume, 1672 fs_vnode *vnode, const char *name) 1673 \brief Remove an attribute. 1674 1675 \param volume The volume object. 1676 \param vnode The node object. 1677 \param name The name of the attribute. 1678 \return \c B_OK if everything went fine, another error code otherwise. 1679*/ 1680 1681//! @} 1682 1683/*! 1684 \name Node and FS Layers 1685*/ 1686 1687//! @{ 1688 1689/*! 1690 \fn status_t (*fs_vnode_ops::create_special_node)(fs_volume *volume, 1691 fs_vnode *dir, const char *name, fs_vnode *subVnode, mode_t mode, 1692 uint32 flags, fs_vnode *_superVnode, ino_t *_nodeID) 1693 \brief TODO: Document! 1694*/ 1695 1696/*! 1697 \fn status_t (*fs_vnode_ops::get_super_vnode)(fs_volume *volume, 1698 fs_vnode *vnode, fs_volume *superVolume, fs_vnode *superVnode) 1699 \brief TODO: Document! 1700*/ 1701 1702 1703//! @} 1704 1705 1706///// Vnode functions ///// 1707 1708/*! 1709 \name Vnode functions 1710*/ 1711 1712//! @{ 1713 1714/*! 1715 \fn status_t new_vnode(fs_volume *volume, ino_t vnodeID, void *privateNode, 1716 fs_vnode_ops *ops) 1717 \brief Create the vnode with ID \a vnodeID and associates it with the 1718 private data handle \a privateNode, but leaves is in an unpublished 1719 state. 1720 1721 The effect of the function is similar to publish_vnode(), but the vnode 1722 remains in an unpublished state, with the effect that a subsequent 1723 remove_vnode() will just delete the vnode and not invoke the file system's 1724 \link fs_vnode_ops::remove_vnode remove_vnode() \endlink when 1725 the final reference is put down. 1726 1727 If the vnode shall be kept, publish_vnode() has to be invoked afterwards to 1728 mark the vnode published. The combined effect is the same as only invoking 1729 publish_vnode(). 1730 1731 You'll usually use this function to secure a vnode ID from being reused 1732 while you are in the process of creating the entry. Note that this function 1733 will panic in case you call it for an existing vnode ID. 1734 1735 The function fails, if the vnode does already exist. 1736 1737 \param volume The volume object. 1738 \param vnodeID The ID of the node. 1739 \param privateNode The private data handle to be associated with the node. 1740 \param ops The operation vector for this vnode. Is not copied and must be 1741 valid through the whole life time of the vnode. 1742 \return \c B_OK if everything went fine, another error code otherwise. 1743*/ 1744 1745/*! 1746 \fn status_t publish_vnode(fs_volume *volume, ino_t vnodeID, 1747 void *privateNode, fs_vnode_ops *ops, int type, uint32 flags) 1748 \brief Creates the vnode with ID \a vnodeID and associates it with the 1749 private data handle \a privateNode or just marks it published. 1750 1751 If the vnode does already exist and has been published, the function fails. 1752 If it has not been published yet (i.e. after a successful new_vnode()), the 1753 function just marks the vnode published. If the vnode did not exist at all 1754 before, it is created and published. 1755 1756 If the function is successful, the caller owns a reference to the vnode. A 1757 sequence of new_vnode() and publish_vnode() results in just one reference as 1758 well. The reference can be surrendered by calling put_vnode(). 1759 1760 If called after a new_vnode() the \a privateNode and \a ops parameters must 1761 be the same as previously passed to new_vnode(). 1762 1763 This call is equivalent to the former BeOS R5 new_vnode() function. 1764 1765 \param volume The volume object. 1766 \param vnodeID The ID of the node. 1767 \param privateNode The private data handle to be associated with the node. 1768 \param ops The operation vector for this vnode. Is not copied and must be 1769 valid through the whole life time of the vnode. 1770 \param type The type of the node as it would appear in a stat::st_mode (with 1771 all non type-related bits set to 0). 1772 \param flags A bitwise combination of none or more of the following: 1773 - B_VNODE_PUBLISH_REMOVED: The node is published in "removed" state, 1774 i.e. it has no entry referring to it and releasing the last 1775 reference to the vnode will remove it. 1776 - B_VNODE_DONT_CREATE_SPECIAL_SUB_NODE: Normally for FIFO or socket type 1777 nodes the VFS creates sub node providing the associated 1778 functionality. This flag prevents that from happing. 1779 \return \c B_OK if everything went fine, another error code otherwise. 1780*/ 1781 1782/*! 1783 \fn status_t get_vnode(fs_volume *volume, ino_t vnodeID, 1784 void **_privateNode) 1785 \brief Retrieves the private data handle for the node with the given ID. 1786 1787 If the function is successful, the caller owns a reference to the vnode. The 1788 reference can be surrendered by calling put_vnode(). 1789 1790 \param volume The volume object. 1791 \param vnodeID The ID of the node. 1792 \param _privateNode Pointer to a pre-allocated variable the private data 1793 handle shall be written to. 1794 \return \c B_OK if everything went fine, another error code otherwise. 1795*/ 1796 1797/*! 1798 \fn status_t put_vnode(fs_volume *volume, ino_t vnodeID) 1799 \brief Surrenders a reference to the specified vnode. 1800 1801 When the last reference to the vnode has been put the VFS will call 1802 fs_vnode_ops::put_vnode() (eventually), respectively, if the node has been 1803 marked removed fs_vnode_ops::remove_vnode() (immediately). 1804 1805 \param volume The volume object. 1806 \param vnodeID The ID of the node. 1807 \return \c B_OK if everything went fine, another error code otherwise. 1808*/ 1809 1810/*! 1811 \fn status_t acquire_vnode(fs_volume *volume, ino_t vnodeID) 1812 \brief Acquires another reference to a vnode. 1813 1814 Similar to get_vnode() in that the function acquires a vnode reference. 1815 Unlike get_vnode() this function can also be invoked between new_vnode() 1816 and publish_vnode(). 1817 1818 \param volume The volume object. 1819 \param vnodeID The ID of the node. 1820 \return \c B_OK if everything went fine, another error code otherwise. 1821*/ 1822 1823/*! 1824 \fn status_t remove_vnode(fs_volume *volume, ino_t vnodeID) 1825 \brief Marks the specified vnode removed. 1826 1827 The caller must own a reference to the vnode or at least ensure that a 1828 reference to the vnode exists. The function does not surrender a reference, 1829 though. 1830 1831 As soon as the last reference to the vnode has been surrendered, the VFS 1832 invokes the node's \link fs_vnode_ops::remove_vnode remove_vnode() \endlink 1833 hook. 1834 1835 \param volume The volume object. 1836 \param vnodeID The ID of the node. 1837 \return \c B_OK if everything went fine, another error code otherwise. 1838*/ 1839 1840/*! 1841 \fn status_t unremove_vnode(fs_volume *volume, ino_t vnodeID) 1842 \brief Clears the "removed" mark of the specified vnode. 1843 1844 The caller must own a reference to the vnode or at least ensure that a 1845 reference to the vnode exists. 1846 1847 The function is usually called when the caller, who has invoked 1848 remove_vnode() before realizes that it is not possible to remove the node 1849 (e.g. due to an error). Afterwards the vnode will continue to exist as if 1850 remove_vnode() had never been invoked. 1851 1852 \param volume The volume object. 1853 \param vnodeID The ID of the node. 1854 \return \c B_OK if everything went fine, another error code otherwise. 1855*/ 1856 1857/*! 1858 \fn status_t get_vnode_removed(fs_volume *volume, ino_t vnodeID, 1859 bool *_removed) 1860 \brief Returns whether the specified vnode is marked removed. 1861 1862 The caller must own a reference to the vnode or at least ensure that a 1863 reference to the vnode exists. 1864 1865 \param volume The volume object. 1866 \param vnodeID The ID of the node. 1867 \param _removed Pointer to a pre-allocated variable set to \c true, if the 1868 node is marked removed, to \c false otherwise. 1869 \return \c B_OK if everything went fine, another error code otherwise. 1870*/ 1871 1872/*! 1873 \fn fs_volume* volume_for_vnode(fs_vnode *vnode) 1874 \brief Returns the volume object for a given vnode. 1875 1876 \param vnode The node object. 1877 \return The volume object for the given vnode. 1878*/ 1879 1880//! @} 1881 1882///// Notification Functions 1883 1884/*! 1885 \name Notification Functions 1886 1887 The following functions are used to implement the node monitor functionality 1888 in your file system. Whenever one of the below mentioned events occur, you 1889 have to call them. 1890 1891 The node monitor will then notify all registered listeners for the nodes 1892 that changed. 1893*/ 1894 1895//! @{ 1896 1897/*! 1898 \fn status_t notify_entry_created(dev_t device, ino_t directory, 1899 const char *name, ino_t node) 1900 \brief Notifies listeners that a file system entry has been created. 1901*/ 1902 1903/*! 1904 \fn status_t notify_entry_removed(dev_t device, ino_t directory, 1905 const char *name, ino_t node) 1906 \brief Notifies listeners that a file system entry has been removed. 1907*/ 1908 1909/*! 1910 \fn status_t notify_entry_moved(dev_t device, ino_t fromDirectory, 1911 const char *fromName, ino_t toDirectory, 1912 const char *toName, ino_t node) 1913 \brief Notifies listeners that a file system entry has been renamed and/or 1914 moved to another directory. 1915*/ 1916 1917/*! 1918 \fn status_t notify_stat_changed(dev_t device, ino_t directory, ino_t node, 1919 uint32 statFields) 1920 \brief Notifies listeners that certain \a statFields of a node were updated. 1921*/ 1922 1923/*! 1924 \fn status_t notify_attribute_changed(dev_t device, ino_t directory, 1925 ino_t node, const char *attribute, int32 cause) 1926 \brief Notifies listeners that an attribute of a node has been changed. 1927*/ 1928 1929/*! 1930 \fn status_t notify_query_entry_created(port_id port, int32 token, 1931 dev_t device, ino_t directory, const char *name, ino_t node) 1932 \brief Notifies listeners that an entry has entered the result set of a live 1933 query. 1934*/ 1935 1936/*! 1937 \fn status_t notify_query_entry_removed(port_id port, int32 token, 1938 dev_t device, ino_t directory, const char *name, ino_t node) 1939 \brief Notifies listeners that an entry has left the result set of a live 1940 query. 1941*/ 1942 1943//! @} 1944