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