fs: correct VATTR_XVATTR checks in XVA_* macros
[unleashed.git] / include / sys / vnode.h
blob19fb0d1f18d2b057c3858fde2cd191c8cccc238b
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2017, Joyent, Inc.
25 * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
41 #ifndef _SYS_VNODE_H
42 #define _SYS_VNODE_H
44 #include <sys/types.h>
45 #include <sys/t_lock.h>
46 #include <sys/rwstlock.h>
47 #include <sys/time_impl.h>
48 #include <sys/cred.h>
49 #include <sys/uio.h>
50 #include <sys/resource.h>
51 #include <vm/seg_enum.h>
52 #include <vm/object.h>
53 #include <sys/kstat.h>
54 #include <sys/kmem.h>
55 #include <sys/list.h>
56 #ifdef _KERNEL
57 #include <sys/buf.h>
58 #include <sys/sdt.h>
59 #endif /* _KERNEL */
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
66 * Statistics for all vnode operations.
67 * All operations record number of ops (since boot/mount/zero'ed).
68 * Certain I/O operations (read, write, readdir) also record number
69 * of bytes transferred.
70 * This appears in two places in the system: one is embedded in each
71 * vfs_t. There is also an array of vopstats_t structures allocated
72 * on a per-fstype basis.
75 #define VOPSTATS_STR "vopstats_" /* Initial string for vopstat kstats */
77 typedef struct vopstats {
78 kstat_named_t nopen; /* fop_open */
79 kstat_named_t nclose; /* fop_close */
80 kstat_named_t nread; /* fop_read */
81 kstat_named_t read_bytes;
82 kstat_named_t nwrite; /* fop_write */
83 kstat_named_t write_bytes;
84 kstat_named_t nioctl; /* fop_ioctl */
85 kstat_named_t nsetfl; /* fop_setfl */
86 kstat_named_t ngetattr; /* fop_getattr */
87 kstat_named_t nsetattr; /* fop_setattr */
88 kstat_named_t naccess; /* fop_access */
89 kstat_named_t nlookup; /* fop_lookup */
90 kstat_named_t ncreate; /* fop_create */
91 kstat_named_t nremove; /* fop_remove */
92 kstat_named_t nlink; /* fop_link */
93 kstat_named_t nrename; /* fop_rename */
94 kstat_named_t nmkdir; /* fop_mkdir */
95 kstat_named_t nrmdir; /* fop_rmdir */
96 kstat_named_t nreaddir; /* fop_readdir */
97 kstat_named_t readdir_bytes;
98 kstat_named_t nsymlink; /* fop_symlink */
99 kstat_named_t nreadlink; /* fop_readlink */
100 kstat_named_t nfsync; /* fop_fsync */
101 kstat_named_t ninactive; /* fop_inactive */
102 kstat_named_t nfid; /* fop_fid */
103 kstat_named_t nrwlock; /* fop_rwlock */
104 kstat_named_t nrwunlock; /* fop_rwunlock */
105 kstat_named_t nseek; /* fop_seek */
106 kstat_named_t ncmp; /* fop_cmp */
107 kstat_named_t nfrlock; /* fop_frlock */
108 kstat_named_t nspace; /* fop_space */
109 kstat_named_t nrealvp; /* fop_realvp */
110 kstat_named_t ngetpage; /* fop_getpage */
111 kstat_named_t nputpage; /* fop_putpage */
112 kstat_named_t nmap; /* fop_map */
113 kstat_named_t naddmap; /* fop_addmap */
114 kstat_named_t ndelmap; /* fop_delmap */
115 kstat_named_t npoll; /* fop_poll */
116 kstat_named_t ndump; /* fop_dump */
117 kstat_named_t npathconf; /* fop_pathconf */
118 kstat_named_t npageio; /* fop_pageio */
119 kstat_named_t ndumpctl; /* fop_dumpctl */
120 kstat_named_t ndispose; /* fop_dispose */
121 kstat_named_t nsetsecattr; /* fop_setsecattr */
122 kstat_named_t ngetsecattr; /* fop_getsecattr */
123 kstat_named_t nshrlock; /* fop_shrlock */
124 kstat_named_t nvnevent; /* fop_vnevent */
125 kstat_named_t nreqzcbuf; /* fop_reqzcbuf */
126 kstat_named_t nretzcbuf; /* fop_retzcbuf */
127 } vopstats_t;
130 * The vnode is the focus of all file activity in UNIX.
131 * A vnode is allocated for each active file, each current
132 * directory, each mounted-on file, and the root.
134 * Each vnode is usually associated with a file-system-specific node (for
135 * UFS, this is the in-memory inode). Generally, a vnode and an fs-node
136 * should be created and destroyed together as a pair.
138 * If a vnode is reused for a new file, it should be reinitialized by calling
139 * either vn_reinit() or vn_recycle().
141 * vn_reinit() resets the entire vnode as if it was returned by vn_alloc().
142 * The caller is responsible for setting up the entire vnode after calling
143 * vn_reinit(). This is important when using kmem caching where the vnode is
144 * allocated by a constructor, for instance.
146 * vn_recycle() is used when the file system keeps some state around in both
147 * the vnode and the associated FS-node. In UFS, for example, the inode of
148 * a deleted file can be reused immediately. The v_data, v_vfsp, v_op, etc.
149 * remains the same but certain fields related to the previous instance need
150 * to be reset. In particular:
151 * v_femhead
152 * v_path
153 * v_rdcnt, v_wrcnt
154 * v_mmap_read, v_mmap_write
158 * vnode types. VNON means no type. These values are unrelated to
159 * values in on-disk inodes.
161 typedef enum vtype {
162 VNON = 0,
163 VREG = 1,
164 VDIR = 2,
165 VBLK = 3,
166 VCHR = 4,
167 VLNK = 5,
168 VFIFO = 6,
169 VDOOR = 7,
170 VPROC = 8,
171 VSOCK = 9,
172 VPORT = 10,
173 VBAD = 11
174 } vtype_t;
177 * VSD - Vnode Specific Data
178 * Used to associate additional private data with a vnode.
180 struct vsd_node {
181 list_node_t vs_nodes; /* list of all VSD nodes */
182 uint_t vs_nkeys; /* entries in value array */
183 void **vs_value; /* array of value/key */
187 * Many of the fields in the vnode are read-only once they are initialized
188 * at vnode creation time. Other fields are protected by locks.
190 * IMPORTANT: vnodes should be created ONLY by calls to vn_alloc(). They
191 * may not be embedded into the file-system specific node (inode). The
192 * size of vnodes may change.
194 * The v_lock protects:
195 * v_flag
196 * v_stream
197 * v_count
198 * v_shrlocks
199 * v_path
200 * v_vsd
201 * v_xattrdir
203 * A special lock (implemented by vn_vfswlock in vnode.c) protects:
204 * v_vfsmountedhere
206 * The global flock_lock mutex (in flock.c) protects:
207 * v_filocks
209 * IMPORTANT NOTE:
211 * The following vnode fields are considered public and may safely be
212 * accessed by file systems or other consumers:
214 * v_lock
215 * v_flag
216 * v_count
217 * v_data
218 * v_vfsp
219 * v_stream
220 * v_type
221 * v_rdev
223 * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD.
224 * In particular, file systems should not access other fields; they may
225 * change or even be removed. The functionality which was once provided
226 * by these fields is available through vn_* functions.
228 * VNODE PATH THEORY:
229 * In each vnode, the v_path field holds a cached version of the canonical
230 * filesystem path which that node represents. Because vnodes lack contextual
231 * information about their own name or position in the VFS hierarchy, this path
232 * must be calculated when the vnode is instantiated by operations such as
233 * fop_create, fop_lookup, or fop_mkdir. During said operations, both the
234 * parent vnode (and its cached v_path) and future name are known, so the
235 * v_path of the resulting object can easily be set.
237 * The caching nature of v_path is complicated in the face of directory
238 * renames. Filesystem drivers are responsible for calling vn_renamepath when
239 * a fop_rename operation succeeds. While the v_path on the renamed vnode will
240 * be updated, existing children of the directory (direct, or at deeper levels)
241 * will now possess v_path caches which are stale.
243 * It is expensive (and for non-directories, impossible) to recalculate stale
244 * v_path entries during operations such as vnodetopath. The best time during
245 * which to correct such wrongs is the same as when v_path is first
246 * initialized: during fop_create/fop_lookup/fop_mkdir/etc, where adequate
247 * context is available to generate the current path.
249 * In order to quickly detect stale v_path entries (without full lookup
250 * verification) to trigger a v_path update, the v_path_stamp field has been
251 * added to vnode_t. As part of successful fop_create/fop_lookup/fop_mkdir
252 * operations, where the name and parent vnode are available, the following
253 * rules are used to determine updates to the child:
255 * 1. If the parent lacks a v_path, clear any existing v_path and v_path_stamp
256 * on the child. Until the parent v_path is refreshed to a valid state, the
257 * child v_path must be considered invalid too.
259 * 2. If the child lacks a v_path (implying v_path_stamp == 0), it inherits the
260 * v_path_stamp value from its parent and its v_path is updated.
262 * 3. If the child v_path_stamp is less than v_path_stamp in the parent, it is
263 * an indication that the child v_path is stale. The v_path is updated and
264 * v_path_stamp in the child is set to the current hrtime().
266 * It does _not_ inherit the parent v_path_stamp in order to propagate the
267 * the time of v_path invalidation through the directory structure. This
268 * prevents concurrent invalidations (operating with a now-incorrect v_path)
269 * at deeper levels in the tree from persisting.
271 * 4. If the child v_path_stamp is greater or equal to the parent, no action
272 * needs to be taken.
274 * Note that fop_rename operations do not follow this ruleset. They perform an
275 * explicit update of v_path and v_path_stamp (setting it to the current time)
277 * With these constraints in place, v_path invalidations and updates should
278 * proceed in a timely manner as vnodes are accessed. While there still are
279 * limited cases where vnodetopath operations will fail, the risk is minimized.
282 struct fem_head; /* from fem.h */
284 typedef struct vnode {
285 kmutex_t v_lock; /* protects vnode fields */
286 uint_t v_flag; /* vnode flags (see below) */
287 uint_t v_count; /* reference count */
288 void *v_data; /* private data for fs */
289 struct vfs *v_vfsp; /* ptr to containing VFS */
290 struct stdata *v_stream; /* associated stream */
291 enum vtype v_type; /* vnode type */
292 dev_t v_rdev; /* device (VCHR, VBLK) */
294 /* PRIVATE FIELDS BELOW - DO NOT USE */
296 struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */
297 const struct vnodeops *v_op; /* vnode operations */
298 struct filock *v_filocks; /* ptr to filock list */
299 struct shrlocklist *v_shrlocks; /* ptr to shrlock list */
300 krwlock_t v_nbllock; /* sync for NBMAND locks */
301 kcondvar_t v_cv; /* synchronize locking */
302 void *v_locality; /* hook for locality info */
303 struct fem_head *v_femhead; /* fs monitoring */
304 char *v_path; /* cached path */
305 hrtime_t v_path_stamp; /* timestamp for cached path */
306 uint_t v_rdcnt; /* open for read count (VREG only) */
307 uint_t v_wrcnt; /* open for write count (VREG only) */
308 u_longlong_t v_mmap_read; /* mmap read count */
309 u_longlong_t v_mmap_write; /* mmap write count */
310 void *v_mpssdata; /* info for large page mappings */
311 void *v_fopdata; /* list of file ops event watches */
312 kmutex_t v_vsd_lock; /* protects v_vsd field */
313 struct vsd_node *v_vsd; /* vnode specific data */
314 struct vnode *v_xattrdir; /* unnamed extended attr dir (GFS) */
315 uint_t v_count_dnlc; /* dnlc reference count */
317 struct vmobject v_object;
318 } vnode_t;
320 #define IS_DEVVP(vp) \
321 ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
323 #define VNODE_ALIGN 64
324 /* Count of low-order 0 bits in a vnode *, based on size and alignment. */
325 #if defined(_LP64)
326 #define VNODE_ALIGN_LOG2 8
327 #else
328 #define VNODE_ALIGN_LOG2 7
329 #endif
332 * vnode flags.
334 #define VROOT 0x01 /* root of its file system */
335 #define VNOCACHE 0x02 /* don't keep cache pages on vnode */
336 #define VNOMAP 0x04 /* file cannot be mapped/faulted */
337 #define VDUP 0x08 /* file should be dup'ed rather then opened */
338 #define VNOSWAP 0x10 /* file cannot be used as virtual swap device */
339 #define VNOMOUNT 0x20 /* file cannot be covered by mount */
340 #define VISSWAP 0x40 /* vnode is being used for swap */
341 #define VSWAPLIKE 0x80 /* vnode acts like swap (but may not be) */
343 #define IS_SWAPVP(vp) (((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0)
345 typedef struct vn_vfslocks_entry {
346 rwstlock_t ve_lock;
347 void *ve_vpvfs;
348 struct vn_vfslocks_entry *ve_next;
349 uint32_t ve_refcnt;
350 char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \
351 sizeof (uint32_t)];
352 } vn_vfslocks_entry_t;
355 * The following two flags are used to lock the v_vfsmountedhere field
357 #define VVFSLOCK 0x100
358 #define VVFSWAIT 0x200
361 * Used to serialize VM operations on a vnode
363 #define VVMLOCK 0x400
366 * Tell vn_open() not to fail a directory open for writing but
367 * to go ahead and call fop_open() to let the filesystem check.
369 #define VDIROPEN 0x800
372 * Flag to let the VM system know that this file is most likely a binary
373 * or shared library since it has been mmap()ed EXEC at some time.
375 #define VVMEXEC 0x1000
377 #define V_XATTRDIR 0x4000 /* attribute unnamed directory */
379 #define IS_XATTRDIR(vp) ((vp)->v_flag & V_XATTRDIR)
381 #define V_LOCALITY 0x8000 /* whether locality aware */
384 * Flag that indicates the VM should maintain the v_object's list with all
385 * modified pages on one end and unmodified pages at the other. This makes
386 * finding dirty pages to write back to disk much faster at the expense of
387 * taking a minor fault on the first store instruction which touches a
388 * writable page.
390 #define VMODSORT (0x10000)
391 #define IS_VMODSORT(vp) (((vp)->v_flag & VMODSORT) != 0)
393 #define VISSWAPFS 0x20000 /* vnode is being used for swapfs */
396 * The mdb memstat command assumes that IS_SWAPFSVP only uses the
397 * vnode's v_flag field. If this changes, cache the additional
398 * fields in mdb; see vn_get in mdb/common/modules/genunix/memory.c
400 #define IS_SWAPFSVP(vp) (((vp)->v_flag & VISSWAPFS) != 0)
402 #define V_SYSATTR 0x40000 /* vnode is a GFS system attribute */
405 * Indication that VOP_LOOKUP operations on this vnode may yield results from a
406 * different VFS instance. The main use of this is to suppress v_path
407 * calculation logic when filesystems such as procfs emit results which defy
408 * expectations about normal VFS behavior.
410 #define VTRAVERSE 0x80000
413 * Vnode attributes. A bit-mask is supplied as part of the
414 * structure to indicate the attributes the caller wants to
415 * set (setattr) or extract (getattr).
419 * Note that va_nodeid and va_nblocks are 64bit data type.
420 * We support large files over NFSV3. With Solaris client and
421 * Server that generates 64bit ino's and sizes these fields
422 * will overflow if they are 32 bit sizes.
425 typedef struct vattr {
426 uint_t va_mask; /* bit-mask of attributes */
427 vtype_t va_type; /* vnode type (for create) */
428 mode_t va_mode; /* file access mode */
429 uid_t va_uid; /* owner user id */
430 gid_t va_gid; /* owner group id */
431 dev_t va_fsid; /* file system id (dev for now) */
432 u_longlong_t va_nodeid; /* node id */
433 nlink_t va_nlink; /* number of references to file */
434 uoff_t va_size; /* file size in bytes */
435 timestruc_t va_atime; /* time of last access */
436 timestruc_t va_mtime; /* time of last modification */
437 timestruc_t va_ctime; /* time of last status change */
438 dev_t va_rdev; /* device the file represents */
439 uint_t va_blksize; /* fundamental block size */
440 u_longlong_t va_nblocks; /* # of blocks allocated */
441 uint_t va_seq; /* sequence number */
442 } vattr_t;
444 #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
447 * Structure of all optional attributes.
449 typedef struct xoptattr {
450 timestruc_t xoa_createtime; /* Create time of file */
451 uint8_t xoa_archive;
452 uint8_t xoa_system;
453 uint8_t xoa_readonly;
454 uint8_t xoa_hidden;
455 uint8_t xoa_nounlink;
456 uint8_t xoa_immutable;
457 uint8_t xoa_appendonly;
458 uint8_t xoa_nodump;
459 uint8_t xoa_opaque;
460 uint8_t xoa_av_quarantined;
461 uint8_t xoa_av_modified;
462 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ];
463 uint8_t xoa_reparse;
464 uint64_t xoa_generation;
465 uint8_t xoa_offline;
466 uint8_t xoa_sparse;
467 } xoptattr_t;
470 * The xvattr structure is really a variable length structure that
471 * is made up of:
472 * - The classic vattr_t (xva_vattr)
473 * - a 32 bit quantity (xva_mapsize) that specifies the size of the
474 * attribute bitmaps in 32 bit words.
475 * - A pointer to the returned attribute bitmap (needed because the
476 * previous element, the requested attribute bitmap) is variable lenth.
477 * - The requested attribute bitmap, which is an array of 32 bit words.
478 * Callers use the XVA_SET_REQ() macro to set the bits corresponding to
479 * the attributes that are being requested.
480 * - The returned attribute bitmap, which is an array of 32 bit words.
481 * File systems that support optional attributes use the XVA_SET_RTN()
482 * macro to set the bits corresponding to the attributes that are being
483 * returned.
484 * - The xoptattr_t structure which contains the attribute values
486 * xva_mapsize determines how many words in the attribute bitmaps.
487 * Immediately following the attribute bitmaps is the xoptattr_t.
488 * xva_getxoptattr() is used to get the pointer to the xoptattr_t
489 * section.
492 #define XVA_MAPSIZE 3 /* Size of attr bitmaps */
493 #define XVA_MAGIC 0x78766174 /* Magic # for verification */
496 * The xvattr structure is an extensible structure which permits optional
497 * attributes to be requested/returned. File systems may or may not support
498 * optional attributes. They do so at their own discretion but if they do
499 * support optional attributes, they must register the VFSFT_XVATTR feature
500 * so that the optional attributes can be set/retrived.
502 * The fields of the xvattr structure are:
504 * xva_vattr - The first element of an xvattr is a legacy vattr structure
505 * which includes the common attributes. If VATTR_XVATTR is set in the va_mask
506 * then the entire structure is treated as an xvattr. If VATTR_XVATTR is not
507 * set, then only the xva_vattr structure can be used.
509 * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
511 * xva_mapsize - Size of requested and returned attribute bitmaps.
513 * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the
514 * size of the array before it, xva_reqattrmap[], could change which means
515 * the location of xva_rtnattrmap[] could change. This will allow unbundled
516 * file systems to find the location of xva_rtnattrmap[] when the sizes change.
518 * xva_reqattrmap[] - Array of requested attributes. Attributes are
519 * represented by a specific bit in a specific element of the attribute
520 * map array. Callers set the bits corresponding to the attributes
521 * that the caller wants to get/set.
523 * xva_rtnattrmap[] - Array of attributes that the file system was able to
524 * process. Not all file systems support all optional attributes. This map
525 * informs the caller which attributes the underlying file system was able
526 * to set/get. (Same structure as the requested attributes array in terms
527 * of each attribute corresponding to specific bits and array elements.)
529 * xva_xoptattrs - Structure containing values of optional attributes.
530 * These values are only valid if the corresponding bits in xva_reqattrmap
531 * are set and the underlying file system supports those attributes.
533 typedef struct xvattr {
534 vattr_t xva_vattr; /* Embedded vattr structure */
535 uint32_t xva_magic; /* Magic Number */
536 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
537 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
538 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
539 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
540 xoptattr_t xva_xoptattrs; /* Optional attributes */
541 } xvattr_t;
543 #ifdef _SYSCALL32
545 * For bigtypes time_t changed to 64 bit on the 64-bit kernel.
546 * Define an old version for user/kernel interface
549 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
550 #pragma pack(4)
551 #endif
553 typedef struct vattr32 {
554 uint32_t va_mask; /* bit-mask of attributes */
555 vtype_t va_type; /* vnode type (for create) */
556 mode32_t va_mode; /* file access mode */
557 uid32_t va_uid; /* owner user id */
558 gid32_t va_gid; /* owner group id */
559 dev32_t va_fsid; /* file system id (dev for now) */
560 u_longlong_t va_nodeid; /* node id */
561 nlink_t va_nlink; /* number of references to file */
562 uoff_t va_size; /* file size in bytes */
563 timestruc32_t va_atime; /* time of last access */
564 timestruc32_t va_mtime; /* time of last modification */
565 timestruc32_t va_ctime; /* time of last status change */
566 dev32_t va_rdev; /* device the file represents */
567 uint32_t va_blksize; /* fundamental block size */
568 u_longlong_t va_nblocks; /* # of blocks allocated */
569 uint32_t va_seq; /* sequence number */
570 } vattr32_t;
572 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
573 #pragma pack()
574 #endif
576 #else /* not _SYSCALL32 */
577 #define vattr32 vattr
578 typedef vattr_t vattr32_t;
579 #endif /* _SYSCALL32 */
582 * Attributes of interest to the caller of setattr or getattr.
584 #define VATTR_TYPE 0x00001
585 #define VATTR_MODE 0x00002
586 #define VATTR_UID 0x00004
587 #define VATTR_GID 0x00008
588 #define VATTR_FSID 0x00010
589 #define VATTR_NODEID 0x00020
590 #define VATTR_NLINK 0x00040
591 #define VATTR_SIZE 0x00080
592 #define VATTR_ATIME 0x00100
593 #define VATTR_MTIME 0x00200
594 #define VATTR_CTIME 0x00400
595 #define VATTR_RDEV 0x00800
596 #define VATTR_BLKSIZE 0x01000
597 #define VATTR_NBLOCKS 0x02000
598 /* 0x04000 */ /* unused */
599 #define VATTR_SEQ 0x08000
601 * If VATTR_XVATTR is set then there are additional bits to process in
602 * the xvattr_t's attribute bitmap. If this is not set then the bitmap
603 * MUST be ignored. Note that this bit must be set/cleared explicitly.
604 * That is, setting VATTR_ALL will NOT set VATTR_XVATTR.
606 #define VATTR_XVATTR 0x10000
608 #define VATTR_ALL (VATTR_TYPE | VATTR_MODE | VATTR_UID | VATTR_GID | \
609 VATTR_FSID | VATTR_NODEID | VATTR_NLINK | \
610 VATTR_SIZE | VATTR_ATIME | VATTR_MTIME | \
611 VATTR_CTIME | VATTR_RDEV | VATTR_BLKSIZE | \
612 VATTR_NBLOCKS | VATTR_SEQ)
614 #define VATTR_STAT (VATTR_MODE | VATTR_UID | VATTR_GID | VATTR_FSID | \
615 VATTR_NODEID | VATTR_NLINK | VATTR_SIZE | \
616 VATTR_ATIME | VATTR_MTIME | VATTR_CTIME | \
617 VATTR_RDEV | VATTR_TYPE)
619 #define VATTR_TIMES (VATTR_ATIME | VATTR_MTIME | VATTR_CTIME)
621 #define VATTR_NOSET (VATTR_NLINK | VATTR_RDEV | VATTR_FSID | \
622 VATTR_NODEID | VATTR_TYPE | VATTR_BLKSIZE | \
623 VATTR_NBLOCKS | VATTR_SEQ)
626 * Attribute bits used in the extensible attribute's (xva's) attribute
627 * bitmaps. Note that the bitmaps are made up of a variable length number
628 * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n"
629 * is the element in the bitmap (starting at 1). This convention is for
630 * the convenience of the maintainer to keep track of which element each
631 * attribute belongs to.
633 * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS
634 * MUST USE THE XAT_* DEFINES.
636 #define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */
637 #define XAT0_CREATETIME 0x00000001 /* Create time of file */
638 #define XAT0_ARCHIVE 0x00000002 /* Archive */
639 #define XAT0_SYSTEM 0x00000004 /* System */
640 #define XAT0_READONLY 0x00000008 /* Readonly */
641 #define XAT0_HIDDEN 0x00000010 /* Hidden */
642 #define XAT0_NOUNLINK 0x00000020 /* Nounlink */
643 #define XAT0_IMMUTABLE 0x00000040 /* immutable */
644 #define XAT0_APPENDONLY 0x00000080 /* appendonly */
645 #define XAT0_NODUMP 0x00000100 /* nodump */
646 #define XAT0_OPAQUE 0x00000200 /* opaque */
647 #define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */
648 #define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */
649 #define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */
650 #define XAT0_REPARSE 0x00002000 /* FS reparse point */
651 #define XAT0_GEN 0x00004000 /* object generation number */
652 #define XAT0_OFFLINE 0x00008000 /* offline */
653 #define XAT0_SPARSE 0x00010000 /* sparse */
655 #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
656 XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
657 XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \
658 XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE)
660 /* Support for XAT_* optional attributes */
661 #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */
662 #define XVA_SHFT 32 /* Used to shift index */
665 * Used to pry out the index and attribute bits from the XAT_* attributes
666 * defined below. Note that we're masking things down to 32 bits then
667 * casting to uint32_t.
669 #define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
670 #define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK))
673 * The following defines present a "flat namespace" so that consumers don't
674 * need to keep track of which element belongs to which bitmap entry.
676 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
678 #define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
679 #define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
680 #define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
681 #define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
682 #define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
683 #define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
684 #define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
685 #define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
686 #define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
687 #define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
688 #define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
689 #define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
690 #define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
691 #define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
692 #define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
693 #define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
694 #define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
697 * The returned attribute map array (xva_rtnattrmap[]) is located past the
698 * requested attribute map array (xva_reqattrmap[]). Its location changes
699 * when the array sizes change. We use a separate pointer in a known location
700 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is
701 * set in xva_init()
703 #define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp)
706 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
707 * of requested attributes (xva_reqattrmap[]).
709 #define XVA_SET_REQ(xvap, attr) \
710 ASSERT((xvap)->xva_vattr.va_mask & VATTR_XVATTR); \
711 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
712 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
714 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
715 * of requested attributes (xva_reqattrmap[]).
717 #define XVA_CLR_REQ(xvap, attr) \
718 ASSERT((xvap)->xva_vattr.va_mask & VATTR_XVATTR); \
719 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
720 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
723 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
724 * of returned attributes (xva_rtnattrmap[]).
726 #define XVA_SET_RTN(xvap, attr) \
727 ASSERT((xvap)->xva_vattr.va_mask & VATTR_XVATTR); \
728 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
729 (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
732 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
733 * to see of the corresponding attribute bit is set. If so, returns non-zero.
735 #define XVA_ISSET_REQ(xvap, attr) \
736 ((((xvap)->xva_vattr.va_mask & VATTR_XVATTR) && \
737 ((xvap)->xva_magic == XVA_MAGIC) && \
738 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
739 ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
742 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
743 * to see of the corresponding attribute bit is set. If so, returns non-zero.
745 #define XVA_ISSET_RTN(xvap, attr) \
746 ((((xvap)->xva_vattr.va_mask & VATTR_XVATTR) && \
747 ((xvap)->xva_magic == XVA_MAGIC) && \
748 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
749 ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
752 * Modes. Some values same as S_xxx entries from stat.h for convenience.
754 #define VSUID 04000 /* set user id on execution */
755 #define VSGID 02000 /* set group id on execution */
756 #define VSVTX 01000 /* save swapped text even after use */
759 * Permissions.
761 #define VREAD 00400
762 #define VWRITE 00200
763 #define VEXEC 00100
765 #define MODEMASK 07777 /* mode bits plus permission bits */
766 #define PERMMASK 00777 /* permission bits */
769 * fop_access flags
771 #define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */
772 #define V_APPEND 0x2 /* want to do append only check */
775 * Check whether mandatory file locking is enabled.
778 #define MANDMODE(mode) (((mode) & (VSGID|(VEXEC>>3))) == VSGID)
779 #define MANDLOCK(vp, mode) ((vp)->v_type == VREG && MANDMODE(mode))
782 * Flags for vnode operations.
784 enum rm { RMFILE, RMDIRECTORY }; /* rm or rmdir (remove) */
785 enum symfollow { NO_FOLLOW, FOLLOW }; /* follow symlinks (or not) */
786 enum vcexcl { NONEXCL, EXCL }; /* (non)excl create */
787 enum create { CRCREAT, CRMKNOD, CRMKDIR }; /* reason for create */
789 typedef enum rm rm_t;
790 typedef enum symfollow symfollow_t;
791 typedef enum vcexcl vcexcl_t;
792 typedef enum create create_t;
795 * Vnode Events - Used by fop_vnevent
796 * The VE_PRE_RENAME_* events fire before the rename operation and are
797 * primarily used for specialized applications, such as NFSv4 delegation, which
798 * need to know about rename before it occurs.
800 typedef enum vnevent {
801 VE_SUPPORT = 0, /* Query */
802 VE_RENAME_SRC = 1, /* Rename, with vnode as source */
803 VE_RENAME_DEST = 2, /* Rename, with vnode as target/destination */
804 VE_REMOVE = 3, /* Remove of vnode's name */
805 VE_RMDIR = 4, /* Remove of directory vnode's name */
806 VE_CREATE = 5, /* Create with vnode's name which exists */
807 VE_LINK = 6, /* Link with vnode's name as source */
808 VE_RENAME_DEST_DIR = 7, /* Rename with vnode as target dir */
809 VE_MOUNTEDOVER = 8, /* File or Filesystem got mounted over vnode */
810 VE_TRUNCATE = 9, /* Truncate */
811 VE_PRE_RENAME_SRC = 10, /* Pre-rename, with vnode as source */
812 VE_PRE_RENAME_DEST = 11, /* Pre-rename, with vnode as target/dest. */
813 VE_PRE_RENAME_DEST_DIR = 12 /* Pre-rename with vnode as target dir */
814 } vnevent_t;
817 * Values for checking vnode open and map counts
819 enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR };
821 typedef enum v_mode v_mode_t;
824 * Structure used on fop_getsecattr and fop_setsecattr operations
827 typedef struct vsecattr {
828 uint_t vsa_mask; /* See below */
829 int vsa_aclcnt; /* ACL entry count */
830 void *vsa_aclentp; /* pointer to ACL entries */
831 int vsa_dfaclcnt; /* default ACL entry count */
832 void *vsa_dfaclentp; /* pointer to default ACL entries */
833 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
834 uint_t vsa_aclflags; /* ACE ACL flags */
835 } vsecattr_t;
837 /* vsa_mask values */
838 #define VSA_ACL 0x0001
839 #define VSA_ACLCNT 0x0002
840 #define VSA_DFACL 0x0004
841 #define VSA_DFACLCNT 0x0008
842 #define VSA_ACE 0x0010
843 #define VSA_ACECNT 0x0020
844 #define VSA_ACE_ALLTYPES 0x0040
845 #define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */
848 * Structure used by various vnode operations to determine
849 * the context (pid, host, identity) of a caller.
851 * The cc_caller_id is used to identify one or more callers who invoke
852 * operations, possibly on behalf of others. For example, the NFS
853 * server could have it's own cc_caller_id which can be detected by
854 * vnode/vfs operations or (FEM) monitors on those operations. New
855 * caller IDs are generated by fs_new_caller_id().
857 typedef struct caller_context {
858 pid_t cc_pid; /* Process ID of the caller */
859 int cc_sysid; /* System ID, used for remote calls */
860 u_longlong_t cc_caller_id; /* Identifier for (set of) caller(s) */
861 ulong_t cc_flags;
862 } caller_context_t;
865 * Flags for caller context. The caller sets CC_DONTBLOCK if it does not
866 * want to block inside of a FEM monitor. The monitor will set CC_WOULDBLOCK
867 * and return EAGAIN if the operation would have blocked.
869 #define CC_WOULDBLOCK 0x01
870 #define CC_DONTBLOCK 0x02
873 * Structure tags for function prototypes, defined elsewhere.
875 struct pathname;
876 struct fid;
877 struct flock64;
878 struct flk_callback;
879 struct shrlock;
880 struct page;
881 struct seg;
882 struct as;
883 struct pollhead;
884 struct taskq;
886 #ifdef _KERNEL
889 * Operations on vnodes.
891 typedef struct vnodeops {
892 const char *vnop_name;
893 int (*vop_open)(struct vnode **, int, cred_t *, caller_context_t *);
894 int (*vop_close)(struct vnode *, int, int, offset_t, cred_t *,
895 caller_context_t *);
896 int (*vop_read)(struct vnode *, uio_t *, int, cred_t *,
897 caller_context_t *);
898 int (*vop_write)(struct vnode *, uio_t *, int, cred_t *,
899 caller_context_t *);
900 int (*vop_ioctl)(struct vnode *, int, intptr_t, int, cred_t *,
901 int *, caller_context_t *);
902 int (*vop_setfl)(struct vnode *, int, int, cred_t *,
903 caller_context_t *);
904 int (*vop_getattr)(struct vnode *, vattr_t *, int, cred_t *,
905 caller_context_t *);
906 int (*vop_setattr)(struct vnode *, vattr_t *, int, cred_t *,
907 caller_context_t *);
908 int (*vop_access)(struct vnode *, int, int, cred_t *,
909 caller_context_t *);
910 int (*vop_lookup)(struct vnode *, char *, struct vnode **,
911 struct pathname *, int, struct vnode *, cred_t *,
912 caller_context_t *, int *, struct pathname *);
913 int (*vop_create)(struct vnode *, char *, vattr_t *, vcexcl_t,
914 int, struct vnode **, cred_t *, int,
915 caller_context_t *, vsecattr_t *);
916 int (*vop_remove)(struct vnode *, char *, cred_t *,
917 caller_context_t *, int);
918 int (*vop_link)(struct vnode *, struct vnode *, char *, cred_t *,
919 caller_context_t *, int);
920 int (*vop_rename)(struct vnode *, char *, struct vnode *, char *,
921 cred_t *, caller_context_t *, int);
922 int (*vop_mkdir)(struct vnode *, char *, vattr_t *, struct vnode **,
923 cred_t *, caller_context_t *, int, vsecattr_t *);
924 int (*vop_rmdir)(struct vnode *, char *, struct vnode *, cred_t *,
925 caller_context_t *, int);
926 int (*vop_readdir)(struct vnode *, uio_t *, cred_t *, int *,
927 caller_context_t *, int);
928 int (*vop_symlink)(struct vnode *, char *, vattr_t *, char *,
929 cred_t *, caller_context_t *, int);
930 int (*vop_readlink)(struct vnode *, uio_t *, cred_t *,
931 caller_context_t *);
932 int (*vop_fsync)(struct vnode *, int, cred_t *, caller_context_t *);
933 void (*vop_inactive)(struct vnode *, cred_t *, caller_context_t *);
934 int (*vop_fid)(struct vnode *, struct fid *, caller_context_t *);
935 int (*vop_rwlock)(struct vnode *, int, caller_context_t *);
936 void (*vop_rwunlock)(struct vnode *, int, caller_context_t *);
937 int (*vop_seek)(struct vnode *, offset_t, offset_t *,
938 caller_context_t *);
939 int (*vop_cmp)(struct vnode *, struct vnode *, caller_context_t *);
940 int (*vop_frlock)(struct vnode *, int, struct flock64 *, int, offset_t,
941 struct flk_callback *, cred_t *, caller_context_t *);
942 int (*vop_space)(struct vnode *, int, struct flock64 *,
943 int, offset_t, cred_t *, caller_context_t *);
944 int (*vop_realvp)(struct vnode *, struct vnode **, caller_context_t *);
945 int (*vop_getpage)(struct vnode *, offset_t, size_t, uint_t *,
946 struct page **, size_t, struct seg *, caddr_t,
947 enum seg_rw, cred_t *, caller_context_t *);
948 int (*vop_putpage)(struct vnode *, offset_t, size_t,
949 int, cred_t *, caller_context_t *);
950 int (*vop_map)(struct vnode *, offset_t, struct as *,
951 caddr_t *, size_t, uchar_t, uchar_t, uint_t, cred_t *,
952 caller_context_t *);
953 int (*vop_addmap)(struct vnode *, offset_t, struct as *,
954 caddr_t, size_t, uchar_t, uchar_t, uint_t, cred_t *,
955 caller_context_t *);
956 int (*vop_delmap)(struct vnode *, offset_t, struct as *,
957 caddr_t, size_t, uint_t, uint_t, uint_t, cred_t *,
958 caller_context_t *);
959 int (*vop_poll)(struct vnode *, short, int, short *,
960 struct pollhead **, caller_context_t *);
961 int (*vop_dump)(struct vnode *, caddr_t, offset_t, offset_t,
962 caller_context_t *);
963 int (*vop_pathconf)(struct vnode *, int, ulong_t *, cred_t *,
964 caller_context_t *);
965 int (*vop_pageio)(struct vnode *, struct page *,
966 uoff_t, size_t, int, cred_t *, caller_context_t *);
967 int (*vop_dumpctl)(struct vnode *, int, offset_t *, caller_context_t *);
968 void (*vop_dispose)(struct vnode *, struct page *,
969 int, int, cred_t *, caller_context_t *);
970 int (*vop_setsecattr)(struct vnode *, vsecattr_t *,
971 int, cred_t *, caller_context_t *);
972 int (*vop_getsecattr)(struct vnode *, vsecattr_t *,
973 int, cred_t *, caller_context_t *);
974 int (*vop_shrlock)(struct vnode *, int, struct shrlock *,
975 int, cred_t *, caller_context_t *);
976 int (*vop_vnevent)(struct vnode *, vnevent_t, struct vnode *,
977 char *, caller_context_t *);
978 int (*vop_reqzcbuf)(struct vnode *, enum uio_rw, xuio_t *,
979 cred_t *, caller_context_t *);
980 int (*vop_retzcbuf)(struct vnode *, xuio_t *, cred_t *,
981 caller_context_t *);
982 } vnodeops_t;
984 typedef int (*fs_generic_func_p) (); /* Generic vop/vfsop/femop/fsemop ptr */
986 extern int fop_open(vnode_t **, int, cred_t *, caller_context_t *);
987 extern int fop_close(vnode_t *, int, int, offset_t, cred_t *,
988 caller_context_t *);
989 extern int fop_read(vnode_t *, uio_t *, int, cred_t *, caller_context_t *);
990 extern int fop_write(vnode_t *, uio_t *, int, cred_t *,
991 caller_context_t *);
992 extern int fop_ioctl(vnode_t *, int, intptr_t, int, cred_t *, int *,
993 caller_context_t *);
994 extern int fop_setfl(vnode_t *, int, int, cred_t *, caller_context_t *);
995 extern int fop_getattr(vnode_t *, vattr_t *, int, cred_t *,
996 caller_context_t *);
997 extern int fop_setattr(vnode_t *, vattr_t *, int, cred_t *,
998 caller_context_t *);
999 extern int fop_access(vnode_t *, int, int, cred_t *, caller_context_t *);
1000 extern int fop_lookup(vnode_t *, char *, vnode_t **, struct pathname *,
1001 int, vnode_t *, cred_t *, caller_context_t *,
1002 int *, struct pathname *);
1003 extern int fop_create(vnode_t *, char *, vattr_t *, vcexcl_t, int,
1004 vnode_t **, cred_t *, int, caller_context_t *,
1005 vsecattr_t *);
1006 extern int fop_remove(vnode_t *vp, char *, cred_t *, caller_context_t *,
1007 int);
1008 extern int fop_link(vnode_t *, vnode_t *, char *, cred_t *,
1009 caller_context_t *, int);
1010 extern int fop_rename(vnode_t *, char *, vnode_t *, char *, cred_t *,
1011 caller_context_t *, int);
1012 extern int fop_mkdir(vnode_t *, char *, vattr_t *, vnode_t **, cred_t *,
1013 caller_context_t *, int, vsecattr_t *);
1014 extern int fop_rmdir(vnode_t *, char *, vnode_t *, cred_t *,
1015 caller_context_t *, int);
1016 extern int fop_readdir(vnode_t *, uio_t *, cred_t *, int *,
1017 caller_context_t *, int);
1018 extern int fop_symlink(vnode_t *, char *, vattr_t *, char *, cred_t *,
1019 caller_context_t *, int);
1020 extern int fop_readlink(vnode_t *, uio_t *, cred_t *, caller_context_t *);
1021 extern int fop_fsync(vnode_t *, int, cred_t *, caller_context_t *);
1022 extern void fop_inactive(vnode_t *, cred_t *, caller_context_t *);
1023 extern int fop_fid(vnode_t *, struct fid *, caller_context_t *);
1024 extern int fop_rwlock(vnode_t *, int, caller_context_t *);
1025 extern void fop_rwunlock(vnode_t *, int, caller_context_t *);
1026 extern int fop_seek(vnode_t *, offset_t, offset_t *, caller_context_t *);
1027 extern int fop_cmp(vnode_t *, vnode_t *, caller_context_t *);
1028 extern int fop_frlock(vnode_t *, int, struct flock64 *, int, offset_t,
1029 struct flk_callback *, cred_t *,
1030 caller_context_t *);
1031 extern int fop_space(vnode_t *, int, struct flock64 *, int, offset_t,
1032 cred_t *, caller_context_t *);
1033 extern int fop_realvp(vnode_t *, vnode_t **, caller_context_t *);
1034 extern int fop_getpage(vnode_t *, offset_t, size_t, uint_t *,
1035 struct page **, size_t, struct seg *,
1036 caddr_t, enum seg_rw, cred_t *,
1037 caller_context_t *);
1038 extern int fop_putpage(vnode_t *, offset_t, size_t, int, cred_t *,
1039 caller_context_t *);
1040 extern int fop_map(vnode_t *, offset_t, struct as *, caddr_t *, size_t,
1041 uchar_t, uchar_t, uint_t, cred_t *cr,
1042 caller_context_t *);
1043 extern int fop_addmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
1044 uchar_t, uchar_t, uint_t, cred_t *,
1045 caller_context_t *);
1046 extern int fop_delmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
1047 uint_t, uint_t, uint_t, cred_t *,
1048 caller_context_t *);
1049 extern int fop_poll(vnode_t *, short, int, short *, struct pollhead **,
1050 caller_context_t *);
1051 extern int fop_dump(vnode_t *, caddr_t, offset_t, offset_t,
1052 caller_context_t *);
1053 extern int fop_pathconf(vnode_t *, int, ulong_t *, cred_t *,
1054 caller_context_t *);
1055 extern int fop_pageio(vnode_t *, struct page *, uoff_t, size_t, int,
1056 cred_t *, caller_context_t *);
1057 extern int fop_dumpctl(vnode_t *, int, offset_t *, caller_context_t *);
1058 extern void fop_dispose(vnode_t *, struct page *, int, int, cred_t *,
1059 caller_context_t *);
1060 extern int fop_setsecattr(vnode_t *, vsecattr_t *, int, cred_t *,
1061 caller_context_t *);
1062 extern int fop_getsecattr(vnode_t *, vsecattr_t *, int, cred_t *,
1063 caller_context_t *);
1064 extern int fop_shrlock(vnode_t *, int, struct shrlock *, int, cred_t *,
1065 caller_context_t *);
1066 extern int fop_vnevent(vnode_t *, vnevent_t, vnode_t *, char *,
1067 caller_context_t *);
1068 extern int fop_reqzcbuf(vnode_t *, enum uio_rw, xuio_t *, cred_t *,
1069 caller_context_t *);
1070 extern int fop_retzcbuf(vnode_t *, xuio_t *, cred_t *, caller_context_t *);
1072 #endif /* _KERNEL */
1074 #define VOPNAME_OPEN "open"
1075 #define VOPNAME_CLOSE "close"
1076 #define VOPNAME_READ "read"
1077 #define VOPNAME_WRITE "write"
1078 #define VOPNAME_IOCTL "ioctl"
1079 #define VOPNAME_SETFL "setfl"
1080 #define VOPNAME_GETATTR "getattr"
1081 #define VOPNAME_SETATTR "setattr"
1082 #define VOPNAME_ACCESS "access"
1083 #define VOPNAME_LOOKUP "lookup"
1084 #define VOPNAME_CREATE "create"
1085 #define VOPNAME_REMOVE "remove"
1086 #define VOPNAME_LINK "link"
1087 #define VOPNAME_RENAME "rename"
1088 #define VOPNAME_MKDIR "mkdir"
1089 #define VOPNAME_RMDIR "rmdir"
1090 #define VOPNAME_READDIR "readdir"
1091 #define VOPNAME_SYMLINK "symlink"
1092 #define VOPNAME_READLINK "readlink"
1093 #define VOPNAME_FSYNC "fsync"
1094 #define VOPNAME_INACTIVE "inactive"
1095 #define VOPNAME_FID "fid"
1096 #define VOPNAME_RWLOCK "rwlock"
1097 #define VOPNAME_RWUNLOCK "rwunlock"
1098 #define VOPNAME_SEEK "seek"
1099 #define VOPNAME_CMP "cmp"
1100 #define VOPNAME_FRLOCK "frlock"
1101 #define VOPNAME_SPACE "space"
1102 #define VOPNAME_REALVP "realvp"
1103 #define VOPNAME_GETPAGE "getpage"
1104 #define VOPNAME_PUTPAGE "putpage"
1105 #define VOPNAME_MAP "map"
1106 #define VOPNAME_ADDMAP "addmap"
1107 #define VOPNAME_DELMAP "delmap"
1108 #define VOPNAME_POLL "poll"
1109 #define VOPNAME_DUMP "dump"
1110 #define VOPNAME_PATHCONF "pathconf"
1111 #define VOPNAME_PAGEIO "pageio"
1112 #define VOPNAME_DUMPCTL "dumpctl"
1113 #define VOPNAME_DISPOSE "dispose"
1114 #define VOPNAME_GETSECATTR "getsecattr"
1115 #define VOPNAME_SETSECATTR "setsecattr"
1116 #define VOPNAME_SHRLOCK "shrlock"
1117 #define VOPNAME_VNEVENT "vnevent"
1118 #define VOPNAME_REQZCBUF "reqzcbuf"
1119 #define VOPNAME_RETZCBUF "retzcbuf"
1122 * Flags for fop_lookup
1124 * Defined in file.h, but also possible, FIGNORECASE and FSEARCH
1127 #define LOOKUP_DIR 0x01 /* want parent dir vp */
1128 #define LOOKUP_XATTR 0x02 /* lookup up extended attr dir */
1129 #define CREATE_XATTR_DIR 0x04 /* Create extended attr dir */
1130 #define LOOKUP_HAVE_SYSATTR_DIR 0x08 /* Already created virtual GFS dir */
1133 * Flags for fop_readdir
1135 #define V_RDDIR_ENTFLAGS 0x01 /* request dirent flags */
1136 #define V_RDDIR_ACCFILTER 0x02 /* filter out inaccessible dirents */
1139 * Flags for fop_rwlock/fop_rwunlock
1140 * fop_rwlock will return the flag that was actually set, or -1 if none.
1142 #define V_WRITELOCK_TRUE (1) /* Request write-lock on the vnode */
1143 #define V_WRITELOCK_FALSE (0) /* Request read-lock on the vnode */
1146 * Flags for fop_dumpctl
1148 #define DUMP_ALLOC 0
1149 #define DUMP_FREE 1
1150 #define DUMP_SCAN 2
1153 * Public vnode manipulation functions.
1155 #ifdef _KERNEL
1157 vnode_t *vn_alloc(int);
1158 void vn_reinit(vnode_t *);
1159 void vn_recycle(vnode_t *);
1160 void vn_free(vnode_t *);
1162 int vn_is_readonly(vnode_t *);
1163 bool vn_is_opened(struct vnode *, v_mode_t);
1164 bool vn_is_mapped(struct vnode *, v_mode_t);
1165 bool vn_has_other_opens(struct vnode *, v_mode_t);
1166 void vn_open_upgrade(vnode_t *, int);
1167 void vn_open_downgrade(vnode_t *, int);
1169 int vn_can_change_zones(vnode_t *vp);
1171 int vn_has_flocks(vnode_t *);
1172 int vn_has_mandatory_locks(vnode_t *, int);
1173 int vn_has_cached_data(vnode_t *);
1175 void vn_setops(struct vnode *, const struct vnodeops *);
1176 const struct vnodeops *vn_getops(struct vnode *);
1177 int vn_matchops(struct vnode *, const struct vnodeops *);
1178 int vn_ismntpt(vnode_t *);
1180 struct vfs *vn_mountedvfs(vnode_t *);
1182 int vn_in_dnlc(vnode_t *);
1184 void vn_create_cache(void);
1185 void vn_destroy_cache(void);
1187 int vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
1188 struct vnode **vpp, enum create crwhy, mode_t umask);
1189 int vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,
1190 struct vnode **vpp, enum create crwhy,
1191 mode_t umask, struct vnode *startvp, int fd);
1192 int vn_create(char *pnamep, enum uio_seg seg, struct vattr *vap,
1193 enum vcexcl excl, int mode, struct vnode **vpp,
1194 enum create why, int flag, mode_t umask);
1195 int vn_createat(char *pnamep, enum uio_seg seg, struct vattr *vap,
1196 enum vcexcl excl, int mode, struct vnode **vpp,
1197 enum create why, int flag, mode_t umask, struct vnode *startvp);
1198 int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len,
1199 offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit,
1200 cred_t *cr, ssize_t *residp);
1201 void vn_rele(struct vnode *vp);
1202 void vn_rele_async(struct vnode *vp, struct taskq *taskq);
1203 void vn_rele_dnlc(struct vnode *vp);
1204 void vn_rele_stream(struct vnode *vp);
1205 int vn_link(char *from, char *to, enum uio_seg seg);
1206 int vn_linkat(vnode_t *fstartvp, char *from, enum symfollow follow,
1207 vnode_t *tstartvp, char *to, enum uio_seg seg);
1208 int vn_rename(char *from, char *to, enum uio_seg seg);
1209 int vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname,
1210 enum uio_seg seg);
1211 int vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag);
1212 int vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg,
1213 enum rm dirflag);
1214 int vn_compare(vnode_t *vp1, vnode_t *vp2);
1215 int vn_vfswlock(struct vnode *vp);
1216 int vn_vfswlock_wait(struct vnode *vp);
1217 int vn_vfsrlock(struct vnode *vp);
1218 int vn_vfsrlock_wait(struct vnode *vp);
1219 void vn_vfsunlock(struct vnode *vp);
1220 int vn_vfswlock_held(struct vnode *vp);
1221 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr);
1222 vnode_t *makespecvp(dev_t dev, vtype_t type);
1223 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
1224 void vn_vfslocks_rele(vn_vfslocks_entry_t *);
1225 boolean_t vn_is_reparse(vnode_t *, cred_t *, caller_context_t *);
1227 void vn_copypath(struct vnode *src, struct vnode *dst);
1228 void vn_setpath_str(struct vnode *vp, const char *str, size_t len);
1229 void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp,
1230 const char *path, size_t plen);
1231 void vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len);
1233 /* Private vnode manipulation functions */
1234 void vn_clearpath(vnode_t *, hrtime_t);
1235 void vn_updatepath(vnode_t *, vnode_t *, const char *);
1238 /* Vnode event notification */
1239 void vnevent_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *);
1240 void vnevent_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *);
1241 void vnevent_remove(vnode_t *, vnode_t *, char *, caller_context_t *);
1242 void vnevent_rmdir(vnode_t *, vnode_t *, char *, caller_context_t *);
1243 void vnevent_create(vnode_t *, caller_context_t *);
1244 void vnevent_link(vnode_t *, caller_context_t *);
1245 void vnevent_rename_dest_dir(vnode_t *, caller_context_t *ct);
1246 void vnevent_mountedover(vnode_t *, caller_context_t *);
1247 void vnevent_truncate(vnode_t *, caller_context_t *);
1248 int vnevent_support(vnode_t *, caller_context_t *);
1249 void vnevent_pre_rename_src(vnode_t *, vnode_t *, char *,
1250 caller_context_t *);
1251 void vnevent_pre_rename_dest(vnode_t *, vnode_t *, char *,
1252 caller_context_t *);
1253 void vnevent_pre_rename_dest_dir(vnode_t *, vnode_t *, char *,
1254 caller_context_t *);
1256 /* Vnode specific data */
1257 void vsd_create(uint_t *, void (*)(void *));
1258 void vsd_destroy(uint_t *);
1259 void *vsd_get(vnode_t *, uint_t);
1260 int vsd_set(vnode_t *, uint_t, void *);
1261 void vsd_free(vnode_t *);
1264 * Extensible vnode attribute (xva) routines:
1265 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set
1266 * VATTR_XVATTR) xva_getxoptattr() returns a ponter to the xoptattr_t
1267 * section of xvattr_t
1269 void xva_init(xvattr_t *);
1270 xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */
1272 void xattr_init(void); /* Initialize vnodeops for xattrs */
1274 /* GFS tunnel for xattrs */
1275 int xattr_dir_lookup(vnode_t *, vnode_t **, int, cred_t *);
1277 /* Reparse Point */
1278 void reparse_point_init(void);
1280 /* Context identification */
1281 u_longlong_t fs_new_caller_id();
1283 int vn_vmpss_usepageio(vnode_t *);
1285 /* Empty v_path placeholder */
1286 extern char *vn_vpath_empty;
1289 * All changes to v_count should be done through VN_HOLD() or VN_RELE(), or
1290 * one of their variants. This makes it possible to ensure proper locking,
1291 * and to guarantee that all modifications are accompanied by a firing of
1292 * the vn-hold or vn-rele SDT DTrace probe.
1294 * Example DTrace command for tracing vnode references using these probes:
1296 * dtrace -q -n 'sdt:::vn-hold,sdt:::vn-rele
1298 * this->vp = (vnode_t *)arg0;
1299 * printf("%s %s(%p[%s]) %d\n", execname, probename, this->vp,
1300 * this->vp->v_path == NULL ? "NULL" : stringof(this->vp->v_path),
1301 * this->vp->v_count)
1302 * }'
1304 #define VN_HOLD_LOCKED(vp) { \
1305 ASSERT(mutex_owned(&(vp)->v_lock)); \
1306 (vp)->v_count++; \
1307 DTRACE_PROBE1(vn__hold, vnode_t *, vp); \
1310 #define VN_HOLD(vp) { \
1311 mutex_enter(&(vp)->v_lock); \
1312 VN_HOLD_LOCKED(vp); \
1313 mutex_exit(&(vp)->v_lock); \
1316 #define VN_RELE(vp) { \
1317 vn_rele(vp); \
1320 #define VN_RELE_ASYNC(vp, taskq) { \
1321 vn_rele_async(vp, taskq); \
1324 #define VN_RELE_LOCKED(vp) { \
1325 ASSERT(mutex_owned(&(vp)->v_lock)); \
1326 ASSERT((vp)->v_count >= 1); \
1327 (vp)->v_count--; \
1328 DTRACE_PROBE1(vn__rele, vnode_t *, vp); \
1331 #define VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev) { \
1332 (vp)->v_vfsp = (vfsp); \
1333 (vp)->v_type = (type); \
1334 (vp)->v_rdev = (dev); \
1338 * Compare two vnodes for equality. In general this macro should be used
1339 * in preference to calling fop_cmp directly.
1341 #define VN_CMP(VP1, VP2) ((VP1) == (VP2) ? 1 : \
1342 ((VP1) && (VP2) && (vn_getops(VP1) == vn_getops(VP2)) ? \
1343 fop_cmp(VP1, VP2, NULL) : 0))
1346 * Some well-known global vnodes used by the VM system to name pages.
1348 extern struct vnode kvps[];
1350 typedef enum {
1351 KV_KVP, /* vnode for all segkmem pages */
1352 KV_ZVP, /* vnode for all ZFS pages */
1353 #if defined(__sparc)
1354 KV_MPVP, /* vnode for all page_t meta-pages */
1355 KV_PROMVP, /* vnode for all PROM pages */
1356 #endif /* __sparc */
1357 KV_MAX /* total number of vnodes in kvps[] */
1358 } kvps_index_t;
1360 #define VN_ISKAS(vp) ((vp) >= &kvps[0] && (vp) < &kvps[KV_MAX])
1362 #endif /* _KERNEL */
1365 * Flags to fop_setattr/fop_getattr.
1367 #define ATTR_UTIME 0x01 /* non-default utime(2) request */
1368 #define ATTR_EXEC 0x02 /* invocation from exec(2) */
1369 #define ATTR_COMM 0x04 /* yield common vp attributes */
1370 #define ATTR_HINT 0x08 /* information returned will be `hint' */
1371 #define ATTR_REAL 0x10 /* yield attributes of the real vp */
1372 #define ATTR_NOACLCHECK 0x20 /* Don't check ACL when checking permissions */
1373 #define ATTR_TRIGGER 0x40 /* Mount first if vnode is a trigger mount */
1375 * Generally useful macros.
1377 #define VBSIZE(vp) ((vp)->v_vfsp->vfs_bsize)
1379 #define VTOZONE(vp) ((vp)->v_vfsp->vfs_zone)
1381 #define NULLVP ((struct vnode *)0)
1382 #define NULLVPP ((struct vnode **)0)
1384 #ifdef _KERNEL
1387 * Structure used while handling asynchronous fop_putpage operations.
1389 struct async_reqs {
1390 struct async_reqs *a_next; /* pointer to next arg struct */
1391 struct vnode *a_vp; /* vnode pointer */
1392 uoff_t a_off; /* offset in file */
1393 uint_t a_len; /* size of i/o request */
1394 int a_flags; /* flags to indicate operation type */
1395 struct cred *a_cred; /* cred pointer */
1396 ushort_t a_prealloced; /* set if struct is pre-allocated */
1400 * VN_DISPOSE() -- given a page pointer, safely invoke fop_dispose().
1401 * Note that there is no guarantee that the page passed in will be
1402 * freed. If that is required, then a check after calling VN_DISPOSE would
1403 * be necessary to ensure the page was freed.
1405 #define VN_DISPOSE(pp, flag, dn, cr) { \
1406 if ((pp)->p_vnode != NULL && !VN_ISKAS((pp)->p_vnode)) \
1407 fop_dispose((pp)->p_vnode, (pp), (flag), (dn), (cr), NULL); \
1408 else if ((flag) == B_FREE) \
1409 page_free((pp), (dn)); \
1410 else \
1411 page_destroy((pp), (dn)); \
1414 #endif /* _KERNEL */
1416 #ifdef __cplusplus
1418 #endif
1420 #endif /* _SYS_VNODE_H */