2001-06-03 06:22:40 +04:00
|
|
|
/* $NetBSD: portal_vnops.c,v 1.38 2001/06/03 02:22:40 chs Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-01-05 17:23:21 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 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.
|
|
|
|
*
|
1994-06-08 15:33:09 +04:00
|
|
|
* from: Id: portal_vnops.c,v 1.4 1992/05/30 10:05:24 jsp Exp
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)portal_vnops.c 8.14 (Berkeley) 5/21/95
|
1994-01-05 17:23:21 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Portal Filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/unpcb.h>
|
1995-10-07 09:25:19 +03:00
|
|
|
#include <sys/syscallargs.h>
|
1996-09-02 03:47:48 +04:00
|
|
|
|
|
|
|
#include <miscfs/genfs/genfs.h>
|
1994-01-05 17:23:21 +03:00
|
|
|
#include <miscfs/portal/portal.h>
|
|
|
|
|
|
|
|
static int portal_fileid = PORTAL_ROOTFILEID+1;
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
static void portal_closefd __P((struct proc *, int));
|
|
|
|
static int portal_connect __P((struct socket *, struct socket *));
|
|
|
|
|
|
|
|
int portal_lookup __P((void *));
|
1999-07-08 05:26:21 +04:00
|
|
|
#define portal_create genfs_eopnotsupp_rele
|
|
|
|
#define portal_mknod genfs_eopnotsupp_rele
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_open __P((void *));
|
1996-09-02 03:47:48 +04:00
|
|
|
#define portal_close genfs_nullop
|
|
|
|
#define portal_access genfs_nullop
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_getattr __P((void *));
|
|
|
|
int portal_setattr __P((void *));
|
1997-11-27 23:36:05 +03:00
|
|
|
#define portal_read genfs_eopnotsupp
|
|
|
|
#define portal_write genfs_eopnotsupp
|
1999-08-04 00:19:16 +04:00
|
|
|
#define portal_fcntl genfs_fcntl
|
1998-08-10 12:11:10 +04:00
|
|
|
#define portal_ioctl genfs_enoioctl
|
1997-11-27 23:36:05 +03:00
|
|
|
#define portal_poll genfs_eopnotsupp
|
1998-03-01 05:20:01 +03:00
|
|
|
#define portal_revoke genfs_revoke
|
1996-09-25 07:01:41 +04:00
|
|
|
#define portal_fsync genfs_nullop
|
1997-11-27 23:36:05 +03:00
|
|
|
#define portal_seek genfs_seek
|
1999-07-08 05:26:21 +04:00
|
|
|
#define portal_remove genfs_eopnotsupp_rele
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_link __P((void *));
|
1999-07-08 05:26:21 +04:00
|
|
|
#define portal_rename genfs_eopnotsupp_rele
|
|
|
|
#define portal_mkdir genfs_eopnotsupp_rele
|
|
|
|
#define portal_rmdir genfs_eopnotsupp_rele
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_symlink __P((void *));
|
|
|
|
int portal_readdir __P((void *));
|
1997-11-27 23:36:05 +03:00
|
|
|
#define portal_readlink genfs_eopnotsupp
|
1996-09-02 03:47:48 +04:00
|
|
|
#define portal_abortop genfs_abortop
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_inactive __P((void *));
|
|
|
|
int portal_reclaim __P((void *));
|
1999-07-08 05:26:21 +04:00
|
|
|
#define portal_lock genfs_lock
|
|
|
|
#define portal_unlock genfs_unlock
|
1996-09-02 03:47:48 +04:00
|
|
|
#define portal_bmap genfs_badop
|
|
|
|
#define portal_strategy genfs_badop
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_print __P((void *));
|
1999-07-08 05:26:21 +04:00
|
|
|
#define portal_islocked genfs_islocked
|
1996-02-10 01:39:56 +03:00
|
|
|
int portal_pathconf __P((void *));
|
1996-09-02 03:47:48 +04:00
|
|
|
#define portal_advlock genfs_badop
|
|
|
|
#define portal_blkatoff genfs_badop
|
|
|
|
#define portal_valloc genfs_eopnotsupp
|
|
|
|
#define portal_vfree genfs_nullop
|
1997-11-27 23:36:05 +03:00
|
|
|
#define portal_truncate genfs_eopnotsupp
|
|
|
|
#define portal_update genfs_eopnotsupp
|
|
|
|
#define portal_bwrite genfs_eopnotsupp
|
1996-02-10 01:39:56 +03:00
|
|
|
|
|
|
|
int (**portal_vnodeop_p) __P((void *));
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_entry_desc portal_vnodeop_entries[] = {
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_default_desc, vn_default_error },
|
|
|
|
{ &vop_lookup_desc, portal_lookup }, /* lookup */
|
|
|
|
{ &vop_create_desc, portal_create }, /* create */
|
|
|
|
{ &vop_mknod_desc, portal_mknod }, /* mknod */
|
|
|
|
{ &vop_open_desc, portal_open }, /* open */
|
|
|
|
{ &vop_close_desc, portal_close }, /* close */
|
|
|
|
{ &vop_access_desc, portal_access }, /* access */
|
|
|
|
{ &vop_getattr_desc, portal_getattr }, /* getattr */
|
|
|
|
{ &vop_setattr_desc, portal_setattr }, /* setattr */
|
|
|
|
{ &vop_read_desc, portal_read }, /* read */
|
|
|
|
{ &vop_write_desc, portal_write }, /* write */
|
1999-08-04 00:19:16 +04:00
|
|
|
{ &vop_fcntl_desc, portal_fcntl }, /* fcntl */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_ioctl_desc, portal_ioctl }, /* ioctl */
|
1996-09-07 16:40:22 +04:00
|
|
|
{ &vop_poll_desc, portal_poll }, /* poll */
|
1998-03-01 05:20:01 +03:00
|
|
|
{ &vop_revoke_desc, portal_revoke }, /* revoke */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_fsync_desc, portal_fsync }, /* fsync */
|
|
|
|
{ &vop_seek_desc, portal_seek }, /* seek */
|
|
|
|
{ &vop_remove_desc, portal_remove }, /* remove */
|
|
|
|
{ &vop_link_desc, portal_link }, /* link */
|
|
|
|
{ &vop_rename_desc, portal_rename }, /* rename */
|
|
|
|
{ &vop_mkdir_desc, portal_mkdir }, /* mkdir */
|
|
|
|
{ &vop_rmdir_desc, portal_rmdir }, /* rmdir */
|
|
|
|
{ &vop_symlink_desc, portal_symlink }, /* symlink */
|
|
|
|
{ &vop_readdir_desc, portal_readdir }, /* readdir */
|
|
|
|
{ &vop_readlink_desc, portal_readlink }, /* readlink */
|
|
|
|
{ &vop_abortop_desc, portal_abortop }, /* abortop */
|
|
|
|
{ &vop_inactive_desc, portal_inactive }, /* inactive */
|
|
|
|
{ &vop_reclaim_desc, portal_reclaim }, /* reclaim */
|
|
|
|
{ &vop_lock_desc, portal_lock }, /* lock */
|
|
|
|
{ &vop_unlock_desc, portal_unlock }, /* unlock */
|
|
|
|
{ &vop_bmap_desc, portal_bmap }, /* bmap */
|
|
|
|
{ &vop_strategy_desc, portal_strategy }, /* strategy */
|
|
|
|
{ &vop_print_desc, portal_print }, /* print */
|
|
|
|
{ &vop_islocked_desc, portal_islocked }, /* islocked */
|
|
|
|
{ &vop_pathconf_desc, portal_pathconf }, /* pathconf */
|
|
|
|
{ &vop_advlock_desc, portal_advlock }, /* advlock */
|
|
|
|
{ &vop_blkatoff_desc, portal_blkatoff }, /* blkatoff */
|
|
|
|
{ &vop_valloc_desc, portal_valloc }, /* valloc */
|
|
|
|
{ &vop_vfree_desc, portal_vfree }, /* vfree */
|
|
|
|
{ &vop_truncate_desc, portal_truncate }, /* truncate */
|
|
|
|
{ &vop_update_desc, portal_update }, /* update */
|
|
|
|
{ &vop_bwrite_desc, portal_bwrite }, /* bwrite */
|
2001-06-03 06:22:40 +04:00
|
|
|
{ NULL, NULL }
|
1996-02-10 01:39:56 +03:00
|
|
|
};
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc portal_vnodeop_opv_desc =
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &portal_vnodeop_p, portal_vnodeop_entries };
|
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
static void
|
|
|
|
portal_closefd(p, fd)
|
|
|
|
struct proc *p;
|
|
|
|
int fd;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
struct sys_close_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
} */ ua;
|
|
|
|
register_t retval[2];
|
1994-01-05 17:23:21 +03:00
|
|
|
int error;
|
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
SCARG(&ua, fd) = fd;
|
|
|
|
error = sys_close(p, &ua, retval);
|
1994-01-05 17:23:21 +03: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)
|
1996-10-13 06:21:25 +04:00
|
|
|
printf("portal_closefd: error = %d\n", error);
|
1994-01-05 17:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vp is the current namei directory
|
1994-06-08 15:33:09 +04:00
|
|
|
* cnp is the name to locate in that directory...
|
1994-01-05 17:23:21 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_lookup(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode * a_dvp;
|
|
|
|
struct vnode ** a_vpp;
|
|
|
|
struct componentname * a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1995-02-03 19:18:46 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vnode **vpp = ap->a_vpp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
1996-10-26 01:57:58 +04:00
|
|
|
const char *pname = cnp->cn_nameptr;
|
1994-01-05 17:23:21 +03:00
|
|
|
struct portalnode *pt;
|
|
|
|
int error;
|
|
|
|
struct vnode *fvp = 0;
|
1996-10-26 01:57:58 +04:00
|
|
|
const char *path;
|
1994-01-05 17:23:21 +03:00
|
|
|
int size;
|
|
|
|
|
1995-02-03 19:18:46 +03: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-01-05 17:23:21 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
error = getnewvnode(VT_PORTAL, dvp->v_mount, portal_vnodeop_p, &fvp);
|
1994-01-05 17:23:21 +03:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
fvp->v_type = VREG;
|
1995-02-03 19:18:46 +03:00
|
|
|
MALLOC(fvp->v_data, void *, sizeof(struct portalnode), M_TEMP,
|
|
|
|
M_WAITOK);
|
1994-01-05 17:23:21 +03:00
|
|
|
|
|
|
|
pt = VTOPORTAL(fvp);
|
|
|
|
/*
|
|
|
|
* 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++;
|
1995-02-03 19:18:46 +03:00
|
|
|
cnp->cn_consume = size - cnp->cn_namelen;
|
1997-05-09 08:05:01 +04:00
|
|
|
cnp->cn_flags &= ~REQUIREDIR;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
pt->pt_arg = malloc(size+1, M_TEMP, M_WAITOK);
|
|
|
|
pt->pt_size = size+1;
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(pt->pt_arg, pname, pt->pt_size);
|
1994-01-05 17:23:21 +03:00
|
|
|
pt->pt_fileid = portal_fileid++;
|
|
|
|
|
1995-02-03 19:18:46 +03:00
|
|
|
*vpp = fvp;
|
1999-07-08 05:26:21 +04:00
|
|
|
VOP_LOCK(fvp, LK_EXCLUSIVE);
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
cnp->cn_flags |= PDIRUNLOCK;
|
|
|
|
}
|
1994-01-05 17:23:21 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:;
|
1995-02-03 19:18:46 +03:00
|
|
|
if (fvp)
|
1994-01-05 17:23:21 +03: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);
|
|
|
|
|
1996-05-23 22:45:14 +04:00
|
|
|
if ((so2->so_options & SO_ACCEPTCONN) == 0 ||
|
|
|
|
(so3 = sonewconn(so2, 0)) == 0)
|
1994-01-05 17:23:21 +03:00
|
|
|
return (ECONNREFUSED);
|
|
|
|
|
|
|
|
unp2 = sotounpcb(so2);
|
|
|
|
unp3 = sotounpcb(so3);
|
1997-06-24 23:12:53 +04:00
|
|
|
if (unp2->unp_addr) {
|
|
|
|
unp3->unp_addr = malloc(unp2->unp_addrlen,
|
|
|
|
M_SONAME, M_WAITOK);
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(unp3->unp_addr, unp2->unp_addr,
|
1997-06-24 23:12:53 +04:00
|
|
|
unp2->unp_addrlen);
|
|
|
|
unp3->unp_addrlen = unp2->unp_addrlen;
|
|
|
|
}
|
1994-01-05 17:23:21 +03:00
|
|
|
|
|
|
|
so2 = so3;
|
|
|
|
|
|
|
|
|
|
|
|
return (unp_connect2(so, so2));
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_open(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-01-05 17:23:21 +03:00
|
|
|
struct socket *so = 0;
|
|
|
|
struct portalnode *pt;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct proc *p = ap->a_p;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
1994-01-05 17:23:21 +03:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (vp->v_flag & VROOT)
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (p->p_dupfd >= 0)
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
pt = VTOPORTAL(vp);
|
|
|
|
fmp = VFSTOPORTAL(vp->v_mount);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new socket.
|
|
|
|
*/
|
1998-07-18 09:04:35 +04:00
|
|
|
error = socreate(AF_LOCAL, &so, SOCK_STREAM, 0);
|
1994-01-05 17:23:21 +03:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserve some buffer space
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
res = pt->pt_size + sizeof(pcred) + 512; /* XXX */
|
1994-01-05 17:23:21 +03:00
|
|
|
error = soreserve(so, res, res);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kick off connection
|
|
|
|
*/
|
|
|
|
error = portal_connect(so, (struct socket *)fmp->pm_server->f_data);
|
|
|
|
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.
|
|
|
|
*/
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1994-01-05 17:23:21 +03:00
|
|
|
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
|
|
|
|
if (fmp->pm_server->f_count == 1) {
|
|
|
|
error = ECONNREFUSED;
|
|
|
|
splx(s);
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
(void) tsleep((caddr_t) &so->so_timeo, PSOCK, "portalcon", 5 * hz);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (so->so_error) {
|
|
|
|
error = so->so_error;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set miscellaneous flags
|
|
|
|
*/
|
|
|
|
so->so_rcv.sb_timeo = 0;
|
|
|
|
so->so_snd.sb_timeo = 0;
|
|
|
|
so->so_rcv.sb_flags |= SB_NOINTR;
|
|
|
|
so->so_snd.sb_flags |= SB_NOINTR;
|
|
|
|
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
pcred.pcr_flag = ap->a_mode;
|
|
|
|
pcred.pcr_uid = ap->a_cred->cr_uid;
|
1995-06-02 02:43:30 +04:00
|
|
|
pcred.pcr_gid = ap->a_cred->cr_gid;
|
1994-06-08 15:33:09 +04:00
|
|
|
pcred.pcr_ngroups = ap->a_cred->cr_ngroups;
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(pcred.pcr_groups, ap->a_cred->cr_groups, NGROUPS * sizeof(gid_t));
|
1994-01-05 17:23:21 +03:00
|
|
|
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;
|
|
|
|
auio.uio_procp = p;
|
|
|
|
auio.uio_offset = 0;
|
|
|
|
auio.uio_resid = aiov[0].iov_len + aiov[1].iov_len;
|
|
|
|
|
1998-10-31 04:18:41 +03:00
|
|
|
error = (*so->so_send)(so, (struct mbuf *) 0, &auio,
|
1994-01-05 17:23:21 +03:00
|
|
|
(struct mbuf *) 0, (struct mbuf *) 0, 0);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
len = auio.uio_resid = sizeof(int);
|
|
|
|
do {
|
|
|
|
struct mbuf *m = 0;
|
|
|
|
int flags = MSG_WAITALL;
|
1998-10-31 04:18:41 +03:00
|
|
|
error = (*so->so_receive)(so, (struct mbuf **) 0, &auio,
|
|
|
|
&m, &cm, &flags);
|
1994-01-05 17:23:21 +03:00
|
|
|
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 *);
|
2000-06-05 21:21:38 +04:00
|
|
|
newfds = (cmsg->cmsg_len - CMSG_ALIGN(sizeof(*cmsg))) / sizeof(int);
|
1994-01-05 17:23:21 +03:00
|
|
|
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.
|
|
|
|
*/
|
2000-06-05 21:21:38 +04:00
|
|
|
ip = (int *) CMSG_DATA(cmsg);
|
1994-01-05 17:23:21 +03:00
|
|
|
fd = *ip++;
|
|
|
|
if (newfds > 1) {
|
|
|
|
/*
|
|
|
|
* Close extra fds.
|
|
|
|
*/
|
|
|
|
int i;
|
1996-10-13 06:21:25 +04:00
|
|
|
printf("portal_open: %d extra fds\n", newfds - 1);
|
1994-01-05 17:23:21 +03:00
|
|
|
for (i = 1; i < newfds; i++) {
|
|
|
|
portal_closefd(p, *ip);
|
|
|
|
ip++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the mode the file is being opened for is a subset
|
|
|
|
* of the mode of the existing descriptor.
|
|
|
|
*/
|
|
|
|
fp = p->p_fd->fd_ofiles[fd];
|
1994-06-08 15:33:09 +04:00
|
|
|
if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) {
|
1994-01-05 17:23:21 +03:00
|
|
|
portal_closefd(p, fd);
|
|
|
|
error = EACCES;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
p->p_dupfd = fd;
|
|
|
|
error = ENXIO;
|
|
|
|
|
|
|
|
bad:;
|
|
|
|
/*
|
|
|
|
* And discard the control message.
|
|
|
|
*/
|
|
|
|
if (cm) {
|
|
|
|
m_freem(cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (so) {
|
|
|
|
soshutdown(so, 2);
|
|
|
|
soclose(so);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_getattr(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
1995-04-15 05:56:43 +04:00
|
|
|
struct timeval tv;
|
1994-01-05 17:23:21 +03:00
|
|
|
|
1998-08-10 00:51:08 +04:00
|
|
|
memset(vap, 0, sizeof(*vap));
|
1994-01-05 17:23:21 +03:00
|
|
|
vattr_null(vap);
|
|
|
|
vap->va_uid = 0;
|
|
|
|
vap->va_gid = 0;
|
|
|
|
vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
|
|
|
|
vap->va_size = DEV_BSIZE;
|
|
|
|
vap->va_blocksize = DEV_BSIZE;
|
1995-04-15 05:56:43 +04:00
|
|
|
microtime(&tv);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&tv, &vap->va_atime);
|
1994-01-05 17:23:21 +03:00
|
|
|
vap->va_mtime = vap->va_atime;
|
|
|
|
vap->va_ctime = vap->va_ctime;
|
|
|
|
vap->va_gen = 0;
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_rdev = 0;
|
|
|
|
/* vap->va_qbytes = 0; */
|
|
|
|
vap->va_bytes = 0;
|
|
|
|
/* vap->va_qsize = 0; */
|
|
|
|
if (vp->v_flag & VROOT) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_setattr(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
/*
|
|
|
|
* Can't mess with the root vnode
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (ap->a_vp->v_flag & VROOT)
|
1994-01-05 17:23:21 +03:00
|
|
|
return (EACCES);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fake readdir, just return empty directory.
|
|
|
|
* It is hard to deal with '.' and '..' so don't bother.
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_readdir(v)
|
|
|
|
void *v;
|
1994-01-05 17:23:21 +03:00
|
|
|
{
|
1996-09-02 03:47:48 +04:00
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_inactive(v)
|
|
|
|
void *v;
|
1994-01-05 17:23:21 +03:00
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct proc *a_p;
|
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(ap->a_vp, 0);
|
1994-01-05 17:23:21 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_reclaim(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct portalnode *pt = VTOPORTAL(ap->a_vp);
|
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
if (pt->pt_arg) {
|
|
|
|
free((caddr_t) pt->pt_arg, M_TEMP);
|
|
|
|
pt->pt_arg = 0;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
FREE(ap->a_vp->v_data, M_TEMP);
|
|
|
|
ap->a_vp->v_data = 0;
|
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Return POSIX pathconf information applicable to special devices.
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int
|
|
|
|
portal_pathconf(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_pathconf_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_name;
|
1994-10-20 07:22:35 +03:00
|
|
|
register_t *a_retval;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*ap->a_retval = LINK_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_MAX_CANON:
|
|
|
|
*ap->a_retval = MAX_CANON;
|
|
|
|
return (0);
|
|
|
|
case _PC_MAX_INPUT:
|
|
|
|
*ap->a_retval = MAX_INPUT;
|
|
|
|
return (0);
|
|
|
|
case _PC_PIPE_BUF:
|
|
|
|
*ap->a_retval = PIPE_BUF;
|
|
|
|
return (0);
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
|
|
|
case _PC_VDISABLE:
|
|
|
|
*ap->a_retval = _POSIX_VDISABLE;
|
|
|
|
return (0);
|
1998-08-03 18:19:57 +04:00
|
|
|
case _PC_SYNC_IO:
|
|
|
|
*ap->a_retval = 1;
|
|
|
|
return (0);
|
1994-06-08 15:33:09 +04:00
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
1994-01-05 17:23:21 +03:00
|
|
|
/*
|
|
|
|
* Print out the contents of a Portal vnode.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_print(v)
|
|
|
|
void *v;
|
1994-01-05 17:23:21 +03:00
|
|
|
{
|
1996-10-13 06:21:25 +04:00
|
|
|
printf("tag VT_PORTAL, portal vnode\n");
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_link(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1996-02-09 17:45:36 +03:00
|
|
|
struct vop_link_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1996-02-09 17:45:36 +03:00
|
|
|
|
|
|
|
VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
|
|
|
|
vput(ap->a_dvp);
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-02-10 01:39:56 +03:00
|
|
|
portal_symlink(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1996-02-09 17:45:36 +03:00
|
|
|
struct vop_symlink_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
char *a_target;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1996-02-09 17:45:36 +03:00
|
|
|
|
|
|
|
VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
|
|
|
|
vput(ap->a_dvp);
|
|
|
|
return (EROFS);
|
|
|
|
}
|