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.35 2007/05/06 19:23:35 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 <netproto/ncp/ncp.h>
51 #include <netproto/ncp/ncp_conn.h>
52 #include <netproto/ncp/ncp_subr.h>
53 #include <netproto/ncp/nwerror.h>
54 #include <netproto/ncp/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_old_create_args *);
64 static int nwfs_mknod(struct vop_old_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_old_remove_args *);
74 static int nwfs_link(struct vop_old_link_args *);
75 static int nwfs_lookup(struct vop_old_lookup_args *);
76 static int nwfs_rename(struct vop_old_rename_args *);
77 static int nwfs_mkdir(struct vop_old_mkdir_args *);
78 static int nwfs_rmdir(struct vop_old_rmdir_args *);
79 static int nwfs_symlink(struct vop_old_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 struct vop_ops nwfs_vnode_vops = {
88 .vop_default = vop_defaultop,
89 .vop_access = nwfs_access,
90 .vop_bmap = nwfs_bmap,
91 .vop_open = nwfs_open,
92 .vop_close = nwfs_close,
93 .vop_old_create = nwfs_create,
94 .vop_fsync = nwfs_fsync,
95 .vop_getattr = nwfs_getattr,
96 .vop_getpages = nwfs_getpages,
97 .vop_putpages = nwfs_putpages,
98 .vop_ioctl = nwfs_ioctl,
99 .vop_inactive = nwfs_inactive,
100 .vop_old_link = nwfs_link,
101 .vop_old_lookup = nwfs_lookup,
102 .vop_old_mkdir = nwfs_mkdir,
103 .vop_old_mknod = nwfs_mknod,
104 .vop_pathconf = nwfs_pathconf,
105 .vop_print = nwfs_print,
106 .vop_read = nwfs_read,
107 .vop_readdir = nwfs_readdir,
108 .vop_reclaim = nwfs_reclaim,
109 .vop_old_remove = nwfs_remove,
110 .vop_old_rename = nwfs_rename,
111 .vop_old_rmdir = nwfs_rmdir,
112 .vop_setattr = nwfs_setattr,
113 .vop_strategy = nwfs_strategy,
114 .vop_old_symlink = nwfs_symlink,
115 .vop_write = nwfs_write
119 * nwfs_access vnode op
120 * for now just return ok
122 * nwfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
123 * struct thread *a_td)
126 nwfs_access(struct vop_access_args *ap)
128 struct vnode *vp = ap->a_vp;
129 struct ucred *cred = ap->a_cred;
130 u_int mode = ap->a_mode;
131 struct nwmount *nmp = VTONWFS(vp);
135 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
136 switch (vp->v_type) {
137 case VREG: case VDIR: case VLNK:
143 if (cred->cr_uid == 0)
145 if (cred->cr_uid != nmp->m.uid) {
147 if (!groupmember(nmp->m.gid, cred))
150 error = (((vp->v_type == VREG) ? nmp->m.file_mode : nmp->m.dir_mode) & mode) == mode ? 0 : EACCES;
156 * nwfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
160 nwfs_open(struct vop_open_args *ap)
162 thread_t td = curthread; /* XXX */
163 struct vnode *vp = ap->a_vp;
164 int mode = ap->a_mode;
165 struct nwnode *np = VTONW(vp);
166 struct ncp_open_info no;
167 struct nwmount *nmp = VTONWFS(vp);
171 NCPVNDEBUG("%s,%d\n",np->n_name, np->opened);
172 if (vp->v_type != VREG && vp->v_type != VDIR) {
173 NCPFATAL("open vtype = %d\n", vp->v_type);
176 if (vp->v_type == VDIR) return 0; /* nothing to do now */
177 if (np->n_flag & NMODIFIED) {
178 if ((error = nwfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
181 error = VOP_GETATTR(vp, &vattr);
184 np->n_mtime = vattr.va_mtime.tv_sec;
186 error = VOP_GETATTR(vp, &vattr);
189 if (np->n_mtime != vattr.va_mtime.tv_sec) {
190 if ((error = nwfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
192 np->n_mtime = vattr.va_mtime.tv_sec;
197 return (vop_stdopen(ap));
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, td, ap->a_cred);
208 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
209 nwm, &no, td, ap->a_cred);
215 np->n_origfh = no.origfh;
216 error = vop_stdopen(ap);
222 * nwfs_close(struct vnode *a_vp, int a_fflag,
223 * struct ucred *a_cred, struct thread *a_td)
226 nwfs_close(struct vop_close_args *ap)
228 thread_t td = curthread; /* XXX */
229 struct vnode *vp = ap->a_vp;
230 struct nwnode *np = VTONW(vp);
233 NCPVNDEBUG("name=%s,td=%p,c=%d\n",np->n_name,ap->a_td,np->opened);
236 if (vp->v_type == VDIR)
240 error = nwfs_vinvalbuf(vp, V_SAVE, 1);
241 if (np->opened == 0) {
242 error = 0; /* huh? */
245 if (--np->opened == 0) {
246 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
256 * nwfs_getattr call from vfs.
258 * nwfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
259 * struct thread *a_td)
262 nwfs_getattr(struct vop_getattr_args *ap)
264 thread_t td = curthread; /* XXX */
265 struct vnode *vp = ap->a_vp;
266 struct nwnode *np = VTONW(vp);
267 struct vattr *va=ap->a_vap;
268 struct nwmount *nmp = VTONWFS(vp);
269 struct nw_entry_info fattr;
273 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_flag & VROOT) != 0);
274 error = nwfs_attr_cachelookup(vp,va);
275 if (!error) return 0;
276 NCPVNDEBUG("not in cache\n");
277 oldsize = np->n_size;
278 if (np->n_flag & NVOLUME) {
279 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
282 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
283 np->n_name, &fattr, td, proc0.p_ucred);
286 NCPVNDEBUG("error %d\n", error);
289 nwfs_attr_cacheenter(vp, &fattr);
292 np->n_size = oldsize;
296 * nwfs_setattr call from vfs.
298 * nwfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred)
301 nwfs_setattr(struct vop_setattr_args *ap)
303 thread_t td = curthread; /* XXX */
304 struct vnode *vp = ap->a_vp;
305 struct nwnode *np = VTONW(vp);
306 struct vattr *vap = ap->a_vap;
311 if (vap->va_flags != VNOVAL)
314 * Disallow write attempts if the filesystem is mounted read-only.
316 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
317 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
318 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
320 if (vap->va_size != VNOVAL) {
321 switch (vp->v_type) {
326 * Disallow write attempts if the filesystem is
329 if (vp->v_mount->mnt_flag & MNT_RDONLY)
331 vnode_pager_setsize(vp, (u_long)vap->va_size);
333 np->n_size = vap->va_size;
339 error = ncp_setattr(vp, vap, ap->a_cred, td);
340 if (error && vap->va_size != VNOVAL) {
342 vnode_pager_setsize(vp, (u_long)tsize);
344 np->n_atime = 0; /* invalidate cache */
345 VOP_GETATTR(vp, vap);
346 np->n_mtime = vap->va_mtime.tv_sec;
353 * nwfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
354 * struct ucred *a_cred)
357 nwfs_read(struct vop_read_args *ap)
359 struct vnode *vp = ap->a_vp;
360 struct uio *uio=ap->a_uio;
362 NCPVNDEBUG("nwfs_read:\n");
364 if (vp->v_type != VREG && vp->v_type != VDIR)
366 error = nwfs_readvnode(vp, uio, ap->a_cred);
371 * nwfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
372 * struct ucred *a_cred)
375 nwfs_write(struct vop_write_args *ap)
377 struct vnode *vp = ap->a_vp;
378 struct uio *uio = ap->a_uio;
381 NCPVNDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
383 if (vp->v_type != VREG)
385 error = nwfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
390 * Create a regular file. On entry the directory to contain the file being
391 * created is locked. We must release before we return.
393 * nwfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
394 * struct componentname *a_cnpl, struct vattr *a_vap)
397 nwfs_create(struct vop_old_create_args *ap)
399 struct vnode *dvp = ap->a_dvp;
400 struct vattr *vap = ap->a_vap;
401 struct vnode **vpp=ap->a_vpp;
402 struct componentname *cnp = ap->a_cnp;
403 struct vnode *vp = (struct vnode *)0;
404 int error = 0, fmode;
407 struct ncp_open_info no;
408 struct nwmount *nmp=VTONWFS(dvp);
414 if (vap->va_type == VSOCK)
416 if ((error = VOP_GETATTR(dvp, &vattr))) {
419 fmode = AR_READ | AR_WRITE;
420 /* if (vap->va_vaflags & VA_EXCLUSIVE)
421 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
423 error = ncp_open_create_file_or_subdir(nmp,dvp,cnp->cn_namelen,cnp->cn_nameptr,
424 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
425 0, fmode, &no, cnp->cn_td, cnp->cn_cred);
427 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_td,cnp->cn_cred);
428 fid.f_parent = VTONW(dvp)->n_fid.f_id;
429 fid.f_id = no.fattr.dirEntNum;
430 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
441 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
442 * NetWare doesn't allow delete/rename operations on an opened file.
444 * nwfs_remove(struct vnode *a_dvp,
445 * struct vnode *a_vp, struct componentname *a_cnp)
448 nwfs_remove(struct vop_old_remove_args *ap)
450 struct vnode *vp = ap->a_vp;
451 struct vnode *dvp = ap->a_dvp;
452 struct componentname *cnp = ap->a_cnp;
453 struct nwnode *np = VTONW(vp);
454 struct nwmount *nmp = VTONWFS(vp);
457 if (vp->v_type == VDIR || np->opened || vp->v_sysref.refcnt > 1) {
459 } else if (!ncp_conn_valid(NWFSTOCONN(nmp))) {
462 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
463 cnp->cn_namelen,cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
465 np->n_flag |= NSHOULDFREE;
466 else if (error == 0x899c)
473 * nwfs_file rename call
475 * nwfs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
476 * struct componentname *a_fcnp, struct vnode *a_tdvp,
477 * struct vnode *a_tvp, struct componentname *a_tcnp)
480 nwfs_rename(struct vop_old_rename_args *ap)
482 struct vnode *fvp = ap->a_fvp;
483 struct vnode *tvp = ap->a_tvp;
484 struct vnode *fdvp = ap->a_fdvp;
485 struct vnode *tdvp = ap->a_tdvp;
486 struct componentname *tcnp = ap->a_tcnp;
487 struct componentname *fcnp = ap->a_fcnp;
488 struct nwmount *nmp=VTONWFS(fvp);
489 u_int16_t oldtype = 6;
492 /* Check for cross-device rename */
493 if ((fvp->v_mount != tdvp->v_mount) ||
494 (tvp && (fvp->v_mount != tvp->v_mount))) {
499 if (tvp && tvp->v_sysref.refcnt > 1) {
503 if (tvp && tvp != fvp) {
504 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
505 tcnp->cn_namelen, tcnp->cn_nameptr,
506 tcnp->cn_td, tcnp->cn_cred);
507 if (error == 0x899c) error = EACCES;
511 if (fvp->v_type == VDIR) {
512 oldtype |= NW_TYPE_SUBDIR;
513 } else if (fvp->v_type == VREG) {
514 oldtype |= NW_TYPE_FILE;
517 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
518 oldtype, &nmp->m.nls,
519 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
520 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
521 tcnp->cn_td,tcnp->cn_cred);
534 nwfs_attr_cacheremove(fdvp);
535 nwfs_attr_cacheremove(tdvp);
537 * Need to get rid of old vnodes, because netware will change
544 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
552 * nwfs hard link create call
553 * Netware filesystems don't know what links are.
555 * nwfs_link(struct vnode *a_tdvp, struct vnode *a_vp,
556 * struct componentname *a_cnp)
559 nwfs_link(struct vop_old_link_args *ap)
565 * nwfs_symlink link create call
566 * Netware filesystems don't know what symlinks are.
568 * nwfs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
569 * struct componentname *a_cnp, struct vattr *a_vap,
573 nwfs_symlink(struct vop_old_symlink_args *ap)
578 static int nwfs_mknod(struct vop_old_mknod_args *ap)
586 * nwfs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
587 * struct componentname *a_cnp, struct vattr *a_vap)
590 nwfs_mkdir(struct vop_old_mkdir_args *ap)
592 struct vnode *dvp = ap->a_dvp;
593 /* struct vattr *vap = ap->a_vap;*/
594 struct componentname *cnp = ap->a_cnp;
595 int len=cnp->cn_namelen;
596 struct ncp_open_info no;
598 struct vnode *newvp = (struct vnode *)0;
602 char *name=cnp->cn_nameptr;
604 if ((error = VOP_GETATTR(dvp, &vattr))) {
607 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
610 if (ncp_open_create_file_or_subdir(VTONWFS(dvp),dvp, cnp->cn_namelen,
611 cnp->cn_nameptr,OC_MODE_CREATE, aDIR, 0xffff,
612 &no, cnp->cn_td, cnp->cn_cred) != 0) {
618 fid.f_parent = VTONW(dvp)->n_fid.f_id;
619 fid.f_id = no.fattr.dirEntNum;
620 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
623 newvp->v_type = VDIR;
631 * nwfs_remove directory call
633 * nwfs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
634 * struct componentname *a_cnp)
637 nwfs_rmdir(struct vop_old_rmdir_args *ap)
639 struct vnode *vp = ap->a_vp;
640 struct vnode *dvp = ap->a_dvp;
641 struct componentname *cnp = ap->a_cnp;
642 struct nwnode *np = VTONW(vp);
643 struct nwmount *nmp = VTONWFS(vp);
644 struct nwnode *dnp = VTONW(dvp);
650 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
651 cnp->cn_namelen, cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
653 np->n_flag |= NSHOULDFREE;
654 else if (error == NWE_DIR_NOT_EMPTY)
656 dnp->n_flag |= NMODIFIED;
657 nwfs_attr_cacheremove(dvp);
664 * nwfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
665 * int *a_eofflag, u_long *a_cookies, int a_ncookies)
668 nwfs_readdir(struct vop_readdir_args *ap)
670 struct vnode *vp = ap->a_vp;
671 struct uio *uio = ap->a_uio;
674 if (vp->v_type != VDIR)
676 if (ap->a_ncookies) {
677 kprintf("nwfs_readdir: no support for cookies now...");
680 if ((error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY)) != 0)
682 error = nwfs_readvnode(vp, uio, ap->a_cred);
688 * nwfs_fsync(struct vnode *a_vp, struct ucred *a_cred,
689 * int a_waitfor, struct thread *a_td)
693 nwfs_fsync(struct vop_fsync_args *ap)
695 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
700 * nwfs_print(struct vnode *a_vp)
704 nwfs_print(struct vop_print_args *ap)
706 struct vnode *vp = ap->a_vp;
707 struct nwnode *np = VTONW(vp);
709 kprintf("nwfs node: name = '%s', fid = %d, pfid = %d\n",
710 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
715 * nwfs_pathconf(struct vnode *vp, int name, register_t *retval)
718 nwfs_pathconf(struct vop_pathconf_args *ap)
720 int name=ap->a_name, error=0;
721 register_t *retval=ap->a_retval;
728 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
731 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
740 * nwfs_strategy(struct vnode *a_vp, struct bio *a_bio)
743 nwfs_strategy(struct vop_strategy_args *ap)
745 struct bio *bio = ap->a_bio;
746 struct buf *bp = bio->bio_buf;
748 struct thread *td = NULL;
751 if ((bp->b_flags & B_ASYNC) == 0)
752 td = curthread; /* YYY dunno if this is legal */
754 * If the op is asynchronous and an i/o daemon is waiting
755 * queue the request, wake it up and wait for completion
756 * otherwise just do it ourselves.
758 if ((bp->b_flags & B_ASYNC) == 0 )
759 error = nwfs_doio(ap->a_vp, bio, proc0.p_ucred, td);
764 * nwfs_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
765 * off_t *a_doffsetp, int *a_runp, int *a_runb)
768 nwfs_bmap(struct vop_bmap_args *ap)
770 struct vnode *vp = ap->a_vp;
772 if (ap->a_vpp != NULL)
774 if (ap->a_doffsetp != NULL)
775 *ap->a_doffsetp = ap->a_loffset;
776 if (ap->a_runp != NULL)
778 if (ap->a_runb != NULL)
784 nwfs_nget(struct mount *mp, ncpfid fid, const struct nw_entry_info *fap,
785 struct vnode *dvp, struct vnode **vpp)
788 struct nwnode *newnp;
792 error = nwfs_allocvp(mp, fid, &vp);
797 newnp->n_attr = fap->attributes;
798 vp->v_type = newnp->n_attr & aDIR ? VDIR : VREG;
799 nwfs_attr_cacheenter(vp, fap);
802 newnp->n_parent = VTONW(dvp)->n_fid;
803 if ((newnp->n_flag & NNEW) && vp->v_type == VDIR) {
804 if ((dvp->v_flag & VROOT) == 0) {
805 newnp->n_refparent = 1;
806 vref(dvp); /* vhold */
810 if ((newnp->n_flag & NNEW) && vp->v_type == VREG)
811 kprintf("new vnode '%s' borned without parent ?\n",newnp->n_name);
813 newnp->n_flag &= ~NNEW;
819 * How to keep the brain busy ...
820 * Currently lookup routine can make two lookup for vnode. This can be
821 * avoided by reorg the code.
823 * nwfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
824 * struct componentname *a_cnp)
827 nwfs_lookup(struct vop_old_lookup_args *ap)
829 struct componentname *cnp = ap->a_cnp;
830 struct vnode *dvp = ap->a_dvp;
831 struct vnode **vpp = ap->a_vpp;
832 int flags = cnp->cn_flags;
835 struct mount *mp = dvp->v_mount;
836 struct nwnode *dnp, *npp;
837 struct nw_entry_info fattr, *fap;
839 int nameiop=cnp->cn_nameiop;
840 int lockparent, wantparent, error = 0, notfound;
841 struct thread *td = cnp->cn_td;
842 char _name[cnp->cn_namelen+1];
843 bcopy(cnp->cn_nameptr,_name,cnp->cn_namelen);
844 _name[cnp->cn_namelen]=0;
846 if (dvp->v_type != VDIR)
848 if ((flags & CNP_ISDOTDOT) && (dvp->v_flag & VROOT)) {
849 kprintf("nwfs_lookup: invalid '..'\n");
853 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
854 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
856 if ((mp->mnt_flag & MNT_RDONLY) && nameiop != NAMEI_LOOKUP)
858 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred)))
860 lockparent = flags & CNP_LOCKPARENT;
861 wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
865 kprintf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_flag & VROOT, (int)flags & CNP_ISDOTDOT);
867 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
868 (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
875 if (flags & CNP_ISDOTDOT) {
876 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
877 fid = nmp->n_rootent;
881 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
888 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
889 0, NULL, fap, td, cnp->cn_cred);
893 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
894 fap, td, cnp->cn_cred);
895 fid.f_id = fap->dirEntNum;
896 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
897 fid.f_parent = dnp->n_fid.f_parent;
899 fid.f_parent = dnp->n_fid.f_id;
900 NCPVNDEBUG("call to ncp_lookup returned=%d\n",notfound);
902 if (notfound && notfound < 0x80 )
903 return (notfound); /* hard error */
904 if (notfound) { /* entry not found */
905 /* Handle RENAME or CREATE case... */
906 if ((nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && wantparent) {
909 return (EJUSTRETURN);
913 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
915 /* handle DELETE case ... */
916 if (nameiop == NAMEI_DELETE) { /* delete last component */
917 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
918 if (error) return (error);
919 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
924 error = nwfs_nget(mp, fid, fap, dvp, &vp);
925 if (error) return (error);
927 if (!lockparent) vn_unlock(dvp);
930 if (nameiop == NAMEI_RENAME && wantparent) {
931 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
932 if (error) return (error);
933 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
934 error = nwfs_nget(mp, fid, fap, dvp, &vp);
935 if (error) return (error);
941 if (flags & CNP_ISDOTDOT) {
942 vn_unlock(dvp); /* race to get the inode */
943 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
945 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
948 if (lockparent && (error = vn_lock(dvp, LK_EXCLUSIVE))) {
953 } else if (NWCMPF(&dnp->n_fid, &fid)) {
957 error = nwfs_nget(mp, fid, fap, dvp, &vp);
958 if (error) return (error);
960 NCPVNDEBUG("lookup: getnewvp!\n");
965 /* XXX MOVE TO NREMOVE */
966 if ((cnp->cn_flags & CNP_MAKEENTRY)) {
967 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;