Deleted Added
full compact
vfs_cache.c (83000) vfs_cache.c (83366)
1/*
2 * Copyright (c) 1989, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Poul-Henning Kamp of the FreeBSD Project.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95
1/*
2 * Copyright (c) 1989, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Poul-Henning Kamp of the FreeBSD Project.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95
37 * $FreeBSD: head/sys/kern/vfs_cache.c 83000 2001-09-04 19:03:47Z iedowse $
37 * $FreeBSD: head/sys/kern/vfs_cache.c 83366 2001-09-12 08:38:13Z julian $
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/lock.h>
44#include <sys/sysctl.h>
45#include <sys/mount.h>

--- 524 unchanged lines hidden (view full) ---

570{
571 struct vnode *dvp, *vp;
572 int lockparent;
573 int error;
574 struct vnode **vpp = ap->a_vpp;
575 struct componentname *cnp = ap->a_cnp;
576 struct ucred *cred = cnp->cn_cred;
577 int flags = cnp->cn_flags;
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/lock.h>
44#include <sys/sysctl.h>
45#include <sys/mount.h>

--- 524 unchanged lines hidden (view full) ---

570{
571 struct vnode *dvp, *vp;
572 int lockparent;
573 int error;
574 struct vnode **vpp = ap->a_vpp;
575 struct componentname *cnp = ap->a_cnp;
576 struct ucred *cred = cnp->cn_cred;
577 int flags = cnp->cn_flags;
578 struct proc *p = cnp->cn_proc;
578 struct thread *td = cnp->cn_thread;
579 u_long vpid; /* capability number of vnode */
580
581 *vpp = NULL;
582 dvp = ap->a_dvp;
583 lockparent = flags & LOCKPARENT;
584
585 if (dvp->v_type != VDIR)
586 return (ENOTDIR);
587
588 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
589 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
590 return (EROFS);
591
579 u_long vpid; /* capability number of vnode */
580
581 *vpp = NULL;
582 dvp = ap->a_dvp;
583 lockparent = flags & LOCKPARENT;
584
585 if (dvp->v_type != VDIR)
586 return (ENOTDIR);
587
588 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
589 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
590 return (EROFS);
591
592 error = VOP_ACCESS(dvp, VEXEC, cred, p);
592 error = VOP_ACCESS(dvp, VEXEC, cred, td);
593
594 if (error)
595 return (error);
596
597 error = cache_lookup(dvp, vpp, cnp);
598
599 if (!error)
600 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
601
602 if (error == ENOENT)
603 return (error);
604
605 vp = *vpp;
606 vpid = vp->v_id;
607 cnp->cn_flags &= ~PDIRUNLOCK;
608 if (dvp == vp) { /* lookup on "." */
609 VREF(vp);
610 error = 0;
611 } else if (flags & ISDOTDOT) {
593
594 if (error)
595 return (error);
596
597 error = cache_lookup(dvp, vpp, cnp);
598
599 if (!error)
600 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
601
602 if (error == ENOENT)
603 return (error);
604
605 vp = *vpp;
606 vpid = vp->v_id;
607 cnp->cn_flags &= ~PDIRUNLOCK;
608 if (dvp == vp) { /* lookup on "." */
609 VREF(vp);
610 error = 0;
611 } else if (flags & ISDOTDOT) {
612 VOP_UNLOCK(dvp, 0, p);
612 VOP_UNLOCK(dvp, 0, td);
613 cnp->cn_flags |= PDIRUNLOCK;
613 cnp->cn_flags |= PDIRUNLOCK;
614 error = vget(vp, LK_EXCLUSIVE, p);
614 error = vget(vp, LK_EXCLUSIVE, td);
615 if (!error && lockparent && (flags & ISLASTCN)) {
615 if (!error && lockparent && (flags & ISLASTCN)) {
616 if ((error = vn_lock(dvp, LK_EXCLUSIVE, p)) == 0)
616 if ((error = vn_lock(dvp, LK_EXCLUSIVE, td)) == 0)
617 cnp->cn_flags &= ~PDIRUNLOCK;
618 }
619 } else {
617 cnp->cn_flags &= ~PDIRUNLOCK;
618 }
619 } else {
620 error = vget(vp, LK_EXCLUSIVE, p);
620 error = vget(vp, LK_EXCLUSIVE, td);
621 if (!lockparent || error || !(flags & ISLASTCN)) {
621 if (!lockparent || error || !(flags & ISLASTCN)) {
622 VOP_UNLOCK(dvp, 0, p);
622 VOP_UNLOCK(dvp, 0, td);
623 cnp->cn_flags |= PDIRUNLOCK;
624 }
625 }
626 /*
627 * Check that the capability number did not change
628 * while we were waiting for the lock.
629 */
630 if (!error) {
631 if (vpid == vp->v_id)
632 return (0);
633 vput(vp);
634 if (lockparent && dvp != vp && (flags & ISLASTCN)) {
623 cnp->cn_flags |= PDIRUNLOCK;
624 }
625 }
626 /*
627 * Check that the capability number did not change
628 * while we were waiting for the lock.
629 */
630 if (!error) {
631 if (vpid == vp->v_id)
632 return (0);
633 vput(vp);
634 if (lockparent && dvp != vp && (flags & ISLASTCN)) {
635 VOP_UNLOCK(dvp, 0, p);
635 VOP_UNLOCK(dvp, 0, td);
636 cnp->cn_flags |= PDIRUNLOCK;
637 }
638 }
639 if (cnp->cn_flags & PDIRUNLOCK) {
636 cnp->cn_flags |= PDIRUNLOCK;
637 }
638 }
639 if (cnp->cn_flags & PDIRUNLOCK) {
640 error = vn_lock(dvp, LK_EXCLUSIVE, p);
640 error = vn_lock(dvp, LK_EXCLUSIVE, td);
641 if (error)
642 return (error);
643 cnp->cn_flags &= ~PDIRUNLOCK;
644 }
645 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
646}
647
648

