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