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 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 /* 30 * University Copyright- Copyright (c) 1982, 1986, 1988 31 * The Regents of the University of California 32 * All Rights Reserved 33 * 34 * University Acknowledgment- Portions of this document are derived from 35 * software developed by the University of California, Berkeley, and its 36 * contributors. 37 */ 38 39 #ifndef _SYS_VNODE_H 40 #define _SYS_VNODE_H 41 42 #include <sys/types.h> 43 #include <sys/t_lock.h> 44 #include <sys/rwstlock.h> 45 #include <sys/time_impl.h> 46 #include <sys/cred.h> 47 #include <sys/uio.h> 48 #include <sys/resource.h> 49 #include <vm/seg_enum.h> 50 #include <sys/kstat.h> 51 #include <sys/kmem.h> 52 #include <sys/list.h> 53 #ifdef _KERNEL 54 #include <sys/buf.h> 55 #endif /* _KERNEL */ 56 57 #ifdef __cplusplus 58 extern "C" { 59 #endif 60 61 /* 62 * Statistics for all vnode operations. 63 * All operations record number of ops (since boot/mount/zero'ed). 64 * Certain I/O operations (read, write, readdir) also record number 65 * of bytes transferred. 66 * This appears in two places in the system: one is embedded in each 67 * vfs_t. There is also an array of vopstats_t structures allocated 68 * on a per-fstype basis. 69 */ 70 71 #define VOPSTATS_STR "vopstats_" /* Initial string for vopstat kstats */ 72 73 typedef struct vopstats { 74 kstat_named_t nopen; /* VOP_OPEN */ 75 kstat_named_t nclose; /* VOP_CLOSE */ 76 kstat_named_t nread; /* VOP_READ */ 77 kstat_named_t read_bytes; 78 kstat_named_t nwrite; /* VOP_WRITE */ 79 kstat_named_t write_bytes; 80 kstat_named_t nioctl; /* VOP_IOCTL */ 81 kstat_named_t nsetfl; /* VOP_SETFL */ 82 kstat_named_t ngetattr; /* VOP_GETATTR */ 83 kstat_named_t nsetattr; /* VOP_SETATTR */ 84 kstat_named_t naccess; /* VOP_ACCESS */ 85 kstat_named_t nlookup; /* VOP_LOOKUP */ 86 kstat_named_t ncreate; /* VOP_CREATE */ 87 kstat_named_t nremove; /* VOP_REMOVE */ 88 kstat_named_t nlink; /* VOP_LINK */ 89 kstat_named_t nrename; /* VOP_RENAME */ 90 kstat_named_t nmkdir; /* VOP_MKDIR */ 91 kstat_named_t nrmdir; /* VOP_RMDIR */ 92 kstat_named_t nreaddir; /* VOP_READDIR */ 93 kstat_named_t readdir_bytes; 94 kstat_named_t nsymlink; /* VOP_SYMLINK */ 95 kstat_named_t nreadlink; /* VOP_READLINK */ 96 kstat_named_t nfsync; /* VOP_FSYNC */ 97 kstat_named_t ninactive; /* VOP_INACTIVE */ 98 kstat_named_t nfid; /* VOP_FID */ 99 kstat_named_t nrwlock; /* VOP_RWLOCK */ 100 kstat_named_t nrwunlock; /* VOP_RWUNLOCK */ 101 kstat_named_t nseek; /* VOP_SEEK */ 102 kstat_named_t ncmp; /* VOP_CMP */ 103 kstat_named_t nfrlock; /* VOP_FRLOCK */ 104 kstat_named_t nspace; /* VOP_SPACE */ 105 kstat_named_t nrealvp; /* VOP_REALVP */ 106 kstat_named_t ngetpage; /* VOP_GETPAGE */ 107 kstat_named_t nputpage; /* VOP_PUTPAGE */ 108 kstat_named_t nmap; /* VOP_MAP */ 109 kstat_named_t naddmap; /* VOP_ADDMAP */ 110 kstat_named_t ndelmap; /* VOP_DELMAP */ 111 kstat_named_t npoll; /* VOP_POLL */ 112 kstat_named_t ndump; /* VOP_DUMP */ 113 kstat_named_t npathconf; /* VOP_PATHCONF */ 114 kstat_named_t npageio; /* VOP_PAGEIO */ 115 kstat_named_t ndumpctl; /* VOP_DUMPCTL */ 116 kstat_named_t ndispose; /* VOP_DISPOSE */ 117 kstat_named_t nsetsecattr; /* VOP_SETSECATTR */ 118 kstat_named_t ngetsecattr; /* VOP_GETSECATTR */ 119 kstat_named_t nshrlock; /* VOP_SHRLOCK */ 120 kstat_named_t nvnevent; /* VOP_VNEVENT */ 121 } vopstats_t; 122 123 /* 124 * The vnode is the focus of all file activity in UNIX. 125 * A vnode is allocated for each active file, each current 126 * directory, each mounted-on file, and the root. 127 * 128 * Each vnode is usually associated with a file-system-specific node (for 129 * UFS, this is the in-memory inode). Generally, a vnode and an fs-node 130 * should be created and destroyed together as a pair. 131 * 132 * If a vnode is reused for a new file, it should be reinitialized by calling 133 * either vn_reinit() or vn_recycle(). 134 * 135 * vn_reinit() resets the entire vnode as if it was returned by vn_alloc(). 136 * The caller is responsible for setting up the entire vnode after calling 137 * vn_reinit(). This is important when using kmem caching where the vnode is 138 * allocated by a constructor, for instance. 139 * 140 * vn_recycle() is used when the file system keeps some state around in both 141 * the vnode and the associated FS-node. In UFS, for example, the inode of 142 * a deleted file can be reused immediately. The v_data, v_vfsp, v_op, etc. 143 * remains the same but certain fields related to the previous instance need 144 * to be reset. In particular: 145 * v_femhead 146 * v_path 147 * v_rdcnt, v_wrcnt 148 * v_mmap_read, v_mmap_write 149 */ 150 151 /* 152 * vnode types. VNON means no type. These values are unrelated to 153 * values in on-disk inodes. 154 */ 155 typedef enum vtype { 156 VNON = 0, 157 VREG = 1, 158 VDIR = 2, 159 VBLK = 3, 160 VCHR = 4, 161 VLNK = 5, 162 VFIFO = 6, 163 VDOOR = 7, 164 VPROC = 8, 165 VSOCK = 9, 166 VPORT = 10, 167 VBAD = 11 168 } vtype_t; 169 170 /* 171 * VSD - Vnode Specific Data 172 * Used to associate additional private data with a vnode. 173 */ 174 struct vsd_node { 175 list_node_t vs_nodes; /* list of all VSD nodes */ 176 uint_t vs_nkeys; /* entries in value array */ 177 void **vs_value; /* array of value/key */ 178 }; 179 180 /* 181 * Many of the fields in the vnode are read-only once they are initialized 182 * at vnode creation time. Other fields are protected by locks. 183 * 184 * IMPORTANT: vnodes should be created ONLY by calls to vn_alloc(). They 185 * may not be embedded into the file-system specific node (inode). The 186 * size of vnodes may change. 187 * 188 * The v_lock protects: 189 * v_flag 190 * v_stream 191 * v_count 192 * v_shrlocks 193 * v_path 194 * v_vsd 195 * v_xattrdir 196 * 197 * A special lock (implemented by vn_vfswlock in vnode.c) protects: 198 * v_vfsmountedhere 199 * 200 * The global flock_lock mutex (in flock.c) protects: 201 * v_filocks 202 * 203 * IMPORTANT NOTE: 204 * 205 * The following vnode fields are considered public and may safely be 206 * accessed by file systems or other consumers: 207 * 208 * v_lock 209 * v_flag 210 * v_count 211 * v_data 212 * v_vfsp 213 * v_stream 214 * v_type 215 * v_rdev 216 * 217 * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD. 218 * In particular, file systems should not access other fields; they may 219 * change or even be removed. The functionality which was once provided 220 * by these fields is available through vn_* functions. 221 */ 222 223 struct fem_head; /* from fem.h */ 224 225 typedef struct vnode { 226 kmutex_t v_lock; /* protects vnode fields */ 227 uint_t v_flag; /* vnode flags (see below) */ 228 uint_t v_count; /* reference count */ 229 void *v_data; /* private data for fs */ 230 struct vfs *v_vfsp; /* ptr to containing VFS */ 231 struct stdata *v_stream; /* associated stream */ 232 enum vtype v_type; /* vnode type */ 233 dev_t v_rdev; /* device (VCHR, VBLK) */ 234 235 /* PRIVATE FIELDS BELOW - DO NOT USE */ 236 237 struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */ 238 struct vnodeops *v_op; /* vnode operations */ 239 struct page *v_pages; /* vnode pages list */ 240 struct filock *v_filocks; /* ptr to filock list */ 241 struct shrlocklist *v_shrlocks; /* ptr to shrlock list */ 242 krwlock_t v_nbllock; /* sync for NBMAND locks */ 243 kcondvar_t v_cv; /* synchronize locking */ 244 void *v_locality; /* hook for locality info */ 245 struct fem_head *v_femhead; /* fs monitoring */ 246 char *v_path; /* cached path */ 247 uint_t v_rdcnt; /* open for read count (VREG only) */ 248 uint_t v_wrcnt; /* open for write count (VREG only) */ 249 u_longlong_t v_mmap_read; /* mmap read count */ 250 u_longlong_t v_mmap_write; /* mmap write count */ 251 void *v_mpssdata; /* info for large page mappings */ 252 void *v_fopdata; /* list of file ops event watches */ 253 struct vsd_node *v_vsd; /* vnode specific data */ 254 struct vnode *v_xattrdir; /* unnamed extended attr dir (GFS) */ 255 uint_t v_count_dnlc; /* dnlc reference count */ 256 } vnode_t; 257 258 #define IS_DEVVP(vp) \ 259 ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO) 260 261 /* 262 * vnode flags. 263 */ 264 #define VROOT 0x01 /* root of its file system */ 265 #define VNOCACHE 0x02 /* don't keep cache pages on vnode */ 266 #define VNOMAP 0x04 /* file cannot be mapped/faulted */ 267 #define VDUP 0x08 /* file should be dup'ed rather then opened */ 268 #define VNOSWAP 0x10 /* file cannot be used as virtual swap device */ 269 #define VNOMOUNT 0x20 /* file cannot be covered by mount */ 270 #define VISSWAP 0x40 /* vnode is being used for swap */ 271 #define VSWAPLIKE 0x80 /* vnode acts like swap (but may not be) */ 272 273 #define IS_SWAPVP(vp) (((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0) 274 275 typedef struct vn_vfslocks_entry { 276 rwstlock_t ve_lock; 277 void *ve_vpvfs; 278 struct vn_vfslocks_entry *ve_next; 279 uint32_t ve_refcnt; 280 char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \ 281 sizeof (uint32_t)]; 282 } vn_vfslocks_entry_t; 283 284 /* 285 * The following two flags are used to lock the v_vfsmountedhere field 286 */ 287 #define VVFSLOCK 0x100 288 #define VVFSWAIT 0x200 289 290 /* 291 * Used to serialize VM operations on a vnode 292 */ 293 #define VVMLOCK 0x400 294 295 /* 296 * Tell vn_open() not to fail a directory open for writing but 297 * to go ahead and call VOP_OPEN() to let the filesystem check. 298 */ 299 #define VDIROPEN 0x800 300 301 /* 302 * Flag to let the VM system know that this file is most likely a binary 303 * or shared library since it has been mmap()ed EXEC at some time. 304 */ 305 #define VVMEXEC 0x1000 306 307 #define VPXFS 0x2000 /* clustering: global fs proxy vnode */ 308 309 #define IS_PXFSVP(vp) ((vp)->v_flag & VPXFS) 310 311 #define V_XATTRDIR 0x4000 /* attribute unnamed directory */ 312 313 #define IS_XATTRDIR(vp) ((vp)->v_flag & V_XATTRDIR) 314 315 #define V_LOCALITY 0x8000 /* whether locality aware */ 316 317 /* 318 * Flag that indicates the VM should maintain the v_pages list with all modified 319 * pages on one end and unmodified pages at the other. This makes finding dirty 320 * pages to write back to disk much faster at the expense of taking a minor 321 * fault on the first store instruction which touches a writable page. 322 */ 323 #define VMODSORT (0x10000) 324 #define IS_VMODSORT(vp) \ 325 (pvn_vmodsort_supported != 0 && ((vp)->v_flag & VMODSORT) != 0) 326 327 #define VISSWAPFS 0x20000 /* vnode is being used for swapfs */ 328 #define IS_SWAPFSVP(vp) (((vp)->v_flag & VISSWAPFS) != 0) 329 330 #define V_SYSATTR 0x40000 /* vnode is a GFS system attribute */ 331 332 /* 333 * Vnode attributes. A bit-mask is supplied as part of the 334 * structure to indicate the attributes the caller wants to 335 * set (setattr) or extract (getattr). 336 */ 337 338 /* 339 * Note that va_nodeid and va_nblocks are 64bit data type. 340 * We support large files over NFSV3. With Solaris client and 341 * Server that generates 64bit ino's and sizes these fields 342 * will overflow if they are 32 bit sizes. 343 */ 344 345 typedef struct vattr { 346 uint_t va_mask; /* bit-mask of attributes */ 347 vtype_t va_type; /* vnode type (for create) */ 348 mode_t va_mode; /* file access mode */ 349 uid_t va_uid; /* owner user id */ 350 gid_t va_gid; /* owner group id */ 351 dev_t va_fsid; /* file system id (dev for now) */ 352 u_longlong_t va_nodeid; /* node id */ 353 nlink_t va_nlink; /* number of references to file */ 354 u_offset_t va_size; /* file size in bytes */ 355 timestruc_t va_atime; /* time of last access */ 356 timestruc_t va_mtime; /* time of last modification */ 357 timestruc_t va_ctime; /* time of last status change */ 358 dev_t va_rdev; /* device the file represents */ 359 uint_t va_blksize; /* fundamental block size */ 360 u_longlong_t va_nblocks; /* # of blocks allocated */ 361 uint_t va_seq; /* sequence number */ 362 } vattr_t; 363 364 #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ 365 366 /* 367 * Structure of all optional attributes. 368 */ 369 typedef struct xoptattr { 370 timestruc_t xoa_createtime; /* Create time of file */ 371 uint8_t xoa_archive; 372 uint8_t xoa_system; 373 uint8_t xoa_readonly; 374 uint8_t xoa_hidden; 375 uint8_t xoa_nounlink; 376 uint8_t xoa_immutable; 377 uint8_t xoa_appendonly; 378 uint8_t xoa_nodump; 379 uint8_t xoa_opaque; 380 uint8_t xoa_av_quarantined; 381 uint8_t xoa_av_modified; 382 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; 383 } xoptattr_t; 384 385 /* 386 * The xvattr structure is really a variable length structure that 387 * is made up of: 388 * - The classic vattr_t (xva_vattr) 389 * - a 32 bit quantity (xva_mapsize) that specifies the size of the 390 * attribute bitmaps in 32 bit words. 391 * - A pointer to the returned attribute bitmap (needed because the 392 * previous element, the requested attribute bitmap) is variable lenth. 393 * - The requested attribute bitmap, which is an array of 32 bit words. 394 * Callers use the XVA_SET_REQ() macro to set the bits corresponding to 395 * the attributes that are being requested. 396 * - The returned attribute bitmap, which is an array of 32 bit words. 397 * File systems that support optional attributes use the XVA_SET_RTN() 398 * macro to set the bits corresponding to the attributes that are being 399 * returned. 400 * - The xoptattr_t structure which contains the attribute values 401 * 402 * xva_mapsize determines how many words in the attribute bitmaps. 403 * Immediately following the attribute bitmaps is the xoptattr_t. 404 * xva_getxoptattr() is used to get the pointer to the xoptattr_t 405 * section. 406 */ 407 408 #define XVA_MAPSIZE 3 /* Size of attr bitmaps */ 409 #define XVA_MAGIC 0x78766174 /* Magic # for verification */ 410 411 /* 412 * The xvattr structure is an extensible structure which permits optional 413 * attributes to be requested/returned. File systems may or may not support 414 * optional attributes. They do so at their own discretion but if they do 415 * support optional attributes, they must register the VFSFT_XVATTR feature 416 * so that the optional attributes can be set/retrived. 417 * 418 * The fields of the xvattr structure are: 419 * 420 * xva_vattr - The first element of an xvattr is a legacy vattr structure 421 * which includes the common attributes. If AT_XVATTR is set in the va_mask 422 * then the entire structure is treated as an xvattr. If AT_XVATTR is not 423 * set, then only the xva_vattr structure can be used. 424 * 425 * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification. 426 * 427 * xva_mapsize - Size of requested and returned attribute bitmaps. 428 * 429 * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the 430 * size of the array before it, xva_reqattrmap[], could change which means 431 * the location of xva_rtnattrmap[] could change. This will allow unbundled 432 * file systems to find the location of xva_rtnattrmap[] when the sizes change. 433 * 434 * xva_reqattrmap[] - Array of requested attributes. Attributes are 435 * represented by a specific bit in a specific element of the attribute 436 * map array. Callers set the bits corresponding to the attributes 437 * that the caller wants to get/set. 438 * 439 * xva_rtnattrmap[] - Array of attributes that the file system was able to 440 * process. Not all file systems support all optional attributes. This map 441 * informs the caller which attributes the underlying file system was able 442 * to set/get. (Same structure as the requested attributes array in terms 443 * of each attribute corresponding to specific bits and array elements.) 444 * 445 * xva_xoptattrs - Structure containing values of optional attributes. 446 * These values are only valid if the corresponding bits in xva_reqattrmap 447 * are set and the underlying file system supports those attributes. 448 */ 449 typedef struct xvattr { 450 vattr_t xva_vattr; /* Embedded vattr structure */ 451 uint32_t xva_magic; /* Magic Number */ 452 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ 453 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ 454 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ 455 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ 456 xoptattr_t xva_xoptattrs; /* Optional attributes */ 457 } xvattr_t; 458 459 #ifdef _SYSCALL32 460 /* 461 * For bigtypes time_t changed to 64 bit on the 64-bit kernel. 462 * Define an old version for user/kernel interface 463 */ 464 465 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 466 #pragma pack(4) 467 #endif 468 469 typedef struct vattr32 { 470 uint32_t va_mask; /* bit-mask of attributes */ 471 vtype_t va_type; /* vnode type (for create) */ 472 mode32_t va_mode; /* file access mode */ 473 uid32_t va_uid; /* owner user id */ 474 gid32_t va_gid; /* owner group id */ 475 dev32_t va_fsid; /* file system id (dev for now) */ 476 u_longlong_t va_nodeid; /* node id */ 477 nlink_t va_nlink; /* number of references to file */ 478 u_offset_t va_size; /* file size in bytes */ 479 timestruc32_t va_atime; /* time of last access */ 480 timestruc32_t va_mtime; /* time of last modification */ 481 timestruc32_t va_ctime; /* time of last status change */ 482 dev32_t va_rdev; /* device the file represents */ 483 uint32_t va_blksize; /* fundamental block size */ 484 u_longlong_t va_nblocks; /* # of blocks allocated */ 485 uint32_t va_seq; /* sequence number */ 486 } vattr32_t; 487 488 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 489 #pragma pack() 490 #endif 491 492 #else /* not _SYSCALL32 */ 493 #define vattr32 vattr 494 typedef vattr_t vattr32_t; 495 #endif /* _SYSCALL32 */ 496 497 /* 498 * Attributes of interest to the caller of setattr or getattr. 499 */ 500 #define AT_TYPE 0x00001 501 #define AT_MODE 0x00002 502 #define AT_UID 0x00004 503 #define AT_GID 0x00008 504 #define AT_FSID 0x00010 505 #define AT_NODEID 0x00020 506 #define AT_NLINK 0x00040 507 #define AT_SIZE 0x00080 508 #define AT_ATIME 0x00100 509 #define AT_MTIME 0x00200 510 #define AT_CTIME 0x00400 511 #define AT_RDEV 0x00800 512 #define AT_BLKSIZE 0x01000 513 #define AT_NBLOCKS 0x02000 514 /* 0x04000 */ /* unused */ 515 #define AT_SEQ 0x08000 516 /* 517 * If AT_XVATTR is set then there are additional bits to process in 518 * the xvattr_t's attribute bitmap. If this is not set then the bitmap 519 * MUST be ignored. Note that this bit must be set/cleared explicitly. 520 * That is, setting AT_ALL will NOT set AT_XVATTR. 521 */ 522 #define AT_XVATTR 0x10000 523 524 #define AT_ALL (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\ 525 AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\ 526 AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) 527 528 #define AT_STAT (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\ 529 AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE) 530 531 #define AT_TIMES (AT_ATIME|AT_MTIME|AT_CTIME) 532 533 #define AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\ 534 AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) 535 536 /* 537 * Attribute bits used in the extensible attribute's (xva's) attribute 538 * bitmaps. Note that the bitmaps are made up of a variable length number 539 * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n" 540 * is the element in the bitmap (starting at 1). This convention is for 541 * the convenience of the maintainer to keep track of which element each 542 * attribute belongs to. 543 * 544 * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS 545 * MUST USE THE XAT_* DEFINES. 546 */ 547 #define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */ 548 #define XAT0_CREATETIME 0x00000001 /* Create time of file */ 549 #define XAT0_ARCHIVE 0x00000002 /* Archive */ 550 #define XAT0_SYSTEM 0x00000004 /* System */ 551 #define XAT0_READONLY 0x00000008 /* Readonly */ 552 #define XAT0_HIDDEN 0x00000010 /* Hidden */ 553 #define XAT0_NOUNLINK 0x00000020 /* Nounlink */ 554 #define XAT0_IMMUTABLE 0x00000040 /* immutable */ 555 #define XAT0_APPENDONLY 0x00000080 /* appendonly */ 556 #define XAT0_NODUMP 0x00000100 /* nodump */ 557 #define XAT0_OPAQUE 0x00000200 /* opaque */ 558 #define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */ 559 #define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */ 560 #define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */ 561 562 #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \ 563 XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \ 564 XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| \ 565 XAT0_AV_MODIFIED|XAT0_AV_SCANSTAMP) 566 567 /* Support for XAT_* optional attributes */ 568 #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */ 569 #define XVA_SHFT 32 /* Used to shift index */ 570 571 /* 572 * Used to pry out the index and attribute bits from the XAT_* attributes 573 * defined below. Note that we're masking things down to 32 bits then 574 * casting to uint32_t. 575 */ 576 #define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK)) 577 #define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK)) 578 579 /* 580 * The following defines present a "flat namespace" so that consumers don't 581 * need to keep track of which element belongs to which bitmap entry. 582 * 583 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER 584 */ 585 #define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME) 586 #define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE) 587 #define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM) 588 #define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY) 589 #define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN) 590 #define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK) 591 #define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE) 592 #define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY) 593 #define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP) 594 #define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE) 595 #define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED) 596 #define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED) 597 #define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP) 598 599 /* 600 * The returned attribute map array (xva_rtnattrmap[]) is located past the 601 * requested attribute map array (xva_reqattrmap[]). Its location changes 602 * when the array sizes change. We use a separate pointer in a known location 603 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is 604 * set in xva_init() 605 */ 606 #define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp) 607 608 /* 609 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap 610 * of requested attributes (xva_reqattrmap[]). 611 */ 612 #define XVA_SET_REQ(xvap, attr) \ 613 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ 614 ASSERT((xvap)->xva_magic == XVA_MAGIC); \ 615 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr) 616 /* 617 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap 618 * of requested attributes (xva_reqattrmap[]). 619 */ 620 #define XVA_CLR_REQ(xvap, attr) \ 621 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ 622 ASSERT((xvap)->xva_magic == XVA_MAGIC); \ 623 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr) 624 625 /* 626 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap 627 * of returned attributes (xva_rtnattrmap[]). 628 */ 629 #define XVA_SET_RTN(xvap, attr) \ 630 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ 631 ASSERT((xvap)->xva_magic == XVA_MAGIC); \ 632 (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr) 633 634 /* 635 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[]) 636 * to see of the corresponding attribute bit is set. If so, returns non-zero. 637 */ 638 #define XVA_ISSET_REQ(xvap, attr) \ 639 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ 640 ((xvap)->xva_magic == XVA_MAGIC) && \ 641 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ 642 ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) 643 644 /* 645 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[]) 646 * to see of the corresponding attribute bit is set. If so, returns non-zero. 647 */ 648 #define XVA_ISSET_RTN(xvap, attr) \ 649 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ 650 ((xvap)->xva_magic == XVA_MAGIC) && \ 651 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ 652 ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) 653 654 /* 655 * Modes. Some values same as S_xxx entries from stat.h for convenience. 656 */ 657 #define VSUID 04000 /* set user id on execution */ 658 #define VSGID 02000 /* set group id on execution */ 659 #define VSVTX 01000 /* save swapped text even after use */ 660 661 /* 662 * Permissions. 663 */ 664 #define VREAD 00400 665 #define VWRITE 00200 666 #define VEXEC 00100 667 668 #define MODEMASK 07777 /* mode bits plus permission bits */ 669 #define PERMMASK 00777 /* permission bits */ 670 671 /* 672 * VOP_ACCESS flags 673 */ 674 #define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */ 675 #define V_APPEND 0x2 /* want to do append only check */ 676 677 /* 678 * Check whether mandatory file locking is enabled. 679 */ 680 681 #define MANDMODE(mode) (((mode) & (VSGID|(VEXEC>>3))) == VSGID) 682 #define MANDLOCK(vp, mode) ((vp)->v_type == VREG && MANDMODE(mode)) 683 684 /* 685 * Flags for vnode operations. 686 */ 687 enum rm { RMFILE, RMDIRECTORY }; /* rm or rmdir (remove) */ 688 enum symfollow { NO_FOLLOW, FOLLOW }; /* follow symlinks (or not) */ 689 enum vcexcl { NONEXCL, EXCL }; /* (non)excl create */ 690 enum create { CRCREAT, CRMKNOD, CRMKDIR }; /* reason for create */ 691 692 typedef enum rm rm_t; 693 typedef enum symfollow symfollow_t; 694 typedef enum vcexcl vcexcl_t; 695 typedef enum create create_t; 696 697 /* Vnode Events - Used by VOP_VNEVENT */ 698 typedef enum vnevent { 699 VE_SUPPORT = 0, /* Query */ 700 VE_RENAME_SRC = 1, /* Rename, with vnode as source */ 701 VE_RENAME_DEST = 2, /* Rename, with vnode as target/destination */ 702 VE_REMOVE = 3, /* Remove of vnode's name */ 703 VE_RMDIR = 4, /* Remove of directory vnode's name */ 704 VE_CREATE = 5, /* Create with vnode's name which exists */ 705 VE_LINK = 6, /* Link with vnode's name as source */ 706 VE_RENAME_DEST_DIR = 7, /* Rename with vnode as target dir */ 707 VE_MOUNTEDOVER = 8 /* File or Filesystem got mounted over vnode */ 708 } vnevent_t; 709 710 /* 711 * Values for checking vnode open and map counts 712 */ 713 enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR }; 714 715 typedef enum v_mode v_mode_t; 716 717 #define V_TRUE 1 718 #define V_FALSE 0 719 720 /* 721 * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations 722 */ 723 724 typedef struct vsecattr { 725 uint_t vsa_mask; /* See below */ 726 int vsa_aclcnt; /* ACL entry count */ 727 void *vsa_aclentp; /* pointer to ACL entries */ 728 int vsa_dfaclcnt; /* default ACL entry count */ 729 void *vsa_dfaclentp; /* pointer to default ACL entries */ 730 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ 731 uint_t vsa_aclflags; /* ACE ACL flags */ 732 } vsecattr_t; 733 734 /* vsa_mask values */ 735 #define VSA_ACL 0x0001 736 #define VSA_ACLCNT 0x0002 737 #define VSA_DFACL 0x0004 738 #define VSA_DFACLCNT 0x0008 739 #define VSA_ACE 0x0010 740 #define VSA_ACECNT 0x0020 741 #define VSA_ACE_ALLTYPES 0x0040 742 #define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */ 743 744 /* 745 * Structure used by various vnode operations to determine 746 * the context (pid, host, identity) of a caller. 747 * 748 * The cc_caller_id is used to identify one or more callers who invoke 749 * operations, possibly on behalf of others. For example, the NFS 750 * server could have it's own cc_caller_id which can be detected by 751 * vnode/vfs operations or (FEM) monitors on those operations. New 752 * caller IDs are generated by fs_new_caller_id(). 753 */ 754 typedef struct caller_context { 755 pid_t cc_pid; /* Process ID of the caller */ 756 int cc_sysid; /* System ID, used for remote calls */ 757 u_longlong_t cc_caller_id; /* Identifier for (set of) caller(s) */ 758 ulong_t cc_flags; 759 } caller_context_t; 760 761 /* 762 * Flags for caller context. The caller sets CC_DONTBLOCK if it does not 763 * want to block inside of a FEM monitor. The monitor will set CC_WOULDBLOCK 764 * and return EAGAIN if the operation would have blocked. 765 */ 766 #define CC_WOULDBLOCK 0x01 767 #define CC_DONTBLOCK 0x02 768 769 /* 770 * Structure tags for function prototypes, defined elsewhere. 771 */ 772 struct pathname; 773 struct fid; 774 struct flock64; 775 struct flk_callback; 776 struct shrlock; 777 struct page; 778 struct seg; 779 struct as; 780 struct pollhead; 781 782 #ifdef _KERNEL 783 784 /* 785 * VNODE_OPS defines all the vnode operations. It is used to define 786 * the vnodeops structure (below) and the fs_func_p union (vfs_opreg.h). 787 */ 788 #define VNODE_OPS \ 789 int (*vop_open)(vnode_t **, int, cred_t *, \ 790 caller_context_t *); \ 791 int (*vop_close)(vnode_t *, int, int, offset_t, cred_t *, \ 792 caller_context_t *); \ 793 int (*vop_read)(vnode_t *, uio_t *, int, cred_t *, \ 794 caller_context_t *); \ 795 int (*vop_write)(vnode_t *, uio_t *, int, cred_t *, \ 796 caller_context_t *); \ 797 int (*vop_ioctl)(vnode_t *, int, intptr_t, int, cred_t *, \ 798 int *, caller_context_t *); \ 799 int (*vop_setfl)(vnode_t *, int, int, cred_t *, \ 800 caller_context_t *); \ 801 int (*vop_getattr)(vnode_t *, vattr_t *, int, cred_t *, \ 802 caller_context_t *); \ 803 int (*vop_setattr)(vnode_t *, vattr_t *, int, cred_t *, \ 804 caller_context_t *); \ 805 int (*vop_access)(vnode_t *, int, int, cred_t *, \ 806 caller_context_t *); \ 807 int (*vop_lookup)(vnode_t *, char *, vnode_t **, \ 808 struct pathname *, \ 809 int, vnode_t *, cred_t *, \ 810 caller_context_t *, int *, \ 811 struct pathname *); \ 812 int (*vop_create)(vnode_t *, char *, vattr_t *, vcexcl_t, \ 813 int, vnode_t **, cred_t *, int, \ 814 caller_context_t *, vsecattr_t *); \ 815 int (*vop_remove)(vnode_t *, char *, cred_t *, \ 816 caller_context_t *, int); \ 817 int (*vop_link)(vnode_t *, vnode_t *, char *, cred_t *, \ 818 caller_context_t *, int); \ 819 int (*vop_rename)(vnode_t *, char *, vnode_t *, char *, \ 820 cred_t *, caller_context_t *, int); \ 821 int (*vop_mkdir)(vnode_t *, char *, vattr_t *, vnode_t **, \ 822 cred_t *, caller_context_t *, int, \ 823 vsecattr_t *); \ 824 int (*vop_rmdir)(vnode_t *, char *, vnode_t *, cred_t *, \ 825 caller_context_t *, int); \ 826 int (*vop_readdir)(vnode_t *, uio_t *, cred_t *, int *, \ 827 caller_context_t *, int); \ 828 int (*vop_symlink)(vnode_t *, char *, vattr_t *, char *, \ 829 cred_t *, caller_context_t *, int); \ 830 int (*vop_readlink)(vnode_t *, uio_t *, cred_t *, \ 831 caller_context_t *); \ 832 int (*vop_fsync)(vnode_t *, int, cred_t *, \ 833 caller_context_t *); \ 834 void (*vop_inactive)(vnode_t *, cred_t *, \ 835 caller_context_t *); \ 836 int (*vop_fid)(vnode_t *, struct fid *, \ 837 caller_context_t *); \ 838 int (*vop_rwlock)(vnode_t *, int, caller_context_t *); \ 839 void (*vop_rwunlock)(vnode_t *, int, caller_context_t *); \ 840 int (*vop_seek)(vnode_t *, offset_t, offset_t *, \ 841 caller_context_t *); \ 842 int (*vop_cmp)(vnode_t *, vnode_t *, caller_context_t *); \ 843 int (*vop_frlock)(vnode_t *, int, struct flock64 *, \ 844 int, offset_t, \ 845 struct flk_callback *, cred_t *, \ 846 caller_context_t *); \ 847 int (*vop_space)(vnode_t *, int, struct flock64 *, \ 848 int, offset_t, \ 849 cred_t *, caller_context_t *); \ 850 int (*vop_realvp)(vnode_t *, vnode_t **, \ 851 caller_context_t *); \ 852 int (*vop_getpage)(vnode_t *, offset_t, size_t, uint_t *, \ 853 struct page **, size_t, struct seg *, \ 854 caddr_t, enum seg_rw, cred_t *, \ 855 caller_context_t *); \ 856 int (*vop_putpage)(vnode_t *, offset_t, size_t, \ 857 int, cred_t *, caller_context_t *); \ 858 int (*vop_map)(vnode_t *, offset_t, struct as *, \ 859 caddr_t *, size_t, \ 860 uchar_t, uchar_t, uint_t, cred_t *, \ 861 caller_context_t *); \ 862 int (*vop_addmap)(vnode_t *, offset_t, struct as *, \ 863 caddr_t, size_t, \ 864 uchar_t, uchar_t, uint_t, cred_t *, \ 865 caller_context_t *); \ 866 int (*vop_delmap)(vnode_t *, offset_t, struct as *, \ 867 caddr_t, size_t, \ 868 uint_t, uint_t, uint_t, cred_t *, \ 869 caller_context_t *); \ 870 int (*vop_poll)(vnode_t *, short, int, short *, \ 871 struct pollhead **, \ 872 caller_context_t *); \ 873 int (*vop_dump)(vnode_t *, caddr_t, offset_t, offset_t, \ 874 caller_context_t *); \ 875 int (*vop_pathconf)(vnode_t *, int, ulong_t *, cred_t *, \ 876 caller_context_t *); \ 877 int (*vop_pageio)(vnode_t *, struct page *, \ 878 u_offset_t, size_t, int, cred_t *, \ 879 caller_context_t *); \ 880 int (*vop_dumpctl)(vnode_t *, int, offset_t *, \ 881 caller_context_t *); \ 882 void (*vop_dispose)(vnode_t *, struct page *, \ 883 int, int, cred_t *, \ 884 caller_context_t *); \ 885 int (*vop_setsecattr)(vnode_t *, vsecattr_t *, \ 886 int, cred_t *, caller_context_t *); \ 887 int (*vop_getsecattr)(vnode_t *, vsecattr_t *, \ 888 int, cred_t *, caller_context_t *); \ 889 int (*vop_shrlock)(vnode_t *, int, struct shrlock *, \ 890 int, cred_t *, caller_context_t *); \ 891 int (*vop_vnevent)(vnode_t *, vnevent_t, vnode_t *, \ 892 char *, caller_context_t *) 893 /* NB: No ";" */ 894 895 /* 896 * Operations on vnodes. Note: File systems must never operate directly 897 * on a 'vnodeops' structure -- it WILL change in future releases! They 898 * must use vn_make_ops() to create the structure. 899 */ 900 typedef struct vnodeops { 901 const char *vnop_name; 902 VNODE_OPS; /* Signatures of all vnode operations (vops) */ 903 } vnodeops_t; 904 905 typedef int (*fs_generic_func_p) (); /* Generic vop/vfsop/femop/fsemop ptr */ 906 907 extern int fop_open(vnode_t **, int, cred_t *, caller_context_t *); 908 extern int fop_close(vnode_t *, int, int, offset_t, cred_t *, 909 caller_context_t *); 910 extern int fop_read(vnode_t *, uio_t *, int, cred_t *, caller_context_t *); 911 extern int fop_write(vnode_t *, uio_t *, int, cred_t *, 912 caller_context_t *); 913 extern int fop_ioctl(vnode_t *, int, intptr_t, int, cred_t *, int *, 914 caller_context_t *); 915 extern int fop_setfl(vnode_t *, int, int, cred_t *, caller_context_t *); 916 extern int fop_getattr(vnode_t *, vattr_t *, int, cred_t *, 917 caller_context_t *); 918 extern int fop_setattr(vnode_t *, vattr_t *, int, cred_t *, 919 caller_context_t *); 920 extern int fop_access(vnode_t *, int, int, cred_t *, caller_context_t *); 921 extern int fop_lookup(vnode_t *, char *, vnode_t **, struct pathname *, 922 int, vnode_t *, cred_t *, caller_context_t *, 923 int *, struct pathname *); 924 extern int fop_create(vnode_t *, char *, vattr_t *, vcexcl_t, int, 925 vnode_t **, cred_t *, int, caller_context_t *, 926 vsecattr_t *); 927 extern int fop_remove(vnode_t *vp, char *, cred_t *, caller_context_t *, 928 int); 929 extern int fop_link(vnode_t *, vnode_t *, char *, cred_t *, 930 caller_context_t *, int); 931 extern int fop_rename(vnode_t *, char *, vnode_t *, char *, cred_t *, 932 caller_context_t *, int); 933 extern int fop_mkdir(vnode_t *, char *, vattr_t *, vnode_t **, cred_t *, 934 caller_context_t *, int, vsecattr_t *); 935 extern int fop_rmdir(vnode_t *, char *, vnode_t *, cred_t *, 936 caller_context_t *, int); 937 extern int fop_readdir(vnode_t *, uio_t *, cred_t *, int *, 938 caller_context_t *, int); 939 extern int fop_symlink(vnode_t *, char *, vattr_t *, char *, cred_t *, 940 caller_context_t *, int); 941 extern int fop_readlink(vnode_t *, uio_t *, cred_t *, caller_context_t *); 942 extern int fop_fsync(vnode_t *, int, cred_t *, caller_context_t *); 943 extern void fop_inactive(vnode_t *, cred_t *, caller_context_t *); 944 extern int fop_fid(vnode_t *, struct fid *, caller_context_t *); 945 extern int fop_rwlock(vnode_t *, int, caller_context_t *); 946 extern void fop_rwunlock(vnode_t *, int, caller_context_t *); 947 extern int fop_seek(vnode_t *, offset_t, offset_t *, caller_context_t *); 948 extern int fop_cmp(vnode_t *, vnode_t *, caller_context_t *); 949 extern int fop_frlock(vnode_t *, int, struct flock64 *, int, offset_t, 950 struct flk_callback *, cred_t *, 951 caller_context_t *); 952 extern int fop_space(vnode_t *, int, struct flock64 *, int, offset_t, 953 cred_t *, caller_context_t *); 954 extern int fop_realvp(vnode_t *, vnode_t **, caller_context_t *); 955 extern int fop_getpage(vnode_t *, offset_t, size_t, uint_t *, 956 struct page **, size_t, struct seg *, 957 caddr_t, enum seg_rw, cred_t *, 958 caller_context_t *); 959 extern int fop_putpage(vnode_t *, offset_t, size_t, int, cred_t *, 960 caller_context_t *); 961 extern int fop_map(vnode_t *, offset_t, struct as *, caddr_t *, size_t, 962 uchar_t, uchar_t, uint_t, cred_t *cr, 963 caller_context_t *); 964 extern int fop_addmap(vnode_t *, offset_t, struct as *, caddr_t, size_t, 965 uchar_t, uchar_t, uint_t, cred_t *, 966 caller_context_t *); 967 extern int fop_delmap(vnode_t *, offset_t, struct as *, caddr_t, size_t, 968 uint_t, uint_t, uint_t, cred_t *, 969 caller_context_t *); 970 extern int fop_poll(vnode_t *, short, int, short *, struct pollhead **, 971 caller_context_t *); 972 extern int fop_dump(vnode_t *, caddr_t, offset_t, offset_t, 973 caller_context_t *); 974 extern int fop_pathconf(vnode_t *, int, ulong_t *, cred_t *, 975 caller_context_t *); 976 extern int fop_pageio(vnode_t *, struct page *, u_offset_t, size_t, int, 977 cred_t *, caller_context_t *); 978 extern int fop_dumpctl(vnode_t *, int, offset_t *, caller_context_t *); 979 extern void fop_dispose(vnode_t *, struct page *, int, int, cred_t *, 980 caller_context_t *); 981 extern int fop_setsecattr(vnode_t *, vsecattr_t *, int, cred_t *, 982 caller_context_t *); 983 extern int fop_getsecattr(vnode_t *, vsecattr_t *, int, cred_t *, 984 caller_context_t *); 985 extern int fop_shrlock(vnode_t *, int, struct shrlock *, int, cred_t *, 986 caller_context_t *); 987 extern int fop_vnevent(vnode_t *, vnevent_t, vnode_t *, char *, 988 caller_context_t *); 989 990 #endif /* _KERNEL */ 991 992 #define VOP_OPEN(vpp, mode, cr, ct) \ 993 fop_open(vpp, mode, cr, ct) 994 #define VOP_CLOSE(vp, f, c, o, cr, ct) \ 995 fop_close(vp, f, c, o, cr, ct) 996 #define VOP_READ(vp, uiop, iof, cr, ct) \ 997 fop_read(vp, uiop, iof, cr, ct) 998 #define VOP_WRITE(vp, uiop, iof, cr, ct) \ 999 fop_write(vp, uiop, iof, cr, ct) 1000 #define VOP_IOCTL(vp, cmd, a, f, cr, rvp, ct) \ 1001 fop_ioctl(vp, cmd, a, f, cr, rvp, ct) 1002 #define VOP_SETFL(vp, f, a, cr, ct) \ 1003 fop_setfl(vp, f, a, cr, ct) 1004 #define VOP_GETATTR(vp, vap, f, cr, ct) \ 1005 fop_getattr(vp, vap, f, cr, ct) 1006 #define VOP_SETATTR(vp, vap, f, cr, ct) \ 1007 fop_setattr(vp, vap, f, cr, ct) 1008 #define VOP_ACCESS(vp, mode, f, cr, ct) \ 1009 fop_access(vp, mode, f, cr, ct) 1010 #define VOP_LOOKUP(vp, cp, vpp, pnp, f, rdir, cr, ct, defp, rpnp) \ 1011 fop_lookup(vp, cp, vpp, pnp, f, rdir, cr, ct, defp, rpnp) 1012 #define VOP_CREATE(dvp, p, vap, ex, mode, vpp, cr, flag, ct, vsap) \ 1013 fop_create(dvp, p, vap, ex, mode, vpp, cr, flag, ct, vsap) 1014 #define VOP_REMOVE(dvp, p, cr, ct, f) \ 1015 fop_remove(dvp, p, cr, ct, f) 1016 #define VOP_LINK(tdvp, fvp, p, cr, ct, f) \ 1017 fop_link(tdvp, fvp, p, cr, ct, f) 1018 #define VOP_RENAME(fvp, fnm, tdvp, tnm, cr, ct, f) \ 1019 fop_rename(fvp, fnm, tdvp, tnm, cr, ct, f) 1020 #define VOP_MKDIR(dp, p, vap, vpp, cr, ct, f, vsap) \ 1021 fop_mkdir(dp, p, vap, vpp, cr, ct, f, vsap) 1022 #define VOP_RMDIR(dp, p, cdir, cr, ct, f) \ 1023 fop_rmdir(dp, p, cdir, cr, ct, f) 1024 #define VOP_READDIR(vp, uiop, cr, eofp, ct, f) \ 1025 fop_readdir(vp, uiop, cr, eofp, ct, f) 1026 #define VOP_SYMLINK(dvp, lnm, vap, tnm, cr, ct, f) \ 1027 fop_symlink(dvp, lnm, vap, tnm, cr, ct, f) 1028 #define VOP_READLINK(vp, uiop, cr, ct) \ 1029 fop_readlink(vp, uiop, cr, ct) 1030 #define VOP_FSYNC(vp, syncflag, cr, ct) \ 1031 fop_fsync(vp, syncflag, cr, ct) 1032 #define VOP_INACTIVE(vp, cr, ct) \ 1033 fop_inactive(vp, cr, ct) 1034 #define VOP_FID(vp, fidp, ct) \ 1035 fop_fid(vp, fidp, ct) 1036 #define VOP_RWLOCK(vp, w, ct) \ 1037 fop_rwlock(vp, w, ct) 1038 #define VOP_RWUNLOCK(vp, w, ct) \ 1039 fop_rwunlock(vp, w, ct) 1040 #define VOP_SEEK(vp, ooff, noffp, ct) \ 1041 fop_seek(vp, ooff, noffp, ct) 1042 #define VOP_CMP(vp1, vp2, ct) \ 1043 fop_cmp(vp1, vp2, ct) 1044 #define VOP_FRLOCK(vp, cmd, a, f, o, cb, cr, ct) \ 1045 fop_frlock(vp, cmd, a, f, o, cb, cr, ct) 1046 #define VOP_SPACE(vp, cmd, a, f, o, cr, ct) \ 1047 fop_space(vp, cmd, a, f, o, cr, ct) 1048 #define VOP_REALVP(vp1, vp2, ct) \ 1049 fop_realvp(vp1, vp2, ct) 1050 #define VOP_GETPAGE(vp, of, sz, pr, pl, ps, sg, a, rw, cr, ct) \ 1051 fop_getpage(vp, of, sz, pr, pl, ps, sg, a, rw, cr, ct) 1052 #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) \ 1053 fop_putpage(vp, of, sz, fl, cr, ct) 1054 #define VOP_MAP(vp, of, as, a, sz, p, mp, fl, cr, ct) \ 1055 fop_map(vp, of, as, a, sz, p, mp, fl, cr, ct) 1056 #define VOP_ADDMAP(vp, of, as, a, sz, p, mp, fl, cr, ct) \ 1057 fop_addmap(vp, of, as, a, sz, p, mp, fl, cr, ct) 1058 #define VOP_DELMAP(vp, of, as, a, sz, p, mp, fl, cr, ct) \ 1059 fop_delmap(vp, of, as, a, sz, p, mp, fl, cr, ct) 1060 #define VOP_POLL(vp, events, anyyet, reventsp, phpp, ct) \ 1061 fop_poll(vp, events, anyyet, reventsp, phpp, ct) 1062 #define VOP_DUMP(vp, addr, bn, count, ct) \ 1063 fop_dump(vp, addr, bn, count, ct) 1064 #define VOP_PATHCONF(vp, cmd, valp, cr, ct) \ 1065 fop_pathconf(vp, cmd, valp, cr, ct) 1066 #define VOP_PAGEIO(vp, pp, io_off, io_len, flags, cr, ct) \ 1067 fop_pageio(vp, pp, io_off, io_len, flags, cr, ct) 1068 #define VOP_DUMPCTL(vp, action, blkp, ct) \ 1069 fop_dumpctl(vp, action, blkp, ct) 1070 #define VOP_DISPOSE(vp, pp, flag, dn, cr, ct) \ 1071 fop_dispose(vp, pp, flag, dn, cr, ct) 1072 #define VOP_GETSECATTR(vp, vsap, f, cr, ct) \ 1073 fop_getsecattr(vp, vsap, f, cr, ct) 1074 #define VOP_SETSECATTR(vp, vsap, f, cr, ct) \ 1075 fop_setsecattr(vp, vsap, f, cr, ct) 1076 #define VOP_SHRLOCK(vp, cmd, shr, f, cr, ct) \ 1077 fop_shrlock(vp, cmd, shr, f, cr, ct) 1078 #define VOP_VNEVENT(vp, vnevent, dvp, fnm, ct) \ 1079 fop_vnevent(vp, vnevent, dvp, fnm, ct) 1080 1081 #define VOPNAME_OPEN "open" 1082 #define VOPNAME_CLOSE "close" 1083 #define VOPNAME_READ "read" 1084 #define VOPNAME_WRITE "write" 1085 #define VOPNAME_IOCTL "ioctl" 1086 #define VOPNAME_SETFL "setfl" 1087 #define VOPNAME_GETATTR "getattr" 1088 #define VOPNAME_SETATTR "setattr" 1089 #define VOPNAME_ACCESS "access" 1090 #define VOPNAME_LOOKUP "lookup" 1091 #define VOPNAME_CREATE "create" 1092 #define VOPNAME_REMOVE "remove" 1093 #define VOPNAME_LINK "link" 1094 #define VOPNAME_RENAME "rename" 1095 #define VOPNAME_MKDIR "mkdir" 1096 #define VOPNAME_RMDIR "rmdir" 1097 #define VOPNAME_READDIR "readdir" 1098 #define VOPNAME_SYMLINK "symlink" 1099 #define VOPNAME_READLINK "readlink" 1100 #define VOPNAME_FSYNC "fsync" 1101 #define VOPNAME_INACTIVE "inactive" 1102 #define VOPNAME_FID "fid" 1103 #define VOPNAME_RWLOCK "rwlock" 1104 #define VOPNAME_RWUNLOCK "rwunlock" 1105 #define VOPNAME_SEEK "seek" 1106 #define VOPNAME_CMP "cmp" 1107 #define VOPNAME_FRLOCK "frlock" 1108 #define VOPNAME_SPACE "space" 1109 #define VOPNAME_REALVP "realvp" 1110 #define VOPNAME_GETPAGE "getpage" 1111 #define VOPNAME_PUTPAGE "putpage" 1112 #define VOPNAME_MAP "map" 1113 #define VOPNAME_ADDMAP "addmap" 1114 #define VOPNAME_DELMAP "delmap" 1115 #define VOPNAME_POLL "poll" 1116 #define VOPNAME_DUMP "dump" 1117 #define VOPNAME_PATHCONF "pathconf" 1118 #define VOPNAME_PAGEIO "pageio" 1119 #define VOPNAME_DUMPCTL "dumpctl" 1120 #define VOPNAME_DISPOSE "dispose" 1121 #define VOPNAME_GETSECATTR "getsecattr" 1122 #define VOPNAME_SETSECATTR "setsecattr" 1123 #define VOPNAME_SHRLOCK "shrlock" 1124 #define VOPNAME_VNEVENT "vnevent" 1125 1126 /* 1127 * Flags for VOP_LOOKUP 1128 * 1129 * Defined in file.h, but also possible, FIGNORECASE 1130 * 1131 */ 1132 #define LOOKUP_DIR 0x01 /* want parent dir vp */ 1133 #define LOOKUP_XATTR 0x02 /* lookup up extended attr dir */ 1134 #define CREATE_XATTR_DIR 0x04 /* Create extended attr dir */ 1135 #define LOOKUP_HAVE_SYSATTR_DIR 0x08 /* Already created virtual GFS dir */ 1136 1137 /* 1138 * Flags for VOP_READDIR 1139 */ 1140 #define V_RDDIR_ENTFLAGS 0x01 /* request dirent flags */ 1141 1142 /* 1143 * Flags for VOP_RWLOCK/VOP_RWUNLOCK 1144 * VOP_RWLOCK will return the flag that was actually set, or -1 if none. 1145 */ 1146 #define V_WRITELOCK_TRUE (1) /* Request write-lock on the vnode */ 1147 #define V_WRITELOCK_FALSE (0) /* Request read-lock on the vnode */ 1148 1149 /* 1150 * Flags for VOP_DUMPCTL 1151 */ 1152 #define DUMP_ALLOC 0 1153 #define DUMP_FREE 1 1154 #define DUMP_SCAN 2 1155 1156 /* 1157 * Public vnode manipulation functions. 1158 */ 1159 #ifdef _KERNEL 1160 1161 vnode_t *vn_alloc(int); 1162 void vn_reinit(vnode_t *); 1163 void vn_recycle(vnode_t *); 1164 void vn_free(vnode_t *); 1165 1166 int vn_is_readonly(vnode_t *); 1167 int vn_is_opened(vnode_t *, v_mode_t); 1168 int vn_is_mapped(vnode_t *, v_mode_t); 1169 int vn_has_other_opens(vnode_t *, v_mode_t); 1170 void vn_open_upgrade(vnode_t *, int); 1171 void vn_open_downgrade(vnode_t *, int); 1172 1173 int vn_can_change_zones(vnode_t *vp); 1174 1175 int vn_has_flocks(vnode_t *); 1176 int vn_has_mandatory_locks(vnode_t *, int); 1177 int vn_has_cached_data(vnode_t *); 1178 1179 void vn_setops(vnode_t *, vnodeops_t *); 1180 vnodeops_t *vn_getops(vnode_t *); 1181 int vn_matchops(vnode_t *, vnodeops_t *); 1182 int vn_matchopval(vnode_t *, char *, fs_generic_func_p); 1183 int vn_ismntpt(vnode_t *); 1184 1185 struct vfs *vn_mountedvfs(vnode_t *); 1186 1187 int vn_in_dnlc(vnode_t *); 1188 1189 void vn_create_cache(void); 1190 void vn_destroy_cache(void); 1191 1192 void vn_freevnodeops(vnodeops_t *); 1193 1194 int vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode, 1195 struct vnode **vpp, enum create crwhy, mode_t umask); 1196 int vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode, 1197 struct vnode **vpp, enum create crwhy, 1198 mode_t umask, struct vnode *startvp, int fd); 1199 int vn_create(char *pnamep, enum uio_seg seg, struct vattr *vap, 1200 enum vcexcl excl, int mode, struct vnode **vpp, 1201 enum create why, int flag, mode_t umask); 1202 int vn_createat(char *pnamep, enum uio_seg seg, struct vattr *vap, 1203 enum vcexcl excl, int mode, struct vnode **vpp, 1204 enum create why, int flag, mode_t umask, struct vnode *startvp); 1205 int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len, 1206 offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit, 1207 cred_t *cr, ssize_t *residp); 1208 void vn_rele(struct vnode *vp); 1209 void vn_rele_dnlc(struct vnode *vp); 1210 void vn_rele_stream(struct vnode *vp); 1211 int vn_link(char *from, char *to, enum uio_seg seg); 1212 int vn_rename(char *from, char *to, enum uio_seg seg); 1213 int vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname, 1214 enum uio_seg seg); 1215 int vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag); 1216 int vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg, 1217 enum rm dirflag); 1218 int vn_compare(vnode_t *vp1, vnode_t *vp2); 1219 int vn_vfswlock(struct vnode *vp); 1220 int vn_vfswlock_wait(struct vnode *vp); 1221 int vn_vfsrlock(struct vnode *vp); 1222 int vn_vfsrlock_wait(struct vnode *vp); 1223 void vn_vfsunlock(struct vnode *vp); 1224 int vn_vfswlock_held(struct vnode *vp); 1225 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr); 1226 vnode_t *makespecvp(dev_t dev, vtype_t type); 1227 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *); 1228 void vn_vfslocks_rele(vn_vfslocks_entry_t *); 1229 1230 void vn_copypath(struct vnode *src, struct vnode *dst); 1231 void vn_setpath_str(struct vnode *vp, const char *str, size_t len); 1232 void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp, 1233 const char *path, size_t plen); 1234 void vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len); 1235 1236 /* Vnode event notification */ 1237 void vnevent_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *); 1238 void vnevent_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *); 1239 void vnevent_remove(vnode_t *, vnode_t *, char *, caller_context_t *); 1240 void vnevent_rmdir(vnode_t *, vnode_t *, char *, caller_context_t *); 1241 void vnevent_create(vnode_t *, caller_context_t *); 1242 void vnevent_link(vnode_t *, caller_context_t *); 1243 void vnevent_rename_dest_dir(vnode_t *, caller_context_t *ct); 1244 void vnevent_mountedover(vnode_t *, caller_context_t *); 1245 int vnevent_support(vnode_t *, caller_context_t *); 1246 1247 /* Vnode specific data */ 1248 void vsd_create(uint_t *, void (*)(void *)); 1249 void vsd_destroy(uint_t *); 1250 void *vsd_get(vnode_t *, uint_t); 1251 int vsd_set(vnode_t *, uint_t, void *); 1252 void vsd_free(vnode_t *); 1253 1254 /* 1255 * Extensible vnode attribute (xva) routines: 1256 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR) 1257 * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t 1258 */ 1259 void xva_init(xvattr_t *); 1260 xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */ 1261 1262 void xattr_init(void); /* Initialize vnodeops for xattrs */ 1263 1264 /* GFS tunnel for xattrs */ 1265 int xattr_dir_lookup(vnode_t *, vnode_t **, int, cred_t *); 1266 1267 /* Context identification */ 1268 u_longlong_t fs_new_caller_id(); 1269 1270 int vn_vmpss_usepageio(vnode_t *); 1271 1272 /* 1273 * Needed for use of IS_VMODSORT() in kernel. 1274 */ 1275 extern uint_t pvn_vmodsort_supported; 1276 1277 #define VN_HOLD(vp) { \ 1278 mutex_enter(&(vp)->v_lock); \ 1279 (vp)->v_count++; \ 1280 mutex_exit(&(vp)->v_lock); \ 1281 } 1282 1283 #define VN_RELE(vp) { \ 1284 vn_rele(vp); \ 1285 } 1286 1287 #define VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev) { \ 1288 (vp)->v_vfsp = (vfsp); \ 1289 (vp)->v_type = (type); \ 1290 (vp)->v_rdev = (dev); \ 1291 } 1292 1293 /* 1294 * Compare two vnodes for equality. In general this macro should be used 1295 * in preference to calling VOP_CMP directly. 1296 */ 1297 #define VN_CMP(VP1, VP2) ((VP1) == (VP2) ? 1 : \ 1298 ((VP1) && (VP2) && (vn_getops(VP1) == vn_getops(VP2)) ? \ 1299 VOP_CMP(VP1, VP2, NULL) : 0)) 1300 1301 extern struct vnode kvp; 1302 extern struct vnode zvp; 1303 1304 #define VN_ISKAS(vp) ((vp) == &kvp || (vp) == &zvp) 1305 1306 #endif /* _KERNEL */ 1307 1308 /* 1309 * Flags to VOP_SETATTR/VOP_GETATTR. 1310 */ 1311 #define ATTR_UTIME 0x01 /* non-default utime(2) request */ 1312 #define ATTR_EXEC 0x02 /* invocation from exec(2) */ 1313 #define ATTR_COMM 0x04 /* yield common vp attributes */ 1314 #define ATTR_HINT 0x08 /* information returned will be `hint' */ 1315 #define ATTR_REAL 0x10 /* yield attributes of the real vp */ 1316 #define ATTR_NOACLCHECK 0x20 /* Don't check ACL when checking permissions */ 1317 #define ATTR_TRIGGER 0x40 /* Mount first if vnode is a trigger mount */ 1318 /* 1319 * Generally useful macros. 1320 */ 1321 #define VBSIZE(vp) ((vp)->v_vfsp->vfs_bsize) 1322 1323 #define VTOZONE(vp) ((vp)->v_vfsp->vfs_zone) 1324 1325 #define NULLVP ((struct vnode *)0) 1326 #define NULLVPP ((struct vnode **)0) 1327 1328 #ifdef _KERNEL 1329 1330 /* 1331 * Structure used while handling asynchronous VOP_PUTPAGE operations. 1332 */ 1333 struct async_reqs { 1334 struct async_reqs *a_next; /* pointer to next arg struct */ 1335 struct vnode *a_vp; /* vnode pointer */ 1336 u_offset_t a_off; /* offset in file */ 1337 uint_t a_len; /* size of i/o request */ 1338 int a_flags; /* flags to indicate operation type */ 1339 struct cred *a_cred; /* cred pointer */ 1340 ushort_t a_prealloced; /* set if struct is pre-allocated */ 1341 }; 1342 1343 /* 1344 * VN_DISPOSE() -- given a page pointer, safely invoke VOP_DISPOSE(). 1345 * Note that there is no guarantee that the page passed in will be 1346 * freed. If that is required, then a check after calling VN_DISPOSE would 1347 * be necessary to ensure the page was freed. 1348 */ 1349 #define VN_DISPOSE(pp, flag, dn, cr) { \ 1350 extern struct vnode kvp; \ 1351 if ((pp)->p_vnode != NULL && !VN_ISKAS((pp)->p_vnode)) \ 1352 VOP_DISPOSE((pp)->p_vnode, (pp), (flag), (dn), (cr), NULL); \ 1353 else if ((flag) == B_FREE) \ 1354 page_free((pp), (dn)); \ 1355 else \ 1356 page_destroy((pp), (dn)); \ 1357 } 1358 1359 #endif /* _KERNEL */ 1360 1361 #ifdef __cplusplus 1362 } 1363 #endif 1364 1365 #endif /* _SYS_VNODE_H */ 1366