xref: /netbsd/external/cddl/osnet/sys/sys/vnode.h (revision 6550d01e)
1 
2 /*	$NetBSD: vnode.h,v 1.8 2011/01/21 12:24:24 pooka Exp $	*/
3 
4 /*
5  * CDDL HEADER START
6  *
7  * The contents of this file are subject to the terms of the
8  * Common Development and Distribution License (the "License").
9  * You may not use this file except in compliance with the License.
10  *
11  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12  * or http://www.opensolaris.org/os/licensing.
13  * See the License for the specific language governing permissions
14  * and limitations under the License.
15  *
16  * When distributing Covered Code, include this CDDL HEADER in each
17  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18  * If applicable, add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your own identifying
20  * information: Portions Copyright [yyyy] [name of copyright owner]
21  *
22  * CDDL HEADER END
23  */
24 /*
25  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 /*
33  * University Copyright- Copyright (c) 1982, 1986, 1988
34  * The Regents of the University of California
35  * All Rights Reserved
36  *
37  * University Acknowledgment- Portions of this document are derived from
38  * software developed by the University of California, Berkeley, and its
39  * contributors.
40  */
41 
42 /*-
43  * Copyright (c) 2009 The NetBSD Foundation, Inc.
44  * All rights reserved.
45  *
46  * This code is derived from software contributed to The NetBSD Foundation
47  * by Andrew Doran.
48  *
49  * Redistribution and use in source and binary forms, with or without
50  * modification, are permitted provided that the following conditions
51  * are met:
52  * 1. Redistributions of source code must retain the above copyright
53  *    notice, this list of conditions and the following disclaimer.
54  * 2. Redistributions in binary form must reproduce the above copyright
55  *    notice, this list of conditions and the following disclaimer in the
56  *    documentation and/or other materials provided with the distribution.
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68  * POSSIBILITY OF SUCH DAMAGE.
69  */
70 
71 /*-
72  * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
73  * All rights reserved.
74  *
75  * Redistribution and use in source and binary forms, with or without
76  * modification, are permitted provided that the following conditions
77  * are met:
78  * 1. Redistributions of source code must retain the above copyright
79  *    notice, this list of conditions and the following disclaimer.
80  * 2. Redistributions in binary form must reproduce the above copyright
81  *    notice, this list of conditions and the following disclaimer in the
82  *    documentation and/or other materials provided with the distribution.
83  *
84  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
85  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
88  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
90  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94  * SUCH DAMAGE.
95  *
96  * $FreeBSD: src/sys/compat/opensolaris/sys/vnode.h,v 1.3 2007/05/31 11:51:49 kib Exp $
97  */
98 
99 #include <sys/mount.h>
100 #include_next <sys/vnode.h>
101 
102 #ifndef _OPENSOLARIS_SYS_VNODE_H_
103 #define	_OPENSOLARIS_SYS_VNODE_H_
104 
105 #include <sys/cred.h>
106 #include <sys/fcntl.h>
107 #include <sys/namei.h>
108 #include <sys/proc.h>
109 #include <sys/filedesc.h>
110 #include <sys/buf.h>
111 #include <sys/debug.h>
112 
113 
114 #ifdef _KERNEL
115 #include <sys/vfs_syscalls.h>
116 #endif
117 
118 typedef	struct vattr	vattr_t;
119 typedef	enum vtype	vtype_t;
120 typedef	void		caller_context_t;
121 
122 typedef int (**vnodeops_t)(void *);
123 
124 #define	vop_fid		vop_vptofh
125 #define	vop_fid_args	vop_vptofh_args
126 #define	a_fid		a_fhp
127 
128 #define	v_count		v_usecount
129 #define	v_object	v_uobj
130 
131 struct vop_vptofh_args {
132 	struct vnode *a_vp;
133 	struct fid *a_fid;
134 };
135 
136 /*
137  * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
138  */
139 
140 /*
141  * Flags to VOP_SETATTR/VOP_GETATTR.
142  */
143 #define ATTR_UTIME  0x01    /* non-default utime(2) request */
144 #define ATTR_EXEC   0x02    /* invocation from exec(2) */
145 #define ATTR_COMM   0x04    /* yield common vp attributes */
146 #define ATTR_HINT   0x08    /* information returned will be `hint' */
147 #define ATTR_REAL   0x10    /* yield attributes of the real vp */
148 #define ATTR_NOACLCHECK 0x20    /* Don't check ACL when checking permissions */
149 #define ATTR_TRIGGER    0x40    /* Mount first if vnode is a trigger mount */
150 
151 typedef struct vsecattr {
152 	uint_t		vsa_mask;	/* See below */
153 	int		vsa_aclcnt;	/* ACL entry count */
154 	void		*vsa_aclentp;	/* pointer to ACL entries */
155 	int		vsa_dfaclcnt;	/* default ACL entry count */
156 	void		*vsa_dfaclentp;	/* pointer to default ACL entries */
157 	size_t		vsa_aclentsz;	/* ACE size in bytes of vsa_aclentp */
158 	uint_t		vsa_aclflags;	/* ACE ACL flags */
159 } vsecattr_t;
160 
161 #define V_XATTRDIR      0x0000  /* attribute unnamed directory */
162 #define IS_XATTRDIR(vp)	(0)
163 
164 #define	AV_SCANSTAMP_SZ	32		/* length of anti-virus scanstamp */
165 
166 /*
167  * Structure of all optional attributes.
168  */
169 typedef struct xoptattr {
170 	timestruc_t	xoa_createtime;	/* Create time of file */
171 	uint8_t		xoa_archive;
172 	uint8_t		xoa_system;
173 	uint8_t		xoa_readonly;
174 	uint8_t		xoa_hidden;
175 	uint8_t		xoa_nounlink;
176 	uint8_t		xoa_immutable;
177 	uint8_t		xoa_appendonly;
178 	uint8_t		xoa_nodump;
179 	uint8_t		xoa_opaque;
180 	uint8_t		xoa_av_quarantined;
181 	uint8_t		xoa_av_modified;
182 	uint8_t		xoa_av_scanstamp[AV_SCANSTAMP_SZ];
183 	uint8_t 	xoa_reparse;
184 } xoptattr_t;
185 
186 
187 /*
188  * The xvattr structure is really a variable length structure that
189  * is made up of:
190  * - The classic vattr_t (xva_vattr)
191  * - a 32 bit quantity (xva_mapsize) that specifies the size of the
192  *   attribute bitmaps in 32 bit words.
193  * - A pointer to the returned attribute bitmap (needed because the
194  *   previous element, the requested attribute bitmap) is variable lenth.
195  * - The requested attribute bitmap, which is an array of 32 bit words.
196  *   Callers use the XVA_SET_REQ() macro to set the bits corresponding to
197  *   the attributes that are being requested.
198  * - The returned attribute bitmap, which is an array of 32 bit words.
199  *   File systems that support optional attributes use the XVA_SET_RTN()
200  *   macro to set the bits corresponding to the attributes that are being
201  *   returned.
202  * - The xoptattr_t structure which contains the attribute values
203  *
204  * xva_mapsize determines how many words in the attribute bitmaps.
205  * Immediately following the attribute bitmaps is the xoptattr_t.
206  * xva_getxoptattr() is used to get the pointer to the xoptattr_t
207  * section.
208  */
209 
210 #define	XVA_MAPSIZE	3		/* Size of attr bitmaps */
211 #define	XVA_MAGIC	0x78766174	/* Magic # for verification */
212 
213 /*
214  * The xvattr structure is an extensible structure which permits optional
215  * attributes to be requested/returned.  File systems may or may not support
216  * optional attributes.  They do so at their own discretion but if they do
217  * support optional attributes, they must register the VFSFT_XVATTR feature
218  * so that the optional attributes can be set/retrived.
219  *
220  * The fields of the xvattr structure are:
221  *
222  * xva_vattr - The first element of an xvattr is a legacy vattr structure
223  * which includes the common attributes.  If AT_XVATTR is set in the va_mask
224  * then the entire structure is treated as an xvattr.  If AT_XVATTR is not
225  * set, then only the xva_vattr structure can be used.
226  *
227  * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
228  *
229  * xva_mapsize - Size of requested and returned attribute bitmaps.
230  *
231  * xva_rtnattrmapp - Pointer to xva_rtnattrmap[].  We need this since the
232  * size of the array before it, xva_reqattrmap[], could change which means
233  * the location of xva_rtnattrmap[] could change.  This will allow unbundled
234  * file systems to find the location of xva_rtnattrmap[] when the sizes change.
235  *
236  * xva_reqattrmap[] - Array of requested attributes.  Attributes are
237  * represented by a specific bit in a specific element of the attribute
238  * map array.  Callers set the bits corresponding to the attributes
239  * that the caller wants to get/set.
240  *
241  * xva_rtnattrmap[] - Array of attributes that the file system was able to
242  * process.  Not all file systems support all optional attributes.  This map
243  * informs the caller which attributes the underlying file system was able
244  * to set/get.  (Same structure as the requested attributes array in terms
245  * of each attribute  corresponding to specific bits and array elements.)
246  *
247  * xva_xoptattrs - Structure containing values of optional attributes.
248  * These values are only valid if the corresponding bits in xva_reqattrmap
249  * are set and the underlying file system supports those attributes.
250  */
251 typedef struct xvattr {
252 	vattr_t		xva_vattr;	/* Embedded vattr structure */
253 	uint32_t	xva_magic;	/* Magic Number */
254 	uint32_t	xva_mapsize;	/* Size of attr bitmap (32-bit words) */
255 	uint32_t	*xva_rtnattrmapp;	/* Ptr to xva_rtnattrmap[] */
256 	uint32_t	xva_reqattrmap[XVA_MAPSIZE];	/* Requested attrs */
257 	uint32_t	xva_rtnattrmap[XVA_MAPSIZE];	/* Returned attrs */
258 	xoptattr_t	xva_xoptattrs;	/* Optional attributes */
259 } xvattr_t;
260 
261 /* vsa_mask values */
262 #define	VSA_ACL			0x0001
263 #define	VSA_ACLCNT		0x0002
264 #define	VSA_DFACL		0x0004
265 #define	VSA_DFACLCNT		0x0008
266 #define	VSA_ACE			0x0010
267 #define	VSA_ACECNT		0x0020
268 #define	VSA_ACE_ALLTYPES	0x0040
269 #define	VSA_ACE_ACLFLAGS	0x0080	/* get/set ACE ACL flags */
270 
271 #define v_lock v_interlock
272 
273 /*
274  * vnode flags.
275  */
276 #define VROOT		VV_ROOT/* root of its file system */
277 #define VNOCACHE	0x00/* don't keep cache pages on vnode */
278 #define VNOMAP		VV_MAPPED/* file cannot be mapped/faulted */
279 #define VDUP		0x00/* file should be dup'ed rather then opened */
280 #define VNOSWAP		0x00/* file cannot be used as virtual swap device */
281 #define VNOMOUNT	0x00/* file cannot be covered by mount */
282 #define VISSWAP		0x00/* vnode is being used for swap */
283 #define VSWAPLIKE	0x00/* vnode acts like swap (but may not be) */
284 
285 int	vn_is_readonly(vnode_t *);
286 
287 #define	vn_free(vp)		vrele((vp))
288 #define	vn_setops(vp, ops)	(0)
289 #define	vn_vfswlock(vp)		(0)
290 #define	vn_vfsunlock(vp)	do { } while (0)
291 #define	vn_ismntpt(vp)		((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
292 #define	vn_mountedvfs(vp)	((vp)->v_mountedhere)
293 #define	vn_has_cached_data(vp)	((vp)->v_uobj.uo_npages > 0)
294 #define vn_renamepath(tdvp, svp, tnm, lentnm)   do { } while (0)
295 
296 #define	VN_HOLD(v)	vref(v)
297 #define	VN_RELE(v)	vrele(v)
298 #define	VN_URELE(v)	vput(v)
299 #define	VN_SET_VFS_TYPE_DEV(vp, vfs, type, flag)	(0)
300 
301 #define VI_LOCK(vp)     mutex_enter(&(vp)->v_interlock)
302 #define VI_UNLOCK(vp)   mutex_exit(&(vp)->v_interlock)
303 
304 #define	VOP_REALVP(vp, vpp, ct)	(*(vpp) = (vp), 0)
305 
306 #define vnevent_remove(vp, dvp, name, ct) do { } while (0)
307 #define vnevent_rmdir(vp, dvp, name, ct) do { } while (0)
308 #define vnevent_rename_src(vp, dvp, name, ct) do { } while (0)
309 #define	vnevent_rename_dest(vp, dvp, name, ct)	do { } while (0)
310 #define vnevent_rename_dest_dir(vp, ct)     do { } while (0)
311 #define vnevent_create(vp, ct)  do { } while (0)
312 #define vnevent_link(vp, ct)            do { } while (0)
313 
314 #define	IS_DEVVP(vp)	\
315 	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
316 
317 #define	MODEMASK	ALLPERMS
318 
319 #define	specvp(vp, rdev, type, cr)	(VN_HOLD(vp), (vp))
320 #define	MANDMODE(mode)	(0)
321 #define	chklock(vp, op, offset, size, mode, ct)	(0)
322 #define	cleanlocks(vp, pid, foo)	do { } while (0)
323 #define	cleanshares(vp, pid)		do { } while (0)
324 
325 /*
326  * We will use va_spare is place of Solaris' va_mask.
327  * This field is initialized in zfs_setattr().
328  */
329 #define	va_mask		va_spare
330 /* TODO: va_fileid is shorter than va_nodeid !!! */
331 #define	va_nodeid	va_fileid
332 /* TODO: This field needs conversion! */
333 #define	va_nblocks	va_bytes
334 #define	va_blksize	va_blocksize
335 #define	va_seq		va_gen
336 
337 #define	EXCL		0
338 
339 #define	AT_TYPE		0x0001
340 #define	AT_MODE		0x0002
341 #define	AT_UID		0x0004
342 #define	AT_GID		0x0008
343 #define	AT_FSID		0x0010
344 #define	AT_NODEID	0x0020
345 #define	AT_NLINK	0x0040
346 #define	AT_SIZE		0x0080
347 #define	AT_ATIME	0x0100
348 #define	AT_MTIME	0x0200
349 #define	AT_CTIME	0x0400
350 #define	AT_RDEV		0x0800
351 #define	AT_BLKSIZE	0x1000
352 #define	AT_NBLOCKS	0x2000
353 #define	AT_SEQ		0x4000
354 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
355 			 AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
356 
357 #define	ACCESSED		(AT_ATIME)
358 #define	STATE_CHANGED		(AT_CTIME)
359 #define	CONTENT_MODIFIED	(AT_MTIME | AT_CTIME)
360 
361 /*
362  * If AT_XVATTR is set then there are additional bits to process in
363  * the xvattr_t's attribute bitmap.  If this is not set then the bitmap
364  * MUST be ignored.  Note that this bit must be set/cleared explicitly.
365  * That is, setting AT_ALL will NOT set AT_XVATTR.
366  */
367 #define	AT_XVATTR	0x10000
368 
369 #define	AT_ALL		(AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
370 			AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
371 			AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
372 
373 #define	AT_STAT		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
374 			AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE)
375 
376 #define	AT_TIMES	(AT_ATIME|AT_MTIME|AT_CTIME)
377 
378 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
379 			AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
380 
381 /*
382  * Attribute bits used in the extensible attribute's (xva's) attribute
383  * bitmaps.  Note that the bitmaps are made up of a variable length number
384  * of 32-bit words.  The convention is to use XAT{n}_{attrname} where "n"
385  * is the element in the bitmap (starting at 1).  This convention is for
386  * the convenience of the maintainer to keep track of which element each
387  * attribute belongs to.
388  *
389  * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY.  CONSUMERS
390  * MUST USE THE XAT_* DEFINES.
391  */
392 #define	XAT0_INDEX	0LL		/* Index into bitmap for XAT0 attrs */
393 #define	XAT0_CREATETIME	0x00000001	/* Create time of file */
394 #define	XAT0_ARCHIVE	0x00000002	/* Archive */
395 #define	XAT0_SYSTEM	0x00000004	/* System */
396 #define	XAT0_READONLY	0x00000008	/* Readonly */
397 #define	XAT0_HIDDEN	0x00000010	/* Hidden */
398 #define	XAT0_NOUNLINK	0x00000020	/* Nounlink */
399 #define	XAT0_IMMUTABLE	0x00000040	/* immutable */
400 #define	XAT0_APPENDONLY	0x00000080	/* appendonly */
401 #define	XAT0_NODUMP	0x00000100	/* nodump */
402 #define	XAT0_OPAQUE	0x00000200	/* opaque */
403 #define	XAT0_AV_QUARANTINED	0x00000400	/* anti-virus quarantine */
404 #define	XAT0_AV_MODIFIED	0x00000800	/* anti-virus modified */
405 #define	XAT0_AV_SCANSTAMP	0x00001000	/* anti-virus scanstamp */
406 #define XAT0_REPARSE 	0x00002000 	/* FS reparse point */
407 
408 #define	XAT0_ALL_ATTRS	(XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
409     XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
410     XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| \
411     XAT0_AV_MODIFIED|XAT0_AV_SCANSTAMP)
412 
413 /* Support for XAT_* optional attributes */
414 #define	XVA_MASK		0xffffffff	/* Used to mask off 32 bits */
415 #define	XVA_SHFT		32		/* Used to shift index */
416 
417 /*
418  * Used to pry out the index and attribute bits from the XAT_* attributes
419  * defined below.  Note that we're masking things down to 32 bits then
420  * casting to uint32_t.
421  */
422 #define	XVA_INDEX(attr)		((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
423 #define	XVA_ATTRBIT(attr)	((uint32_t)((attr) & XVA_MASK))
424 
425 /*
426  * The following defines present a "flat namespace" so that consumers don't
427  * need to keep track of which element belongs to which bitmap entry.
428  *
429  * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
430  */
431 #define	XAT_CREATETIME		((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
432 #define	XAT_ARCHIVE		((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
433 #define	XAT_SYSTEM		((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
434 #define	XAT_READONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
435 #define	XAT_HIDDEN		((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
436 #define	XAT_NOUNLINK		((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
437 #define	XAT_IMMUTABLE		((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
438 #define	XAT_APPENDONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
439 #define	XAT_NODUMP		((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
440 #define	XAT_OPAQUE		((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
441 #define	XAT_AV_QUARANTINED	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
442 #define	XAT_AV_MODIFIED		((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
443 #define	XAT_AV_SCANSTAMP	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
444 #define XAT_REPARSE 		((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
445 
446 /*
447  * The returned attribute map array (xva_rtnattrmap[]) is located past the
448  * requested attribute map array (xva_reqattrmap[]).  Its location changes
449  * when the array sizes change.  We use a separate pointer in a known location
450  * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[].  This is
451  * set in xva_init()
452  */
453 #define	XVA_RTNATTRMAP(xvap)	((xvap)->xva_rtnattrmapp)
454 
455 /*
456  * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
457  * of requested attributes (xva_reqattrmap[]).
458  */
459 #define	XVA_SET_REQ(xvap, attr)					\
460 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
461 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
462 	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
463 
464 /*
465  * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
466  * of requested attributes (xva_reqattrmap[]).
467  */
468 #define XVA_CLR_REQ(xvap, attr)                                 \
469 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);          \
470 	ASSERT((xvap)->xva_magic == XVA_MAGIC);                 \
471 	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
472 /*
473  * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
474  * of returned attributes (xva_rtnattrmap[]).
475  */
476 #define	XVA_SET_RTN(xvap, attr)					\
477 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
478 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
479 	(XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
480 
481 /*
482  * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
483  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
484  */
485 #define	XVA_ISSET_REQ(xvap, attr)					\
486 	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
487 		((xvap)->xva_magic == XVA_MAGIC) &&			\
488 		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
489 	((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) :	0)
490 
491 /*
492  * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
493  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
494  */
495 #define	XVA_ISSET_RTN(xvap, attr)					\
496 	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
497 		((xvap)->xva_magic == XVA_MAGIC) &&			\
498 		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
499 	((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
500 
501 static __inline void
502 vattr_init_mask(vattr_t *vap)
503 {
504 
505 	vap->va_mask = 0;
506 
507 	if (vap->va_type != VNON)
508 		vap->va_mask |= AT_TYPE;
509 	if (vap->va_uid != (uid_t)VNOVAL)
510 		vap->va_mask |= AT_UID;
511 	if (vap->va_gid != (gid_t)VNOVAL)
512 		vap->va_mask |= AT_GID;
513 	if (vap->va_size != (u_quad_t)VNOVAL)
514 		vap->va_mask |= AT_SIZE;
515 	if (vap->va_atime.tv_sec != VNOVAL)
516 		vap->va_mask |= AT_ATIME;
517 	if (vap->va_mtime.tv_sec != VNOVAL)
518 		vap->va_mask |= AT_MTIME;
519 	if (vap->va_mode != (u_short)VNOVAL)
520 		vap->va_mask |= AT_MODE;
521 }
522 
523 #define	FCREAT	O_CREAT
524 #define	FTRUNC	O_TRUNC
525 #define	FSYNC	FFSYNC
526 #define	FOFFMAX	0x00
527 
528 enum create	{ CRCREAT };
529 
530 static __inline int
531 zfs_vn_open(const char *pnamep, enum uio_seg seg, int filemode, int createmode,
532     vnode_t **vpp, enum create crwhy, mode_t umask)
533 {
534 	struct pathbuf *pb;
535 	struct nameidata nd;
536 	int error;
537 
538 	ASSERT(seg == UIO_SYSSPACE);
539 	ASSERT((filemode & (FWRITE | FCREAT | FTRUNC | FOFFMAX)) != 0);
540 	ASSERT(crwhy == CRCREAT);
541 	ASSERT(umask == 0);
542 
543 	pb = pathbuf_create(pnamep);
544 	if (pb == NULL) {
545 		return ENOMEM;
546 	}
547 	NDINIT(&nd, LOOKUP, NOFOLLOW, pb);
548 	error = vn_open(&nd, filemode, createmode);
549 	if (error == 0) {
550 		VOP_UNLOCK(nd.ni_vp);
551 		*vpp = nd.ni_vp;
552 	}
553 	pathbuf_destroy(pb);
554 	return (error);
555 }
556 #define	vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)	\
557 	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
558 
559 #define	vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, umask, rootvn, unk)	\
560 	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
561 
562 #define	RLIM64_INFINITY	0
563 static __inline int
564 zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
565     offset_t offset, enum uio_seg seg, int ioflag, uint64_t ulimit, cred_t *cr,
566     ssize_t *residp)
567 {
568 	int error;
569 	size_t resid;
570 
571 	ASSERT(rw == UIO_WRITE);
572 	ASSERT(ioflag == 0);
573 	ASSERT(ulimit == RLIM64_INFINITY);
574 
575 	ioflag = IO_APPEND | IO_UNIT;
576 
577 	error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr,
578 	    &resid, curlwp);
579 	if (residp != NULL)
580 		*residp = (ssize_t)resid;
581 	return (error);
582 }
583 #define	vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
584 	zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
585 
586 static __inline int
587 zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
588 {
589 	int error;
590 
591 	ASSERT(flag == FSYNC);
592 
593 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
594 	error = VOP_FSYNC(vp, cr, FSYNC_WAIT, 0, 0);
595 	VOP_UNLOCK(vp);
596 	return (error);
597 }
598 #define	VOP_FSYNC(vp, flag, cr, unk)	zfs_vop_fsync((vp), (flag), (cr))
599 
600 static __inline int
601 zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
602 {
603 
604 	ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
605 	ASSERT(count == 1);
606 	ASSERT(offset == 0);
607 
608 	return (vn_close(vp, flag, cr));
609 }
610 #define	VOP_CLOSE(vp, oflags, count, offset, cr, unk) \
611 	zfs_vop_close((vp), (oflags), (count), (offset), (cr))
612 
613 static __inline int
614 zfs_vop_getattr(vnode_t *vp, vattr_t *ap, int flag, cred_t *cr)
615 {
616 	int error;
617 
618 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
619 	error = VOP_GETATTR(vp, ap, cr);
620 	VOP_UNLOCK(vp);
621 	return (error);
622 }
623 #define	VOP_GETATTR(vp, ap, flag, cr, unk)	zfs_vop_getattr((vp), (ap), (flag), (cr))
624 
625 static __inline int
626 zfs_vop_seek(vnode_t *vp, off_t off, off_t *offp)
627 {
628 	int error;
629 
630 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
631 	error = VOP_SEEK(vp, off, *offp, kauth_cred_get());
632 	VOP_UNLOCK(vp);
633 	return (error);
634 }
635 #define	VOP_SEEK(vp, off, offp, unk)	zfs_vop_seek(vp, off, offp)
636 
637 #define	B_INVAL		BC_INVAL
638 
639 static __inline int
640 zfs_vop_putpage(vnode_t *vp, off_t off, size_t len, int flag)
641 {
642 	int nbflag;
643 
644 	nbflag = 0;
645 	if (len == 0) {
646 		nbflag |= PGO_ALLPAGES;
647 	}
648 	if ((flag & B_ASYNC) == 0) {
649 		nbflag |= PGO_SYNCIO;
650 	}
651 	if ((flag & B_INVAL) != 0) {
652 		nbflag |= PGO_FREE;
653 	} else {
654 		nbflag |= PGO_CLEANIT;
655 	}
656 
657 	mutex_enter(&vp->v_interlock);
658 	return VOP_PUTPAGES(vp, off, len, nbflag);
659 }
660 #define	VOP_PUTPAGE(vp, off, len, flag, cr, ct)	zfs_vop_putpage((vp), (off), (len), (flag))
661 
662 static __inline int
663 vn_rename(char *from, char *to, enum uio_seg seg)
664 {
665 
666 	ASSERT(seg == UIO_SYSSPACE);
667 
668 	return (do_sys_rename(from, to, seg, 0));
669 }
670 
671 enum rm	{ RMFILE };
672 static __inline int
673 vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
674 {
675 
676 	ASSERT(seg == UIO_SYSSPACE);
677 	ASSERT(dirflag == RMFILE);
678 
679 	return (do_sys_unlink(fnamep, seg));
680 }
681 
682 #define VN_RELE_ASYNC(vp, taskq) 	vrele_async((vp))
683 #define vn_exists(a) 	do { } while(0)
684 #define vn_reinit(a) 	vclean((a), 0)
685 
686 /*
687  * Flags for VOP_LOOKUP
688  *
689  * Defined in file.h, but also possible, FIGNORECASE
690  *
691  */
692 #define LOOKUP_XATTR 		0x02	/* lookup up extended attr dir */
693 
694 /*
695  * Flags for VOP_READDIR
696  */
697 #define V_RDDIR_ENTFLAGS 	0x01    /* request dirent flags */
698 #define	V_RDDIR_ACCFILTER 	0x02	/* filter out inaccessible dirents */
699 
700 /*
701  * Extensible vnode attribute (xva) routines:
702  * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
703  * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
704  */
705 void            xva_init(xvattr_t *);
706 xoptattr_t	*xva_getxoptattr(xvattr_t *);
707 
708 /*
709  * VOP_ACCESS flags
710  */
711 #define V_ACE_MASK  0x1 /* mask represents  NFSv4 ACE permissions */
712 #define V_APPEND    0x2 /* want to do append only check */
713 
714 #endif	/* _OPENSOLARIS_SYS_VNODE_H_ */
715