--- 9 unchanged lines hidden (view full) ---

658
659static u_long numcwdcalls; STATNODE(CTLFLAG_RD, numcwdcalls, &numcwdcalls);
660static u_long numcwdfail1; STATNODE(CTLFLAG_RD, numcwdfail1, &numcwdfail1);
661static u_long numcwdfail2; STATNODE(CTLFLAG_RD, numcwdfail2, &numcwdfail2);
662static u_long numcwdfail3; STATNODE(CTLFLAG_RD, numcwdfail3, &numcwdfail3);
663static u_long numcwdfail4; STATNODE(CTLFLAG_RD, numcwdfail4, &numcwdfail4);
664static u_long numcwdfound; STATNODE(CTLFLAG_RD, numcwdfound, &numcwdfound);
665int
641 if (error)
642 return (error);
643 cnp->cn_flags &= ~PDIRUNLOCK;
644 }
645 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
646}
647
648

--- 9 unchanged lines hidden (view full) ---

658
659static u_long numcwdcalls; STATNODE(CTLFLAG_RD, numcwdcalls, &numcwdcalls);
660static u_long numcwdfail1; STATNODE(CTLFLAG_RD, numcwdfail1, &numcwdfail1);
661static u_long numcwdfail2; STATNODE(CTLFLAG_RD, numcwdfail2, &numcwdfail2);
662static u_long numcwdfail3; STATNODE(CTLFLAG_RD, numcwdfail3, &numcwdfail3);
663static u_long numcwdfail4; STATNODE(CTLFLAG_RD, numcwdfail4, &numcwdfail4);
664static u_long numcwdfound; STATNODE(CTLFLAG_RD, numcwdfound, &numcwdfound);
665int
666__getcwd(p, uap)
667 struct proc *p;
666__getcwd(td, uap)
667 struct thread *td;
668 struct __getcwd_args *uap;
669{
670 char *bp, *buf;
671 int error, i, slash_prefixed;
672 struct filedesc *fdp;
673 struct namecache *ncp;
674 struct vnode *vp;
675
676 numcwdcalls++;
677 if (disablecwd)
678 return (ENODEV);
679 if (uap->buflen < 2)
680 return (EINVAL);
681 if (uap->buflen > MAXPATHLEN)
682 uap->buflen = MAXPATHLEN;
683 buf = bp = malloc(uap->buflen, M_TEMP, M_WAITOK);
684 bp += uap->buflen - 1;
685 *bp = '\0';
668 struct __getcwd_args *uap;
669{
670 char *bp, *buf;
671 int error, i, slash_prefixed;
672 struct filedesc *fdp;
673 struct namecache *ncp;
674 struct vnode *vp;
675
676 numcwdcalls++;
677 if (disablecwd)
678 return (ENODEV);
679 if (uap->buflen < 2)
680 return (EINVAL);
681 if (uap->buflen > MAXPATHLEN)
682 uap->buflen = MAXPATHLEN;
683 buf = bp = malloc(uap->buflen, M_TEMP, M_WAITOK);
684 bp += uap->buflen - 1;
685 *bp = '\0';
686 fdp = p->p_fd;
686 fdp = td->td_proc->p_fd;
687 slash_prefixed = 0;
688 for (vp = fdp->fd_cdir; vp != fdp->fd_rdir && vp != rootvnode;) {
689 if (vp->v_flag & VROOT) {
690 if (vp->v_mount == NULL) { /* forced unmount */
691 free(buf, M_TEMP);
692 return (EBADF);
693 }
694 vp = vp->v_mount->mnt_vnodecovered;

--- 143 unchanged lines hidden ---
687 slash_prefixed = 0;
688 for (vp = fdp->fd_cdir; vp != fdp->fd_rdir && vp != rootvnode;) {
689 if (vp->v_flag & VROOT) {
690 if (vp->v_mount == NULL) { /* forced unmount */
691 free(buf, M_TEMP);
692 return (EBADF);
693 }
694 vp = vp->v_mount->mnt_vnodecovered;

--- 143 unchanged lines hidden ---