]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/smbfs/smbfs_vnops.c
Implement pci_enable_msi() and pci_disable_msi() in the LinuxKPI.
[FreeBSD/FreeBSD.git] / sys / fs / smbfs / smbfs_vnops.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2000-2001 Boris Popov
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/namei.h>
33 #include <sys/kernel.h>
34 #include <sys/proc.h>
35 #include <sys/bio.h>
36 #include <sys/buf.h>
37 #include <sys/fcntl.h>
38 #include <sys/mount.h>
39 #include <sys/unistd.h>
40 #include <sys/vnode.h>
41 #include <sys/limits.h>
42 #include <sys/lockf.h>
43 #include <sys/stat.h>
44
45 #include <vm/vm.h>
46 #include <vm/vm_extern.h>
47
48
49 #include <netsmb/smb.h>
50 #include <netsmb/smb_conn.h>
51 #include <netsmb/smb_subr.h>
52
53 #include <fs/smbfs/smbfs.h>
54 #include <fs/smbfs/smbfs_node.h>
55 #include <fs/smbfs/smbfs_subr.h>
56
57 /*
58  * Prototypes for SMBFS vnode operations
59  */
60 static vop_create_t     smbfs_create;
61 static vop_mknod_t      smbfs_mknod;
62 static vop_open_t       smbfs_open;
63 static vop_close_t      smbfs_close;
64 static vop_access_t     smbfs_access;
65 static vop_getattr_t    smbfs_getattr;
66 static vop_setattr_t    smbfs_setattr;
67 static vop_read_t       smbfs_read;
68 static vop_write_t      smbfs_write;
69 static vop_fsync_t      smbfs_fsync;
70 static vop_remove_t     smbfs_remove;
71 static vop_link_t       smbfs_link;
72 static vop_lookup_t     smbfs_lookup;
73 static vop_rename_t     smbfs_rename;
74 static vop_mkdir_t      smbfs_mkdir;
75 static vop_rmdir_t      smbfs_rmdir;
76 static vop_symlink_t    smbfs_symlink;
77 static vop_readdir_t    smbfs_readdir;
78 static vop_strategy_t   smbfs_strategy;
79 static vop_print_t      smbfs_print;
80 static vop_pathconf_t   smbfs_pathconf;
81 static vop_advlock_t    smbfs_advlock;
82 static vop_getextattr_t smbfs_getextattr;
83
84 struct vop_vector smbfs_vnodeops = {
85         .vop_default =          &default_vnodeops,
86
87         .vop_access =           smbfs_access,
88         .vop_advlock =          smbfs_advlock,
89         .vop_close =            smbfs_close,
90         .vop_create =           smbfs_create,
91         .vop_fsync =            smbfs_fsync,
92         .vop_getattr =          smbfs_getattr,
93         .vop_getextattr =       smbfs_getextattr,
94         .vop_getpages =         smbfs_getpages,
95         .vop_inactive =         smbfs_inactive,
96         .vop_ioctl =            smbfs_ioctl,
97         .vop_link =             smbfs_link,
98         .vop_lookup =           smbfs_lookup,
99         .vop_mkdir =            smbfs_mkdir,
100         .vop_mknod =            smbfs_mknod,
101         .vop_open =             smbfs_open,
102         .vop_pathconf =         smbfs_pathconf,
103         .vop_print =            smbfs_print,
104         .vop_putpages =         smbfs_putpages,
105         .vop_read =             smbfs_read,
106         .vop_readdir =          smbfs_readdir,
107         .vop_reclaim =          smbfs_reclaim,
108         .vop_remove =           smbfs_remove,
109         .vop_rename =           smbfs_rename,
110         .vop_rmdir =            smbfs_rmdir,
111         .vop_setattr =          smbfs_setattr,
112 /*      .vop_setextattr =       smbfs_setextattr,*/
113         .vop_strategy =         smbfs_strategy,
114         .vop_symlink =          smbfs_symlink,
115         .vop_write =            smbfs_write,
116 };
117
118 static int
119 smbfs_access(ap)
120         struct vop_access_args /* {
121                 struct vnode *a_vp;
122                 accmode_t a_accmode;
123                 struct ucred *a_cred;
124                 struct thread *a_td;
125         } */ *ap;
126 {
127         struct vnode *vp = ap->a_vp;
128         accmode_t accmode = ap->a_accmode;
129         mode_t mpmode;
130         struct smbmount *smp = VTOSMBFS(vp);
131
132         SMBVDEBUG("\n");
133         if ((accmode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
134                 switch (vp->v_type) {
135                     case VREG: case VDIR: case VLNK:
136                         return EROFS;
137                     default:
138                         break;
139                 }
140         }
141         mpmode = vp->v_type == VREG ? smp->sm_file_mode : smp->sm_dir_mode;
142         return (vaccess(vp->v_type, mpmode, smp->sm_uid,
143             smp->sm_gid, ap->a_accmode, ap->a_cred, NULL));
144 }
145
146 /* ARGSUSED */
147 static int
148 smbfs_open(ap)
149         struct vop_open_args /* {
150                 struct vnode *a_vp;
151                 int  a_mode;
152                 struct ucred *a_cred;
153                 struct thread *a_td;
154         } */ *ap;
155 {
156         struct vnode *vp = ap->a_vp;
157         struct smbnode *np = VTOSMB(vp);
158         struct smb_cred *scred;
159         struct vattr vattr;
160         int mode = ap->a_mode;
161         int error, accmode;
162
163         SMBVDEBUG("%s,%d\n", np->n_name, (np->n_flag & NOPEN) != 0);
164         if (vp->v_type != VREG && vp->v_type != VDIR) { 
165                 SMBFSERR("open eacces vtype=%d\n", vp->v_type);
166                 return EACCES;
167         }
168         if (vp->v_type == VDIR) {
169                 np->n_flag |= NOPEN;
170                 return 0;
171         }
172         if (np->n_flag & NMODIFIED) {
173                 if ((error = smbfs_vinvalbuf(vp, ap->a_td)) == EINTR)
174                         return error;
175                 smbfs_attr_cacheremove(vp);
176                 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
177                 if (error)
178                         return error;
179                 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
180         } else {
181                 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
182                 if (error)
183                         return error;
184                 if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
185                         error = smbfs_vinvalbuf(vp, ap->a_td);
186                         if (error == EINTR)
187                                 return error;
188                         np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
189                 }
190         }
191         if ((np->n_flag & NOPEN) != 0)
192                 return 0;
193         /*
194          * Use DENYNONE to give unixy semantics of permitting
195          * everything not forbidden by permissions.  Ie denial
196          * is up to server with clients/openers needing to use
197          * advisory locks for further control.
198          */
199         accmode = SMB_SM_DENYNONE|SMB_AM_OPENREAD;
200         if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
201                 accmode = SMB_SM_DENYNONE|SMB_AM_OPENRW;
202         scred = smbfs_malloc_scred();
203         smb_makescred(scred, ap->a_td, ap->a_cred);
204         error = smbfs_smb_open(np, accmode, scred);
205         if (error) {
206                 if (mode & FWRITE)
207                         return EACCES;
208                 else if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
209                         accmode = SMB_SM_DENYNONE|SMB_AM_OPENREAD;
210                         error = smbfs_smb_open(np, accmode, scred);
211                 }
212         }
213         if (error == 0) {
214                 np->n_flag |= NOPEN;
215                 vnode_create_vobject(ap->a_vp, vattr.va_size, ap->a_td);
216         }
217         smbfs_attr_cacheremove(vp);
218         smbfs_free_scred(scred);
219         return error;
220 }
221
222 static int
223 smbfs_close(ap)
224         struct vop_close_args /* {
225                 struct vnodeop_desc *a_desc;
226                 struct vnode *a_vp;
227                 int  a_fflag;
228                 struct ucred *a_cred;
229                 struct thread *a_td;
230         } */ *ap;
231 {
232         struct vnode *vp = ap->a_vp;
233         struct thread *td = ap->a_td;
234         struct smbnode *np = VTOSMB(vp);
235         struct smb_cred *scred;
236
237         if (vp->v_type == VDIR && (np->n_flag & NOPEN) != 0 &&
238             np->n_dirseq != NULL) {
239                 scred = smbfs_malloc_scred();
240                 smb_makescred(scred, td, ap->a_cred);
241                 smbfs_findclose(np->n_dirseq, scred);
242                 smbfs_free_scred(scred);
243                 np->n_dirseq = NULL;
244         }
245         return 0;
246 }
247
248 /*
249  * smbfs_getattr call from vfs.
250  */
251 static int
252 smbfs_getattr(ap)
253         struct vop_getattr_args /* {
254                 struct vnode *a_vp;
255                 struct vattr *a_vap;
256                 struct ucred *a_cred;
257         } */ *ap;
258 {
259         struct vnode *vp = ap->a_vp;
260         struct smbnode *np = VTOSMB(vp);
261         struct vattr *va=ap->a_vap;
262         struct smbfattr fattr;
263         struct smb_cred *scred;
264         u_quad_t oldsize;
265         int error;
266
267         SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
268         error = smbfs_attr_cachelookup(vp, va);
269         if (!error)
270                 return 0;
271         SMBVDEBUG("not in the cache\n");
272         scred = smbfs_malloc_scred();
273         smb_makescred(scred, curthread, ap->a_cred);
274         oldsize = np->n_size;
275         error = smbfs_smb_lookup(np, NULL, 0, &fattr, scred);
276         if (error) {
277                 SMBVDEBUG("error %d\n", error);
278                 smbfs_free_scred(scred);
279                 return error;
280         }
281         smbfs_attr_cacheenter(vp, &fattr);
282         smbfs_attr_cachelookup(vp, va);
283         if (np->n_flag & NOPEN)
284                 np->n_size = oldsize;
285         smbfs_free_scred(scred);
286         return 0;
287 }
288
289 static int
290 smbfs_setattr(ap)
291         struct vop_setattr_args /* {
292                 struct vnode *a_vp;
293                 struct vattr *a_vap;
294                 struct ucred *a_cred;
295         } */ *ap;
296 {
297         struct vnode *vp = ap->a_vp;
298         struct smbnode *np = VTOSMB(vp);
299         struct vattr *vap = ap->a_vap;
300         struct timespec *mtime, *atime;
301         struct smb_cred *scred;
302         struct smb_share *ssp = np->n_mount->sm_share;
303         struct smb_vc *vcp = SSTOVC(ssp);
304         struct thread *td = curthread;
305         u_quad_t tsize = 0;
306         int isreadonly, doclose, error = 0;
307         int old_n_dosattr;
308
309         SMBVDEBUG("\n");
310         isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
311         /*
312          * Disallow write attempts if the filesystem is mounted read-only.
313          */
314         if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL || 
315              vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
316              vap->va_mode != (mode_t)VNOVAL || vap->va_flags != VNOVAL) &&
317              isreadonly)
318                 return EROFS;
319
320         /*
321          * We only support setting four flags.  Don't allow setting others.
322          *
323          * We map UF_READONLY to SMB_FA_RDONLY, unlike the MacOS X version
324          * of this code, which maps both UF_IMMUTABLE AND SF_IMMUTABLE to
325          * SMB_FA_RDONLY.  The immutable flags have different semantics
326          * than readonly, which is the reason for the difference.
327          */
328         if (vap->va_flags != VNOVAL) {
329                 if (vap->va_flags & ~(UF_HIDDEN|UF_SYSTEM|UF_ARCHIVE|
330                                       UF_READONLY))
331                         return EINVAL;
332         }
333
334         scred = smbfs_malloc_scred();
335         smb_makescred(scred, td, ap->a_cred);
336         if (vap->va_size != VNOVAL) {
337                 switch (vp->v_type) {
338                     case VDIR:
339                         error = EISDIR;
340                         goto out;
341                     case VREG:
342                         break;
343                     default:
344                         error = EINVAL;
345                         goto out;
346                 }
347                 if (isreadonly) {
348                         error = EROFS;
349                         goto out;
350                 }
351                 doclose = 0;
352                 vnode_pager_setsize(vp, (u_long)vap->va_size);
353                 tsize = np->n_size;
354                 np->n_size = vap->va_size;
355                 if ((np->n_flag & NOPEN) == 0) {
356                         error = smbfs_smb_open(np,
357                                                SMB_SM_DENYNONE|SMB_AM_OPENRW,
358                                                scred);
359                         if (error == 0)
360                                 doclose = 1;
361                 }
362                 if (error == 0)
363                         error = smbfs_smb_setfsize(np,
364                             (int64_t)vap->va_size, scred);
365                 if (doclose)
366                         smbfs_smb_close(ssp, np->n_fid, NULL, scred);
367                 if (error) {
368                         np->n_size = tsize;
369                         vnode_pager_setsize(vp, (u_long)tsize);
370                         goto out;
371                 }
372         }
373         if ((vap->va_flags != VNOVAL) || (vap->va_mode != (mode_t)VNOVAL)) {
374                 old_n_dosattr = np->n_dosattr;
375
376                 if (vap->va_mode != (mode_t)VNOVAL) {
377                         if (vap->va_mode & S_IWUSR)
378                                 np->n_dosattr &= ~SMB_FA_RDONLY;
379                         else
380                                 np->n_dosattr |= SMB_FA_RDONLY;
381                 }
382
383                 if (vap->va_flags != VNOVAL) {
384                         if (vap->va_flags & UF_HIDDEN)
385                                 np->n_dosattr |= SMB_FA_HIDDEN;
386                         else
387                                 np->n_dosattr &= ~SMB_FA_HIDDEN;
388
389                         if (vap->va_flags & UF_SYSTEM)
390                                 np->n_dosattr |= SMB_FA_SYSTEM;
391                         else
392                                 np->n_dosattr &= ~SMB_FA_SYSTEM;
393
394                         if (vap->va_flags & UF_ARCHIVE)
395                                 np->n_dosattr |= SMB_FA_ARCHIVE;
396                         else
397                                 np->n_dosattr &= ~SMB_FA_ARCHIVE;
398
399                         /*
400                          * We only support setting the immutable / readonly
401                          * bit for regular files.  According to comments in
402                          * the MacOS X version of this code, supporting the
403                          * readonly bit on directories doesn't do the same
404                          * thing in Windows as in Unix.
405                          */
406                         if (vp->v_type == VREG) {
407                                 if (vap->va_flags & UF_READONLY)
408                                         np->n_dosattr |= SMB_FA_RDONLY;
409                                 else
410                                         np->n_dosattr &= ~SMB_FA_RDONLY;
411                         }
412                 }
413
414                 if (np->n_dosattr != old_n_dosattr) {
415                         error = smbfs_smb_setpattr(np, np->n_dosattr, NULL, scred);
416                         if (error)
417                                 goto out;
418                 }
419         }
420         mtime = atime = NULL;
421         if (vap->va_mtime.tv_sec != VNOVAL)
422                 mtime = &vap->va_mtime;
423         if (vap->va_atime.tv_sec != VNOVAL)
424                 atime = &vap->va_atime;
425         if (mtime != atime) {
426                 if (vap->va_vaflags & VA_UTIMES_NULL) {
427                         error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td);
428                         if (error)
429                                 error = VOP_ACCESS(vp, VWRITE, ap->a_cred, td);
430                 } else
431                         error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td);
432 #if 0
433                 if (mtime == NULL)
434                         mtime = &np->n_mtime;
435                 if (atime == NULL)
436                         atime = &np->n_atime;
437 #endif
438                 /*
439                  * If file is opened, then we can use handle based calls.
440                  * If not, use path based ones.
441                  */
442                 if ((np->n_flag & NOPEN) == 0) {
443                         if (vcp->vc_flags & SMBV_WIN95) {
444                                 error = VOP_OPEN(vp, FWRITE, ap->a_cred, td,
445                                     NULL);
446                                 if (!error) {
447 /*                                      error = smbfs_smb_setfattrNT(np, 0,
448                                             mtime, atime, scred);
449                                         VOP_GETATTR(vp, &vattr, ap->a_cred); */
450                                         if (mtime)
451                                                 np->n_mtime = *mtime;
452                                         VOP_CLOSE(vp, FWRITE, ap->a_cred, td);
453                                 }
454                         } else if ((vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS)) {
455                                 error = smbfs_smb_setptime2(np, mtime, atime, 0, scred);
456 /*                              error = smbfs_smb_setpattrNT(np, 0, mtime, atime, scred);*/
457                         } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
458                                 error = smbfs_smb_setptime2(np, mtime, atime, 0, scred);
459                         } else {
460                                 error = smbfs_smb_setpattr(np, 0, mtime, scred);
461                         }
462                 } else {
463                         if (vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS) {
464                                 error = smbfs_smb_setfattrNT(np, 0, mtime, atime, scred);
465                         } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN1_0) {
466                                 error = smbfs_smb_setftime(np, mtime, atime, scred);
467                         } else {
468                                 /*
469                                  * I have no idea how to handle this for core
470                                  * level servers. The possible solution is to
471                                  * update mtime after file is closed.
472                                  */
473                                  SMBERROR("can't update times on an opened file\n");
474                         }
475                 }
476         }
477         /*
478          * Invalidate attribute cache in case if server doesn't set
479          * required attributes.
480          */
481         smbfs_attr_cacheremove(vp);     /* invalidate cache */
482         VOP_GETATTR(vp, vap, ap->a_cred);
483         np->n_mtime.tv_sec = vap->va_mtime.tv_sec;
484 out:
485         smbfs_free_scred(scred);
486         return error;
487 }
488 /*
489  * smbfs_read call.
490  */
491 static int
492 smbfs_read(ap)
493         struct vop_read_args /* {
494                 struct vnode *a_vp;
495                 struct uio *a_uio;
496                 int  a_ioflag;
497                 struct ucred *a_cred;
498         } */ *ap;
499 {
500         struct vnode *vp = ap->a_vp;
501         struct uio *uio = ap->a_uio;
502
503         SMBVDEBUG("\n");
504         if (vp->v_type != VREG && vp->v_type != VDIR)
505                 return EPERM;
506         return smbfs_readvnode(vp, uio, ap->a_cred);
507 }
508
509 static int
510 smbfs_write(ap)
511         struct vop_write_args /* {
512                 struct vnode *a_vp;
513                 struct uio *a_uio;
514                 int  a_ioflag;
515                 struct ucred *a_cred;
516         } */ *ap;
517 {
518         struct vnode *vp = ap->a_vp;
519         struct uio *uio = ap->a_uio;
520
521         SMBVDEBUG("%d,ofs=%jd,sz=%zd\n",vp->v_type, (intmax_t)uio->uio_offset, 
522             uio->uio_resid);
523         if (vp->v_type != VREG)
524                 return (EPERM);
525         return smbfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
526 }
527 /*
528  * smbfs_create call
529  * Create a regular file. On entry the directory to contain the file being
530  * created is locked.  We must release before we return. We must also free
531  * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
532  * only if the SAVESTART bit in cn_flags is clear on success.
533  */
534 static int
535 smbfs_create(ap)
536         struct vop_create_args /* {
537                 struct vnode *a_dvp;
538                 struct vnode **a_vpp;
539                 struct componentname *a_cnp;
540                 struct vattr *a_vap;
541         } */ *ap;
542 {
543         struct vnode *dvp = ap->a_dvp;
544         struct vattr *vap = ap->a_vap;
545         struct vnode **vpp=ap->a_vpp;
546         struct componentname *cnp = ap->a_cnp;
547         struct smbnode *dnp = VTOSMB(dvp);
548         struct vnode *vp;
549         struct vattr vattr;
550         struct smbfattr fattr;
551         struct smb_cred *scred;
552         char *name = cnp->cn_nameptr;
553         int nmlen = cnp->cn_namelen;
554         int error;
555         
556
557         SMBVDEBUG("\n");
558         *vpp = NULL;
559         if (vap->va_type != VREG)
560                 return EOPNOTSUPP;
561         if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)))
562                 return error;
563         scred = smbfs_malloc_scred();
564         smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
565         
566         error = smbfs_smb_create(dnp, name, nmlen, scred);
567         if (error)
568                 goto out;
569         error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, scred);
570         if (error)
571                 goto out;
572         error = smbfs_nget(VTOVFS(dvp), dvp, name, nmlen, &fattr, &vp);
573         if (error)
574                 goto out;
575         *vpp = vp;
576         if (cnp->cn_flags & MAKEENTRY)
577                 cache_enter(dvp, vp, cnp);
578 out:
579         smbfs_free_scred(scred);
580         return error;
581 }
582
583 static int
584 smbfs_remove(ap)
585         struct vop_remove_args /* {
586                 struct vnodeop_desc *a_desc;
587                 struct vnode * a_dvp;
588                 struct vnode * a_vp;
589                 struct componentname * a_cnp;
590         } */ *ap;
591 {
592         struct vnode *vp = ap->a_vp;
593 /*      struct vnode *dvp = ap->a_dvp;*/
594         struct componentname *cnp = ap->a_cnp;
595         struct smbnode *np = VTOSMB(vp);
596         struct smb_cred *scred;
597         int error;
598
599         if (vp->v_type == VDIR || (np->n_flag & NOPEN) != 0 || vrefcnt(vp) != 1)
600                 return EPERM;
601         scred = smbfs_malloc_scred();
602         smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
603         error = smbfs_smb_delete(np, scred);
604         if (error == 0)
605                 np->n_flag |= NGONE;
606         cache_purge(vp);
607         smbfs_free_scred(scred);
608         return error;
609 }
610
611 /*
612  * smbfs_file rename call
613  */
614 static int
615 smbfs_rename(ap)
616         struct vop_rename_args  /* {
617                 struct vnode *a_fdvp;
618                 struct vnode *a_fvp;
619                 struct componentname *a_fcnp;
620                 struct vnode *a_tdvp;
621                 struct vnode *a_tvp;
622                 struct componentname *a_tcnp;
623         } */ *ap;
624 {
625         struct vnode *fvp = ap->a_fvp;
626         struct vnode *tvp = ap->a_tvp;
627         struct vnode *fdvp = ap->a_fdvp;
628         struct vnode *tdvp = ap->a_tdvp;
629         struct componentname *tcnp = ap->a_tcnp;
630 /*      struct componentname *fcnp = ap->a_fcnp;*/
631         struct smb_cred *scred;
632         u_int16_t flags = 6;
633         int error=0;
634
635         scred = NULL;
636         /* Check for cross-device rename */
637         if ((fvp->v_mount != tdvp->v_mount) ||
638             (tvp && (fvp->v_mount != tvp->v_mount))) {
639                 error = EXDEV;
640                 goto out;
641         }
642
643         if (tvp && vrefcnt(tvp) > 1) {
644                 error = EBUSY;
645                 goto out;
646         }
647         flags = 0x10;                   /* verify all writes */
648         if (fvp->v_type == VDIR) {
649                 flags |= 2;
650         } else if (fvp->v_type == VREG) {
651                 flags |= 1;
652         } else {
653                 return EINVAL;
654         }
655         scred = smbfs_malloc_scred();
656         smb_makescred(scred, tcnp->cn_thread, tcnp->cn_cred);
657         /*
658          * It seems that Samba doesn't implement SMB_COM_MOVE call...
659          */
660 #ifdef notnow
661         if (SMB_DIALECT(SSTOCN(smp->sm_share)) >= SMB_DIALECT_LANMAN1_0) {
662                 error = smbfs_smb_move(VTOSMB(fvp), VTOSMB(tdvp),
663                     tcnp->cn_nameptr, tcnp->cn_namelen, flags, scred);
664         } else
665 #endif
666         {
667                 /*
668                  * We have to do the work atomicaly
669                  */
670                 if (tvp && tvp != fvp) {
671                         error = smbfs_smb_delete(VTOSMB(tvp), scred);
672                         if (error)
673                                 goto out_cacherem;
674                         VTOSMB(fvp)->n_flag |= NGONE;
675                 }
676                 error = smbfs_smb_rename(VTOSMB(fvp), VTOSMB(tdvp),
677                     tcnp->cn_nameptr, tcnp->cn_namelen, scred);
678         }
679
680         if (fvp->v_type == VDIR) {
681                 if (tvp != NULL && tvp->v_type == VDIR)
682                         cache_purge(tdvp);
683                 cache_purge(fdvp);
684         }
685
686 out_cacherem:
687         smbfs_attr_cacheremove(fdvp);
688         smbfs_attr_cacheremove(tdvp);
689 out:
690         smbfs_free_scred(scred);
691         if (tdvp == tvp)
692                 vrele(tdvp);
693         else
694                 vput(tdvp);
695         if (tvp)
696                 vput(tvp);
697         vrele(fdvp);
698         vrele(fvp);
699 #ifdef possible_mistake
700         vgone(fvp);
701         if (tvp)
702                 vgone(tvp);
703 #endif
704         return error;
705 }
706
707 /*
708  * somtime it will come true...
709  */
710 static int
711 smbfs_link(ap)
712         struct vop_link_args /* {
713                 struct vnode *a_tdvp;
714                 struct vnode *a_vp;
715                 struct componentname *a_cnp;
716         } */ *ap;
717 {
718         return EOPNOTSUPP;
719 }
720
721 /*
722  * smbfs_symlink link create call.
723  * Sometime it will be functional...
724  */
725 static int
726 smbfs_symlink(ap)
727         struct vop_symlink_args /* {
728                 struct vnode *a_dvp;
729                 struct vnode **a_vpp;
730                 struct componentname *a_cnp;
731                 struct vattr *a_vap;
732                 char *a_target;
733         } */ *ap;
734 {
735         return EOPNOTSUPP;
736 }
737
738 static int
739 smbfs_mknod(ap) 
740         struct vop_mknod_args /* {
741         } */ *ap;
742 {
743         return EOPNOTSUPP;
744 }
745
746 static int
747 smbfs_mkdir(ap)
748         struct vop_mkdir_args /* {
749                 struct vnode *a_dvp;
750                 struct vnode **a_vpp;
751                 struct componentname *a_cnp;
752                 struct vattr *a_vap;
753         } */ *ap;
754 {
755         struct vnode *dvp = ap->a_dvp;
756 /*      struct vattr *vap = ap->a_vap;*/
757         struct vnode *vp;
758         struct componentname *cnp = ap->a_cnp;
759         struct smbnode *dnp = VTOSMB(dvp);
760         struct vattr vattr;
761         struct smb_cred *scred;
762         struct smbfattr fattr;
763         char *name = cnp->cn_nameptr;
764         int len = cnp->cn_namelen;
765         int error;
766
767         if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred))) {
768                 return error;
769         }       
770         if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.'))))
771                 return EEXIST;
772         scred = smbfs_malloc_scred();
773         smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
774         error = smbfs_smb_mkdir(dnp, name, len, scred);
775         if (error)
776                 goto out;
777         error = smbfs_smb_lookup(dnp, name, len, &fattr, scred);
778         if (error)
779                 goto out;
780         error = smbfs_nget(VTOVFS(dvp), dvp, name, len, &fattr, &vp);
781         if (error)
782                 goto out;
783         *ap->a_vpp = vp;
784 out:
785         smbfs_free_scred(scred);
786         return error;
787 }
788
789 /*
790  * smbfs_remove directory call
791  */
792 static int
793 smbfs_rmdir(ap)
794         struct vop_rmdir_args /* {
795                 struct vnode *a_dvp;
796                 struct vnode *a_vp;
797                 struct componentname *a_cnp;
798         } */ *ap;
799 {
800         struct vnode *vp = ap->a_vp;
801         struct vnode *dvp = ap->a_dvp;
802         struct componentname *cnp = ap->a_cnp;
803 /*      struct smbmount *smp = VTOSMBFS(vp);*/
804         struct smbnode *dnp = VTOSMB(dvp);
805         struct smbnode *np = VTOSMB(vp);
806         struct smb_cred *scred;
807         int error;
808
809         if (dvp == vp)
810                 return EINVAL;
811
812         scred = smbfs_malloc_scred();
813         smb_makescred(scred, cnp->cn_thread, cnp->cn_cred);
814         error = smbfs_smb_rmdir(np, scred);
815         if (error == 0)
816                 np->n_flag |= NGONE;
817         dnp->n_flag |= NMODIFIED;
818         smbfs_attr_cacheremove(dvp);
819 /*      cache_purge(dvp);*/
820         cache_purge(vp);
821         smbfs_free_scred(scred);
822         return error;
823 }
824
825 /*
826  * smbfs_readdir call
827  */
828 static int
829 smbfs_readdir(ap)
830         struct vop_readdir_args /* {
831                 struct vnode *a_vp;
832                 struct uio *a_uio;
833                 struct ucred *a_cred;
834                 int *a_eofflag;
835                 u_long *a_cookies;
836                 int a_ncookies;
837         } */ *ap;
838 {
839         struct vnode *vp = ap->a_vp;
840         struct uio *uio = ap->a_uio;
841         int error;
842
843         if (vp->v_type != VDIR)
844                 return (EPERM);
845 #ifdef notnow
846         if (ap->a_ncookies) {
847                 printf("smbfs_readdir: no support for cookies now...");
848                 return (EOPNOTSUPP);
849         }
850 #endif
851         error = smbfs_readvnode(vp, uio, ap->a_cred);
852         return error;
853 }
854
855 /* ARGSUSED */
856 static int
857 smbfs_fsync(ap)
858         struct vop_fsync_args /* {
859                 struct vnodeop_desc *a_desc;
860                 struct vnode * a_vp;
861                 struct ucred * a_cred;
862                 int  a_waitfor;
863                 struct thread * a_td;
864         } */ *ap;
865 {
866 /*      return (smb_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
867     return (0);
868 }
869
870 static 
871 int smbfs_print (ap) 
872         struct vop_print_args /* {
873         struct vnode *a_vp;
874         } */ *ap;
875 {
876         struct vnode *vp = ap->a_vp;
877         struct smbnode *np = VTOSMB(vp);
878
879         if (np == NULL) {
880                 printf("no smbnode data\n");
881                 return (0);
882         }
883         printf("\tname = %s, parent = %p, open = %d\n", np->n_name,
884             np->n_parent ? np->n_parent : NULL, (np->n_flag & NOPEN) != 0);
885         return (0);
886 }
887
888 static int
889 smbfs_pathconf (ap)
890         struct vop_pathconf_args  /* {
891         struct vnode *vp;
892         int name;
893         register_t *retval;
894         } */ *ap;
895 {
896         struct smbmount *smp = VFSTOSMBFS(VTOVFS(ap->a_vp));
897         struct smb_vc *vcp = SSTOVC(smp->sm_share);
898         long *retval = ap->a_retval;
899         int error = 0;
900         
901         switch (ap->a_name) {
902             case _PC_FILESIZEBITS:
903                 if (vcp->vc_sopt.sv_caps & (SMB_CAP_LARGE_READX |
904                     SMB_CAP_LARGE_WRITEX))
905                     *retval = 64;
906                 else
907                     *retval = 32;
908                 break;
909             case _PC_NAME_MAX:
910                 *retval = (vcp->vc_hflags2 & SMB_FLAGS2_KNOWS_LONG_NAMES) ? 255 : 12;
911                 break;
912             case _PC_PATH_MAX:
913                 *retval = 800;  /* XXX: a correct one ? */
914                 break;
915             case _PC_NO_TRUNC:
916                 *retval = 1;
917                 break;
918             default:
919                 error = vop_stdpathconf(ap);
920         }
921         return error;
922 }
923
924 static int
925 smbfs_strategy (ap) 
926         struct vop_strategy_args /* {
927         struct buf *a_bp
928         } */ *ap;
929 {
930         struct buf *bp=ap->a_bp;
931         struct ucred *cr;
932         struct thread *td;
933
934         SMBVDEBUG("\n");
935         if (bp->b_flags & B_ASYNC)
936                 td = (struct thread *)0;
937         else
938                 td = curthread; /* XXX */
939         if (bp->b_iocmd == BIO_READ)
940                 cr = bp->b_rcred;
941         else
942                 cr = bp->b_wcred;
943
944         if ((bp->b_flags & B_ASYNC) == 0 )
945                 (void)smbfs_doio(ap->a_vp, bp, cr, td);
946         return (0);
947 }
948
949 int
950 smbfs_ioctl(ap)
951         struct vop_ioctl_args /* {
952                 struct vnode *a_vp;
953                 u_long a_command;
954                 caddr_t a_data;
955                 int fflag;
956                 struct ucred *cred;
957                 struct thread *td;
958         } */ *ap;
959 {
960         return ENOTTY;
961 }
962
963 static char smbfs_atl[] = "rhsvda";
964 static int
965 smbfs_getextattr(struct vop_getextattr_args *ap)
966 /* {
967         IN struct vnode *a_vp;
968         IN char *a_name;
969         INOUT struct uio *a_uio;
970         IN struct ucred *a_cred;
971         IN struct thread *a_td;
972 };
973 */
974 {
975         struct vnode *vp = ap->a_vp;
976         struct thread *td = ap->a_td;
977         struct ucred *cred = ap->a_cred;
978         struct uio *uio = ap->a_uio;
979         const char *name = ap->a_name;
980         struct smbnode *np = VTOSMB(vp);
981         struct vattr vattr;
982         char buf[10];
983         int i, attr, error;
984
985         error = VOP_ACCESS(vp, VREAD, cred, td);
986         if (error)
987                 return error;
988         error = VOP_GETATTR(vp, &vattr, cred);
989         if (error)
990                 return error;
991         if (strcmp(name, "dosattr") == 0) {
992                 attr = np->n_dosattr;
993                 for (i = 0; i < 6; i++, attr >>= 1)
994                         buf[i] = (attr & 1) ? smbfs_atl[i] : '-';
995                 buf[i] = 0;
996                 error = uiomove(buf, i, uio);
997                 
998         } else
999                 error = EINVAL;
1000         return error;
1001 }
1002
1003 /*
1004  * Since we expected to support F_GETLK (and SMB protocol has no such function),
1005  * it is necessary to use lf_advlock(). It would be nice if this function had
1006  * a callback mechanism because it will help to improve a level of consistency.
1007  */
1008 int
1009 smbfs_advlock(ap)
1010         struct vop_advlock_args /* {
1011                 struct vnode *a_vp;
1012                 caddr_t  a_id;
1013                 int  a_op;
1014                 struct flock *a_fl;
1015                 int  a_flags;
1016         } */ *ap;
1017 {
1018         struct vnode *vp = ap->a_vp;
1019         struct smbnode *np = VTOSMB(vp);
1020         struct flock *fl = ap->a_fl;
1021         caddr_t id = (caddr_t)1 /* ap->a_id */;
1022 /*      int flags = ap->a_flags;*/
1023         struct thread *td = curthread;
1024         struct smb_cred *scred;
1025         u_quad_t size;
1026         off_t start, end, oadd;
1027         int error, lkop;
1028
1029         if (vp->v_type == VDIR) {
1030                 /*
1031                  * SMB protocol have no support for directory locking.
1032                  * Although locks can be processed on local machine, I don't
1033                  * think that this is a good idea, because some programs
1034                  * can work wrong assuming directory is locked. So, we just
1035                  * return 'operation not supported
1036                  */
1037                  return EOPNOTSUPP;
1038         }
1039         size = np->n_size;
1040         switch (fl->l_whence) {
1041
1042         case SEEK_SET:
1043         case SEEK_CUR:
1044                 start = fl->l_start;
1045                 break;
1046
1047         case SEEK_END:
1048                 if (size > OFF_MAX ||
1049                     (fl->l_start > 0 && size > OFF_MAX - fl->l_start))
1050                         return EOVERFLOW;
1051                 start = size + fl->l_start;
1052                 break;
1053
1054         default:
1055                 return EINVAL;
1056         }
1057         if (start < 0)
1058                 return EINVAL;
1059         if (fl->l_len < 0) {
1060                 if (start == 0)
1061                         return EINVAL;
1062                 end = start - 1;
1063                 start += fl->l_len;
1064                 if (start < 0)
1065                         return EINVAL;
1066         } else if (fl->l_len == 0)
1067                 end = -1;
1068         else {
1069                 oadd = fl->l_len - 1;
1070                 if (oadd > OFF_MAX - start)
1071                         return EOVERFLOW;
1072                 end = start + oadd;
1073         }
1074         scred = smbfs_malloc_scred();
1075         smb_makescred(scred, td, td->td_ucred);
1076         switch (ap->a_op) {
1077             case F_SETLK:
1078                 switch (fl->l_type) {
1079                     case F_WRLCK:
1080                         lkop = SMB_LOCK_EXCL;
1081                         break;
1082                     case F_RDLCK:
1083                         lkop = SMB_LOCK_SHARED;
1084                         break;
1085                     case F_UNLCK:
1086                         lkop = SMB_LOCK_RELEASE;
1087                         break;
1088                     default:
1089                         smbfs_free_scred(scred);
1090                         return EINVAL;
1091                 }
1092                 error = lf_advlock(ap, &vp->v_lockf, size);
1093                 if (error)
1094                         break;
1095                 lkop = SMB_LOCK_EXCL;
1096                 error = smbfs_smb_lock(np, lkop, id, start, end, scred);
1097                 if (error) {
1098                         int oldtype = fl->l_type;
1099                         fl->l_type = F_UNLCK;
1100                         ap->a_op = F_UNLCK;
1101                         lf_advlock(ap, &vp->v_lockf, size);
1102                         fl->l_type = oldtype;
1103                 }
1104                 break;
1105             case F_UNLCK:
1106                 lf_advlock(ap, &vp->v_lockf, size);
1107                 error = smbfs_smb_lock(np, SMB_LOCK_RELEASE, id, start, end, scred);
1108                 break;
1109             case F_GETLK:
1110                 error = lf_advlock(ap, &vp->v_lockf, size);
1111                 break;
1112             default:
1113                 smbfs_free_scred(scred);
1114                 return EINVAL;
1115         }
1116         smbfs_free_scred(scred);
1117         return error;
1118 }
1119
1120 static int
1121 smbfs_pathcheck(struct smbmount *smp, const char *name, int nmlen, int nameiop)
1122 {
1123         static const char *badchars = "*/:<>?";
1124         static const char *badchars83 = " +|,[]=;";
1125         const char *cp;
1126         int i, error;
1127
1128         /*
1129          * Backslash characters, being a path delimiter, are prohibited
1130          * within a path component even for LOOKUP operations.
1131          */
1132         if (strchr(name, '\\') != NULL)
1133                 return ENOENT;
1134
1135         if (nameiop == LOOKUP)
1136                 return 0;
1137         error = ENOENT;
1138         if (SMB_DIALECT(SSTOVC(smp->sm_share)) < SMB_DIALECT_LANMAN2_0) {
1139                 /*
1140                  * Name should conform 8.3 format
1141                  */
1142                 if (nmlen > 12)
1143                         return ENAMETOOLONG;
1144                 cp = strchr(name, '.');
1145                 if (cp == NULL)
1146                         return error;
1147                 if (cp == name || (cp - name) > 8)
1148                         return error;
1149                 cp = strchr(cp + 1, '.');
1150                 if (cp != NULL)
1151                         return error;
1152                 for (cp = name, i = 0; i < nmlen; i++, cp++)
1153                         if (strchr(badchars83, *cp) != NULL)
1154                                 return error;
1155         }
1156         for (cp = name, i = 0; i < nmlen; i++, cp++)
1157                 if (strchr(badchars, *cp) != NULL)
1158                         return error;
1159         return 0;
1160 }
1161
1162 /*
1163  * Things go even weird without fixed inode numbers...
1164  */
1165 int
1166 smbfs_lookup(ap)
1167         struct vop_lookup_args /* {
1168                 struct vnodeop_desc *a_desc;
1169                 struct vnode *a_dvp;
1170                 struct vnode **a_vpp;
1171                 struct componentname *a_cnp;
1172         } */ *ap;
1173 {
1174         struct componentname *cnp = ap->a_cnp;
1175         struct thread *td = cnp->cn_thread;
1176         struct vnode *dvp = ap->a_dvp;
1177         struct vnode **vpp = ap->a_vpp;
1178         struct vnode *vp;
1179         struct smbmount *smp;
1180         struct mount *mp = dvp->v_mount;
1181         struct smbnode *dnp;
1182         struct smbfattr fattr, *fap;
1183         struct smb_cred *scred;
1184         char *name = cnp->cn_nameptr;
1185         int flags = cnp->cn_flags;
1186         int nameiop = cnp->cn_nameiop;
1187         int nmlen = cnp->cn_namelen;
1188         int error, islastcn, isdot;
1189         int killit;
1190         
1191         SMBVDEBUG("\n");
1192         if (dvp->v_type != VDIR)
1193                 return ENOTDIR;
1194         if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
1195                 SMBFSERR("invalid '..'\n");
1196                 return EIO;
1197         }
1198         islastcn = flags & ISLASTCN;
1199         if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
1200                 return EROFS;
1201         if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0)
1202                 return error;
1203         smp = VFSTOSMBFS(mp);
1204         dnp = VTOSMB(dvp);
1205         isdot = (nmlen == 1 && name[0] == '.');
1206
1207         error = smbfs_pathcheck(smp, cnp->cn_nameptr, cnp->cn_namelen, nameiop);
1208
1209         if (error) 
1210                 return ENOENT;
1211
1212         error = cache_lookup(dvp, vpp, cnp, NULL, NULL);
1213         SMBVDEBUG("cache_lookup returned %d\n", error);
1214         if (error > 0)
1215                 return error;
1216         if (error) {            /* name was found */
1217                 struct vattr vattr;
1218
1219                 killit = 0;
1220                 vp = *vpp;
1221                 error = VOP_GETATTR(vp, &vattr, cnp->cn_cred);
1222                 /*
1223                  * If the file type on the server is inconsistent
1224                  * with what it was when we created the vnode,
1225                  * kill the bogus vnode now and fall through to
1226                  * the code below to create a new one with the
1227                  * right type.
1228                  */
1229                 if (error == 0 &&
1230                    ((vp->v_type == VDIR &&
1231                    (VTOSMB(vp)->n_dosattr & SMB_FA_DIR) == 0) ||
1232                    (vp->v_type == VREG &&
1233                    (VTOSMB(vp)->n_dosattr & SMB_FA_DIR) != 0)))
1234                    killit = 1;
1235                 else if (error == 0
1236              /*    && vattr.va_ctime.tv_sec == VTOSMB(vp)->n_ctime*/) {
1237                      if (nameiop != LOOKUP && islastcn)
1238                              cnp->cn_flags |= SAVENAME;
1239                      SMBVDEBUG("use cached vnode\n");
1240                      return (0);
1241                 }
1242                 cache_purge(vp);
1243                 /*
1244                  * XXX This is not quite right, if '.' is
1245                  * inconsistent, we really need to start the lookup
1246                  * all over again.  Hopefully there is some other
1247                  * guarantee that prevents this case from happening.
1248                  */
1249                 if (killit && vp != dvp)
1250                         vgone(vp);
1251                 if (vp != dvp)
1252                         vput(vp);
1253                 else
1254                         vrele(vp);
1255                 *vpp = NULLVP;
1256         }
1257         /* 
1258          * entry is not in the cache or has been expired
1259          */
1260         error = 0;
1261         *vpp = NULLVP;
1262         scred = smbfs_malloc_scred();
1263         smb_makescred(scred, td, cnp->cn_cred);
1264         fap = &fattr;
1265         if (flags & ISDOTDOT) {
1266                 /*
1267                  * In the DOTDOT case, don't go over-the-wire
1268                  * in order to request attributes. We already
1269                  * know it's a directory and subsequent call to
1270                  * smbfs_getattr() will restore consistency.
1271                  *
1272                  */
1273                 SMBVDEBUG("smbfs_smb_lookup: dotdot\n");
1274         } else if (isdot) {
1275                 error = smbfs_smb_lookup(dnp, NULL, 0, fap, scred);
1276                 SMBVDEBUG("result of smbfs_smb_lookup: %d\n", error);
1277         }
1278         else {
1279                 error = smbfs_smb_lookup(dnp, name, nmlen, fap, scred);
1280                 SMBVDEBUG("result of smbfs_smb_lookup: %d\n", error);
1281         }
1282         if (error && error != ENOENT)
1283                 goto out;
1284         if (error) {                    /* entry not found */
1285                 /*
1286                  * Handle RENAME or CREATE case...
1287                  */
1288                 if ((nameiop == CREATE || nameiop == RENAME) && islastcn) {
1289                         error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
1290                         if (error)
1291                                 goto out;
1292                         cnp->cn_flags |= SAVENAME;
1293                         error = EJUSTRETURN;
1294                         goto out;
1295                 }
1296                 error = ENOENT;
1297                 goto out;
1298         }/* else {
1299                 SMBVDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
1300         }*/
1301         /*
1302          * handle DELETE case ...
1303          */
1304         if (nameiop == DELETE && islastcn) {    /* delete last component */
1305                 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
1306                 if (error)
1307                         goto out;
1308                 if (isdot) {
1309                         VREF(dvp);
1310                         *vpp = dvp;
1311                         goto out;
1312                 }
1313                 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1314                 if (error)
1315                         goto out;
1316                 *vpp = vp;
1317                 cnp->cn_flags |= SAVENAME;
1318                 goto out;
1319         }
1320         if (nameiop == RENAME && islastcn) {
1321                 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
1322                 if (error)
1323                         goto out;
1324                 if (isdot) {
1325                         error = EISDIR;
1326                         goto out;
1327                 }
1328                 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1329                 if (error)
1330                         goto out;
1331                 *vpp = vp;
1332                 cnp->cn_flags |= SAVENAME;
1333                 goto out;
1334         }
1335         if (flags & ISDOTDOT) {
1336                 mp = dvp->v_mount;
1337                 error = vfs_busy(mp, MBF_NOWAIT);
1338                 if (error != 0) {
1339                         vfs_ref(mp);
1340                         VOP_UNLOCK(dvp, 0);
1341                         error = vfs_busy(mp, 0);
1342                         vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1343                         vfs_rel(mp);
1344                         if (error) {
1345                                 error = ENOENT;
1346                                 goto out;
1347                         }
1348                         if ((dvp->v_iflag & VI_DOOMED) != 0) {
1349                                 vfs_unbusy(mp);
1350                                 error = ENOENT;
1351                                 goto out;
1352                         }
1353                 }       
1354                 VOP_UNLOCK(dvp, 0);
1355                 error = smbfs_nget(mp, dvp, name, nmlen, NULL, &vp);
1356                 vfs_unbusy(mp);
1357                 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1358                 if ((dvp->v_iflag & VI_DOOMED) != 0) {
1359                         if (error == 0)
1360                                 vput(vp);
1361                         error = ENOENT;
1362                 }
1363                 if (error)
1364                         goto out;
1365                 *vpp = vp;
1366         } else if (isdot) {
1367                 vref(dvp);
1368                 *vpp = dvp;
1369         } else {
1370                 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1371                 if (error)
1372                         goto out;
1373                 *vpp = vp;
1374                 SMBVDEBUG("lookup: getnewvp!\n");
1375         }
1376         if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
1377 /*              VTOSMB(*vpp)->n_ctime = VTOSMB(*vpp)->n_vattr.va_ctime.tv_sec;*/
1378                 cache_enter(dvp, *vpp, cnp);
1379         }
1380 out:
1381         smbfs_free_scred(scred);
1382         return (error);
1383 }