2 * Copyright (c) 1999, 2000, 2001 Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/namei.h>
37 #include <sys/kernel.h>
40 #include <sys/fcntl.h>
41 #include <sys/mount.h>
42 #include <sys/unistd.h>
43 #include <sys/vnode.h>
46 #include <vm/vm_extern.h>
48 #include <machine/mutex.h>
50 #include <netncp/ncp.h>
51 #include <netncp/ncp_conn.h>
52 #include <netncp/ncp_subr.h>
53 #include <netncp/nwerror.h>
54 #include <netncp/ncp_nls.h>
56 #include <fs/nwfs/nwfs.h>
57 #include <fs/nwfs/nwfs_node.h>
58 #include <fs/nwfs/nwfs_subr.h>
61 * Prototypes for NWFS vnode operations
63 static vop_create_t nwfs_create;
64 static vop_mknod_t nwfs_mknod;
65 static vop_open_t nwfs_open;
66 static vop_close_t nwfs_close;
67 static vop_access_t nwfs_access;
68 static vop_getattr_t nwfs_getattr;
69 static vop_setattr_t nwfs_setattr;
70 static vop_read_t nwfs_read;
71 static vop_write_t nwfs_write;
72 static vop_fsync_t nwfs_fsync;
73 static vop_remove_t nwfs_remove;
74 static vop_link_t nwfs_link;
75 static vop_lookup_t nwfs_lookup;
76 static vop_rename_t nwfs_rename;
77 static vop_mkdir_t nwfs_mkdir;
78 static vop_rmdir_t nwfs_rmdir;
79 static vop_symlink_t nwfs_symlink;
80 static vop_readdir_t nwfs_readdir;
81 static vop_strategy_t nwfs_strategy;
82 static vop_print_t nwfs_print;
83 static vop_pathconf_t nwfs_pathconf;
85 /* Global vfs data structures for nwfs */
86 struct vop_vector nwfs_vnodeops = {
87 .vop_default = &default_vnodeops,
88 .vop_access = nwfs_access,
89 .vop_open = nwfs_open,
90 .vop_close = nwfs_close,
91 .vop_create = nwfs_create,
92 .vop_fsync = nwfs_fsync,
93 .vop_getattr = nwfs_getattr,
94 .vop_getpages = nwfs_getpages,
95 .vop_putpages = nwfs_putpages,
96 .vop_ioctl = nwfs_ioctl,
97 .vop_inactive = nwfs_inactive,
98 .vop_link = nwfs_link,
99 .vop_lookup = nwfs_lookup,
100 .vop_mkdir = nwfs_mkdir,
101 .vop_mknod = nwfs_mknod,
102 .vop_pathconf = nwfs_pathconf,
103 .vop_print = nwfs_print,
104 .vop_read = nwfs_read,
105 .vop_readdir = nwfs_readdir,
106 .vop_reclaim = nwfs_reclaim,
107 .vop_remove = nwfs_remove,
108 .vop_rename = nwfs_rename,
109 .vop_rmdir = nwfs_rmdir,
110 .vop_setattr = nwfs_setattr,
111 .vop_strategy = nwfs_strategy,
112 .vop_symlink = nwfs_symlink,
113 .vop_write = nwfs_write,
117 * nwfs_access vnode op
121 struct vop_access_args /* {
124 struct ucred *a_cred;
128 struct vnode *vp = ap->a_vp;
130 struct nwmount *nmp = VTONWFS(vp);
133 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
134 switch (vp->v_type) {
135 case VREG: case VDIR: case VLNK:
141 mpmode = vp->v_type == VREG ? nmp->m.file_mode :
143 return (vaccess(vp->v_type, mpmode, nmp->m.uid,
144 nmp->m.gid, ap->a_mode, ap->a_cred, NULL));
152 struct vop_open_args /* {
155 struct ucred *a_cred;
159 struct vnode *vp = ap->a_vp;
160 int mode = ap->a_mode;
161 struct nwnode *np = VTONW(vp);
162 struct ncp_open_info no;
163 struct nwmount *nmp = VTONWFS(vp);
167 NCPVNDEBUG("%s,%d\n", np->n_name, np->opened);
168 if (vp->v_type != VREG && vp->v_type != VDIR) {
169 NCPFATAL("open vtype = %d\n", vp->v_type);
172 if (vp->v_type == VDIR) return 0; /* nothing to do now */
173 if (np->n_flag & NMODIFIED) {
174 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1)) == EINTR)
177 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
178 if (error) return (error);
179 np->n_mtime = vattr.va_mtime.tv_sec;
181 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
182 if (error) return (error);
183 if (np->n_mtime != vattr.va_mtime.tv_sec) {
184 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1)) == EINTR)
186 np->n_mtime = vattr.va_mtime.tv_sec;
194 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
196 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
197 0, nwm, &no, ap->a_td, ap->a_cred);
202 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
203 nwm, &no, ap->a_td, ap->a_cred);
208 np->n_origfh = no.origfh;
216 struct vop_close_args /* {
217 struct vnodeop_desc *a_desc;
220 struct ucred *a_cred;
224 struct vnode *vp = ap->a_vp;
225 struct nwnode *np = VTONW(vp);
228 NCPVNDEBUG("name=%s,pid=%d,c=%d\n", np->n_name, ap->a_td->td_proc->p_pid,
231 if (vp->v_type == VDIR) return 0; /* nothing to do now */
233 mtx_lock(&vp->v_interlock);
234 if (np->opened == 0) {
235 mtx_unlock(&vp->v_interlock);
238 mtx_unlock(&vp->v_interlock);
239 error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1);
240 mtx_lock(&vp->v_interlock);
241 if (np->opened == 0) {
242 mtx_unlock(&vp->v_interlock);
245 if (--np->opened == 0) {
246 mtx_unlock(&vp->v_interlock);
247 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
248 ap->a_td, ap->a_cred);
250 mtx_unlock(&vp->v_interlock);
256 * nwfs_getattr call from vfs.
260 struct vop_getattr_args /* {
263 struct ucred *a_cred;
267 struct vnode *vp = ap->a_vp;
268 struct nwnode *np = VTONW(vp);
269 struct vattr *va=ap->a_vap;
270 struct nwmount *nmp = VTONWFS(vp);
271 struct nw_entry_info fattr;
275 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
276 error = nwfs_attr_cachelookup(vp, va);
277 if (!error) return 0;
278 NCPVNDEBUG("not in cache\n");
279 oldsize = np->n_size;
280 if (np->n_flag & NVOLUME) {
281 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
282 ap->a_td, ap->a_cred);
284 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
285 np->n_name, &fattr, ap->a_td, ap->a_cred);
288 NCPVNDEBUG("error %d\n", error);
291 nwfs_attr_cacheenter(vp, &fattr);
294 np->n_size = oldsize;
298 * nwfs_setattr call from vfs.
302 struct vop_setattr_args /* {
305 struct ucred *a_cred;
309 struct vnode *vp = ap->a_vp;
310 struct nwnode *np = VTONW(vp);
311 struct vattr *vap = ap->a_vap;
316 if (vap->va_flags != VNOVAL)
319 * Disallow write attempts if the filesystem is mounted read-only.
321 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
322 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
323 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
325 if (vap->va_size != VNOVAL) {
326 switch (vp->v_type) {
331 * Disallow write attempts if the filesystem is
334 if (vp->v_mount->mnt_flag & MNT_RDONLY)
336 vnode_pager_setsize(vp, (u_long)vap->va_size);
338 np->n_size = vap->va_size;
344 error = ncp_setattr(vp, vap, ap->a_cred, ap->a_td);
345 if (error && vap->va_size != VNOVAL) {
347 vnode_pager_setsize(vp, (u_long)tsize);
349 np->n_atime = 0; /* invalidate cache */
350 VOP_GETATTR(vp, vap, ap->a_cred, ap->a_td);
351 np->n_mtime = vap->va_mtime.tv_sec;
359 struct vop_read_args /* {
363 struct ucred *a_cred;
366 struct vnode *vp = ap->a_vp;
367 struct uio *uio=ap->a_uio;
369 NCPVNDEBUG("nwfs_read:\n");
371 if (vp->v_type != VREG && vp->v_type != VDIR)
373 error = nwfs_readvnode(vp, uio, ap->a_cred);
379 struct vop_write_args /* {
383 struct ucred *a_cred;
386 struct vnode *vp = ap->a_vp;
387 struct uio *uio = ap->a_uio;
390 NCPVNDEBUG("%d,ofs=%d,sz=%d\n", vp->v_type, (int)uio->uio_offset, uio->uio_resid);
392 if (vp->v_type != VREG)
394 error = nwfs_writevnode(vp, uio, ap->a_cred, ap->a_ioflag);
399 * Create a regular file. On entry the directory to contain the file being
400 * created is locked. We must release before we return. We must also free
401 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
402 * only if the SAVESTART bit in cn_flags is clear on success.
406 struct vop_create_args /* {
408 struct vnode **a_vpp;
409 struct componentname *a_cnp;
413 struct vnode *dvp = ap->a_dvp;
414 struct vattr *vap = ap->a_vap;
415 struct vnode **vpp=ap->a_vpp;
416 struct componentname *cnp = ap->a_cnp;
417 struct vnode *vp = (struct vnode *)0;
418 int error = 0, fmode;
421 struct ncp_open_info no;
422 struct nwmount *nmp=VTONWFS(dvp);
428 if (vap->va_type == VSOCK)
430 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
433 fmode = AR_READ | AR_WRITE;
434 /* if (vap->va_vaflags & VA_EXCLUSIVE)
435 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
437 error = ncp_open_create_file_or_subdir(nmp, dvp, cnp->cn_namelen, cnp->cn_nameptr,
438 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
439 0, fmode, &no, cnp->cn_thread, cnp->cn_cred);
441 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_thread, cnp->cn_cred);
442 fid.f_parent = VTONW(dvp)->n_fid.f_id;
443 fid.f_id = no.fattr.dirEntNum;
444 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
450 if (cnp->cn_flags & MAKEENTRY)
451 cache_enter(dvp, vp, cnp);
457 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
458 * NetWare doesn't allow delete/rename operations on an opened file.
462 struct vop_remove_args /* {
463 struct vnodeop_desc *a_desc;
464 struct vnode * a_dvp;
466 struct componentname * a_cnp;
469 struct vnode *vp = ap->a_vp;
470 struct vnode *dvp = ap->a_dvp;
471 struct componentname *cnp = ap->a_cnp;
472 struct nwnode *np = VTONW(vp);
473 struct nwmount *nmp = VTONWFS(vp);
476 if (vp->v_type == VDIR || np->opened || vrefcnt(vp) != 1)
479 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
480 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
482 np->n_flag |= NSHOULDFREE;
483 else if (error == 0x899c)
489 * nwfs_file rename call
493 struct vop_rename_args /* {
494 struct vnode *a_fdvp;
496 struct componentname *a_fcnp;
497 struct vnode *a_tdvp;
499 struct componentname *a_tcnp;
502 struct vnode *fvp = ap->a_fvp;
503 struct vnode *tvp = ap->a_tvp;
504 struct vnode *fdvp = ap->a_fdvp;
505 struct vnode *tdvp = ap->a_tdvp;
506 struct componentname *tcnp = ap->a_tcnp;
507 struct componentname *fcnp = ap->a_fcnp;
508 struct nwmount *nmp=VTONWFS(fvp);
509 u_int16_t oldtype = 6;
512 /* Check for cross-device rename */
513 if ((fvp->v_mount != tdvp->v_mount) ||
514 (tvp && (fvp->v_mount != tvp->v_mount))) {
519 if (tvp && vrefcnt(tvp) > 1) {
523 if (fvp->v_type == VDIR) {
524 oldtype |= NW_TYPE_SUBDIR;
525 } else if (fvp->v_type == VREG) {
526 oldtype |= NW_TYPE_FILE;
531 if (tvp && tvp != fvp) {
532 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
533 tcnp->cn_namelen, tcnp->cn_nameptr,
534 tcnp->cn_thread, tcnp->cn_cred);
535 if (error == 0x899c) error = EACCES;
539 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
540 oldtype, &nmp->m.nls,
541 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
542 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
543 tcnp->cn_thread, tcnp->cn_cred);
547 if (fvp->v_type == VDIR) {
548 if (tvp != NULL && tvp->v_type == VDIR)
553 nwfs_attr_cacheremove(fdvp);
554 nwfs_attr_cacheremove(tdvp);
555 nwfs_attr_cacheremove(fvp);
566 nwfs_attr_cacheremove(tvp);
568 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
576 * nwfs hard link create call
577 * Netware filesystems don't know what links are.
581 struct vop_link_args /* {
582 struct vnode *a_tdvp;
584 struct componentname *a_cnp;
591 * nwfs_symlink link create call
592 * Netware filesystems don't know what symlinks are.
596 struct vop_symlink_args /* {
598 struct vnode **a_vpp;
599 struct componentname *a_cnp;
607 static int nwfs_mknod(ap)
608 struct vop_mknod_args /* {
619 struct vop_mkdir_args /* {
621 struct vnode **a_vpp;
622 struct componentname *a_cnp;
626 struct vnode *dvp = ap->a_dvp;
627 /* struct vattr *vap = ap->a_vap;*/
628 struct componentname *cnp = ap->a_cnp;
629 int len=cnp->cn_namelen;
630 struct ncp_open_info no;
632 struct vnode *newvp = (struct vnode *)0;
636 char *name=cnp->cn_nameptr;
638 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
641 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
644 if (ncp_open_create_file_or_subdir(VTONWFS(dvp), dvp, cnp->cn_namelen,
645 cnp->cn_nameptr, OC_MODE_CREATE, aDIR, 0xffff,
646 &no, cnp->cn_thread, cnp->cn_cred) != 0) {
652 fid.f_parent = VTONW(dvp)->n_fid.f_id;
653 fid.f_id = no.fattr.dirEntNum;
654 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
657 newvp->v_type = VDIR;
665 * nwfs_remove directory call
669 struct vop_rmdir_args /* {
672 struct componentname *a_cnp;
675 struct vnode *vp = ap->a_vp;
676 struct vnode *dvp = ap->a_dvp;
677 struct componentname *cnp = ap->a_cnp;
678 struct nwnode *np = VTONW(vp);
679 struct nwmount *nmp = VTONWFS(vp);
680 struct nwnode *dnp = VTONW(dvp);
686 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
687 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
689 np->n_flag |= NSHOULDFREE;
690 else if (error == NWE_DIR_NOT_EMPTY)
692 dnp->n_flag |= NMODIFIED;
693 nwfs_attr_cacheremove(dvp);
704 struct vop_readdir_args /* {
707 struct ucred *a_cred;
713 struct vnode *vp = ap->a_vp;
714 struct uio *uio = ap->a_uio;
717 if (vp->v_type != VDIR)
719 if (ap->a_ncookies) {
720 printf("nwfs_readdir: no support for cookies now...");
724 error = nwfs_readvnode(vp, uio, ap->a_cred);
730 struct vop_fsync_args /* {
731 struct vnodeop_desc *a_desc;
733 struct ucred * a_cred;
738 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
745 struct vop_print_args /* {
749 struct vnode *vp = ap->a_vp;
750 struct nwnode *np = VTONW(vp);
752 printf("\tnwfs node: name = '%s', fid = %d, pfid = %d\n",
753 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
757 static int nwfs_pathconf (ap)
758 struct vop_pathconf_args /* {
764 int name=ap->a_name, error=0;
765 register_t *retval=ap->a_retval;
772 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
775 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
783 static int nwfs_strategy (ap)
784 struct vop_strategy_args /* {
788 struct buf *bp=ap->a_bp;
794 if (bp->b_flags & B_ASYNC)
795 td = (struct thread *)0;
797 td = curthread; /* XXX */
798 if (bp->b_iocmd == BIO_READ)
803 * If the op is asynchronous and an i/o daemon is waiting
804 * queue the request, wake it up and wait for completion
805 * otherwise just do it ourselves.
807 if ((bp->b_flags & B_ASYNC) == 0 )
808 error = nwfs_doio(ap->a_vp, bp, cr, td);
814 * How to keep the brain busy ...
815 * Currently lookup routine can make two lookup for vnode. This can be
816 * avoided by reorg the code.
820 struct vop_lookup_args /* {
821 struct vnodeop_desc *a_desc;
823 struct vnode **a_vpp;
824 struct componentname *a_cnp;
827 struct componentname *cnp = ap->a_cnp;
828 struct vnode *dvp = ap->a_dvp;
829 struct vnode **vpp = ap->a_vpp;
830 int flags = cnp->cn_flags;
833 struct mount *mp = dvp->v_mount;
834 struct nwnode *dnp, *npp;
835 struct nw_entry_info fattr, *fap;
837 int nameiop=cnp->cn_nameiop, islastcn;
838 int lockparent, wantparent, error = 0, notfound;
839 struct thread *td = cnp->cn_thread;
840 char _name[cnp->cn_namelen+1];
841 bcopy(cnp->cn_nameptr, _name, cnp->cn_namelen);
842 _name[cnp->cn_namelen]=0;
844 if (dvp->v_type != VDIR)
846 if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
847 printf("nwfs_lookup: invalid '..'\n");
851 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
852 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
854 islastcn = flags & ISLASTCN;
855 if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
857 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)))
859 lockparent = flags & LOCKPARENT;
860 wantparent = flags & (LOCKPARENT|WANTPARENT);
864 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_vflag & VV_ROOT, (int)flags & ISDOTDOT);
866 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
867 (nameiop == CREATE || nameiop == RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
871 error = cache_lookup(dvp, vpp, cnp);
872 NCPVNDEBUG("cache_lookup returned %d\n", error);
875 if (error) { /* name was found */
881 if (dvp == vp) { /* lookup on current */
884 NCPVNDEBUG("cached '.'");
885 } else if (flags & ISDOTDOT) {
886 VOP_UNLOCK(dvp, 0, td); /* unlock parent */
887 error = vget(vp, LK_EXCLUSIVE, td);
888 if (!error && lockparent && islastcn)
889 error = vn_lock(dvp, LK_EXCLUSIVE, td);
891 error = vget(vp, LK_EXCLUSIVE, td);
892 if (!lockparent || error || !islastcn)
893 VOP_UNLOCK(dvp, 0, td);
896 if (vpid == vp->v_id) {
897 if (!VOP_GETATTR(vp, &vattr, cnp->cn_cred, td)
898 && vattr.va_ctime.tv_sec == VTONW(vp)->n_ctime) {
899 if (nameiop != LOOKUP && islastcn)
900 cnp->cn_flags |= SAVENAME;
901 NCPVNDEBUG("use cached vnode");
907 if (lockparent && dvp != vp && islastcn)
908 VOP_UNLOCK(dvp, 0, td);
910 error = vn_lock(dvp, LK_EXCLUSIVE, td);
915 /* not in cache, so ... */
919 if (flags & ISDOTDOT) {
920 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
921 fid = nmp->n_rootent;
925 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
932 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
933 0, NULL, fap, td, cnp->cn_cred);
937 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
938 fap, td, cnp->cn_cred);
939 fid.f_id = fap->dirEntNum;
940 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
941 fid.f_parent = dnp->n_fid.f_parent;
943 fid.f_parent = dnp->n_fid.f_id;
944 NCPVNDEBUG("call to ncp_lookup returned=%d\n", notfound);
946 if (notfound && notfound < 0x80 )
947 return (notfound); /* hard error */
948 if (notfound) { /* entry not found */
949 /* Handle RENAME or CREATE case... */
950 if ((nameiop == CREATE || nameiop == RENAME) && wantparent && islastcn) {
951 cnp->cn_flags |= SAVENAME;
953 VOP_UNLOCK(dvp, 0, td);
954 return (EJUSTRETURN);
958 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
960 /* handle DELETE case ... */
961 if (nameiop == DELETE && islastcn) { /* delete last component */
962 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
963 if (error) return (error);
964 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
969 error = nwfs_nget(mp, fid, fap, dvp, &vp);
970 if (error) return (error);
972 cnp->cn_flags |= SAVENAME; /* I free it later */
973 if (!lockparent) VOP_UNLOCK(dvp, 0, td);
976 if (nameiop == RENAME && islastcn && wantparent) {
977 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
978 if (error) return (error);
979 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
980 error = nwfs_nget(mp, fid, fap, dvp, &vp);
981 if (error) return (error);
983 cnp->cn_flags |= SAVENAME;
985 VOP_UNLOCK(dvp, 0, td);
988 if (flags & ISDOTDOT) {
989 VOP_UNLOCK(dvp, 0, td); /* race to get the inode */
990 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
992 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
995 if (lockparent && islastcn &&
996 (error = vn_lock(dvp, LK_EXCLUSIVE, td))) {
1001 } else if (NWCMPF(&dnp->n_fid, &fid)) {
1005 error = nwfs_nget(mp, fid, fap, dvp, &vp);
1006 if (error) return (error);
1008 NCPVNDEBUG("lookup: getnewvp!\n");
1009 if (!lockparent || !islastcn)
1010 VOP_UNLOCK(dvp, 0, td);
1012 if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
1013 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
1014 cache_enter(dvp, *vpp, cnp);