Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: vnode.h,v 1.23 2026/03/23 23:43:28 yamt Exp $	*/
      2 
      3 /*
      4  * CDDL HEADER START
      5  *
      6  * The contents of this file are subject to the terms of the
      7  * Common Development and Distribution License (the "License").
      8  * You may not use this file except in compliance with the License.
      9  *
     10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     11  * or http://www.opensolaris.org/os/licensing.
     12  * See the License for the specific language governing permissions
     13  * and limitations under the License.
     14  *
     15  * When distributing Covered Code, include this CDDL HEADER in each
     16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     17  * If applicable, add the following below this CDDL HEADER, with the
     18  * fields enclosed by brackets "[]" replaced with your own identifying
     19  * information: Portions Copyright [yyyy] [name of copyright owner]
     20  *
     21  * CDDL HEADER END
     22  */
     23 /*
     24  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
     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 /*-
     41  * Copyright (c) 2009 The NetBSD Foundation, Inc.
     42  * All rights reserved.
     43  *
     44  * This code is derived from software contributed to The NetBSD Foundation
     45  * by Andrew Doran.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  *
     56  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     57  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     58  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     59  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     60  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     66  * POSSIBILITY OF SUCH DAMAGE.
     67  */
     68 
     69 /*-
     70  * Copyright (c) 2007 Pawel Jakub Dawidek <pjd (at) FreeBSD.org>
     71  * All rights reserved.
     72  *
     73  * Redistribution and use in source and binary forms, with or without
     74  * modification, are permitted provided that the following conditions
     75  * are met:
     76  * 1. Redistributions of source code must retain the above copyright
     77  *    notice, this list of conditions and the following disclaimer.
     78  * 2. Redistributions in binary form must reproduce the above copyright
     79  *    notice, this list of conditions and the following disclaimer in the
     80  *    documentation and/or other materials provided with the distribution.
     81  *
     82  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
     83  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     84  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     85  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
     86  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     87  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     88  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     89  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     90  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     91  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     92  * SUCH DAMAGE.
     93  *
     94  * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/vnode.h 308691 2016-11-15 18:22:50Z alc $
     95  */
     96 
     97 #ifndef _OPENSOLARIS_SYS_VNODE_H_
     98 #define	_OPENSOLARIS_SYS_VNODE_H_
     99 
    100 #ifdef _KERNEL
    101 
    102 struct vattr;
    103 typedef	struct vattr	vattr_t;
    104 typedef enum vtype vtype_t;
    105 
    106 #include <sys/namei.h>
    107 enum symfollow { NO_FOLLOW = NOFOLLOW };
    108 
    109 /*
    110  * We'll use the two-parameter FreeBSD VOP_UNLOCK() in ZFS code.
    111  */
    112 
    113 #define VOP_UNLOCK __hide_VOP_UNLOCK
    114 #include_next <sys/vnode.h>
    115 /* verify that the real definition is what we expect */
    116 int __hide_VOP_UNLOCK(struct vnode *);
    117 #undef VOP_UNLOCK
    118 
    119 int VOP_UNLOCK(struct vnode *, int);
    120 
    121 #include <sys/cred.h>
    122 #include <sys/fcntl.h>
    123 #include <sys/proc.h>
    124 #include <sys/filedesc.h>
    125 #include <sys/buf.h>
    126 
    127 #include <sys/vfs_syscalls.h>
    128 
    129 typedef int (**vnodeops_t)(void *);
    130 
    131 #define	vop_fid		vop_vptofh
    132 #define	vop_fid_args	vop_vptofh_args
    133 #define	a_fid		a_fhp
    134 
    135 #define	v_object	v_uobj
    136 
    137 struct vop_vptofh_args {
    138 	struct vnode *a_vp;
    139 	struct fid *a_fid;
    140 };
    141 
    142 #define IS_XATTRDIR(vp)	(0)
    143 
    144 #define v_lock v_interlock
    145 
    146 #define SAVENAME 0
    147 
    148 int	vn_is_readonly(vnode_t *);
    149 
    150 #define	vn_vfswlock(vp)		(0)
    151 #define	vn_vfsunlock(vp)	do { } while (0)
    152 #define	vn_ismntpt(vp)		((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
    153 #define	vn_mountedvfs(vp)	((vp)->v_mountedhere)
    154 #define vn_has_cached_data(vp)	(((vp)->v_iflag & VI_PAGES) != 0)
    155 #define	vn_exists(vp)		do { } while (0)
    156 #define	vn_invalid(vp)		do { } while (0)
    157 #define	vn_free(vp)		do { } while (0)
    158 #define vn_renamepath(tdvp, svp, tnm, lentnm)   do { } while (0)
    159 #define	vn_matchops(vp, vops)	((vp)->v_op == &(vops))
    160 
    161 #define	VN_HOLD(v)	vref(v)
    162 #define	VN_RELE(v)						      \
    163 do {								      \
    164 	if (vrefcnt(v) == 0) {					      \
    165 		printf("VN_RELE(%s,%d): %p unused\n", __FILE__, __LINE__, v); \
    166 		vprint("VN_RELE", (v));				      \
    167 		panic("VN_RELE");				      \
    168 	} else {						      \
    169 		vrele(v);					      \
    170 	}							      \
    171 } while (/*CONSTCOND*/0)
    172 #define	VN_URELE(v)	vput(v)
    173 #undef VN_RELE_ASYNC
    174 #define VN_RELE_ASYNC(vp, taskq) 	vrele_async((vp))
    175 
    176 #define	vnevent_create(vp, ct)			do { } while (0)
    177 #define	vnevent_link(vp, ct)			do { } while (0)
    178 #define	vnevent_remove(vp, dvp, name, ct)	do { } while (0)
    179 #define	vnevent_rmdir(vp, dvp, name, ct)	do { } while (0)
    180 #define	vnevent_rename_src(vp, dvp, name, ct)	do { } while (0)
    181 #define	vnevent_rename_dest(vp, dvp, name, ct)	do { } while (0)
    182 #define	vnevent_rename_dest_dir(vp, ct)		do { } while (0)
    183 
    184 #define	specvp(vp, rdev, type, cr)	(VN_HOLD(vp), (vp))
    185 #define	MANDMODE(mode)	(0)
    186 #define	MANDLOCK(vp, mode)	(0)
    187 #define	chklock(vp, op, offset, size, mode, ct)	(0)
    188 #define	cleanlocks(vp, pid, foo)	do { } while (0)
    189 #define	cleanshares(vp, pid)		do { } while (0)
    190 
    191 /*
    192  * We will use va_spare is place of Solaris' va_mask.
    193  * This field is initialized in zfs_setattr().
    194  */
    195 #define	va_mask		va_spare
    196 /* TODO: va_fileid is shorter than va_nodeid !!! */
    197 #define	va_nodeid	va_fileid
    198 /* TODO: This field needs conversion! */
    199 #define	va_nblocks	va_bytes
    200 #define	va_blksize	va_blocksize
    201 #define	va_seq		va_gen
    202 
    203 #define	EXCL		0
    204 
    205 #define	ACCESSED		(AT_ATIME)
    206 #define	STATE_CHANGED		(AT_CTIME)
    207 #define	CONTENT_MODIFIED	(AT_MTIME | AT_CTIME)
    208 
    209 static inline void
    210 vattr_init_mask(vattr_t *vap)
    211 {
    212 
    213 	vap->va_mask = 0;
    214 
    215 	if (vap->va_type != VNON)
    216 		vap->va_mask |= AT_TYPE;
    217 	if (vap->va_uid != (uid_t)VNOVAL)
    218 		vap->va_mask |= AT_UID;
    219 	if (vap->va_gid != (gid_t)VNOVAL)
    220 		vap->va_mask |= AT_GID;
    221 	if (vap->va_size != (u_quad_t)VNOVAL)
    222 		vap->va_mask |= AT_SIZE;
    223 	if (vap->va_atime.tv_sec != VNOVAL)
    224 		vap->va_mask |= AT_ATIME;
    225 	if (vap->va_mtime.tv_sec != VNOVAL)
    226 		vap->va_mask |= AT_MTIME;
    227 	if (vap->va_mode != (mode_t)VNOVAL)
    228 		vap->va_mask |= AT_MODE;
    229 	if (vap->va_flags != VNOVAL)
    230 		vap->va_mask |= AT_XVATTR;
    231 }
    232 
    233 #define	FCREAT	O_CREAT
    234 #define	FTRUNC	O_TRUNC
    235 #define	FSYNC	FFSYNC
    236 #define	FOFFMAX	0x00
    237 
    238 static inline int
    239 zfs_vn_open(const char *pnamep, enum uio_seg seg, int filemode, int createmode,
    240     vnode_t **vpp, enum create crwhy, mode_t umask, vnode_t *rootvn)
    241 {
    242 	struct pathbuf *pb;
    243 	int error;
    244 
    245 	ASSERT(seg == UIO_SYSSPACE);
    246 	ASSERT((filemode & (FWRITE | FCREAT | FTRUNC | FOFFMAX)) != 0);
    247 	ASSERT(crwhy == CRCREAT);
    248 	ASSERT(umask == 0);
    249 
    250 	pb = pathbuf_create(pnamep);
    251 	error = vn_open(rootvn, pb, 0, filemode, createmode, vpp, NULL, NULL);
    252 	if (error == 0) {
    253 		VOP_UNLOCK(*vpp, 0);
    254 	}
    255 	pathbuf_destroy(pb);
    256 	return (error);
    257 }
    258 #define	vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)	\
    259 	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask), NULL)
    260 
    261 #define	vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, umask, rootvn, unk)	\
    262 	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask), (rootvn))
    263 
    264 #define	RLIM64_INFINITY	0
    265 static inline int
    266 zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
    267     offset_t offset, enum uio_seg seg, int ioflag, uint64_t ulimit, cred_t *cr,
    268     ssize_t *residp)
    269 {
    270 	int error;
    271 	size_t resid;
    272 
    273 	ASSERT(rw == UIO_READ || rw == UIO_WRITE);
    274 	ASSERT(ioflag == 0);
    275 	ASSERT(ulimit == RLIM64_INFINITY);
    276 
    277 	ioflag = IO_UNIT;
    278 
    279 	error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr,
    280 	    &resid, curlwp);
    281 	if (residp != NULL)
    282 		*residp = (ssize_t)resid;
    283 	return (error);
    284 }
    285 #define	vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
    286 	zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
    287 
    288 static inline int
    289 zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
    290 {
    291 	int error;
    292 
    293 	ASSERT(flag == FSYNC);
    294 
    295 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    296 	error = VOP_FSYNC(vp, cr, FSYNC_WAIT, 0, 0);
    297 	VOP_UNLOCK(vp, 0);
    298 	return (error);
    299 }
    300 #define	VOP_FSYNC(vp, flag, cr, unk)	zfs_vop_fsync((vp), (flag), (cr))
    301 
    302 static inline int
    303 zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
    304 {
    305 
    306 	ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
    307 	ASSERT(count == 1);
    308 	ASSERT(offset == 0);
    309 
    310 	return (vn_close(vp, flag, cr));
    311 }
    312 #define	VOP_CLOSE(vp, oflags, count, offset, cr, unk) \
    313 	zfs_vop_close((vp), (oflags), (count), (offset), (cr))
    314 
    315 static inline int
    316 zfs_vop_getattr(vnode_t *vp, vattr_t *ap, int flag, cred_t *cr)
    317 {
    318 	int error;
    319 
    320 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    321 	error = VOP_GETATTR(vp, ap, cr);
    322 	VOP_UNLOCK(vp, 0);
    323 	return (error);
    324 }
    325 #define	VOP_GETATTR(vp, ap, flag, cr, unk)	zfs_vop_getattr((vp), (ap), (flag), (cr))
    326 
    327 static inline int
    328 zfs_vop_seek(vnode_t *vp, off_t off, off_t *offp)
    329 {
    330 	int error;
    331 
    332 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    333 	error = VOP_SEEK(vp, off, *offp, CRED());
    334 	VOP_UNLOCK(vp, 0);
    335 	return (error);
    336 }
    337 #define	VOP_SEEK(vp, off, offp, unk)	zfs_vop_seek(vp, off, offp)
    338 
    339 #define	B_INVAL		BC_INVAL
    340 
    341 static inline int
    342 zfs_vop_putpage(vnode_t *vp, off_t off, size_t len, int flag)
    343 {
    344 	int nbflag;
    345 
    346 	nbflag = 0;
    347 	if (len == 0) {
    348 		nbflag |= PGO_ALLPAGES;
    349 	}
    350 	if ((flag & B_ASYNC) == 0) {
    351 		nbflag |= PGO_SYNCIO;
    352 	}
    353 	if ((flag & B_INVAL) != 0) {
    354 		nbflag |= PGO_FREE;
    355 	} else {
    356 		nbflag |= PGO_CLEANIT;
    357 	}
    358 
    359 	mutex_enter(vp->v_interlock);
    360 	return VOP_PUTPAGES(vp, off, len, nbflag);
    361 }
    362 #define	VOP_PUTPAGE(vp, off, len, flag, cr, ct)	zfs_vop_putpage((vp), (off), (len), (flag))
    363 
    364 static inline int
    365 vn_rename(char *from, char *to, enum uio_seg seg)
    366 {
    367 
    368 	ASSERT(seg == UIO_SYSSPACE);
    369 
    370 	return (do_sys_rename(from, to, seg, 0));
    371 }
    372 
    373 static inline int
    374 vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
    375 {
    376 
    377 	ASSERT(seg == UIO_SYSSPACE);
    378 	ASSERT(dirflag == RMFILE);
    379 
    380 	return (do_sys_unlink(fnamep, seg));
    381 }
    382 
    383 /*
    384  * VOP_ACCESS flags
    385  */
    386 #define V_APPEND    0x2 /* want to do append only check */
    387 
    388 #define VV_NOSYNC	0
    389 
    390 #define VI_LOCK(vp)     mutex_enter((vp)->v_interlock)
    391 #define VI_UNLOCK(vp)   mutex_exit((vp)->v_interlock)
    392 
    393 #define VATTR_NULL(x) vattr_null(x)
    394 
    395 #define getnewvnode_reserve(x)
    396 #define getnewvnode_drop_reserve()
    397 #define cache_purge_negative(vp) cache_purge(vp)
    398 
    399 #endif	/* _KERNEL */
    400 
    401 #endif	/* _OPENSOLARIS_SYS_VNODE_H_ */
    402