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.31 2006/07/19 06:08:13 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_islocked = vop_stdislocked,
101 .vop_old_link = nwfs_link,
102 .vop_lock = vop_stdlock,
103 .vop_old_lookup = nwfs_lookup,
104 .vop_old_mkdir = nwfs_mkdir,
105 .vop_old_mknod = nwfs_mknod,
106 .vop_pathconf = nwfs_pathconf,
107 .vop_print = nwfs_print,
108 .vop_read = nwfs_read,
109 .vop_readdir = nwfs_readdir,
110 .vop_reclaim = nwfs_reclaim,
111 .vop_old_remove = nwfs_remove,
112 .vop_old_rename = nwfs_rename,
113 .vop_old_rmdir = nwfs_rmdir,
114 .vop_setattr = nwfs_setattr,
115 .vop_strategy = nwfs_strategy,
116 .vop_old_symlink = nwfs_symlink,
117 .vop_unlock = vop_stdunlock,
118 .vop_write = nwfs_write
122 * nwfs_access vnode op
123 * for now just return ok
125 * nwfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
126 * struct thread *a_td)
129 nwfs_access(struct vop_access_args *ap)
131 struct vnode *vp = ap->a_vp;
132 struct ucred *cred = ap->a_cred;
133 u_int mode = ap->a_mode;
134 struct nwmount *nmp = VTONWFS(vp);
138 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
139 switch (vp->v_type) {
140 case VREG: case VDIR: case VLNK:
146 if (cred->cr_uid == 0)
148 if (cred->cr_uid != nmp->m.uid) {
150 if (!groupmember(nmp->m.gid, cred))
153 error = (((vp->v_type == VREG) ? nmp->m.file_mode : nmp->m.dir_mode) & mode) == mode ? 0 : EACCES;
159 * nwfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
163 nwfs_open(struct vop_open_args *ap)
165 thread_t td = curthread; /* XXX */
166 struct vnode *vp = ap->a_vp;
167 int mode = ap->a_mode;
168 struct nwnode *np = VTONW(vp);
169 struct ncp_open_info no;
170 struct nwmount *nmp = VTONWFS(vp);
174 NCPVNDEBUG("%s,%d\n",np->n_name, np->opened);
175 if (vp->v_type != VREG && vp->v_type != VDIR) {
176 NCPFATAL("open vtype = %d\n", vp->v_type);
179 if (vp->v_type == VDIR) return 0; /* nothing to do now */
180 if (np->n_flag & NMODIFIED) {
181 if ((error = nwfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
184 error = VOP_GETATTR(vp, &vattr);
187 np->n_mtime = vattr.va_mtime.tv_sec;
189 error = VOP_GETATTR(vp, &vattr);
192 if (np->n_mtime != vattr.va_mtime.tv_sec) {
193 if ((error = nwfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
195 np->n_mtime = vattr.va_mtime.tv_sec;
200 return (vop_stdopen(ap));
203 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
205 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
206 0, nwm, &no, td, ap->a_cred);
211 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
212 nwm, &no, td, ap->a_cred);
218 np->n_origfh = no.origfh;
219 error = vop_stdopen(ap);
225 * nwfs_close(struct vnode *a_vp, int a_fflag,
226 * struct ucred *a_cred, struct thread *a_td)
229 nwfs_close(struct vop_close_args *ap)
231 thread_t td = curthread; /* XXX */
232 struct vnode *vp = ap->a_vp;
233 struct nwnode *np = VTONW(vp);
236 NCPVNDEBUG("name=%s,td=%p,c=%d\n",np->n_name,ap->a_td,np->opened);
239 if (vp->v_type == VDIR)
243 error = nwfs_vinvalbuf(vp, V_SAVE, 1);
244 if (np->opened == 0) {
245 error = 0; /* huh? */
248 if (--np->opened == 0) {
249 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
259 * nwfs_getattr call from vfs.
261 * nwfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
262 * struct thread *a_td)
265 nwfs_getattr(struct vop_getattr_args *ap)
267 thread_t td = curthread; /* XXX */
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_flag & VROOT) != 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,
285 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
286 np->n_name, &fattr, td, proc0.p_ucred);
289 NCPVNDEBUG("error %d\n", error);
292 nwfs_attr_cacheenter(vp, &fattr);
295 np->n_size = oldsize;
299 * nwfs_setattr call from vfs.
301 * nwfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred)
304 nwfs_setattr(struct vop_setattr_args *ap)
306 thread_t td = curthread; /* XXX */
307 struct vnode *vp = ap->a_vp;
308 struct nwnode *np = VTONW(vp);
309 struct vattr *vap = ap->a_vap;
314 if (vap->va_flags != VNOVAL)
317 * Disallow write attempts if the filesystem is mounted read-only.
319 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
320 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
321 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
323 if (vap->va_size != VNOVAL) {
324 switch (vp->v_type) {
329 * Disallow write attempts if the filesystem is
332 if (vp->v_mount->mnt_flag & MNT_RDONLY)
334 vnode_pager_setsize(vp, (u_long)vap->va_size);
336 np->n_size = vap->va_size;
342 error = ncp_setattr(vp, vap, ap->a_cred, td);
343 if (error && vap->va_size != VNOVAL) {
345 vnode_pager_setsize(vp, (u_long)tsize);
347 np->n_atime = 0; /* invalidate cache */
348 VOP_GETATTR(vp, vap);
349 np->n_mtime = vap->va_mtime.tv_sec;
356 * nwfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
357 * struct ucred *a_cred)
360 nwfs_read(struct vop_read_args *ap)
362 struct vnode *vp = ap->a_vp;
363 struct uio *uio=ap->a_uio;
365 NCPVNDEBUG("nwfs_read:\n");
367 if (vp->v_type != VREG && vp->v_type != VDIR)
369 error = nwfs_readvnode(vp, uio, ap->a_cred);
374 * nwfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
375 * struct ucred *a_cred)
378 nwfs_write(struct vop_write_args *ap)
380 struct vnode *vp = ap->a_vp;
381 struct uio *uio = ap->a_uio;
384 NCPVNDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
386 if (vp->v_type != VREG)
388 error = nwfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
393 * Create a regular file. On entry the directory to contain the file being
394 * created is locked. We must release before we return.
396 * nwfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
397 * struct componentname *a_cnpl, struct vattr *a_vap)
400 nwfs_create(struct vop_old_create_args *ap)
402 struct vnode *dvp = ap->a_dvp;
403 struct vattr *vap = ap->a_vap;
404 struct vnode **vpp=ap->a_vpp;
405 struct componentname *cnp = ap->a_cnp;
406 struct vnode *vp = (struct vnode *)0;
407 int error = 0, fmode;
410 struct ncp_open_info no;
411 struct nwmount *nmp=VTONWFS(dvp);
417 if (vap->va_type == VSOCK)
419 if ((error = VOP_GETATTR(dvp, &vattr))) {
422 fmode = AR_READ | AR_WRITE;
423 /* if (vap->va_vaflags & VA_EXCLUSIVE)
424 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
426 error = ncp_open_create_file_or_subdir(nmp,dvp,cnp->cn_namelen,cnp->cn_nameptr,
427 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
428 0, fmode, &no, cnp->cn_td, cnp->cn_cred);
430 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_td,cnp->cn_cred);
431 fid.f_parent = VTONW(dvp)->n_fid.f_id;
432 fid.f_id = no.fattr.dirEntNum;
433 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
444 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
445 * NetWare doesn't allow delete/rename operations on an opened file.
447 * nwfs_remove(struct vnode *a_dvp,
448 * struct vnode *a_vp, struct componentname *a_cnp)
451 nwfs_remove(struct vop_old_remove_args *ap)
453 struct vnode *vp = ap->a_vp;
454 struct vnode *dvp = ap->a_dvp;
455 struct componentname *cnp = ap->a_cnp;
456 struct nwnode *np = VTONW(vp);
457 struct nwmount *nmp = VTONWFS(vp);
460 if (vp->v_type == VDIR || np->opened || vp->v_usecount != 1) {
462 } else if (!ncp_conn_valid(NWFSTOCONN(nmp))) {
465 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
466 cnp->cn_namelen,cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
468 np->n_flag |= NSHOULDFREE;
469 else if (error == 0x899c)
476 * nwfs_file rename call
478 * nwfs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
479 * struct componentname *a_fcnp, struct vnode *a_tdvp,
480 * struct vnode *a_tvp, struct componentname *a_tcnp)
483 nwfs_rename(struct vop_old_rename_args *ap)
485 struct vnode *fvp = ap->a_fvp;
486 struct vnode *tvp = ap->a_tvp;
487 struct vnode *fdvp = ap->a_fdvp;
488 struct vnode *tdvp = ap->a_tdvp;
489 struct componentname *tcnp = ap->a_tcnp;
490 struct componentname *fcnp = ap->a_fcnp;
491 struct nwmount *nmp=VTONWFS(fvp);
492 u_int16_t oldtype = 6;
495 /* Check for cross-device rename */
496 if ((fvp->v_mount != tdvp->v_mount) ||
497 (tvp && (fvp->v_mount != tvp->v_mount))) {
502 if (tvp && tvp->v_usecount > 1) {
506 if (tvp && tvp != fvp) {
507 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
508 tcnp->cn_namelen, tcnp->cn_nameptr,
509 tcnp->cn_td, tcnp->cn_cred);
510 if (error == 0x899c) error = EACCES;
514 if (fvp->v_type == VDIR) {
515 oldtype |= NW_TYPE_SUBDIR;
516 } else if (fvp->v_type == VREG) {
517 oldtype |= NW_TYPE_FILE;
520 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
521 oldtype, &nmp->m.nls,
522 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
523 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
524 tcnp->cn_td,tcnp->cn_cred);
537 nwfs_attr_cacheremove(fdvp);
538 nwfs_attr_cacheremove(tdvp);
540 * Need to get rid of old vnodes, because netware will change
547 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
555 * nwfs hard link create call
556 * Netware filesystems don't know what links are.
558 * nwfs_link(struct vnode *a_tdvp, struct vnode *a_vp,
559 * struct componentname *a_cnp)
562 nwfs_link(struct vop_old_link_args *ap)
568 * nwfs_symlink link create call
569 * Netware filesystems don't know what symlinks are.
571 * nwfs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
572 * struct componentname *a_cnp, struct vattr *a_vap,
576 nwfs_symlink(struct vop_old_symlink_args *ap)
581 static int nwfs_mknod(struct vop_old_mknod_args *ap)
589 * nwfs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
590 * struct componentname *a_cnp, struct vattr *a_vap)
593 nwfs_mkdir(struct vop_old_mkdir_args *ap)
595 struct vnode *dvp = ap->a_dvp;
596 /* struct vattr *vap = ap->a_vap;*/
597 struct componentname *cnp = ap->a_cnp;
598 int len=cnp->cn_namelen;
599 struct ncp_open_info no;
601 struct vnode *newvp = (struct vnode *)0;
605 char *name=cnp->cn_nameptr;
607 if ((error = VOP_GETATTR(dvp, &vattr))) {
610 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
613 if (ncp_open_create_file_or_subdir(VTONWFS(dvp),dvp, cnp->cn_namelen,
614 cnp->cn_nameptr,OC_MODE_CREATE, aDIR, 0xffff,
615 &no, cnp->cn_td, cnp->cn_cred) != 0) {
621 fid.f_parent = VTONW(dvp)->n_fid.f_id;
622 fid.f_id = no.fattr.dirEntNum;
623 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
626 newvp->v_type = VDIR;
634 * nwfs_remove directory call
636 * nwfs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
637 * struct componentname *a_cnp)
640 nwfs_rmdir(struct vop_old_rmdir_args *ap)
642 struct vnode *vp = ap->a_vp;
643 struct vnode *dvp = ap->a_dvp;
644 struct componentname *cnp = ap->a_cnp;
645 struct nwnode *np = VTONW(vp);
646 struct nwmount *nmp = VTONWFS(vp);
647 struct nwnode *dnp = VTONW(dvp);
653 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
654 cnp->cn_namelen, cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
656 np->n_flag |= NSHOULDFREE;
657 else if (error == NWE_DIR_NOT_EMPTY)
659 dnp->n_flag |= NMODIFIED;
660 nwfs_attr_cacheremove(dvp);
667 * nwfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
668 * int *a_eofflag, u_long *a_cookies, int a_ncookies)
671 nwfs_readdir(struct vop_readdir_args *ap)
673 struct vnode *vp = ap->a_vp;
674 struct uio *uio = ap->a_uio;
677 if (vp->v_type != VDIR)
679 if (ap->a_ncookies) {
680 printf("nwfs_readdir: no support for cookies now...");
684 error = nwfs_readvnode(vp, uio, ap->a_cred);
689 * nwfs_fsync(struct vnode *a_vp, struct ucred *a_cred,
690 * int a_waitfor, struct thread *a_td)
694 nwfs_fsync(struct vop_fsync_args *ap)
696 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
701 * nwfs_print(struct vnode *a_vp)
705 nwfs_print(struct vop_print_args *ap)
707 struct vnode *vp = ap->a_vp;
708 struct nwnode *np = VTONW(vp);
710 printf("nwfs node: name = '%s', fid = %d, pfid = %d\n",
711 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
716 * nwfs_pathconf(struct vnode *vp, int name, register_t *retval)
719 nwfs_pathconf(struct vop_pathconf_args *ap)
721 int name=ap->a_name, error=0;
722 register_t *retval=ap->a_retval;
729 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
732 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
741 * nwfs_strategy(struct vnode *a_vp, struct bio *a_bio)
744 nwfs_strategy(struct vop_strategy_args *ap)
746 struct bio *bio = ap->a_bio;
747 struct buf *bp = bio->bio_buf;
749 struct thread *td = NULL;
752 if ((bp->b_flags & B_ASYNC) == 0)
753 td = curthread; /* YYY dunno if this is legal */
755 * If the op is asynchronous and an i/o daemon is waiting
756 * queue the request, wake it up and wait for completion
757 * otherwise just do it ourselves.
759 if ((bp->b_flags & B_ASYNC) == 0 )
760 error = nwfs_doio(ap->a_vp, bio, proc0.p_ucred, td);
765 * nwfs_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
766 * off_t *a_doffsetp, int *a_runp, int *a_runb)
769 nwfs_bmap(struct vop_bmap_args *ap)
771 struct vnode *vp = ap->a_vp;
773 if (ap->a_vpp != NULL)
775 if (ap->a_doffsetp != NULL)
776 *ap->a_doffsetp = ap->a_loffset;
777 if (ap->a_runp != NULL)
779 if (ap->a_runb != NULL)
785 nwfs_nget(struct mount *mp, ncpfid fid, const struct nw_entry_info *fap,
786 struct vnode *dvp, struct vnode **vpp)
789 struct nwnode *newnp;
793 error = nwfs_allocvp(mp, fid, &vp);
798 newnp->n_attr = fap->attributes;
799 vp->v_type = newnp->n_attr & aDIR ? VDIR : VREG;
800 nwfs_attr_cacheenter(vp, fap);
803 newnp->n_parent = VTONW(dvp)->n_fid;
804 if ((newnp->n_flag & NNEW) && vp->v_type == VDIR) {
805 if ((dvp->v_flag & VROOT) == 0) {
806 newnp->n_refparent = 1;
807 vref(dvp); /* vhold */
811 if ((newnp->n_flag & NNEW) && vp->v_type == VREG)
812 printf("new vnode '%s' borned without parent ?\n",newnp->n_name);
814 newnp->n_flag &= ~NNEW;
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.
824 * nwfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
825 * struct componentname *a_cnp)
828 nwfs_lookup(struct vop_old_lookup_args *ap)
830 struct componentname *cnp = ap->a_cnp;
831 struct vnode *dvp = ap->a_dvp;
832 struct vnode **vpp = ap->a_vpp;
833 int flags = cnp->cn_flags;
836 struct mount *mp = dvp->v_mount;
837 struct nwnode *dnp, *npp;
838 struct nw_entry_info fattr, *fap;
840 int nameiop=cnp->cn_nameiop;
841 int lockparent, wantparent, error = 0, notfound;
842 struct thread *td = cnp->cn_td;
843 char _name[cnp->cn_namelen+1];
844 bcopy(cnp->cn_nameptr,_name,cnp->cn_namelen);
845 _name[cnp->cn_namelen]=0;
847 if (dvp->v_type != VDIR)
849 if ((flags & CNP_ISDOTDOT) && (dvp->v_flag & VROOT)) {
850 printf("nwfs_lookup: invalid '..'\n");
854 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
855 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
857 if ((mp->mnt_flag & MNT_RDONLY) && nameiop != NAMEI_LOOKUP)
859 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred)))
861 lockparent = flags & CNP_LOCKPARENT;
862 wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
866 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_flag & VROOT, (int)flags & CNP_ISDOTDOT);
868 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
869 (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
876 if (flags & CNP_ISDOTDOT) {
877 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
878 fid = nmp->n_rootent;
882 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
889 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
890 0, NULL, fap, td, cnp->cn_cred);
894 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
895 fap, td, cnp->cn_cred);
896 fid.f_id = fap->dirEntNum;
897 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
898 fid.f_parent = dnp->n_fid.f_parent;
900 fid.f_parent = dnp->n_fid.f_id;
901 NCPVNDEBUG("call to ncp_lookup returned=%d\n",notfound);
903 if (notfound && notfound < 0x80 )
904 return (notfound); /* hard error */
905 if (notfound) { /* entry not found */
906 /* Handle RENAME or CREATE case... */
907 if ((nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && wantparent) {
910 return (EJUSTRETURN);
914 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
916 /* handle DELETE case ... */
917 if (nameiop == NAMEI_DELETE) { /* delete last component */
918 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
919 if (error) return (error);
920 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
925 error = nwfs_nget(mp, fid, fap, dvp, &vp);
926 if (error) return (error);
928 if (!lockparent) VOP_UNLOCK(dvp, 0);
931 if (nameiop == NAMEI_RENAME && wantparent) {
932 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
933 if (error) return (error);
934 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
935 error = nwfs_nget(mp, fid, fap, dvp, &vp);
936 if (error) return (error);
942 if (flags & CNP_ISDOTDOT) {
943 VOP_UNLOCK(dvp, 0); /* race to get the inode */
944 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
946 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
949 if (lockparent && (error = vn_lock(dvp, LK_EXCLUSIVE))) {
954 } else if (NWCMPF(&dnp->n_fid, &fid)) {
958 error = nwfs_nget(mp, fid, fap, dvp, &vp);
959 if (error) return (error);
961 NCPVNDEBUG("lookup: getnewvp!\n");
966 /* XXX MOVE TO NREMOVE */
967 if ((cnp->cn_flags & CNP_MAKEENTRY)) {
968 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;