1 .\" $NetBSD: puffs_ops.3,v 1.21.4.2 2009/04/12 02:24:16 snj Exp $
3 .\" Copyright (c) 2007 Antti Kantee. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nd puffs callback operations
38 .Fa "struct puffs_usermount *pu" "struct statvfs *sbp"
42 .Fa "struct puffs_usermount *pu" "int waitfor" "const struct puffs_cred *pcr"
46 .Fa "struct puffs_usermount *pu" "void *fid" "size_t fidsize"
47 .Fa "struct puffs_newinfo *pni"
51 .Fa "struct puffs_usermount *pu" "puffs_cooie_t cookie" "void *fid"
55 .Fn puffs_fs_suspend "struct puffs_usermount *pu" "int status"
58 .Fa "struct puffs_usermount *pu" "int flags"
62 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
63 .Fa "struct puffs_newinfo *pni" "const struct puffs_cn *pcn"
67 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
68 .Fa "struct puffs_newinfo *pni" "const struct puffs_cn *pcn"
69 .Fa "const struct vattr *vap"
73 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
74 .Fa "struct puffs_newinfo *pni" "const struct puffs_cn *pcn"
75 .Fa "const struct vattr *vap"
79 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "int mode"
80 .Fa "const struct puffs_cred *pcr"
84 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "int flags"
85 .Fa "const struct puffs_cred *pcr"
89 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "int mode"
90 .Fa "const struct puffs_cred *pcr"
93 .Fo puffs_node_getattr
94 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "struct vattr *vap"
95 .Fa "const struct puffs_cred *pcr"
98 .Fo puffs_node_setattr
99 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "const struct vattr *vap"
100 .Fa "const struct puffs_cred *pcr"
104 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "int *events"
108 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "int flags"
109 .Fa "const struct puffs_cred *pcr"
113 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
114 .Fa "const struct puffs_cred *pcr" "int flags" "off_t offlo" "off_t offhi"
118 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "off_t oldoff"
119 .Fa "off_t newoff" "const struct puffs_cred *pcr"
122 .Fo puffs_node_remove
123 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "puffs_cookie_t targ"
124 .Fa "const struct puffs_cn *pcn"
128 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "puffs_cookie_t targ"
129 .Fa "const struct puffs_cn *pcn"
132 .Fo puffs_node_rename
133 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "puffs_cookie_t src"
134 .Fa "const struct puffs_cn *pcn_src" "puffs_cookie_t targ_dir"
135 .Fa "puffs_cookie_t targ" "const struct puffs_cn *pcn_targ"
139 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
140 .Fa "struct puffs_newinfo *pni" "const struct puffs_cn *pcn"
141 .Fa "const struct vattr *vap"
145 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "puffs_cookie_t targ"
146 .Fa "const struct puffs_cn *pcn"
149 .Fo puffs_node_readdir
150 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "struct dirent *dent"
151 .Fa "off_t *readoff" "size_t *reslen" "const struct puffs_cred *pcr"
152 .Fa "int *eofflag" "off_t *cookies" "size_t *ncookies"
155 .Fo puffs_node_symlink
156 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
157 .Fa "struct puffs_newinfo *pni"
158 .Fa "const struct puffs_cn *pcn_src" "const struct vattr *vap"
159 .Fa "const char *link_target"
162 .Fo puffs_node_readlink
163 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
164 .Fa "const struct puffs_cred *pcr" "char *link" "size_t *linklen"
168 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "uint8_t *buf"
169 .Fa "off_t offset" "size_t *resid" "const struct puffs_cred *pcr" "int ioflag"
173 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc" "uint8_t *buf"
174 .Fa "off_t offset" "size_t *resid" "const struct puffs_cred *pcr" "int ioflag"
177 .Fn puffs_node_print "struct puffs_usermount *pu" "puffs_cookie_t opc"
179 .Fo puffs_node_reclaim
180 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
183 .Fo puffs_node_inactive
184 .Fa "struct puffs_usermount *pu" "puffs_cookie_t opc"
187 .Fn puffs_setback "struct puffs_cc *pcc" "int op"
189 .Fn puffs_newinfo_setcookie "struct puffs_newinfo *pni" "puffs_cookie_t cookie"
191 .Fn puffs_newinfo_setvtype "struct puffs_newinfo *pni" "enum vtype vtype"
193 .Fn puffs_newinfo_setsize "struct puffs_newinfo *pni" "voff_t size"
195 .Fn puffs_newinfo_setrdev "struct puffs_newinfo *pni" "dev_t rdev"
199 requires to function can be divided into two categories: file system
200 callbacks and node callbacks.
201 The former affect the entire file system while the latter are targeted
202 at a file or a directory and a file.
203 They are roughly equivalent to the vfs and vnode operations in the
206 All callbacks can be prototyped with the file system name and operation
208 .Fn PUFFSOP_PROTOS fsname .
209 .Ss File system callbacks (puffs_fs)
211 .It Fn puffs_fs_statvfs "pu" "sbp"
212 The following fields of the argument
216 * unsigned long f_bsize; file system block size
217 * unsigned long f_frsize; fundamental file system block size
218 * fsblkcnt_t f_blocks; number of blocks in file system,
219 * (in units of f_frsize)
221 * fsblkcnt_t f_bfree; free blocks avail in file system
222 * fsblkcnt_t f_bavail; free blocks avail to non-root
223 * fsblkcnt_t f_bresvd; blocks reserved for root
225 * fsfilcnt_t f_files; total file nodes in file system
226 * fsfilcnt_t f_ffree; free file nodes in file system
227 * fsfilcnt_t f_favail; free file nodes avail to non-root
228 * fsfilcnt_t f_fresvd; file nodes reserved for root
231 .It Fn puffs_fs_sync "pu" "waitfor" "pcr"
232 All the dirty buffers that have been cached at the file server
233 level including metadata should be committed to stable storage.
236 parameter affects the operation.
238 .Bl -tag -width XMNT_NOWAITX
240 Wait for all I/O for complete until returning.
242 Initiate I/O, but do not wait for completion.
244 Synchorize data not synchoronized by the file system syncer,
245 i.e. data not written when
251 The credentials for the initiator of the sync operation are present in
253 and will usually be either file system or kernel credentials, but might
254 also be user credentials.
255 However, most of the time it is advisable to sync regardless of the
256 credentials of the caller.
257 .It Fn puffs_fs_fhtonode "pu" "fid" "fidsize" "pni"
258 Translates a file handle
263 indicates how large the file handle is.
264 In case the file system's handles are static length, this parameter can
265 be ignored as the kernel guarantees all file handles passed to the file
266 server are of correct length.
267 For dynamic length handles the field should be examined and
269 returned in case the file handle length is not correct.
271 This function provides essentially the same information to the kernel as
272 .Fn puffs_node_lookup .
273 The information is necessary for creating a new vnode corresponding to
275 .It Fn puffs_fs_nodetofh "pu" "cookie" "fid" "fidsize"
276 Create a file handle from the node described by
278 The file handle should contain enough information to reliably identify
279 the node even after reboots and the pathname/inode being replaced by
281 If this is not possible, it is up to the author of the file system to
282 act responsibly and decide if the file system can support file handles
285 For file systems which want dynamic length file handles, this function
286 must check if the file handle space indicated by
288 is large enough to accommodate the file handle for the node.
289 If not, it must fill in the correct size and return
291 In either case, the handle length should be supplied to the kernel in
293 File systems with static length handles can ignore the size parameter as
294 the kernel always supplies the correct size buffer.
295 .It Fn puffs_fs_suspend "pu" "status"
296 Called when file system suspension reaches various phases.
299 for more information.
300 .It Fn puffs_fs_unmount "pu" "flags"
301 Unmount the file system.
302 The kernel has assumedly flushed all cached data when this callback
304 If the file system cannot currently be safely be unmounted, for whatever
305 reason, the kernel will honor an error value and not forcibly unmount.
308 is not honored by the file server, the kernel will forcibly unmount
312 These operations operate in the level of individual files.
313 The file cookie is always provided as the second argument
315 If the operation is for a file, it will be the cookie of the file.
316 The case the operation involves a directory (such as
317 .Dq create file in directory ) ,
318 the cookie will be for the directory.
319 Some operations take additional cookies to describe the rest of
321 The return value 0 signals success, else an appropriate errno value
323 Please note that neither this list nor the descriptions are complete.
325 .It Fn puffs_node_lookup "pu" "opc" "pni" "pcn"
326 This function is used to locate nodes, or in other words translate
327 pathname components to file system data structures.
328 The implementation should match the name in
330 against the existing entries in the directory provided by the cookie
332 If found, the cookie for the located node should be set in
335 .Fn puffs_newinfo_setcookie .
336 Additionally, the vnode type and size (latter applicable to regular files only)
338 .Fn puffs_newinfo_setvtype
340 .Fn puffs_newinfo_setsize ,
342 If the located entry is a block device or character device file,
343 the dev_t for the entry should be set using
344 .Fn puffs_newinfo_setrdev .
346 The type of operation is found from
347 .Va pcn-\*[Gt]pcn_nameiop :
348 .Bl -tag -width XPUFFSLOOKUP_LOOKUPX
349 .It Dv PUFFSLOOKUP_LOOKUP
350 Normal lookup operation.
351 .It Dv PUFFSLOOKUP_CREATE
352 Lookup to create a node.
353 .It Dv PUFFSLOOKUP_DELETE
354 Lookup for node deletion.
355 .It Dv PUFFSLOOKUP_RENAME
356 Lookup for the target of a rename operation (source will be looked
358 .Dv PUFFSLOOKUP_DELETE ) .
361 The final component from a pathname lookup usually requires special
363 It can be identified by looking at the
364 .Va pcn-\*[Gt]pcn_flags
366 .Dv PUFFSLOOKUP_ISLASTCN .
367 For example, in most cases the lookup operation will want to check if
368 a delete, rename or create operation has enough credentials to perform
371 The return value 0 signals a found node and a nonzero value signals
375 signals "success" for cases where the lookup operation is
376 .Dv PUFFSLOOKUP_CREATE
378 .Dv PUFFSLOOKUP_RENAME .
379 Failure in these cases can be signalled by returning another appropriate
380 error code, for example
383 Usually a null-terminated string for the next pathname component is
385 .Ar pcn-\*[Gt]pcn_name .
386 In case the file system is using the option
387 .Dv PUFFS_KFLAG_LOOKUP_FULLPNBUF ,
388 the remainder of the complete pathname under lookup is found in
390 .Ar pcn-\*[Gt]pcn_namelen
391 always specifies the length of the next component.
392 If operating with a full path, the file system is allowed to consume
393 more than the next component's length in node lookup.
394 This is done by setting
395 .Ar pcn-\*[Gt]pcn_consume
396 to indicate the amount of
398 characters in addition to
399 .Ar pcn-\*[Gt]pcn_namelen
401 .It Fn puffs_node_create "pu" "opc" "pni" "pcn" "va"
402 .It Fn puffs_node_mkdir "pu" "opc" "pni" "pcn" "va"
403 .It Fn puffs_node_mknod "pu" "opc" "pni" "pcn" "va"
404 A file node is created in the directory denoted by the cookie
406 by any of the above callbacks.
407 The name of the new file can be found from
409 and the attributes are specified by
411 and the cookie for the newly created node should be set in
413 The only difference between these three is that they create a regular
414 file, directory and device special file, respectively.
416 In case of mknod, the device identifier can be found in
417 .Fa va-\*[Gt]va_rdev .
418 .It Fn puffs_node_open "pu" "opc" "mode" "pcr"
419 Open the node denoted by the cookie
423 specifies the flags that
425 was called with, e.g.
429 .It Fn puffs_node_close "pu" "opc" "flags" "pcr"
433 parameter describes the flags that the file was opened with.
434 .It Fn puffs_node_access "pu" "opc" "mode" "pcr"
435 Check if the credentials of
437 have the right to perform the operation specified by
443 can specify read, write or execute by
449 .It Fn puffs_node_getattr "pu" "opc" "va" "pcr"
450 The attributes of the node specified by
452 must be copied to the space pointed by
454 .It Fn puffs_node_setattr "pu" "opc" "va" "pcr"
455 The attributes for the node specified by
457 must be set to those contained in
461 which contain a value different from
463 (typecast to the field's type!) contain a valid value.
464 .It Fn puffs_node_poll "pu" "opc" "events"
465 Poll for events on node
471 are available, the function should set the bitmask to match available
472 events and return immediately.
473 Otherwise, the function should block (yield) until some events in
475 become available and only then set the
479 In case this function returns an error,
483 equivalent) will be delivered to the calling process.
486 The system call interface for
488 contains a timeout parameter.
489 At this level, however, the timeout is not supplied.
490 In case input does not arrive, the file system should periodically
491 unblock and return 0 new events to avoid hanging forever.
492 This will hopefully be better supported by libpuffs in the future.
493 .It Fn puffs_node_mmap "pu" "opc" "flags" "pcr"
494 Called when a regular file is being memory mapped by
497 is currently always 0.
498 .It Fn puffs_node_fsync "pu" "opc" "pcr" "flags" "offlo" "offhi"
499 Sychronize a node's contents onto stable storage.
500 This is necessary only if the file server caches some information
501 before committing it.
504 specifies the minimum level of sychronization required (XXX: they are
510 specify the data offsets requiring to be synced.
511 A high offset of 0 means sync from
513 to the end of the file.
514 .It Fn puffs_node_seek "pu" "opc" "oldoff" "newoff" "pcr"
517 is seekable to the location
521 specifies the offset we are starting the seek from.
522 Most file systems dealing only with regular will choose to not
524 However, it is useful for example in cases where files are
526 .It Fn puffs_node_remove "pu" "opc" "targ" "pcn"
527 .It Fn puffs_node_rmdir "pu" "opc" "targ" "pcn"
530 from the directory indicated by
532 The directory entry name to be removed is provided by
534 The rmdir operation removes only directories, while the remove
535 operation removes all other types except directories.
537 It is paramount to note that the file system may not remove the
538 node data structures at this point, only the directory entry and prevent
539 lookups from finding the node again.
540 This is to retain the
543 The data may be removed only when
544 .Fn puffs_node_reclaim
545 is called for the node, as this assures there are no further users.
546 .It Fn puffs_node_link "pu" "opc" "targ" "pcn"
547 Create a hard link for the node
553 provides the directory entry name for the new link.
554 .It Fn puffs_node_rename "pu" "src_dir" "src" "pcn_src" "targ_dir" "targ" "pcn_targ"
557 with the name specified by
561 The target directory and target name are given by
567 the target node already exists, it is specified by
569 and must be replaced atomically.
575 It is legal to replace a directory node by another directory node with
576 the means of rename if the target directory is empty, otherwise
579 All other types can replace all other types.
580 In case a rename between incompatible types is attempted, the errors
584 should be returned, depending on the target type.
585 .It Fn puffs_node_readdir "pu" "opc" "dent" "readoff" "reslen" "pcr" "eofflag" "cookies" "ncookies"
586 To read directory entries,
587 .Fn puffs_node_readdir
589 It should store directories as
591 in the space pointed to by
593 The amount of space available is given by
595 and before returning it should be set to the amount of space
600 is used to specify the offset to the directory.
601 Its intepretation is up to the file system and it should be set to
602 signal the continuation point when there is no more room for the next
605 It is most performant to return the maximal amount of directory
607 It is easiest to generate directory entries by using
609 which also automatically advances the necessary pointers.
611 In case end-of-directory is reached,
613 should be set to one.
614 Note that even a new call to readdir may start where
616 points to end-of-directory.
618 If the file system supports file handles, the arguments
624 is a vector for offsets corresponding to read offsets.
625 One cookie should be filled out for each directory entry.
626 The value of the cookie should equal the offset of the
628 directory entry, i.e. which offset should be passed to readdir for
629 the first entry read to be the entry following the current one.
631 is the number of slots for cookies in the cookie vector upon entry to
632 the function and must be set to the amount of cookies stored in the
633 vector (i.e. amount of directory entries read) upon exit.
634 There is always enough space in the cookie vector for the maximal number
635 of entries that will fit into the directory entry buffer.
636 For filling out the vector, the helper function
637 .Fn PUFFS_STORE_DCOOKIE cookies ncookies offset
639 This properly checks against
645 must be initialized to zero before the first call to
646 .Fn PUFFS_STORE_DCOOKIE .
647 .It Fn puffs_node_symlink "pu" "opc" "pni" "pcn_src" "va" "link_target"
648 Create a symbolic link into the directory
652 and the initial attributes in
656 contains a null-terminated string for the link target.
657 The created node cookie should be set in
659 .It Fn puffs_node_readlink "pu" "opc" "pcr" "link" "linklen"
660 Read the target of a symbolic link
662 The result is placed in the buffer pointed to by
664 This buffer's length is given in
666 and it must be updated to reflect the real link length.
667 A terminating nul character should not be put into the buffer and
669 be included in the link length.
670 .It Fn puffs_node_read "pu" "opc" "buf" "offset" "resid" "pcr" "ioflag"
671 Read the contents of a file
673 It will gather the data from
675 in the file and read the number
678 The buffer is guaranteed to have this much space.
679 The amount of data requested by
681 should be read, except in the case of eof-of-file or an error.
684 should be set to indicate the amount of request NOT completed.
685 In the normal case this should be 0.
686 .It Fn puffs_node_write "pu" "opc" "buf" "offset" "resid" "pcr" "ioflag"
692 and extend the file if necessary.
693 The number of octets written is indicated by
695 everything must be written or an error will be generated.
696 The parameter must be set to indicate the amount of data NOT written.
699 is specified, the data should be appended to the end of the file.
700 .It Fn puffs_node_print "pu" "opc"
701 Print information about node. This is used only for kernel-initiated
703 .It Fn puffs_node_reclaim "pu" "opc"
704 The kernel will no longer reference the cookie and resources associated
705 with it may be freed.
708 has a link count of zero, it may be safely removed now.
709 .It Fn puffs_node_inactive "pu" "opc"
712 has lost its last reference in the kernel.
713 However, the cookie must still remain valid until
714 .Fn puffs_node_reclaim
716 .It Fn puffs_setback "pcc" "op"
717 Issue a "setback" operation which will be handled when the request response
718 is returned to the kernel.
719 Currently this can be only called from mmap, open, remove and rmdir.
720 The valid parameters for
723 .Dv PUFFS_SETBACK_INACT_N1
725 .Dv PUFFS_SETBACK_INACT_N2 .
726 These signal that a file system mounted with
727 .Dv PUFFS_KFLAG_IAONDEMAND
728 should call the file system inactive method for the specified node.
729 The node number 1 always means the operation cookie
731 while the node number 2 can be used to specify the second node argument
732 present in some methods, e.g. remove.
733 .It Fn puffs_newinfo_setcookie pni cookie
734 Set cookie for node provided by this method to
736 .It Fn puffs_newinfo_setvtype pni vtype
737 Set the type of the newly located node to
739 This call is valid only for
743 .It Fn puffs_newinfo_setsize pni size
744 Set the size of the newly located node to
746 If left unset, the value defaults to 0.
747 This call is valid only for
751 .It Fn puffs_newinfo_setrdev pni rdev
752 Set the type of the newly located node to
754 This call is valid only for
758 producing device type nodes.