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