vfs_vnops.c (2102) | vfs_vnops.c (3308) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94 |
39 * $Id: vfs_vnops.c,v 1.3 1994/08/02 07:43:33 davidg Exp $ | 39 * $Id: vfs_vnops.c,v 1.4 1994/08/18 03:53:38 davidg Exp $ |
40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/file.h> 46#include <sys/stat.h> 47#include <sys/buf.h> --- 25 unchanged lines hidden (view full) --- 73 struct vattr *vap = &vat; 74 int error; 75 76 if (fmode & O_CREAT) { 77 ndp->ni_cnd.cn_nameiop = CREATE; 78 ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF; 79 if ((fmode & O_EXCL) == 0) 80 ndp->ni_cnd.cn_flags |= FOLLOW; | 40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/file.h> 46#include <sys/stat.h> 47#include <sys/buf.h> --- 25 unchanged lines hidden (view full) --- 73 struct vattr *vap = &vat; 74 int error; 75 76 if (fmode & O_CREAT) { 77 ndp->ni_cnd.cn_nameiop = CREATE; 78 ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF; 79 if ((fmode & O_EXCL) == 0) 80 ndp->ni_cnd.cn_flags |= FOLLOW; |
81 if (error = namei(ndp)) | 81 error = namei(ndp); 82 if (error) |
82 return (error); 83 if (ndp->ni_vp == NULL) { 84 VATTR_NULL(vap); 85 vap->va_type = VREG; 86 vap->va_mode = cmode; 87 LEASE_CHECK(ndp->ni_dvp, p, cred, LEASE_WRITE); | 83 return (error); 84 if (ndp->ni_vp == NULL) { 85 VATTR_NULL(vap); 86 vap->va_type = VREG; 87 vap->va_mode = cmode; 88 LEASE_CHECK(ndp->ni_dvp, p, cred, LEASE_WRITE); |
88 if (error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, 89 &ndp->ni_cnd, vap)) | 89 error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, 90 &ndp->ni_cnd, vap); 91 if (error) |
90 return (error); 91 fmode &= ~O_TRUNC; 92 vp = ndp->ni_vp; 93 } else { 94 VOP_ABORTOP(ndp->ni_dvp, &ndp->ni_cnd); 95 if (ndp->ni_dvp == ndp->ni_vp) 96 vrele(ndp->ni_dvp); 97 else --- 4 unchanged lines hidden (view full) --- 102 error = EEXIST; 103 goto bad; 104 } 105 fmode &= ~O_CREAT; 106 } 107 } else { 108 ndp->ni_cnd.cn_nameiop = LOOKUP; 109 ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF; | 92 return (error); 93 fmode &= ~O_TRUNC; 94 vp = ndp->ni_vp; 95 } else { 96 VOP_ABORTOP(ndp->ni_dvp, &ndp->ni_cnd); 97 if (ndp->ni_dvp == ndp->ni_vp) 98 vrele(ndp->ni_dvp); 99 else --- 4 unchanged lines hidden (view full) --- 104 error = EEXIST; 105 goto bad; 106 } 107 fmode &= ~O_CREAT; 108 } 109 } else { 110 ndp->ni_cnd.cn_nameiop = LOOKUP; 111 ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF; |
110 if (error = namei(ndp)) | 112 error = namei(ndp); 113 if (error) |
111 return (error); 112 vp = ndp->ni_vp; 113 } 114 if (vp->v_type == VSOCK) { 115 error = EOPNOTSUPP; 116 goto bad; 117 } 118 if ((fmode & O_CREAT) == 0) { 119 if (fmode & FREAD) { | 114 return (error); 115 vp = ndp->ni_vp; 116 } 117 if (vp->v_type == VSOCK) { 118 error = EOPNOTSUPP; 119 goto bad; 120 } 121 if ((fmode & O_CREAT) == 0) { 122 if (fmode & FREAD) { |
120 if (error = VOP_ACCESS(vp, VREAD, cred, p)) | 123 error = VOP_ACCESS(vp, VREAD, cred, p); 124 if (error) |
121 goto bad; 122 } 123 if (fmode & (FWRITE | O_TRUNC)) { 124 if (vp->v_type == VDIR) { 125 error = EISDIR; 126 goto bad; 127 } | 125 goto bad; 126 } 127 if (fmode & (FWRITE | O_TRUNC)) { 128 if (vp->v_type == VDIR) { 129 error = EISDIR; 130 goto bad; 131 } |
128 if ((error = vn_writechk(vp)) || 129 (error = VOP_ACCESS(vp, VWRITE, cred, p))) | 132 error = vn_writechk(vp); 133 if(error) |
130 goto bad; | 134 goto bad; |
135 error = VOP_ACCESS(vp, VWRITE, cred, p); 136 if(error) 137 goto bad; |
|
131 } 132 } 133 if (fmode & O_TRUNC) { 134 VOP_UNLOCK(vp); /* XXX */ 135 LEASE_CHECK(vp, p, cred, LEASE_WRITE); 136 VOP_LOCK(vp); /* XXX */ 137 VATTR_NULL(vap); 138 vap->va_size = 0; | 138 } 139 } 140 if (fmode & O_TRUNC) { 141 VOP_UNLOCK(vp); /* XXX */ 142 LEASE_CHECK(vp, p, cred, LEASE_WRITE); 143 VOP_LOCK(vp); /* XXX */ 144 VATTR_NULL(vap); 145 vap->va_size = 0; |
139 if (error = VOP_SETATTR(vp, vap, cred, p)) | 146 error = VOP_SETATTR(vp, vap, cred, p); 147 if (error) |
140 goto bad; 141 } | 148 goto bad; 149 } |
142 if (error = VOP_OPEN(vp, fmode, cred, p)) | 150 error = VOP_OPEN(vp, fmode, cred, p); 151 if (error) |
143 goto bad; 144 if (fmode & FWRITE) 145 vp->v_writecount++; 146 return (0); 147bad: 148 vput(vp); 149 return (error); 150} --- 12 unchanged lines hidden (view full) --- 163 * Disallow write attempts on read-only file systems; 164 * unless the file is a socket or a block or character 165 * device resident on the file system. 166 */ 167 if (vp->v_mount->mnt_flag & MNT_RDONLY) { 168 switch (vp->v_type) { 169 case VREG: case VDIR: case VLNK: 170 return (EROFS); | 152 goto bad; 153 if (fmode & FWRITE) 154 vp->v_writecount++; 155 return (0); 156bad: 157 vput(vp); 158 return (error); 159} --- 12 unchanged lines hidden (view full) --- 172 * Disallow write attempts on read-only file systems; 173 * unless the file is a socket or a block or character 174 * device resident on the file system. 175 */ 176 if (vp->v_mount->mnt_flag & MNT_RDONLY) { 177 switch (vp->v_type) { 178 case VREG: case VDIR: case VLNK: 179 return (EROFS); |
180 default: 181 break; |
|
171 } 172 } 173 /* 174 * If there's shared text associated with 175 * the vnode, try to free it up once. If 176 * we fail, we can't allow writing. 177 */ 178 if ((vp->v_flag & VTEXT) && !vnode_pager_uncache(vp)) --- 197 unchanged lines hidden (view full) --- 376 struct vattr vattr; 377 int error; 378 379 switch (vp->v_type) { 380 381 case VREG: 382 case VDIR: 383 if (com == FIONREAD) { | 182 } 183 } 184 /* 185 * If there's shared text associated with 186 * the vnode, try to free it up once. If 187 * we fail, we can't allow writing. 188 */ 189 if ((vp->v_flag & VTEXT) && !vnode_pager_uncache(vp)) --- 197 unchanged lines hidden (view full) --- 387 struct vattr vattr; 388 int error; 389 390 switch (vp->v_type) { 391 392 case VREG: 393 case VDIR: 394 if (com == FIONREAD) { |
384 if (error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) | 395 error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); 396 if (error) |
385 return (error); 386 *(int *)data = vattr.va_size - fp->f_offset; 387 return (0); 388 } 389 if (com == FIONBIO || com == FIOASYNC) /* XXX */ 390 return (0); /* XXX */ 391 /* fall into ... */ 392 --- 50 unchanged lines hidden --- | 397 return (error); 398 *(int *)data = vattr.va_size - fp->f_offset; 399 return (0); 400 } 401 if (com == FIONBIO || com == FIOASYNC) /* XXX */ 402 return (0); /* XXX */ 403 /* fall into ... */ 404 --- 50 unchanged lines hidden --- |