fs: clean up vnode ops definition indirection
[unleashed.git] / include / sys / vnode.h
blobfb3fbeee5a6dfcc74b847f1155182c1ad36e84f4
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) 2013, Joyent, Inc. All rights reserved.
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.
229 struct fem_head; /* from fem.h */
231 typedef struct vnode {
232 kmutex_t v_lock; /* protects vnode fields */
233 uint_t v_flag; /* vnode flags (see below) */
234 uint_t v_count; /* reference count */
235 void *v_data; /* private data for fs */
236 struct vfs *v_vfsp; /* ptr to containing VFS */
237 struct stdata *v_stream; /* associated stream */
238 enum vtype v_type; /* vnode type */
239 dev_t v_rdev; /* device (VCHR, VBLK) */
241 /* PRIVATE FIELDS BELOW - DO NOT USE */
243 struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */
244 const struct vnodeops *v_op; /* vnode operations */
245 struct filock *v_filocks; /* ptr to filock list */
246 struct shrlocklist *v_shrlocks; /* ptr to shrlock list */
247 krwlock_t v_nbllock; /* sync for NBMAND locks */
248 kcondvar_t v_cv; /* synchronize locking */
249 void *v_locality; /* hook for locality info */
250 struct fem_head *v_femhead; /* fs monitoring */
251 char *v_path; /* cached path */
252 uint_t v_rdcnt; /* open for read count (VREG only) */
253 uint_t v_wrcnt; /* open for write count (VREG only) */
254 u_longlong_t v_mmap_read; /* mmap read count */
255 u_longlong_t v_mmap_write; /* mmap write count */
256 void *v_mpssdata; /* info for large page mappings */
257 void *v_fopdata; /* list of file ops event watches */
258 kmutex_t v_vsd_lock; /* protects v_vsd field */
259 struct vsd_node *v_vsd; /* vnode specific data */
260 struct vnode *v_xattrdir; /* unnamed extended attr dir (GFS) */
261 uint_t v_count_dnlc; /* dnlc reference count */
263 struct vmobject v_object;
264 } vnode_t;
266 #define IS_DEVVP(vp) \
267 ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
269 #define VNODE_ALIGN 64
270 /* Count of low-order 0 bits in a vnode *, based on size and alignment. */
271 #if defined(_LP64)
272 #define VNODE_ALIGN_LOG2 8
273 #else
274 #define VNODE_ALIGN_LOG2 7
275 #endif
278 * vnode flags.
280 #define VROOT 0x01 /* root of its file system */
281 #define VNOCACHE 0x02 /* don't keep cache pages on vnode */
282 #define VNOMAP 0x04 /* file cannot be mapped/faulted */
283 #define VDUP 0x08 /* file should be dup'ed rather then opened */
284 #define VNOSWAP 0x10 /* file cannot be used as virtual swap device */
285 #define VNOMOUNT 0x20 /* file cannot be covered by mount */
286 #define VISSWAP 0x40 /* vnode is being used for swap */
287 #define VSWAPLIKE 0x80 /* vnode acts like swap (but may not be) */
289 #define IS_SWAPVP(vp) (((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0)
291 typedef struct vn_vfslocks_entry {
292 rwstlock_t ve_lock;
293 void *ve_vpvfs;
294 struct vn_vfslocks_entry *ve_next;
295 uint32_t ve_refcnt;
296 char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \
297 sizeof (uint32_t)];
298 } vn_vfslocks_entry_t;
301 * The following two flags are used to lock the v_vfsmountedhere field
303 #define VVFSLOCK 0x100
304 #define VVFSWAIT 0x200
307 * Used to serialize VM operations on a vnode
309 #define VVMLOCK 0x400
312 * Tell vn_open() not to fail a directory open for writing but
313 * to go ahead and call fop_open() to let the filesystem check.
315 #define VDIROPEN 0x800
318 * Flag to let the VM system know that this file is most likely a binary
319 * or shared library since it has been mmap()ed EXEC at some time.
321 #define VVMEXEC 0x1000
323 #define V_XATTRDIR 0x4000 /* attribute unnamed directory */
325 #define IS_XATTRDIR(vp) ((vp)->v_flag & V_XATTRDIR)
327 #define V_LOCALITY 0x8000 /* whether locality aware */
330 * Flag that indicates the VM should maintain the v_object's list with all
331 * modified pages on one end and unmodified pages at the other. This makes
332 * finding dirty pages to write back to disk much faster at the expense of
333 * taking a minor fault on the first store instruction which touches a
334 * writable page.
336 #define VMODSORT (0x10000)
337 #define IS_VMODSORT(vp) (((vp)->v_flag & VMODSORT) != 0)
339 #define VISSWAPFS 0x20000 /* vnode is being used for swapfs */
342 * The mdb memstat command assumes that IS_SWAPFSVP only uses the
343 * vnode's v_flag field. If this changes, cache the additional
344 * fields in mdb; see vn_get in mdb/common/modules/genunix/memory.c
346 #define IS_SWAPFSVP(vp) (((vp)->v_flag & VISSWAPFS) != 0)
348 #define V_SYSATTR 0x40000 /* vnode is a GFS system attribute */
351 * Vnode attributes. A bit-mask is supplied as part of the
352 * structure to indicate the attributes the caller wants to
353 * set (setattr) or extract (getattr).
357 * Note that va_nodeid and va_nblocks are 64bit data type.
358 * We support large files over NFSV3. With Solaris client and
359 * Server that generates 64bit ino's and sizes these fields
360 * will overflow if they are 32 bit sizes.
363 typedef struct vattr {
364 uint_t va_mask; /* bit-mask of attributes */
365 vtype_t va_type; /* vnode type (for create) */
366 mode_t va_mode; /* file access mode */
367 uid_t va_uid; /* owner user id */
368 gid_t va_gid; /* owner group id */
369 dev_t va_fsid; /* file system id (dev for now) */
370 u_longlong_t va_nodeid; /* node id */
371 nlink_t va_nlink; /* number of references to file */
372 uoff_t va_size; /* file size in bytes */
373 timestruc_t va_atime; /* time of last access */
374 timestruc_t va_mtime; /* time of last modification */
375 timestruc_t va_ctime; /* time of last status change */
376 dev_t va_rdev; /* device the file represents */
377 uint_t va_blksize; /* fundamental block size */
378 u_longlong_t va_nblocks; /* # of blocks allocated */
379 uint_t va_seq; /* sequence number */
380 } vattr_t;
382 #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
385 * Structure of all optional attributes.
387 typedef struct xoptattr {
388 timestruc_t xoa_createtime; /* Create time of file */
389 uint8_t xoa_archive;
390 uint8_t xoa_system;
391 uint8_t xoa_readonly;
392 uint8_t xoa_hidden;
393 uint8_t xoa_nounlink;
394 uint8_t xoa_immutable;
395 uint8_t xoa_appendonly;
396 uint8_t xoa_nodump;
397 uint8_t xoa_opaque;
398 uint8_t xoa_av_quarantined;
399 uint8_t xoa_av_modified;
400 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ];
401 uint8_t xoa_reparse;
402 uint64_t xoa_generation;
403 uint8_t xoa_offline;
404 uint8_t xoa_sparse;
405 } xoptattr_t;
408 * The xvattr structure is really a variable length structure that
409 * is made up of:
410 * - The classic vattr_t (xva_vattr)
411 * - a 32 bit quantity (xva_mapsize) that specifies the size of the
412 * attribute bitmaps in 32 bit words.
413 * - A pointer to the returned attribute bitmap (needed because the
414 * previous element, the requested attribute bitmap) is variable lenth.
415 * - The requested attribute bitmap, which is an array of 32 bit words.
416 * Callers use the XVA_SET_REQ() macro to set the bits corresponding to
417 * the attributes that are being requested.
418 * - The returned attribute bitmap, which is an array of 32 bit words.
419 * File systems that support optional attributes use the XVA_SET_RTN()
420 * macro to set the bits corresponding to the attributes that are being
421 * returned.
422 * - The xoptattr_t structure which contains the attribute values
424 * xva_mapsize determines how many words in the attribute bitmaps.
425 * Immediately following the attribute bitmaps is the xoptattr_t.
426 * xva_getxoptattr() is used to get the pointer to the xoptattr_t
427 * section.
430 #define XVA_MAPSIZE 3 /* Size of attr bitmaps */
431 #define XVA_MAGIC 0x78766174 /* Magic # for verification */
434 * The xvattr structure is an extensible structure which permits optional
435 * attributes to be requested/returned. File systems may or may not support
436 * optional attributes. They do so at their own discretion but if they do
437 * support optional attributes, they must register the VFSFT_XVATTR feature
438 * so that the optional attributes can be set/retrived.
440 * The fields of the xvattr structure are:
442 * xva_vattr - The first element of an xvattr is a legacy vattr structure
443 * which includes the common attributes. If AT_XVATTR is set in the va_mask
444 * then the entire structure is treated as an xvattr. If AT_XVATTR is not
445 * set, then only the xva_vattr structure can be used.
447 * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
449 * xva_mapsize - Size of requested and returned attribute bitmaps.
451 * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the
452 * size of the array before it, xva_reqattrmap[], could change which means
453 * the location of xva_rtnattrmap[] could change. This will allow unbundled
454 * file systems to find the location of xva_rtnattrmap[] when the sizes change.
456 * xva_reqattrmap[] - Array of requested attributes. Attributes are
457 * represented by a specific bit in a specific element of the attribute
458 * map array. Callers set the bits corresponding to the attributes
459 * that the caller wants to get/set.
461 * xva_rtnattrmap[] - Array of attributes that the file system was able to
462 * process. Not all file systems support all optional attributes. This map
463 * informs the caller which attributes the underlying file system was able
464 * to set/get. (Same structure as the requested attributes array in terms
465 * of each attribute corresponding to specific bits and array elements.)
467 * xva_xoptattrs - Structure containing values of optional attributes.
468 * These values are only valid if the corresponding bits in xva_reqattrmap
469 * are set and the underlying file system supports those attributes.
471 typedef struct xvattr {
472 vattr_t xva_vattr; /* Embedded vattr structure */
473 uint32_t xva_magic; /* Magic Number */
474 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
475 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
476 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
477 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
478 xoptattr_t xva_xoptattrs; /* Optional attributes */
479 } xvattr_t;
481 #ifdef _SYSCALL32
483 * For bigtypes time_t changed to 64 bit on the 64-bit kernel.
484 * Define an old version for user/kernel interface
487 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
488 #pragma pack(4)
489 #endif
491 typedef struct vattr32 {
492 uint32_t va_mask; /* bit-mask of attributes */
493 vtype_t va_type; /* vnode type (for create) */
494 mode32_t va_mode; /* file access mode */
495 uid32_t va_uid; /* owner user id */
496 gid32_t va_gid; /* owner group id */
497 dev32_t va_fsid; /* file system id (dev for now) */
498 u_longlong_t va_nodeid; /* node id */
499 nlink_t va_nlink; /* number of references to file */
500 uoff_t va_size; /* file size in bytes */
501 timestruc32_t va_atime; /* time of last access */
502 timestruc32_t va_mtime; /* time of last modification */
503 timestruc32_t va_ctime; /* time of last status change */
504 dev32_t va_rdev; /* device the file represents */
505 uint32_t va_blksize; /* fundamental block size */
506 u_longlong_t va_nblocks; /* # of blocks allocated */
507 uint32_t va_seq; /* sequence number */
508 } vattr32_t;
510 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
511 #pragma pack()
512 #endif
514 #else /* not _SYSCALL32 */
515 #define vattr32 vattr
516 typedef vattr_t vattr32_t;
517 #endif /* _SYSCALL32 */
520 * Attributes of interest to the caller of setattr or getattr.
522 #define AT_TYPE 0x00001
523 #define AT_MODE 0x00002
524 #define AT_UID 0x00004
525 #define AT_GID 0x00008
526 #define AT_FSID 0x00010
527 #define AT_NODEID 0x00020
528 #define AT_NLINK 0x00040
529 #define AT_SIZE 0x00080
530 #define AT_ATIME 0x00100
531 #define AT_MTIME 0x00200
532 #define AT_CTIME 0x00400
533 #define AT_RDEV 0x00800
534 #define AT_BLKSIZE 0x01000
535 #define AT_NBLOCKS 0x02000
536 /* 0x04000 */ /* unused */
537 #define AT_SEQ 0x08000
539 * If AT_XVATTR is set then there are additional bits to process in
540 * the xvattr_t's attribute bitmap. If this is not set then the bitmap
541 * MUST be ignored. Note that this bit must be set/cleared explicitly.
542 * That is, setting AT_ALL will NOT set AT_XVATTR.
544 #define AT_XVATTR 0x10000
546 #define AT_ALL (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
547 AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
548 AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
550 #define AT_STAT (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
551 AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE)
553 #define AT_TIMES (AT_ATIME|AT_MTIME|AT_CTIME)
555 #define AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
556 AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
559 * Attribute bits used in the extensible attribute's (xva's) attribute
560 * bitmaps. Note that the bitmaps are made up of a variable length number
561 * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n"
562 * is the element in the bitmap (starting at 1). This convention is for
563 * the convenience of the maintainer to keep track of which element each
564 * attribute belongs to.
566 * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS
567 * MUST USE THE XAT_* DEFINES.
569 #define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */
570 #define XAT0_CREATETIME 0x00000001 /* Create time of file */
571 #define XAT0_ARCHIVE 0x00000002 /* Archive */
572 #define XAT0_SYSTEM 0x00000004 /* System */
573 #define XAT0_READONLY 0x00000008 /* Readonly */
574 #define XAT0_HIDDEN 0x00000010 /* Hidden */
575 #define XAT0_NOUNLINK 0x00000020 /* Nounlink */
576 #define XAT0_IMMUTABLE 0x00000040 /* immutable */
577 #define XAT0_APPENDONLY 0x00000080 /* appendonly */
578 #define XAT0_NODUMP 0x00000100 /* nodump */
579 #define XAT0_OPAQUE 0x00000200 /* opaque */
580 #define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */
581 #define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */
582 #define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */
583 #define XAT0_REPARSE 0x00002000 /* FS reparse point */
584 #define XAT0_GEN 0x00004000 /* object generation number */
585 #define XAT0_OFFLINE 0x00008000 /* offline */
586 #define XAT0_SPARSE 0x00010000 /* sparse */
588 #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
589 XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
590 XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \
591 XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE)
593 /* Support for XAT_* optional attributes */
594 #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */
595 #define XVA_SHFT 32 /* Used to shift index */
598 * Used to pry out the index and attribute bits from the XAT_* attributes
599 * defined below. Note that we're masking things down to 32 bits then
600 * casting to uint32_t.
602 #define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
603 #define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK))
606 * The following defines present a "flat namespace" so that consumers don't
607 * need to keep track of which element belongs to which bitmap entry.
609 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
611 #define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
612 #define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
613 #define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
614 #define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
615 #define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
616 #define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
617 #define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
618 #define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
619 #define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
620 #define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
621 #define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
622 #define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
623 #define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
624 #define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
625 #define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
626 #define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
627 #define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
630 * The returned attribute map array (xva_rtnattrmap[]) is located past the
631 * requested attribute map array (xva_reqattrmap[]). Its location changes
632 * when the array sizes change. We use a separate pointer in a known location
633 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is
634 * set in xva_init()
636 #define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp)
639 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
640 * of requested attributes (xva_reqattrmap[]).
642 #define XVA_SET_REQ(xvap, attr) \
643 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \
644 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
645 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
647 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
648 * of requested attributes (xva_reqattrmap[]).
650 #define XVA_CLR_REQ(xvap, attr) \
651 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \
652 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
653 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
656 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
657 * of returned attributes (xva_rtnattrmap[]).
659 #define XVA_SET_RTN(xvap, attr) \
660 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \
661 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
662 (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
665 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
666 * to see of the corresponding attribute bit is set. If so, returns non-zero.
668 #define XVA_ISSET_REQ(xvap, attr) \
669 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \
670 ((xvap)->xva_magic == XVA_MAGIC) && \
671 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
672 ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
675 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
676 * to see of the corresponding attribute bit is set. If so, returns non-zero.
678 #define XVA_ISSET_RTN(xvap, attr) \
679 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \
680 ((xvap)->xva_magic == XVA_MAGIC) && \
681 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
682 ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
685 * Modes. Some values same as S_xxx entries from stat.h for convenience.
687 #define VSUID 04000 /* set user id on execution */
688 #define VSGID 02000 /* set group id on execution */
689 #define VSVTX 01000 /* save swapped text even after use */
692 * Permissions.
694 #define VREAD 00400
695 #define VWRITE 00200
696 #define VEXEC 00100
698 #define MODEMASK 07777 /* mode bits plus permission bits */
699 #define PERMMASK 00777 /* permission bits */
702 * fop_access flags
704 #define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */
705 #define V_APPEND 0x2 /* want to do append only check */
708 * Check whether mandatory file locking is enabled.
711 #define MANDMODE(mode) (((mode) & (VSGID|(VEXEC>>3))) == VSGID)
712 #define MANDLOCK(vp, mode) ((vp)->v_type == VREG && MANDMODE(mode))
715 * Flags for vnode operations.
717 enum rm { RMFILE, RMDIRECTORY }; /* rm or rmdir (remove) */
718 enum symfollow { NO_FOLLOW, FOLLOW }; /* follow symlinks (or not) */
719 enum vcexcl { NONEXCL, EXCL }; /* (non)excl create */
720 enum create { CRCREAT, CRMKNOD, CRMKDIR }; /* reason for create */
722 typedef enum rm rm_t;
723 typedef enum symfollow symfollow_t;
724 typedef enum vcexcl vcexcl_t;
725 typedef enum create create_t;
728 * Vnode Events - Used by fop_vnevent
729 * The VE_PRE_RENAME_* events fire before the rename operation and are
730 * primarily used for specialized applications, such as NFSv4 delegation, which
731 * need to know about rename before it occurs.
733 typedef enum vnevent {
734 VE_SUPPORT = 0, /* Query */
735 VE_RENAME_SRC = 1, /* Rename, with vnode as source */
736 VE_RENAME_DEST = 2, /* Rename, with vnode as target/destination */
737 VE_REMOVE = 3, /* Remove of vnode's name */
738 VE_RMDIR = 4, /* Remove of directory vnode's name */
739 VE_CREATE = 5, /* Create with vnode's name which exists */
740 VE_LINK = 6, /* Link with vnode's name as source */
741 VE_RENAME_DEST_DIR = 7, /* Rename with vnode as target dir */
742 VE_MOUNTEDOVER = 8, /* File or Filesystem got mounted over vnode */
743 VE_TRUNCATE = 9, /* Truncate */
744 VE_PRE_RENAME_SRC = 10, /* Pre-rename, with vnode as source */
745 VE_PRE_RENAME_DEST = 11, /* Pre-rename, with vnode as target/dest. */
746 VE_PRE_RENAME_DEST_DIR = 12 /* Pre-rename with vnode as target dir */
747 } vnevent_t;
750 * Values for checking vnode open and map counts
752 enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR };
754 typedef enum v_mode v_mode_t;
756 #define V_TRUE 1
757 #define V_FALSE 0
760 * Structure used on fop_getsecattr and fop_setsecattr operations
763 typedef struct vsecattr {
764 uint_t vsa_mask; /* See below */
765 int vsa_aclcnt; /* ACL entry count */
766 void *vsa_aclentp; /* pointer to ACL entries */
767 int vsa_dfaclcnt; /* default ACL entry count */
768 void *vsa_dfaclentp; /* pointer to default ACL entries */
769 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
770 uint_t vsa_aclflags; /* ACE ACL flags */
771 } vsecattr_t;
773 /* vsa_mask values */
774 #define VSA_ACL 0x0001
775 #define VSA_ACLCNT 0x0002
776 #define VSA_DFACL 0x0004
777 #define VSA_DFACLCNT 0x0008
778 #define VSA_ACE 0x0010
779 #define VSA_ACECNT 0x0020
780 #define VSA_ACE_ALLTYPES 0x0040
781 #define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */
784 * Structure used by various vnode operations to determine
785 * the context (pid, host, identity) of a caller.
787 * The cc_caller_id is used to identify one or more callers who invoke
788 * operations, possibly on behalf of others. For example, the NFS
789 * server could have it's own cc_caller_id which can be detected by
790 * vnode/vfs operations or (FEM) monitors on those operations. New
791 * caller IDs are generated by fs_new_caller_id().
793 typedef struct caller_context {
794 pid_t cc_pid; /* Process ID of the caller */
795 int cc_sysid; /* System ID, used for remote calls */
796 u_longlong_t cc_caller_id; /* Identifier for (set of) caller(s) */
797 ulong_t cc_flags;
798 } caller_context_t;
801 * Flags for caller context. The caller sets CC_DONTBLOCK if it does not
802 * want to block inside of a FEM monitor. The monitor will set CC_WOULDBLOCK
803 * and return EAGAIN if the operation would have blocked.
805 #define CC_WOULDBLOCK 0x01
806 #define CC_DONTBLOCK 0x02
809 * Structure tags for function prototypes, defined elsewhere.
811 struct pathname;
812 struct fid;
813 struct flock64;
814 struct flk_callback;
815 struct shrlock;
816 struct page;
817 struct seg;
818 struct as;
819 struct pollhead;
820 struct taskq;
822 #ifdef _KERNEL
825 * Operations on vnodes.
827 typedef struct vnodeops {
828 const char *vnop_name;
829 int (*vop_open)(struct vnode **, int, cred_t *, caller_context_t *);
830 int (*vop_close)(struct vnode *, int, int, offset_t, cred_t *,
831 caller_context_t *);
832 int (*vop_read)(struct vnode *, uio_t *, int, cred_t *,
833 caller_context_t *);
834 int (*vop_write)(struct vnode *, uio_t *, int, cred_t *,
835 caller_context_t *);
836 int (*vop_ioctl)(struct vnode *, int, intptr_t, int, cred_t *,
837 int *, caller_context_t *);
838 int (*vop_setfl)(struct vnode *, int, int, cred_t *,
839 caller_context_t *);
840 int (*vop_getattr)(struct vnode *, vattr_t *, int, cred_t *,
841 caller_context_t *);
842 int (*vop_setattr)(struct vnode *, vattr_t *, int, cred_t *,
843 caller_context_t *);
844 int (*vop_access)(struct vnode *, int, int, cred_t *,
845 caller_context_t *);
846 int (*vop_lookup)(struct vnode *, char *, struct vnode **,
847 struct pathname *, int, struct vnode *, cred_t *,
848 caller_context_t *, int *, struct pathname *);
849 int (*vop_create)(struct vnode *, char *, vattr_t *, vcexcl_t,
850 int, struct vnode **, cred_t *, int,
851 caller_context_t *, vsecattr_t *);
852 int (*vop_remove)(struct vnode *, char *, cred_t *,
853 caller_context_t *, int);
854 int (*vop_link)(struct vnode *, struct vnode *, char *, cred_t *,
855 caller_context_t *, int);
856 int (*vop_rename)(struct vnode *, char *, struct vnode *, char *,
857 cred_t *, caller_context_t *, int);
858 int (*vop_mkdir)(struct vnode *, char *, vattr_t *, struct vnode **,
859 cred_t *, caller_context_t *, int, vsecattr_t *);
860 int (*vop_rmdir)(struct vnode *, char *, struct vnode *, cred_t *,
861 caller_context_t *, int);
862 int (*vop_readdir)(struct vnode *, uio_t *, cred_t *, int *,
863 caller_context_t *, int);
864 int (*vop_symlink)(struct vnode *, char *, vattr_t *, char *,
865 cred_t *, caller_context_t *, int);
866 int (*vop_readlink)(struct vnode *, uio_t *, cred_t *,
867 caller_context_t *);
868 int (*vop_fsync)(struct vnode *, int, cred_t *, caller_context_t *);
869 void (*vop_inactive)(struct vnode *, cred_t *, caller_context_t *);
870 int (*vop_fid)(struct vnode *, struct fid *, caller_context_t *);
871 int (*vop_rwlock)(struct vnode *, int, caller_context_t *);
872 void (*vop_rwunlock)(struct vnode *, int, caller_context_t *);
873 int (*vop_seek)(struct vnode *, offset_t, offset_t *,
874 caller_context_t *);
875 int (*vop_cmp)(struct vnode *, struct vnode *, caller_context_t *);
876 int (*vop_frlock)(struct vnode *, int, struct flock64 *, int, offset_t,
877 struct flk_callback *, cred_t *, caller_context_t *);
878 int (*vop_space)(struct vnode *, int, struct flock64 *,
879 int, offset_t, cred_t *, caller_context_t *);
880 int (*vop_realvp)(struct vnode *, struct vnode **, caller_context_t *);
881 int (*vop_getpage)(struct vnode *, offset_t, size_t, uint_t *,
882 struct page **, size_t, struct seg *, caddr_t,
883 enum seg_rw, cred_t *, caller_context_t *);
884 int (*vop_putpage)(struct vnode *, offset_t, size_t,
885 int, cred_t *, caller_context_t *);
886 int (*vop_map)(struct vnode *, offset_t, struct as *,
887 caddr_t *, size_t, uchar_t, uchar_t, uint_t, cred_t *,
888 caller_context_t *);
889 int (*vop_addmap)(struct vnode *, offset_t, struct as *,
890 caddr_t, size_t, uchar_t, uchar_t, uint_t, cred_t *,
891 caller_context_t *);
892 int (*vop_delmap)(struct vnode *, offset_t, struct as *,
893 caddr_t, size_t, uint_t, uint_t, uint_t, cred_t *,
894 caller_context_t *);
895 int (*vop_poll)(struct vnode *, short, int, short *,
896 struct pollhead **, caller_context_t *);
897 int (*vop_dump)(struct vnode *, caddr_t, offset_t, offset_t,
898 caller_context_t *);
899 int (*vop_pathconf)(struct vnode *, int, ulong_t *, cred_t *,
900 caller_context_t *);
901 int (*vop_pageio)(struct vnode *, struct page *,
902 uoff_t, size_t, int, cred_t *, caller_context_t *);
903 int (*vop_dumpctl)(struct vnode *, int, offset_t *, caller_context_t *);
904 void (*vop_dispose)(struct vnode *, struct page *,
905 int, int, cred_t *, caller_context_t *);
906 int (*vop_setsecattr)(struct vnode *, vsecattr_t *,
907 int, cred_t *, caller_context_t *);
908 int (*vop_getsecattr)(struct vnode *, vsecattr_t *,
909 int, cred_t *, caller_context_t *);
910 int (*vop_shrlock)(struct vnode *, int, struct shrlock *,
911 int, cred_t *, caller_context_t *);
912 int (*vop_vnevent)(struct vnode *, vnevent_t, struct vnode *,
913 char *, caller_context_t *);
914 int (*vop_reqzcbuf)(struct vnode *, enum uio_rw, xuio_t *,
915 cred_t *, caller_context_t *);
916 int (*vop_retzcbuf)(struct vnode *, xuio_t *, cred_t *,
917 caller_context_t *);
918 } vnodeops_t;
920 typedef int (*fs_generic_func_p) (); /* Generic vop/vfsop/femop/fsemop ptr */
922 extern int fop_open(vnode_t **, int, cred_t *, caller_context_t *);
923 extern int fop_close(vnode_t *, int, int, offset_t, cred_t *,
924 caller_context_t *);
925 extern int fop_read(vnode_t *, uio_t *, int, cred_t *, caller_context_t *);
926 extern int fop_write(vnode_t *, uio_t *, int, cred_t *,
927 caller_context_t *);
928 extern int fop_ioctl(vnode_t *, int, intptr_t, int, cred_t *, int *,
929 caller_context_t *);
930 extern int fop_setfl(vnode_t *, int, int, cred_t *, caller_context_t *);
931 extern int fop_getattr(vnode_t *, vattr_t *, int, cred_t *,
932 caller_context_t *);
933 extern int fop_setattr(vnode_t *, vattr_t *, int, cred_t *,
934 caller_context_t *);
935 extern int fop_access(vnode_t *, int, int, cred_t *, caller_context_t *);
936 extern int fop_lookup(vnode_t *, char *, vnode_t **, struct pathname *,
937 int, vnode_t *, cred_t *, caller_context_t *,
938 int *, struct pathname *);
939 extern int fop_create(vnode_t *, char *, vattr_t *, vcexcl_t, int,
940 vnode_t **, cred_t *, int, caller_context_t *,
941 vsecattr_t *);
942 extern int fop_remove(vnode_t *vp, char *, cred_t *, caller_context_t *,
943 int);
944 extern int fop_link(vnode_t *, vnode_t *, char *, cred_t *,
945 caller_context_t *, int);
946 extern int fop_rename(vnode_t *, char *, vnode_t *, char *, cred_t *,
947 caller_context_t *, int);
948 extern int fop_mkdir(vnode_t *, char *, vattr_t *, vnode_t **, cred_t *,
949 caller_context_t *, int, vsecattr_t *);
950 extern int fop_rmdir(vnode_t *, char *, vnode_t *, cred_t *,
951 caller_context_t *, int);
952 extern int fop_readdir(vnode_t *, uio_t *, cred_t *, int *,
953 caller_context_t *, int);
954 extern int fop_symlink(vnode_t *, char *, vattr_t *, char *, cred_t *,
955 caller_context_t *, int);
956 extern int fop_readlink(vnode_t *, uio_t *, cred_t *, caller_context_t *);
957 extern int fop_fsync(vnode_t *, int, cred_t *, caller_context_t *);
958 extern void fop_inactive(vnode_t *, cred_t *, caller_context_t *);
959 extern int fop_fid(vnode_t *, struct fid *, caller_context_t *);
960 extern int fop_rwlock(vnode_t *, int, caller_context_t *);
961 extern void fop_rwunlock(vnode_t *, int, caller_context_t *);
962 extern int fop_seek(vnode_t *, offset_t, offset_t *, caller_context_t *);
963 extern int fop_cmp(vnode_t *, vnode_t *, caller_context_t *);
964 extern int fop_frlock(vnode_t *, int, struct flock64 *, int, offset_t,
965 struct flk_callback *, cred_t *,
966 caller_context_t *);
967 extern int fop_space(vnode_t *, int, struct flock64 *, int, offset_t,
968 cred_t *, caller_context_t *);
969 extern int fop_realvp(vnode_t *, vnode_t **, caller_context_t *);
970 extern int fop_getpage(vnode_t *, offset_t, size_t, uint_t *,
971 struct page **, size_t, struct seg *,
972 caddr_t, enum seg_rw, cred_t *,
973 caller_context_t *);
974 extern int fop_putpage(vnode_t *, offset_t, size_t, int, cred_t *,
975 caller_context_t *);
976 extern int fop_map(vnode_t *, offset_t, struct as *, caddr_t *, size_t,
977 uchar_t, uchar_t, uint_t, cred_t *cr,
978 caller_context_t *);
979 extern int fop_addmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
980 uchar_t, uchar_t, uint_t, cred_t *,
981 caller_context_t *);
982 extern int fop_delmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
983 uint_t, uint_t, uint_t, cred_t *,
984 caller_context_t *);
985 extern int fop_poll(vnode_t *, short, int, short *, struct pollhead **,
986 caller_context_t *);
987 extern int fop_dump(vnode_t *, caddr_t, offset_t, offset_t,
988 caller_context_t *);
989 extern int fop_pathconf(vnode_t *, int, ulong_t *, cred_t *,
990 caller_context_t *);
991 extern int fop_pageio(vnode_t *, struct page *, uoff_t, size_t, int,
992 cred_t *, caller_context_t *);
993 extern int fop_dumpctl(vnode_t *, int, offset_t *, caller_context_t *);
994 extern void fop_dispose(vnode_t *, struct page *, int, int, cred_t *,
995 caller_context_t *);
996 extern int fop_setsecattr(vnode_t *, vsecattr_t *, int, cred_t *,
997 caller_context_t *);
998 extern int fop_getsecattr(vnode_t *, vsecattr_t *, int, cred_t *,
999 caller_context_t *);
1000 extern int fop_shrlock(vnode_t *, int, struct shrlock *, int, cred_t *,
1001 caller_context_t *);
1002 extern int fop_vnevent(vnode_t *, vnevent_t, vnode_t *, char *,
1003 caller_context_t *);
1004 extern int fop_reqzcbuf(vnode_t *, enum uio_rw, xuio_t *, cred_t *,
1005 caller_context_t *);
1006 extern int fop_retzcbuf(vnode_t *, xuio_t *, cred_t *, caller_context_t *);
1008 #endif /* _KERNEL */
1010 #define VOPNAME_OPEN "open"
1011 #define VOPNAME_CLOSE "close"
1012 #define VOPNAME_READ "read"
1013 #define VOPNAME_WRITE "write"
1014 #define VOPNAME_IOCTL "ioctl"
1015 #define VOPNAME_SETFL "setfl"
1016 #define VOPNAME_GETATTR "getattr"
1017 #define VOPNAME_SETATTR "setattr"
1018 #define VOPNAME_ACCESS "access"
1019 #define VOPNAME_LOOKUP "lookup"
1020 #define VOPNAME_CREATE "create"
1021 #define VOPNAME_REMOVE "remove"
1022 #define VOPNAME_LINK "link"
1023 #define VOPNAME_RENAME "rename"
1024 #define VOPNAME_MKDIR "mkdir"
1025 #define VOPNAME_RMDIR "rmdir"
1026 #define VOPNAME_READDIR "readdir"
1027 #define VOPNAME_SYMLINK "symlink"
1028 #define VOPNAME_READLINK "readlink"
1029 #define VOPNAME_FSYNC "fsync"
1030 #define VOPNAME_INACTIVE "inactive"
1031 #define VOPNAME_FID "fid"
1032 #define VOPNAME_RWLOCK "rwlock"
1033 #define VOPNAME_RWUNLOCK "rwunlock"
1034 #define VOPNAME_SEEK "seek"
1035 #define VOPNAME_CMP "cmp"
1036 #define VOPNAME_FRLOCK "frlock"
1037 #define VOPNAME_SPACE "space"
1038 #define VOPNAME_REALVP "realvp"
1039 #define VOPNAME_GETPAGE "getpage"
1040 #define VOPNAME_PUTPAGE "putpage"
1041 #define VOPNAME_MAP "map"
1042 #define VOPNAME_ADDMAP "addmap"
1043 #define VOPNAME_DELMAP "delmap"
1044 #define VOPNAME_POLL "poll"
1045 #define VOPNAME_DUMP "dump"
1046 #define VOPNAME_PATHCONF "pathconf"
1047 #define VOPNAME_PAGEIO "pageio"
1048 #define VOPNAME_DUMPCTL "dumpctl"
1049 #define VOPNAME_DISPOSE "dispose"
1050 #define VOPNAME_GETSECATTR "getsecattr"
1051 #define VOPNAME_SETSECATTR "setsecattr"
1052 #define VOPNAME_SHRLOCK "shrlock"
1053 #define VOPNAME_VNEVENT "vnevent"
1054 #define VOPNAME_REQZCBUF "reqzcbuf"
1055 #define VOPNAME_RETZCBUF "retzcbuf"
1058 * Flags for fop_lookup
1060 * Defined in file.h, but also possible, FIGNORECASE and FSEARCH
1063 #define LOOKUP_DIR 0x01 /* want parent dir vp */
1064 #define LOOKUP_XATTR 0x02 /* lookup up extended attr dir */
1065 #define CREATE_XATTR_DIR 0x04 /* Create extended attr dir */
1066 #define LOOKUP_HAVE_SYSATTR_DIR 0x08 /* Already created virtual GFS dir */
1069 * Flags for fop_readdir
1071 #define V_RDDIR_ENTFLAGS 0x01 /* request dirent flags */
1072 #define V_RDDIR_ACCFILTER 0x02 /* filter out inaccessible dirents */
1075 * Flags for fop_rwlock/fop_rwunlock
1076 * fop_rwlock will return the flag that was actually set, or -1 if none.
1078 #define V_WRITELOCK_TRUE (1) /* Request write-lock on the vnode */
1079 #define V_WRITELOCK_FALSE (0) /* Request read-lock on the vnode */
1082 * Flags for fop_dumpctl
1084 #define DUMP_ALLOC 0
1085 #define DUMP_FREE 1
1086 #define DUMP_SCAN 2
1089 * Public vnode manipulation functions.
1091 #ifdef _KERNEL
1093 vnode_t *vn_alloc(int);
1094 void vn_reinit(vnode_t *);
1095 void vn_recycle(vnode_t *);
1096 void vn_free(vnode_t *);
1098 int vn_is_readonly(vnode_t *);
1099 int vn_is_opened(vnode_t *, v_mode_t);
1100 int vn_is_mapped(vnode_t *, v_mode_t);
1101 int vn_has_other_opens(vnode_t *, v_mode_t);
1102 void vn_open_upgrade(vnode_t *, int);
1103 void vn_open_downgrade(vnode_t *, int);
1105 int vn_can_change_zones(vnode_t *vp);
1107 int vn_has_flocks(vnode_t *);
1108 int vn_has_mandatory_locks(vnode_t *, int);
1109 int vn_has_cached_data(vnode_t *);
1111 void vn_setops(struct vnode *, const struct vnodeops *);
1112 const struct vnodeops *vn_getops(struct vnode *);
1113 int vn_matchops(struct vnode *, const struct vnodeops *);
1114 int vn_ismntpt(vnode_t *);
1116 struct vfs *vn_mountedvfs(vnode_t *);
1118 int vn_in_dnlc(vnode_t *);
1120 void vn_create_cache(void);
1121 void vn_destroy_cache(void);
1123 int vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
1124 struct vnode **vpp, enum create crwhy, mode_t umask);
1125 int vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,
1126 struct vnode **vpp, enum create crwhy,
1127 mode_t umask, struct vnode *startvp, int fd);
1128 int vn_create(char *pnamep, enum uio_seg seg, struct vattr *vap,
1129 enum vcexcl excl, int mode, struct vnode **vpp,
1130 enum create why, int flag, mode_t umask);
1131 int vn_createat(char *pnamep, enum uio_seg seg, struct vattr *vap,
1132 enum vcexcl excl, int mode, struct vnode **vpp,
1133 enum create why, int flag, mode_t umask, struct vnode *startvp);
1134 int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len,
1135 offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit,
1136 cred_t *cr, ssize_t *residp);
1137 void vn_rele(struct vnode *vp);
1138 void vn_rele_async(struct vnode *vp, struct taskq *taskq);
1139 void vn_rele_dnlc(struct vnode *vp);
1140 void vn_rele_stream(struct vnode *vp);
1141 int vn_link(char *from, char *to, enum uio_seg seg);
1142 int vn_linkat(vnode_t *fstartvp, char *from, enum symfollow follow,
1143 vnode_t *tstartvp, char *to, enum uio_seg seg);
1144 int vn_rename(char *from, char *to, enum uio_seg seg);
1145 int vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname,
1146 enum uio_seg seg);
1147 int vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag);
1148 int vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg,
1149 enum rm dirflag);
1150 int vn_compare(vnode_t *vp1, vnode_t *vp2);
1151 int vn_vfswlock(struct vnode *vp);
1152 int vn_vfswlock_wait(struct vnode *vp);
1153 int vn_vfsrlock(struct vnode *vp);
1154 int vn_vfsrlock_wait(struct vnode *vp);
1155 void vn_vfsunlock(struct vnode *vp);
1156 int vn_vfswlock_held(struct vnode *vp);
1157 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr);
1158 vnode_t *makespecvp(dev_t dev, vtype_t type);
1159 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
1160 void vn_vfslocks_rele(vn_vfslocks_entry_t *);
1161 boolean_t vn_is_reparse(vnode_t *, cred_t *, caller_context_t *);
1163 void vn_copypath(struct vnode *src, struct vnode *dst);
1164 void vn_setpath_str(struct vnode *vp, const char *str, size_t len);
1165 void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp,
1166 const char *path, size_t plen);
1167 void vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len);
1169 /* Vnode event notification */
1170 void vnevent_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *);
1171 void vnevent_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *);
1172 void vnevent_remove(vnode_t *, vnode_t *, char *, caller_context_t *);
1173 void vnevent_rmdir(vnode_t *, vnode_t *, char *, caller_context_t *);
1174 void vnevent_create(vnode_t *, caller_context_t *);
1175 void vnevent_link(vnode_t *, caller_context_t *);
1176 void vnevent_rename_dest_dir(vnode_t *, caller_context_t *ct);
1177 void vnevent_mountedover(vnode_t *, caller_context_t *);
1178 void vnevent_truncate(vnode_t *, caller_context_t *);
1179 int vnevent_support(vnode_t *, caller_context_t *);
1180 void vnevent_pre_rename_src(vnode_t *, vnode_t *, char *,
1181 caller_context_t *);
1182 void vnevent_pre_rename_dest(vnode_t *, vnode_t *, char *,
1183 caller_context_t *);
1184 void vnevent_pre_rename_dest_dir(vnode_t *, vnode_t *, char *,
1185 caller_context_t *);
1187 /* Vnode specific data */
1188 void vsd_create(uint_t *, void (*)(void *));
1189 void vsd_destroy(uint_t *);
1190 void *vsd_get(vnode_t *, uint_t);
1191 int vsd_set(vnode_t *, uint_t, void *);
1192 void vsd_free(vnode_t *);
1195 * Extensible vnode attribute (xva) routines:
1196 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
1197 * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
1199 void xva_init(xvattr_t *);
1200 xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */
1202 void xattr_init(void); /* Initialize vnodeops for xattrs */
1204 /* GFS tunnel for xattrs */
1205 int xattr_dir_lookup(vnode_t *, vnode_t **, int, cred_t *);
1207 /* Reparse Point */
1208 void reparse_point_init(void);
1210 /* Context identification */
1211 u_longlong_t fs_new_caller_id();
1213 int vn_vmpss_usepageio(vnode_t *);
1216 * All changes to v_count should be done through VN_HOLD() or VN_RELE(), or
1217 * one of their variants. This makes it possible to ensure proper locking,
1218 * and to guarantee that all modifications are accompanied by a firing of
1219 * the vn-hold or vn-rele SDT DTrace probe.
1221 * Example DTrace command for tracing vnode references using these probes:
1223 * dtrace -q -n 'sdt:::vn-hold,sdt:::vn-rele
1225 * this->vp = (vnode_t *)arg0;
1226 * printf("%s %s(%p[%s]) %d\n", execname, probename, this->vp,
1227 * this->vp->v_path == NULL ? "NULL" : stringof(this->vp->v_path),
1228 * this->vp->v_count)
1229 * }'
1231 #define VN_HOLD_LOCKED(vp) { \
1232 ASSERT(mutex_owned(&(vp)->v_lock)); \
1233 (vp)->v_count++; \
1234 DTRACE_PROBE1(vn__hold, vnode_t *, vp); \
1237 #define VN_HOLD(vp) { \
1238 mutex_enter(&(vp)->v_lock); \
1239 VN_HOLD_LOCKED(vp); \
1240 mutex_exit(&(vp)->v_lock); \
1243 #define VN_RELE(vp) { \
1244 vn_rele(vp); \
1247 #define VN_RELE_ASYNC(vp, taskq) { \
1248 vn_rele_async(vp, taskq); \
1251 #define VN_RELE_LOCKED(vp) { \
1252 ASSERT(mutex_owned(&(vp)->v_lock)); \
1253 ASSERT((vp)->v_count >= 1); \
1254 (vp)->v_count--; \
1255 DTRACE_PROBE1(vn__rele, vnode_t *, vp); \
1258 #define VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev) { \
1259 (vp)->v_vfsp = (vfsp); \
1260 (vp)->v_type = (type); \
1261 (vp)->v_rdev = (dev); \
1265 * Compare two vnodes for equality. In general this macro should be used
1266 * in preference to calling fop_cmp directly.
1268 #define VN_CMP(VP1, VP2) ((VP1) == (VP2) ? 1 : \
1269 ((VP1) && (VP2) && (vn_getops(VP1) == vn_getops(VP2)) ? \
1270 fop_cmp(VP1, VP2, NULL) : 0))
1273 * Some well-known global vnodes used by the VM system to name pages.
1275 extern struct vnode kvps[];
1277 typedef enum {
1278 KV_KVP, /* vnode for all segkmem pages */
1279 KV_ZVP, /* vnode for all ZFS pages */
1280 #if defined(__sparc)
1281 KV_MPVP, /* vnode for all page_t meta-pages */
1282 KV_PROMVP, /* vnode for all PROM pages */
1283 #endif /* __sparc */
1284 KV_MAX /* total number of vnodes in kvps[] */
1285 } kvps_index_t;
1287 #define VN_ISKAS(vp) ((vp) >= &kvps[0] && (vp) < &kvps[KV_MAX])
1289 #endif /* _KERNEL */
1292 * Flags to fop_setattr/fop_getattr.
1294 #define ATTR_UTIME 0x01 /* non-default utime(2) request */
1295 #define ATTR_EXEC 0x02 /* invocation from exec(2) */
1296 #define ATTR_COMM 0x04 /* yield common vp attributes */
1297 #define ATTR_HINT 0x08 /* information returned will be `hint' */
1298 #define ATTR_REAL 0x10 /* yield attributes of the real vp */
1299 #define ATTR_NOACLCHECK 0x20 /* Don't check ACL when checking permissions */
1300 #define ATTR_TRIGGER 0x40 /* Mount first if vnode is a trigger mount */
1302 * Generally useful macros.
1304 #define VBSIZE(vp) ((vp)->v_vfsp->vfs_bsize)
1306 #define VTOZONE(vp) ((vp)->v_vfsp->vfs_zone)
1308 #define NULLVP ((struct vnode *)0)
1309 #define NULLVPP ((struct vnode **)0)
1311 #ifdef _KERNEL
1314 * Structure used while handling asynchronous fop_putpage operations.
1316 struct async_reqs {
1317 struct async_reqs *a_next; /* pointer to next arg struct */
1318 struct vnode *a_vp; /* vnode pointer */
1319 uoff_t a_off; /* offset in file */
1320 uint_t a_len; /* size of i/o request */
1321 int a_flags; /* flags to indicate operation type */
1322 struct cred *a_cred; /* cred pointer */
1323 ushort_t a_prealloced; /* set if struct is pre-allocated */
1327 * VN_DISPOSE() -- given a page pointer, safely invoke fop_dispose().
1328 * Note that there is no guarantee that the page passed in will be
1329 * freed. If that is required, then a check after calling VN_DISPOSE would
1330 * be necessary to ensure the page was freed.
1332 #define VN_DISPOSE(pp, flag, dn, cr) { \
1333 if ((pp)->p_vnode != NULL && !VN_ISKAS((pp)->p_vnode)) \
1334 fop_dispose((pp)->p_vnode, (pp), (flag), (dn), (cr), NULL); \
1335 else if ((flag) == B_FREE) \
1336 page_free((pp), (dn)); \
1337 else \
1338 page_destroy((pp), (dn)); \
1341 #endif /* _KERNEL */
1343 #ifdef __cplusplus
1345 #endif
1347 #endif /* _SYS_VNODE_H */