s3:libsmb: let cli_write_max_bufsize() return the max number of possible bytes
authorStefan Metzmacher <metze@samba.org>
Mon, 12 Sep 2011 00:45:22 +0000 (02:45 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 14 Sep 2011 20:09:36 +0000 (13:09 -0700)
s3:libsmb: let cli_write_max_bufsize() return the max number of possible bytes

We now return what's possible on the wire.

Which is 0x1FFFF - data_offset if CAP_LARGE_WRITEX is given by
the server (without signing) or 0xFFFFFF - data_offset
if CIFS_UNIX_LARGE_READ_CAP is available (without signing/sealing).
Otherwise we return max_xmit - data_offset.

metze

Signed-off-by: Jeremy Allison <jra@samba.org>
source3/libsmb/clireadwrite.c

index d1c58f7c2a2b059873cd062f3b685c2ae365a9bd..fe966ca8dff9042b3c16320019bb5c461aa26e28 100644 (file)
@@ -73,35 +73,42 @@ static size_t cli_write_max_bufsize(struct cli_state *cli,
                                    uint16_t write_mode,
                                    uint8_t wct)
 {
-        if (write_mode == 0 &&
-           !client_is_signing_on(cli) &&
-           !cli_encryption_on(cli) &&
-           (cli->server_posix_capabilities & CIFS_UNIX_LARGE_WRITE_CAP) &&
-           (cli_state_capabilities(cli) & CAP_LARGE_FILES)) {
-               /* Only do massive writes if we can do them direct
-                * with no signing or encrypting - not on a pipe. */
-               return CLI_SAMBA_MAX_POSIX_LARGE_WRITEX_SIZE;
-       }
+       uint32_t min_space;
+       uint32_t data_offset;
+       uint32_t useable_space = 0;
+
+       data_offset = HDR_VWV;
+       data_offset += wct * sizeof(uint16_t);
+       data_offset += sizeof(uint16_t); /* byte count */
+       data_offset += 1; /* pad */
 
-       if (cli->is_samba) {
-               return CLI_SAMBA_MAX_LARGE_WRITEX_SIZE;
+       min_space = cli_state_available_size(cli, data_offset);
+
+       if (cli->server_posix_capabilities & CIFS_UNIX_LARGE_WRITE_CAP) {
+               useable_space = 0xFFFFFF - data_offset;
+       } else if (cli_state_capabilities(cli) & CAP_LARGE_WRITEX) {
+               useable_space = 0x1FFFF - data_offset;
+       } else {
+               return min_space;
        }
 
-       if (((cli_state_capabilities(cli) & CAP_LARGE_WRITEX) == 0)
-           || client_is_signing_on(cli)
-           || strequal(cli->dev, "LPT1:")) {
-               size_t data_offset = smb_size - 4;
-               size_t useable_space;
+       if (write_mode != 0) {
+               return min_space;
+       }
 
-               data_offset += wct * sizeof(uint16_t);
-               data_offset += 1; /* pad */
+       if (client_is_signing_on(cli)) {
+               return min_space;
+       }
 
-               useable_space = cli_state_available_size(cli, data_offset);
+       if (cli_encryption_on(cli)) {
+               return min_space;
+       }
 
-               return useable_space;
+       if (strequal(cli->dev, "LPT1:")) {
+               return min_space;
        }
 
-       return CLI_WINDOWS_MAX_LARGE_WRITEX_SIZE;
+       return useable_space;
 }
 
 struct cli_read_andx_state {