xref: /freebsd/sys/contrib/openzfs/include/os/freebsd/spl/sys/vnode_impl.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Copyright 2017 RackTop Systems.
26  */
27 
28 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 /*
32  * University Copyright- Copyright (c) 1982, 1986, 1988
33  * The Regents of the University of California
34  * All Rights Reserved
35  *
36  * University Acknowledgment- Portions of this document are derived from
37  * software developed by the University of California, Berkeley, and its
38  * contributors.
39  */
40 
41 #ifndef _SYS_VNODE_IMPL_H
42 #define	_SYS_VNODE_IMPL_H
43 
44 
45 #define	IS_DEVVP(vp)	\
46 	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
47 
48 #define	AV_SCANSTAMP_SZ	32		/* length of anti-virus scanstamp */
49 
50 /*
51  * The xvattr structure is really a variable length structure that
52  * is made up of:
53  * - The classic vattr_t (xva_vattr)
54  * - a 32 bit quantity (xva_mapsize) that specifies the size of the
55  *   attribute bitmaps in 32 bit words.
56  * - A pointer to the returned attribute bitmap (needed because the
57  *   previous element, the requested attribute bitmap) is variable length.
58  * - The requested attribute bitmap, which is an array of 32 bit words.
59  *   Callers use the XVA_SET_REQ() macro to set the bits corresponding to
60  *   the attributes that are being requested.
61  * - The returned attribute bitmap, which is an array of 32 bit words.
62  *   File systems that support optional attributes use the XVA_SET_RTN()
63  *   macro to set the bits corresponding to the attributes that are being
64  *   returned.
65  * - The xoptattr_t structure which contains the attribute values
66  *
67  * xva_mapsize determines how many words in the attribute bitmaps.
68  * Immediately following the attribute bitmaps is the xoptattr_t.
69  * xva_getxoptattr() is used to get the pointer to the xoptattr_t
70  * section.
71  */
72 
73 #define	XVA_MAPSIZE	3		/* Size of attr bitmaps */
74 #define	XVA_MAGIC	0x78766174	/* Magic # for verification */
75 
76 /*
77  * The xvattr structure is an extensible structure which permits optional
78  * attributes to be requested/returned.  File systems may or may not support
79  * optional attributes.  They do so at their own discretion but if they do
80  * support optional attributes, they must register the VFSFT_XVATTR feature
81  * so that the optional attributes can be set/retrieved.
82  *
83  * The fields of the xvattr structure are:
84  *
85  * xva_vattr - The first element of an xvattr is a legacy vattr structure
86  * which includes the common attributes.  If AT_XVATTR is set in the va_mask
87  * then the entire structure is treated as an xvattr.  If AT_XVATTR is not
88  * set, then only the xva_vattr structure can be used.
89  *
90  * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
91  *
92  * xva_mapsize - Size of requested and returned attribute bitmaps.
93  *
94  * xva_rtnattrmapp - Pointer to xva_rtnattrmap[].  We need this since the
95  * size of the array before it, xva_reqattrmap[], could change which means
96  * the location of xva_rtnattrmap[] could change.  This will allow unbundled
97  * file systems to find the location of xva_rtnattrmap[] when the sizes change.
98  *
99  * xva_reqattrmap[] - Array of requested attributes.  Attributes are
100  * represented by a specific bit in a specific element of the attribute
101  * map array.  Callers set the bits corresponding to the attributes
102  * that the caller wants to get/set.
103  *
104  * xva_rtnattrmap[] - Array of attributes that the file system was able to
105  * process.  Not all file systems support all optional attributes.  This map
106  * informs the caller which attributes the underlying file system was able
107  * to set/get.  (Same structure as the requested attributes array in terms
108  * of each attribute  corresponding to specific bits and array elements.)
109  *
110  * xva_xoptattrs - Structure containing values of optional attributes.
111  * These values are only valid if the corresponding bits in xva_reqattrmap
112  * are set and the underlying file system supports those attributes.
113  */
114 
115 
116 
117 /*
118  * Attribute bits used in the extensible attribute's (xva's) attribute
119  * bitmaps.  Note that the bitmaps are made up of a variable length number
120  * of 32-bit words.  The convention is to use XAT{n}_{attrname} where "n"
121  * is the element in the bitmap (starting at 1).  This convention is for
122  * the convenience of the maintainer to keep track of which element each
123  * attribute belongs to.
124  *
125  * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY.  CONSUMERS
126  * MUST USE THE XAT_* DEFINES.
127  */
128 #define	XAT0_INDEX	0LL		/* Index into bitmap for XAT0 attrs */
129 #define	XAT0_CREATETIME	0x00000001	/* Create time of file */
130 #define	XAT0_ARCHIVE	0x00000002	/* Archive */
131 #define	XAT0_SYSTEM	0x00000004	/* System */
132 #define	XAT0_READONLY	0x00000008	/* Readonly */
133 #define	XAT0_HIDDEN	0x00000010	/* Hidden */
134 #define	XAT0_NOUNLINK	0x00000020	/* Nounlink */
135 #define	XAT0_IMMUTABLE	0x00000040	/* immutable */
136 #define	XAT0_APPENDONLY	0x00000080	/* appendonly */
137 #define	XAT0_NODUMP	0x00000100	/* nodump */
138 #define	XAT0_OPAQUE	0x00000200	/* opaque */
139 #define	XAT0_AV_QUARANTINED	0x00000400	/* anti-virus quarantine */
140 #define	XAT0_AV_MODIFIED	0x00000800	/* anti-virus modified */
141 #define	XAT0_AV_SCANSTAMP	0x00001000	/* anti-virus scanstamp */
142 #define	XAT0_REPARSE	0x00002000	/* FS reparse point */
143 #define	XAT0_GEN	0x00004000	/* object generation number */
144 #define	XAT0_OFFLINE	0x00008000	/* offline */
145 #define	XAT0_SPARSE	0x00010000	/* sparse */
146 
147 /* Support for XAT_* optional attributes */
148 #define	XVA_MASK		0xffffffff	/* Used to mask off 32 bits */
149 #define	XVA_SHFT		32		/* Used to shift index */
150 
151 /*
152  * Used to pry out the index and attribute bits from the XAT_* attributes
153  * defined below.  Note that we're masking things down to 32 bits then
154  * casting to uint32_t.
155  */
156 #define	XVA_INDEX(attr)		((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
157 #define	XVA_ATTRBIT(attr)	((uint32_t)((attr) & XVA_MASK))
158 
159 /*
160  * The following defines present a "flat namespace" so that consumers don't
161  * need to keep track of which element belongs to which bitmap entry.
162  *
163  * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
164  */
165 #define	XAT_CREATETIME		((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
166 #define	XAT_ARCHIVE		((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
167 #define	XAT_SYSTEM		((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
168 #define	XAT_READONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
169 #define	XAT_HIDDEN		((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
170 #define	XAT_NOUNLINK		((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
171 #define	XAT_IMMUTABLE		((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
172 #define	XAT_APPENDONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
173 #define	XAT_NODUMP		((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
174 #define	XAT_OPAQUE		((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
175 #define	XAT_AV_QUARANTINED	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
176 #define	XAT_AV_MODIFIED		((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
177 #define	XAT_AV_SCANSTAMP	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
178 #define	XAT_REPARSE		((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
179 #define	XAT_GEN			((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
180 #define	XAT_OFFLINE		((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
181 #define	XAT_SPARSE		((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
182 
183 /*
184  * The returned attribute map array (xva_rtnattrmap[]) is located past the
185  * requested attribute map array (xva_reqattrmap[]).  Its location changes
186  * when the array sizes change.  We use a separate pointer in a known location
187  * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[].  This is
188  * set in xva_init()
189  */
190 #define	XVA_RTNATTRMAP(xvap)	((xvap)->xva_rtnattrmapp)
191 
192 #define	MODEMASK	07777		/* mode bits plus permission bits */
193 #define	PERMMASK	00777		/* permission bits */
194 
195 /*
196  * Flags for vnode operations.
197  */
198 enum rm		{ RMFILE, RMDIRECTORY };	/* rm or rmdir (remove) */
199 enum create	{ CRCREAT, CRMKNOD, CRMKDIR };	/* reason for create */
200 
201 /*
202  * Structure used by various vnode operations to determine
203  * the context (pid, host, identity) of a caller.
204  *
205  * The cc_caller_id is used to identify one or more callers who invoke
206  * operations, possibly on behalf of others.  For example, the NFS
207  * server could have its own cc_caller_id which can be detected by
208  * vnode/vfs operations or (FEM) monitors on those operations.  New
209  * caller IDs are generated by fs_new_caller_id().
210  */
211 typedef struct caller_context {
212 	pid_t		cc_pid;		/* Process ID of the caller */
213 	int		cc_sysid;	/* System ID, used for remote calls */
214 	u_longlong_t	cc_caller_id;	/* Identifier for (set of) caller(s) */
215 	ulong_t		cc_flags;
216 } caller_context_t;
217 
218 struct taskq;
219 
220 /*
221  * Flags for VOP_LOOKUP
222  *
223  * Defined in file.h, but also possible, FIGNORECASE and FSEARCH
224  *
225  */
226 #define	LOOKUP_DIR		0x01	/* want parent dir vp */
227 #define	LOOKUP_XATTR		0x02	/* lookup up extended attr dir */
228 #define	CREATE_XATTR_DIR	0x04	/* Create extended attr dir */
229 #define	LOOKUP_HAVE_SYSATTR_DIR	0x08	/* Already created virtual GFS dir */
230 
231 /*
232  * Public vnode manipulation functions.
233  */
234 
235 void	vn_rele_async(struct vnode *vp, struct taskq *taskq);
236 
237 #define	VN_RELE_ASYNC(vp, taskq)	{ \
238 	vn_rele_async(vp, taskq); \
239 }
240 
241 /*
242  * Flags to VOP_SETATTR/VOP_GETATTR.
243  */
244 #define	ATTR_UTIME	0x01	/* non-default utime(2) request */
245 #define	ATTR_EXEC	0x02	/* invocation from exec(2) */
246 #define	ATTR_COMM	0x04	/* yield common vp attributes */
247 #define	ATTR_HINT	0x08	/* information returned will be `hint' */
248 #define	ATTR_REAL	0x10	/* yield attributes of the real vp */
249 #define	ATTR_NOACLCHECK	0x20	/* Don't check ACL when checking permissions */
250 #define	ATTR_TRIGGER	0x40	/* Mount first if vnode is a trigger mount */
251 
252 #ifdef	__cplusplus
253 }
254 #endif
255 
256 #endif	/* _SYS_VNODE_H */
257