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,
89 .vop_access = nwfs_access,
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_inactive = nwfs_inactive,
96 .vop_ioctl = nwfs_ioctl,
97 .vop_link = nwfs_link,
98 .vop_lookup = nwfs_lookup,
99 .vop_mkdir = nwfs_mkdir,
100 .vop_mknod = nwfs_mknod,
101 .vop_open = nwfs_open,
102 .vop_pathconf = nwfs_pathconf,
103 .vop_print = nwfs_print,
104 .vop_putpages = nwfs_putpages,
105 .vop_read = nwfs_read,
106 .vop_readdir = nwfs_readdir,
107 .vop_reclaim = nwfs_reclaim,
108 .vop_remove = nwfs_remove,
109 .vop_rename = nwfs_rename,
110 .vop_rmdir = nwfs_rmdir,
111 .vop_setattr = nwfs_setattr,
112 .vop_strategy = nwfs_strategy,
113 .vop_symlink = nwfs_symlink,
114 .vop_write = nwfs_write,
118 * nwfs_access vnode op
122 struct vop_access_args /* {
125 struct ucred *a_cred;
129 struct vnode *vp = ap->a_vp;
131 struct nwmount *nmp = VTONWFS(vp);
134 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
135 switch (vp->v_type) {
136 case VREG: case VDIR: case VLNK:
142 mpmode = vp->v_type == VREG ? nmp->m.file_mode :
144 return (vaccess(vp->v_type, mpmode, nmp->m.uid,
145 nmp->m.gid, ap->a_mode, ap->a_cred, NULL));
153 struct vop_open_args /* {
156 struct ucred *a_cred;
160 struct vnode *vp = ap->a_vp;
161 int mode = ap->a_mode;
162 struct nwnode *np = VTONW(vp);
163 struct ncp_open_info no;
164 struct nwmount *nmp = VTONWFS(vp);
168 NCPVNDEBUG("%s,%d\n", np->n_name, np->opened);
169 if (vp->v_type != VREG && vp->v_type != VDIR) {
170 NCPFATAL("open vtype = %d\n", vp->v_type);
173 if (vp->v_type == VDIR) return 0; /* nothing to do now */
174 if (np->n_flag & NMODIFIED) {
175 if ((error = nwfs_vinvalbuf(vp, ap->a_td)) == EINTR)
178 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
179 if (error) return (error);
180 np->n_mtime = vattr.va_mtime.tv_sec;
182 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
183 if (error) return (error);
184 if (np->n_mtime != vattr.va_mtime.tv_sec) {
185 if ((error = nwfs_vinvalbuf(vp, ap->a_td)) == EINTR)
187 np->n_mtime = vattr.va_mtime.tv_sec;
195 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
197 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
198 0, nwm, &no, ap->a_td, ap->a_cred);
203 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
204 nwm, &no, ap->a_td, ap->a_cred);
209 np->n_origfh = no.origfh;
217 struct vop_close_args /* {
218 struct vnodeop_desc *a_desc;
221 struct ucred *a_cred;
225 struct vnode *vp = ap->a_vp;
226 struct nwnode *np = VTONW(vp);
229 NCPVNDEBUG("name=%s,pid=%d,c=%d\n", np->n_name, ap->a_td->td_proc->p_pid,
232 if (vp->v_type == VDIR) return 0; /* nothing to do now */
234 mtx_lock(&vp->v_interlock);
235 if (np->opened == 0) {
236 mtx_unlock(&vp->v_interlock);
239 mtx_unlock(&vp->v_interlock);
240 error = nwfs_vinvalbuf(vp, ap->a_td);
241 mtx_lock(&vp->v_interlock);
242 if (np->opened == 0) {
243 mtx_unlock(&vp->v_interlock);
246 if (--np->opened == 0) {
247 mtx_unlock(&vp->v_interlock);
248 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
249 ap->a_td, ap->a_cred);
251 mtx_unlock(&vp->v_interlock);
257 * nwfs_getattr call from vfs.
261 struct vop_getattr_args /* {
264 struct ucred *a_cred;
268 struct vnode *vp = ap->a_vp;
269 struct nwnode *np = VTONW(vp);
270 struct vattr *va=ap->a_vap;
271 struct nwmount *nmp = VTONWFS(vp);
272 struct nw_entry_info fattr;
276 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
277 error = nwfs_attr_cachelookup(vp, va);
278 if (!error) return 0;
279 NCPVNDEBUG("not in cache\n");
280 oldsize = np->n_size;
281 if (np->n_flag & NVOLUME) {
282 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
283 ap->a_td, ap->a_cred);
285 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
286 np->n_name, &fattr, ap->a_td, ap->a_cred);
289 NCPVNDEBUG("error %d\n", error);
292 nwfs_attr_cacheenter(vp, &fattr);
295 np->n_size = oldsize;
299 * nwfs_setattr call from vfs.
303 struct vop_setattr_args /* {
306 struct ucred *a_cred;
310 struct vnode *vp = ap->a_vp;
311 struct nwnode *np = VTONW(vp);
312 struct vattr *vap = ap->a_vap;
317 if (vap->va_flags != VNOVAL)
320 * Disallow write attempts if the filesystem is mounted read-only.
322 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
323 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
324 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
326 if (vap->va_size != VNOVAL) {
327 switch (vp->v_type) {
332 * Disallow write attempts if the filesystem is
335 if (vp->v_mount->mnt_flag & MNT_RDONLY)
337 vnode_pager_setsize(vp, (u_long)vap->va_size);
339 np->n_size = vap->va_size;
345 error = ncp_setattr(vp, vap, ap->a_cred, ap->a_td);
346 if (error && vap->va_size != VNOVAL) {
348 vnode_pager_setsize(vp, (u_long)tsize);
350 np->n_atime = 0; /* invalidate cache */
351 VOP_GETATTR(vp, vap, ap->a_cred, ap->a_td);
352 np->n_mtime = vap->va_mtime.tv_sec;
360 struct vop_read_args /* {
364 struct ucred *a_cred;
367 struct vnode *vp = ap->a_vp;
368 struct uio *uio=ap->a_uio;
370 NCPVNDEBUG("nwfs_read:\n");
372 if (vp->v_type != VREG && vp->v_type != VDIR)
374 error = nwfs_readvnode(vp, uio, ap->a_cred);
380 struct vop_write_args /* {
384 struct ucred *a_cred;
387 struct vnode *vp = ap->a_vp;
388 struct uio *uio = ap->a_uio;
391 NCPVNDEBUG("%d,ofs=%d,sz=%d\n", vp->v_type, (int)uio->uio_offset, uio->uio_resid);
393 if (vp->v_type != VREG)
395 error = nwfs_writevnode(vp, uio, ap->a_cred, ap->a_ioflag);
400 * Create a regular file. On entry the directory to contain the file being
401 * created is locked. We must release before we return. We must also free
402 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
403 * only if the SAVESTART bit in cn_flags is clear on success.
407 struct vop_create_args /* {
409 struct vnode **a_vpp;
410 struct componentname *a_cnp;
414 struct vnode *dvp = ap->a_dvp;
415 struct vattr *vap = ap->a_vap;
416 struct vnode **vpp=ap->a_vpp;
417 struct componentname *cnp = ap->a_cnp;
418 struct vnode *vp = (struct vnode *)0;
419 int error = 0, fmode;
422 struct ncp_open_info no;
423 struct nwmount *nmp=VTONWFS(dvp);
429 if (vap->va_type == VSOCK)
431 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
434 fmode = AR_READ | AR_WRITE;
435 /* if (vap->va_vaflags & VA_EXCLUSIVE)
436 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
438 error = ncp_open_create_file_or_subdir(nmp, dvp, cnp->cn_namelen, cnp->cn_nameptr,
439 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
440 0, fmode, &no, cnp->cn_thread, cnp->cn_cred);
442 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_thread, cnp->cn_cred);
443 fid.f_parent = VTONW(dvp)->n_fid.f_id;
444 fid.f_id = no.fattr.dirEntNum;
445 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
451 if (cnp->cn_flags & MAKEENTRY)
452 cache_enter(dvp, vp, cnp);
458 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
459 * NetWare doesn't allow delete/rename operations on an opened file.
463 struct vop_remove_args /* {
464 struct vnodeop_desc *a_desc;
465 struct vnode * a_dvp;
467 struct componentname * a_cnp;
470 struct vnode *vp = ap->a_vp;
471 struct vnode *dvp = ap->a_dvp;
472 struct componentname *cnp = ap->a_cnp;
473 struct nwnode *np = VTONW(vp);
474 struct nwmount *nmp = VTONWFS(vp);
477 if (vp->v_type == VDIR || np->opened || vrefcnt(vp) != 1)
480 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
481 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
483 np->n_flag |= NSHOULDFREE;
484 else if (error == 0x899c)
490 * nwfs_file rename call
494 struct vop_rename_args /* {
495 struct vnode *a_fdvp;
497 struct componentname *a_fcnp;
498 struct vnode *a_tdvp;
500 struct componentname *a_tcnp;
503 struct vnode *fvp = ap->a_fvp;
504 struct vnode *tvp = ap->a_tvp;
505 struct vnode *fdvp = ap->a_fdvp;
506 struct vnode *tdvp = ap->a_tdvp;
507 struct componentname *tcnp = ap->a_tcnp;
508 struct componentname *fcnp = ap->a_fcnp;
509 struct nwmount *nmp=VTONWFS(fvp);
510 u_int16_t oldtype = 6;
513 /* Check for cross-device rename */
514 if ((fvp->v_mount != tdvp->v_mount) ||
515 (tvp && (fvp->v_mount != tvp->v_mount))) {
520 if (tvp && vrefcnt(tvp) > 1) {
524 if (fvp->v_type == VDIR) {
525 oldtype |= NW_TYPE_SUBDIR;
526 } else if (fvp->v_type == VREG) {
527 oldtype |= NW_TYPE_FILE;
532 if (tvp && tvp != fvp) {
533 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
534 tcnp->cn_namelen, tcnp->cn_nameptr,
535 tcnp->cn_thread, tcnp->cn_cred);
536 if (error == 0x899c) error = EACCES;
540 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
541 oldtype, &nmp->m.nls,
542 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
543 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
544 tcnp->cn_thread, tcnp->cn_cred);
548 if (fvp->v_type == VDIR) {
549 if (tvp != NULL && tvp->v_type == VDIR)
554 nwfs_attr_cacheremove(fdvp);
555 nwfs_attr_cacheremove(tdvp);
556 nwfs_attr_cacheremove(fvp);
567 nwfs_attr_cacheremove(tvp);
569 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
577 * nwfs hard link create call
578 * Netware filesystems don't know what links are.
582 struct vop_link_args /* {
583 struct vnode *a_tdvp;
585 struct componentname *a_cnp;
592 * nwfs_symlink link create call
593 * Netware filesystems don't know what symlinks are.
597 struct vop_symlink_args /* {
599 struct vnode **a_vpp;
600 struct componentname *a_cnp;
608 static int nwfs_mknod(ap)
609 struct vop_mknod_args /* {
620 struct vop_mkdir_args /* {
622 struct vnode **a_vpp;
623 struct componentname *a_cnp;
627 struct vnode *dvp = ap->a_dvp;
628 /* struct vattr *vap = ap->a_vap;*/
629 struct componentname *cnp = ap->a_cnp;
630 int len=cnp->cn_namelen;
631 struct ncp_open_info no;
633 struct vnode *newvp = (struct vnode *)0;
637 char *name=cnp->cn_nameptr;
639 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
642 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
645 if (ncp_open_create_file_or_subdir(VTONWFS(dvp), dvp, cnp->cn_namelen,
646 cnp->cn_nameptr, OC_MODE_CREATE, aDIR, 0xffff,
647 &no, cnp->cn_thread, cnp->cn_cred) != 0) {
653 fid.f_parent = VTONW(dvp)->n_fid.f_id;
654 fid.f_id = no.fattr.dirEntNum;
655 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
658 newvp->v_type = VDIR;
666 * nwfs_remove directory call
670 struct vop_rmdir_args /* {
673 struct componentname *a_cnp;
676 struct vnode *vp = ap->a_vp;
677 struct vnode *dvp = ap->a_dvp;
678 struct componentname *cnp = ap->a_cnp;
679 struct nwnode *np = VTONW(vp);
680 struct nwmount *nmp = VTONWFS(vp);
681 struct nwnode *dnp = VTONW(dvp);
687 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
688 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
690 np->n_flag |= NSHOULDFREE;
691 else if (error == NWE_DIR_NOT_EMPTY)
693 dnp->n_flag |= NMODIFIED;
694 nwfs_attr_cacheremove(dvp);
705 struct vop_readdir_args /* {
708 struct ucred *a_cred;
714 struct vnode *vp = ap->a_vp;
715 struct uio *uio = ap->a_uio;
718 if (vp->v_type != VDIR)
720 if (ap->a_ncookies) {
721 printf("nwfs_readdir: no support for cookies now...");
725 error = nwfs_readvnode(vp, uio, ap->a_cred);
731 struct vop_fsync_args /* {
732 struct vnodeop_desc *a_desc;
734 struct ucred * a_cred;
739 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
746 struct vop_print_args /* {
750 struct vnode *vp = ap->a_vp;
751 struct nwnode *np = VTONW(vp);
753 printf("\tnwfs node: name = '%s', fid = %d, pfid = %d\n",
754 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
758 static int nwfs_pathconf (ap)
759 struct vop_pathconf_args /* {
765 int name=ap->a_name, error=0;
766 register_t *retval=ap->a_retval;
773 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
776 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
784 static int nwfs_strategy (ap)
785 struct vop_strategy_args /* {
789 struct buf *bp=ap->a_bp;
795 if (bp->b_flags & B_ASYNC)
796 td = (struct thread *)0;
798 td = curthread; /* XXX */
799 if (bp->b_iocmd == BIO_READ)
804 * If the op is asynchronous and an i/o daemon is waiting
805 * queue the request, wake it up and wait for completion
806 * otherwise just do it ourselves.
808 if ((bp->b_flags & B_ASYNC) == 0 )
809 error = nwfs_doio(ap->a_vp, bp, cr, td);
815 * How to keep the brain busy ...
816 * Currently lookup routine can make two lookup for vnode. This can be
817 * avoided by reorg the code.
821 struct vop_lookup_args /* {
822 struct vnodeop_desc *a_desc;
824 struct vnode **a_vpp;
825 struct componentname *a_cnp;
828 struct componentname *cnp = ap->a_cnp;
829 struct vnode *dvp = ap->a_dvp;
830 struct vnode **vpp = ap->a_vpp;
831 int flags = cnp->cn_flags;
834 struct mount *mp = dvp->v_mount;
835 struct nwnode *dnp, *npp;
836 struct nw_entry_info fattr, *fap;
838 int nameiop=cnp->cn_nameiop, islastcn;
839 int error = 0, notfound;
840 struct thread *td = cnp->cn_thread;
841 char _name[cnp->cn_namelen+1];
842 bcopy(cnp->cn_nameptr, _name, cnp->cn_namelen);
843 _name[cnp->cn_namelen]=0;
845 if (dvp->v_type != VDIR)
847 if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
848 printf("nwfs_lookup: invalid '..'\n");
852 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
853 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
855 islastcn = flags & ISLASTCN;
856 if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
858 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)))
863 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_vflag & VV_ROOT, (int)flags & ISDOTDOT);
865 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
866 (nameiop == CREATE || nameiop == RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
870 error = cache_lookup(dvp, vpp, cnp);
871 NCPVNDEBUG("cache_lookup returned %d\n", error);
874 if (error) { /* name was found */
879 if (dvp == vp) { /* lookup on current */
882 NCPVNDEBUG("cached '.'");
883 } else if (flags & ISDOTDOT) {
884 VOP_UNLOCK(dvp, 0, td); /* unlock parent */
885 error = vget(vp, LK_EXCLUSIVE, td);
886 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
888 error = vget(vp, LK_EXCLUSIVE, td);
890 if (!VOP_GETATTR(vp, &vattr, cnp->cn_cred, td)
891 && vattr.va_ctime.tv_sec == VTONW(vp)->n_ctime) {
892 if (nameiop != LOOKUP && islastcn)
893 cnp->cn_flags |= SAVENAME;
894 NCPVNDEBUG("use cached vnode");
907 /* not in cache, so ... */
911 if (flags & ISDOTDOT) {
912 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
913 fid = nmp->n_rootent;
917 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
924 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
925 0, NULL, fap, td, cnp->cn_cred);
929 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
930 fap, td, cnp->cn_cred);
931 fid.f_id = fap->dirEntNum;
932 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
933 fid.f_parent = dnp->n_fid.f_parent;
935 fid.f_parent = dnp->n_fid.f_id;
936 NCPVNDEBUG("call to ncp_lookup returned=%d\n", notfound);
938 if (notfound && notfound < 0x80 )
939 return (notfound); /* hard error */
940 if (notfound) { /* entry not found */
941 /* Handle RENAME or CREATE case... */
942 if ((nameiop == CREATE || nameiop == RENAME) && islastcn) {
943 cnp->cn_flags |= SAVENAME;
944 return (EJUSTRETURN);
948 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
950 /* handle DELETE case ... */
951 if (nameiop == DELETE && islastcn) { /* delete last component */
952 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
953 if (error) return (error);
954 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
959 error = nwfs_nget(mp, fid, fap, dvp, &vp);
960 if (error) return (error);
962 cnp->cn_flags |= SAVENAME; /* I free it later */
965 if (nameiop == RENAME && islastcn) {
966 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
967 if (error) return (error);
968 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
969 error = nwfs_nget(mp, fid, fap, dvp, &vp);
970 if (error) return (error);
972 cnp->cn_flags |= SAVENAME;
975 if (flags & ISDOTDOT) {
976 VOP_UNLOCK(dvp, 0, td); /* race to get the inode */
977 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
978 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
982 } else if (NWCMPF(&dnp->n_fid, &fid)) {
986 error = nwfs_nget(mp, fid, fap, dvp, &vp);
987 if (error) return (error);
989 NCPVNDEBUG("lookup: getnewvp!\n");
991 if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
992 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
993 cache_enter(dvp, *vpp, cnp);