xref: /illumos-gate/usr/src/uts/common/fs/hsfs/hsfs_vnops.c (revision cfa550136d2fd688834f77802d74ab392ec9fa44)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Vnode operations for the High Sierra filesystem
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate #include <sys/time.h>
377c478bd9Sstevel@tonic-gate #include <sys/systm.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <sys/resource.h>
407c478bd9Sstevel@tonic-gate #include <sys/signal.h>
417c478bd9Sstevel@tonic-gate #include <sys/cred.h>
427c478bd9Sstevel@tonic-gate #include <sys/user.h>
437c478bd9Sstevel@tonic-gate #include <sys/buf.h>
447c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
457c478bd9Sstevel@tonic-gate #include <sys/stat.h>
467c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
477c478bd9Sstevel@tonic-gate #include <sys/mode.h>
487c478bd9Sstevel@tonic-gate #include <sys/proc.h>
497c478bd9Sstevel@tonic-gate #include <sys/disp.h>
507c478bd9Sstevel@tonic-gate #include <sys/file.h>
517c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
527c478bd9Sstevel@tonic-gate #include <sys/flock.h>
537c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
547c478bd9Sstevel@tonic-gate #include <sys/uio.h>
557c478bd9Sstevel@tonic-gate #include <sys/conf.h>
567c478bd9Sstevel@tonic-gate #include <sys/errno.h>
577c478bd9Sstevel@tonic-gate #include <sys/mman.h>
587c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
597c478bd9Sstevel@tonic-gate #include <sys/debug.h>
607c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
617c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
627c478bd9Sstevel@tonic-gate #include <sys/fbuf.h>
637c478bd9Sstevel@tonic-gate #include <sys/dirent.h>
647c478bd9Sstevel@tonic-gate #include <sys/errno.h>
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #include <vm/hat.h>
677c478bd9Sstevel@tonic-gate #include <vm/page.h>
687c478bd9Sstevel@tonic-gate #include <vm/pvn.h>
697c478bd9Sstevel@tonic-gate #include <vm/as.h>
707c478bd9Sstevel@tonic-gate #include <vm/seg.h>
717c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
727c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
737c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
747c478bd9Sstevel@tonic-gate #include <vm/rm.h>
757c478bd9Sstevel@tonic-gate #include <vm/page.h>
767c478bd9Sstevel@tonic-gate #include <sys/swap.h>
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
797c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
807c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
817c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
827c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* ARGSUSED */
877c478bd9Sstevel@tonic-gate static int
887c478bd9Sstevel@tonic-gate hsfs_fsync(vnode_t *cp, int syncflag, cred_t *cred)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	return (0);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*ARGSUSED*/
957c478bd9Sstevel@tonic-gate static int
967c478bd9Sstevel@tonic-gate hsfs_read(struct vnode *vp, struct uio *uiop, int ioflag, struct cred *cred,
977c478bd9Sstevel@tonic-gate 	struct caller_context *ct)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
1007c478bd9Sstevel@tonic-gate 	ulong_t off;
1017c478bd9Sstevel@tonic-gate 	long mapon, on;
1027c478bd9Sstevel@tonic-gate 	caddr_t base;
1037c478bd9Sstevel@tonic-gate 	uint_t	filesize;
1047c478bd9Sstevel@tonic-gate 	long nbytes, n;
1057c478bd9Sstevel@tonic-gate 	uint_t flags;
1067c478bd9Sstevel@tonic-gate 	int error;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
1097c478bd9Sstevel@tonic-gate 	/*
1107c478bd9Sstevel@tonic-gate 	 * if vp is of type VDIR, make sure dirent
1117c478bd9Sstevel@tonic-gate 	 * is filled up with all info (because of ptbl)
1127c478bd9Sstevel@tonic-gate 	 */
1137c478bd9Sstevel@tonic-gate 	if (vp->v_type == VDIR) {
1147c478bd9Sstevel@tonic-gate 		if (hp->hs_dirent.ext_size == 0)
1157c478bd9Sstevel@tonic-gate 			hs_filldirent(vp, &hp->hs_dirent);
1167c478bd9Sstevel@tonic-gate 	}
1177c478bd9Sstevel@tonic-gate 	filesize = hp->hs_dirent.ext_size;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	if (uiop->uio_loffset >= MAXOFF_T) {
1207c478bd9Sstevel@tonic-gate 		error = 0;
1217c478bd9Sstevel@tonic-gate 		goto out;
1227c478bd9Sstevel@tonic-gate 	}
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	if (uiop->uio_offset >= filesize) {
1257c478bd9Sstevel@tonic-gate 		error = 0;
1267c478bd9Sstevel@tonic-gate 		goto out;
1277c478bd9Sstevel@tonic-gate 	}
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	do {
1307c478bd9Sstevel@tonic-gate 		/* map file to correct page boundary */
1317c478bd9Sstevel@tonic-gate 		off = uiop->uio_offset & MAXBMASK;
1327c478bd9Sstevel@tonic-gate 		mapon = uiop->uio_offset & MAXBOFFSET;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 		/* set read in data size */
1357c478bd9Sstevel@tonic-gate 		on = (uiop->uio_offset) & PAGEOFFSET;
1367c478bd9Sstevel@tonic-gate 		nbytes = MIN(PAGESIZE - on, uiop->uio_resid);
1377c478bd9Sstevel@tonic-gate 		/* adjust down if > EOF */
1387c478bd9Sstevel@tonic-gate 		n = MIN((filesize - uiop->uio_offset), nbytes);
1397c478bd9Sstevel@tonic-gate 		if (n == 0) {
1407c478bd9Sstevel@tonic-gate 			error = 0;
1417c478bd9Sstevel@tonic-gate 			goto out;
1427c478bd9Sstevel@tonic-gate 		}
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 		/* map the file into memory */
1457c478bd9Sstevel@tonic-gate 		base = segmap_getmapflt(segkmap, vp, (u_offset_t)off,
1467c478bd9Sstevel@tonic-gate 					MAXBSIZE, 1, S_READ);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 		error = uiomove(base+mapon, (size_t)n, UIO_READ, uiop);
1497c478bd9Sstevel@tonic-gate 		if (error == 0) {
1507c478bd9Sstevel@tonic-gate 			/*
1517c478bd9Sstevel@tonic-gate 			 * if read a whole block, or read to eof,
1527c478bd9Sstevel@tonic-gate 			 *  won't need this buffer again soon.
1537c478bd9Sstevel@tonic-gate 			 */
1547c478bd9Sstevel@tonic-gate 			if (n + on == PAGESIZE ||
1557c478bd9Sstevel@tonic-gate 			    uiop->uio_offset == filesize)
1567c478bd9Sstevel@tonic-gate 				flags = SM_DONTNEED;
1577c478bd9Sstevel@tonic-gate 			else
1587c478bd9Sstevel@tonic-gate 				flags = 0;
1597c478bd9Sstevel@tonic-gate 			error = segmap_release(segkmap, base, flags);
1607c478bd9Sstevel@tonic-gate 		} else
1617c478bd9Sstevel@tonic-gate 			(void) segmap_release(segkmap, base, 0);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	} while (error == 0 && uiop->uio_resid > 0);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate out:
1667c478bd9Sstevel@tonic-gate 	return (error);
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
1707c478bd9Sstevel@tonic-gate static int
1717c478bd9Sstevel@tonic-gate hsfs_getattr(
1727c478bd9Sstevel@tonic-gate 	struct vnode *vp,
1737c478bd9Sstevel@tonic-gate 	struct vattr *vap,
1747c478bd9Sstevel@tonic-gate 	int flags,
1757c478bd9Sstevel@tonic-gate 	struct cred *cred)
1767c478bd9Sstevel@tonic-gate {
1777c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
1787c478bd9Sstevel@tonic-gate 	struct vfs *vfsp;
1797c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
1827c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vp->v_vfsp);
1837c478bd9Sstevel@tonic-gate 	vfsp = vp->v_vfsp;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if ((hp->hs_dirent.ext_size == 0) && (vp->v_type == VDIR)) {
1867c478bd9Sstevel@tonic-gate 		hs_filldirent(vp, &hp->hs_dirent);
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 	vap->va_type = IFTOVT(hp->hs_dirent.mode);
1897c478bd9Sstevel@tonic-gate 	vap->va_mode = hp->hs_dirent.mode;
1907c478bd9Sstevel@tonic-gate 	vap->va_uid = hp->hs_dirent.uid;
1917c478bd9Sstevel@tonic-gate 	vap->va_gid = hp->hs_dirent.gid;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	vap->va_fsid = vfsp->vfs_dev;
1947c478bd9Sstevel@tonic-gate 	vap->va_nodeid = (ino64_t)hp->hs_nodeid;
1957c478bd9Sstevel@tonic-gate 	vap->va_nlink = hp->hs_dirent.nlink;
1967c478bd9Sstevel@tonic-gate 	vap->va_size =	(offset_t)hp->hs_dirent.ext_size;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	vap->va_atime.tv_sec = hp->hs_dirent.adate.tv_sec;
1997c478bd9Sstevel@tonic-gate 	vap->va_atime.tv_nsec = hp->hs_dirent.adate.tv_usec*1000;
2007c478bd9Sstevel@tonic-gate 	vap->va_mtime.tv_sec = hp->hs_dirent.mdate.tv_sec;
2017c478bd9Sstevel@tonic-gate 	vap->va_mtime.tv_nsec = hp->hs_dirent.mdate.tv_usec*1000;
2027c478bd9Sstevel@tonic-gate 	vap->va_ctime.tv_sec = hp->hs_dirent.cdate.tv_sec;
2037c478bd9Sstevel@tonic-gate 	vap->va_ctime.tv_nsec = hp->hs_dirent.cdate.tv_usec*1000;
2047c478bd9Sstevel@tonic-gate 	if (vp->v_type == VCHR || vp->v_type == VBLK)
2057c478bd9Sstevel@tonic-gate 		vap->va_rdev = hp->hs_dirent.r_dev;
2067c478bd9Sstevel@tonic-gate 	else
2077c478bd9Sstevel@tonic-gate 		vap->va_rdev = 0;
2087c478bd9Sstevel@tonic-gate 	vap->va_blksize = vfsp->vfs_bsize;
2097c478bd9Sstevel@tonic-gate 	/* no. of blocks = no. of data blocks + no. of xar blocks */
2107c478bd9Sstevel@tonic-gate 	vap->va_nblocks = (fsblkcnt64_t)howmany(vap->va_size + (u_longlong_t)
2117c478bd9Sstevel@tonic-gate 	    (hp->hs_dirent.xar_len << fsp->hsfs_vol.lbn_shift), DEV_BSIZE);
2127c478bd9Sstevel@tonic-gate 	vap->va_seq = hp->hs_seq;
2137c478bd9Sstevel@tonic-gate 	return (0);
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2177c478bd9Sstevel@tonic-gate static int
2187c478bd9Sstevel@tonic-gate hsfs_readlink(struct vnode *vp, struct uio *uiop, struct cred *cred)
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	if (vp->v_type != VLNK)
2237c478bd9Sstevel@tonic-gate 		return (EINVAL);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	if (hp->hs_dirent.sym_link == (char *)NULL)
2287c478bd9Sstevel@tonic-gate 		return (ENOENT);
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	return (uiomove(hp->hs_dirent.sym_link,
2317c478bd9Sstevel@tonic-gate 	    (size_t)MIN(hp->hs_dirent.ext_size,
2327c478bd9Sstevel@tonic-gate 	    uiop->uio_resid), UIO_READ, uiop));
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2367c478bd9Sstevel@tonic-gate static void
2377c478bd9Sstevel@tonic-gate hsfs_inactive(struct vnode *vp, struct cred *cred)
2387c478bd9Sstevel@tonic-gate {
2397c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
2407c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	int nopage;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
2457c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vp->v_vfsp);
2467c478bd9Sstevel@tonic-gate 	/*
2477c478bd9Sstevel@tonic-gate 	 * Note: acquiring and holding v_lock for quite a while
2487c478bd9Sstevel@tonic-gate 	 * here serializes on the vnode; this is unfortunate, but
2497c478bd9Sstevel@tonic-gate 	 * likely not to overly impact performance, as the underlying
2507c478bd9Sstevel@tonic-gate 	 * device (CDROM drive) is quite slow.
2517c478bd9Sstevel@tonic-gate 	 */
2527c478bd9Sstevel@tonic-gate 	rw_enter(&fsp->hsfs_hash_lock, RW_WRITER);
2537c478bd9Sstevel@tonic-gate 	mutex_enter(&hp->hs_contents_lock);
2547c478bd9Sstevel@tonic-gate 	mutex_enter(&vp->v_lock);
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	if (vp->v_count < 1) {
2577c478bd9Sstevel@tonic-gate 		panic("hsfs_inactive: v_count < 1");
2587c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	if (vp->v_count > 1 || (hp->hs_flags & HREF) == 0) {
2627c478bd9Sstevel@tonic-gate 		vp->v_count--;	/* release hold from vn_rele */
2637c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
2647c478bd9Sstevel@tonic-gate 		mutex_exit(&hp->hs_contents_lock);
2657c478bd9Sstevel@tonic-gate 		rw_exit(&fsp->hsfs_hash_lock);
2667c478bd9Sstevel@tonic-gate 		return;
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 	vp->v_count--;	/* release hold from vn_rele */
2697c478bd9Sstevel@tonic-gate 	if (vp->v_count == 0) {
2707c478bd9Sstevel@tonic-gate 		/*
2717c478bd9Sstevel@tonic-gate 		 * Free the hsnode.
2727c478bd9Sstevel@tonic-gate 		 * If there are no pages associated with the
2737c478bd9Sstevel@tonic-gate 		 * hsnode, give it back to the kmem_cache,
2747c478bd9Sstevel@tonic-gate 		 * else put at the end of this file system's
2757c478bd9Sstevel@tonic-gate 		 * internal free list.
2767c478bd9Sstevel@tonic-gate 		 */
2777c478bd9Sstevel@tonic-gate 		nopage = !vn_has_cached_data(vp);
2787c478bd9Sstevel@tonic-gate 		hp->hs_flags = 0;
2797c478bd9Sstevel@tonic-gate 		/*
2807c478bd9Sstevel@tonic-gate 		 * exit these locks now, since hs_freenode may
2817c478bd9Sstevel@tonic-gate 		 * kmem_free the hsnode and embedded vnode
2827c478bd9Sstevel@tonic-gate 		 */
2837c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
2847c478bd9Sstevel@tonic-gate 		mutex_exit(&hp->hs_contents_lock);
2857c478bd9Sstevel@tonic-gate 		hs_freenode(vp, fsp, nopage);
2867c478bd9Sstevel@tonic-gate 	} else {
2877c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
2887c478bd9Sstevel@tonic-gate 		mutex_exit(&hp->hs_contents_lock);
2897c478bd9Sstevel@tonic-gate 	}
2907c478bd9Sstevel@tonic-gate 	rw_exit(&fsp->hsfs_hash_lock);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2957c478bd9Sstevel@tonic-gate static int
2967c478bd9Sstevel@tonic-gate hsfs_lookup(
2977c478bd9Sstevel@tonic-gate 	struct vnode *dvp,
2987c478bd9Sstevel@tonic-gate 	char *nm,
2997c478bd9Sstevel@tonic-gate 	struct vnode **vpp,
3007c478bd9Sstevel@tonic-gate 	struct pathname *pnp,
3017c478bd9Sstevel@tonic-gate 	int flags,
3027c478bd9Sstevel@tonic-gate 	struct vnode *rdir,
3037c478bd9Sstevel@tonic-gate 	struct cred *cred)
3047c478bd9Sstevel@tonic-gate {
3057c478bd9Sstevel@tonic-gate 	int error;
3067c478bd9Sstevel@tonic-gate 	int namelen = (int)strlen(nm);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	if (*nm == '\0') {
3097c478bd9Sstevel@tonic-gate 		VN_HOLD(dvp);
3107c478bd9Sstevel@tonic-gate 		*vpp = dvp;
3117c478bd9Sstevel@tonic-gate 		return (0);
3127c478bd9Sstevel@tonic-gate 	}
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	/*
3157c478bd9Sstevel@tonic-gate 	 * If we're looking for ourself, life is simple.
3167c478bd9Sstevel@tonic-gate 	 */
3177c478bd9Sstevel@tonic-gate 	if (namelen == 1 && *nm == '.') {
3187c478bd9Sstevel@tonic-gate 		if (error = hs_access(dvp, (mode_t)VEXEC, cred))
3197c478bd9Sstevel@tonic-gate 			return (error);
3207c478bd9Sstevel@tonic-gate 		VN_HOLD(dvp);
3217c478bd9Sstevel@tonic-gate 		*vpp = dvp;
3227c478bd9Sstevel@tonic-gate 		return (0);
3237c478bd9Sstevel@tonic-gate 	}
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	return (hs_dirlook(dvp, nm, namelen, vpp, cred));
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3307c478bd9Sstevel@tonic-gate static int
3317c478bd9Sstevel@tonic-gate hsfs_readdir(
3327c478bd9Sstevel@tonic-gate 	struct vnode	*vp,
3337c478bd9Sstevel@tonic-gate 	struct uio	*uiop,
3347c478bd9Sstevel@tonic-gate 	struct cred	*cred,
3357c478bd9Sstevel@tonic-gate 	int		*eofp)
3367c478bd9Sstevel@tonic-gate {
3377c478bd9Sstevel@tonic-gate 	struct hsnode	*dhp;
3387c478bd9Sstevel@tonic-gate 	struct hsfs	*fsp;
3397c478bd9Sstevel@tonic-gate 	struct hs_direntry hd;
3407c478bd9Sstevel@tonic-gate 	struct dirent64	*nd;
3417c478bd9Sstevel@tonic-gate 	int		error;
3427c478bd9Sstevel@tonic-gate 	uint_t		offset;		/* real offset in directory */
3437c478bd9Sstevel@tonic-gate 	uint_t		dirsiz;		/* real size of directory */
3447c478bd9Sstevel@tonic-gate 	uchar_t		*blkp;
3457c478bd9Sstevel@tonic-gate 	int		hdlen;		/* length of hs directory entry */
3467c478bd9Sstevel@tonic-gate 	long		ndlen;		/* length of dirent entry */
3477c478bd9Sstevel@tonic-gate 	int		bytes_wanted;
3487c478bd9Sstevel@tonic-gate 	size_t		bufsize;	/* size of dirent buffer */
3497c478bd9Sstevel@tonic-gate 	char		*outbuf;	/* ptr to dirent buffer */
3507c478bd9Sstevel@tonic-gate 	char		*dname;
3517c478bd9Sstevel@tonic-gate 	int		dnamelen;
3527c478bd9Sstevel@tonic-gate 	size_t		dname_size;
3537c478bd9Sstevel@tonic-gate 	struct fbuf	*fbp;
3547c478bd9Sstevel@tonic-gate 	uint_t		last_offset;	/* last index into current dir block */
3557c478bd9Sstevel@tonic-gate 	ulong_t		dir_lbn;	/* lbn of directory */
3567c478bd9Sstevel@tonic-gate 	ino64_t		dirino;	/* temporary storage before storing in dirent */
3577c478bd9Sstevel@tonic-gate 	off_t		diroff;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	dhp = VTOH(vp);
3607c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vp->v_vfsp);
3617c478bd9Sstevel@tonic-gate 	if (dhp->hs_dirent.ext_size == 0)
3627c478bd9Sstevel@tonic-gate 		hs_filldirent(vp, &dhp->hs_dirent);
3637c478bd9Sstevel@tonic-gate 	dirsiz = dhp->hs_dirent.ext_size;
3647c478bd9Sstevel@tonic-gate 	dir_lbn = dhp->hs_dirent.ext_lbn;
3657c478bd9Sstevel@tonic-gate 	if (uiop->uio_loffset >= dirsiz) {	/* at or beyond EOF */
3667c478bd9Sstevel@tonic-gate 		if (eofp)
3677c478bd9Sstevel@tonic-gate 			*eofp = 1;
3687c478bd9Sstevel@tonic-gate 		return (0);
3697c478bd9Sstevel@tonic-gate 	}
3707c478bd9Sstevel@tonic-gate 	ASSERT(uiop->uio_loffset <= MAXOFF_T);
3717c478bd9Sstevel@tonic-gate 	offset = (uint_t)uiop->uio_offset;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	dname_size = fsp->hsfs_namemax + 1;	/* 1 for the ending NUL */
3747c478bd9Sstevel@tonic-gate 	dname = kmem_alloc(dname_size, KM_SLEEP);
3757c478bd9Sstevel@tonic-gate 	bufsize = uiop->uio_resid + sizeof (struct dirent64);
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	outbuf = kmem_alloc(bufsize, KM_SLEEP);
3787c478bd9Sstevel@tonic-gate 	nd = (struct dirent64 *)outbuf;
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	while (offset < dirsiz) {
3817c478bd9Sstevel@tonic-gate 		if ((offset & MAXBMASK) + MAXBSIZE > dirsiz)
3827c478bd9Sstevel@tonic-gate 			bytes_wanted = dirsiz - (offset & MAXBMASK);
3837c478bd9Sstevel@tonic-gate 		else
3847c478bd9Sstevel@tonic-gate 			bytes_wanted = MAXBSIZE;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 		error = fbread(vp, (offset_t)(offset & MAXBMASK),
3877c478bd9Sstevel@tonic-gate 			(unsigned int)bytes_wanted, S_READ, &fbp);
3887c478bd9Sstevel@tonic-gate 		if (error)
3897c478bd9Sstevel@tonic-gate 			goto done;
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 		blkp = (uchar_t *)fbp->fb_addr;
3927c478bd9Sstevel@tonic-gate 		last_offset = (offset & MAXBMASK) + fbp->fb_count - 1;
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate #define	rel_offset(offset) ((offset) & MAXBOFFSET)	/* index into blkp */
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 		while (offset < last_offset) {
3977c478bd9Sstevel@tonic-gate 			/*
3987c478bd9Sstevel@tonic-gate 			 * Directory Entries cannot span sectors.
3997c478bd9Sstevel@tonic-gate 			 * Unused bytes at the end of each sector are zeroed.
4007c478bd9Sstevel@tonic-gate 			 * Therefore, detect this condition when the size
4017c478bd9Sstevel@tonic-gate 			 * field of the directory entry is zero.
4027c478bd9Sstevel@tonic-gate 			 */
4037c478bd9Sstevel@tonic-gate 			hdlen = (int)((uchar_t)
4047c478bd9Sstevel@tonic-gate 				HDE_DIR_LEN(&blkp[rel_offset(offset)]));
4057c478bd9Sstevel@tonic-gate 			if (hdlen == 0) {
4067c478bd9Sstevel@tonic-gate 				/* advance to next sector boundary */
4077c478bd9Sstevel@tonic-gate 				offset = (offset & MAXHSMASK) + HS_SECTOR_SIZE;
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 				/*
4107c478bd9Sstevel@tonic-gate 				 * Have we reached the end of current block?
4117c478bd9Sstevel@tonic-gate 				 */
4127c478bd9Sstevel@tonic-gate 				if (offset > last_offset)
4137c478bd9Sstevel@tonic-gate 					break;
4147c478bd9Sstevel@tonic-gate 				else
4157c478bd9Sstevel@tonic-gate 					continue;
4167c478bd9Sstevel@tonic-gate 			}
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 			/* make sure this is nullified before  reading it */
4197c478bd9Sstevel@tonic-gate 			bzero(&hd, sizeof (hd));
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 			/*
4227c478bd9Sstevel@tonic-gate 			 * Just ignore invalid directory entries.
4237c478bd9Sstevel@tonic-gate 			 * XXX - maybe hs_parsedir() will detect EXISTENCE bit
4247c478bd9Sstevel@tonic-gate 			 */
4257c478bd9Sstevel@tonic-gate 			if (!hs_parsedir(fsp, &blkp[rel_offset(offset)],
4267c478bd9Sstevel@tonic-gate 				&hd, dname, &dnamelen)) {
4277c478bd9Sstevel@tonic-gate 				/*
4287c478bd9Sstevel@tonic-gate 				 * Determine if there is enough room
4297c478bd9Sstevel@tonic-gate 				 */
4307c478bd9Sstevel@tonic-gate 				ndlen = (long)DIRENT64_RECLEN((dnamelen));
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 				if ((ndlen + ((char *)nd - outbuf)) >
4337c478bd9Sstevel@tonic-gate 				    uiop->uio_resid) {
4347c478bd9Sstevel@tonic-gate 					fbrelse(fbp, S_READ);
4357c478bd9Sstevel@tonic-gate 					goto done; /* output buffer full */
4367c478bd9Sstevel@tonic-gate 				}
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 				diroff = offset + hdlen;
4397c478bd9Sstevel@tonic-gate 				/*
4407c478bd9Sstevel@tonic-gate 				 * Generate nodeid.
4417c478bd9Sstevel@tonic-gate 				 * If a directory, nodeid points to the
4427c478bd9Sstevel@tonic-gate 				 * canonical dirent describing the directory:
4437c478bd9Sstevel@tonic-gate 				 * the dirent of the "." entry for the
4447c478bd9Sstevel@tonic-gate 				 * directory, which is pointed to by all
4457c478bd9Sstevel@tonic-gate 				 * dirents for that directory.
4467c478bd9Sstevel@tonic-gate 				 * Otherwise, nodeid points to dirent of file.
4477c478bd9Sstevel@tonic-gate 				 */
4487c478bd9Sstevel@tonic-gate 				if (hd.type == VDIR) {
4497c478bd9Sstevel@tonic-gate 					dirino = (ino64_t)
4507c478bd9Sstevel@tonic-gate 					    MAKE_NODEID(hd.ext_lbn, 0,
4517c478bd9Sstevel@tonic-gate 					    vp->v_vfsp);
4527c478bd9Sstevel@tonic-gate 				} else {
4537c478bd9Sstevel@tonic-gate 					struct hs_volume *hvp;
4547c478bd9Sstevel@tonic-gate 					offset_t lbn, off;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 					/*
4577c478bd9Sstevel@tonic-gate 					 * Normalize lbn and off
4587c478bd9Sstevel@tonic-gate 					 */
4597c478bd9Sstevel@tonic-gate 					hvp = &fsp->hsfs_vol;
4607c478bd9Sstevel@tonic-gate 					lbn = dir_lbn +
4617c478bd9Sstevel@tonic-gate 					    (offset >> hvp->lbn_shift);
4627c478bd9Sstevel@tonic-gate 					off = offset & hvp->lbn_maxoffset;
4637c478bd9Sstevel@tonic-gate 					dirino = (ino64_t)MAKE_NODEID(lbn,
4647c478bd9Sstevel@tonic-gate 					    off, vp->v_vfsp);
4657c478bd9Sstevel@tonic-gate 				}
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 				/* strncpy(9f) will zero uninitialized bytes */
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 				ASSERT(strlen(dname) + 1 <=
4717c478bd9Sstevel@tonic-gate 				    DIRENT64_NAMELEN(ndlen));
4727c478bd9Sstevel@tonic-gate 				(void) strncpy(nd->d_name, dname,
4737c478bd9Sstevel@tonic-gate 				    DIRENT64_NAMELEN(ndlen));
4747c478bd9Sstevel@tonic-gate 				nd->d_reclen = (ushort_t)ndlen;
4757c478bd9Sstevel@tonic-gate 				nd->d_off = (offset_t)diroff;
4767c478bd9Sstevel@tonic-gate 				nd->d_ino = dirino;
4777c478bd9Sstevel@tonic-gate 				nd = (struct dirent64 *)((char *)nd + ndlen);
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 				/*
4807c478bd9Sstevel@tonic-gate 				 * free up space allocated for symlink
4817c478bd9Sstevel@tonic-gate 				 */
4827c478bd9Sstevel@tonic-gate 				if (hd.sym_link != (char *)NULL) {
4837c478bd9Sstevel@tonic-gate 					kmem_free(hd.sym_link,
4847c478bd9Sstevel@tonic-gate 					    (size_t)(hd.ext_size+1));
4857c478bd9Sstevel@tonic-gate 					hd.sym_link = (char *)NULL;
4867c478bd9Sstevel@tonic-gate 				}
4877c478bd9Sstevel@tonic-gate 			}
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 			offset += hdlen;
4907c478bd9Sstevel@tonic-gate 		}
4917c478bd9Sstevel@tonic-gate 		fbrelse(fbp, S_READ);
4927c478bd9Sstevel@tonic-gate 	}
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	/*
4957c478bd9Sstevel@tonic-gate 	 * Got here for one of the following reasons:
4967c478bd9Sstevel@tonic-gate 	 *	1) outbuf is full (error == 0)
4977c478bd9Sstevel@tonic-gate 	 *	2) end of directory reached (error == 0)
4987c478bd9Sstevel@tonic-gate 	 *	3) error reading directory sector (error != 0)
4997c478bd9Sstevel@tonic-gate 	 *	4) directory entry crosses sector boundary (error == 0)
5007c478bd9Sstevel@tonic-gate 	 *
5017c478bd9Sstevel@tonic-gate 	 * If any directory entries have been copied, don't report
5027c478bd9Sstevel@tonic-gate 	 * case 4.  Instead, return the valid directory entries.
5037c478bd9Sstevel@tonic-gate 	 *
5047c478bd9Sstevel@tonic-gate 	 * If no entries have been copied, report the error.
5057c478bd9Sstevel@tonic-gate 	 * If case 4, this will be indistiguishable from EOF.
5067c478bd9Sstevel@tonic-gate 	 */
5077c478bd9Sstevel@tonic-gate done:
5087c478bd9Sstevel@tonic-gate 	ndlen = ((char *)nd - outbuf);
5097c478bd9Sstevel@tonic-gate 	if (ndlen != 0) {
5107c478bd9Sstevel@tonic-gate 		error = uiomove(outbuf, (size_t)ndlen, UIO_READ, uiop);
5117c478bd9Sstevel@tonic-gate 		uiop->uio_offset = offset;
5127c478bd9Sstevel@tonic-gate 	}
5137c478bd9Sstevel@tonic-gate 	kmem_free(dname, dname_size);
5147c478bd9Sstevel@tonic-gate 	kmem_free(outbuf, bufsize);
5157c478bd9Sstevel@tonic-gate 	if (eofp && error == 0)
5167c478bd9Sstevel@tonic-gate 		*eofp = (uiop->uio_offset >= dirsiz);
5177c478bd9Sstevel@tonic-gate 	return (error);
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate static int
5217c478bd9Sstevel@tonic-gate hsfs_fid(struct vnode *vp, struct fid *fidp)
5227c478bd9Sstevel@tonic-gate {
5237c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
5247c478bd9Sstevel@tonic-gate 	struct hsfid *fid;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	if (fidp->fid_len < (sizeof (*fid) - sizeof (fid->hf_len))) {
5277c478bd9Sstevel@tonic-gate 		fidp->fid_len = sizeof (*fid) - sizeof (fid->hf_len);
5287c478bd9Sstevel@tonic-gate 		return (ENOSPC);
5297c478bd9Sstevel@tonic-gate 	}
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	fid = (struct hsfid *)fidp;
5327c478bd9Sstevel@tonic-gate 	fid->hf_len = sizeof (*fid) - sizeof (fid->hf_len);
5337c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
5347c478bd9Sstevel@tonic-gate 	mutex_enter(&hp->hs_contents_lock);
5357c478bd9Sstevel@tonic-gate 	fid->hf_dir_lbn = hp->hs_dir_lbn;
5367c478bd9Sstevel@tonic-gate 	fid->hf_dir_off = (ushort_t)hp->hs_dir_off;
5377c478bd9Sstevel@tonic-gate 	mutex_exit(&hp->hs_contents_lock);
5387c478bd9Sstevel@tonic-gate 	return (0);
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5427c478bd9Sstevel@tonic-gate static int
5437c478bd9Sstevel@tonic-gate hsfs_open(struct vnode **vpp, int flag, struct cred *cred)
5447c478bd9Sstevel@tonic-gate {
5457c478bd9Sstevel@tonic-gate 	return (0);
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5497c478bd9Sstevel@tonic-gate static int
5507c478bd9Sstevel@tonic-gate hsfs_close(
5517c478bd9Sstevel@tonic-gate 	struct vnode *vp,
5527c478bd9Sstevel@tonic-gate 	int flag,
5537c478bd9Sstevel@tonic-gate 	int count,
5547c478bd9Sstevel@tonic-gate 	offset_t offset,
5557c478bd9Sstevel@tonic-gate 	struct cred *cred)
5567c478bd9Sstevel@tonic-gate {
5577c478bd9Sstevel@tonic-gate 	(void) cleanlocks(vp, ttoproc(curthread)->p_pid, 0);
5587c478bd9Sstevel@tonic-gate 	cleanshares(vp, ttoproc(curthread)->p_pid);
5597c478bd9Sstevel@tonic-gate 	return (0);
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
5637c478bd9Sstevel@tonic-gate static int
5647c478bd9Sstevel@tonic-gate hsfs_access(struct vnode *vp, int mode, int flags, cred_t *cred)
5657c478bd9Sstevel@tonic-gate {
5667c478bd9Sstevel@tonic-gate 	return (hs_access(vp, (mode_t)mode, cred));
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate /*
5707c478bd9Sstevel@tonic-gate  * the seek time of a CD-ROM is very slow, and data transfer
5717c478bd9Sstevel@tonic-gate  * rate is even worse (max. 150K per sec).  The design
5727c478bd9Sstevel@tonic-gate  * decision is to reduce access to cd-rom as much as possible,
5737c478bd9Sstevel@tonic-gate  * and to transfer a sizable block (read-ahead) of data at a time.
5747c478bd9Sstevel@tonic-gate  * UFS style of read ahead one block at a time is not appropriate,
5757c478bd9Sstevel@tonic-gate  * and is not supported
5767c478bd9Sstevel@tonic-gate  */
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate  * KLUSTSIZE should be a multiple of PAGESIZE and <= MAXPHYS.
5807c478bd9Sstevel@tonic-gate  */
5817c478bd9Sstevel@tonic-gate #define	KLUSTSIZE	(56 * 1024)
5827c478bd9Sstevel@tonic-gate /* we don't support read ahead */
5837c478bd9Sstevel@tonic-gate int hsfs_lostpage;	/* no. of times we lost original page */
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate /*
5867c478bd9Sstevel@tonic-gate  * Used to prevent biodone() from releasing buf resources that
5877c478bd9Sstevel@tonic-gate  * we didn't allocate in quite the usual way.
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5907c478bd9Sstevel@tonic-gate int
5917c478bd9Sstevel@tonic-gate hsfs_iodone(struct buf *bp)
5927c478bd9Sstevel@tonic-gate {
5937c478bd9Sstevel@tonic-gate 	sema_v(&bp->b_io);
5947c478bd9Sstevel@tonic-gate 	return (0);
5957c478bd9Sstevel@tonic-gate }
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate /*
5987c478bd9Sstevel@tonic-gate  * Each file may have a different interleaving on disk.  This makes
5997c478bd9Sstevel@tonic-gate  * things somewhat interesting.  The gist is that there are some
6007c478bd9Sstevel@tonic-gate  * number of contiguous data sectors, followed by some other number
6017c478bd9Sstevel@tonic-gate  * of contiguous skip sectors.  The sum of those two sets of sectors
6027c478bd9Sstevel@tonic-gate  * defines the interleave size.  Unfortunately, it means that we generally
6037c478bd9Sstevel@tonic-gate  * can't simply read N sectors starting at a given offset to satisfy
6047c478bd9Sstevel@tonic-gate  * any given request.
6057c478bd9Sstevel@tonic-gate  *
6067c478bd9Sstevel@tonic-gate  * What we do is get the relevant memory pages via pvn_read_kluster(),
6077c478bd9Sstevel@tonic-gate  * then stride through the interleaves, setting up a buf for each
6087c478bd9Sstevel@tonic-gate  * sector that needs to be brought in.  Instead of kmem_alloc'ing
6097c478bd9Sstevel@tonic-gate  * space for the sectors, though, we just point at the appropriate
6107c478bd9Sstevel@tonic-gate  * spot in the relevant page for each of them.  This saves us a bunch
6117c478bd9Sstevel@tonic-gate  * of copying.
6127c478bd9Sstevel@tonic-gate  */
6137c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6147c478bd9Sstevel@tonic-gate static int
6157c478bd9Sstevel@tonic-gate hsfs_getapage(
6167c478bd9Sstevel@tonic-gate 	struct vnode *vp,
6177c478bd9Sstevel@tonic-gate 	u_offset_t off,
6187c478bd9Sstevel@tonic-gate 	size_t len,
6197c478bd9Sstevel@tonic-gate 	uint_t *protp,
6207c478bd9Sstevel@tonic-gate 	struct page *pl[],
6217c478bd9Sstevel@tonic-gate 	size_t plsz,
6227c478bd9Sstevel@tonic-gate 	struct seg *seg,
6237c478bd9Sstevel@tonic-gate 	caddr_t addr,
6247c478bd9Sstevel@tonic-gate 	enum seg_rw rw,
6257c478bd9Sstevel@tonic-gate 	struct cred *cred)
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
6287c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
6297c478bd9Sstevel@tonic-gate 	int	err;
6307c478bd9Sstevel@tonic-gate 	struct buf *bufs;
6317c478bd9Sstevel@tonic-gate 	caddr_t *vas;
6327c478bd9Sstevel@tonic-gate 	caddr_t va;
6337c478bd9Sstevel@tonic-gate 	struct page *pp, *searchp, *lastp;
6347c478bd9Sstevel@tonic-gate 	page_t	*pagefound;
6357c478bd9Sstevel@tonic-gate 	offset_t	bof;
6367c478bd9Sstevel@tonic-gate 	struct vnode *devvp;
6377c478bd9Sstevel@tonic-gate 	ulong_t	byte_offset;
6387c478bd9Sstevel@tonic-gate 	size_t	io_len_tmp;
6397c478bd9Sstevel@tonic-gate 	uint_t	io_off, io_len;
6407c478bd9Sstevel@tonic-gate 	uint_t	xlen;
6417c478bd9Sstevel@tonic-gate 	uint_t	filsiz;
6427c478bd9Sstevel@tonic-gate 	uint_t	secsize;
6437c478bd9Sstevel@tonic-gate 	uint_t	bufcnt;
6447c478bd9Sstevel@tonic-gate 	uint_t	bufsused;
6457c478bd9Sstevel@tonic-gate 	uint_t	count;
6467c478bd9Sstevel@tonic-gate 	uint_t	io_end;
6477c478bd9Sstevel@tonic-gate 	uint_t	which_chunk_lbn;
6487c478bd9Sstevel@tonic-gate 	uint_t	offset_lbn;
6497c478bd9Sstevel@tonic-gate 	uint_t	offset_extra;
6507c478bd9Sstevel@tonic-gate 	offset_t	offset_bytes;
6517c478bd9Sstevel@tonic-gate 	uint_t	remaining_bytes;
6527c478bd9Sstevel@tonic-gate 	uint_t	extension;
6537c478bd9Sstevel@tonic-gate 	int	remainder;	/* must be signed */
6547c478bd9Sstevel@tonic-gate 	int	chunk_lbn_count;
6557c478bd9Sstevel@tonic-gate 	int	chunk_data_bytes;
6567c478bd9Sstevel@tonic-gate 	int	xarsiz;
6577c478bd9Sstevel@tonic-gate 	diskaddr_t driver_block;
6587c478bd9Sstevel@tonic-gate 	u_offset_t io_off_tmp;
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	/*
6617c478bd9Sstevel@tonic-gate 	 * We don't support asynchronous operation at the moment, so
6627c478bd9Sstevel@tonic-gate 	 * just pretend we did it.  If the pages are ever actually
6637c478bd9Sstevel@tonic-gate 	 * needed, they'll get brought in then.
6647c478bd9Sstevel@tonic-gate 	 */
6657c478bd9Sstevel@tonic-gate 	if (pl == NULL)
6667c478bd9Sstevel@tonic-gate 		return (0);
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
6697c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vp->v_vfsp);
6707c478bd9Sstevel@tonic-gate 	devvp = fsp->hsfs_devvp;
6717c478bd9Sstevel@tonic-gate 	secsize = fsp->hsfs_vol.lbn_size;  /* bytes per logical block */
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	/* file data size */
6747c478bd9Sstevel@tonic-gate 	filsiz = hp->hs_dirent.ext_size;
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	/* disk addr for start of file */
6777c478bd9Sstevel@tonic-gate 	bof = LBN_TO_BYTE((offset_t)hp->hs_dirent.ext_lbn, vp->v_vfsp);
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	/* xarsiz byte must be skipped for data */
6807c478bd9Sstevel@tonic-gate 	xarsiz = hp->hs_dirent.xar_len << fsp->hsfs_vol.lbn_shift;
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 	/* how many logical blocks in an interleave (data+skip) */
6837c478bd9Sstevel@tonic-gate 	chunk_lbn_count = hp->hs_dirent.intlf_sz + hp->hs_dirent.intlf_sk;
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	if (chunk_lbn_count == 0) {
6867c478bd9Sstevel@tonic-gate 		chunk_lbn_count = 1;
6877c478bd9Sstevel@tonic-gate 	}
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	/*
6907c478bd9Sstevel@tonic-gate 	 * Convert interleaving size into bytes.  The zero case
6917c478bd9Sstevel@tonic-gate 	 * (no interleaving) optimization is handled as a side-
6927c478bd9Sstevel@tonic-gate 	 * effect of the read-ahead logic.
6937c478bd9Sstevel@tonic-gate 	 */
6947c478bd9Sstevel@tonic-gate 	if (hp->hs_dirent.intlf_sz == 0) {
6957c478bd9Sstevel@tonic-gate 		chunk_data_bytes = LBN_TO_BYTE(1, vp->v_vfsp);
6967c478bd9Sstevel@tonic-gate 	} else {
6977c478bd9Sstevel@tonic-gate 		chunk_data_bytes = LBN_TO_BYTE(hp->hs_dirent.intlf_sz,
6987c478bd9Sstevel@tonic-gate 			vp->v_vfsp);
6997c478bd9Sstevel@tonic-gate 	}
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate reread:
7027c478bd9Sstevel@tonic-gate 	err = 0;
7037c478bd9Sstevel@tonic-gate 	pagefound = 0;
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	/*
7067c478bd9Sstevel@tonic-gate 	 * Do some read-ahead.  This mostly saves us a bit of
7077c478bd9Sstevel@tonic-gate 	 * system cpu time more than anything else when doing
7087c478bd9Sstevel@tonic-gate 	 * sequential reads.  At some point, could do the
7097c478bd9Sstevel@tonic-gate 	 * read-ahead asynchronously which might gain us something
7107c478bd9Sstevel@tonic-gate 	 * on wall time, but it seems unlikely....
7117c478bd9Sstevel@tonic-gate 	 *
7127c478bd9Sstevel@tonic-gate 	 * We do the easy case here, which is to read through
7137c478bd9Sstevel@tonic-gate 	 * the end of the chunk, minus whatever's at the end that
7147c478bd9Sstevel@tonic-gate 	 * won't exactly fill a page.
7157c478bd9Sstevel@tonic-gate 	 */
7167c478bd9Sstevel@tonic-gate 	which_chunk_lbn = (off + len) / chunk_data_bytes;
7177c478bd9Sstevel@tonic-gate 	extension = ((which_chunk_lbn + 1) * chunk_data_bytes) - off;
7187c478bd9Sstevel@tonic-gate 	extension -= (extension % PAGESIZE);
7197c478bd9Sstevel@tonic-gate 	if (extension != 0 && extension < filsiz - off) {
7207c478bd9Sstevel@tonic-gate 		len = extension;
7217c478bd9Sstevel@tonic-gate 	}
7227c478bd9Sstevel@tonic-gate 	/*
7237c478bd9Sstevel@tonic-gate 	 * Some cd writers don't write sectors that aren't used.  Also,
7247c478bd9Sstevel@tonic-gate 	 * there's no point in reading sectors we'll never look at.  So,
7257c478bd9Sstevel@tonic-gate 	 * if we're asked to go beyond the end of a file, truncate to the
7267c478bd9Sstevel@tonic-gate 	 * length of that file.
7277c478bd9Sstevel@tonic-gate 	 *
7287c478bd9Sstevel@tonic-gate 	 * Additionally, this behaviour is required by section 6.4.5 of
7297c478bd9Sstevel@tonic-gate 	 * ISO 9660:1988(E).
7307c478bd9Sstevel@tonic-gate 	 */
7317c478bd9Sstevel@tonic-gate 	if (len > (filsiz - off)) {
7327c478bd9Sstevel@tonic-gate 		len = filsiz - off;
7337c478bd9Sstevel@tonic-gate 	}
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 	/*
7367c478bd9Sstevel@tonic-gate 	 * After all that, make sure we're asking for things in units
7377c478bd9Sstevel@tonic-gate 	 * that bdev_strategy() will understand (see bug 4202551).
7387c478bd9Sstevel@tonic-gate 	 */
7397c478bd9Sstevel@tonic-gate 	len = roundup(len, DEV_BSIZE);
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate 	pp = NULL;
7427c478bd9Sstevel@tonic-gate again:
7437c478bd9Sstevel@tonic-gate 	/* search for page in buffer */
7447c478bd9Sstevel@tonic-gate 	if ((pagefound = page_exists(vp, off)) == 0) {
7457c478bd9Sstevel@tonic-gate 		/*
7467c478bd9Sstevel@tonic-gate 		 * Need to really do disk IO to get the page.
7477c478bd9Sstevel@tonic-gate 		 */
7487c478bd9Sstevel@tonic-gate 		pp = pvn_read_kluster(vp, off, seg, addr, &io_off_tmp,
7497c478bd9Sstevel@tonic-gate 		    &io_len_tmp, off, len, 0);
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 		if (pp == NULL)
7527c478bd9Sstevel@tonic-gate 			goto again;
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 		io_off = (uint_t)io_off_tmp;
7557c478bd9Sstevel@tonic-gate 		io_len = (uint_t)io_len_tmp;
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 		/* check for truncation */
7587c478bd9Sstevel@tonic-gate 		/*
7597c478bd9Sstevel@tonic-gate 		 * xxx Clean up and return EIO instead?
7607c478bd9Sstevel@tonic-gate 		 * xxx Ought to go to u_offset_t for everything, but we
7617c478bd9Sstevel@tonic-gate 		 * xxx call lots of things that want uint_t arguments.
7627c478bd9Sstevel@tonic-gate 		 */
7637c478bd9Sstevel@tonic-gate 		ASSERT(io_off == io_off_tmp);
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 		/*
7667c478bd9Sstevel@tonic-gate 		 * get enough buffers for worst-case scenario
7677c478bd9Sstevel@tonic-gate 		 * (i.e., no coalescing possible).
7687c478bd9Sstevel@tonic-gate 		 */
7697c478bd9Sstevel@tonic-gate 		bufcnt = (len + secsize - 1) / secsize;
7707c478bd9Sstevel@tonic-gate 		bufs = kmem_zalloc(bufcnt * sizeof (struct buf), KM_SLEEP);
7717c478bd9Sstevel@tonic-gate 		vas = kmem_alloc(bufcnt * sizeof (caddr_t), KM_SLEEP);
7727c478bd9Sstevel@tonic-gate 		for (count = 0; count < bufcnt; count++) {
7737c478bd9Sstevel@tonic-gate 			bufs[count].b_edev = devvp->v_rdev;
7747c478bd9Sstevel@tonic-gate 			bufs[count].b_dev = cmpdev(devvp->v_rdev);
7757c478bd9Sstevel@tonic-gate 			bufs[count].b_flags = B_NOCACHE|B_BUSY|B_READ;
7767c478bd9Sstevel@tonic-gate 			bufs[count].b_iodone = hsfs_iodone;
7777c478bd9Sstevel@tonic-gate 			bufs[count].b_vp = vp;
7787c478bd9Sstevel@tonic-gate 			bufs[count].b_file = vp;
7797c478bd9Sstevel@tonic-gate 			sema_init(&bufs[count].b_io, 0, NULL,
7807c478bd9Sstevel@tonic-gate 			    SEMA_DEFAULT, NULL);
7817c478bd9Sstevel@tonic-gate 			sema_init(&bufs[count].b_sem, 0, NULL,
7827c478bd9Sstevel@tonic-gate 			    SEMA_DEFAULT, NULL);
7837c478bd9Sstevel@tonic-gate 		}
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 		/* zero not-to-be-read page parts */
7867c478bd9Sstevel@tonic-gate 		xlen = io_len & PAGEOFFSET;
7877c478bd9Sstevel@tonic-gate 		if (xlen != 0)
7887c478bd9Sstevel@tonic-gate 			pagezero(pp->p_prev, xlen, PAGESIZE - xlen);
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 		va = NULL;
7917c478bd9Sstevel@tonic-gate 		lastp = NULL;
7927c478bd9Sstevel@tonic-gate 		searchp = pp;
7937c478bd9Sstevel@tonic-gate 		io_end = io_off + io_len;
7947c478bd9Sstevel@tonic-gate 		for (count = 0, byte_offset = io_off;
7957c478bd9Sstevel@tonic-gate 			byte_offset < io_end;
7967c478bd9Sstevel@tonic-gate 			count++) {
7977c478bd9Sstevel@tonic-gate 			ASSERT(count < bufcnt);
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 			/* Compute disk address for interleaving. */
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 			/* considered without skips */
8027c478bd9Sstevel@tonic-gate 			which_chunk_lbn = byte_offset / chunk_data_bytes;
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 			/* factor in skips */
8057c478bd9Sstevel@tonic-gate 			offset_lbn = which_chunk_lbn * chunk_lbn_count;
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate 			/* convert to physical byte offset for lbn */
8087c478bd9Sstevel@tonic-gate 			offset_bytes = LBN_TO_BYTE(offset_lbn, vp->v_vfsp);
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 			/* don't forget offset into lbn */
8117c478bd9Sstevel@tonic-gate 			offset_extra = byte_offset % chunk_data_bytes;
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 			/* get virtual block number for driver */
8147c478bd9Sstevel@tonic-gate 			driver_block = lbtodb(bof + xarsiz
8157c478bd9Sstevel@tonic-gate 				+ offset_bytes + offset_extra);
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 			if (lastp != searchp) {
8187c478bd9Sstevel@tonic-gate 				/* this branch taken first time through loop */
8197c478bd9Sstevel@tonic-gate 				va = vas[count]
8207c478bd9Sstevel@tonic-gate 					= ppmapin(searchp, PROT_WRITE,
8217c478bd9Sstevel@tonic-gate 						(caddr_t)-1);
8227c478bd9Sstevel@tonic-gate 				/* ppmapin() guarantees not to return NULL */
8237c478bd9Sstevel@tonic-gate 			} else {
8247c478bd9Sstevel@tonic-gate 				vas[count] = NULL;
8257c478bd9Sstevel@tonic-gate 			}
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 			bufs[count].b_un.b_addr = va + byte_offset % PAGESIZE;
8287c478bd9Sstevel@tonic-gate 			bufs[count].b_offset =
8297c478bd9Sstevel@tonic-gate 			    (offset_t)(byte_offset - io_off + off);
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 			/*
8327c478bd9Sstevel@tonic-gate 			 * We specifically use the b_lblkno member here
8337c478bd9Sstevel@tonic-gate 			 * as even in the 32 bit world driver_block can
8347c478bd9Sstevel@tonic-gate 			 * get very large in line with the ISO9660 spec.
8357c478bd9Sstevel@tonic-gate 			 */
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 			bufs[count].b_lblkno = driver_block;
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 			remaining_bytes = ((which_chunk_lbn + 1)
8407c478bd9Sstevel@tonic-gate 				* chunk_data_bytes)
8417c478bd9Sstevel@tonic-gate 				- byte_offset;
8427c478bd9Sstevel@tonic-gate 
8437c478bd9Sstevel@tonic-gate 			/*
8447c478bd9Sstevel@tonic-gate 			 * remaining_bytes can't be zero, as we derived
8457c478bd9Sstevel@tonic-gate 			 * which_chunk_lbn directly from byte_offset.
8467c478bd9Sstevel@tonic-gate 			 */
8477c478bd9Sstevel@tonic-gate 			if ((remaining_bytes+byte_offset) < (off+len)) {
8487c478bd9Sstevel@tonic-gate 				/* coalesce-read the rest of the chunk */
8497c478bd9Sstevel@tonic-gate 				bufs[count].b_bcount = remaining_bytes;
8507c478bd9Sstevel@tonic-gate 			} else {
8517c478bd9Sstevel@tonic-gate 				/* get the final bits */
8527c478bd9Sstevel@tonic-gate 				bufs[count].b_bcount = off + len - byte_offset;
8537c478bd9Sstevel@tonic-gate 			}
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 			/*
8567c478bd9Sstevel@tonic-gate 			 * It would be nice to do multiple pages'
8577c478bd9Sstevel@tonic-gate 			 * worth at once here when the opportunity
8587c478bd9Sstevel@tonic-gate 			 * arises, as that has been shown to improve
8597c478bd9Sstevel@tonic-gate 			 * our wall time.  However, to do that
8607c478bd9Sstevel@tonic-gate 			 * requires that we use the pageio subsystem,
8617c478bd9Sstevel@tonic-gate 			 * which doesn't mix well with what we're
8627c478bd9Sstevel@tonic-gate 			 * already using here.  We can't use pageio
8637c478bd9Sstevel@tonic-gate 			 * all the time, because that subsystem
8647c478bd9Sstevel@tonic-gate 			 * assumes that a page is stored in N
8657c478bd9Sstevel@tonic-gate 			 * contiguous blocks on the device.
8667c478bd9Sstevel@tonic-gate 			 * Interleaving violates that assumption.
8677c478bd9Sstevel@tonic-gate 			 */
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate 			remainder = PAGESIZE - (byte_offset % PAGESIZE);
8707c478bd9Sstevel@tonic-gate 			if (bufs[count].b_bcount > remainder) {
8717c478bd9Sstevel@tonic-gate 				bufs[count].b_bcount = remainder;
8727c478bd9Sstevel@tonic-gate 			}
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 			bufs[count].b_bufsize = bufs[count].b_bcount;
8757c478bd9Sstevel@tonic-gate 			byte_offset += bufs[count].b_bcount;
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 			(void) bdev_strategy(&bufs[count]);
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 			lwp_stat_update(LWP_STAT_INBLK, 1);
8807c478bd9Sstevel@tonic-gate 			lastp = searchp;
8817c478bd9Sstevel@tonic-gate 			if ((remainder - bufs[count].b_bcount) < 1) {
8827c478bd9Sstevel@tonic-gate 				searchp = searchp->p_next;
8837c478bd9Sstevel@tonic-gate 			}
8847c478bd9Sstevel@tonic-gate 		}
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 		bufsused = count;
8877c478bd9Sstevel@tonic-gate 		/* Now wait for everything to come in */
8887c478bd9Sstevel@tonic-gate 		for (count = 0; count < bufsused; count++) {
8897c478bd9Sstevel@tonic-gate 			if (err == 0) {
8907c478bd9Sstevel@tonic-gate 				err = biowait(&bufs[count]);
8917c478bd9Sstevel@tonic-gate 			} else
8927c478bd9Sstevel@tonic-gate 				(void) biowait(&bufs[count]);
8937c478bd9Sstevel@tonic-gate 		}
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 		/* Don't leak resources */
8967c478bd9Sstevel@tonic-gate 		for (count = 0; count < bufcnt; count++) {
8977c478bd9Sstevel@tonic-gate 			sema_destroy(&bufs[count].b_io);
8987c478bd9Sstevel@tonic-gate 			sema_destroy(&bufs[count].b_sem);
8997c478bd9Sstevel@tonic-gate 			if (count < bufsused && vas[count] != NULL) {
9007c478bd9Sstevel@tonic-gate 				ppmapout(vas[count]);
9017c478bd9Sstevel@tonic-gate 			}
9027c478bd9Sstevel@tonic-gate 		}
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 		kmem_free(vas, bufcnt * sizeof (caddr_t));
9057c478bd9Sstevel@tonic-gate 		kmem_free(bufs, bufcnt * sizeof (struct buf));
9067c478bd9Sstevel@tonic-gate 	}
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate 	if (err) {
9097c478bd9Sstevel@tonic-gate 		pvn_read_done(pp, B_ERROR);
9107c478bd9Sstevel@tonic-gate 		return (err);
9117c478bd9Sstevel@tonic-gate 	}
9127c478bd9Sstevel@tonic-gate 
9137c478bd9Sstevel@tonic-gate 	/*
9147c478bd9Sstevel@tonic-gate 	 * Lock the requested page, and the one after it if possible.
9157c478bd9Sstevel@tonic-gate 	 * Don't bother if our caller hasn't given us a place to stash
9167c478bd9Sstevel@tonic-gate 	 * the page pointers, since otherwise we'd lock pages that would
9177c478bd9Sstevel@tonic-gate 	 * never get unlocked.
9187c478bd9Sstevel@tonic-gate 	 */
9197c478bd9Sstevel@tonic-gate 	if (pagefound) {
9207c478bd9Sstevel@tonic-gate 		int index;
9217c478bd9Sstevel@tonic-gate 		ulong_t soff;
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 		/*
9247c478bd9Sstevel@tonic-gate 		 * Make sure it's in memory before we say it's here.
9257c478bd9Sstevel@tonic-gate 		 */
9267c478bd9Sstevel@tonic-gate 		if ((pp = page_lookup(vp, off, SE_SHARED)) == NULL) {
9277c478bd9Sstevel@tonic-gate 			hsfs_lostpage++;
9287c478bd9Sstevel@tonic-gate 			goto reread;
9297c478bd9Sstevel@tonic-gate 		}
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate 		pl[0] = pp;
9327c478bd9Sstevel@tonic-gate 		index = 1;
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate 		/*
9357c478bd9Sstevel@tonic-gate 		 * Try to lock the next page, if it exists, without
9367c478bd9Sstevel@tonic-gate 		 * blocking.
9377c478bd9Sstevel@tonic-gate 		 */
9387c478bd9Sstevel@tonic-gate 		plsz -= PAGESIZE;
9397c478bd9Sstevel@tonic-gate 		/* LINTED (plsz is unsigned) */
9407c478bd9Sstevel@tonic-gate 		for (soff = off + PAGESIZE; plsz > 0;
9417c478bd9Sstevel@tonic-gate 		    soff += PAGESIZE, plsz -= PAGESIZE) {
9427c478bd9Sstevel@tonic-gate 			pp = page_lookup_nowait(vp, (u_offset_t)soff,
9437c478bd9Sstevel@tonic-gate 					SE_SHARED);
9447c478bd9Sstevel@tonic-gate 			if (pp == NULL)
9457c478bd9Sstevel@tonic-gate 				break;
9467c478bd9Sstevel@tonic-gate 			pl[index++] = pp;
9477c478bd9Sstevel@tonic-gate 		}
9487c478bd9Sstevel@tonic-gate 		pl[index] = NULL;
9497c478bd9Sstevel@tonic-gate 		return (0);
9507c478bd9Sstevel@tonic-gate 	}
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate 	if (pp != NULL) {
9537c478bd9Sstevel@tonic-gate 		pvn_plist_init(pp, pl, plsz, off, io_len, rw);
9547c478bd9Sstevel@tonic-gate 	}
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 	return (err);
9577c478bd9Sstevel@tonic-gate }
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate static int
9607c478bd9Sstevel@tonic-gate hsfs_getpage(
9617c478bd9Sstevel@tonic-gate 	struct vnode *vp,
9627c478bd9Sstevel@tonic-gate 	offset_t off,
9637c478bd9Sstevel@tonic-gate 	size_t len,
9647c478bd9Sstevel@tonic-gate 	uint_t *protp,
9657c478bd9Sstevel@tonic-gate 	struct page *pl[],
9667c478bd9Sstevel@tonic-gate 	size_t plsz,
9677c478bd9Sstevel@tonic-gate 	struct seg *seg,
9687c478bd9Sstevel@tonic-gate 	caddr_t addr,
9697c478bd9Sstevel@tonic-gate 	enum seg_rw rw,
9707c478bd9Sstevel@tonic-gate 	struct cred *cred)
9717c478bd9Sstevel@tonic-gate {
9727c478bd9Sstevel@tonic-gate 	int err;
9737c478bd9Sstevel@tonic-gate 	uint_t filsiz;
9747c478bd9Sstevel@tonic-gate 	struct hsnode *hp = VTOH(vp);
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	/* does not support write */
9777c478bd9Sstevel@tonic-gate 	if (rw == S_WRITE) {
9787c478bd9Sstevel@tonic-gate 		panic("write attempt on READ ONLY HSFS");
9797c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
9807c478bd9Sstevel@tonic-gate 	}
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate 	if (vp->v_flag & VNOMAP) {
9837c478bd9Sstevel@tonic-gate 		return (ENOSYS);
9847c478bd9Sstevel@tonic-gate 	}
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	ASSERT(off <= MAXOFF_T);
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate 	/*
9897c478bd9Sstevel@tonic-gate 	 * Determine file data size for EOF check.
9907c478bd9Sstevel@tonic-gate 	 */
9917c478bd9Sstevel@tonic-gate 	filsiz = hp->hs_dirent.ext_size;
9927c478bd9Sstevel@tonic-gate 	if ((off + len) > (offset_t)(filsiz + PAGEOFFSET) && seg != segkmap)
9937c478bd9Sstevel@tonic-gate 		return (EFAULT);	/* beyond EOF */
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate 	if (protp != NULL)
9967c478bd9Sstevel@tonic-gate 		*protp = PROT_ALL;
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 	if (len <= PAGESIZE)
9997c478bd9Sstevel@tonic-gate 		err = hsfs_getapage(vp, (u_offset_t)off, len, protp, pl, plsz,
10007c478bd9Sstevel@tonic-gate 		    seg, addr, rw, cred);
10017c478bd9Sstevel@tonic-gate 	else
10027c478bd9Sstevel@tonic-gate 		err = pvn_getpages(hsfs_getapage, vp, off, len, protp,
10037c478bd9Sstevel@tonic-gate 		    pl, plsz, seg, addr, rw, cred);
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate 	return (err);
10067c478bd9Sstevel@tonic-gate }
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate /*
10117c478bd9Sstevel@tonic-gate  * This function should never be called. We need to have it to pass
10127c478bd9Sstevel@tonic-gate  * it as an argument to other functions.
10137c478bd9Sstevel@tonic-gate  */
10147c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10157c478bd9Sstevel@tonic-gate int
10167c478bd9Sstevel@tonic-gate hsfs_putapage(
10177c478bd9Sstevel@tonic-gate 	vnode_t		*vp,
10187c478bd9Sstevel@tonic-gate 	page_t		*pp,
10197c478bd9Sstevel@tonic-gate 	u_offset_t	*offp,
10207c478bd9Sstevel@tonic-gate 	size_t		*lenp,
10217c478bd9Sstevel@tonic-gate 	int		flags,
10227c478bd9Sstevel@tonic-gate 	cred_t		*cr)
10237c478bd9Sstevel@tonic-gate {
10247c478bd9Sstevel@tonic-gate 	/* should never happen - just destroy it */
10257c478bd9Sstevel@tonic-gate 	cmn_err(CE_NOTE, "hsfs_putapage: dirty HSFS page");
10267c478bd9Sstevel@tonic-gate 	pvn_write_done(pp, B_ERROR | B_WRITE | B_INVAL | B_FORCE | flags);
10277c478bd9Sstevel@tonic-gate 	return (0);
10287c478bd9Sstevel@tonic-gate }
10297c478bd9Sstevel@tonic-gate 
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate /*
10327c478bd9Sstevel@tonic-gate  * The only flags we support are B_INVAL, B_FREE and B_DONTNEED.
10337c478bd9Sstevel@tonic-gate  * B_INVAL is set by:
10347c478bd9Sstevel@tonic-gate  *
10357c478bd9Sstevel@tonic-gate  *	1) the MC_SYNC command of memcntl(2) to support the MS_INVALIDATE flag.
10367c478bd9Sstevel@tonic-gate  *	2) the MC_ADVISE command of memcntl(2) with the MADV_DONTNEED advice
10377c478bd9Sstevel@tonic-gate  *	   which translates to an MC_SYNC with the MS_INVALIDATE flag.
10387c478bd9Sstevel@tonic-gate  *
10397c478bd9Sstevel@tonic-gate  * The B_FREE (as well as the B_DONTNEED) flag is set when the
10407c478bd9Sstevel@tonic-gate  * MADV_SEQUENTIAL advice has been used. VOP_PUTPAGE is invoked
10417c478bd9Sstevel@tonic-gate  * from SEGVN to release pages behind a pagefault.
10427c478bd9Sstevel@tonic-gate  */
10437c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10447c478bd9Sstevel@tonic-gate static int
10457c478bd9Sstevel@tonic-gate hsfs_putpage(
10467c478bd9Sstevel@tonic-gate 	struct vnode	*vp,
10477c478bd9Sstevel@tonic-gate 	offset_t	off,
10487c478bd9Sstevel@tonic-gate 	size_t		len,
10497c478bd9Sstevel@tonic-gate 	int		flags,
10507c478bd9Sstevel@tonic-gate 	struct cred	*cr)
10517c478bd9Sstevel@tonic-gate {
10527c478bd9Sstevel@tonic-gate 	int error = 0;
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	if (vp->v_count == 0) {
10557c478bd9Sstevel@tonic-gate 		panic("hsfs_putpage: bad v_count");
10567c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
10577c478bd9Sstevel@tonic-gate 	}
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 	if (vp->v_flag & VNOMAP)
10607c478bd9Sstevel@tonic-gate 		return (ENOSYS);
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate 	ASSERT(off <= MAXOFF_T);
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 	if (!vn_has_cached_data(vp))	/* no pages mapped */
10657c478bd9Sstevel@tonic-gate 		return (0);
10667c478bd9Sstevel@tonic-gate 
10677c478bd9Sstevel@tonic-gate 	if (len == 0)		/* from 'off' to EOF */
10687c478bd9Sstevel@tonic-gate 		error = pvn_vplist_dirty(vp, off,
10697c478bd9Sstevel@tonic-gate 					hsfs_putapage, flags, cr);
10707c478bd9Sstevel@tonic-gate 	else {
10717c478bd9Sstevel@tonic-gate 		offset_t end_off = off + len;
10727c478bd9Sstevel@tonic-gate 		offset_t file_size = VTOH(vp)->hs_dirent.ext_size;
10737c478bd9Sstevel@tonic-gate 		offset_t io_off;
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate 		file_size = (file_size + PAGESIZE - 1) & PAGEMASK;
10767c478bd9Sstevel@tonic-gate 		if (end_off > file_size)
10777c478bd9Sstevel@tonic-gate 			end_off = file_size;
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 		for (io_off = off; io_off < end_off; io_off += PAGESIZE) {
10807c478bd9Sstevel@tonic-gate 			page_t *pp;
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate 			/*
10837c478bd9Sstevel@tonic-gate 			 * We insist on getting the page only if we are
10847c478bd9Sstevel@tonic-gate 			 * about to invalidate, free or write it and
10857c478bd9Sstevel@tonic-gate 			 * the B_ASYNC flag is not set.
10867c478bd9Sstevel@tonic-gate 			 */
10877c478bd9Sstevel@tonic-gate 			if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
10887c478bd9Sstevel@tonic-gate 				pp = page_lookup(vp, io_off,
10897c478bd9Sstevel@tonic-gate 					(flags & (B_INVAL | B_FREE)) ?
10907c478bd9Sstevel@tonic-gate 					    SE_EXCL : SE_SHARED);
10917c478bd9Sstevel@tonic-gate 			} else {
10927c478bd9Sstevel@tonic-gate 				pp = page_lookup_nowait(vp, io_off,
10937c478bd9Sstevel@tonic-gate 					(flags & B_FREE) ? SE_EXCL : SE_SHARED);
10947c478bd9Sstevel@tonic-gate 			}
10957c478bd9Sstevel@tonic-gate 
10967c478bd9Sstevel@tonic-gate 			if (pp == NULL)
10977c478bd9Sstevel@tonic-gate 				continue;
10987c478bd9Sstevel@tonic-gate 			/*
10997c478bd9Sstevel@tonic-gate 			 * Normally pvn_getdirty() should return 0, which
11007c478bd9Sstevel@tonic-gate 			 * impies that it has done the job for us.
11017c478bd9Sstevel@tonic-gate 			 * The shouldn't-happen scenario is when it returns 1.
11027c478bd9Sstevel@tonic-gate 			 * This means that the page has been modified and
11037c478bd9Sstevel@tonic-gate 			 * needs to be put back.
11047c478bd9Sstevel@tonic-gate 			 * Since we can't write on a CD, we fake a failed
11057c478bd9Sstevel@tonic-gate 			 * I/O and force pvn_write_done() to destroy the page.
11067c478bd9Sstevel@tonic-gate 			 */
11077c478bd9Sstevel@tonic-gate 			if (pvn_getdirty(pp, flags) == 1) {
11087c478bd9Sstevel@tonic-gate 				cmn_err(CE_NOTE,
11097c478bd9Sstevel@tonic-gate 					"hsfs_putpage: dirty HSFS page");
11107c478bd9Sstevel@tonic-gate 				pvn_write_done(pp, flags |
11117c478bd9Sstevel@tonic-gate 				    B_ERROR | B_WRITE | B_INVAL | B_FORCE);
11127c478bd9Sstevel@tonic-gate 			}
11137c478bd9Sstevel@tonic-gate 		}
11147c478bd9Sstevel@tonic-gate 	}
11157c478bd9Sstevel@tonic-gate 	return (error);
11167c478bd9Sstevel@tonic-gate }
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 
11197c478bd9Sstevel@tonic-gate /*ARGSUSED*/
11207c478bd9Sstevel@tonic-gate static int
11217c478bd9Sstevel@tonic-gate hsfs_map(
11227c478bd9Sstevel@tonic-gate 	struct vnode *vp,
11237c478bd9Sstevel@tonic-gate 	offset_t off,
11247c478bd9Sstevel@tonic-gate 	struct as *as,
11257c478bd9Sstevel@tonic-gate 	caddr_t *addrp,
11267c478bd9Sstevel@tonic-gate 	size_t len,
11277c478bd9Sstevel@tonic-gate 	uchar_t prot,
11287c478bd9Sstevel@tonic-gate 	uchar_t maxprot,
11297c478bd9Sstevel@tonic-gate 	uint_t flags,
11307c478bd9Sstevel@tonic-gate 	struct cred *cred)
11317c478bd9Sstevel@tonic-gate {
11327c478bd9Sstevel@tonic-gate 	struct segvn_crargs vn_a;
11337c478bd9Sstevel@tonic-gate 	int error;
11347c478bd9Sstevel@tonic-gate 
11357c478bd9Sstevel@tonic-gate 	/* VFS_RECORD(vp->v_vfsp, VS_MAP, VS_CALL); */
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate 	if (vp->v_flag & VNOMAP)
11387c478bd9Sstevel@tonic-gate 		return (ENOSYS);
11397c478bd9Sstevel@tonic-gate 
1140*cfa55013Speterte 	if (off > MAXOFF_T || off < 0 ||
1141*cfa55013Speterte 	    (off + len) < 0 || (off + len) > MAXOFF_T)
1142*cfa55013Speterte 		return (ENXIO);
11437c478bd9Sstevel@tonic-gate 
11447c478bd9Sstevel@tonic-gate 	if (vp->v_type != VREG) {
11457c478bd9Sstevel@tonic-gate 		return (ENODEV);
11467c478bd9Sstevel@tonic-gate 	}
11477c478bd9Sstevel@tonic-gate 
11487c478bd9Sstevel@tonic-gate 	/*
11497c478bd9Sstevel@tonic-gate 	 * If file is being locked, disallow mapping.
11507c478bd9Sstevel@tonic-gate 	 */
11517c478bd9Sstevel@tonic-gate 	if (vn_has_mandatory_locks(vp, VTOH(vp)->hs_dirent.mode))
11527c478bd9Sstevel@tonic-gate 		return (EAGAIN);
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate 	as_rangelock(as);
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 	if ((flags & MAP_FIXED) == 0) {
11577c478bd9Sstevel@tonic-gate 		map_addr(addrp, len, off, 1, flags);
11587c478bd9Sstevel@tonic-gate 		if (*addrp == NULL) {
11597c478bd9Sstevel@tonic-gate 			as_rangeunlock(as);
11607c478bd9Sstevel@tonic-gate 			return (ENOMEM);
11617c478bd9Sstevel@tonic-gate 		}
11627c478bd9Sstevel@tonic-gate 	} else {
11637c478bd9Sstevel@tonic-gate 		/*
11647c478bd9Sstevel@tonic-gate 		 * User specified address - blow away any previous mappings
11657c478bd9Sstevel@tonic-gate 		 */
11667c478bd9Sstevel@tonic-gate 		(void) as_unmap(as, *addrp, len);
11677c478bd9Sstevel@tonic-gate 	}
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate 	vn_a.vp = vp;
11707c478bd9Sstevel@tonic-gate 	vn_a.offset = off;
11717c478bd9Sstevel@tonic-gate 	vn_a.type = flags & MAP_TYPE;
11727c478bd9Sstevel@tonic-gate 	vn_a.prot = prot;
11737c478bd9Sstevel@tonic-gate 	vn_a.maxprot = maxprot;
11747c478bd9Sstevel@tonic-gate 	vn_a.flags = flags & ~MAP_TYPE;
11757c478bd9Sstevel@tonic-gate 	vn_a.cred = cred;
11767c478bd9Sstevel@tonic-gate 	vn_a.amp = NULL;
11777c478bd9Sstevel@tonic-gate 	vn_a.szc = 0;
11787c478bd9Sstevel@tonic-gate 	vn_a.lgrp_mem_policy_flags = 0;
11797c478bd9Sstevel@tonic-gate 
11807c478bd9Sstevel@tonic-gate 	error = as_map(as, *addrp, len, segvn_create, &vn_a);
11817c478bd9Sstevel@tonic-gate 	as_rangeunlock(as);
11827c478bd9Sstevel@tonic-gate 	return (error);
11837c478bd9Sstevel@tonic-gate }
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate /* ARGSUSED */
11867c478bd9Sstevel@tonic-gate static int
11877c478bd9Sstevel@tonic-gate hsfs_addmap(
11887c478bd9Sstevel@tonic-gate 	struct vnode *vp,
11897c478bd9Sstevel@tonic-gate 	offset_t off,
11907c478bd9Sstevel@tonic-gate 	struct as *as,
11917c478bd9Sstevel@tonic-gate 	caddr_t addr,
11927c478bd9Sstevel@tonic-gate 	size_t len,
11937c478bd9Sstevel@tonic-gate 	uchar_t prot,
11947c478bd9Sstevel@tonic-gate 	uchar_t maxprot,
11957c478bd9Sstevel@tonic-gate 	uint_t flags,
11967c478bd9Sstevel@tonic-gate 	struct cred *cr)
11977c478bd9Sstevel@tonic-gate {
11987c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 	if (vp->v_flag & VNOMAP)
12017c478bd9Sstevel@tonic-gate 		return (ENOSYS);
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
12047c478bd9Sstevel@tonic-gate 	mutex_enter(&hp->hs_contents_lock);
12057c478bd9Sstevel@tonic-gate 	hp->hs_mapcnt += btopr(len);
12067c478bd9Sstevel@tonic-gate 	mutex_exit(&hp->hs_contents_lock);
12077c478bd9Sstevel@tonic-gate 	return (0);
12087c478bd9Sstevel@tonic-gate }
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate /*ARGSUSED*/
12117c478bd9Sstevel@tonic-gate static int
12127c478bd9Sstevel@tonic-gate hsfs_delmap(
12137c478bd9Sstevel@tonic-gate 	struct vnode *vp,
12147c478bd9Sstevel@tonic-gate 	offset_t off,
12157c478bd9Sstevel@tonic-gate 	struct as *as,
12167c478bd9Sstevel@tonic-gate 	caddr_t addr,
12177c478bd9Sstevel@tonic-gate 	size_t len,
12187c478bd9Sstevel@tonic-gate 	uint_t prot,
12197c478bd9Sstevel@tonic-gate 	uint_t maxprot,
12207c478bd9Sstevel@tonic-gate 	uint_t flags,
12217c478bd9Sstevel@tonic-gate 	struct cred *cr)
12227c478bd9Sstevel@tonic-gate {
12237c478bd9Sstevel@tonic-gate 	struct hsnode *hp;
12247c478bd9Sstevel@tonic-gate 
12257c478bd9Sstevel@tonic-gate 	if (vp->v_flag & VNOMAP)
12267c478bd9Sstevel@tonic-gate 		return (ENOSYS);
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate 	hp = VTOH(vp);
12297c478bd9Sstevel@tonic-gate 	mutex_enter(&hp->hs_contents_lock);
12307c478bd9Sstevel@tonic-gate 	hp->hs_mapcnt -= btopr(len);	/* Count released mappings */
12317c478bd9Sstevel@tonic-gate 	ASSERT(hp->hs_mapcnt >= 0);
12327c478bd9Sstevel@tonic-gate 	mutex_exit(&hp->hs_contents_lock);
12337c478bd9Sstevel@tonic-gate 	return (0);
12347c478bd9Sstevel@tonic-gate }
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate /* ARGSUSED */
12377c478bd9Sstevel@tonic-gate static int
12387c478bd9Sstevel@tonic-gate hsfs_seek(struct vnode *vp, offset_t ooff, offset_t *noffp)
12397c478bd9Sstevel@tonic-gate {
12407c478bd9Sstevel@tonic-gate 	return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
12417c478bd9Sstevel@tonic-gate }
12427c478bd9Sstevel@tonic-gate 
12437c478bd9Sstevel@tonic-gate /* ARGSUSED */
12447c478bd9Sstevel@tonic-gate static int
12457c478bd9Sstevel@tonic-gate hsfs_frlock(
12467c478bd9Sstevel@tonic-gate 	struct vnode *vp,
12477c478bd9Sstevel@tonic-gate 	int cmd,
12487c478bd9Sstevel@tonic-gate 	struct flock64 *bfp,
12497c478bd9Sstevel@tonic-gate 	int flag,
12507c478bd9Sstevel@tonic-gate 	offset_t offset,
12517c478bd9Sstevel@tonic-gate 	struct flk_callback *flk_cbp,
12527c478bd9Sstevel@tonic-gate 	cred_t *cr)
12537c478bd9Sstevel@tonic-gate {
12547c478bd9Sstevel@tonic-gate 	struct hsnode *hp = VTOH(vp);
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate 	/*
12577c478bd9Sstevel@tonic-gate 	 * If the file is being mapped, disallow fs_frlock.
12587c478bd9Sstevel@tonic-gate 	 * We are not holding the hs_contents_lock while checking
12597c478bd9Sstevel@tonic-gate 	 * hs_mapcnt because the current locking strategy drops all
12607c478bd9Sstevel@tonic-gate 	 * locks before calling fs_frlock.
12617c478bd9Sstevel@tonic-gate 	 * So, hs_mapcnt could change before we enter fs_frlock making
12627c478bd9Sstevel@tonic-gate 	 * it meaningless to have held hs_contents_lock in the first place.
12637c478bd9Sstevel@tonic-gate 	 */
12647c478bd9Sstevel@tonic-gate 	if (hp->hs_mapcnt > 0 && MANDLOCK(vp, hp->hs_dirent.mode))
12657c478bd9Sstevel@tonic-gate 		return (EAGAIN);
12667c478bd9Sstevel@tonic-gate 
12677c478bd9Sstevel@tonic-gate 	return (fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr));
12687c478bd9Sstevel@tonic-gate }
12697c478bd9Sstevel@tonic-gate 
12707c478bd9Sstevel@tonic-gate const fs_operation_def_t hsfs_vnodeops_template[] = {
12717c478bd9Sstevel@tonic-gate 	VOPNAME_OPEN, hsfs_open,
12727c478bd9Sstevel@tonic-gate 	VOPNAME_CLOSE, hsfs_close,
12737c478bd9Sstevel@tonic-gate 	VOPNAME_READ, hsfs_read,
12747c478bd9Sstevel@tonic-gate 	VOPNAME_GETATTR, hsfs_getattr,
12757c478bd9Sstevel@tonic-gate 	VOPNAME_ACCESS, hsfs_access,
12767c478bd9Sstevel@tonic-gate 	VOPNAME_LOOKUP, hsfs_lookup,
12777c478bd9Sstevel@tonic-gate 	VOPNAME_READDIR, hsfs_readdir,
12787c478bd9Sstevel@tonic-gate 	VOPNAME_READLINK, hsfs_readlink,
12797c478bd9Sstevel@tonic-gate 	VOPNAME_FSYNC, hsfs_fsync,
12807c478bd9Sstevel@tonic-gate 	VOPNAME_INACTIVE, (fs_generic_func_p) hsfs_inactive,
12817c478bd9Sstevel@tonic-gate 	VOPNAME_FID, hsfs_fid,
12827c478bd9Sstevel@tonic-gate 	VOPNAME_SEEK, hsfs_seek,
12837c478bd9Sstevel@tonic-gate 	VOPNAME_FRLOCK, hsfs_frlock,
12847c478bd9Sstevel@tonic-gate 	VOPNAME_GETPAGE, hsfs_getpage,
12857c478bd9Sstevel@tonic-gate 	VOPNAME_PUTPAGE, hsfs_putpage,
12867c478bd9Sstevel@tonic-gate 	VOPNAME_MAP, (fs_generic_func_p) hsfs_map,
12877c478bd9Sstevel@tonic-gate 	VOPNAME_ADDMAP, (fs_generic_func_p) hsfs_addmap,
12887c478bd9Sstevel@tonic-gate 	VOPNAME_DELMAP, hsfs_delmap,
12897c478bd9Sstevel@tonic-gate 	NULL, NULL
12907c478bd9Sstevel@tonic-gate };
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate struct vnodeops *hsfs_vnodeops;
1293