Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/smbfs Add support for 64 bit file offsets to smbfs_sm...



details:   https://anonhg.NetBSD.org/src/rev/8ea7cd1db738
branches:  trunk
changeset: 748327:8ea7cd1db738
user:      tron <tron%NetBSD.org@localhost>
date:      Tue Oct 20 20:55:01 2009 +0000

description:
Add support for 64 bit file offsets to smbfs_smb_setfsize(), largely
based on code taken from FreeBSD.

This stops truncation of files larger than 4GB by VOP_SETATTR() which e.g.
happened when copying large files "rump_smbfs". Kudos to Antti Kantee
for diagnosing the problem in smbfs_smb_setfsize().

diffstat:

 sys/fs/smbfs/smbfs_smb.c  |  42 +++++++++++++++++++++++++++++++++++++++---
 sys/fs/smbfs/smbfs_subr.h |   5 +++--
 2 files changed, 42 insertions(+), 5 deletions(-)

diffs (89 lines):

diff -r 1a2c6f5c9d2d -r 8ea7cd1db738 sys/fs/smbfs/smbfs_smb.c
--- a/sys/fs/smbfs/smbfs_smb.c  Tue Oct 20 19:10:09 2009 +0000
+++ b/sys/fs/smbfs/smbfs_smb.c  Tue Oct 20 20:55:01 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: smbfs_smb.c,v 1.40 2009/04/18 14:58:04 tsutsui Exp $   */
+/*     $NetBSD: smbfs_smb.c,v 1.41 2009/10/20 20:55:01 tron Exp $      */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.40 2009/04/18 14:58:04 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.41 2009/10/20 20:55:01 tron Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -265,14 +265,50 @@
        return 0;
 }
 
+static int
+smbfs_smb_seteof(struct smbnode *np, int64_t newsize, struct smb_cred *scred)
+{
+       struct smb_t2rq *t2p;
+       struct smb_share *ssp = np->n_mount->sm_share;
+       struct mbchain *mbp;
+       int error;
+
+       error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_FILE_INFORMATION,
+           scred, &t2p);
+       if (error)
+               return error;
+       mbp = &t2p->t2_tparam;
+       mb_init(mbp);
+       mb_put_mem(mbp, (void *)&np->n_fid, 2, MB_MSYSTEM);
+       mb_put_uint16le(mbp, SMB_SET_FILE_END_OF_FILE_INFO);
+       mb_put_uint32le(mbp, 0);
+       mbp = &t2p->t2_tdata;
+       mb_init(mbp);
+       mb_put_int64le(mbp, newsize);
+       mb_put_uint32le(mbp, 0);                        /* padding */
+       mb_put_uint16le(mbp, 0);
+       t2p->t2_maxpcount = 2;
+       t2p->t2_maxdcount = 0;
+       error = smb_t2_request(t2p);
+       smb_t2_done(t2p);
+       return error;
+}
+
 int
-smbfs_smb_setfsize(struct smbnode *np, int newsize, struct smb_cred *scred)
+smbfs_smb_setfsize(struct smbnode *np, u_quad_t newsize,
+                  struct smb_cred *scred)
 {
        struct smb_share *ssp = np->n_mount->sm_share;
        struct smb_rq *rqp;
        struct mbchain *mbp;
        int error;
 
+       if (newsize >= (1LL << 32)) {
+               if (!(SMB_CAPS(SSTOVC(ssp)) & SMB_CAP_LARGE_FILES))
+                       return EFBIG;
+               return smbfs_smb_seteof(np, (int64_t)newsize, scred);
+       }
+
        error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_WRITE, scred, &rqp);
        if (error)
                return error;
diff -r 1a2c6f5c9d2d -r 8ea7cd1db738 sys/fs/smbfs/smbfs_subr.h
--- a/sys/fs/smbfs/smbfs_subr.h Tue Oct 20 19:10:09 2009 +0000
+++ b/sys/fs/smbfs/smbfs_subr.h Tue Oct 20 20:55:01 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: smbfs_subr.h,v 1.19 2008/06/28 01:34:05 rumble Exp $   */
+/*     $NetBSD: smbfs_subr.h,v 1.20 2009/10/20 20:55:01 tron Exp $     */
 
 /*
  * Copyright (c) 2000-2001, Boris Popov
@@ -135,7 +135,8 @@
        off_t start, off_t end, struct smb_cred *scred);
 int  smbfs_smb_statvfs(struct smb_share *ssp, struct statvfs *sbp,
        struct smb_cred *scred);
-int  smbfs_smb_setfsize(struct smbnode *np, int newsize, struct smb_cred *scred);
+int  smbfs_smb_setfsize(struct smbnode *np, u_quad_t newsize,
+                       struct smb_cred *scred);
 
 int  smbfs_smb_setpattr(struct smbnode *np, u_int16_t attr,
        struct timespec *mtime, struct smb_cred *scred);



Home | Main Index | Thread Index | Old Index