2 * Copyright (c) 2000-2001 Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $FreeBSD: src/sys/fs/smbfs/smbfs_vnops.c,v 1.2.2.8 2003/04/04 08:57:23 tjr Exp $
33 * $DragonFly: src/sys/vfs/smbfs/smbfs_vnops.c,v 1.32 2006/07/18 22:22:16 dillon Exp $
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/namei.h>
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>
47 #include <vm/vm_extern.h>
48 #include <vm/vm_zone.h>
51 #include <netproto/smb/smb.h>
52 #include <netproto/smb/smb_conn.h>
53 #include <netproto/smb/smb_subr.h>
56 #include "smbfs_node.h"
57 #include "smbfs_subr.h"
62 * Prototypes for SMBFS vnode operations
64 static int smbfs_create(struct vop_old_create_args *);
65 static int smbfs_mknod(struct vop_old_mknod_args *);
66 static int smbfs_open(struct vop_open_args *);
67 static int smbfs_closel(struct vop_close_args *);
68 static int smbfs_access(struct vop_access_args *);
69 static int smbfs_getattr(struct vop_getattr_args *);
70 static int smbfs_setattr(struct vop_setattr_args *);
71 static int smbfs_read(struct vop_read_args *);
72 static int smbfs_write(struct vop_write_args *);
73 static int smbfs_fsync(struct vop_fsync_args *);
74 static int smbfs_remove(struct vop_old_remove_args *);
75 static int smbfs_link(struct vop_old_link_args *);
76 static int smbfs_lookup(struct vop_old_lookup_args *);
77 static int smbfs_rename(struct vop_old_rename_args *);
78 static int smbfs_mkdir(struct vop_old_mkdir_args *);
79 static int smbfs_rmdir(struct vop_old_rmdir_args *);
80 static int smbfs_symlink(struct vop_old_symlink_args *);
81 static int smbfs_readdir(struct vop_readdir_args *);
82 static int smbfs_bmap(struct vop_bmap_args *);
83 static int smbfs_strategy(struct vop_strategy_args *);
84 static int smbfs_print(struct vop_print_args *);
85 static int smbfs_pathconf(struct vop_pathconf_args *ap);
86 static int smbfs_advlock(struct vop_advlock_args *);
87 static int smbfs_getextattr(struct vop_getextattr_args *ap);
89 struct vop_ops smbfs_vnode_vops = {
90 .vop_default = vop_defaultop,
91 .vop_access = smbfs_access,
92 .vop_advlock = smbfs_advlock,
93 .vop_bmap = smbfs_bmap,
94 .vop_close = smbfs_closel,
95 .vop_old_create = smbfs_create,
96 .vop_fsync = smbfs_fsync,
97 .vop_getattr = smbfs_getattr,
98 .vop_getpages = smbfs_getpages,
99 .vop_inactive = smbfs_inactive,
100 .vop_ioctl = smbfs_ioctl,
101 .vop_islocked = vop_stdislocked,
102 .vop_old_link = smbfs_link,
103 .vop_lock = vop_stdlock,
104 .vop_old_lookup = smbfs_lookup,
105 .vop_old_mkdir = smbfs_mkdir,
106 .vop_old_mknod = smbfs_mknod,
107 .vop_open = smbfs_open,
108 .vop_pathconf = smbfs_pathconf,
109 .vop_print = smbfs_print,
110 .vop_putpages = smbfs_putpages,
111 .vop_read = smbfs_read,
112 .vop_readdir = smbfs_readdir,
113 .vop_reclaim = smbfs_reclaim,
114 .vop_old_remove = smbfs_remove,
115 .vop_old_rename = smbfs_rename,
116 .vop_old_rmdir = smbfs_rmdir,
117 .vop_setattr = smbfs_setattr,
118 .vop_strategy = smbfs_strategy,
119 .vop_old_symlink = smbfs_symlink,
120 .vop_unlock = vop_stdunlock,
121 .vop_write = smbfs_write,
122 .vop_getextattr = smbfs_getextattr
123 /* .vop_setextattr = smbfs_setextattr */
127 * smbfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
128 * struct thread *a_td)
131 smbfs_access(struct vop_access_args *ap)
133 struct vnode *vp = ap->a_vp;
134 struct ucred *cred = ap->a_cred;
135 u_int mode = ap->a_mode;
136 struct smbmount *smp = VTOSMBFS(vp);
140 if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
141 switch (vp->v_type) {
142 case VREG: case VDIR: case VLNK:
148 if (cred->cr_uid == 0)
150 if (cred->cr_uid != smp->sm_args.uid) {
152 if (!groupmember(smp->sm_args.gid, cred))
155 error = (((vp->v_type == VREG) ? smp->sm_args.file_mode : smp->sm_args.dir_mode) & mode) == mode ? 0 : EACCES;
160 * smbfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
161 * struct thread *a_td)
165 smbfs_open(struct vop_open_args *ap)
167 struct vnode *vp = ap->a_vp;
168 struct smbnode *np = VTOSMB(vp);
169 struct smb_cred scred;
171 int mode = ap->a_mode;
174 SMBVDEBUG("%s,%d\n", np->n_name, np->n_opencount);
175 if (vp->v_type != VREG && vp->v_type != VDIR) {
176 SMBFSERR("open eacces vtype=%d\n", vp->v_type);
179 if (vp->v_type == VDIR) {
180 if (np->n_opencount == 0)
181 np->n_cached_cred = crhold(ap->a_cred);
183 return (vop_stdopen(ap));
185 if (np->n_flag & NMODIFIED) {
186 if ((error = smbfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
188 smbfs_attr_cacheremove(vp);
189 error = VOP_GETATTR(vp, &vattr);
192 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
194 error = VOP_GETATTR(vp, &vattr);
197 if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
198 error = smbfs_vinvalbuf(vp, V_SAVE, 1);
201 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
204 if (np->n_opencount) {
206 return (vop_stdopen(ap));
208 accmode = SMB_AM_OPENREAD;
209 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
210 accmode = SMB_AM_OPENRW;
211 smb_makescred(&scred, curthread, ap->a_cred);
212 error = smbfs_smb_open(np, accmode, &scred);
216 accmode = SMB_AM_OPENREAD;
217 error = smbfs_smb_open(np, accmode, &scred);
220 np->n_cached_cred = crhold(ap->a_cred);
223 smbfs_attr_cacheremove(vp);
230 smbfs_closel(struct vop_close_args *ap)
232 struct vnode *vp = ap->a_vp;
233 struct smbnode *np = VTOSMB(vp);
234 struct smb_cred scred;
238 SMBVDEBUG("name=%s, pid=%d, c=%d\n",np->n_name, p->p_pid, np->n_opencount);
240 smb_makescred(&scred, curthread, proc0.p_ucred);
243 if (np->n_opencount == 0) {
244 if (vp->v_type != VDIR)
245 SMBERROR("Negative opencount\n");
249 if (vp->v_type == VDIR) {
253 smbfs_findclose(np->n_dirseq, &scred);
257 error = smbfs_vinvalbuf(vp, V_SAVE, 1);
260 VOP_GETATTR(vp, &vattr);
261 error = smbfs_smb_close(np->n_mount->sm_share, np->n_fid,
262 &np->n_mtime, &scred);
264 crfree(np->n_cached_cred);
265 np->n_cached_cred = NULL;
266 smbfs_attr_cacheremove(vp);
273 * smbfs_getattr call from vfs.
275 * smbfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct thread *a_td)
278 smbfs_getattr(struct vop_getattr_args *ap)
280 struct vnode *vp = ap->a_vp;
281 struct smbnode *np = VTOSMB(vp);
282 struct vattr *va=ap->a_vap;
283 struct smbfattr fattr;
284 struct smb_cred scred;
288 SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_flag & VROOT) != 0);
289 error = smbfs_attr_cachelookup(vp, va);
292 SMBVDEBUG("not in the cache\n");
293 smb_makescred(&scred, curthread, proc0.p_ucred);
294 oldsize = np->n_size;
295 error = smbfs_smb_lookup(np, NULL, 0, &fattr, &scred);
297 SMBVDEBUG("error %d\n", error);
300 smbfs_attr_cacheenter(vp, &fattr);
301 smbfs_attr_cachelookup(vp, va);
303 np->n_size = oldsize;
308 * smbfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
309 * struct thread *a_td)
312 smbfs_setattr(struct vop_setattr_args *ap)
314 struct vnode *vp = ap->a_vp;
315 struct smbnode *np = VTOSMB(vp);
316 struct vattr *vap = ap->a_vap;
317 struct timespec *mtime, *atime;
318 struct smb_cred scred;
319 struct smb_share *ssp = np->n_mount->sm_share;
320 struct smb_vc *vcp = SSTOVC(ssp);
322 int isreadonly, doclose, error = 0;
325 if (vap->va_flags != VNOVAL)
327 isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
329 * Disallow write attempts if the filesystem is mounted read-only.
331 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
332 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
333 vap->va_mode != (mode_t)VNOVAL) && isreadonly)
335 smb_makescred(&scred, curthread, ap->a_cred);
336 if (vap->va_size != VNOVAL) {
337 switch (vp->v_type) {
348 vnode_pager_setsize(vp, (u_long)vap->va_size);
350 np->n_size = vap->va_size;
351 if (np->n_opencount == 0) {
352 error = smbfs_smb_open(np, SMB_AM_OPENRW, &scred);
357 error = smbfs_smb_setfsize(np, vap->va_size, &scred);
359 smbfs_smb_close(ssp, np->n_fid, NULL, &scred);
362 vnode_pager_setsize(vp, (u_long)tsize);
366 mtime = atime = NULL;
367 if (vap->va_mtime.tv_sec != VNOVAL)
368 mtime = &vap->va_mtime;
369 if (vap->va_atime.tv_sec != VNOVAL)
370 atime = &vap->va_atime;
371 if (mtime != atime) {
372 if (ap->a_cred->cr_uid != VTOSMBFS(vp)->sm_args.uid &&
373 (error = suser_cred(ap->a_cred, PRISON_ROOT)) &&
374 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
375 (error = VOP_ACCESS(vp, VWRITE, ap->a_cred))))
379 mtime = &np->n_mtime;
381 atime = &np->n_atime;
384 * If file is opened, then we can use handle based calls.
385 * If not, use path based ones.
387 if (np->n_opencount == 0) {
388 if (vcp->vc_flags & SMBV_WIN95) {
389 error = VOP_OPEN(vp, FWRITE, ap->a_cred, NULL);
391 /* error = smbfs_smb_setfattrNT(np, 0, mtime, atime, &scred);
392 VOP_GETATTR(vp, &vattr);*/
394 np->n_mtime = *mtime;
395 VOP_CLOSE(vp, FWRITE);
397 } else if ((vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS)) {
398 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
399 /* error = smbfs_smb_setpattrNT(np, 0, mtime, atime, &scred);*/
400 } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
401 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
403 error = smbfs_smb_setpattr(np, 0, mtime, &scred);
406 if (vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS) {
407 error = smbfs_smb_setfattrNT(np, 0, mtime, atime, &scred);
408 } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN1_0) {
409 error = smbfs_smb_setftime(np, mtime, atime, &scred);
412 * I have no idea how to handle this for core
413 * level servers. The possible solution is to
414 * update mtime after file is closed.
416 SMBERROR("can't update times on an opened file\n");
421 * Invalidate attribute cache in case if server doesn't set
422 * required attributes.
424 smbfs_attr_cacheremove(vp); /* invalidate cache */
425 VOP_GETATTR(vp, vap);
426 np->n_mtime.tv_sec = vap->va_mtime.tv_sec;
432 * smbfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
433 * struct ucred *a_cred)
436 smbfs_read(struct vop_read_args *ap)
438 struct vnode *vp = ap->a_vp;
439 struct uio *uio = ap->a_uio;
442 if (vp->v_type != VREG && vp->v_type != VDIR)
444 return smbfs_readvnode(vp, uio, ap->a_cred);
448 * smbfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
449 * struct ucred *a_cred)
452 smbfs_write(struct vop_write_args *ap)
454 struct vnode *vp = ap->a_vp;
455 struct uio *uio = ap->a_uio;
457 SMBVDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
458 if (vp->v_type != VREG)
460 return smbfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
464 * Create a regular file. On entry the directory to contain the file being
465 * created is locked. We must release before we return.
467 * smbfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
468 * struct componentname *a_cnp, struct vattr *a_vap)
471 smbfs_create(struct vop_old_create_args *ap)
473 struct vnode *dvp = ap->a_dvp;
474 struct vattr *vap = ap->a_vap;
475 struct vnode **vpp=ap->a_vpp;
476 struct componentname *cnp = ap->a_cnp;
477 struct smbnode *dnp = VTOSMB(dvp);
480 struct smbfattr fattr;
481 struct smb_cred scred;
482 char *name = cnp->cn_nameptr;
483 int nmlen = cnp->cn_namelen;
489 if (vap->va_type != VREG)
491 if ((error = VOP_GETATTR(dvp, &vattr)))
493 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
495 error = smbfs_smb_create(dnp, name, nmlen, &scred);
498 error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, &scred);
501 error = smbfs_nget(VTOVFS(dvp), dvp, name, nmlen, &fattr, &vp);
509 * smbfs_remove(struct vnodeop_desc *a_desc, struct vnode *a_dvp,
510 * struct vnode *a_vp, struct componentname *a_cnp)
513 smbfs_remove(struct vop_old_remove_args *ap)
515 struct vnode *vp = ap->a_vp;
516 /* struct vnode *dvp = ap->a_dvp;*/
517 struct componentname *cnp = ap->a_cnp;
518 struct smbnode *np = VTOSMB(vp);
519 struct smb_cred scred;
522 if (vp->v_type == VDIR || np->n_opencount || vp->v_usecount != 1)
524 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
525 error = smbfs_smb_delete(np, &scred);
530 * smbfs_file rename call
532 * smbfs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
533 * struct componentname *a_fcnp, struct vnode *a_tdvp,
534 * struct vnode *a_tvp, struct componentname *a_tcnp)
537 smbfs_rename(struct vop_old_rename_args *ap)
539 struct vnode *fvp = ap->a_fvp;
540 struct vnode *tvp = ap->a_tvp;
541 struct vnode *fdvp = ap->a_fdvp;
542 struct vnode *tdvp = ap->a_tdvp;
543 struct componentname *tcnp = ap->a_tcnp;
544 /* struct componentname *fcnp = ap->a_fcnp;*/
545 struct smb_cred scred;
549 /* Check for cross-device rename */
550 if ((fvp->v_mount != tdvp->v_mount) ||
551 (tvp && (fvp->v_mount != tvp->v_mount))) {
556 if (tvp && tvp->v_usecount > 1) {
560 flags = 0x10; /* verify all writes */
561 if (fvp->v_type == VDIR) {
563 } else if (fvp->v_type == VREG) {
569 smb_makescred(&scred, tcnp->cn_td, tcnp->cn_cred);
571 * It seems that Samba doesn't implement SMB_COM_MOVE call...
574 if (SMB_DIALECT(SSTOCN(smp->sm_share)) >= SMB_DIALECT_LANMAN1_0) {
575 error = smbfs_smb_move(VTOSMB(fvp), VTOSMB(tdvp),
576 tcnp->cn_nameptr, tcnp->cn_namelen, flags, &scred);
581 * We have to do the work atomicaly
583 if (tvp && tvp != fvp) {
584 error = smbfs_smb_delete(VTOSMB(tvp), &scred);
588 error = smbfs_smb_rename(VTOSMB(fvp), VTOSMB(tdvp),
589 tcnp->cn_nameptr, tcnp->cn_namelen, &scred);
593 smbfs_attr_cacheremove(fdvp);
594 smbfs_attr_cacheremove(tdvp);
604 #ifdef possible_mistake
614 * somtime it will come true...
616 * smbfs_link(struct vnode *a_tdvp, struct vnode *a_vp,
617 * struct componentname *a_cnp)
620 smbfs_link(struct vop_old_link_args *ap)
626 * smbfs_symlink link create call.
627 * Sometime it will be functional...
629 * smbfs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
630 * struct componentname *a_cnp, struct vattr *a_vap,
634 smbfs_symlink(struct vop_old_symlink_args *ap)
640 smbfs_mknod(struct vop_old_mknod_args *ap)
646 * smbfs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
647 * struct componentname *a_cnp, struct vattr *a_vap)
650 smbfs_mkdir(struct vop_old_mkdir_args *ap)
652 struct vnode *dvp = ap->a_dvp;
653 /* struct vattr *vap = ap->a_vap;*/
655 struct componentname *cnp = ap->a_cnp;
656 struct smbnode *dnp = VTOSMB(dvp);
658 struct smb_cred scred;
659 struct smbfattr fattr;
660 char *name = cnp->cn_nameptr;
661 int len = cnp->cn_namelen;
664 if ((error = VOP_GETATTR(dvp, &vattr))) {
667 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.'))))
669 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
670 error = smbfs_smb_mkdir(dnp, name, len, &scred);
673 error = smbfs_smb_lookup(dnp, name, len, &fattr, &scred);
676 error = smbfs_nget(VTOVFS(dvp), dvp, name, len, &fattr, &vp);
684 * smbfs_remove directory call
686 * smbfs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
687 * struct componentname *a_cnp)
690 smbfs_rmdir(struct vop_old_rmdir_args *ap)
692 struct vnode *vp = ap->a_vp;
693 struct vnode *dvp = ap->a_dvp;
694 struct componentname *cnp = ap->a_cnp;
695 /* struct smbmount *smp = VTOSMBFS(vp);*/
696 struct smbnode *dnp = VTOSMB(dvp);
697 struct smbnode *np = VTOSMB(vp);
698 struct smb_cred scred;
704 smb_makescred(&scred, cnp->cn_td, cnp->cn_cred);
705 error = smbfs_smb_rmdir(np, &scred);
706 dnp->n_flag |= NMODIFIED;
707 smbfs_attr_cacheremove(dvp);
714 * smbfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
715 * int *a_eofflag, u_long *a_cookies, int a_ncookies)
718 smbfs_readdir(struct vop_readdir_args *ap)
720 struct vnode *vp = ap->a_vp;
721 struct uio *uio = ap->a_uio;
724 if (vp->v_type != VDIR)
727 if (ap->a_ncookies) {
728 printf("smbfs_readdir: no support for cookies now...");
732 error = smbfs_readvnode(vp, uio, ap->a_cred);
737 * smbfs_fsync(struct vnodeop_desc *a_desc, struct vnode *a_vp,
738 * struct ucred *a_cred, int a_waitfor, struct thread *a_td)
742 smbfs_fsync(struct vop_fsync_args *ap)
744 /* return (smb_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
749 * smbfs_print(struct vnode *a_vp)
752 smbfs_print(struct vop_print_args *ap)
754 struct vnode *vp = ap->a_vp;
755 struct smbnode *np = VTOSMB(vp);
758 printf("no smbnode data\n");
761 printf("tag VT_SMBFS, name = %s, parent = %p, opencount = %d",
762 np->n_name, np->n_parent ? np->n_parent : NULL,
764 lockmgr_printinfo(&vp->v_lock);
770 * smbfs_pathconf(struct vnode *vp, int name, register_t *retval)
773 smbfs_pathconf(struct vop_pathconf_args *ap)
775 struct smbmount *smp = VFSTOSMBFS(VTOVFS(ap->a_vp));
776 struct smb_vc *vcp = SSTOVC(smp->sm_share);
777 register_t *retval = ap->a_retval;
780 switch (ap->a_name) {
785 *retval = (vcp->vc_hflags2 & SMB_FLAGS2_KNOWS_LONG_NAMES) ? 255 : 12;
788 *retval = 800; /* XXX: a correct one ? */
797 * smbfs_strategy(struct vnode *a_vp, struct bio *a_bio)
800 smbfs_strategy(struct vop_strategy_args *ap)
802 struct bio *bio = ap->a_bio;
803 struct buf *bp = bio->bio_buf;
804 struct thread *td = NULL;
808 if ((bp->b_flags & B_ASYNC) == 0)
809 td = curthread; /* XXX */
811 if ((bp->b_flags & B_ASYNC) == 0 )
812 error = smbfs_doio(ap->a_vp, bio, proc0.p_ucred, td);
817 * smbfs_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
818 * off_t *a_doffsetp, int *a_runp, int *a_runb)
821 smbfs_bmap(struct vop_bmap_args *ap)
823 struct vnode *vp = ap->a_vp;
825 if (ap->a_vpp != NULL)
827 if (ap->a_doffsetp != NULL)
828 *ap->a_doffsetp = ap->a_loffset;
829 if (ap->a_runp != NULL)
831 if (ap->a_runb != NULL)
837 * smbfs_ioctl(struct vnode *a_vp, u_long a_command, caddr_t a_data,
838 * int fflag, struct ucred *cred, struct proc *p)
841 smbfs_ioctl(struct vop_ioctl_args *ap)
846 static char smbfs_atl[] = "rhsvda";
848 smbfs_getextattr(struct vop_getextattr_args *ap)
850 IN struct vnode *a_vp;
852 INOUT struct uio *a_uio;
853 IN struct ucred *a_cred;
854 IN struct thread *a_td;
858 struct vnode *vp = ap->a_vp;
859 struct ucred *cred = ap->a_cred;
860 struct uio *uio = ap->a_uio;
861 const char *name = ap->a_name;
862 struct smbnode *np = VTOSMB(vp);
867 error = VOP_ACCESS(vp, VREAD, cred);
870 error = VOP_GETATTR(vp, &vattr);
873 if (strcmp(name, "dosattr") == 0) {
874 attr = np->n_dosattr;
875 for (i = 0; i < 6; i++, attr >>= 1)
876 buf[i] = (attr & 1) ? smbfs_atl[i] : '-';
878 error = uiomove(buf, i, uio);
886 * Since we expected to support F_GETLK (and SMB protocol has no such function),
887 * it is necessary to use lf_advlock(). It would be nice if this function had
888 * a callback mechanism because it will help to improve a level of consistency.
890 * smbfs_advlock(struct vnode *a_vp, caddr_t a_id, int a_op,
891 * struct flock *a_fl, int a_flags)
894 smbfs_advlock(struct vop_advlock_args *ap)
896 struct vnode *vp = ap->a_vp;
897 struct smbnode *np = VTOSMB(vp);
898 struct flock *fl = ap->a_fl;
899 caddr_t id = (caddr_t)1 /* ap->a_id */;
900 /* int flags = ap->a_flags;*/
901 struct thread *td = curthread; /* XXX */
902 struct smb_cred scred;
903 off_t start, end, size;
906 if (vp->v_type == VDIR) {
908 * SMB protocol have no support for directory locking.
909 * Although locks can be processed on local machine, I don't
910 * think that this is a good idea, because some programs
911 * can work wrong assuming directory is locked. So, we just
912 * return 'operation not supported
917 switch (fl->l_whence) {
923 start = fl->l_start + size;
932 end = start + fl->l_len - 1;
936 smb_makescred(&scred, td, td->td_proc ? td->td_proc->p_ucred : NULL);
939 switch (fl->l_type) {
941 lkop = SMB_LOCK_EXCL;
944 lkop = SMB_LOCK_SHARED;
947 lkop = SMB_LOCK_RELEASE;
952 error = lf_advlock(ap, &np->n_lockf, size);
955 lkop = SMB_LOCK_EXCL;
956 error = smbfs_smb_lock(np, lkop, id, start, end, &scred);
959 lf_advlock(ap, &np->n_lockf, size);
963 lf_advlock(ap, &np->n_lockf, size);
964 error = smbfs_smb_lock(np, SMB_LOCK_RELEASE, id, start, end, &scred);
967 error = lf_advlock(ap, &np->n_lockf, size);
976 smbfs_pathcheck(struct smbmount *smp, const char *name, int nmlen, int nameiop)
978 static const char *badchars = "*/:<>;?";
979 static const char *badchars83 = " +|,";
984 * Backslash characters, being a path delimiter, are prohibited
985 * within a path component even for LOOKUP operations.
987 if (index(name, '\\') != NULL)
990 if (nameiop == NAMEI_LOOKUP)
993 if (SMB_DIALECT(SSTOVC(smp->sm_share)) < SMB_DIALECT_LANMAN2_0) {
995 * Name should conform 8.3 format
999 cp = index(name, '.');
1002 if (cp == name || (cp - name) > 8)
1004 cp = index(cp + 1, '.');
1007 for (cp = name, i = 0; i < nmlen; i++, cp++)
1008 if (index(badchars83, *cp) != NULL)
1011 for (cp = name, i = 0; i < nmlen; i++, cp++)
1012 if (index(badchars, *cp) != NULL)
1018 * Things go even weird without fixed inode numbers...
1020 * smbfs_lookup(struct vnodeop_desc *a_desc, struct vnode *a_dvp,
1021 * struct vnode **a_vpp, struct componentname *a_cnp)
1024 smbfs_lookup(struct vop_old_lookup_args *ap)
1026 struct componentname *cnp = ap->a_cnp;
1027 struct thread *td = cnp->cn_td;
1028 struct vnode *dvp = ap->a_dvp;
1029 struct vnode **vpp = ap->a_vpp;
1031 struct smbmount *smp;
1032 struct mount *mp = dvp->v_mount;
1033 struct smbnode *dnp;
1034 struct smbfattr fattr, *fap;
1035 struct smb_cred scred;
1036 char *name = cnp->cn_nameptr;
1037 int flags = cnp->cn_flags;
1038 int nameiop = cnp->cn_nameiop;
1039 int nmlen = cnp->cn_namelen;
1040 int lockparent, wantparent, error, isdot;
1043 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
1044 if (dvp->v_type != VDIR)
1046 if ((flags & CNP_ISDOTDOT) && (dvp->v_flag & VROOT)) {
1047 SMBFSERR("invalid '..'\n");
1050 #ifdef SMB_VNODE_DEBUG
1057 SMBVDEBUG("%d '%s' in '%s' id=d\n", nameiop, name,
1058 VTOSMB(dvp)->n_name);
1062 if ((mp->mnt_flag & MNT_RDONLY) && nameiop != NAMEI_LOOKUP)
1064 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred)) != 0)
1066 lockparent = flags & CNP_LOCKPARENT;
1067 wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
1068 smp = VFSTOSMBFS(mp);
1070 isdot = (nmlen == 1 && name[0] == '.');
1072 error = smbfs_pathcheck(smp, cnp->cn_nameptr, cnp->cn_namelen, nameiop);
1079 smb_makescred(&scred, td, cnp->cn_cred);
1081 if (flags & CNP_ISDOTDOT) {
1082 error = smbfs_smb_lookup(VTOSMB(dnp->n_parent), NULL, 0, fap,
1084 SMBVDEBUG("result of dotdot lookup: %d\n", error);
1087 error = smbfs_smb_lookup(dnp, name, nmlen, fap, &scred);
1088 /* if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.')*/
1089 SMBVDEBUG("result of smbfs_smb_lookup: %d\n", error);
1091 if (error && error != ENOENT)
1093 if (error) { /* entry not found */
1095 * Handle RENAME or CREATE case...
1097 if ((nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && wantparent) {
1098 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
1103 cnp->cn_flags |= CNP_PDIRUNLOCK;
1105 return (EJUSTRETURN);
1109 SMBVDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
1112 * handle DELETE case ...
1114 if (nameiop == NAMEI_DELETE) { /* delete last component */
1115 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
1123 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1129 cnp->cn_flags |= CNP_PDIRUNLOCK;
1133 if (nameiop == NAMEI_RENAME && wantparent) {
1134 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
1139 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1145 cnp->cn_flags |= CNP_PDIRUNLOCK;
1149 if (flags & CNP_ISDOTDOT) {
1151 error = smbfs_nget(mp, dvp, name, nmlen, NULL, &vp);
1153 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1157 error = vn_lock(dvp, LK_EXCLUSIVE);
1159 cnp->cn_flags |= CNP_PDIRUNLOCK;
1169 error = smbfs_nget(mp, dvp, name, nmlen, fap, &vp);
1173 SMBVDEBUG("lookup: getnewvp!\n");
1176 cnp->cn_flags |= CNP_PDIRUNLOCK;