2 * Copyright (c) 1999, 2000 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
32 * $FreeBSD: src/sys/nwfs/nwfs_vnops.c,v 1.6.2.3 2001/03/14 11:26:59 bp Exp $
33 * $DragonFly: src/sys/vfs/nwfs/nwfs_vnops.c,v 1.6 2003/08/07 21:17:43 dillon Exp $
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
40 #include <sys/namei.h>
41 #include <sys/fcntl.h>
42 #include <sys/mount.h>
43 #include <sys/unistd.h>
44 #include <sys/vnode.h>
47 #include <vm/vm_extern.h>
48 #include <vm/vm_zone.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>
57 #include "nwfs_node.h"
58 #include "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_bmap(struct vop_bmap_args *);
82 static int nwfs_strategy(struct vop_strategy_args *);
83 static int nwfs_print(struct vop_print_args *);
84 static int nwfs_pathconf(struct vop_pathconf_args *ap);
86 /* Global vfs data structures for nwfs */
87 vop_t **nwfs_vnodeop_p;
88 static struct vnodeopv_entry_desc nwfs_vnodeop_entries[] = {
89 { &vop_default_desc, (vop_t *) vop_defaultop },
90 { &vop_access_desc, (vop_t *) nwfs_access },
91 { &vop_bmap_desc, (vop_t *) nwfs_bmap },
92 { &vop_open_desc, (vop_t *) nwfs_open },
93 { &vop_close_desc, (vop_t *) nwfs_close },
94 { &vop_create_desc, (vop_t *) nwfs_create },
95 { &vop_fsync_desc, (vop_t *) nwfs_fsync },
96 { &vop_getattr_desc, (vop_t *) nwfs_getattr },
97 { &vop_getpages_desc, (vop_t *) nwfs_getpages },
98 { &vop_putpages_desc, (vop_t *) nwfs_putpages },
99 { &vop_ioctl_desc, (vop_t *) nwfs_ioctl },
100 { &vop_inactive_desc, (vop_t *) nwfs_inactive },
101 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
102 { &vop_link_desc, (vop_t *) nwfs_link },
103 { &vop_lock_desc, (vop_t *) vop_stdlock },
104 { &vop_lookup_desc, (vop_t *) nwfs_lookup },
105 { &vop_mkdir_desc, (vop_t *) nwfs_mkdir },
106 { &vop_mknod_desc, (vop_t *) nwfs_mknod },
107 { &vop_pathconf_desc, (vop_t *) nwfs_pathconf },
108 { &vop_print_desc, (vop_t *) nwfs_print },
109 { &vop_read_desc, (vop_t *) nwfs_read },
110 { &vop_readdir_desc, (vop_t *) nwfs_readdir },
111 { &vop_reclaim_desc, (vop_t *) nwfs_reclaim },
112 { &vop_remove_desc, (vop_t *) nwfs_remove },
113 { &vop_rename_desc, (vop_t *) nwfs_rename },
114 { &vop_rmdir_desc, (vop_t *) nwfs_rmdir },
115 { &vop_setattr_desc, (vop_t *) nwfs_setattr },
116 { &vop_strategy_desc, (vop_t *) nwfs_strategy },
117 { &vop_symlink_desc, (vop_t *) nwfs_symlink },
118 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
119 { &vop_write_desc, (vop_t *) nwfs_write },
122 static struct vnodeopv_desc nwfs_vnodeop_opv_desc =
123 { &nwfs_vnodeop_p, nwfs_vnodeop_entries };
125 VNODEOP_SET(nwfs_vnodeop_opv_desc);
128 * nwfs_access vnode op
129 * for now just return ok
133 struct vop_access_args /* {
136 struct ucred *a_cred;
140 struct vnode *vp = ap->a_vp;
141 struct ucred *cred = ap->a_cred;
142 u_int mode = ap->a_mode;
143 struct nwmount *nmp = VTONWFS(vp);
147 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
148 switch (vp->v_type) {
149 case VREG: case VDIR: case VLNK:
155 if (cred->cr_uid == 0)
157 if (cred->cr_uid != nmp->m.uid) {
159 if (!groupmember(nmp->m.gid, cred))
162 error = (((vp->v_type == VREG) ? nmp->m.file_mode : nmp->m.dir_mode) & mode) == mode ? 0 : EACCES;
171 struct vop_open_args /* {
174 struct ucred *a_cred;
178 struct vnode *vp = ap->a_vp;
179 int mode = ap->a_mode;
180 struct nwnode *np = VTONW(vp);
181 struct ncp_open_info no;
182 struct nwmount *nmp = VTONWFS(vp);
186 NCPVNDEBUG("%s,%d\n",np->n_name, np->opened);
187 if (vp->v_type != VREG && vp->v_type != VDIR) {
188 NCPFATAL("open vtype = %d\n", vp->v_type);
191 if (vp->v_type == VDIR) return 0; /* nothing to do now */
192 if (np->n_flag & NMODIFIED) {
193 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1)) == EINTR)
196 error = VOP_GETATTR(vp, &vattr, ap->a_td);
197 if (error) return (error);
198 np->n_mtime = vattr.va_mtime.tv_sec;
200 error = VOP_GETATTR(vp, &vattr, ap->a_td);
201 if (error) return (error);
202 if (np->n_mtime != vattr.va_mtime.tv_sec) {
203 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1)) == EINTR)
205 np->n_mtime = vattr.va_mtime.tv_sec;
213 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
215 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
216 0, nwm, &no, ap->a_td, ap->a_cred);
221 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
222 nwm, &no, ap->a_td,ap->a_cred);
227 np->n_origfh = no.origfh;
235 struct vop_close_args /* {
236 struct vnodeop_desc *a_desc;
239 struct ucred *a_cred;
243 struct vnode *vp = ap->a_vp;
244 struct nwnode *np = VTONW(vp);
247 NCPVNDEBUG("name=%s,td=%p,c=%d\n",np->n_name,ap->a_td,np->opened);
249 if (vp->v_type == VDIR) return 0; /* nothing to do now */
251 lwkt_gettoken(&vp->v_interlock);
252 if (np->opened == 0) {
253 lwkt_reltoken(&vp->v_interlock);
256 lwkt_reltoken(&vp->v_interlock);
257 error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
258 lwkt_gettoken(&vp->v_interlock);
259 if (np->opened == 0) {
260 lwkt_reltoken(&vp->v_interlock);
263 if (--np->opened == 0) {
264 lwkt_reltoken(&vp->v_interlock);
265 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
266 ap->a_td, proc0.p_ucred);
268 lwkt_reltoken(&vp->v_interlock);
275 * nwfs_getattr call from vfs.
279 struct vop_getattr_args /* {
282 struct ucred *a_cred;
286 struct vnode *vp = ap->a_vp;
287 struct nwnode *np = VTONW(vp);
288 struct vattr *va=ap->a_vap;
289 struct nwmount *nmp = VTONWFS(vp);
290 struct nw_entry_info fattr;
294 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_flag & VROOT) != 0);
295 error = nwfs_attr_cachelookup(vp,va);
296 if (!error) return 0;
297 NCPVNDEBUG("not in cache\n");
298 oldsize = np->n_size;
299 if (np->n_flag & NVOLUME) {
300 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
301 ap->a_td,proc0.p_ucred);
303 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
304 np->n_name, &fattr, ap->a_td, proc0.p_ucred);
307 NCPVNDEBUG("error %d\n", error);
310 nwfs_attr_cacheenter(vp, &fattr);
313 np->n_size = oldsize;
317 * nwfs_setattr call from vfs.
321 struct vop_setattr_args /* {
324 struct ucred *a_cred;
328 struct vnode *vp = ap->a_vp;
329 struct nwnode *np = VTONW(vp);
330 struct vattr *vap = ap->a_vap;
335 if (vap->va_flags != VNOVAL)
338 * Disallow write attempts if the filesystem is mounted read-only.
340 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
341 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
342 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
344 if (vap->va_size != VNOVAL) {
345 switch (vp->v_type) {
350 * Disallow write attempts if the filesystem is
353 if (vp->v_mount->mnt_flag & MNT_RDONLY)
355 vnode_pager_setsize(vp, (u_long)vap->va_size);
357 np->n_size = vap->va_size;
363 error = ncp_setattr(vp, vap, ap->a_cred, ap->a_td);
364 if (error && vap->va_size != VNOVAL) {
366 vnode_pager_setsize(vp, (u_long)tsize);
368 np->n_atime = 0; /* invalidate cache */
369 VOP_GETATTR(vp, vap, ap->a_td);
370 np->n_mtime = vap->va_mtime.tv_sec;
378 struct vop_read_args /* {
382 struct ucred *a_cred;
385 struct vnode *vp = ap->a_vp;
386 struct uio *uio=ap->a_uio;
388 NCPVNDEBUG("nwfs_read:\n");
390 if (vp->v_type != VREG && vp->v_type != VDIR)
392 error = nwfs_readvnode(vp, uio, ap->a_cred);
398 struct vop_write_args /* {
402 struct ucred *a_cred;
405 struct vnode *vp = ap->a_vp;
406 struct uio *uio = ap->a_uio;
409 NCPVNDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
411 if (vp->v_type != VREG)
413 error = nwfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
418 * Create a regular file. On entry the directory to contain the file being
419 * created is locked. We must release before we return. We must also free
420 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
421 * only if the SAVESTART bit in cn_flags is clear on success.
425 struct vop_create_args /* {
427 struct vnode **a_vpp;
428 struct componentname *a_cnp;
432 struct vnode *dvp = ap->a_dvp;
433 struct vattr *vap = ap->a_vap;
434 struct vnode **vpp=ap->a_vpp;
435 struct componentname *cnp = ap->a_cnp;
436 struct vnode *vp = (struct vnode *)0;
437 int error = 0, fmode;
440 struct ncp_open_info no;
441 struct nwmount *nmp=VTONWFS(dvp);
447 if (vap->va_type == VSOCK)
449 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td))) {
452 fmode = AR_READ | AR_WRITE;
453 /* if (vap->va_vaflags & VA_EXCLUSIVE)
454 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
456 error = ncp_open_create_file_or_subdir(nmp,dvp,cnp->cn_namelen,cnp->cn_nameptr,
457 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
458 0, fmode, &no, cnp->cn_td, cnp->cn_cred);
460 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_td,cnp->cn_cred);
461 fid.f_parent = VTONW(dvp)->n_fid.f_id;
462 fid.f_id = no.fattr.dirEntNum;
463 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
469 if (cnp->cn_flags & MAKEENTRY)
470 cache_enter(dvp, vp, cnp);
476 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
477 * NetWare doesn't allow delete/rename operations on an opened file.
481 struct vop_remove_args /* {
482 struct vnodeop_desc *a_desc;
483 struct vnode * a_dvp;
485 struct componentname * a_cnp;
488 struct vnode *vp = ap->a_vp;
489 struct vnode *dvp = ap->a_dvp;
490 struct componentname *cnp = ap->a_cnp;
491 struct nwnode *np = VTONW(vp);
492 struct nwmount *nmp = VTONWFS(vp);
495 if (vp->v_type == VDIR || np->opened || vp->v_usecount != 1) {
497 } else if (!ncp_conn_valid(NWFSTOCONN(nmp))) {
501 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
502 cnp->cn_namelen,cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
504 np->n_flag |= NSHOULDFREE;
505 else if (error == 0x899c)
512 * nwfs_file rename call
516 struct vop_rename_args /* {
517 struct vnode *a_fdvp;
519 struct componentname *a_fcnp;
520 struct vnode *a_tdvp;
522 struct componentname *a_tcnp;
525 struct vnode *fvp = ap->a_fvp;
526 struct vnode *tvp = ap->a_tvp;
527 struct vnode *fdvp = ap->a_fdvp;
528 struct vnode *tdvp = ap->a_tdvp;
529 struct componentname *tcnp = ap->a_tcnp;
530 struct componentname *fcnp = ap->a_fcnp;
531 struct nwmount *nmp=VTONWFS(fvp);
532 u_int16_t oldtype = 6;
535 /* Check for cross-device rename */
536 if ((fvp->v_mount != tdvp->v_mount) ||
537 (tvp && (fvp->v_mount != tvp->v_mount))) {
542 if (tvp && tvp->v_usecount > 1) {
546 if (tvp && tvp != fvp) {
547 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
548 tcnp->cn_namelen, tcnp->cn_nameptr,
549 tcnp->cn_td, tcnp->cn_cred);
550 if (error == 0x899c) error = EACCES;
554 if (fvp->v_type == VDIR) {
555 oldtype |= NW_TYPE_SUBDIR;
556 } else if (fvp->v_type == VREG) {
557 oldtype |= NW_TYPE_FILE;
560 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
561 oldtype, &nmp->m.nls,
562 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
563 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
564 tcnp->cn_td,tcnp->cn_cred);
568 if (fvp->v_type == VDIR) {
569 if (tvp != NULL && tvp->v_type == VDIR)
582 nwfs_attr_cacheremove(fdvp);
583 nwfs_attr_cacheremove(tdvp);
585 * Need to get rid of old vnodes, because netware will change
592 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
600 * nwfs hard link create call
601 * Netware filesystems don't know what links are.
605 struct vop_link_args /* {
606 struct vnode *a_tdvp;
608 struct componentname *a_cnp;
615 * nwfs_symlink link create call
616 * Netware filesystems don't know what symlinks are.
620 struct vop_symlink_args /* {
622 struct vnode **a_vpp;
623 struct componentname *a_cnp;
631 static int nwfs_mknod(ap)
632 struct vop_mknod_args /* {
643 struct vop_mkdir_args /* {
645 struct vnode **a_vpp;
646 struct componentname *a_cnp;
650 struct vnode *dvp = ap->a_dvp;
651 /* struct vattr *vap = ap->a_vap;*/
652 struct componentname *cnp = ap->a_cnp;
653 int len=cnp->cn_namelen;
654 struct ncp_open_info no;
656 struct vnode *newvp = (struct vnode *)0;
660 char *name=cnp->cn_nameptr;
662 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td))) {
665 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
668 if (ncp_open_create_file_or_subdir(VTONWFS(dvp),dvp, cnp->cn_namelen,
669 cnp->cn_nameptr,OC_MODE_CREATE, aDIR, 0xffff,
670 &no, cnp->cn_td, cnp->cn_cred) != 0) {
676 fid.f_parent = VTONW(dvp)->n_fid.f_id;
677 fid.f_id = no.fattr.dirEntNum;
678 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
681 newvp->v_type = VDIR;
689 * nwfs_remove directory call
693 struct vop_rmdir_args /* {
696 struct componentname *a_cnp;
699 struct vnode *vp = ap->a_vp;
700 struct vnode *dvp = ap->a_dvp;
701 struct componentname *cnp = ap->a_cnp;
702 struct nwnode *np = VTONW(vp);
703 struct nwmount *nmp = VTONWFS(vp);
704 struct nwnode *dnp = VTONW(dvp);
710 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
711 cnp->cn_namelen, cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
713 np->n_flag |= NSHOULDFREE;
714 else if (error == NWE_DIR_NOT_EMPTY)
716 dnp->n_flag |= NMODIFIED;
717 nwfs_attr_cacheremove(dvp);
728 struct vop_readdir_args /* {
731 struct ucred *a_cred;
737 struct vnode *vp = ap->a_vp;
738 struct uio *uio = ap->a_uio;
741 if (vp->v_type != VDIR)
743 if (ap->a_ncookies) {
744 printf("nwfs_readdir: no support for cookies now...");
748 error = nwfs_readvnode(vp, uio, ap->a_cred);
754 struct vop_fsync_args /* {
755 struct vnodeop_desc *a_desc;
757 struct ucred * a_cred;
762 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
769 struct vop_print_args /* {
773 struct vnode *vp = ap->a_vp;
774 struct nwnode *np = VTONW(vp);
776 printf("nwfs node: name = '%s', fid = %d, pfid = %d\n",
777 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
781 static int nwfs_pathconf (ap)
782 struct vop_pathconf_args /* {
788 int name=ap->a_name, error=0;
789 register_t *retval=ap->a_retval;
796 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
799 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
807 static int nwfs_strategy (ap)
808 struct vop_strategy_args /* {
812 struct buf *bp=ap->a_bp;
814 struct thread *td = NULL;
817 if (bp->b_flags & B_PHYS)
818 panic("nwfs physio");
819 if ((bp->b_flags & B_ASYNC) == 0)
820 td = curthread; /* YYY dunno if this is legal */
822 * If the op is asynchronous and an i/o daemon is waiting
823 * queue the request, wake it up and wait for completion
824 * otherwise just do it ourselves.
826 if ((bp->b_flags & B_ASYNC) == 0 )
827 error = nwfs_doio(bp, proc0.p_ucred, td);
833 struct vop_bmap_args /* {
836 struct vnode **a_vpp;
842 struct vnode *vp = ap->a_vp;
844 if (ap->a_vpp != NULL)
846 if (ap->a_bnp != NULL)
847 *ap->a_bnp = ap->a_bn * btodb(vp->v_mount->mnt_stat.f_iosize);
848 if (ap->a_runp != NULL)
850 if (ap->a_runb != NULL)
856 nwfs_nget(struct mount *mp, ncpfid fid, struct nw_entry_info *fap,
857 struct vnode *dvp, struct vnode **vpp)
860 struct nwnode *newnp;
864 error = nwfs_allocvp(mp, fid, &vp);
869 newnp->n_attr = fap->attributes;
870 vp->v_type = newnp->n_attr & aDIR ? VDIR : VREG;
871 nwfs_attr_cacheenter(vp, fap);
874 newnp->n_parent = VTONW(dvp)->n_fid;
875 if ((newnp->n_flag & NNEW) && vp->v_type == VDIR) {
876 if ((dvp->v_flag & VROOT) == 0) {
877 newnp->n_refparent = 1;
878 vref(dvp); /* vhold */
882 if ((newnp->n_flag & NNEW) && vp->v_type == VREG)
883 printf("new vnode '%s' borned without parent ?\n",newnp->n_name);
885 newnp->n_flag &= ~NNEW;
891 * How to keep the brain busy ...
892 * Currently lookup routine can make two lookup for vnode. This can be
893 * avoided by reorg the code.
897 struct vop_lookup_args /* {
898 struct vnodeop_desc *a_desc;
900 struct vnode **a_vpp;
901 struct componentname *a_cnp;
904 struct componentname *cnp = ap->a_cnp;
905 struct vnode *dvp = ap->a_dvp;
906 struct vnode **vpp = ap->a_vpp;
907 int flags = cnp->cn_flags;
910 struct mount *mp = dvp->v_mount;
911 struct nwnode *dnp, *npp;
912 struct nw_entry_info fattr, *fap;
914 int nameiop=cnp->cn_nameiop, islastcn;
915 int lockparent, wantparent, error = 0, notfound;
916 struct thread *td = cnp->cn_td;
917 char _name[cnp->cn_namelen+1];
918 bcopy(cnp->cn_nameptr,_name,cnp->cn_namelen);
919 _name[cnp->cn_namelen]=0;
921 if (dvp->v_type != VDIR)
923 if ((flags & ISDOTDOT) && (dvp->v_flag & VROOT)) {
924 printf("nwfs_lookup: invalid '..'\n");
928 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
929 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
931 islastcn = flags & ISLASTCN;
932 if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
934 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)))
936 lockparent = flags & LOCKPARENT;
937 wantparent = flags & (LOCKPARENT|WANTPARENT);
941 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_flag & VROOT, (int)flags & ISDOTDOT);
943 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
944 (nameiop == CREATE || nameiop == RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
948 error = cache_lookup(dvp, vpp, cnp);
949 NCPVNDEBUG("cache_lookup returned %d\n",error);
952 if (error) { /* name was found */
958 if (dvp == vp) { /* lookup on current */
961 NCPVNDEBUG("cached '.'");
962 } else if (flags & ISDOTDOT) {
963 VOP_UNLOCK(dvp, 0, td); /* unlock parent */
964 error = vget(vp, LK_EXCLUSIVE, td);
965 if (!error && lockparent && islastcn)
966 error = vn_lock(dvp, LK_EXCLUSIVE, td);
968 error = vget(vp, LK_EXCLUSIVE, td);
969 if (!lockparent || error || !islastcn)
970 VOP_UNLOCK(dvp, 0, td);
973 if (vpid == vp->v_id) {
974 if (!VOP_GETATTR(vp, &vattr, td)
975 && vattr.va_ctime.tv_sec == VTONW(vp)->n_ctime) {
976 if (nameiop != LOOKUP && islastcn)
977 cnp->cn_flags |= SAVENAME;
978 NCPVNDEBUG("use cached vnode");
984 if (lockparent && dvp != vp && islastcn)
985 VOP_UNLOCK(dvp, 0, td);
987 error = vn_lock(dvp, LK_EXCLUSIVE, td);
992 /* not in cache, so ... */
996 if (flags & ISDOTDOT) {
997 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
998 fid = nmp->n_rootent;
1002 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
1006 fid = dnp->n_parent;
1009 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
1010 0, NULL, fap, td, cnp->cn_cred);
1014 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
1015 fap, td, cnp->cn_cred);
1016 fid.f_id = fap->dirEntNum;
1017 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
1018 fid.f_parent = dnp->n_fid.f_parent;
1020 fid.f_parent = dnp->n_fid.f_id;
1021 NCPVNDEBUG("call to ncp_lookup returned=%d\n",notfound);
1023 if (notfound && notfound < 0x80 )
1024 return (notfound); /* hard error */
1025 if (notfound) { /* entry not found */
1026 /* Handle RENAME or CREATE case... */
1027 if ((nameiop == CREATE || nameiop == RENAME) && wantparent && islastcn) {
1028 cnp->cn_flags |= SAVENAME;
1030 VOP_UNLOCK(dvp, 0, td);
1031 return (EJUSTRETURN);
1035 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
1037 /* handle DELETE case ... */
1038 if (nameiop == DELETE && islastcn) { /* delete last component */
1039 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_td);
1040 if (error) return (error);
1041 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
1046 error = nwfs_nget(mp, fid, fap, dvp, &vp);
1047 if (error) return (error);
1049 cnp->cn_flags |= SAVENAME; /* I free it later */
1050 if (!lockparent) VOP_UNLOCK(dvp,0,td);
1053 if (nameiop == RENAME && islastcn && wantparent) {
1054 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_td);
1055 if (error) return (error);
1056 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
1057 error = nwfs_nget(mp, fid, fap, dvp, &vp);
1058 if (error) return (error);
1060 cnp->cn_flags |= SAVENAME;
1062 VOP_UNLOCK(dvp,0,td);
1065 if (flags & ISDOTDOT) {
1066 VOP_UNLOCK(dvp, 0, td); /* race to get the inode */
1067 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
1069 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
1072 if (lockparent && islastcn &&
1073 (error = vn_lock(dvp, LK_EXCLUSIVE, td))) {
1078 } else if (NWCMPF(&dnp->n_fid, &fid)) {
1082 error = nwfs_nget(mp, fid, fap, dvp, &vp);
1083 if (error) return (error);
1085 NCPVNDEBUG("lookup: getnewvp!\n");
1086 if (!lockparent || !islastcn)
1087 VOP_UNLOCK(dvp, 0, td);
1089 if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
1090 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
1091 cache_enter(dvp, *vpp, cnp);