Commit 44df7e69 authored by ROOL's avatar ROOL 🤖
Browse files

Be more efficient with buffers

Take note of, and use, the MaxBufferSize that the server tells us during negotiation rather than a fixed value.
If the server doesn't say, use 1k as the default as before.
Submission from Colin Granville.

Version 2.50. Tagged as 'LanManFS-2_50'
parent ea7965b5
/* (2.49) /* (2.50)
* *
* This file is automatically maintained by srccommit, do not edit manually. * This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1. * Last processed by srccommit version: 1.1.
* *
*/ */
#define Module_MajorVersion_CMHG 2.49 #define Module_MajorVersion_CMHG 2.50
#define Module_MinorVersion_CMHG #define Module_MinorVersion_CMHG
#define Module_Date_CMHG 05 Jul 2015 #define Module_Date_CMHG 12 Jul 2015
#define Module_MajorVersion "2.49" #define Module_MajorVersion "2.50"
#define Module_Version 249 #define Module_Version 250
#define Module_MinorVersion "" #define Module_MinorVersion ""
#define Module_Date "05 Jul 2015" #define Module_Date "12 Jul 2015"
#define Module_ApplicationDate "05-Jul-15" #define Module_ApplicationDate "12-Jul-15"
#define Module_ComponentName "LanManFS" #define Module_ComponentName "LanManFS"
#define Module_ComponentPath "castle/RiscOS/Sources/Networking/Omni/Protocols/LanManFS" #define Module_ComponentPath "castle/RiscOS/Sources/Networking/Omni/Protocols/LanManFS"
#define Module_FullVersion "2.49" #define Module_FullVersion "2.50"
#define Module_HelpVersion "2.49 (05 Jul 2015)" #define Module_HelpVersion "2.50 (12 Jul 2015)"
#define Module_LibraryVersionInfo "2:49" #define Module_LibraryVersionInfo "2:50"
...@@ -104,10 +104,11 @@ ...@@ -104,10 +104,11 @@
/* Tuning parameters */ /* Tuning parameters */
#define FILE_BLOCK_SIZE 1024 #define MAX_RX_BLOCK_SIZE (3*1452) /* Windows clients' default, see [MS-CIFS].pdf note 91 (p709) */
#define RDRAW_BLOCK_SIZE 32768 #define MAX_CORE_TX_BLOCK_SIZE 1024 /* Core dialect doesn't send MaxBufferSize value */
#define WRRAW_BLOCK_SIZE 16384 #define RDRAW_BLOCK_SIZE 32768
#define PRN_BLOCK_SIZE 1024 #define WRRAW_BLOCK_SIZE 16384
#define PRN_BLOCK_SIZE 1024
/* This structure relies on Norcroft C packing the bytes & words /* This structure relies on Norcroft C packing the bytes & words
properly! properly!
...@@ -281,6 +282,7 @@ struct ActiveServer ...@@ -281,6 +282,7 @@ struct ActiveServer
BYTE *blob; BYTE *blob;
char servname[NAME_LIMIT]; /* upper case */ char servname[NAME_LIMIT]; /* upper case */
char username[NAME_LIMIT]; /* case preserved */ char username[NAME_LIMIT]; /* case preserved */
unsigned int maxTxBufferSize; /* maximum SMB message size the server can receive */
}; };
typedef struct ActiveServer *hSERVER; typedef struct ActiveServer *hSERVER;
...@@ -874,7 +876,10 @@ static err_t SMB_Negotiate( hSHARE hS ) ...@@ -874,7 +876,10 @@ static err_t SMB_Negotiate( hSHARE hS )
if ( SMB_RxWords[0] >= DIALECT_LM12X002 ) if ( SMB_RxWords[0] >= DIALECT_LM12X002 )
{ {
if (SMB_RxWords[0] >= DIALECT_NT) { if (SMB_RxWords[0] >= DIALECT_NT) {
unsigned char *buf = ((unsigned char *)SMB_RxWords) + 7;
/* grr - different response format */ /* grr - different response format */
hS->hServer->maxTxBufferSize = (buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24));
hS->hServer->ProtFlags = PROT_RWMULTI + PROT_SETDATETIME + hS->hServer->ProtFlags = PROT_RWMULTI + PROT_SETDATETIME +
(SMB_RxWords[9] & 0x100 ? PROT_READRAW+PROT_WRITERAW : 0 ) + (SMB_RxWords[9] & 0x100 ? PROT_READRAW+PROT_WRITERAW : 0 ) +
(SMB_RxWords[1] & 1 ? PROT_USERLOGON : 0 ) + (SMB_RxWords[1] & 1 ? PROT_USERLOGON : 0 ) +
...@@ -893,6 +898,7 @@ static err_t SMB_Negotiate( hSHARE hS ) ...@@ -893,6 +898,7 @@ static err_t SMB_Negotiate( hSHARE hS )
} }
else { else {
hS->hServer->bloblen = SMB_RxWords[11]; hS->hServer->bloblen = SMB_RxWords[11];
hS->hServer->maxTxBufferSize = SMB_RxWords[2];
hS->hServer->ProtFlags = PROT_RWMULTI + PROT_SETDATETIME + hS->hServer->ProtFlags = PROT_RWMULTI + PROT_SETDATETIME +
(SMB_RxWords[1] & 1 ? PROT_USERLOGON : 0 ) + (SMB_RxWords[1] & 1 ? PROT_USERLOGON : 0 ) +
(SMB_RxWords[1] & 2 ? PROT_ENCRYPT : 0 ) + (SMB_RxWords[1] & 2 ? PROT_ENCRYPT : 0 ) +
...@@ -919,6 +925,7 @@ static err_t SMB_Negotiate( hSHARE hS ) ...@@ -919,6 +925,7 @@ static err_t SMB_Negotiate( hSHARE hS )
} }
else else
{ {
hS->hServer->maxTxBufferSize = MAX_CORE_TX_BLOCK_SIZE;
hS->hServer->ProtFlags = PROT_SETDATETIME; hS->hServer->ProtFlags = PROT_SETDATETIME;
hS->hServer->SMB_flg = 0; hS->hServer->SMB_flg = 0;
#ifdef LONGNAMES #ifdef LONGNAMES
...@@ -941,7 +948,7 @@ static err_t SMB_SessSetup ( hSHARE hS, char *userid, char *passwd ) ...@@ -941,7 +948,7 @@ static err_t SMB_SessSetup ( hSHARE hS, char *userid, char *passwd )
SMB_TxWords[0] = 0x00FF; /* No additional command */ SMB_TxWords[0] = 0x00FF; /* No additional command */
SMB_TxWords[1] = 0; /* Offset to next cmd */ SMB_TxWords[1] = 0; /* Offset to next cmd */
SMB_TxWords[2] = 4096; /* Our buffer size */ SMB_TxWords[2] = MAX_RX_BLOCK_SIZE; /* Maximum SMB message size we can receive */
SMB_TxWords[3] = 0; /* Max pending requests */ SMB_TxWords[3] = 0; /* Max pending requests */
SMB_TxWords[4] = 0; /* First & only VC */ SMB_TxWords[4] = 0; /* First & only VC */
SMB_TxWords[5] = hS->hServer->Sesskey & 0xFFFF; SMB_TxWords[5] = hS->hServer->Sesskey & 0xFFFF;
...@@ -2565,7 +2572,7 @@ err_t SMB_Read ( int FH, uint offset, uint len, BYTE *where, ...@@ -2565,7 +2572,7 @@ err_t SMB_Read ( int FH, uint offset, uint len, BYTE *where,
if ( hS->hServer->ProtFlags & PROT_READRAW ) if ( hS->hServer->ProtFlags & PROT_READRAW )
{ {
while ( len_left > FILE_BLOCK_SIZE ) while ( len_left > MAX_RX_BLOCK_SIZE )
{ {
n_read = SMB_ReadRaw ( hS, fid, offset, len_left, where ); n_read = SMB_ReadRaw ( hS, fid, offset, len_left, where );
if ( n_read == 0 ) /* Didn't work? Find out why */ if ( n_read == 0 ) /* Didn't work? Find out why */
...@@ -2582,7 +2589,7 @@ err_t SMB_Read ( int FH, uint offset, uint len, BYTE *where, ...@@ -2582,7 +2589,7 @@ err_t SMB_Read ( int FH, uint offset, uint len, BYTE *where,
while ( len_left > 0 ) while ( len_left > 0 )
{ {
SMB_TxWords[0] = fid; SMB_TxWords[0] = fid;
SMB_TxWords[1] = min(len_left,FILE_BLOCK_SIZE); SMB_TxWords[1] = min(len_left, MAX_RX_BLOCK_SIZE);
SMB_TxWords[2] = offset & 0xFFFF; SMB_TxWords[2] = offset & 0xFFFF;
SMB_TxWords[3] = (offset >> 16 ); SMB_TxWords[3] = (offset >> 16 );
SMB_TxWords[4] = (len_left); SMB_TxWords[4] = (len_left);
...@@ -2611,7 +2618,7 @@ err_t SMB_Read ( int FH, uint offset, uint len, BYTE *where, ...@@ -2611,7 +2618,7 @@ err_t SMB_Read ( int FH, uint offset, uint len, BYTE *where,
FreeChain(pB_res); FreeChain(pB_res);
if ( n_read < FILE_BLOCK_SIZE ) /* Reached end of file */ if ( n_read < MAX_RX_BLOCK_SIZE ) /* Reached end of file */
break; break;
} }
...@@ -2668,7 +2675,7 @@ err_t SMB_Write ( int FH, uint offset, uint len, BYTE *where, ...@@ -2668,7 +2675,7 @@ err_t SMB_Write ( int FH, uint offset, uint len, BYTE *where,
if ( hS->hServer->ProtFlags & PROT_WRITERAW ) if ( hS->hServer->ProtFlags & PROT_WRITERAW )
{ {
while ( len_left > FILE_BLOCK_SIZE ) while ( len_left > hS->hServer->maxTxBufferSize )
{ {
n_written = min(len_left,WRRAW_BLOCK_SIZE); n_written = min(len_left,WRRAW_BLOCK_SIZE);
res = SMB_WriteRaw ( hS, fid, offset, n_written, where ); res = SMB_WriteRaw ( hS, fid, offset, n_written, where );
...@@ -2683,7 +2690,7 @@ err_t SMB_Write ( int FH, uint offset, uint len, BYTE *where, ...@@ -2683,7 +2690,7 @@ err_t SMB_Write ( int FH, uint offset, uint len, BYTE *where,
while ( len_left > 0 ) while ( len_left > 0 )
{ {
n_written = min(len_left,FILE_BLOCK_SIZE); n_written = min(len_left, hS->hServer->maxTxBufferSize);
SMB_TxWords[0] = fid; SMB_TxWords[0] = fid;
SMB_TxWords[1] = n_written; SMB_TxWords[1] = n_written;
SMB_TxWords[2] = offset & 0xFFFF; SMB_TxWords[2] = offset & 0xFFFF;
...@@ -2706,7 +2713,7 @@ err_t SMB_Write ( int FH, uint offset, uint len, BYTE *where, ...@@ -2706,7 +2713,7 @@ err_t SMB_Write ( int FH, uint offset, uint len, BYTE *where,
where += n_written; where += n_written;
offset += n_written; offset += n_written;
if ( n_written < FILE_BLOCK_SIZE ) /* End of data */ if ( n_written < hS->hServer->maxTxBufferSize ) /* End of data */
break; break;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment