Deleted Added
full compact
smbfs_vnops.c (178243) smbfs_vnops.c (182371)
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

--- 15 unchanged lines hidden (view full) ---

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 *
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

--- 15 unchanged lines hidden (view full) ---

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: head/sys/fs/smbfs/smbfs_vnops.c 178243 2008-04-16 11:33:32Z kib $
32 * $FreeBSD: head/sys/fs/smbfs/smbfs_vnops.c 182371 2008-08-28 15:23:18Z attilio $
33 */
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/namei.h>
37#include <sys/kernel.h>
38#include <sys/proc.h>
39#include <sys/bio.h>
40#include <sys/buf.h>

--- 131 unchanged lines hidden (view full) ---

172 if (vp->v_type == VDIR) {
173 np->n_flag |= NOPEN;
174 return 0;
175 }
176 if (np->n_flag & NMODIFIED) {
177 if ((error = smbfs_vinvalbuf(vp, ap->a_td)) == EINTR)
178 return error;
179 smbfs_attr_cacheremove(vp);
33 */
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/namei.h>
37#include <sys/kernel.h>
38#include <sys/proc.h>
39#include <sys/bio.h>
40#include <sys/buf.h>

--- 131 unchanged lines hidden (view full) ---

172 if (vp->v_type == VDIR) {
173 np->n_flag |= NOPEN;
174 return 0;
175 }
176 if (np->n_flag & NMODIFIED) {
177 if ((error = smbfs_vinvalbuf(vp, ap->a_td)) == EINTR)
178 return error;
179 smbfs_attr_cacheremove(vp);
180 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
180 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
181 if (error)
182 return error;
183 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
184 } else {
181 if (error)
182 return error;
183 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
184 } else {
185 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
185 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
186 if (error)
187 return error;
188 if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
189 error = smbfs_vinvalbuf(vp, ap->a_td);
190 if (error == EINTR)
191 return error;
192 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
193 }

--- 55 unchanged lines hidden (view full) ---

249 * smbfs_getattr call from vfs.
250 */
251static int
252smbfs_getattr(ap)
253 struct vop_getattr_args /* {
254 struct vnode *a_vp;
255 struct vattr *a_vap;
256 struct ucred *a_cred;
186 if (error)
187 return error;
188 if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
189 error = smbfs_vinvalbuf(vp, ap->a_td);
190 if (error == EINTR)
191 return error;
192 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
193 }

--- 55 unchanged lines hidden (view full) ---

249 * smbfs_getattr call from vfs.
250 */
251static int
252smbfs_getattr(ap)
253 struct vop_getattr_args /* {
254 struct vnode *a_vp;
255 struct vattr *a_vap;
256 struct ucred *a_cred;
257 struct thread *a_td;
258 } */ *ap;
259{
260 struct vnode *vp = ap->a_vp;
261 struct smbnode *np = VTOSMB(vp);
262 struct vattr *va=ap->a_vap;
263 struct smbfattr fattr;
264 struct smb_cred scred;
265 u_quad_t oldsize;
266 int error;
267
268 SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
269 error = smbfs_attr_cachelookup(vp, va);
270 if (!error)
271 return 0;
272 SMBVDEBUG("not in the cache\n");
257 } */ *ap;
258{
259 struct vnode *vp = ap->a_vp;
260 struct smbnode *np = VTOSMB(vp);
261 struct vattr *va=ap->a_vap;
262 struct smbfattr fattr;
263 struct smb_cred scred;
264 u_quad_t oldsize;
265 int error;
266
267 SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
268 error = smbfs_attr_cachelookup(vp, va);
269 if (!error)
270 return 0;
271 SMBVDEBUG("not in the cache\n");
273 smb_makescred(&scred, ap->a_td, ap->a_cred);
272 smb_makescred(&scred, curthread, ap->a_cred);
274 oldsize = np->n_size;
275 error = smbfs_smb_lookup(np, NULL, 0, &fattr, &scred);
276 if (error) {
277 SMBVDEBUG("error %d\n", error);
278 return error;
279 }
280 smbfs_attr_cacheenter(vp, &fattr);
281 smbfs_attr_cachelookup(vp, va);
282 if (np->n_flag & NOPEN)
283 np->n_size = oldsize;
284 return 0;
285}
286
287static int
288smbfs_setattr(ap)
289 struct vop_setattr_args /* {
290 struct vnode *a_vp;
291 struct vattr *a_vap;
292 struct ucred *a_cred;
273 oldsize = np->n_size;
274 error = smbfs_smb_lookup(np, NULL, 0, &fattr, &scred);
275 if (error) {
276 SMBVDEBUG("error %d\n", error);
277 return error;
278 }
279 smbfs_attr_cacheenter(vp, &fattr);
280 smbfs_attr_cachelookup(vp, va);
281 if (np->n_flag & NOPEN)
282 np->n_size = oldsize;
283 return 0;
284}
285
286static int
287smbfs_setattr(ap)
288 struct vop_setattr_args /* {
289 struct vnode *a_vp;
290 struct vattr *a_vap;
291 struct ucred *a_cred;
293 struct thread *a_td;
294 } */ *ap;
295{
296 struct vnode *vp = ap->a_vp;
297 struct smbnode *np = VTOSMB(vp);
298 struct vattr *vap = ap->a_vap;
299 struct timespec *mtime, *atime;
300 struct smb_cred scred;
301 struct smb_share *ssp = np->n_mount->sm_share;
302 struct smb_vc *vcp = SSTOVC(ssp);
292 } */ *ap;
293{
294 struct vnode *vp = ap->a_vp;
295 struct smbnode *np = VTOSMB(vp);
296 struct vattr *vap = ap->a_vap;
297 struct timespec *mtime, *atime;
298 struct smb_cred scred;
299 struct smb_share *ssp = np->n_mount->sm_share;
300 struct smb_vc *vcp = SSTOVC(ssp);
301 struct thread *td = curthread;
303 u_quad_t tsize = 0;
304 int isreadonly, doclose, error = 0;
305 int old_n_dosattr;
306
307 SMBVDEBUG("\n");
308 if (vap->va_flags != VNOVAL)
309 return EOPNOTSUPP;
310 isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
311 /*
312 * Disallow write attempts if the filesystem is mounted read-only.
313 */
314 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
315 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
316 vap->va_mode != (mode_t)VNOVAL) && isreadonly)
317 return EROFS;
302 u_quad_t tsize = 0;
303 int isreadonly, doclose, error = 0;
304 int old_n_dosattr;
305
306 SMBVDEBUG("\n");
307 if (vap->va_flags != VNOVAL)
308 return EOPNOTSUPP;
309 isreadonly = (vp->v_mount->mnt_flag & MNT_RDONLY);
310 /*
311 * Disallow write attempts if the filesystem is mounted read-only.
312 */
313 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
314 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
315 vap->va_mode != (mode_t)VNOVAL) && isreadonly)
316 return EROFS;
318 smb_makescred(&scred, ap->a_td, ap->a_cred);
317 smb_makescred(&scred, td, ap->a_cred);
319 if (vap->va_size != VNOVAL) {
320 switch (vp->v_type) {
321 case VDIR:
322 return EISDIR;
323 case VREG:
324 break;
325 default:
326 return EINVAL;

--- 35 unchanged lines hidden (view full) ---

362 }
363 mtime = atime = NULL;
364 if (vap->va_mtime.tv_sec != VNOVAL)
365 mtime = &vap->va_mtime;
366 if (vap->va_atime.tv_sec != VNOVAL)
367 atime = &vap->va_atime;
368 if (mtime != atime) {
369 if (vap->va_vaflags & VA_UTIMES_NULL) {
318 if (vap->va_size != VNOVAL) {
319 switch (vp->v_type) {
320 case VDIR:
321 return EISDIR;
322 case VREG:
323 break;
324 default:
325 return EINVAL;

--- 35 unchanged lines hidden (view full) ---

361 }
362 mtime = atime = NULL;
363 if (vap->va_mtime.tv_sec != VNOVAL)
364 mtime = &vap->va_mtime;
365 if (vap->va_atime.tv_sec != VNOVAL)
366 atime = &vap->va_atime;
367 if (mtime != atime) {
368 if (vap->va_vaflags & VA_UTIMES_NULL) {
370 error = VOP_ACCESS(vp, VADMIN, ap->a_cred, ap->a_td);
369 error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td);
371 if (error)
370 if (error)
372 error = VOP_ACCESS(vp, VWRITE, ap->a_cred,
373 ap->a_td);
371 error = VOP_ACCESS(vp, VWRITE, ap->a_cred, td);
374 } else
372 } else
375 error = VOP_ACCESS(vp, VADMIN, ap->a_cred, ap->a_td);
373 error = VOP_ACCESS(vp, VADMIN, ap->a_cred, td);
376#if 0
377 if (mtime == NULL)
378 mtime = &np->n_mtime;
379 if (atime == NULL)
380 atime = &np->n_atime;
381#endif
382 /*
383 * If file is opened, then we can use handle based calls.
384 * If not, use path based ones.
385 */
386 if ((np->n_flag & NOPEN) == 0) {
387 if (vcp->vc_flags & SMBV_WIN95) {
374#if 0
375 if (mtime == NULL)
376 mtime = &np->n_mtime;
377 if (atime == NULL)
378 atime = &np->n_atime;
379#endif
380 /*
381 * If file is opened, then we can use handle based calls.
382 * If not, use path based ones.
383 */
384 if ((np->n_flag & NOPEN) == 0) {
385 if (vcp->vc_flags & SMBV_WIN95) {
388 error = VOP_OPEN(vp, FWRITE, ap->a_cred, ap->a_td, NULL);
386 error = VOP_OPEN(vp, FWRITE, ap->a_cred, td,
387 NULL);
389 if (!error) {
388 if (!error) {
390/* error = smbfs_smb_setfattrNT(np, 0, mtime, atime, &scred);
391 VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);*/
392 if (mtime)
393 np->n_mtime = *mtime;
394 VOP_CLOSE(vp, FWRITE, ap->a_cred, ap->a_td);
389/* error = smbfs_smb_setfattrNT(np, 0,
390 mtime, atime, &scred);
391 VOP_GETATTR(vp, &vattr, ap->a_cred); */
392 if (mtime)
393 np->n_mtime = *mtime;
394 VOP_CLOSE(vp, FWRITE, ap->a_cred, td);
395 }
396 } else if ((vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS)) {
397 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
398/* error = smbfs_smb_setpattrNT(np, 0, mtime, atime, &scred);*/
399 } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
400 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
401 } else {
402 error = smbfs_smb_setpattr(np, 0, mtime, &scred);

--- 13 unchanged lines hidden (view full) ---

416 }
417 }
418 }
419 /*
420 * Invalidate attribute cache in case if server doesn't set
421 * required attributes.
422 */
423 smbfs_attr_cacheremove(vp); /* invalidate cache */
395 }
396 } else if ((vcp->vc_sopt.sv_caps & SMB_CAP_NT_SMBS)) {
397 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
398/* error = smbfs_smb_setpattrNT(np, 0, mtime, atime, &scred);*/
399 } else if (SMB_DIALECT(vcp) >= SMB_DIALECT_LANMAN2_0) {
400 error = smbfs_smb_setptime2(np, mtime, atime, 0, &scred);
401 } else {
402 error = smbfs_smb_setpattr(np, 0, mtime, &scred);

--- 13 unchanged lines hidden (view full) ---

416 }
417 }
418 }
419 /*
420 * Invalidate attribute cache in case if server doesn't set
421 * required attributes.
422 */
423 smbfs_attr_cacheremove(vp); /* invalidate cache */
424 VOP_GETATTR(vp, vap, ap->a_cred, ap->a_td);
424 VOP_GETATTR(vp, vap, ap->a_cred);
425 np->n_mtime.tv_sec = vap->va_mtime.tv_sec;
426 return error;
427}
428/*
429 * smbfs_read call.
430 */
431static int
432smbfs_read(ap)

