1/* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright 2017 RackTop Systems. 25 */ 26 27/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29 30/* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40#ifndef _SYS_VNODE_H 41#define _SYS_VNODE_H 42 43#include_next <sys/vnode.h> 44 45#define IS_DEVVP(vp) \ 46 ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO) 47 48#define V_XATTRDIR 0x0000 /* attribute unnamed directory */ 49 50#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ 51 52/* 53 * Structure of all optional attributes. 54 */ 55typedef struct xoptattr { 56 timestruc_t xoa_createtime; /* Create time of file */ 57 uint8_t xoa_archive; 58 uint8_t xoa_system; 59 uint8_t xoa_readonly; 60 uint8_t xoa_hidden; 61 uint8_t xoa_nounlink; 62 uint8_t xoa_immutable; 63 uint8_t xoa_appendonly; 64 uint8_t xoa_nodump; 65 uint8_t xoa_opaque; 66 uint8_t xoa_av_quarantined; 67 uint8_t xoa_av_modified; 68 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; 69 uint8_t xoa_reparse; 70 uint64_t xoa_generation; 71 uint8_t xoa_offline; 72 uint8_t xoa_sparse; 73} xoptattr_t; 74 75/* 76 * The xvattr structure is really a variable length structure that 77 * is made up of: 78 * - The classic vattr_t (xva_vattr) 79 * - a 32 bit quantity (xva_mapsize) that specifies the size of the 80 * attribute bitmaps in 32 bit words. 81 * - A pointer to the returned attribute bitmap (needed because the 82 * previous element, the requested attribute bitmap) is variable lenth. 83 * - The requested attribute bitmap, which is an array of 32 bit words. 84 * Callers use the XVA_SET_REQ() macro to set the bits corresponding to 85 * the attributes that are being requested. 86 * - The returned attribute bitmap, which is an array of 32 bit words. 87 * File systems that support optional attributes use the XVA_SET_RTN() 88 * macro to set the bits corresponding to the attributes that are being 89 * returned. 90 * - The xoptattr_t structure which contains the attribute values 91 * 92 * xva_mapsize determines how many words in the attribute bitmaps. 93 * Immediately following the attribute bitmaps is the xoptattr_t. 94 * xva_getxoptattr() is used to get the pointer to the xoptattr_t 95 * section. 96 */ 97 98#define XVA_MAPSIZE 3 /* Size of attr bitmaps */ 99#define XVA_MAGIC 0x78766174 /* Magic # for verification */ 100 101/* 102 * The xvattr structure is an extensible structure which permits optional 103 * attributes to be requested/returned. File systems may or may not support 104 * optional attributes. They do so at their own discretion but if they do 105 * support optional attributes, they must register the VFSFT_XVATTR feature 106 * so that the optional attributes can be set/retrived. 107 * 108 * The fields of the xvattr structure are: 109 * 110 * xva_vattr - The first element of an xvattr is a legacy vattr structure 111 * which includes the common attributes. If AT_XVATTR is set in the va_mask 112 * then the entire structure is treated as an xvattr. If AT_XVATTR is not 113 * set, then only the xva_vattr structure can be used. 114 * 115 * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification. 116 * 117 * xva_mapsize - Size of requested and returned attribute bitmaps. 118 * 119 * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the 120 * size of the array before it, xva_reqattrmap[], could change which means 121 * the location of xva_rtnattrmap[] could change. This will allow unbundled 122 * file systems to find the location of xva_rtnattrmap[] when the sizes change. 123 * 124 * xva_reqattrmap[] - Array of requested attributes. Attributes are 125 * represented by a specific bit in a specific element of the attribute 126 * map array. Callers set the bits corresponding to the attributes 127 * that the caller wants to get/set. 128 * 129 * xva_rtnattrmap[] - Array of attributes that the file system was able to 130 * process. Not all file systems support all optional attributes. This map 131 * informs the caller which attributes the underlying file system was able 132 * to set/get. (Same structure as the requested attributes array in terms 133 * of each attribute corresponding to specific bits and array elements.) 134 * 135 * xva_xoptattrs - Structure containing values of optional attributes. 136 * These values are only valid if the corresponding bits in xva_reqattrmap 137 * are set and the underlying file system supports those attributes. 138 */ 139typedef struct xvattr { 140 vattr_t xva_vattr; /* Embedded vattr structure */ 141 uint32_t xva_magic; /* Magic Number */ 142 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ 143 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ 144 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ 145 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ 146 xoptattr_t xva_xoptattrs; /* Optional attributes */ 147} xvattr_t; 148 149/* 150 * Attributes of interest to the caller of setattr or getattr. 151 */ 152#define AT_TYPE 0x00001 153#define AT_MODE 0x00002 154#define AT_UID 0x00004 155#define AT_GID 0x00008 156#define AT_FSID 0x00010 157#define AT_NODEID 0x00020 158#define AT_NLINK 0x00040 159#define AT_SIZE 0x00080 160#define AT_ATIME 0x00100 161#define AT_MTIME 0x00200 162#define AT_CTIME 0x00400 163#define AT_RDEV 0x00800 164#define AT_BLKSIZE 0x01000 165#define AT_NBLOCKS 0x02000 166/* 0x04000 */ /* unused */ 167#define AT_SEQ 0x08000 168/* 169 * If AT_XVATTR is set then there are additional bits to process in 170 * the xvattr_t's attribute bitmap. If this is not set then the bitmap 171 * MUST be ignored. Note that this bit must be set/cleared explicitly. 172 * That is, setting AT_ALL will NOT set AT_XVATTR. 173 */ 174#define AT_XVATTR 0x10000 175 176#define AT_ALL (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\ 177 AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\ 178 AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) 179 180#define AT_STAT (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\ 181 AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE) 182 183#define AT_TIMES (AT_ATIME|AT_MTIME|AT_CTIME) 184 185#define AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\ 186 AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) 187 188/* 189 * Attribute bits used in the extensible attribute's (xva's) attribute 190 * bitmaps. Note that the bitmaps are made up of a variable length number 191 * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n" 192 * is the element in the bitmap (starting at 1). This convention is for 193 * the convenience of the maintainer to keep track of which element each 194 * attribute belongs to. 195 * 196 * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS 197 * MUST USE THE XAT_* DEFINES. 198 */ 199#define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */ 200#define XAT0_CREATETIME 0x00000001 /* Create time of file */ 201#define XAT0_ARCHIVE 0x00000002 /* Archive */ 202#define XAT0_SYSTEM 0x00000004 /* System */ 203#define XAT0_READONLY 0x00000008 /* Readonly */ 204#define XAT0_HIDDEN 0x00000010 /* Hidden */ 205#define XAT0_NOUNLINK 0x00000020 /* Nounlink */ 206#define XAT0_IMMUTABLE 0x00000040 /* immutable */ 207#define XAT0_APPENDONLY 0x00000080 /* appendonly */ 208#define XAT0_NODUMP 0x00000100 /* nodump */ 209#define XAT0_OPAQUE 0x00000200 /* opaque */ 210#define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */ 211#define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */ 212#define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */ 213#define XAT0_REPARSE 0x00002000 /* FS reparse point */ 214#define XAT0_GEN 0x00004000 /* object generation number */ 215#define XAT0_OFFLINE 0x00008000 /* offline */ 216#define XAT0_SPARSE 0x00010000 /* sparse */ 217 218#define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \ 219 XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \ 220 XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \ 221 XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE) 222 223/* Support for XAT_* optional attributes */ 224#define XVA_MASK 0xffffffff /* Used to mask off 32 bits */ 225#define XVA_SHFT 32 /* Used to shift index */ 226 227/* 228 * Used to pry out the index and attribute bits from the XAT_* attributes 229 * defined below. Note that we're masking things down to 32 bits then 230 * casting to uint32_t. 231 */ 232#define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK)) 233#define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK)) 234 235/* 236 * The following defines present a "flat namespace" so that consumers don't 237 * need to keep track of which element belongs to which bitmap entry. 238 * 239 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER 240 */ 241#define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME) 242#define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE) 243#define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM) 244#define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY) 245#define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN) 246#define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK) 247#define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE) 248#define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY) 249#define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP) 250#define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE) 251#define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED) 252#define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED) 253#define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP) 254#define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE) 255#define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN) 256#define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE) 257#define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE) 258 259/* 260 * The returned attribute map array (xva_rtnattrmap[]) is located past the 261 * requested attribute map array (xva_reqattrmap[]). Its location changes 262 * when the array sizes change. We use a separate pointer in a known location 263 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is 264 * set in xva_init() 265 */ 266#define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp) 267 268/* 269 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap 270 * of requested attributes (xva_reqattrmap[]). 271 */ 272#define XVA_SET_REQ(xvap, attr) { \ 273 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ 274 ASSERT((xvap)->xva_magic == XVA_MAGIC); \ 275 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr); \ 276} 277/* 278 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap 279 * of requested attributes (xva_reqattrmap[]). 280 */ 281#define XVA_CLR_REQ(xvap, attr) { \ 282 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ 283 ASSERT((xvap)->xva_magic == XVA_MAGIC); \ 284 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr); \ 285} 286 287/* 288 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap 289 * of returned attributes (xva_rtnattrmap[]). 290 */ 291#define XVA_SET_RTN(xvap, attr) { \ 292 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ 293 ASSERT((xvap)->xva_magic == XVA_MAGIC); \ 294 (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr); \ 295} 296 297/* 298 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[]) 299 * to see of the corresponding attribute bit is set. If so, returns non-zero. 300 */ 301#define XVA_ISSET_REQ(xvap, attr) \ 302 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ 303 ((xvap)->xva_magic == XVA_MAGIC) && \ 304 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ 305 ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) 306 307/* 308 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[]) 309 * to see of the corresponding attribute bit is set. If so, returns non-zero. 310 */ 311#define XVA_ISSET_RTN(xvap, attr) \ 312 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ 313 ((xvap)->xva_magic == XVA_MAGIC) && \ 314 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ 315 ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) 316 317#define MODEMASK 07777 /* mode bits plus permission bits */ 318#define PERMMASK 00777 /* permission bits */ 319 320/* 321 * VOP_ACCESS flags 322 */ 323#define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */ 324 325/* 326 * Flags for vnode operations. 327 */ 328enum rm { RMFILE, RMDIRECTORY }; /* rm or rmdir (remove) */ 329enum create { CRCREAT, CRMKNOD, CRMKDIR }; /* reason for create */ 330 331/* 332 * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations 333 */ 334 335typedef struct vsecattr { 336 uint_t vsa_mask; /* See below */ 337 int vsa_aclcnt; /* ACL entry count */ 338 void *vsa_aclentp; /* pointer to ACL entries */ 339 int vsa_dfaclcnt; /* default ACL entry count */ 340 void *vsa_dfaclentp; /* pointer to default ACL entries */ 341 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ 342 uint_t vsa_aclflags; /* ACE ACL flags */ 343} vsecattr_t; 344 345/* vsa_mask values */ 346#define VSA_ACL 0x0001 347#define VSA_ACLCNT 0x0002 348#define VSA_DFACL 0x0004 349#define VSA_DFACLCNT 0x0008 350#define VSA_ACE 0x0010 351#define VSA_ACECNT 0x0020 352#define VSA_ACE_ALLTYPES 0x0040 353#define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */ 354 355/* 356 * Structure used by various vnode operations to determine 357 * the context (pid, host, identity) of a caller. 358 * 359 * The cc_caller_id is used to identify one or more callers who invoke 360 * operations, possibly on behalf of others. For example, the NFS 361 * server could have it's own cc_caller_id which can be detected by 362 * vnode/vfs operations or (FEM) monitors on those operations. New 363 * caller IDs are generated by fs_new_caller_id(). 364 */ 365typedef struct caller_context { 366 pid_t cc_pid; /* Process ID of the caller */ 367 int cc_sysid; /* System ID, used for remote calls */ 368 u_longlong_t cc_caller_id; /* Identifier for (set of) caller(s) */ 369 ulong_t cc_flags; 370} caller_context_t; 371 372struct taskq; 373 374/* 375 * Flags for VOP_LOOKUP 376 * 377 * Defined in file.h, but also possible, FIGNORECASE and FSEARCH 378 * 379 */ 380#define LOOKUP_DIR 0x01 /* want parent dir vp */ 381#define LOOKUP_XATTR 0x02 /* lookup up extended attr dir */ 382#define CREATE_XATTR_DIR 0x04 /* Create extended attr dir */ 383#define LOOKUP_HAVE_SYSATTR_DIR 0x08 /* Already created virtual GFS dir */ 384 385/* 386 * Flags for VOP_READDIR 387 */ 388#define V_RDDIR_ENTFLAGS 0x01 /* request dirent flags */ 389#define V_RDDIR_ACCFILTER 0x02 /* filter out inaccessible dirents */ 390 391/* 392 * Public vnode manipulation functions. 393 */ 394#ifdef _KERNEL 395 396void vn_rele_async(struct vnode *vp, struct taskq *taskq); 397 398/* 399 * Extensible vnode attribute (xva) routines: 400 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR) 401 * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t 402 */ 403void xva_init(xvattr_t *); 404xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */ 405 406#define VN_RELE_ASYNC(vp, taskq) { \ 407 vn_rele_async(vp, taskq); \ 408} 409 410#endif /* _KERNEL */ 411 412/* 413 * Flags to VOP_SETATTR/VOP_GETATTR. 414 */ 415#define ATTR_UTIME 0x01 /* non-default utime(2) request */ 416#define ATTR_EXEC 0x02 /* invocation from exec(2) */ 417#define ATTR_COMM 0x04 /* yield common vp attributes */ 418#define ATTR_HINT 0x08 /* information returned will be `hint' */ 419#define ATTR_REAL 0x10 /* yield attributes of the real vp */ 420#define ATTR_NOACLCHECK 0x20 /* Don't check ACL when checking permissions */ 421#define ATTR_TRIGGER 0x40 /* Mount first if vnode is a trigger mount */ 422 423#ifdef __cplusplus 424} 425#endif 426 427#endif /* _SYS_VNODE_H */ 428