1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software donated to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1997-02-10 02:22:35 +00:00
|
|
|
* @(#)portal_vnops.c 8.14 (Berkeley) 5/21/95
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Portal Filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2002-05-31 11:52:35 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/vnode.h>
|
1997-03-23 03:37:54 +00:00
|
|
|
#include <sys/fcntl.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/file.h>
|
2002-05-31 11:52:35 +00:00
|
|
|
#include <sys/stat.h>
|
2002-05-20 05:41:09 +00:00
|
|
|
#include <sys/mount.h>
|
2002-05-31 11:52:35 +00:00
|
|
|
#include <sys/malloc.h>
|
2002-05-20 05:41:09 +00:00
|
|
|
#include <sys/namei.h>
|
2002-05-31 11:52:35 +00:00
|
|
|
#include <sys/mbuf.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/un.h>
|
1998-05-17 09:37:39 +00:00
|
|
|
#include <sys/unpcb.h>
|
2001-05-23 09:42:29 +00:00
|
|
|
#include <fs/portalfs/portal.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
static int portal_fileid = PORTAL_ROOTFILEID+1;
|
|
|
|
|
2002-03-19 22:20:14 +00:00
|
|
|
static void portal_closefd(struct thread *td, int fd);
|
|
|
|
static int portal_connect(struct socket *so, struct socket *so2);
|
|
|
|
static int portal_getattr(struct vop_getattr_args *ap);
|
|
|
|
static int portal_lookup(struct vop_lookup_args *ap);
|
|
|
|
static int portal_open(struct vop_open_args *ap);
|
|
|
|
static int portal_readdir(struct vop_readdir_args *ap);
|
|
|
|
static int portal_reclaim(struct vop_reclaim_args *ap);
|
|
|
|
static int portal_setattr(struct vop_setattr_args *ap);
|
1995-12-03 14:54:48 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
static void
|
2001-09-12 08:38:13 +00:00
|
|
|
portal_closefd(td, fd)
|
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
int fd;
|
|
|
|
{
|
|
|
|
int error;
|
1995-03-28 07:58:53 +00:00
|
|
|
struct close_args ua;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
ua.fd = fd;
|
2001-09-12 08:38:13 +00:00
|
|
|
error = close(td, &ua);
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* We should never get an error, and there isn't anything
|
|
|
|
* we could do if we got one, so just print a message.
|
|
|
|
*/
|
|
|
|
if (error)
|
|
|
|
printf("portal_closefd: error = %d\n", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vp is the current namei directory
|
|
|
|
* cnp is the name to locate in that directory...
|
|
|
|
*/
|
1995-12-11 09:24:58 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
portal_lookup(ap)
|
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode * a_dvp;
|
|
|
|
struct vnode ** a_vpp;
|
|
|
|
struct componentname * a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
1997-02-10 02:22:35 +00:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vnode **vpp = ap->a_vpp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
char *pname = cnp->cn_nameptr;
|
2003-01-05 00:46:01 +00:00
|
|
|
struct thread *td = cnp->cn_thread;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct portalnode *pt;
|
|
|
|
int error;
|
|
|
|
struct vnode *fvp = 0;
|
|
|
|
char *path;
|
|
|
|
int size;
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
*vpp = NULLVP;
|
|
|
|
|
|
|
|
if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)
|
|
|
|
return (EROFS);
|
|
|
|
|
|
|
|
if (cnp->cn_namelen == 1 && *pname == '.') {
|
|
|
|
*vpp = dvp;
|
|
|
|
VREF(dvp);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-06-12 03:37:57 +00:00
|
|
|
/*
|
|
|
|
* Do the MALLOC before the getnewvnode since doing so afterward
|
|
|
|
* might cause a bogus v_data pointer to get dereferenced
|
|
|
|
* elsewhere if MALLOC should block.
|
|
|
|
*/
|
|
|
|
MALLOC(pt, struct portalnode *, sizeof(struct portalnode),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_TEMP, M_WAITOK);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-09-14 09:02:28 +00:00
|
|
|
error = getnewvnode("portal", dvp->v_mount, portal_vnodeop_p, &fvp);
|
1996-06-12 03:37:57 +00:00
|
|
|
if (error) {
|
|
|
|
FREE(pt, M_TEMP);
|
1994-05-24 10:09:53 +00:00
|
|
|
goto bad;
|
1996-06-12 03:37:57 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
fvp->v_type = VREG;
|
1996-06-12 03:37:57 +00:00
|
|
|
fvp->v_data = pt;
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Save all of the remaining pathname and
|
|
|
|
* advance the namei next pointer to the end
|
|
|
|
* of the string.
|
|
|
|
*/
|
|
|
|
for (size = 0, path = pname; *path; path++)
|
|
|
|
size++;
|
1997-02-10 02:22:35 +00:00
|
|
|
cnp->cn_consume = size - cnp->cn_namelen;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
pt->pt_arg = malloc(size+1, M_TEMP, M_WAITOK);
|
1994-05-24 10:09:53 +00:00
|
|
|
pt->pt_size = size+1;
|
|
|
|
bcopy(pname, pt->pt_arg, pt->pt_size);
|
|
|
|
pt->pt_fileid = portal_fileid++;
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
*vpp = fvp;
|
2003-01-05 00:46:01 +00:00
|
|
|
vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, td);
|
|
|
|
/*
|
|
|
|
* As we are the last component of the path name, fix up
|
|
|
|
* the locking on the directory node.
|
|
|
|
*/
|
|
|
|
if ((cnp->cn_flags & LOCKPARENT) == 0) {
|
|
|
|
VOP_UNLOCK(dvp, 0, td);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:;
|
1997-02-10 02:22:35 +00:00
|
|
|
if (fvp)
|
1994-05-24 10:09:53 +00:00
|
|
|
vrele(fvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
portal_connect(so, so2)
|
|
|
|
struct socket *so;
|
|
|
|
struct socket *so2;
|
|
|
|
{
|
|
|
|
/* from unp_connect, bypassing the namei stuff... */
|
|
|
|
struct socket *so3;
|
|
|
|
struct unpcb *unp2;
|
|
|
|
struct unpcb *unp3;
|
|
|
|
|
|
|
|
if (so2 == 0)
|
|
|
|
return (ECONNREFUSED);
|
|
|
|
|
|
|
|
if (so->so_type != so2->so_type)
|
|
|
|
return (EPROTOTYPE);
|
|
|
|
|
2002-05-31 11:52:35 +00:00
|
|
|
if ((so2->so_options & SO_ACCEPTCONN) == 0)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (ECONNREFUSED);
|
|
|
|
|
|
|
|
if ((so3 = sonewconn(so2, 0)) == 0)
|
|
|
|
return (ECONNREFUSED);
|
|
|
|
|
|
|
|
unp2 = sotounpcb(so2);
|
|
|
|
unp3 = sotounpcb(so3);
|
|
|
|
if (unp2->unp_addr)
|
1997-08-16 19:16:27 +00:00
|
|
|
unp3->unp_addr = (struct sockaddr_un *)
|
2004-03-01 03:14:23 +00:00
|
|
|
sodupsockaddr((struct sockaddr *)unp2->unp_addr,
|
|
|
|
M_NOWAIT);
|
1994-05-24 10:09:53 +00:00
|
|
|
so2 = so3;
|
|
|
|
|
2004-03-31 01:41:30 +00:00
|
|
|
return (uipc_connect2(so, so2));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1995-12-11 09:24:58 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
portal_open(ap)
|
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct socket *so = 0;
|
|
|
|
struct portalnode *pt;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td = ap->a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
int s;
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov[2];
|
|
|
|
int res;
|
|
|
|
struct mbuf *cm = 0;
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
int newfds;
|
|
|
|
int *ip;
|
|
|
|
int fd;
|
|
|
|
int error;
|
|
|
|
int len;
|
|
|
|
struct portalmount *fmp;
|
|
|
|
struct file *fp;
|
|
|
|
struct portal_cred pcred;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to do when opening the root node.
|
|
|
|
*/
|
2002-08-04 10:29:36 +00:00
|
|
|
if (vp->v_vflag & VV_ROOT)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can't be opened unless the caller is set up
|
|
|
|
* to deal with the side effects. Check for this
|
|
|
|
* by testing whether the p_dupfd has been set.
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
if (td->td_dupfd >= 0)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
pt = VTOPORTAL(vp);
|
|
|
|
fmp = VFSTOPORTAL(vp->v_mount);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new socket.
|
|
|
|
*/
|
2002-02-27 18:32:23 +00:00
|
|
|
error = socreate(AF_UNIX, &so, SOCK_STREAM, 0, ap->a_td->td_ucred,
|
|
|
|
ap->a_td);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserve some buffer space
|
|
|
|
*/
|
|
|
|
res = pt->pt_size + sizeof(pcred) + 512; /* XXX */
|
|
|
|
error = soreserve(so, res, res);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kick off connection
|
|
|
|
*/
|
2003-01-13 00:33:17 +00:00
|
|
|
error = portal_connect(so, fmp->pm_server->f_data);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for connection to complete
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* XXX: Since the mount point is holding a reference on the
|
|
|
|
* underlying server socket, it is not easy to find out whether
|
|
|
|
* the server process is still running. To handle this problem
|
|
|
|
* we loop waiting for the new socket to be connected (something
|
|
|
|
* which will only happen if the server is still running) or for
|
|
|
|
* the reference count on the server socket to drop to 1, which
|
|
|
|
* will happen if the server dies. Sleep for 5 second intervals
|
|
|
|
* and keep polling the reference count. XXX.
|
|
|
|
*/
|
|
|
|
s = splnet();
|
|
|
|
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
|
|
|
|
if (fmp->pm_server->f_count == 1) {
|
|
|
|
error = ECONNREFUSED;
|
|
|
|
splx(s);
|
|
|
|
goto bad;
|
|
|
|
}
|
2002-05-31 11:52:35 +00:00
|
|
|
(void) tsleep((caddr_t) &so->so_timeo, PSOCK, "portalcon", 5 * hz);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (so->so_error) {
|
|
|
|
error = so->so_error;
|
|
|
|
goto bad;
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Set miscellaneous flags
|
|
|
|
*/
|
|
|
|
so->so_rcv.sb_timeo = 0;
|
|
|
|
so->so_snd.sb_timeo = 0;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_rcv.sb_flags |= SB_NOINTR;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
SOCKBUF_LOCK(&so->so_snd);
|
1994-05-24 10:09:53 +00:00
|
|
|
so->so_snd.sb_flags |= SB_NOINTR;
|
2004-06-17 22:48:11 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_snd);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
pcred.pcr_flag = ap->a_mode;
|
|
|
|
pcred.pcr_uid = ap->a_cred->cr_uid;
|
|
|
|
pcred.pcr_ngroups = ap->a_cred->cr_ngroups;
|
|
|
|
bcopy(ap->a_cred->cr_groups, pcred.pcr_groups, NGROUPS * sizeof(gid_t));
|
|
|
|
aiov[0].iov_base = (caddr_t) &pcred;
|
|
|
|
aiov[0].iov_len = sizeof(pcred);
|
|
|
|
aiov[1].iov_base = pt->pt_arg;
|
|
|
|
aiov[1].iov_len = pt->pt_size;
|
|
|
|
auio.uio_iov = aiov;
|
|
|
|
auio.uio_iovcnt = 2;
|
|
|
|
auio.uio_rw = UIO_WRITE;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
2001-09-12 08:38:13 +00:00
|
|
|
auio.uio_td = td;
|
1994-05-24 10:09:53 +00:00
|
|
|
auio.uio_offset = 0;
|
|
|
|
auio.uio_resid = aiov[0].iov_len + aiov[1].iov_len;
|
|
|
|
|
1997-08-16 19:16:27 +00:00
|
|
|
error = sosend(so, (struct sockaddr *) 0, &auio,
|
2001-09-12 08:38:13 +00:00
|
|
|
(struct mbuf *) 0, (struct mbuf *) 0, 0 , td);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
len = auio.uio_resid = sizeof(int);
|
|
|
|
do {
|
|
|
|
struct mbuf *m = 0;
|
|
|
|
int flags = MSG_WAITALL;
|
1997-08-16 19:16:27 +00:00
|
|
|
error = soreceive(so, (struct sockaddr **) 0, &auio,
|
1994-05-24 10:09:53 +00:00
|
|
|
&m, &cm, &flags);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab an error code from the mbuf.
|
|
|
|
*/
|
|
|
|
if (m) {
|
|
|
|
m = m_pullup(m, sizeof(int)); /* Needed? */
|
|
|
|
if (m) {
|
|
|
|
error = *(mtod(m, int *));
|
|
|
|
m_freem(m);
|
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (cm == 0) {
|
|
|
|
error = ECONNRESET; /* XXX */
|
|
|
|
#ifdef notdef
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (cm == 0 && auio.uio_resid == len && !error);
|
|
|
|
|
|
|
|
if (cm == 0)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
if (auio.uio_resid) {
|
|
|
|
error = 0;
|
|
|
|
#ifdef notdef
|
|
|
|
error = EMSGSIZE;
|
|
|
|
goto bad;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Break apart the control message, and retrieve the
|
|
|
|
* received file descriptor. Note that more than one descriptor
|
|
|
|
* may have been received, or that the rights chain may have more
|
|
|
|
* than a single mbuf in it. What to do?
|
|
|
|
*/
|
|
|
|
cmsg = mtod(cm, struct cmsghdr *);
|
|
|
|
newfds = (cmsg->cmsg_len - sizeof(*cmsg)) / sizeof (int);
|
|
|
|
if (newfds == 0) {
|
|
|
|
error = ECONNREFUSED;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* At this point the rights message consists of a control message
|
|
|
|
* header, followed by a data region containing a vector of
|
|
|
|
* integer file descriptors. The fds were allocated by the action
|
|
|
|
* of receiving the control message.
|
|
|
|
*/
|
|
|
|
ip = (int *) (cmsg + 1);
|
|
|
|
fd = *ip++;
|
|
|
|
if (newfds > 1) {
|
|
|
|
/*
|
|
|
|
* Close extra fds.
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
printf("portal_open: %d extra fds\n", newfds - 1);
|
|
|
|
for (i = 1; i < newfds; i++) {
|
2001-09-12 08:38:13 +00:00
|
|
|
portal_closefd(td, *ip);
|
1994-05-24 10:09:53 +00:00
|
|
|
ip++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* Check that the mode the file is being opened for is a subset
|
1994-05-24 10:09:53 +00:00
|
|
|
* of the mode of the existing descriptor.
|
|
|
|
*/
|
2002-01-14 00:13:45 +00:00
|
|
|
if ((error = fget(td, fd, &fp)) != 0)
|
2002-01-13 11:58:06 +00:00
|
|
|
goto bad;
|
1994-05-24 10:09:53 +00:00
|
|
|
if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) {
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
2001-09-12 08:38:13 +00:00
|
|
|
portal_closefd(td, fd);
|
1994-05-24 10:09:53 +00:00
|
|
|
error = EACCES;
|
|
|
|
goto bad;
|
|
|
|
}
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the dup fd in the proc structure then return the
|
|
|
|
* special error code (ENXIO) which causes magic things to
|
|
|
|
* happen in vn_open. The whole concept is, well, hmmm.
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_dupfd = fd;
|
1994-05-24 10:09:53 +00:00
|
|
|
error = ENXIO;
|
|
|
|
|
|
|
|
bad:;
|
|
|
|
/*
|
|
|
|
* And discard the control message.
|
|
|
|
*/
|
1995-05-30 08:16:23 +00:00
|
|
|
if (cm) {
|
1994-05-24 10:09:53 +00:00
|
|
|
m_freem(cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (so) {
|
|
|
|
soshutdown(so, 2);
|
|
|
|
soclose(so);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-12-11 09:24:58 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
portal_getattr(ap)
|
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
|
|
|
|
bzero(vap, sizeof(*vap));
|
|
|
|
vattr_null(vap);
|
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
|
|
|
vap->va_size = DEV_BSIZE;
|
|
|
|
vap->va_blocksize = DEV_BSIZE;
|
1998-03-26 20:54:05 +00:00
|
|
|
nanotime(&vap->va_atime);
|
1994-05-24 10:09:53 +00:00
|
|
|
vap->va_mtime = vap->va_atime;
|
1999-12-21 06:29:00 +00:00
|
|
|
vap->va_ctime = vap->va_mtime;
|
1994-05-24 10:09:53 +00:00
|
|
|
vap->va_gen = 0;
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_rdev = 0;
|
|
|
|
/* vap->va_qbytes = 0; */
|
|
|
|
vap->va_bytes = 0;
|
|
|
|
/* vap->va_qsize = 0; */
|
2002-08-04 10:29:36 +00:00
|
|
|
if (vp->v_vflag & VV_ROOT) {
|
1994-05-24 10:09:53 +00:00
|
|
|
vap->va_type = VDIR;
|
|
|
|
vap->va_mode = S_IRUSR|S_IWUSR|S_IXUSR|
|
|
|
|
S_IRGRP|S_IWGRP|S_IXGRP|
|
|
|
|
S_IROTH|S_IWOTH|S_IXOTH;
|
|
|
|
vap->va_nlink = 2;
|
|
|
|
vap->va_fileid = 2;
|
|
|
|
} else {
|
|
|
|
vap->va_type = VREG;
|
|
|
|
vap->va_mode = S_IRUSR|S_IWUSR|
|
|
|
|
S_IRGRP|S_IWGRP|
|
|
|
|
S_IROTH|S_IWOTH;
|
|
|
|
vap->va_nlink = 1;
|
|
|
|
vap->va_fileid = VTOPORTAL(vp)->pt_fileid;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-12-11 09:24:58 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
portal_setattr(ap)
|
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can't mess with the root vnode
|
|
|
|
*/
|
2002-08-04 10:29:36 +00:00
|
|
|
if (ap->a_vp->v_vflag & VV_ROOT)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (EACCES);
|
|
|
|
|
1998-06-10 21:21:31 +00:00
|
|
|
if (ap->a_vap->va_flags != VNOVAL)
|
1998-06-10 06:34:57 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fake readdir, just return empty directory.
|
|
|
|
* It is hard to deal with '.' and '..' so don't bother.
|
|
|
|
*/
|
1995-12-11 09:24:58 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
portal_readdir(ap)
|
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cred;
|
1997-02-10 02:22:35 +00:00
|
|
|
int *a_eofflag;
|
|
|
|
u_long *a_cookies;
|
|
|
|
int a_ncookies;
|
1994-05-24 10:09:53 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
|
|
|
* We don't allow exporting portal mounts, and currently local
|
|
|
|
* requests do not need cookies.
|
|
|
|
*/
|
|
|
|
if (ap->a_ncookies)
|
|
|
|
panic("portal_readdir: not hungry");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-12-11 09:24:58 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
portal_reclaim(ap)
|
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct portalnode *pt = VTOPORTAL(ap->a_vp);
|
|
|
|
|
|
|
|
if (pt->pt_arg) {
|
|
|
|
free((caddr_t) pt->pt_arg, M_TEMP);
|
|
|
|
pt->pt_arg = 0;
|
|
|
|
}
|
|
|
|
FREE(ap->a_vp->v_data, M_TEMP);
|
|
|
|
ap->a_vp->v_data = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-11-09 08:17:23 +00:00
|
|
|
vop_t **portal_vnodeop_p;
|
1995-12-11 09:24:58 +00:00
|
|
|
static struct vnodeopv_entry_desc portal_vnodeop_entries[] = {
|
1997-10-26 20:55:39 +00:00
|
|
|
{ &vop_default_desc, (vop_t *) vop_defaultop },
|
|
|
|
{ &vop_access_desc, (vop_t *) vop_null },
|
1997-10-15 09:22:02 +00:00
|
|
|
{ &vop_getattr_desc, (vop_t *) portal_getattr },
|
|
|
|
{ &vop_lookup_desc, (vop_t *) portal_lookup },
|
|
|
|
{ &vop_open_desc, (vop_t *) portal_open },
|
1997-10-16 20:32:40 +00:00
|
|
|
{ &vop_pathconf_desc, (vop_t *) vop_stdpathconf },
|
1997-10-15 09:22:02 +00:00
|
|
|
{ &vop_readdir_desc, (vop_t *) portal_readdir },
|
|
|
|
{ &vop_reclaim_desc, (vop_t *) portal_reclaim },
|
|
|
|
{ &vop_setattr_desc, (vop_t *) portal_setattr },
|
1995-11-09 08:17:23 +00:00
|
|
|
{ NULL, NULL }
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
1995-12-11 09:24:58 +00:00
|
|
|
static struct vnodeopv_desc portal_vnodeop_opv_desc =
|
1994-05-24 10:09:53 +00:00
|
|
|
{ &portal_vnodeop_p, portal_vnodeop_entries };
|
1994-09-21 03:47:43 +00:00
|
|
|
|
|
|
|
VNODEOP_SET(portal_vnodeop_opv_desc);
|