--- 59 unchanged lines hidden (view full) ---

492 int nmlen = cnp->cn_namelen;
493 int error;
494
495
496 SMBVDEBUG("\n");
497 *vpp = NULL;
498 if (vap->va_type != VREG)
499 return EOPNOTSUPP;
425 np->n_mtime.tv_sec = vap->va_mtime.tv_sec;
426 return error;
427}
428/*
429 * smbfs_read call.
430 */
431static int
432smbfs_read(ap)

--- 59 unchanged lines hidden (view full) ---

492 int nmlen = cnp->cn_namelen;
493 int error;
494
495
496 SMBVDEBUG("\n");
497 *vpp = NULL;
498 if (vap->va_type != VREG)
499 return EOPNOTSUPP;
500 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)))
500 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)))
501 return error;
502 smb_makescred(&scred, cnp->cn_thread, cnp->cn_cred);
503
504 error = smbfs_smb_create(dnp, name, nmlen, &scred);
505 if (error)
506 return error;
507 error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, &scred);
508 if (error)

--- 182 unchanged lines hidden (view full) ---

691 struct smbnode *dnp = VTOSMB(dvp);
692 struct vattr vattr;
693 struct smb_cred scred;
694 struct smbfattr fattr;
695 char *name = cnp->cn_nameptr;
696 int len = cnp->cn_namelen;
697 int error;
698
501 return error;
502 smb_makescred(&scred, cnp->cn_thread, cnp->cn_cred);
503
504 error = smbfs_smb_create(dnp, name, nmlen, &scred);
505 if (error)
506 return error;
507 error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, &scred);
508 if (error)

