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