Simplify vn_lock(), VOP_LOCK(), and VOP_UNLOCK() by removing the thread_t
[dragonfly.git] / sys / vfs / smbfs / smbfs_vnops.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 2000-2001 Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
19 *
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
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/fs/smbfs/smbfs_vnops.c,v 1.2.2.8 2003/04/04 08:57:23 tjr Exp $
ca466bae 33 * $DragonFly: src/sys/vfs/smbfs/smbfs_vnops.c,v 1.29 2006/05/05 21:15:10 dillon Exp $
984263bc
MD
34 */
35#include <sys/param.h>
36#include <sys/systm.h>
984263bc
MD
37#include <sys/kernel.h>
38#include <sys/proc.h>
dadab5e9 39#include <sys/namei.h>
984263bc
MD
40#include <sys/fcntl.h>
41#include <sys/mount.h>
42#include <sys/unistd.h>
43#include <sys/vnode.h>
44#include <sys/lockf.h>
45
46#include <vm/vm.h>
47#include <vm/vm_extern.h>
48#include <vm/vm_zone.h>
49
50
d2438d69
MD
51#include <netproto/smb/smb.h>
52#include <netproto/smb/smb_conn.h>
53#include <netproto/smb/smb_subr.h>
984263bc 54
1f2de5d4
MD
55#include "smbfs.h"
56#include "smbfs_node.h"
57#include "smbfs_subr.h"
984263bc
MD
58
59#include <sys/buf.h>
60
61/*
62 * Prototypes for SMBFS vnode operations
63 */
e62afb5f
MD
64static int smbfs_create(struct vop_old_create_args *);
65static int smbfs_mknod(struct vop_old_mknod_args *);
984263bc 66static int smbfs_open(struct vop_open_args *);
5fd012e0 67static int smbfs_closel(struct vop_close_args *);
984263bc
MD
68static int smbfs_access(struct vop_access_args *);
69static int smbfs_getattr(struct vop_getattr_args *);
70static int smbfs_setattr(struct vop_setattr_args *);
71static int smbfs_read(struct vop_read_args *);
72static int smbfs_write(struct vop_write_args *);
73static int smbfs_fsync(struct vop_fsync_args *);
e62afb5f
MD
74static int smbfs_remove(struct vop_old_remove_args *);
75static int smbfs_link(struct vop_old_link_args *);
76static int smbfs_lookup(struct vop_old_lookup_args *);
77static int smbfs_rename(struct vop_old_rename_args *);
78static int smbfs_mkdir(struct vop_old_mkdir_args *);
79static int smbfs_rmdir(struct vop_old_rmdir_args *);
80static int smbfs_symlink(struct vop_old_symlink_args *);
984263bc
MD
81static int smbfs_readdir(struct vop_readdir_args *);
82static int smbfs_bmap(struct vop_bmap_args *);
83static int smbfs_strategy(struct vop_strategy_args *);
84static int smbfs_print(struct vop_print_args *);
85static int smbfs_pathconf(struct vop_pathconf_args *ap);
86static int smbfs_advlock(struct vop_advlock_args *);
87static int smbfs_getextattr(struct vop_getextattr_args *ap);
88
0961aa92 89struct vnodeopv_entry_desc smbfs_vnodeop_entries[] = {
2d3e977e 90 { &vop_default_desc, vop_defaultop },
625ddaba
JS
91 { &vop_access_desc, (vnodeopv_entry_t) smbfs_access },
92 { &vop_advlock_desc, (vnodeopv_entry_t) smbfs_advlock },
93 { &vop_bmap_desc, (vnodeopv_entry_t) smbfs_bmap },
94 { &vop_close_desc, (vnodeopv_entry_t) smbfs_closel },
e62afb5f 95 { &vop_old_create_desc, (vnodeopv_entry_t) smbfs_create },
625ddaba
JS
96 { &vop_fsync_desc, (vnodeopv_entry_t) smbfs_fsync },
97 { &vop_getattr_desc, (vnodeopv_entry_t) smbfs_getattr },
98 { &vop_getpages_desc, (vnodeopv_entry_t) smbfs_getpages },
99 { &vop_inactive_desc, (vnodeopv_entry_t) smbfs_inactive },
100 { &vop_ioctl_desc, (vnodeopv_entry_t) smbfs_ioctl },
101 { &vop_islocked_desc, (vnodeopv_entry_t) vop_stdislocked },
e62afb5f 102 { &vop_old_link_desc, (vnodeopv_entry_t) smbfs_link },
625ddaba 103 { &vop_lock_desc, (vnodeopv_entry_t) vop_stdlock },
e62afb5f
MD
104 { &vop_old_lookup_desc, (vnodeopv_entry_t) smbfs_lookup },
105 { &vop_old_mkdir_desc, (vnodeopv_entry_t) smbfs_mkdir },
106 { &vop_old_mknod_desc, (vnodeopv_entry_t) smbfs_mknod },
625ddaba
JS
107 { &vop_open_desc, (vnodeopv_entry_t) smbfs_open },
108 { &vop_pathconf_desc, (vnodeopv_entry_t) smbfs_pathconf },
109 { &vop_print_desc, (vnodeopv_entry_t) smbfs_print },
110 { &vop_putpages_desc, (vnodeopv_entry_t) smbfs_putpages },
111 { &vop_read_desc, (vnodeopv_entry_t) smbfs_read },
112 { &vop_readdir_desc, (vnodeopv_entry_t) smbfs_readdir },
113 { &vop_reclaim_desc, (vnodeopv_entry_t) smbfs_reclaim },
e62afb5f
MD
114 { &vop_old_remove_desc, (vnodeopv_entry_t) smbfs_remove },
115 { &vop_old_rename_desc, (vnodeopv_entry_t) smbfs_rename },
116 { &vop_old_rmdir_desc, (vnodeopv_entry_t) smbfs_rmdir },
625ddaba
JS
117 { &vop_setattr_desc, (vnodeopv_entry_t) smbfs_setattr },
118 { &vop_strategy_desc, (vnodeopv_entry_t) smbfs_strategy },
e62afb5f 119 { &vop_old_symlink_desc, (vnodeopv_entry_t) smbfs_symlink },
625ddaba
JS
120 { &vop_unlock_desc, (vnodeopv_entry_t) vop_stdunlock },
121 { &vop_write_desc, (vnodeopv_entry_t) smbfs_write },
122 { &vop_getextattr_desc, (vnodeopv_entry_t) smbfs_getextattr },
123/* { &vop_setextattr_desc, (vnodeopv_entry_t) smbfs_setextattr },*/
984263bc
MD
124 { NULL, NULL }
125};
126
9c2a2cee
CP
127/*
128 * smbfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
129 * struct thread *a_td)
130 */
984263bc 131static int
9c2a2cee 132smbfs_access(struct vop_access_args *ap)
984263bc
MD
133{
134 struct vnode *vp = ap->a_vp;
135 struct ucred *cred = ap->a_cred;
136 u_int mode = ap->a_mode;
137 struct smbmount *smp = VTOSMBFS(vp);
138 int error = 0;
139
140 SMBVDEBUG("\n");
141 if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
142 switch (vp->v_type) {
143 case VREG: case VDIR: case VLNK:
144 return EROFS;
145 default:
146 break;
147 }
148 }
149 if (cred->cr_uid == 0)
150 return 0;
151 if (cred->cr_uid != smp->sm_args.uid) {
152 mode >>= 3;
153 if (!groupmember(smp->sm_args.gid, cred))
154 mode >>= 3;
155 }
156 error = (((vp->v_type == VREG) ? smp->sm_args.file_mode : smp->sm_args.dir_mode) & mode) == mode ? 0 : EACCES;
157 return error;
158}
159
9c2a2cee
CP
160/*
161 * smbfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
162 * struct thread *a_td)
163 */
984263bc
MD
164/* ARGSUSED */
165static int
9c2a2cee 166smbfs_open(struct vop_open_args *ap)
984263bc
MD
167{
168 struct vnode *vp = ap->a_vp;
169 struct smbnode *np = VTOSMB(vp);
170 struct smb_cred scred;
171 struct vattr vattr;
172 int mode = ap->a_mode;
173 int error, accmode;
174
175 SMBVDEBUG("%s,%d\n", np->n_name, np->n_opencount);
176 if (vp->v_type != VREG && vp->v_type != VDIR) {
177 SMBFSERR("open eacces vtype=%d\n", vp->v_type);
178 return EACCES;
179 }
180 if (vp->v_type == VDIR) {
61670a01
MD
181 if (np->n_opencount == 0)
182 np->n_cached_cred = crhold(ap->a_cred);
984263bc 183 np->n_opencount++;
8ddc6004 184 return (vop_stdopen(ap));
984263bc
MD
185 }
186 if (np->n_flag & NMODIFIED) {
3b568787 187 if ((error = smbfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1)) == EINTR)
984263bc
MD
188 return error;
189 smbfs_attr_cacheremove(vp);
3b568787 190 error = VOP_GETATTR(vp, &vattr, ap->a_td);
984263bc
MD
191 if (error)
192 return error;
193 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
194 } else {
3b568787 195 error = VOP_GETATTR(vp, &vattr, ap->a_td);
984263bc
MD
196 if (error)
197 return error;
198 if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
3b568787 199 error = smbfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
984263bc
MD
200 if (error == EINTR)
201 return error;
202 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
203 }
204 }
205 if (np->n_opencount) {
206 np->n_opencount++;
8ddc6004 207 return (vop_stdopen(ap));
984263bc
MD
208 }
209 accmode = SMB_AM_OPENREAD;
210 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
211 accmode = SMB_AM_OPENRW;
dadab5e9 212 smb_makescred(&scred, ap->a_td, ap->a_cred);
984263bc
MD
213 error = smbfs_smb_open(np, accmode, &scred);
214 if (error) {
215 if (mode & FWRITE)
216 return EACCES;
217 accmode = SMB_AM_OPENREAD;
218 error = smbfs_smb_open(np, accmode, &scred);
219 }
220 if (!error) {
61670a01 221 np->n_cached_cred = crhold(ap->a_cred);
984263bc
MD
222 np->n_opencount++;
223 }
224 smbfs_attr_cacheremove(vp);
8ddc6004
MD
225 if (error == 0)
226 vop_stdopen(ap);
984263bc
MD
227 return error;
228}
229
230static int
231smbfs_closel(struct vop_close_args *ap)
232{
233 struct vnode *vp = ap->a_vp;
234 struct smbnode *np = VTOSMB(vp);
dadab5e9 235 struct thread *td = ap->a_td;
984263bc
MD
236 struct smb_cred scred;
237 struct vattr vattr;
238 int error;
239
240 SMBVDEBUG("name=%s, pid=%d, c=%d\n",np->n_name, p->p_pid, np->n_opencount);
241
3b568787 242 smb_makescred(&scred, td, proc0.p_ucred);
8ddc6004 243 error = 0;
984263bc
MD
244
245 if (np->n_opencount == 0) {
246 if (vp->v_type != VDIR)
247 SMBERROR("Negative opencount\n");
8ddc6004 248 goto done;
984263bc
MD
249 }
250 np->n_opencount--;
251 if (vp->v_type == VDIR) {
252 if (np->n_opencount)
8ddc6004 253 goto done;
984263bc
MD
254 if (np->n_dirseq) {
255 smbfs_findclose(np->n_dirseq, &scred);
256 np->n_dirseq = NULL;
257 }
984263bc 258 } else {
3b568787 259 error = smbfs_vinvalbuf(vp, V_SAVE, td, 1);
984263bc 260 if (np->n_opencount)
8ddc6004 261 goto done;
3b568787 262 VOP_GETATTR(vp, &vattr, td);
984263bc
MD
263 error = smbfs_smb_close(np->n_mount->sm_share, np->n_fid,
264 &np->n_mtime, &scred);
265 }
61670a01
MD
266 crfree(np->n_cached_cred);
267 np->n_cached_cred = NULL;
984263bc 268 smbfs_attr_cacheremove(vp);
8ddc6004
MD
269done:
270 vop_stdclose(ap);
984263bc
MD
271 return error;
272}
273
984263bc
MD
274/*
275 * smbfs_getattr call from vfs.
9c2a2cee
CP
276 *
277 * smbfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct thread *a_td)
984263bc
MD
278 */
279static int
9c2a2cee 280smbfs_getattr(struct vop_getattr_args *ap)
984263bc
MD
281{
282 struct vnode *vp = ap->a_vp;
283 struct smbnode *np = VTOSMB(vp);
284 struct vattr *va=ap->a_vap;
285 struct smbfattr fattr;
286 struct smb_cred scred;
274a0ba3 287 u_quad_t oldsize;
984263bc
MD
288 int error;
289
290 SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_flag & VROOT) != 0);
291 error = smbfs_attr_cachelookup(vp, va);
292 if (!error)
293 return 0;
294 SMBVDEBUG("not in the cache\n");
3b568787 295 smb_makescred(&scred, ap->a_td, proc0.p_ucred);
984263bc
MD
296 oldsize = np->n_size;
297 error = smbfs_smb_lookup(np, NULL, 0, &fattr, &scred);
298 if (error) {
299 SMBVDEBUG("error %d\n", error);
300 return error;
301 }
302 smbfs_attr_cacheenter(vp, &fattr);
303 smbfs_attr_cachelookup(vp, va);
304 if (np->n_opencount)
305 np->n_size = oldsize;
306 return 0;
307}
308
9c2a2cee
CP
309/*
310 * smbfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
311 * struct thread *a_td)
312 */
984263bc 313static int
9c2a2cee 314smbfs_setattr(struct vop_setattr_args *ap)
984263bc
MD
315{
316 struct vnode *vp = ap->a_vp;
317 struct smbnode *np = VTOSMB(vp);
318 struct vattr *vap = ap->a_vap;
319 struct timespec *mtime, *atime;
320 struct smb_cred scred;
321 struct smb_share *ssp = np->n_mount->sm_share;
322 struct smb_vc *vcp = SSTOVC(ssp);
323 u_quad_t tsize = 0;
324 int isreadonly, doclose, error = 0;
325
326 SMBVDEBUG("\n");
327 if (vap->va_flags != VNOVAL)
328 return EOPNOTSUPP;
329 isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
330 /*
331 * Disallow write attempts if the filesystem is mounted read-only.
332 */
333 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
334 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
335 vap->va_mode != (mode_t)VNOVAL) && isreadonly)
336 return EROFS;
dadab5e9 337 smb_makescred(&scred, ap->a_td, ap->a_cred);
984263bc
MD
338 if (vap->va_size != VNOVAL) {
339 switch (vp->v_type) {
340 case VDIR:
341 return EISDIR;
342 case VREG:
343 break;
344 default:
345 return EINVAL;
346 };
347 if (isreadonly)
348 return EROFS;
349 doclose = 0;
350 vnode_pager_setsize(vp, (u_long)vap->va_size);
351 tsize = np->n_size;
352 np->n_size = vap->va_size;
353 if (np->n_opencount == 0) {
354 error = smbfs_smb_open(np, SMB_AM_OPENRW, &scred);
355 if (error == 0)
356 doclose = 1;
357 }
358 if (error == 0)
359 error = smbfs_smb_setfsize(np, vap->va_size, &scred);
360 if (doclose)
361 smbfs_smb_close(ssp, np->n_fid, NULL, &scred);
362 if (error) {
363 np->n_size = tsize;
364 vnode_pager_setsize(vp, (u_long)tsize);
365 return error;
366 }
367 }
368 mtime = atime = NULL;
369 if (vap->va_mtime.tv_sec != VNOVAL)
370 mtime = &vap->va_mtime;
371 if (vap->va_atime.tv_sec != VNOVAL)
372 atime = &vap->va_atime;
373 if (mtime != atime) {
374 if (ap->a_cred->cr_uid != VTOSMBFS(vp)->sm_args.uid &&
dadab5e9 375 (error = suser_cred(ap->a_cred, PRISON_ROOT)) &&
984263bc 376 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
dadab5e9 377 (error = VOP_ACCESS(vp, VWRITE, ap->a_cred, ap->a_td))))
984263bc
MD
378 return (error);
379#if 0
380 if (mtime == NULL)
381 mtime = &np->n_mtime;
382 if (atime == NULL)
383 atime = &np->n_atime;
384#endif
385 /*
386 * If file is opened, then we can use handle based calls.
387 * If not, use path based ones.
388 */
389 if (np->n_opencount == 0) {
390 if (vcp->vc_flags & SMBV_WIN95) {
fad57d0e 391 error = VOP_OPEN(vp, FWRITE, ap->a_cred, NULL, ap->a_td);
984263bc
MD
392 if (!error) {
393/* error = smbfs_smb_setfattrNT(np, 0, mtime, atime, &scred);
3b568787 394 VOP_GETATTR(vp, &vattr, ap->a_td);*/
984263bc
MD
395 if (mtime)
396 np->n_mtime = *mtime;
3b568787 397 VOP_CLOSE(vp, FWRITE, ap->a_td);
984263bc
MD
398 }
399 } else if ((vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS)) {
400 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
401/* error = smbfs_smb_setpattrNT(np, 0, mtime, atime, &scred);*/
402 } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
403 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
404 } else {
405 error = smbfs_smb_setpattr(np, 0, mtime, &scred);
406 }
407 } else {
408 if (vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS) {
409 error = smbfs_smb_setfattrNT(np, 0, mtime, atime, &scred);
410 } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN1_0) {
411 error = smbfs_smb_setftime(np, mtime, atime, &scred);
412 } else {
413 /*
414 * I have no idea how to handle this for core
415 * level servers. The possible solution is to
416 * update mtime after file is closed.
417 */
418 SMBERROR("can't update times on an opened file\n");
419 }
420 }
421 }
422 /*
423 * Invalidate attribute cache in case if server doesn't set
424 * required attributes.
425 */
426 smbfs_attr_cacheremove(vp); /* invalidate cache */
3b568787 427 VOP_GETATTR(vp, vap, ap->a_td);
984263bc
MD
428 np->n_mtime.tv_sec = vap->va_mtime.tv_sec;
429 return error;
430}
431/*
432 * smbfs_read call.
9c2a2cee
CP
433 *
434 * smbfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
435 * struct ucred *a_cred)
984263bc
MD
436 */
437static int
9c2a2cee 438smbfs_read(struct vop_read_args *ap)
984263bc
MD
439{
440 struct vnode *vp = ap->a_vp;
441 struct uio *uio = ap->a_uio;
442
443 SMBVDEBUG("\n");
444 if (vp->v_type != VREG && vp->v_type != VDIR)
445 return EPERM;
446 return smbfs_readvnode(vp, uio, ap->a_cred);
447}
448
9c2a2cee
CP
449/*
450 * smbfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
451 * struct ucred *a_cred)
452 */
984263bc 453static int
9c2a2cee 454smbfs_write(struct vop_write_args *ap)
984263bc
MD
455{
456 struct vnode *vp = ap->a_vp;
457 struct uio *uio = ap->a_uio;
458
459 SMBVDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
460 if (vp->v_type != VREG)
461 return (EPERM);
462 return smbfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
463}
464/*
465 * smbfs_create call
466 * Create a regular file. On entry the directory to contain the file being
fad57d0e 467 * created is locked. We must release before we return.
9c2a2cee
CP
468 *
469 * smbfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
470 * struct componentname *a_cnp, struct vattr *a_vap)
984263bc
MD
471 */
472static int
e62afb5f 473smbfs_create(struct vop_old_create_args *ap)
984263bc
MD
474{
475 struct vnode *dvp = ap->a_dvp;
476 struct vattr *vap = ap->a_vap;
477 struct vnode **vpp=ap->a_vpp;
478 struct componentname *cnp = ap->a_cnp;
479 struct smbnode *dnp = VTOSMB(dvp);
480 struct vnode *vp;
481 struct vattr vattr;
482 struct smbfattr fattr;
483 struct smb_cred scred;
484 char *name = cnp->cn_nameptr;
485 int nmlen = cnp->cn_namelen;
486 int error;
487
488
489 SMBVDEBUG("\n");
490 *vpp = NULL;
491 if (vap->va_type != VREG)
492 return EOPNOTSUPP;
3b568787 493 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td)))
984263bc 494 return error;
dadab5e9 495 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
984263bc
MD
496
497 error = smbfs_smb_create(dnp, name, nmlen, &scred);
498 if (error)
499 return error;
500 error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, &scred);
501 if (error)
502 return error;
503 error = smbfs_nget(VTOVFS(dvp), dvp, name, nmlen, &fattr, &vp);
504 if (error)
505 return error;
506 *vpp = vp;
984263bc
MD
507 return error;
508}
509
9c2a2cee
CP
510/*
511 * smbfs_remove(struct vnodeop_desc *a_desc, struct vnode *a_dvp,
512 * struct vnode *a_vp, struct componentname *a_cnp)
513 */
984263bc 514static int
e62afb5f 515smbfs_remove(struct vop_old_remove_args *ap)
984263bc
MD
516{
517 struct vnode *vp = ap->a_vp;
518/* struct vnode *dvp = ap->a_dvp;*/
519 struct componentname *cnp = ap->a_cnp;
520 struct smbnode *np = VTOSMB(vp);
521 struct smb_cred scred;
522 int error;
523
524 if (vp->v_type == VDIR || np->n_opencount || vp->v_usecount != 1)
525 return EPERM;
dadab5e9 526 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
984263bc 527 error = smbfs_smb_delete(np, &scred);
984263bc
MD
528 return error;
529}
530
531/*
532 * smbfs_file rename call
9c2a2cee
CP
533 *
534 * smbfs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
535 * struct componentname *a_fcnp, struct vnode *a_tdvp,
536 * struct vnode *a_tvp, struct componentname *a_tcnp)
984263bc
MD
537 */
538static int
e62afb5f 539smbfs_rename(struct vop_old_rename_args *ap)
984263bc
MD
540{
541 struct vnode *fvp = ap->a_fvp;
542 struct vnode *tvp = ap->a_tvp;
543 struct vnode *fdvp = ap->a_fdvp;
544 struct vnode *tdvp = ap->a_tdvp;
545 struct componentname *tcnp = ap->a_tcnp;
546/* struct componentname *fcnp = ap->a_fcnp;*/
547 struct smb_cred scred;
548 u_int16_t flags = 6;
549 int error=0;
550
551 /* Check for cross-device rename */
552 if ((fvp->v_mount != tdvp->v_mount) ||
553 (tvp && (fvp->v_mount != tvp->v_mount))) {
554 error = EXDEV;
555 goto out;
556 }
557
558 if (tvp && tvp->v_usecount > 1) {
559 error = EBUSY;
560 goto out;
561 }
562 flags = 0x10; /* verify all writes */
563 if (fvp->v_type == VDIR) {
564 flags |= 2;
565 } else if (fvp->v_type == VREG) {
566 flags |= 1;
567 } else {
568 error = EINVAL;
569 goto out;
570 }
dadab5e9 571 smb_makescred(&scred, tcnp->cn_td, tcnp->cn_cred);
984263bc
MD
572 /*
573 * It seems that Samba doesn't implement SMB_COM_MOVE call...
574 */
575#ifdef notnow
576 if (SMB_DIALECT(SSTOCN(smp->sm_share)) >= SMB_DIALECT_LANMAN1_0) {
577 error = smbfs_smb_move(VTOSMB(fvp), VTOSMB(tdvp),
578 tcnp->cn_nameptr, tcnp->cn_namelen, flags, &scred);
579 } else
580#endif
581 {
582 /*
583 * We have to do the work atomicaly
584 */
585 if (tvp && tvp != fvp) {
586 error = smbfs_smb_delete(VTOSMB(tvp), &scred);
587 if (error)
588 goto out_cacherem;
589 }
590 error = smbfs_smb_rename(VTOSMB(fvp), VTOSMB(tdvp),
591 tcnp->cn_nameptr, tcnp->cn_namelen, &scred);
592 }
593
984263bc
MD
594out_cacherem:
595 smbfs_attr_cacheremove(fdvp);
596 smbfs_attr_cacheremove(tdvp);
597out:
598 if (tdvp == tvp)
599 vrele(tdvp);
600 else
601 vput(tdvp);
602 if (tvp)
603 vput(tvp);
604 vrele(fdvp);
605 vrele(fvp);
606#ifdef possible_mistake
5fd012e0 607#error x
984263bc
MD
608 vgone(fvp);
609 if (tvp)
610 vgone(tvp);
611#endif
612 return error;
613}
614
615/*
616 * somtime it will come true...
9c2a2cee
CP
617 *
618 * smbfs_link(struct vnode *a_tdvp, struct vnode *a_vp,
619 * struct componentname *a_cnp)
984263bc
MD
620 */
621static int
e62afb5f 622smbfs_link(struct vop_old_link_args *ap)
984263bc
MD
623{
624 return EOPNOTSUPP;
625}
626
627/*
628 * smbfs_symlink link create call.
629 * Sometime it will be functional...
9c2a2cee
CP
630 *
631 * smbfs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
632 * struct componentname *a_cnp, struct vattr *a_vap,
633 * char *a_target)
984263bc
MD
634 */
635static int
e62afb5f 636smbfs_symlink(struct vop_old_symlink_args *ap)
984263bc
MD
637{
638 return EOPNOTSUPP;
639}
640
641static int
e62afb5f 642smbfs_mknod(struct vop_old_mknod_args *ap)
984263bc
MD
643{
644 return EOPNOTSUPP;
645}
646
9c2a2cee
CP
647/*
648 * smbfs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
649 * struct componentname *a_cnp, struct vattr *a_vap)
650 */
984263bc 651static int
e62afb5f 652smbfs_mkdir(struct vop_old_mkdir_args *ap)
984263bc
MD
653{
654 struct vnode *dvp = ap->a_dvp;
655/* struct vattr *vap = ap->a_vap;*/
656 struct vnode *vp;
657 struct componentname *cnp = ap->a_cnp;
658 struct smbnode *dnp = VTOSMB(dvp);
659 struct vattr vattr;
660 struct smb_cred scred;
661 struct smbfattr fattr;
662 char *name = cnp->cn_nameptr;
663 int len = cnp->cn_namelen;
664 int error;
665
3b568787 666 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td))) {
984263bc
MD
667 return error;
668 }
669 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.'))))
670 return EEXIST;
dadab5e9 671 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
984263bc
MD
672 error = smbfs_smb_mkdir(dnp, name, len, &scred);
673 if (error)
674 return error;
675 error = smbfs_smb_lookup(dnp, name, len, &fattr, &scred);
676 if (error)
677 return error;
678 error = smbfs_nget(VTOVFS(dvp), dvp, name, len, &fattr, &vp);
679 if (error)
680 return error;
681 *ap->a_vpp = vp;
682 return 0;
683}
684
685/*
686 * smbfs_remove directory call
9c2a2cee
CP
687 *
688 * smbfs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
689 * struct componentname *a_cnp)
984263bc
MD
690 */
691static int
e62afb5f 692smbfs_rmdir(struct vop_old_rmdir_args *ap)
984263bc
MD
693{
694 struct vnode *vp = ap->a_vp;
695 struct vnode *dvp = ap->a_dvp;
696 struct componentname *cnp = ap->a_cnp;
697/* struct smbmount *smp = VTOSMBFS(vp);*/
698 struct smbnode *dnp = VTOSMB(dvp);
699 struct smbnode *np = VTOSMB(vp);
700 struct smb_cred scred;
701 int error;
702
703 if (dvp == vp)
704 return EINVAL;
705
dadab5e9 706 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
984263bc
MD
707 error = smbfs_smb_rmdir(np, &scred);
708 dnp->n_flag |= NMODIFIED;
709 smbfs_attr_cacheremove(dvp);
984263bc
MD
710 return error;
711}
712
713/*
714 * smbfs_readdir call
9c2a2cee
CP
715 *
716 * smbfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
717 * int *a_eofflag, u_long *a_cookies, int a_ncookies)
984263bc
MD
718 */
719static int
9c2a2cee 720smbfs_readdir(struct vop_readdir_args *ap)
984263bc
MD
721{
722 struct vnode *vp = ap->a_vp;
723 struct uio *uio = ap->a_uio;
724 int error;
725
726 if (vp->v_type != VDIR)
727 return (EPERM);
728#ifdef notnow
729 if (ap->a_ncookies) {
730 printf("smbfs_readdir: no support for cookies now...");
731 return (EOPNOTSUPP);
732 }
733#endif
734 error = smbfs_readvnode(vp, uio, ap->a_cred);
735 return error;
736}
737
9c2a2cee
CP
738/*
739 * smbfs_fsync(struct vnodeop_desc *a_desc, struct vnode *a_vp,
740 * struct ucred *a_cred, int a_waitfor, struct thread *a_td)
741 */
984263bc
MD
742/* ARGSUSED */
743static int
9c2a2cee 744smbfs_fsync(struct vop_fsync_args *ap)
984263bc 745{
dadab5e9 746/* return (smb_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
984263bc
MD
747 return (0);
748}
749
9c2a2cee
CP
750/*
751 * smbfs_print(struct vnode *a_vp)
752 */
753static int
754smbfs_print(struct vop_print_args *ap)
984263bc
MD
755{
756 struct vnode *vp = ap->a_vp;
757 struct smbnode *np = VTOSMB(vp);
758
759 if (np == NULL) {
760 printf("no smbnode data\n");
761 return (0);
762 }
763 printf("tag VT_SMBFS, name = %s, parent = %p, opencount = %d",
764 np->n_name, np->n_parent ? np->n_parent : NULL,
765 np->n_opencount);
3446c007 766 lockmgr_printinfo(&vp->v_lock);
984263bc
MD
767 printf("\n");
768 return (0);
769}
770
9c2a2cee
CP
771/*
772 * smbfs_pathconf(struct vnode *vp, int name, register_t *retval)
773 */
984263bc 774static int
9c2a2cee 775smbfs_pathconf(struct vop_pathconf_args *ap)
984263bc
MD
776{
777 struct smbmount *smp = VFSTOSMBFS(VTOVFS(ap->a_vp));
778 struct smb_vc *vcp = SSTOVC(smp->sm_share);
779 register_t *retval = ap->a_retval;
780 int error = 0;
781
782 switch (ap->a_name) {
783 case _PC_LINK_MAX:
784 *retval = 0;
785 break;
786 case _PC_NAME_MAX:
787 *retval = (vcp->vc_hflags2 & SMB_FLAGS2_KNOWS_LONG_NAMES) ? 255 : 12;
788 break;
789 case _PC_PATH_MAX:
790 *retval = 800; /* XXX: a correct one ? */
791 break;
792 default:
793 error = EINVAL;
794 }
795 return error;
796}
797
9c2a2cee 798/*
81b5c339 799 * smbfs_strategy(struct vnode *a_vp, struct bio *a_bio)
9c2a2cee 800 */
984263bc 801static int
9c2a2cee 802smbfs_strategy(struct vop_strategy_args *ap)
984263bc 803{
81b5c339
MD
804 struct bio *bio = ap->a_bio;
805 struct buf *bp = bio->bio_buf;
dadab5e9 806 struct thread *td = NULL;
984263bc
MD
807 int error = 0;
808
809 SMBVDEBUG("\n");
dadab5e9
MD
810 if ((bp->b_flags & B_ASYNC) == 0)
811 td = curthread; /* XXX */
984263bc
MD
812
813 if ((bp->b_flags & B_ASYNC) == 0 )
81b5c339 814 error = smbfs_doio(ap->a_vp, bio, proc0.p_ucred, td);
984263bc
MD
815 return error;
816}
817
9c2a2cee 818/*
54078292
MD
819 * smbfs_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
820 * off_t *a_doffsetp, int *a_runp, int *a_runb)
9c2a2cee 821 */
984263bc 822static int
9c2a2cee 823smbfs_bmap(struct vop_bmap_args *ap)
984263bc
MD
824{
825 struct vnode *vp = ap->a_vp;
826
827 if (ap->a_vpp != NULL)
828 *ap->a_vpp = vp;
54078292
MD
829 if (ap->a_doffsetp != NULL)
830 *ap->a_doffsetp = ap->a_loffset;
984263bc
MD
831 if (ap->a_runp != NULL)
832 *ap->a_runp = 0;
833 if (ap->a_runb != NULL)
834 *ap->a_runb = 0;
835 return (0);
836}
837
9c2a2cee
CP
838/*
839 * smbfs_ioctl(struct vnode *a_vp, u_long a_command, caddr_t a_data,
840 * int fflag, struct ucred *cred, struct proc *p)
841 */
984263bc 842int
9c2a2cee 843smbfs_ioctl(struct vop_ioctl_args *ap)
984263bc
MD
844{
845 return EINVAL;
846}
847
848static char smbfs_atl[] = "rhsvda";
849static int
850smbfs_getextattr(struct vop_getextattr_args *ap)
851/* {
852 IN struct vnode *a_vp;
853 IN char *a_name;
854 INOUT struct uio *a_uio;
855 IN struct ucred *a_cred;
dadab5e9 856 IN struct thread *a_td;
984263bc
MD
857};
858*/
859{
860 struct vnode *vp = ap->a_vp;
dadab5e9 861 struct thread *td = ap->a_td;
984263bc
MD
862 struct ucred *cred = ap->a_cred;
863 struct uio *uio = ap->a_uio;
864 const char *name = ap->a_name;
865 struct smbnode *np = VTOSMB(vp);
866 struct vattr vattr;
867 char buf[10];
868 int i, attr, error;
869
dadab5e9 870 error = VOP_ACCESS(vp, VREAD, cred, td);
984263bc
MD
871 if (error)
872 return error;
3b568787 873 error = VOP_GETATTR(vp, &vattr, td);
984263bc
MD
874 if (error)
875 return error;
876 if (strcmp(name, "dosattr") == 0) {
877 attr = np->n_dosattr;
878 for (i = 0; i < 6; i++, attr >>= 1)
879 buf[i] = (attr & 1) ? smbfs_atl[i] : '-';
880 buf[i] = 0;
881 error = uiomove(buf, i, uio);
882
883 } else
884 error = EINVAL;
885 return error;
886}
887
888/*
889 * Since we expected to support F_GETLK (and SMB protocol has no such function),
890 * it is necessary to use lf_advlock(). It would be nice if this function had
891 * a callback mechanism because it will help to improve a level of consistency.
9c2a2cee
CP
892 *
893 * smbfs_advlock(struct vnode *a_vp, caddr_t a_id, int a_op,
894 * struct flock *a_fl, int a_flags)
984263bc
MD
895 */
896int
9c2a2cee 897smbfs_advlock(struct vop_advlock_args *ap)
984263bc
MD
898{
899 struct vnode *vp = ap->a_vp;
900 struct smbnode *np = VTOSMB(vp);
901 struct flock *fl = ap->a_fl;
902 caddr_t id = (caddr_t)1 /* ap->a_id */;
903/* int flags = ap->a_flags;*/
dadab5e9 904 struct thread *td = curthread; /* XXX */
984263bc
MD
905 struct smb_cred scred;
906 off_t start, end, size;
907 int error, lkop;
908
909 if (vp->v_type == VDIR) {
910 /*
911 * SMB protocol have no support for directory locking.
912 * Although locks can be processed on local machine, I don't
913 * think that this is a good idea, because some programs
914 * can work wrong assuming directory is locked. So, we just
915 * return 'operation not supported
916 */
917 return EOPNOTSUPP;
918 }
919 size = np->n_size;
920 switch (fl->l_whence) {
921 case SEEK_SET:
922 case SEEK_CUR:
923 start = fl->l_start;
924 break;
925 case SEEK_END:
926 start = fl->l_start + size;
927 default:
928 return EINVAL;
929 }
930 if (start < 0)
931 return EINVAL;
932 if (fl->l_len == 0)
933 end = -1;
934 else {
935 end = start + fl->l_len - 1;
936 if (end < start)
937 return EINVAL;
938 }
dadab5e9 939 smb_makescred(&scred, td, td->td_proc ? td->td_proc->p_ucred : NULL);
984263bc
MD
940 switch (ap->a_op) {
941 case F_SETLK:
942 switch (fl->l_type) {
943 case F_WRLCK:
944 lkop = SMB_LOCK_EXCL;
945 break;
946 case F_RDLCK:
947 lkop = SMB_LOCK_SHARED;
948 break;
949 case F_UNLCK:
950 lkop = SMB_LOCK_RELEASE;
951 break;
952 default:
953 return EINVAL;
954 }
955 error = lf_advlock(ap, &np->n_lockf, size);
956 if (error)
957 break;
958 lkop = SMB_LOCK_EXCL;
959 error = smbfs_smb_lock(np, lkop, id, start, end, &scred);
960 if (error) {
961 ap->a_op = F_UNLCK;
962 lf_advlock(ap, &np->n_lockf, size);
963 }
964 break;
965 case F_UNLCK:
966 lf_advlock(ap, &np->n_lockf, size);
967 error = smbfs_smb_lock(np, SMB_LOCK_RELEASE, id, start, end, &scred);
968 break;
969 case F_GETLK:
970 error = lf_advlock(ap, &np->n_lockf, size);
971 break;
972 default:
973 return EINVAL;
974 }
975 return error;
976}
977
978static int
979smbfs_pathcheck(struct smbmount *smp, const char *name, int nmlen, int nameiop)
980{
981 static const char *badchars = "*/\[]:<>=;?";
982 static const char *badchars83 = " +|,";
983 const char *cp;
984 int i, error;
985
2b69e610 986 if (nameiop == NAMEI_LOOKUP)
984263bc
MD
987 return 0;
988 error = ENOENT;
989 if (SMB_DIALECT(SSTOVC(smp->sm_share)) < SMB_DIALECT_LANMAN2_0) {
990 /*
991 * Name should conform 8.3 format
992 */
993 if (nmlen > 12)
994 return ENAMETOOLONG;
995 cp = index(name, '.');
996 if (cp == NULL)
997 return error;
998 if (cp == name || (cp - name) > 8)
999 return error;
1000 cp = index(cp + 1, '.');
1001 if (cp != NULL)
1002 return error;
1003 for (cp = name, i = 0; i < nmlen; i++, cp++)
1004 if (index(badchars83, *cp) != NULL)
1005 return error;
1006 }
1007 for (cp = name, i = 0; i < nmlen; i++, cp++)
1008 if (index(badchars, *cp) != NULL)
1009 return error;
1010 return 0;
1011}
1012
1013/*
1014 * Things go even weird without fixed inode numbers...
9c2a2cee
CP
1015 *
1016 * smbfs_lookup(struct vnodeop_desc *a_desc, struct vnode *a_dvp,
1017 * struct vnode **a_vpp, struct componentname *a_cnp)
984263bc
MD
1018 */
1019int
e62afb5f 1020smbfs_lookup(struct vop_old_lookup_args *ap)
984263bc
MD
1021{
1022 struct componentname *cnp = ap->a_cnp;
dadab5e9 1023 struct thread *td = cnp->cn_td;
984263bc
MD
1024 struct vnode *dvp = ap->a_dvp;
1025 struct vnode **vpp = ap->a_vpp;
1026 struct vnode *vp;
1027 struct smbmount *smp;
1028 struct mount *mp = dvp->v_mount;
1029 struct smbnode *dnp;
1030 struct smbfattr fattr, *fap;
1031 struct smb_cred scred;
1032 char *name = cnp->cn_nameptr;
1033 int flags = cnp->cn_flags;
1034 int nameiop = cnp->cn_nameiop;
1035 int nmlen = cnp->cn_namelen;
fad57d0e 1036 int lockparent, wantparent, error, isdot;
984263bc
MD
1037
1038 SMBVDEBUG("\n");
2b69e610 1039 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
984263bc
MD
1040 if (dvp->v_type != VDIR)
1041 return ENOTDIR;
2b69e610 1042 if ((flags & CNP_ISDOTDOT) && (dvp->v_flag & VROOT)) {
984263bc
MD
1043 SMBFSERR("invalid '..'\n");
1044 return EIO;
1045 }
1046#ifdef SMB_VNODE_DEBUG
1047 {
1048 char *cp, c;
1049
1050 cp = name + nmlen;
1051 c = *cp;
1052 *cp = 0;
1053 SMBVDEBUG("%d '%s' in '%s' id=d\n", nameiop, name,
1054 VTOSMB(dvp)->n_name);
1055 *cp = c;
1056 }
1057#endif
fad57d0e 1058 if ((mp->mnt_flag & MNT_RDONLY) && nameiop != NAMEI_LOOKUP)
984263bc 1059 return EROFS;
dadab5e9 1060 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0)
984263bc 1061 return error;
2b69e610
MD
1062 lockparent = flags & CNP_LOCKPARENT;
1063 wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
984263bc
MD
1064 smp = VFSTOSMBFS(mp);
1065 dnp = VTOSMB(dvp);
1066 isdot = (nmlen == 1 && name[0] == '.');
1067
1068 error = smbfs_pathcheck(smp, cnp->cn_nameptr, cnp->cn_namelen, nameiop);
1069
1070 if (error)
1071 return ENOENT;
1072
984263bc
MD
1073 error = 0;
1074 *vpp = NULLVP;
dadab5e9 1075 smb_makescred(&scred, td, cnp->cn_cred);
984263bc 1076 fap = &fattr;
2b69e610 1077 if (flags & CNP_ISDOTDOT) {
984263bc
MD
1078 error = smbfs_smb_lookup(VTOSMB(dnp->n_parent), NULL, 0, fap,
1079 &scred);
1080 SMBVDEBUG("result of dotdot lookup: %d\n", error);
1081 } else {
1082 fap = &fattr;
1083 error = smbfs_smb_lookup(dnp, name, nmlen, fap, &scred);
1084/* if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.')*/
1085 SMBVDEBUG("result of smbfs_smb_lookup: %d\n", error);
1086 }
1087 if (error && error != ENOENT)
1088 return error;
1089 if (error) { /* entry not found */
1090 /*
1091 * Handle RENAME or CREATE case...
1092 */
fad57d0e 1093 if ((nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && wantparent) {
dadab5e9 1094 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
984263bc
MD
1095 if (error)
1096 return error;
984263bc 1097 if (!lockparent) {
ca466bae 1098 VOP_UNLOCK(dvp, 0);
2b69e610 1099 cnp->cn_flags |= CNP_PDIRUNLOCK;
984263bc
MD
1100 }
1101 return (EJUSTRETURN);
1102 }
1103 return ENOENT;
1104 }/* else {
1105 SMBVDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
1106 }*/
1107 /*
1108 * handle DELETE case ...
1109 */
fad57d0e 1110 if (nameiop == NAMEI_DELETE) { /* delete last component */
dadab5e9 1111 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
984263bc
MD
1112 if (error)
1113 return error;
1114 if (isdot) {
597aea93 1115 vref(dvp);
984263bc
MD
1116 *vpp = dvp;
1117 return 0;
1118 }
1119 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1120 if (error)
1121 return error;
1122 *vpp = vp;
984263bc 1123 if (!lockparent) {
ca466bae 1124 VOP_UNLOCK(dvp, 0);
2b69e610 1125 cnp->cn_flags |= CNP_PDIRUNLOCK;
984263bc
MD
1126 }
1127 return 0;
1128 }
fad57d0e 1129 if (nameiop == NAMEI_RENAME && wantparent) {
dadab5e9 1130 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
984263bc
MD
1131 if (error)
1132 return error;
1133 if (isdot)
1134 return EISDIR;
1135 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1136 if (error)
1137 return error;
1138 *vpp = vp;
984263bc 1139 if (!lockparent) {
ca466bae 1140 VOP_UNLOCK(dvp, 0);
2b69e610 1141 cnp->cn_flags |= CNP_PDIRUNLOCK;
984263bc
MD
1142 }
1143 return 0;
1144 }
2b69e610 1145 if (flags & CNP_ISDOTDOT) {
ca466bae 1146 VOP_UNLOCK(dvp, 0);
984263bc
MD
1147 error = smbfs_nget(mp, dvp, name, nmlen, NULL, &vp);
1148 if (error) {
ca466bae 1149 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
1150 return error;
1151 }
fad57d0e 1152 if (lockparent) {
ca466bae 1153 error = vn_lock(dvp, LK_EXCLUSIVE);
984263bc 1154 if (error) {
2b69e610 1155 cnp->cn_flags |= CNP_PDIRUNLOCK;
984263bc
MD
1156 vput(vp);
1157 return error;
1158 }
1159 }
1160 *vpp = vp;
1161 } else if (isdot) {
1162 vref(dvp);
1163 *vpp = dvp;
1164 } else {
1165 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1166 if (error)
1167 return error;
1168 *vpp = vp;
1169 SMBVDEBUG("lookup: getnewvp!\n");
fad57d0e 1170 if (!lockparent) {
ca466bae 1171 VOP_UNLOCK(dvp, 0);
2b69e610 1172 cnp->cn_flags |= CNP_PDIRUNLOCK;
984263bc
MD
1173 }
1174 }
984263bc
MD
1175 return 0;
1176}