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