1 
2 /*	$NetBSD: vnode.h,v 1.13 2015/04/09 05:32:53 riastradh 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)	do { \
298 	    if ((v)->v_usecount == 0) \
299 		    printf("%s, %d: %p unused\n", __FILE__, __LINE__, v); \
300 	    else \
301 		    vrele(v); \
302     } while (/*CONSTCOND*/0)
303 #define	VN_URELE(v)	vput(v)
304 #define	VN_SET_VFS_TYPE_DEV(vp, vfs, type, flag)	(0)
305 
306 #define VI_LOCK(vp)     mutex_enter((vp)->v_interlock)
307 #define VI_UNLOCK(vp)   mutex_exit((vp)->v_interlock)
308 
309 #define	VOP_REALVP(vp, vpp, ct)	(*(vpp) = (vp), 0)
310 
311 #define vnevent_remove(vp, dvp, name, ct) do { } while (0)
312 #define vnevent_rmdir(vp, dvp, name, ct) do { } while (0)
313 #define vnevent_rename_src(vp, dvp, name, ct) do { } while (0)
314 #define	vnevent_rename_dest(vp, dvp, name, ct)	do { } while (0)
315 #define vnevent_rename_dest_dir(vp, ct)     do { } while (0)
316 #define vnevent_create(vp, ct)  do { } while (0)
317 #define vnevent_link(vp, ct)            do { } while (0)
318 
319 #define	IS_DEVVP(vp)	\
320 	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
321 
322 #define	MODEMASK	ALLPERMS
323 
324 #define	specvp(vp, rdev, type, cr)	(VN_HOLD(vp), (vp))
325 #define	MANDMODE(mode)	(0)
326 #define	chklock(vp, op, offset, size, mode, ct)	(0)
327 #define	cleanlocks(vp, pid, foo)	do { } while (0)
328 #define	cleanshares(vp, pid)		do { } while (0)
329 
330 /*
331  * We will use va_spare is place of Solaris' va_mask.
332  * This field is initialized in zfs_setattr().
333  */
334 #define	va_mask		va_spare
335 /* TODO: va_fileid is shorter than va_nodeid !!! */
336 #define	va_nodeid	va_fileid
337 /* TODO: This field needs conversion! */
338 #define	va_nblocks	va_bytes
339 #define	va_blksize	va_blocksize
340 #define	va_seq		va_gen
341 
342 #define	EXCL		0
343 
344 #define	AT_TYPE		0x0001
345 #define	AT_MODE		0x0002
346 #define	AT_UID		0x0004
347 #define	AT_GID		0x0008
348 #define	AT_FSID		0x0010
349 #define	AT_NODEID	0x0020
350 #define	AT_NLINK	0x0040
351 #define	AT_SIZE		0x0080
352 #define	AT_ATIME	0x0100
353 #define	AT_MTIME	0x0200
354 #define	AT_CTIME	0x0400
355 #define	AT_RDEV		0x0800
356 #define	AT_BLKSIZE	0x1000
357 #define	AT_NBLOCKS	0x2000
358 #define	AT_SEQ		0x4000
359 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
360 			 AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
361 
362 #define	ACCESSED		(AT_ATIME)
363 #define	STATE_CHANGED		(AT_CTIME)
364 #define	CONTENT_MODIFIED	(AT_MTIME | AT_CTIME)
365 
366 /*
367  * If AT_XVATTR is set then there are additional bits to process in
368  * the xvattr_t's attribute bitmap.  If this is not set then the bitmap
369  * MUST be ignored.  Note that this bit must be set/cleared explicitly.
370  * That is, setting AT_ALL will NOT set AT_XVATTR.
371  */
372 #define	AT_XVATTR	0x10000
373 
374 #define	AT_ALL		(AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
375 			AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
376 			AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
377 
378 #define	AT_STAT		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
379 			AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE)
380 
381 #define	AT_TIMES	(AT_ATIME|AT_MTIME|AT_CTIME)
382 
383 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
384 			AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
385 
386 /*
387  * Attribute bits used in the extensible attribute's (xva's) attribute
388  * bitmaps.  Note that the bitmaps are made up of a variable length number
389  * of 32-bit words.  The convention is to use XAT{n}_{attrname} where "n"
390  * is the element in the bitmap (starting at 1).  This convention is for
391  * the convenience of the maintainer to keep track of which element each
392  * attribute belongs to.
393  *
394  * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY.  CONSUMERS
395  * MUST USE THE XAT_* DEFINES.
396  */
397 #define	XAT0_INDEX	0LL		/* Index into bitmap for XAT0 attrs */
398 #define	XAT0_CREATETIME	0x00000001	/* Create time of file */
399 #define	XAT0_ARCHIVE	0x00000002	/* Archive */
400 #define	XAT0_SYSTEM	0x00000004	/* System */
401 #define	XAT0_READONLY	0x00000008	/* Readonly */
402 #define	XAT0_HIDDEN	0x00000010	/* Hidden */
403 #define	XAT0_NOUNLINK	0x00000020	/* Nounlink */
404 #define	XAT0_IMMUTABLE	0x00000040	/* immutable */
405 #define	XAT0_APPENDONLY	0x00000080	/* appendonly */
406 #define	XAT0_NODUMP	0x00000100	/* nodump */
407 #define	XAT0_OPAQUE	0x00000200	/* opaque */
408 #define	XAT0_AV_QUARANTINED	0x00000400	/* anti-virus quarantine */
409 #define	XAT0_AV_MODIFIED	0x00000800	/* anti-virus modified */
410 #define	XAT0_AV_SCANSTAMP	0x00001000	/* anti-virus scanstamp */
411 #define XAT0_REPARSE 	0x00002000 	/* FS reparse point */
412 
413 #define	XAT0_ALL_ATTRS	(XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
414     XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
415     XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| \
416     XAT0_AV_MODIFIED|XAT0_AV_SCANSTAMP)
417 
418 /* Support for XAT_* optional attributes */
419 #define	XVA_MASK		0xffffffff	/* Used to mask off 32 bits */
420 #define	XVA_SHFT		32		/* Used to shift index */
421 
422 /*
423  * Used to pry out the index and attribute bits from the XAT_* attributes
424  * defined below.  Note that we're masking things down to 32 bits then
425  * casting to uint32_t.
426  */
427 #define	XVA_INDEX(attr)		((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
428 #define	XVA_ATTRBIT(attr)	((uint32_t)((attr) & XVA_MASK))
429 
430 /*
431  * The following defines present a "flat namespace" so that consumers don't
432  * need to keep track of which element belongs to which bitmap entry.
433  *
434  * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
435  */
436 #define	XAT_CREATETIME		((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
437 #define	XAT_ARCHIVE		((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
438 #define	XAT_SYSTEM		((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
439 #define	XAT_READONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
440 #define	XAT_HIDDEN		((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
441 #define	XAT_NOUNLINK		((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
442 #define	XAT_IMMUTABLE		((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
443 #define	XAT_APPENDONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
444 #define	XAT_NODUMP		((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
445 #define	XAT_OPAQUE		((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
446 #define	XAT_AV_QUARANTINED	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
447 #define	XAT_AV_MODIFIED		((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
448 #define	XAT_AV_SCANSTAMP	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
449 #define XAT_REPARSE 		((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
450 
451 /*
452  * The returned attribute map array (xva_rtnattrmap[]) is located past the
453  * requested attribute map array (xva_reqattrmap[]).  Its location changes
454  * when the array sizes change.  We use a separate pointer in a known location
455  * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[].  This is
456  * set in xva_init()
457  */
458 #define	XVA_RTNATTRMAP(xvap)	((xvap)->xva_rtnattrmapp)
459 
460 /*
461  * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
462  * of requested attributes (xva_reqattrmap[]).
463  */
464 #define	XVA_SET_REQ(xvap, attr)					\
465 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
466 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
467 	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
468 
469 /*
470  * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
471  * of requested attributes (xva_reqattrmap[]).
472  */
473 #define XVA_CLR_REQ(xvap, attr)                                 \
474 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);          \
475 	ASSERT((xvap)->xva_magic == XVA_MAGIC);                 \
476 	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
477 /*
478  * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
479  * of returned attributes (xva_rtnattrmap[]).
480  */
481 #define	XVA_SET_RTN(xvap, attr)					\
482 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
483 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
484 	(XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
485 
486 /*
487  * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
488  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
489  */
490 #define	XVA_ISSET_REQ(xvap, attr)					\
491 	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
492 		((xvap)->xva_magic == XVA_MAGIC) &&			\
493 		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
494 	((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) :	0)
495 
496 /*
497  * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
498  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
499  */
500 #define	XVA_ISSET_RTN(xvap, attr)					\
501 	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
502 		((xvap)->xva_magic == XVA_MAGIC) &&			\
503 		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
504 	((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
505 
506 static __inline void
vattr_init_mask(vattr_t * vap)507 vattr_init_mask(vattr_t *vap)
508 {
509 
510 	vap->va_mask = 0;
511 
512 	if (vap->va_type != VNON)
513 		vap->va_mask |= AT_TYPE;
514 	if (vap->va_uid != (uid_t)VNOVAL)
515 		vap->va_mask |= AT_UID;
516 	if (vap->va_gid != (gid_t)VNOVAL)
517 		vap->va_mask |= AT_GID;
518 	if (vap->va_size != (u_quad_t)VNOVAL)
519 		vap->va_mask |= AT_SIZE;
520 	if (vap->va_atime.tv_sec != VNOVAL)
521 		vap->va_mask |= AT_ATIME;
522 	if (vap->va_mtime.tv_sec != VNOVAL)
523 		vap->va_mask |= AT_MTIME;
524 	if (vap->va_mode != (mode_t)VNOVAL)
525 		vap->va_mask |= AT_MODE;
526 }
527 
528 #define	FCREAT	O_CREAT
529 #define	FTRUNC	O_TRUNC
530 #define	FSYNC	FFSYNC
531 #define	FOFFMAX	0x00
532 
533 enum create	{ CRCREAT };
534 
535 static __inline int
zfs_vn_open(const char * pnamep,enum uio_seg seg,int filemode,int createmode,vnode_t ** vpp,enum create crwhy,mode_t umask)536 zfs_vn_open(const char *pnamep, enum uio_seg seg, int filemode, int createmode,
537     vnode_t **vpp, enum create crwhy, mode_t umask)
538 {
539 	struct pathbuf *pb;
540 	struct nameidata nd;
541 	int error;
542 
543 	ASSERT(seg == UIO_SYSSPACE);
544 	ASSERT((filemode & (FWRITE | FCREAT | FTRUNC | FOFFMAX)) != 0);
545 	ASSERT(crwhy == CRCREAT);
546 	ASSERT(umask == 0);
547 
548 	pb = pathbuf_create(pnamep);
549 	if (pb == NULL) {
550 		return ENOMEM;
551 	}
552 	NDINIT(&nd, LOOKUP, NOFOLLOW, pb);
553 	error = vn_open(&nd, filemode, createmode);
554 	if (error == 0) {
555 		VOP_UNLOCK(nd.ni_vp);
556 		*vpp = nd.ni_vp;
557 	}
558 	pathbuf_destroy(pb);
559 	return (error);
560 }
561 #define	vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)	\
562 	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
563 
564 #define	vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, umask, rootvn, unk)	\
565 	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
566 
567 #define	RLIM64_INFINITY	0
568 static __inline int
zfs_vn_rdwr(enum uio_rw rw,vnode_t * vp,caddr_t base,ssize_t len,offset_t offset,enum uio_seg seg,int ioflag,uint64_t ulimit,cred_t * cr,ssize_t * residp)569 zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
570     offset_t offset, enum uio_seg seg, int ioflag, uint64_t ulimit, cred_t *cr,
571     ssize_t *residp)
572 {
573 	int error;
574 	size_t resid;
575 
576 	ASSERT(rw == UIO_WRITE);
577 	ASSERT(ioflag == 0);
578 	ASSERT(ulimit == RLIM64_INFINITY);
579 
580 	ioflag = IO_UNIT;
581 
582 	error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr,
583 	    &resid, curlwp);
584 	if (residp != NULL)
585 		*residp = (ssize_t)resid;
586 	return (error);
587 }
588 #define	vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
589 	zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
590 
591 static __inline int
zfs_vop_fsync(vnode_t * vp,int flag,cred_t * cr)592 zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
593 {
594 	int error;
595 
596 	ASSERT(flag == FSYNC);
597 
598 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
599 	error = VOP_FSYNC(vp, cr, FSYNC_WAIT, 0, 0);
600 	VOP_UNLOCK(vp);
601 	return (error);
602 }
603 #define	VOP_FSYNC(vp, flag, cr, unk)	zfs_vop_fsync((vp), (flag), (cr))
604 
605 static __inline int
zfs_vop_close(vnode_t * vp,int flag,int count,offset_t offset,cred_t * cr)606 zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
607 {
608 
609 	ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
610 	ASSERT(count == 1);
611 	ASSERT(offset == 0);
612 
613 	return (vn_close(vp, flag, cr));
614 }
615 #define	VOP_CLOSE(vp, oflags, count, offset, cr, unk) \
616 	zfs_vop_close((vp), (oflags), (count), (offset), (cr))
617 
618 static __inline int
zfs_vop_getattr(vnode_t * vp,vattr_t * ap,int flag,cred_t * cr)619 zfs_vop_getattr(vnode_t *vp, vattr_t *ap, int flag, cred_t *cr)
620 {
621 	int error;
622 
623 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
624 	error = VOP_GETATTR(vp, ap, cr);
625 	VOP_UNLOCK(vp);
626 	return (error);
627 }
628 #define	VOP_GETATTR(vp, ap, flag, cr, unk)	zfs_vop_getattr((vp), (ap), (flag), (cr))
629 
630 static __inline int
zfs_vop_seek(vnode_t * vp,off_t off,off_t * offp)631 zfs_vop_seek(vnode_t *vp, off_t off, off_t *offp)
632 {
633 	int error;
634 
635 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
636 	error = VOP_SEEK(vp, off, *offp, kauth_cred_get());
637 	VOP_UNLOCK(vp);
638 	return (error);
639 }
640 #define	VOP_SEEK(vp, off, offp, unk)	zfs_vop_seek(vp, off, offp)
641 
642 #define	B_INVAL		BC_INVAL
643 
644 static __inline int
zfs_vop_putpage(vnode_t * vp,off_t off,size_t len,int flag)645 zfs_vop_putpage(vnode_t *vp, off_t off, size_t len, int flag)
646 {
647 	int nbflag;
648 
649 	nbflag = 0;
650 	if (len == 0) {
651 		nbflag |= PGO_ALLPAGES;
652 	}
653 	if ((flag & B_ASYNC) == 0) {
654 		nbflag |= PGO_SYNCIO;
655 	}
656 	if ((flag & B_INVAL) != 0) {
657 		nbflag |= PGO_FREE;
658 	} else {
659 		nbflag |= PGO_CLEANIT;
660 	}
661 
662 	mutex_enter(vp->v_interlock);
663 	return VOP_PUTPAGES(vp, off, len, nbflag);
664 }
665 #define	VOP_PUTPAGE(vp, off, len, flag, cr, ct)	zfs_vop_putpage((vp), (off), (len), (flag))
666 
667 static __inline int
vn_rename(char * from,char * to,enum uio_seg seg)668 vn_rename(char *from, char *to, enum uio_seg seg)
669 {
670 
671 	ASSERT(seg == UIO_SYSSPACE);
672 
673 	return (do_sys_rename(from, to, seg, 0));
674 }
675 
676 enum rm	{ RMFILE };
677 static __inline int
vn_remove(char * fnamep,enum uio_seg seg,enum rm dirflag)678 vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
679 {
680 
681 	ASSERT(seg == UIO_SYSSPACE);
682 	ASSERT(dirflag == RMFILE);
683 
684 	return (do_sys_unlink(fnamep, seg));
685 }
686 
687 #define VN_RELE_ASYNC(vp, taskq) 	vrele_async((vp))
688 #define vn_exists(a) 	do { } while(0)
689 
690 /*
691  * Flags for VOP_LOOKUP
692  *
693  * Defined in file.h, but also possible, FIGNORECASE
694  *
695  */
696 #define LOOKUP_XATTR 		0x02	/* lookup up extended attr dir */
697 
698 /*
699  * Flags for VOP_READDIR
700  */
701 #define V_RDDIR_ENTFLAGS 	0x01    /* request dirent flags */
702 #define	V_RDDIR_ACCFILTER 	0x02	/* filter out inaccessible dirents */
703 
704 /*
705  * Extensible vnode attribute (xva) routines:
706  * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
707  * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
708  */
709 void            xva_init(xvattr_t *);
710 xoptattr_t	*xva_getxoptattr(xvattr_t *);
711 
712 /*
713  * VOP_ACCESS flags
714  */
715 #define V_ACE_MASK  0x1 /* mask represents  NFSv4 ACE permissions */
716 #define V_APPEND    0x2 /* want to do append only check */
717 
718 #endif	/* _OPENSOLARIS_SYS_VNODE_H_ */
719