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