153846Spendry /*
263246Sbostic  * Copyright (c) 1992, 1993
363246Sbostic  *	The Regents of the University of California.  All rights reserved.
453846Spendry  *
553846Spendry  * This code is derived from software donated to Berkeley by
653846Spendry  * Jan-Simon Pendry.
753846Spendry  *
853846Spendry  * %sccs.include.redist.c%
953846Spendry  *
10*67366Smckusick  *	@(#)portal_vnops.c	8.9 (Berkeley) 06/04/94
1153846Spendry  *
1253846Spendry  * $Id: portal_vnops.c,v 1.4 1992/05/30 10:05:24 jsp Exp jsp $
1353846Spendry  */
1453846Spendry 
1553846Spendry /*
1653846Spendry  * Portal Filesystem
1753846Spendry  */
1853846Spendry 
1953846Spendry #include <sys/param.h>
2053846Spendry #include <sys/systm.h>
2153846Spendry #include <sys/kernel.h>
2253846Spendry #include <sys/types.h>
2353846Spendry #include <sys/time.h>
2453846Spendry #include <sys/proc.h>
2553846Spendry #include <sys/filedesc.h>
2653846Spendry #include <sys/vnode.h>
2753846Spendry #include <sys/file.h>
2853846Spendry #include <sys/stat.h>
2953846Spendry #include <sys/mount.h>
3053846Spendry #include <sys/malloc.h>
3153846Spendry #include <sys/namei.h>
3253846Spendry #include <sys/mbuf.h>
3353846Spendry #include <sys/socket.h>
3453846Spendry #include <sys/socketvar.h>
3553846Spendry #include <sys/un.h>
3653846Spendry #include <sys/unpcb.h>
3755027Smckusick #include <miscfs/portal/portal.h>
3853846Spendry 
3953846Spendry static int portal_fileid = PORTAL_ROOTFILEID+1;
4053846Spendry 
4153846Spendry static void
4253846Spendry portal_closefd(p, fd)
4353846Spendry 	struct proc *p;
4453846Spendry 	int fd;
4553846Spendry {
4653846Spendry 	int error;
4753846Spendry 	struct {
4853846Spendry 		int fd;
4953846Spendry 	} ua;
5053846Spendry 	int rc;
5153846Spendry 
5253846Spendry 	ua.fd = fd;
5353846Spendry 	error = close(p, &ua, &rc);
5453846Spendry 	/*
5553846Spendry 	 * We should never get an error, and there isn't anything
5653846Spendry 	 * we could do if we got one, so just print a message.
5753846Spendry 	 */
5853846Spendry 	if (error)
5953846Spendry 		printf("portal_closefd: error = %d\n", error);
6053846Spendry }
6153846Spendry 
6253846Spendry /*
6353846Spendry  * vp is the current namei directory
6453846Spendry  * cnp is the name to locate in that directory...
6553846Spendry  */
6665516Spendry int
6755027Smckusick portal_lookup(ap)
6855027Smckusick 	struct vop_lookup_args /* {
6955027Smckusick 		struct vnode * a_dvp;
7055027Smckusick 		struct vnode ** a_vpp;
7155027Smckusick 		struct componentname * a_cnp;
7255027Smckusick 	} */ *ap;
7353846Spendry {
7453846Spendry 	char *pname = ap->a_cnp->cn_nameptr;
7553846Spendry 	struct portalnode *pt;
7653846Spendry 	int error;
7753846Spendry 	struct vnode *fvp = 0;
7853846Spendry 	char *path;
7953846Spendry 	int size;
8053846Spendry 
8153846Spendry 	if (ap->a_cnp->cn_namelen == 1 && *pname == '.') {
8253846Spendry 		*ap->a_vpp = ap->a_dvp;
8353846Spendry 		VREF(ap->a_dvp);
8453846Spendry 		/*VOP_LOCK(ap->a_dvp);*/
8553846Spendry 		return (0);
8653846Spendry 	}
8753846Spendry 
8853846Spendry 
8965380Spendry 	error = getnewvnode(VT_PORTAL, ap->a_dvp->v_mount, portal_vnodeop_p, &fvp);
9053846Spendry 	if (error)
9153846Spendry 		goto bad;
9253846Spendry 	fvp->v_type = VREG;
9353846Spendry 	MALLOC(fvp->v_data, void *, sizeof(struct portalnode),
9453846Spendry 		M_TEMP, M_WAITOK);
9553846Spendry 
9653846Spendry 	pt = VTOPORTAL(fvp);
9753846Spendry 	/*
9853846Spendry 	 * Save all of the remaining pathname and
9953846Spendry 	 * advance the namei next pointer to the end
10053846Spendry 	 * of the string.
10153846Spendry 	 */
10253846Spendry 	for (size = 0, path = pname; *path; path++)
10353846Spendry 		size++;
10454978Spendry 	ap->a_cnp->cn_consume = size - ap->a_cnp->cn_namelen;
10554978Spendry 
10653846Spendry 	pt->pt_arg = malloc(size+1, M_TEMP, M_WAITOK);
10753846Spendry 	pt->pt_size = size+1;
10853846Spendry 	bcopy(pname, pt->pt_arg, pt->pt_size);
10953846Spendry 	pt->pt_fileid = portal_fileid++;
11053846Spendry 
11153846Spendry 	*ap->a_vpp = fvp;
11253846Spendry 	/*VOP_LOCK(fvp);*/
11353846Spendry 	return (0);
11453846Spendry 
11553846Spendry bad:;
11653846Spendry 	if (fvp) {
11753846Spendry 		vrele(fvp);
11853846Spendry 	}
11953846Spendry 	*ap->a_vpp = NULL;
12053846Spendry 	return (error);
12153846Spendry }
12253846Spendry 
12353846Spendry static int
12453846Spendry portal_connect(so, so2)
12553846Spendry 	struct socket *so;
12653846Spendry 	struct socket *so2;
12753846Spendry {
12853846Spendry 	/* from unp_connect, bypassing the namei stuff... */
12953846Spendry 	struct socket *so3;
13053846Spendry 	struct unpcb *unp2;
13153846Spendry 	struct unpcb *unp3;
13253846Spendry 
13353846Spendry 	if (so2 == 0)
13453846Spendry 		return (ECONNREFUSED);
13553846Spendry 
13653846Spendry 	if (so->so_type != so2->so_type)
13753846Spendry 		return (EPROTOTYPE);
13853846Spendry 
13953846Spendry 	if ((so2->so_options & SO_ACCEPTCONN) == 0)
14053846Spendry 		return (ECONNREFUSED);
14153846Spendry 
14253846Spendry 	if ((so3 = sonewconn(so2, 0)) == 0)
14353846Spendry 		return (ECONNREFUSED);
14453846Spendry 
14553846Spendry 	unp2 = sotounpcb(so2);
14653846Spendry 	unp3 = sotounpcb(so3);
14753846Spendry 	if (unp2->unp_addr)
14853846Spendry 		unp3->unp_addr = m_copy(unp2->unp_addr, 0, (int)M_COPYALL);
14953846Spendry 
15053846Spendry 	so2 = so3;
15153846Spendry 
15253846Spendry 
15353846Spendry 	return (unp_connect2(so, so2));
15453846Spendry }
15553846Spendry 
15665516Spendry int
15755027Smckusick portal_open(ap)
15855027Smckusick 	struct vop_open_args /* {
15955027Smckusick 		struct vnode *a_vp;
16055027Smckusick 		int  a_mode;
16155027Smckusick 		struct ucred *a_cred;
16255027Smckusick 		struct proc *a_p;
16355027Smckusick 	} */ *ap;
16453846Spendry {
16553846Spendry 	struct socket *so = 0;
16653846Spendry 	struct portalnode *pt;
16755910Spendry 	struct proc *p = ap->a_p;
16855910Spendry 	struct vnode *vp = ap->a_vp;
16953846Spendry 	int s;
17053846Spendry 	struct uio auio;
17153846Spendry 	struct iovec aiov[2];
17253846Spendry 	int res;
17353846Spendry 	struct mbuf *cm = 0;
17453846Spendry 	struct cmsghdr *cmsg;
17553846Spendry 	int newfds;
17653846Spendry 	int *ip;
17753846Spendry 	int fd;
17853846Spendry 	int error;
17953846Spendry 	int len;
18053846Spendry 	struct portalmount *fmp;
18153846Spendry 	struct file *fp;
18253846Spendry 	struct portal_cred pcred;
18353846Spendry 
18453846Spendry 	/*
18553846Spendry 	 * Nothing to do when opening the root node.
18653846Spendry 	 */
18755910Spendry 	if (vp->v_flag & VROOT)
18853846Spendry 		return (0);
18953846Spendry 
19053846Spendry 	/*
19153846Spendry 	 * Can't be opened unless the caller is set up
19253846Spendry 	 * to deal with the side effects.  Check for this
19353846Spendry 	 * by testing whether the p_dupfd has been set.
19453846Spendry 	 */
19555910Spendry 	if (p->p_dupfd >= 0)
19653846Spendry 		return (ENODEV);
19753846Spendry 
19855910Spendry 	pt = VTOPORTAL(vp);
19955910Spendry 	fmp = VFSTOPORTAL(vp->v_mount);
20053846Spendry 
20153846Spendry 	/*
20253846Spendry 	 * Create a new socket.
20353846Spendry 	 */
20453846Spendry 	error = socreate(AF_UNIX, &so, SOCK_STREAM, 0);
20553846Spendry 	if (error)
20653846Spendry 		goto bad;
20753846Spendry 
20853846Spendry 	/*
20953846Spendry 	 * Reserve some buffer space
21053846Spendry 	 */
21154978Spendry 	res = pt->pt_size + sizeof(pcred) + 512;	/* XXX */
21253846Spendry 	error = soreserve(so, res, res);
21353846Spendry 	if (error)
21453846Spendry 		goto bad;
21553846Spendry 
21653846Spendry 	/*
21753846Spendry 	 * Kick off connection
21853846Spendry 	 */
21953846Spendry 	error = portal_connect(so, (struct socket *)fmp->pm_server->f_data);
22053846Spendry 	if (error)
22153846Spendry 		goto bad;
22253846Spendry 
22353846Spendry 	/*
22453846Spendry 	 * Wait for connection to complete
22553846Spendry 	 */
22653846Spendry 	/*
22753846Spendry 	 * XXX: Since the mount point is holding a reference on the
22853846Spendry 	 * underlying server socket, it is not easy to find out whether
22953846Spendry 	 * the server process is still running.  To handle this problem
23053846Spendry 	 * we loop waiting for the new socket to be connected (something
23153846Spendry 	 * which will only happen if the server is still running) or for
23253846Spendry 	 * the reference count on the server socket to drop to 1, which
23353846Spendry 	 * will happen if the server dies.  Sleep for 5 second intervals
23453846Spendry 	 * and keep polling the reference count.   XXX.
23553846Spendry 	 */
23653846Spendry 	s = splnet();
23753846Spendry 	while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
23853846Spendry 		if (fmp->pm_server->f_count == 1) {
23953846Spendry 			error = ECONNREFUSED;
24053846Spendry 			splx(s);
24153846Spendry 			goto bad;
24253846Spendry 		}
24353846Spendry 		(void) tsleep((caddr_t) &so->so_timeo, PSOCK, "portalcon", 5 * hz);
24453846Spendry 	}
24553846Spendry 	splx(s);
24653846Spendry 
24753846Spendry 	if (so->so_error) {
24853846Spendry 		error = so->so_error;
24953846Spendry 		goto bad;
25053846Spendry 	}
25153846Spendry 
25253846Spendry 	/*
25353846Spendry 	 * Set miscellaneous flags
25453846Spendry 	 */
25553846Spendry 	so->so_rcv.sb_timeo = 0;
25653846Spendry 	so->so_snd.sb_timeo = 0;
25753846Spendry 	so->so_rcv.sb_flags |= SB_NOINTR;
25853846Spendry 	so->so_snd.sb_flags |= SB_NOINTR;
25953846Spendry 
26053846Spendry 
26154978Spendry 	pcred.pcr_flag = ap->a_mode;
26253846Spendry 	pcred.pcr_uid = ap->a_cred->cr_uid;
26354978Spendry 	pcred.pcr_ngroups = ap->a_cred->cr_ngroups;
26454978Spendry 	bcopy(ap->a_cred->cr_groups, pcred.pcr_groups, NGROUPS * sizeof(gid_t));
26553846Spendry 	aiov[0].iov_base = (caddr_t) &pcred;
26653846Spendry 	aiov[0].iov_len = sizeof(pcred);
26753846Spendry 	aiov[1].iov_base = pt->pt_arg;
26853846Spendry 	aiov[1].iov_len = pt->pt_size;
26953846Spendry 	auio.uio_iov = aiov;
27053846Spendry 	auio.uio_iovcnt = 2;
27153846Spendry 	auio.uio_rw = UIO_WRITE;
27253846Spendry 	auio.uio_segflg = UIO_SYSSPACE;
27355910Spendry 	auio.uio_procp = p;
27453846Spendry 	auio.uio_offset = 0;
27553846Spendry 	auio.uio_resid = aiov[0].iov_len + aiov[1].iov_len;
27653846Spendry 
27765492Spendry 	error = sosend(so, (struct mbuf *) 0, &auio,
27853846Spendry 			(struct mbuf *) 0, (struct mbuf *) 0, 0);
27953846Spendry 	if (error)
28053846Spendry 		goto bad;
28153846Spendry 
28253846Spendry 	len = auio.uio_resid = sizeof(int);
28353846Spendry 	do {
28453846Spendry 		struct mbuf *m = 0;
28553846Spendry 		int flags = MSG_WAITALL;
28653846Spendry 		error = soreceive(so, (struct mbuf **) 0, &auio,
28753846Spendry 					&m, &cm, &flags);
28853846Spendry 		if (error)
28953846Spendry 			goto bad;
29053846Spendry 
29153846Spendry 		/*
29253846Spendry 		 * Grab an error code from the mbuf.
29353846Spendry 		 */
29453846Spendry 		if (m) {
29553846Spendry 			m = m_pullup(m, sizeof(int));	/* Needed? */
29653846Spendry 			if (m) {
29753846Spendry 				error = *(mtod(m, int *));
29853846Spendry 				m_freem(m);
29953846Spendry 			} else {
30053846Spendry 				error = EINVAL;
30153846Spendry 			}
30253846Spendry 		} else {
30353846Spendry 			if (cm == 0) {
30453846Spendry 				error = ECONNRESET;	 /* XXX */
30553846Spendry #ifdef notdef
30653846Spendry 				break;
30753846Spendry #endif
30853846Spendry 			}
30953846Spendry 		}
31053846Spendry 	} while (cm == 0 && auio.uio_resid == len && !error);
31153846Spendry 
31253846Spendry 	if (cm == 0)
31353846Spendry 		goto bad;
31453846Spendry 
31553846Spendry 	if (auio.uio_resid) {
31653846Spendry 		error = 0;
31753846Spendry #ifdef notdef
31853846Spendry 		error = EMSGSIZE;
31953846Spendry 		goto bad;
32053846Spendry #endif
32153846Spendry 	}
32253846Spendry 
32353846Spendry 	/*
32453846Spendry 	 * XXX: Break apart the control message, and retrieve the
32553846Spendry 	 * received file descriptor.  Note that more than one descriptor
32653846Spendry 	 * may have been received, or that the rights chain may have more
32753846Spendry 	 * than a single mbuf in it.  What to do?
32853846Spendry 	 */
32953846Spendry 	cmsg = mtod(cm, struct cmsghdr *);
33053846Spendry 	newfds = (cmsg->cmsg_len - sizeof(*cmsg)) / sizeof (int);
33153846Spendry 	if (newfds == 0) {
33253846Spendry 		error = ECONNREFUSED;
33353846Spendry 		goto bad;
33453846Spendry 	}
33553846Spendry 	/*
33653846Spendry 	 * At this point the rights message consists of a control message
33753846Spendry 	 * header, followed by a data region containing a vector of
33853846Spendry 	 * integer file descriptors.  The fds were allocated by the action
33953846Spendry 	 * of receiving the control message.
34053846Spendry 	 */
34153846Spendry 	ip = (int *) (cmsg + 1);
34253846Spendry 	fd = *ip++;
34353846Spendry 	if (newfds > 1) {
34453846Spendry 		/*
34553846Spendry 		 * Close extra fds.
34653846Spendry 		 */
34753846Spendry 		int i;
34853846Spendry 		printf("portal_open: %d extra fds\n", newfds - 1);
34953846Spendry 		for (i = 1; i < newfds; i++) {
35055910Spendry 			portal_closefd(p, *ip);
35153846Spendry 			ip++;
35253846Spendry 		}
35353846Spendry 	}
35453846Spendry 
35553846Spendry 	/*
35655910Spendry 	 * Check that the mode the file is being opened for is a subset
35755910Spendry 	 * of the mode of the existing descriptor.
35853846Spendry 	 */
35955910Spendry  	fp = p->p_fd->fd_ofiles[fd];
36053846Spendry 	if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) {
36155910Spendry 		portal_closefd(p, fd);
36253846Spendry 		error = EACCES;
36353846Spendry 		goto bad;
36453846Spendry 	}
36553846Spendry 
36653846Spendry 	/*
36753846Spendry 	 * Save the dup fd in the proc structure then return the
36853846Spendry 	 * special error code (ENXIO) which causes magic things to
36953846Spendry 	 * happen in vn_open.  The whole concept is, well, hmmm.
37053846Spendry 	 */
37155910Spendry 	p->p_dupfd = fd;
37253846Spendry 	error = ENXIO;
37353846Spendry 
37453846Spendry bad:;
37553846Spendry 	/*
37653846Spendry 	 * And discard the control message.
37753846Spendry 	 */
37853846Spendry 	if (cm) {
37953846Spendry 		m_freem(cm);
38053846Spendry 	}
38153846Spendry 
38253846Spendry 	if (so) {
38353846Spendry 		soshutdown(so, 2);
38453846Spendry 		soclose(so);
38553846Spendry 	}
38653846Spendry 	return (error);
38753846Spendry }
38853846Spendry 
38965516Spendry int
39055027Smckusick portal_getattr(ap)
39155027Smckusick 	struct vop_getattr_args /* {
39255027Smckusick 		struct vnode *a_vp;
39355027Smckusick 		struct vattr *a_vap;
39455027Smckusick 		struct ucred *a_cred;
39555027Smckusick 		struct proc *a_p;
39655027Smckusick 	} */ *ap;
39753846Spendry {
39855910Spendry 	struct vnode *vp = ap->a_vp;
39955910Spendry 	struct vattr *vap = ap->a_vap;
40053846Spendry 
40165450Sbostic 	bzero(vap, sizeof(*vap));
40255910Spendry 	vattr_null(vap);
40355910Spendry 	vap->va_uid = 0;
40455910Spendry 	vap->va_gid = 0;
40555910Spendry 	vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
40655910Spendry 	vap->va_size = DEV_BSIZE;
40755910Spendry 	vap->va_blocksize = DEV_BSIZE;
40855910Spendry 	microtime(&vap->va_atime);
40955910Spendry 	vap->va_mtime = vap->va_atime;
41055910Spendry 	vap->va_ctime = vap->va_ctime;
41155910Spendry 	vap->va_gen = 0;
41255910Spendry 	vap->va_flags = 0;
41355910Spendry 	vap->va_rdev = 0;
41455910Spendry 	/* vap->va_qbytes = 0; */
41555910Spendry 	vap->va_bytes = 0;
41655910Spendry 	/* vap->va_qsize = 0; */
41755910Spendry 	if (vp->v_flag & VROOT) {
41855910Spendry 		vap->va_type = VDIR;
41955910Spendry 		vap->va_mode = S_IRUSR|S_IWUSR|S_IXUSR|
42053846Spendry 				S_IRGRP|S_IWGRP|S_IXGRP|
42153846Spendry 				S_IROTH|S_IWOTH|S_IXOTH;
42255910Spendry 		vap->va_nlink = 2;
42355910Spendry 		vap->va_fileid = 2;
42453846Spendry 	} else {
42555910Spendry 		vap->va_type = VREG;
42655910Spendry 		vap->va_mode = S_IRUSR|S_IWUSR|
42753846Spendry 				S_IRGRP|S_IWGRP|
42853846Spendry 				S_IROTH|S_IWOTH;
42955910Spendry 		vap->va_nlink = 1;
43055910Spendry 		vap->va_fileid = VTOPORTAL(vp)->pt_fileid;
43153846Spendry 	}
43253846Spendry 	return (0);
43353846Spendry }
43453846Spendry 
43565516Spendry int
43655027Smckusick portal_setattr(ap)
43755027Smckusick 	struct vop_setattr_args /* {
43855027Smckusick 		struct vnode *a_vp;
43955027Smckusick 		struct vattr *a_vap;
44055027Smckusick 		struct ucred *a_cred;
44155027Smckusick 		struct proc *a_p;
44255027Smckusick 	} */ *ap;
44353846Spendry {
44465516Spendry 
44553846Spendry 	/*
44653846Spendry 	 * Can't mess with the root vnode
44753846Spendry 	 */
44853846Spendry 	if (ap->a_vp->v_flag & VROOT)
44953846Spendry 		return (EACCES);
45053846Spendry 
45153846Spendry 	return (0);
45253846Spendry }
45353846Spendry 
45453846Spendry /*
45553846Spendry  * Fake readdir, just return empty directory.
45653846Spendry  * It is hard to deal with '.' and '..' so don't bother.
45753846Spendry  */
45865516Spendry int
45955027Smckusick portal_readdir(ap)
46055027Smckusick 	struct vop_readdir_args /* {
46155027Smckusick 		struct vnode *a_vp;
46255027Smckusick 		struct uio *a_uio;
46355027Smckusick 		struct ucred *a_cred;
464*67366Smckusick 		int *a_eofflag;
465*67366Smckusick 		u_long *a_cookies;
466*67366Smckusick 		int a_ncookies;
46755027Smckusick 	} */ *ap;
46853846Spendry {
46965516Spendry 
470*67366Smckusick 	/*
471*67366Smckusick 	 * We don't allow exporting portal mounts, and currently local
472*67366Smckusick 	 * requests do not need cookies.
473*67366Smckusick 	 */
474*67366Smckusick 	if (ap->a_ncookies)
475*67366Smckusick 		panic("portal_readdir: not hungry");
476*67366Smckusick 
47753846Spendry 	return (0);
47853846Spendry }
47953846Spendry 
48065516Spendry int
48155027Smckusick portal_inactive(ap)
48255027Smckusick 	struct vop_inactive_args /* {
48355027Smckusick 		struct vnode *a_vp;
48455027Smckusick 	} */ *ap;
48553846Spendry {
48665516Spendry 
48753846Spendry 	return (0);
48853846Spendry }
48953846Spendry 
49065516Spendry int
49155027Smckusick portal_reclaim(ap)
49255027Smckusick 	struct vop_reclaim_args /* {
49355027Smckusick 		struct vnode *a_vp;
49455027Smckusick 	} */ *ap;
49553846Spendry {
49653846Spendry 	struct portalnode *pt = VTOPORTAL(ap->a_vp);
49765516Spendry 
49853846Spendry 	if (pt->pt_arg) {
49953846Spendry 		free((caddr_t) pt->pt_arg, M_TEMP);
50053846Spendry 		pt->pt_arg = 0;
50153846Spendry 	}
50265384Spendry 	FREE(ap->a_vp->v_data, M_TEMP);
50365384Spendry 	ap->a_vp->v_data = 0;
50465516Spendry 
50553846Spendry 	return (0);
50653846Spendry }
50753846Spendry 
50853846Spendry /*
50965741Spendry  * Return POSIX pathconf information applicable to special devices.
51065741Spendry  */
51165741Spendry portal_pathconf(ap)
51265741Spendry 	struct vop_pathconf_args /* {
51365741Spendry 		struct vnode *a_vp;
51465741Spendry 		int a_name;
51565741Spendry 		int *a_retval;
51665741Spendry 	} */ *ap;
51765741Spendry {
51865741Spendry 
51965741Spendry 	switch (ap->a_name) {
52065741Spendry 	case _PC_LINK_MAX:
52165741Spendry 		*ap->a_retval = LINK_MAX;
52265741Spendry 		return (0);
52365741Spendry 	case _PC_MAX_CANON:
52465741Spendry 		*ap->a_retval = MAX_CANON;
52565741Spendry 		return (0);
52665741Spendry 	case _PC_MAX_INPUT:
52765741Spendry 		*ap->a_retval = MAX_INPUT;
52865741Spendry 		return (0);
52965741Spendry 	case _PC_PIPE_BUF:
53065741Spendry 		*ap->a_retval = PIPE_BUF;
53165741Spendry 		return (0);
53265741Spendry 	case _PC_CHOWN_RESTRICTED:
53365741Spendry 		*ap->a_retval = 1;
53465741Spendry 		return (0);
53565741Spendry 	case _PC_VDISABLE:
53665741Spendry 		*ap->a_retval = _POSIX_VDISABLE;
53765741Spendry 		return (0);
53865741Spendry 	default:
53965741Spendry 		return (EINVAL);
54065741Spendry 	}
54165741Spendry 	/* NOTREACHED */
54265741Spendry }
54365741Spendry 
54465741Spendry /*
54553846Spendry  * Print out the contents of a Portal vnode.
54653846Spendry  */
54753846Spendry /* ARGSUSED */
54865516Spendry int
54955027Smckusick portal_print(ap)
55055027Smckusick 	struct vop_print_args /* {
55155027Smckusick 		struct vnode *a_vp;
55255027Smckusick 	} */ *ap;
55353846Spendry {
55455027Smckusick 
55553846Spendry 	printf("tag VT_PORTAL, portal vnode\n");
55655027Smckusick 	return (0);
55753846Spendry }
55853846Spendry 
55953846Spendry /*void*/
56065516Spendry int
56155027Smckusick portal_vfree(ap)
56255027Smckusick 	struct vop_vfree_args /* {
56355027Smckusick 		struct vnode *a_pvp;
56455027Smckusick 		ino_t a_ino;
56555027Smckusick 		int a_mode;
56655027Smckusick 	} */ *ap;
56753846Spendry {
56855027Smckusick 
56955027Smckusick 	return (0);
57053846Spendry }
57153846Spendry 
57253846Spendry 
57353846Spendry /*
57453846Spendry  * Portal vnode unsupported operation
57553846Spendry  */
57665516Spendry int
57753846Spendry portal_enotsupp()
57853846Spendry {
57955027Smckusick 
58053846Spendry 	return (EOPNOTSUPP);
58153846Spendry }
58253846Spendry 
58353846Spendry /*
58453846Spendry  * Portal "should never get here" operation
58553846Spendry  */
58665516Spendry int
58753846Spendry portal_badop()
58853846Spendry {
58955027Smckusick 
59053846Spendry 	panic("portal: bad op");
59153846Spendry 	/* NOTREACHED */
59253846Spendry }
59353846Spendry 
59453846Spendry /*
59553846Spendry  * Portal vnode null operation
59653846Spendry  */
59765516Spendry int
59853846Spendry portal_nullop()
59953846Spendry {
60055027Smckusick 
60153846Spendry 	return (0);
60253846Spendry }
60353846Spendry 
60455027Smckusick #define portal_create ((int (*) __P((struct vop_create_args *)))portal_enotsupp)
60553846Spendry #define portal_mknod ((int (*) __P((struct  vop_mknod_args *)))portal_enotsupp)
60653846Spendry #define portal_close ((int (*) __P((struct  vop_close_args *)))nullop)
60753846Spendry #define portal_access ((int (*) __P((struct  vop_access_args *)))nullop)
60853846Spendry #define portal_read ((int (*) __P((struct  vop_read_args *)))portal_enotsupp)
60953846Spendry #define portal_write ((int (*) __P((struct  vop_write_args *)))portal_enotsupp)
61053846Spendry #define portal_ioctl ((int (*) __P((struct  vop_ioctl_args *)))portal_enotsupp)
61155027Smckusick #define portal_select ((int (*) __P((struct vop_select_args *)))portal_enotsupp)
61253846Spendry #define portal_mmap ((int (*) __P((struct  vop_mmap_args *)))portal_enotsupp)
61353846Spendry #define portal_fsync ((int (*) __P((struct  vop_fsync_args *)))nullop)
61453846Spendry #define portal_seek ((int (*) __P((struct  vop_seek_args *)))nullop)
61555027Smckusick #define portal_remove ((int (*) __P((struct vop_remove_args *)))portal_enotsupp)
61653846Spendry #define portal_link ((int (*) __P((struct  vop_link_args *)))portal_enotsupp)
61755027Smckusick #define portal_rename ((int (*) __P((struct vop_rename_args *)))portal_enotsupp)
61853846Spendry #define portal_mkdir ((int (*) __P((struct  vop_mkdir_args *)))portal_enotsupp)
61953846Spendry #define portal_rmdir ((int (*) __P((struct  vop_rmdir_args *)))portal_enotsupp)
62055171Spendry #define portal_symlink \
62155027Smckusick 	((int (*) __P((struct  vop_symlink_args *)))portal_enotsupp)
62255171Spendry #define portal_readlink \
62355027Smckusick 	((int (*) __P((struct  vop_readlink_args *)))portal_enotsupp)
62453846Spendry #define portal_abortop ((int (*) __P((struct  vop_abortop_args *)))nullop)
62553846Spendry #define portal_lock ((int (*) __P((struct  vop_lock_args *)))nullop)
62653846Spendry #define portal_unlock ((int (*) __P((struct  vop_unlock_args *)))nullop)
62753846Spendry #define portal_bmap ((int (*) __P((struct  vop_bmap_args *)))portal_badop)
62855171Spendry #define portal_strategy \
62955027Smckusick 	((int (*) __P((struct  vop_strategy_args *)))portal_badop)
63053846Spendry #define portal_islocked ((int (*) __P((struct  vop_islocked_args *)))nullop)
63155171Spendry #define portal_advlock \
63255027Smckusick 	((int (*) __P((struct  vop_advlock_args *)))portal_enotsupp)
63355171Spendry #define portal_blkatoff \
63455027Smckusick 	((int (*) __P((struct  vop_blkatoff_args *)))portal_enotsupp)
63553846Spendry #define portal_valloc ((int(*) __P(( \
63653846Spendry 		struct vnode *pvp, \
63753846Spendry 		int mode, \
63853846Spendry 		struct ucred *cred, \
63953846Spendry 		struct vnode **vpp))) portal_enotsupp)
64055171Spendry #define portal_truncate \
64155027Smckusick 	((int (*) __P((struct  vop_truncate_args *)))portal_enotsupp)
64255027Smckusick #define portal_update ((int (*) __P((struct vop_update_args *)))portal_enotsupp)
64355027Smckusick #define portal_bwrite ((int (*) __P((struct vop_bwrite_args *)))portal_enotsupp)
64453846Spendry 
64553846Spendry int (**portal_vnodeop_p)();
64653846Spendry struct vnodeopv_entry_desc portal_vnodeop_entries[] = {
64753846Spendry 	{ &vop_default_desc, vn_default_error },
64853846Spendry 	{ &vop_lookup_desc, portal_lookup },		/* lookup */
64953846Spendry 	{ &vop_create_desc, portal_create },		/* create */
65053846Spendry 	{ &vop_mknod_desc, portal_mknod },		/* mknod */
65153846Spendry 	{ &vop_open_desc, portal_open },		/* open */
65253846Spendry 	{ &vop_close_desc, portal_close },		/* close */
65353846Spendry 	{ &vop_access_desc, portal_access },		/* access */
65453846Spendry 	{ &vop_getattr_desc, portal_getattr },		/* getattr */
65553846Spendry 	{ &vop_setattr_desc, portal_setattr },		/* setattr */
65653846Spendry 	{ &vop_read_desc, portal_read },		/* read */
65753846Spendry 	{ &vop_write_desc, portal_write },		/* write */
65853846Spendry 	{ &vop_ioctl_desc, portal_ioctl },		/* ioctl */
65953846Spendry 	{ &vop_select_desc, portal_select },		/* select */
66053846Spendry 	{ &vop_mmap_desc, portal_mmap },		/* mmap */
66153846Spendry 	{ &vop_fsync_desc, portal_fsync },		/* fsync */
66253846Spendry 	{ &vop_seek_desc, portal_seek },		/* seek */
66353846Spendry 	{ &vop_remove_desc, portal_remove },		/* remove */
66453846Spendry 	{ &vop_link_desc, portal_link },		/* link */
66553846Spendry 	{ &vop_rename_desc, portal_rename },		/* rename */
66653846Spendry 	{ &vop_mkdir_desc, portal_mkdir },		/* mkdir */
66753846Spendry 	{ &vop_rmdir_desc, portal_rmdir },		/* rmdir */
66853846Spendry 	{ &vop_symlink_desc, portal_symlink },		/* symlink */
66953846Spendry 	{ &vop_readdir_desc, portal_readdir },		/* readdir */
67053846Spendry 	{ &vop_readlink_desc, portal_readlink },	/* readlink */
67153846Spendry 	{ &vop_abortop_desc, portal_abortop },		/* abortop */
67253846Spendry 	{ &vop_inactive_desc, portal_inactive },	/* inactive */
67353846Spendry 	{ &vop_reclaim_desc, portal_reclaim },		/* reclaim */
67453846Spendry 	{ &vop_lock_desc, portal_lock },		/* lock */
67553846Spendry 	{ &vop_unlock_desc, portal_unlock },		/* unlock */
67653846Spendry 	{ &vop_bmap_desc, portal_bmap },		/* bmap */
67753846Spendry 	{ &vop_strategy_desc, portal_strategy },	/* strategy */
67853846Spendry 	{ &vop_print_desc, portal_print },		/* print */
67953846Spendry 	{ &vop_islocked_desc, portal_islocked },	/* islocked */
68065741Spendry 	{ &vop_pathconf_desc, portal_pathconf },	/* pathconf */
68153846Spendry 	{ &vop_advlock_desc, portal_advlock },		/* advlock */
68253846Spendry 	{ &vop_blkatoff_desc, portal_blkatoff },	/* blkatoff */
68353846Spendry 	{ &vop_valloc_desc, portal_valloc },		/* valloc */
68453846Spendry 	{ &vop_vfree_desc, portal_vfree },		/* vfree */
68553846Spendry 	{ &vop_truncate_desc, portal_truncate },	/* truncate */
68653846Spendry 	{ &vop_update_desc, portal_update },		/* update */
68753846Spendry 	{ &vop_bwrite_desc, portal_bwrite },		/* bwrite */
68853846Spendry 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
68953846Spendry };
69053846Spendry struct vnodeopv_desc portal_vnodeop_opv_desc =
69153846Spendry 	{ &portal_vnodeop_p, portal_vnodeop_entries };
692