--- 182 unchanged lines hidden (view full) ---

691 struct smbnode *dnp = VTOSMB(dvp);
692 struct vattr vattr;
693 struct smb_cred scred;
694 struct smbfattr fattr;
695 char *name = cnp->cn_nameptr;
696 int len = cnp->cn_namelen;
697 int error;
698
699 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
699 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred))) {
700 return error;
701 }
702 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.'))))
703 return EEXIST;
704 smb_makescred(&scred, cnp->cn_thread, cnp->cn_cred);
705 error = smbfs_smb_mkdir(dnp, name, len, &scred);
706 if (error)
707 return error;

--- 193 unchanged lines hidden (view full) ---

901 struct smbnode *np = VTOSMB(vp);
902 struct vattr vattr;
903 char buf[10];
904 int i, attr, error;
905
906 error = VOP_ACCESS(vp, VREAD, cred, td);
907 if (error)
908 return error;
700 return error;
701 }
702 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.'))))
703 return EEXIST;
704 smb_makescred(&scred, cnp->cn_thread, cnp->cn_cred);
705 error = smbfs_smb_mkdir(dnp, name, len, &scred);
706 if (error)
707 return error;

--- 193 unchanged lines hidden (view full) ---

901 struct smbnode *np = VTOSMB(vp);
902 struct vattr vattr;
903 char buf[10];
904 int i, attr, error;
905
906 error = VOP_ACCESS(vp, VREAD, cred, td);
907 if (error)
908 return error;
909 error = VOP_GETATTR(vp, &vattr, cred, td);
909 error = VOP_GETATTR(vp, &vattr, cred);
910 if (error)
911 return error;
912 if (strcmp(name, "dosattr") == 0) {
913 attr = np->n_dosattr;
914 for (i = 0; i < 6; i++, attr >>= 1)
915 buf[i] = (attr & 1) ? smbfs_atl[i] : '-';
916 buf[i] = 0;
917 error = uiomove(buf, i, uio);

--- 224 unchanged lines hidden (view full) ---

1142 SMBVDEBUG("cache_lookup returned %d\n", error);
1143 if (error > 0)
1144 return error;
1145 if (error) { /* name was found */
1146 struct vattr vattr;
1147
1148 killit = 0;
1149 vp = *vpp;
910 if (error)
911 return error;
912 if (strcmp(name, "dosattr") == 0) {
913 attr = np->n_dosattr;
914 for (i = 0; i < 6; i++, attr >>= 1)
915 buf[i] = (attr & 1) ? smbfs_atl[i] : '-';
916 buf[i] = 0;
917 error = uiomove(buf, i, uio);

--- 224 unchanged lines hidden (view full) ---

1142 SMBVDEBUG("cache_lookup returned %d\n", error);
1143 if (error > 0)
1144 return error;
1145 if (error) { /* name was found */
1146 struct vattr vattr;
1147
1148 killit = 0;
1149 vp = *vpp;
1150 error = VOP_GETATTR(vp, &vattr, cnp->cn_cred, td);
1150 error = VOP_GETATTR(vp, &vattr, cnp->cn_cred);
1151 /*
1152 * If the file type on the server is inconsistent
1153 * with what it was when we created the vnode,
1154 * kill the bogus vnode now and fall through to
1155 * the code below to create a new one with the
1156 * right type.
1157 */
1158 if (error == 0 &&

--- 116 unchanged lines hidden ---
1151 /*
1152 * If the file type on the server is inconsistent
1153 * with what it was when we created the vnode,
1154 * kill the bogus vnode now and fall through to
1155 * the code below to create a new one with the
1156 * right type.
1157 */
1158 if (error == 0 &&

--- 116 unchanged lines hidden ---