From 1a320dc9be592763fb30fa23e61c56ce57051c64 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 14 Nov 1994 06:01:16 +0000 Subject: [PATCH] added extra argument in vn_open and VOP_OPEN to allow cloning devices --- sys/kern/kern_acct.c | 4 ++-- sys/kern/kern_ktrace.c | 4 ++-- sys/kern/kern_sig.c | 4 ++-- sys/kern/vfs_syscalls.c | 20 ++++++++++++++++++-- sys/kern/vfs_vnops.c | 7 ++++--- sys/kern/vnode_if.src | 3 ++- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 5136abf14954..153707e09a27 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_acct.c,v 1.33 1994/10/20 04:22:39 cgd Exp $ */ +/* $NetBSD: kern_acct.c,v 1.34 1994/11/14 06:01:16 christos Exp $ */ /*- * Copyright (c) 1994 Christopher G. Demetriou @@ -115,7 +115,7 @@ acct(p, uap, retval) if (SCARG(uap, path) != NULL) { NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p); - if (error = vn_open(&nd, FWRITE, 0)) + if (error = vn_open(&nd, FWRITE, 0, NULL)) return (error); VOP_UNLOCK(nd.ni_vp); if (nd.ni_vp->v_type != VREG) { diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 74233504616e..6a73ec6896c8 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ktrace.c,v 1.13 1994/10/20 04:22:49 cgd Exp $ */ +/* $NetBSD: kern_ktrace.c,v 1.14 1994/11/14 06:01:18 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -249,7 +249,7 @@ ktrace(curp, uap, retval) */ NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, fname), curp); - if (error = vn_open(&nd, FREAD|FWRITE, 0)) { + if (error = vn_open(&nd, FREAD|FWRITE, 0, NULL)) { curp->p_traceflag &= ~KTRFAC_ACTIVE; return (error); } diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 301999593ad4..54e2ba2f093c 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.34 1994/11/06 20:39:50 mycroft Exp $ */ +/* $NetBSD: kern_sig.c,v 1.35 1994/11/14 06:01:20 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -1172,7 +1172,7 @@ coredump(p) sprintf(name, "%s.core", p->p_comm); NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p); if (error = vn_open(&nd, - O_CREAT | FWRITE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) + O_CREAT | FWRITE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, NULL)) return (error); vp = nd.ni_vp; diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 813c5988eb90..c8dc602e43b5 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.36 1994/10/30 21:48:14 cgd Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.37 1994/11/14 06:01:22 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -617,7 +617,8 @@ open(p, uap, retval) cmode = ((SCARG(uap, mode) &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); p->p_dupfd = -indx - 1; /* XXX check for fdopen */ - if (error = vn_open(&nd, flags, cmode)) { + fp->f_data = (caddr_t) NULL; + if (error = vn_open(&nd, flags, cmode, fp)) { ffree(fp); if ((error == ENODEV || error == ENXIO) && p->p_dupfd >= 0 && /* XXX from fdopen */ @@ -631,8 +632,23 @@ open(p, uap, retval) fdp->fd_ofiles[indx] = NULL; return (error); } + p->p_dupfd = 0; vp = nd.ni_vp; + + if (fp->f_data != (caddr_t) NULL) { + /* + * The fp data was changed, so it is a cloning operation + * Cleanup and return + */ + VOP_UNLOCK(vp); + if (flags & FWRITE) + vp->v_writecount--; + vput(vp); + *retval = indx; + return (0); + } + fp->f_flag = flags & FMASK; fp->f_type = DTYPE_VNODE; fp->f_ops = &vnops; diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index a46caa790f7b..f0e6f4fd621c 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnops.c,v 1.15 1994/10/30 21:48:16 cgd Exp $ */ +/* $NetBSD: vfs_vnops.c,v 1.16 1994/11/14 06:01:24 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -62,9 +62,10 @@ struct fileops vnops = * Common code for vnode open operations. * Check permissions, and call the VOP_OPEN or VOP_CREATE routine. */ -vn_open(ndp, fmode, cmode) +vn_open(ndp, fmode, cmode, fp) register struct nameidata *ndp; int fmode, cmode; + struct file *fp; { register struct vnode *vp; register struct proc *p = ndp->ni_cnd.cn_proc; @@ -139,7 +140,7 @@ vn_open(ndp, fmode, cmode) if (error = VOP_SETATTR(vp, vap, cred, p)) goto bad; } - if (error = VOP_OPEN(vp, fmode, cred, p)) + if (error = VOP_OPEN(vp, fmode, cred, p, fp)) goto bad; if (fmode & FWRITE) vp->v_writecount++; diff --git a/sys/kern/vnode_if.src b/sys/kern/vnode_if.src index 82cd36eed9d3..29e85a9b90ab 100644 --- a/sys/kern/vnode_if.src +++ b/sys/kern/vnode_if.src @@ -1,4 +1,4 @@ -# $NetBSD: vnode_if.src,v 1.4 1994/10/30 21:48:17 cgd Exp $ +# $NetBSD: vnode_if.src,v 1.5 1994/11/14 06:01:25 christos Exp $ # # Copyright (c) 1992, 1993 # The Regents of the University of California. All rights reserved. @@ -58,6 +58,7 @@ vop_open { IN int mode; IN struct ucred *cred; IN struct proc *p; + INOUT struct file *fp; }; vop_close {