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 int nwfs_create(struct vop_create_args *);
64 static int nwfs_mknod(struct vop_mknod_args *);
65 static int nwfs_open(struct vop_open_args *);
66 static int nwfs_close(struct vop_close_args *);
67 static int nwfs_access(struct vop_access_args *);
68 static int nwfs_getattr(struct vop_getattr_args *);
69 static int nwfs_setattr(struct vop_setattr_args *);
70 static int nwfs_read(struct vop_read_args *);
71 static int nwfs_write(struct vop_write_args *);
72 static int nwfs_fsync(struct vop_fsync_args *);
73 static int nwfs_remove(struct vop_remove_args *);
74 static int nwfs_link(struct vop_link_args *);
75 static int nwfs_lookup(struct vop_lookup_args *);
76 static int nwfs_rename(struct vop_rename_args *);
77 static int nwfs_mkdir(struct vop_mkdir_args *);
78 static int nwfs_rmdir(struct vop_rmdir_args *);
79 static int nwfs_symlink(struct vop_symlink_args *);
80 static int nwfs_readdir(struct vop_readdir_args *);
81 static int nwfs_strategy(struct vop_strategy_args *);
82 static int nwfs_print(struct vop_print_args *);
83 static int nwfs_pathconf(struct vop_pathconf_args *ap);
85 /* Global vfs data structures for nwfs */
86 vop_t **nwfs_vnodeop_p;
87 static struct vnodeopv_entry_desc nwfs_vnodeop_entries[] = {
88 { &vop_default_desc, (vop_t *) vop_defaultop },
89 { &vop_access_desc, (vop_t *) nwfs_access },
90 { &vop_open_desc, (vop_t *) nwfs_open },
91 { &vop_close_desc, (vop_t *) nwfs_close },
92 { &vop_create_desc, (vop_t *) nwfs_create },
93 { &vop_fsync_desc, (vop_t *) nwfs_fsync },
94 { &vop_getattr_desc, (vop_t *) nwfs_getattr },
95 { &vop_getpages_desc, (vop_t *) nwfs_getpages },
96 { &vop_putpages_desc, (vop_t *) nwfs_putpages },
97 { &vop_ioctl_desc, (vop_t *) nwfs_ioctl },
98 { &vop_inactive_desc, (vop_t *) nwfs_inactive },
99 { &vop_link_desc, (vop_t *) nwfs_link },
100 { &vop_lookup_desc, (vop_t *) nwfs_lookup },
101 { &vop_mkdir_desc, (vop_t *) nwfs_mkdir },
102 { &vop_mknod_desc, (vop_t *) nwfs_mknod },
103 { &vop_pathconf_desc, (vop_t *) nwfs_pathconf },
104 { &vop_print_desc, (vop_t *) nwfs_print },
105 { &vop_read_desc, (vop_t *) nwfs_read },
106 { &vop_readdir_desc, (vop_t *) nwfs_readdir },
107 { &vop_reclaim_desc, (vop_t *) nwfs_reclaim },
108 { &vop_remove_desc, (vop_t *) nwfs_remove },
109 { &vop_rename_desc, (vop_t *) nwfs_rename },
110 { &vop_rmdir_desc, (vop_t *) nwfs_rmdir },
111 { &vop_setattr_desc, (vop_t *) nwfs_setattr },
112 { &vop_strategy_desc, (vop_t *) nwfs_strategy },
113 { &vop_symlink_desc, (vop_t *) nwfs_symlink },
114 { &vop_write_desc, (vop_t *) nwfs_write },
117 static struct vnodeopv_desc nwfs_vnodeop_opv_desc =
118 { &nwfs_vnodeop_p, nwfs_vnodeop_entries };
120 VNODEOP_SET(nwfs_vnodeop_opv_desc);
123 * nwfs_access vnode op
127 struct vop_access_args /* {
130 struct ucred *a_cred;
134 struct vnode *vp = ap->a_vp;
136 struct nwmount *nmp = VTONWFS(vp);
139 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
140 switch (vp->v_type) {
141 case VREG: case VDIR: case VLNK:
147 mpmode = vp->v_type == VREG ? nmp->m.file_mode :
149 return (vaccess(vp->v_type, mpmode, nmp->m.uid,
150 nmp->m.gid, ap->a_mode, ap->a_cred, NULL));
158 struct vop_open_args /* {
161 struct ucred *a_cred;
165 struct vnode *vp = ap->a_vp;
166 int mode = ap->a_mode;
167 struct nwnode *np = VTONW(vp);
168 struct ncp_open_info no;
169 struct nwmount *nmp = VTONWFS(vp);
173 NCPVNDEBUG("%s,%d\n", np->n_name, np->opened);
174 if (vp->v_type != VREG && vp->v_type != VDIR) {
175 NCPFATAL("open vtype = %d\n", vp->v_type);
178 if (vp->v_type == VDIR) return 0; /* nothing to do now */
179 if (np->n_flag & NMODIFIED) {
180 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1)) == EINTR)
183 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
184 if (error) return (error);
185 np->n_mtime = vattr.va_mtime.tv_sec;
187 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
188 if (error) return (error);
189 if (np->n_mtime != vattr.va_mtime.tv_sec) {
190 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1)) == EINTR)
192 np->n_mtime = vattr.va_mtime.tv_sec;
200 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
202 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
203 0, nwm, &no, ap->a_td, ap->a_cred);
208 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
209 nwm, &no, ap->a_td, ap->a_cred);
214 np->n_origfh = no.origfh;
222 struct vop_close_args /* {
223 struct vnodeop_desc *a_desc;
226 struct ucred *a_cred;
230 struct vnode *vp = ap->a_vp;
231 struct nwnode *np = VTONW(vp);
234 NCPVNDEBUG("name=%s,pid=%d,c=%d\n", np->n_name, ap->a_td->td_proc->p_pid,
237 if (vp->v_type == VDIR) return 0; /* nothing to do now */
239 mtx_lock(&vp->v_interlock);
240 if (np->opened == 0) {
241 mtx_unlock(&vp->v_interlock);
244 mtx_unlock(&vp->v_interlock);
245 error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1);
246 mtx_lock(&vp->v_interlock);
247 if (np->opened == 0) {
248 mtx_unlock(&vp->v_interlock);
251 if (--np->opened == 0) {
252 mtx_unlock(&vp->v_interlock);
253 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
254 ap->a_td, ap->a_cred);
256 mtx_unlock(&vp->v_interlock);
262 * nwfs_getattr call from vfs.
266 struct vop_getattr_args /* {
269 struct ucred *a_cred;
273 struct vnode *vp = ap->a_vp;
274 struct nwnode *np = VTONW(vp);
275 struct vattr *va=ap->a_vap;
276 struct nwmount *nmp = VTONWFS(vp);
277 struct nw_entry_info fattr;
281 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
282 error = nwfs_attr_cachelookup(vp, va);
283 if (!error) return 0;
284 NCPVNDEBUG("not in cache\n");
285 oldsize = np->n_size;
286 if (np->n_flag & NVOLUME) {
287 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
288 ap->a_td, ap->a_cred);
290 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
291 np->n_name, &fattr, ap->a_td, ap->a_cred);
294 NCPVNDEBUG("error %d\n", error);
297 nwfs_attr_cacheenter(vp, &fattr);
300 np->n_size = oldsize;
304 * nwfs_setattr call from vfs.
308 struct vop_setattr_args /* {
311 struct ucred *a_cred;
315 struct vnode *vp = ap->a_vp;
316 struct nwnode *np = VTONW(vp);
317 struct vattr *vap = ap->a_vap;
322 if (vap->va_flags != VNOVAL)
325 * Disallow write attempts if the filesystem is mounted read-only.
327 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
328 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
329 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
331 if (vap->va_size != VNOVAL) {
332 switch (vp->v_type) {
337 * Disallow write attempts if the filesystem is
340 if (vp->v_mount->mnt_flag & MNT_RDONLY)
342 vnode_pager_setsize(vp, (u_long)vap->va_size);
344 np->n_size = vap->va_size;
350 error = ncp_setattr(vp, vap, ap->a_cred, ap->a_td);
351 if (error && vap->va_size != VNOVAL) {
353 vnode_pager_setsize(vp, (u_long)tsize);
355 np->n_atime = 0; /* invalidate cache */
356 VOP_GETATTR(vp, vap, ap->a_cred, ap->a_td);
357 np->n_mtime = vap->va_mtime.tv_sec;
365 struct vop_read_args /* {
369 struct ucred *a_cred;
372 struct vnode *vp = ap->a_vp;
373 struct uio *uio=ap->a_uio;
375 NCPVNDEBUG("nwfs_read:\n");
377 if (vp->v_type != VREG && vp->v_type != VDIR)
379 error = nwfs_readvnode(vp, uio, ap->a_cred);
385 struct vop_write_args /* {
389 struct ucred *a_cred;
392 struct vnode *vp = ap->a_vp;
393 struct uio *uio = ap->a_uio;
396 NCPVNDEBUG("%d,ofs=%d,sz=%d\n", vp->v_type, (int)uio->uio_offset, uio->uio_resid);
398 if (vp->v_type != VREG)
400 error = nwfs_writevnode(vp, uio, ap->a_cred, ap->a_ioflag);
405 * Create a regular file. On entry the directory to contain the file being
406 * created is locked. We must release before we return. We must also free
407 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
408 * only if the SAVESTART bit in cn_flags is clear on success.
412 struct vop_create_args /* {
414 struct vnode **a_vpp;
415 struct componentname *a_cnp;
419 struct vnode *dvp = ap->a_dvp;
420 struct vattr *vap = ap->a_vap;
421 struct vnode **vpp=ap->a_vpp;
422 struct componentname *cnp = ap->a_cnp;
423 struct vnode *vp = (struct vnode *)0;
424 int error = 0, fmode;
427 struct ncp_open_info no;
428 struct nwmount *nmp=VTONWFS(dvp);
434 if (vap->va_type == VSOCK)
436 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
439 fmode = AR_READ | AR_WRITE;
440 /* if (vap->va_vaflags & VA_EXCLUSIVE)
441 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
443 error = ncp_open_create_file_or_subdir(nmp, dvp, cnp->cn_namelen, cnp->cn_nameptr,
444 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
445 0, fmode, &no, cnp->cn_thread, cnp->cn_cred);
447 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_thread, cnp->cn_cred);
448 fid.f_parent = VTONW(dvp)->n_fid.f_id;
449 fid.f_id = no.fattr.dirEntNum;
450 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
456 if (cnp->cn_flags & MAKEENTRY)
457 cache_enter(dvp, vp, cnp);
463 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
464 * NetWare doesn't allow delete/rename operations on an opened file.
468 struct vop_remove_args /* {
469 struct vnodeop_desc *a_desc;
470 struct vnode * a_dvp;
472 struct componentname * a_cnp;
475 struct vnode *vp = ap->a_vp;
476 struct vnode *dvp = ap->a_dvp;
477 struct componentname *cnp = ap->a_cnp;
478 struct nwnode *np = VTONW(vp);
479 struct nwmount *nmp = VTONWFS(vp);
482 if (vp->v_type == VDIR || np->opened || vrefcnt(vp) != 1)
485 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
486 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
488 np->n_flag |= NSHOULDFREE;
489 else if (error == 0x899c)
495 * nwfs_file rename call
499 struct vop_rename_args /* {
500 struct vnode *a_fdvp;
502 struct componentname *a_fcnp;
503 struct vnode *a_tdvp;
505 struct componentname *a_tcnp;
508 struct vnode *fvp = ap->a_fvp;
509 struct vnode *tvp = ap->a_tvp;
510 struct vnode *fdvp = ap->a_fdvp;
511 struct vnode *tdvp = ap->a_tdvp;
512 struct componentname *tcnp = ap->a_tcnp;
513 struct componentname *fcnp = ap->a_fcnp;
514 struct nwmount *nmp=VTONWFS(fvp);
515 u_int16_t oldtype = 6;
518 /* Check for cross-device rename */
519 if ((fvp->v_mount != tdvp->v_mount) ||
520 (tvp && (fvp->v_mount != tvp->v_mount))) {
525 if (tvp && vrefcnt(tvp) > 1) {
529 if (fvp->v_type == VDIR) {
530 oldtype |= NW_TYPE_SUBDIR;
531 } else if (fvp->v_type == VREG) {
532 oldtype |= NW_TYPE_FILE;
537 if (tvp && tvp != fvp) {
538 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
539 tcnp->cn_namelen, tcnp->cn_nameptr,
540 tcnp->cn_thread, tcnp->cn_cred);
541 if (error == 0x899c) error = EACCES;
545 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
546 oldtype, &nmp->m.nls,
547 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
548 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
549 tcnp->cn_thread, tcnp->cn_cred);
553 if (fvp->v_type == VDIR) {
554 if (tvp != NULL && tvp->v_type == VDIR)
559 nwfs_attr_cacheremove(fdvp);
560 nwfs_attr_cacheremove(tdvp);
561 nwfs_attr_cacheremove(fvp);
572 nwfs_attr_cacheremove(tvp);
574 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
582 * nwfs hard link create call
583 * Netware filesystems don't know what links are.
587 struct vop_link_args /* {
588 struct vnode *a_tdvp;
590 struct componentname *a_cnp;
597 * nwfs_symlink link create call
598 * Netware filesystems don't know what symlinks are.
602 struct vop_symlink_args /* {
604 struct vnode **a_vpp;
605 struct componentname *a_cnp;
613 static int nwfs_mknod(ap)
614 struct vop_mknod_args /* {
625 struct vop_mkdir_args /* {
627 struct vnode **a_vpp;
628 struct componentname *a_cnp;
632 struct vnode *dvp = ap->a_dvp;
633 /* struct vattr *vap = ap->a_vap;*/
634 struct componentname *cnp = ap->a_cnp;
635 int len=cnp->cn_namelen;
636 struct ncp_open_info no;
638 struct vnode *newvp = (struct vnode *)0;
642 char *name=cnp->cn_nameptr;
644 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
647 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
650 if (ncp_open_create_file_or_subdir(VTONWFS(dvp), dvp, cnp->cn_namelen,
651 cnp->cn_nameptr, OC_MODE_CREATE, aDIR, 0xffff,
652 &no, cnp->cn_thread, cnp->cn_cred) != 0) {
658 fid.f_parent = VTONW(dvp)->n_fid.f_id;
659 fid.f_id = no.fattr.dirEntNum;
660 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
663 newvp->v_type = VDIR;
671 * nwfs_remove directory call
675 struct vop_rmdir_args /* {
678 struct componentname *a_cnp;
681 struct vnode *vp = ap->a_vp;
682 struct vnode *dvp = ap->a_dvp;
683 struct componentname *cnp = ap->a_cnp;
684 struct nwnode *np = VTONW(vp);
685 struct nwmount *nmp = VTONWFS(vp);
686 struct nwnode *dnp = VTONW(dvp);
692 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
693 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
695 np->n_flag |= NSHOULDFREE;
696 else if (error == NWE_DIR_NOT_EMPTY)
698 dnp->n_flag |= NMODIFIED;
699 nwfs_attr_cacheremove(dvp);
710 struct vop_readdir_args /* {
713 struct ucred *a_cred;
719 struct vnode *vp = ap->a_vp;
720 struct uio *uio = ap->a_uio;
723 if (vp->v_type != VDIR)
725 if (ap->a_ncookies) {
726 printf("nwfs_readdir: no support for cookies now...");
730 error = nwfs_readvnode(vp, uio, ap->a_cred);
736 struct vop_fsync_args /* {
737 struct vnodeop_desc *a_desc;
739 struct ucred * a_cred;
744 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
751 struct vop_print_args /* {
755 struct vnode *vp = ap->a_vp;
756 struct nwnode *np = VTONW(vp);
758 printf("\tnwfs node: name = '%s', fid = %d, pfid = %d\n",
759 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
763 static int nwfs_pathconf (ap)
764 struct vop_pathconf_args /* {
770 int name=ap->a_name, error=0;
771 register_t *retval=ap->a_retval;
778 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
781 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
789 static int nwfs_strategy (ap)
790 struct vop_strategy_args /* {
794 struct buf *bp=ap->a_bp;
800 if (bp->b_flags & B_ASYNC)
801 td = (struct thread *)0;
803 td = curthread; /* XXX */
804 if (bp->b_iocmd == BIO_READ)
809 * If the op is asynchronous and an i/o daemon is waiting
810 * queue the request, wake it up and wait for completion
811 * otherwise just do it ourselves.
813 if ((bp->b_flags & B_ASYNC) == 0 )
814 error = nwfs_doio(ap->a_vp, bp, cr, td);
820 * How to keep the brain busy ...
821 * Currently lookup routine can make two lookup for vnode. This can be
822 * avoided by reorg the code.
826 struct vop_lookup_args /* {
827 struct vnodeop_desc *a_desc;
829 struct vnode **a_vpp;
830 struct componentname *a_cnp;
833 struct componentname *cnp = ap->a_cnp;
834 struct vnode *dvp = ap->a_dvp;
835 struct vnode **vpp = ap->a_vpp;
836 int flags = cnp->cn_flags;
839 struct mount *mp = dvp->v_mount;
840 struct nwnode *dnp, *npp;
841 struct nw_entry_info fattr, *fap;
843 int nameiop=cnp->cn_nameiop, islastcn;
844 int lockparent, wantparent, error = 0, notfound;
845 struct thread *td = cnp->cn_thread;
846 char _name[cnp->cn_namelen+1];
847 bcopy(cnp->cn_nameptr, _name, cnp->cn_namelen);
848 _name[cnp->cn_namelen]=0;
850 if (dvp->v_type != VDIR)
852 if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
853 printf("nwfs_lookup: invalid '..'\n");
857 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
858 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
860 islastcn = flags & ISLASTCN;
861 if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
863 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)))
865 lockparent = flags & LOCKPARENT;
866 wantparent = flags & (LOCKPARENT|WANTPARENT);
870 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_vflag & VV_ROOT, (int)flags & ISDOTDOT);
872 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
873 (nameiop == CREATE || nameiop == RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
877 error = cache_lookup(dvp, vpp, cnp);
878 NCPVNDEBUG("cache_lookup returned %d\n", error);
881 if (error) { /* name was found */
887 if (dvp == vp) { /* lookup on current */
890 NCPVNDEBUG("cached '.'");
891 } else if (flags & ISDOTDOT) {
892 VOP_UNLOCK(dvp, 0, td); /* unlock parent */
893 error = vget(vp, LK_EXCLUSIVE, td);
894 if (!error && lockparent && islastcn)
895 error = vn_lock(dvp, LK_EXCLUSIVE, td);
897 error = vget(vp, LK_EXCLUSIVE, td);
898 if (!lockparent || error || !islastcn)
899 VOP_UNLOCK(dvp, 0, td);
902 if (vpid == vp->v_id) {
903 if (!VOP_GETATTR(vp, &vattr, cnp->cn_cred, td)
904 && vattr.va_ctime.tv_sec == VTONW(vp)->n_ctime) {
905 if (nameiop != LOOKUP && islastcn)
906 cnp->cn_flags |= SAVENAME;
907 NCPVNDEBUG("use cached vnode");
913 if (lockparent && dvp != vp && islastcn)
914 VOP_UNLOCK(dvp, 0, td);
916 error = vn_lock(dvp, LK_EXCLUSIVE, td);
921 /* not in cache, so ... */
925 if (flags & ISDOTDOT) {
926 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
927 fid = nmp->n_rootent;
931 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
938 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
939 0, NULL, fap, td, cnp->cn_cred);
943 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
944 fap, td, cnp->cn_cred);
945 fid.f_id = fap->dirEntNum;
946 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
947 fid.f_parent = dnp->n_fid.f_parent;
949 fid.f_parent = dnp->n_fid.f_id;
950 NCPVNDEBUG("call to ncp_lookup returned=%d\n", notfound);
952 if (notfound && notfound < 0x80 )
953 return (notfound); /* hard error */
954 if (notfound) { /* entry not found */
955 /* Handle RENAME or CREATE case... */
956 if ((nameiop == CREATE || nameiop == RENAME) && wantparent && islastcn) {
957 cnp->cn_flags |= SAVENAME;
959 VOP_UNLOCK(dvp, 0, td);
960 return (EJUSTRETURN);
964 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
966 /* handle DELETE case ... */
967 if (nameiop == DELETE && islastcn) { /* delete last component */
968 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
969 if (error) return (error);
970 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
975 error = nwfs_nget(mp, fid, fap, dvp, &vp);
976 if (error) return (error);
978 cnp->cn_flags |= SAVENAME; /* I free it later */
979 if (!lockparent) VOP_UNLOCK(dvp, 0, td);
982 if (nameiop == RENAME && islastcn && wantparent) {
983 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
984 if (error) return (error);
985 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
986 error = nwfs_nget(mp, fid, fap, dvp, &vp);
987 if (error) return (error);
989 cnp->cn_flags |= SAVENAME;
991 VOP_UNLOCK(dvp, 0, td);
994 if (flags & ISDOTDOT) {
995 VOP_UNLOCK(dvp, 0, td); /* race to get the inode */
996 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
998 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
1001 if (lockparent && islastcn &&
1002 (error = vn_lock(dvp, LK_EXCLUSIVE, td))) {
1007 } else if (NWCMPF(&dnp->n_fid, &fid)) {
1011 error = nwfs_nget(mp, fid, fap, dvp, &vp);
1012 if (error) return (error);
1014 NCPVNDEBUG("lookup: getnewvp!\n");
1015 if (!lockparent || !islastcn)
1016 VOP_UNLOCK(dvp, 0, td);
1018 if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
1019 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
1020 cache_enter(dvp, *vpp, cnp);