Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

763 lines
26 KiB

  1. /*++
  2. Copyright (c) 1989 - 1999 Microsoft Corporation
  3. Module Name:
  4. read.c
  5. Abstract:
  6. This module implements the mini redirector call down routines pertaining to
  7. read of file system objects.
  8. Notes:
  9. The READ adn WRITE paths in the mini redirector have to contend with a number
  10. of different variations based on the kind of the server and the capabilities
  11. of the server.
  12. Currently there are atleast four variations of the read operation that needs
  13. to be supported.
  14. 1) SMB_COM_READ
  15. This is the read operation of choice against all servers which
  16. support old dialects of the SMB protocol ( < DF_LANMAN10 )
  17. 2) SMB_COM_READ_ANDX
  18. This is the read operation of choice against all servers which
  19. support read extensions in the new dialects of the SMB protocol
  20. However READ_ANDX itself can be further customized based upon the
  21. server capabilities. There are two dimensions in which this
  22. change can occur -- large sized reads being supported.
  23. In addition the SMB protocol supports the following flavours of a READ
  24. operation which are not supported in the redirector
  25. 1) SMB_COM_READ_RAW
  26. This is used to initiate large transfers to a server. However this
  27. ties up the VC exclusively for this operation. The large READ_ANDX
  28. overcomes this by providing for large read operations which can
  29. be multiplexed on the VC.
  30. 2) SMB_COM_READ_MPX,SMB_COM_READ_MPX_SECONDARY,
  31. These operations were designed for a direct host client. The NT
  32. redriector does not use these operations because the recent
  33. changes to NetBt allows us to go directly over a TCP connection.
  34. The implementation of a read operation in the RDR hinges upon two decisions --
  35. selecting the type of command to use and decomposing the original read
  36. operation into a number of smaller read operations while adhering to
  37. protocol/server restrictions.
  38. The exchange engine provides the facility for sending a packet to the server
  39. and picking up the associated response. Based upon the amount of data to be
  40. read a number of such operations need to be initiated.
  41. This module is organized as follows ---
  42. MRxSmbRead --
  43. This represents the top level entry point in the dispatch vector for
  44. read operations associated with this mini redirector.
  45. MRxSmbBuildReadRequest --
  46. This routine is used for formatting the read command to be sent to
  47. the server. We will require a new routine for each new type of read
  48. operation that we would like to support
  49. SmbPseExchangeStart_Read --
  50. This routine is the heart of the read engine. It farms out the
  51. necessary number of read operations and ensures the continuation
  52. of the local operation on completion for both synchronous and
  53. asynchronous reads.
  54. All the state information required for the read operation is captured in an
  55. instance of SMB_PSE_ORDINARY_EXCHANGE. This state information can be split
  56. into two parts - the generic state information and the state information
  57. specific to the read operation. The read operation specific state information
  58. has been encapsulated in SMB_PSE_OE_READWRITE field in the exchange instance.
  59. The read operation begins with the instantiation of an exchange in MRxSmbRead
  60. and is driven through the various stages based upon a state diagram. The
  61. state diagram is encoded in the OpSpecificState field in the ordinary
  62. exchange.
  63. The state diagram associated with the read exchange is as follows
  64. SmbPseOEInnerIoStates_Initial
  65. |
  66. |
  67. |
  68. V
  69. ---->SmbPseOEInnerIoStates_ReadyToSend
  70. | |
  71. | |
  72. | |
  73. | V
  74. ---SmbPseOEInnerIoStates_OperationOutstanding
  75. |
  76. |
  77. |
  78. V
  79. SmbPseOEInnerIoStates_OperationCompleted
  80. --*/
  81. #include "precomp.h"
  82. #pragma hdrstop
  83. #pragma warning(error:4101) // Unreferenced local variable
  84. #ifdef ALLOC_PRAGMA
  85. #pragma alloc_text(PAGE, MRxSmbRead)
  86. #pragma alloc_text(PAGE, MRxSmbBuildReadAndX)
  87. #pragma alloc_text(PAGE, MRxSmbBuildCoreRead)
  88. #pragma alloc_text(PAGE, MRxSmbBuildSmallRead)
  89. #pragma alloc_text(PAGE, SmbPseExchangeStart_Read)
  90. #pragma alloc_text(PAGE, MRxSmbFinishNoCopyRead)
  91. #endif
  92. //
  93. // The local debug trace level
  94. //
  95. #define Dbg (DEBUG_TRACE_READ)
  96. ULONG MRxSmbSrvReadBufSize = 0xffff; //use the negotiated size
  97. ULONG MRxSmbReadSendOptions = 0; //use the default options
  98. NTSTATUS
  99. MRxSmbBuildReadRequest(
  100. PSMB_PSE_ORDINARY_EXCHANGE OrdinaryExchange);
  101. NTSTATUS
  102. MRxSmbRead(
  103. IN PRX_CONTEXT RxContext
  104. )
  105. /*++
  106. Routine Description:
  107. This routine handles network read requests.
  108. Arguments:
  109. RxContext - the RDBSS context
  110. Return Value:
  111. NTSTATUS - The return status for the operation
  112. --*/
  113. {
  114. NTSTATUS Status = STATUS_SUCCESS;
  115. RxCaptureFcb;
  116. RxCaptureFobx;
  117. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  118. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  119. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  120. PMRX_V_NET_ROOT VNetRootToUse = capFobx->pSrvOpen->pVNetRoot;
  121. PSMB_PSE_ORDINARY_EXCHANGE OrdinaryExchange;
  122. PAGED_CODE();
  123. RxDbgTrace(+1, Dbg, ("MRxSmbRead\n", 0 ));
  124. ASSERT( NodeType(capFobx->pSrvOpen) == RDBSS_NTC_SRVOPEN );
  125. do {
  126. Status = __SmbPseCreateOrdinaryExchange(
  127. RxContext,
  128. VNetRootToUse,
  129. SMBPSE_OE_FROM_READ,
  130. SmbPseExchangeStart_Read,
  131. &OrdinaryExchange );
  132. if (Status != STATUS_SUCCESS) {
  133. RxDbgTrace(-1, Dbg, ("Couldn't get the smb buf!\n"));
  134. return Status;
  135. }
  136. OrdinaryExchange->pSmbCeSynchronizationEvent = &RxContext->SyncEvent;
  137. Status = SmbPseInitiateOrdinaryExchange(OrdinaryExchange);
  138. if (Status != STATUS_PENDING) {
  139. BOOLEAN FinalizationComplete;
  140. FinalizationComplete = SmbPseFinalizeOrdinaryExchange(OrdinaryExchange);
  141. ASSERT(FinalizationComplete);
  142. }
  143. if ((Status == STATUS_RETRY) &&
  144. BooleanFlagOn(RxContext->Flags,RX_CONTEXT_FLAG_ASYNC_OPERATION)) {
  145. MRxSmbResumeAsyncReadWriteRequests(RxContext);
  146. Status = STATUS_PENDING;
  147. }
  148. } while (Status == STATUS_RETRY);
  149. RxDbgTrace(-1, Dbg, ("MRxSmbRead exit with status=%08lx\n", Status ));
  150. return(Status);
  151. } // MRxSmbRead
  152. NTSTATUS
  153. SmbPseExchangeStart_Read(
  154. SMBPSE_ORDINARY_EXCHANGE_ARGUMENT_SIGNATURE
  155. )
  156. /*++
  157. Routine Description:
  158. This is the start routine for read.
  159. Arguments:
  160. RxContext - the local context
  161. OrdinaryExchange - the exchange instance
  162. Return Value:
  163. NTSTATUS - The return status for the operation
  164. --*/
  165. {
  166. NTSTATUS Status;
  167. PSMBSTUFFER_BUFFER_STATE StufferState = &OrdinaryExchange->AssociatedStufferState;
  168. ULONG StartEntryCount;
  169. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  170. PSMB_PSE_OE_READWRITE rw = &OrdinaryExchange->ReadWrite;
  171. PSMBCEDB_SERVER_ENTRY pServerEntry = SmbCeGetExchangeServerEntry(OrdinaryExchange);
  172. PSMBCE_SERVER pServer = SmbCeGetExchangeServer(OrdinaryExchange);
  173. PSMBCE_NET_ROOT pNetRoot = SmbCeGetExchangeNetRoot(OrdinaryExchange);
  174. RxCaptureFcb;
  175. RxCaptureFobx;
  176. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  177. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  178. PMRX_SMB_FCB SmbFcb = MRxSmbGetFcbExtension(capFcb);
  179. PSMBCE_SESSION pSession = SmbCeGetExchangeSession(OrdinaryExchange);
  180. BOOLEAN SynchronousIo =
  181. !BooleanFlagOn(RxContext->Flags,RX_CONTEXT_FLAG_ASYNC_OPERATION);
  182. PAGED_CODE();
  183. RxDbgTrace(+1, Dbg, ("SmbPseExchangeStart_Read\n", 0 ));
  184. ASSERT( (OrdinaryExchange->SmbCeFlags&SMBCE_EXCHANGE_ATTEMPT_RECONNECTS) == 0 );
  185. ASSERT(OrdinaryExchange->Type == ORDINARY_EXCHANGE);
  186. OrdinaryExchange->StartEntryCount++;
  187. StartEntryCount = OrdinaryExchange->StartEntryCount;
  188. // Ensure that the Fid is validated
  189. SetFlag(OrdinaryExchange->Flags,SMBPSE_OE_FLAG_VALIDATE_FID);
  190. for (;;) {
  191. switch (OrdinaryExchange->OpSpecificState) {
  192. case SmbPseOEInnerIoStates_Initial:
  193. {
  194. OrdinaryExchange->OpSpecificState = SmbPseOEInnerIoStates_ReadyToSend;
  195. // If not a synchronous read, then continue here when resumed
  196. if (!SynchronousIo) {
  197. OrdinaryExchange->AsyncResumptionRoutine = SmbPseExchangeStart_Read;
  198. }
  199. MRxSmbSetInitialSMB(StufferState STUFFERTRACE(Dbg,'FC'));
  200. rw->UserBufferBase = RxLowIoGetBufferAddress(RxContext);
  201. rw->ByteOffsetAsLI.QuadPart = LowIoContext->ParamsFor.ReadWrite.ByteOffset;
  202. rw->RemainingByteCount = LowIoContext->ParamsFor.ReadWrite.ByteCount;
  203. rw->ThisBufferOffset = 0;
  204. rw->PartialDataMdlInUse = FALSE;
  205. rw->PartialExchangeMdlInUse = FALSE;
  206. rw->UserBufferPortionLength = 0;
  207. rw->ExchangeBufferPortionLength = 0;
  208. }
  209. //lack of break is intentional
  210. case SmbPseOEInnerIoStates_ReadyToSend:
  211. {
  212. OrdinaryExchange->OpSpecificState = SmbPseOEInnerIoStates_OperationOutstanding;
  213. ClearFlag(OrdinaryExchange->OpSpecificFlags,OE_RW_FLAG_SUCCESS_IN_COPYHANDLER);
  214. OrdinaryExchange->SendOptions = MRxSmbReadSendOptions;
  215. Status = MRxSmbBuildReadRequest(
  216. OrdinaryExchange);
  217. if (Status != STATUS_SUCCESS) {
  218. RxDbgTrace(0, Dbg, ("bad read stuffer status........\n"));
  219. goto FINALLY;
  220. }
  221. if (FALSE &&
  222. FlagOn(
  223. LowIoContext->ParamsFor.ReadWrite.Flags,
  224. LOWIO_READWRITEFLAG_PAGING_IO)) {
  225. RxLog(
  226. ("PagingIoRead: rxc/offset/length %lx/%lx/%lx",
  227. RxContext,
  228. &rw->ByteOffsetAsLI,
  229. rw->ThisByteCount
  230. )
  231. );
  232. }
  233. InterlockedIncrement(&MRxSmbStatistics.ReadSmbs);
  234. Status = SmbPseOrdinaryExchange(
  235. SMBPSE_ORDINARY_EXCHANGE_ARGUMENTS,
  236. SMBPSE_OETYPE_READ );
  237. // If the status is PENDING, then we're done for now. We must
  238. // wait until we're re-entered when the receive happens.
  239. if (Status == STATUS_PENDING) {
  240. ASSERT(!SynchronousIo);
  241. goto FINALLY;
  242. }
  243. }
  244. //lack of break is intentional
  245. case SmbPseOEInnerIoStates_OperationOutstanding:
  246. {
  247. OrdinaryExchange->OpSpecificState = SmbPseOEInnerIoStates_ReadyToSend;
  248. OrdinaryExchange->Status = OrdinaryExchange->SmbStatus;
  249. if (rw->BytesReturned > 0) {
  250. if (rw->PartialDataMdlInUse) {
  251. MmPrepareMdlForReuse(
  252. &rw->PartialDataMdl);
  253. rw->PartialDataMdlInUse = FALSE;
  254. }
  255. } else {
  256. if (OrdinaryExchange->Status == STATUS_SUCCESS) {
  257. OrdinaryExchange->Status = STATUS_END_OF_FILE;
  258. }
  259. }
  260. rw->RemainingByteCount -= rw->BytesReturned;
  261. if ((OrdinaryExchange->Status == STATUS_END_OF_FILE) &&
  262. (RxContext->InformationToReturn > 0)) {
  263. OrdinaryExchange->Status = STATUS_SUCCESS;
  264. rw->RemainingByteCount = 0;
  265. }
  266. RxContext->InformationToReturn += rw->BytesReturned;
  267. Status = OrdinaryExchange->Status;
  268. if ((NT_ERROR(Status) &&
  269. Status != STATUS_RETRY) ||
  270. (rw->RemainingByteCount==0) ) {
  271. goto FINALLY;
  272. }
  273. if (capFcb->pNetRoot->Type != NET_ROOT_DISK) {
  274. if (Status != STATUS_BUFFER_OVERFLOW) {
  275. goto FINALLY;
  276. } else {
  277. ASSERT (rw->BytesReturned == rw->ThisByteCount);
  278. }
  279. }
  280. //reset the smbstatus.....
  281. rw->ByteOffsetAsLI.QuadPart += rw->BytesReturned;
  282. rw->ThisBufferOffset += rw->BytesReturned;
  283. rw->BytesReturned = 0;
  284. MRxSmbSetInitialSMB(StufferState STUFFERTRACE(Dbg,'FC'));
  285. break;
  286. }
  287. }
  288. }
  289. FINALLY:
  290. if ( Status != STATUS_PENDING) {
  291. if (Status != STATUS_RETRY) {
  292. SmbPseAsyncCompletionIfNecessary(OrdinaryExchange,RxContext);
  293. }
  294. }
  295. RxDbgTrace(-1, Dbg, ("SmbPseExchangeStart_Read exit w %08lx\n", Status ));
  296. return Status;
  297. } // SmbPseExchangeStart_Read
  298. NTSTATUS
  299. MRxSmbFinishNoCopyRead (
  300. PSMB_PSE_ORDINARY_EXCHANGE OrdinaryExchange
  301. )
  302. {
  303. PAGED_CODE();
  304. return(OrdinaryExchange->NoCopyFinalStatus);
  305. }
  306. UCHAR
  307. MRxSmbReadHandler_NoCopy (
  308. IN OUT PSMB_PSE_ORDINARY_EXCHANGE OrdinaryExchange,
  309. IN ULONG BytesIndicated,
  310. IN ULONG BytesAvailable,
  311. OUT ULONG *pBytesTaken,
  312. IN PSMB_HEADER pSmbHeader,
  313. OUT PMDL *pDataBufferPointer,
  314. OUT PULONG pDataSize,
  315. #if DBG
  316. IN UCHAR ThisIsAReenter,
  317. #endif
  318. IN PRESP_READ_ANDX Response
  319. )
  320. /*++
  321. Routine Description:
  322. This routine causes the bytes from the message to be transferred to the user's
  323. buffer. In order to do this, it takes enough bytes from the indication and
  324. then crafts up an MDL to cause the transport to do the copy.
  325. Arguments:
  326. please refer to smbpse.c...the only place from which this may be called
  327. Return Value:
  328. UCHAR - a value representing the action that OE receive routine will perform.
  329. options are discard (in case of an error),
  330. copy_for_resume (never called after this is all debugged),
  331. and normal
  332. --*/
  333. {
  334. PSMBSTUFFER_BUFFER_STATE StufferState = &OrdinaryExchange->AssociatedStufferState;
  335. PSMB_PSE_OE_READWRITE rw = &OrdinaryExchange->ReadWrite;
  336. PRX_CONTEXT RxContext = OrdinaryExchange->RxContext;
  337. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  338. PMDL OriginalDataMdl = LowIoContext->ParamsFor.ReadWrite.Buffer;
  339. PBYTE UserBuffer,ExchangeBuffer;
  340. ULONG BytesReturned,DataOffset;
  341. ULONG UserBufferLength;
  342. ULONG StartingOffsetInUserBuffer;
  343. UCHAR ContinuationCode;
  344. RxDbgTrace(+1, Dbg, ("MRxSmbFinishReadNoCopy\n"));
  345. SmbPseOEAssertConsistentLinkageFromOE("MRxSmbFinishReadNoCopy:");
  346. UserBufferLength = MmGetMdlByteCount(OriginalDataMdl);
  347. UserBuffer = rw->UserBufferBase + rw->ThisBufferOffset;
  348. ExchangeBuffer = StufferState->BufferBase;
  349. switch (OrdinaryExchange->LastSmbCommand) {
  350. case SMB_COM_READ_ANDX:
  351. {
  352. if (Response->WordCount != 12) {
  353. OrdinaryExchange->Status = STATUS_INVALID_NETWORK_RESPONSE;
  354. ContinuationCode = SMBPSE_NOCOPYACTION_DISCARD;
  355. goto FINALLY;
  356. }
  357. BytesReturned = SmbGetUshort(&Response->DataLength);
  358. DataOffset = SmbGetUshort(&Response->DataOffset);
  359. }
  360. if (DataOffset > sizeof(SMB_HEADER)+sizeof(RESP_READ_ANDX)) {
  361. OrdinaryExchange->Status = STATUS_INVALID_NETWORK_RESPONSE;
  362. ContinuationCode = SMBPSE_NOCOPYACTION_DISCARD;
  363. goto FINALLY;
  364. }
  365. break;
  366. case SMB_COM_READ:
  367. {
  368. PRESP_READ CoreResponse = (PRESP_READ)Response; //recast response for core read
  369. if (Response->WordCount != 5) {
  370. OrdinaryExchange->Status = STATUS_INVALID_NETWORK_RESPONSE;
  371. ContinuationCode = SMBPSE_NOCOPYACTION_DISCARD;
  372. goto FINALLY;
  373. }
  374. BytesReturned = SmbGetUshort(&CoreResponse->DataLength);
  375. DataOffset = sizeof(SMB_HEADER)+FIELD_OFFSET(RESP_READ,Buffer[0]);
  376. }
  377. break;
  378. }
  379. if ( BytesReturned > rw->ThisByteCount ) {
  380. //cut back if we got a bad response
  381. BytesReturned = rw->ThisByteCount;
  382. }
  383. RxDbgTrace(0, Dbg, ("-->ByteCount,Offset,Returned,DOffset,Buffer=%08lx/%08lx/%08lx/%08lx/%08lx\n",
  384. rw->ThisByteCount,
  385. rw->ThisBufferOffset,
  386. BytesReturned,DataOffset,UserBuffer
  387. ));
  388. OrdinaryExchange->ContinuationRoutine = MRxSmbFinishNoCopyRead;
  389. OrdinaryExchange->ReadWrite.BytesReturned = BytesReturned;
  390. // now, move the data to the user's buffer If enough is showing, just copy it in.
  391. StartingOffsetInUserBuffer = rw->ThisBufferOffset;
  392. rw->UserBufferPortionLength = BytesReturned;
  393. rw->ExchangeBufferPortionLength = 0;
  394. if (BytesIndicated >= (DataOffset +
  395. rw->UserBufferPortionLength +
  396. rw->ExchangeBufferPortionLength)) {
  397. RtlCopyMemory(
  398. UserBuffer,
  399. ((PBYTE)pSmbHeader)+DataOffset,
  400. rw->UserBufferPortionLength);
  401. *pBytesTaken = DataOffset +
  402. rw->UserBufferPortionLength +
  403. rw->ExchangeBufferPortionLength;
  404. RxDbgTrace(-1, Dbg, ("MRxSmbFinishReadNoCopy copy fork\n" ));
  405. ContinuationCode = SMBPSE_NOCOPYACTION_NORMALFINISH;
  406. } else {
  407. // otherwise, MDL it in. we use the smbbuf as an Mdl!
  408. if (BytesIndicated < DataOffset) {
  409. OrdinaryExchange->Status = STATUS_INVALID_NETWORK_RESPONSE;
  410. ContinuationCode = SMBPSE_NOCOPYACTION_DISCARD;
  411. goto FINALLY;
  412. }
  413. if (rw->UserBufferPortionLength > 0) {
  414. rw->PartialDataMdlInUse = TRUE;
  415. MmInitializeMdl(
  416. &rw->PartialDataMdl,
  417. 0,
  418. PAGE_SIZE + rw->UserBufferPortionLength);
  419. IoBuildPartialMdl(
  420. OriginalDataMdl,
  421. &rw->PartialDataMdl,
  422. (PCHAR)MmGetMdlVirtualAddress(OriginalDataMdl) + StartingOffsetInUserBuffer,
  423. rw->UserBufferPortionLength);
  424. }
  425. if (rw->ExchangeBufferPortionLength > 0) {
  426. rw->PartialExchangeMdlInUse = TRUE;
  427. MmInitializeMdl(
  428. &rw->PartialExchangeMdl,
  429. 0,
  430. PAGE_SIZE + rw->ExchangeBufferPortionLength);
  431. IoBuildPartialMdl(
  432. StufferState->HeaderMdl,
  433. &rw->PartialExchangeMdl,
  434. MmGetMdlVirtualAddress( StufferState->HeaderMdl ),
  435. rw->ExchangeBufferPortionLength);
  436. }
  437. if (rw->PartialDataMdlInUse) {
  438. if (rw->PartialExchangeMdlInUse) {
  439. rw->PartialDataMdl.Next = &rw->PartialExchangeMdl;
  440. }
  441. *pDataBufferPointer = &rw->PartialDataMdl;
  442. } else {
  443. *pDataBufferPointer = &rw->PartialExchangeMdl;
  444. }
  445. *pDataSize = rw->UserBufferPortionLength +
  446. rw->ExchangeBufferPortionLength;
  447. *pBytesTaken = DataOffset;
  448. RxDbgTrace(-1, Dbg, ("MRxSmbFinishReadNoCopy mdlcopy fork \n" ));
  449. ContinuationCode = SMBPSE_NOCOPYACTION_MDLFINISH;
  450. }
  451. FINALLY:
  452. return ContinuationCode;
  453. }
  454. NTSTATUS
  455. MRxSmbBuildReadRequest(
  456. PSMB_PSE_ORDINARY_EXCHANGE OrdinaryExchange)
  457. /*++
  458. Routine Description:
  459. This routine formats the appropriate type of read request issued to the
  460. server
  461. Arguments:
  462. OrdinaryExchange - the exchange instance encapsulating the information
  463. Return Value:
  464. STATUS_SUCCESS if successful
  465. --*/
  466. {
  467. NTSTATUS Status;
  468. UCHAR SmbCommand;
  469. ULONG SmbCommandSize;
  470. ULONG OffsetLow,OffsetHigh;
  471. PSMB_PSE_OE_READWRITE rw = &OrdinaryExchange->ReadWrite;
  472. PSMBCEDB_SERVER_ENTRY pServerEntry = SmbCeGetExchangeServerEntry(OrdinaryExchange);
  473. PSMBCE_SERVER pServer = SmbCeGetExchangeServer(OrdinaryExchange);
  474. PSMBCE_NET_ROOT pNetRoot = SmbCeGetExchangeNetRoot(OrdinaryExchange);
  475. PMRX_V_NET_ROOT pVNetRoot = SmbCeGetExchangeVNetRoot(OrdinaryExchange);
  476. PRX_CONTEXT RxContext = OrdinaryExchange->RxContext;
  477. PSMBSTUFFER_BUFFER_STATE StufferState = &OrdinaryExchange->AssociatedStufferState;
  478. RxCaptureFcb;
  479. RxCaptureFobx;
  480. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  481. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  482. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  483. rw->ThisByteCount = min(rw->RemainingByteCount,pNetRoot->MaximumReadBufferSize);
  484. OffsetLow = rw->ByteOffsetAsLI.LowPart;
  485. OffsetHigh = rw->ByteOffsetAsLI.HighPart;
  486. if (FlagOn(pServer->DialectFlags,DF_LANMAN10)) {
  487. SmbCommand = SMB_COM_READ_ANDX;
  488. SmbCommandSize = SMB_REQUEST_SIZE(NT_READ_ANDX);
  489. } else {
  490. SmbCommandSize = SMB_REQUEST_SIZE(READ);
  491. SmbCommand = SMB_COM_READ;
  492. }
  493. MRxSmbDumpStufferState(
  494. 1000,
  495. "SMB w/ READ before stuffing",
  496. StufferState);
  497. Status = MRxSmbStartSMBCommand (
  498. StufferState,
  499. SetInitialSMB_Never,
  500. SmbCommand,
  501. SmbCommandSize,
  502. NO_EXTRA_DATA,
  503. NO_SPECIAL_ALIGNMENT,
  504. RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  505. 0,0,0,0 STUFFERTRACE(Dbg,'FC'));
  506. if (Status != STATUS_SUCCESS) {
  507. return Status;
  508. }
  509. switch (SmbCommand) {
  510. case SMB_COM_READ:
  511. {
  512. // below, we just set mincount==maxcount. rdr1 did this.......
  513. MRxSmbStuffSMB (
  514. StufferState,
  515. "0wwdwB!",
  516. // 0 UCHAR WordCount;
  517. smbSrvOpen->Fid, // w _USHORT( Fid );
  518. rw->ThisByteCount, // w _USHORT( Count );
  519. OffsetLow, // d _ULONG( Offset );
  520. rw->RemainingByteCount, // w _USHORT( Remaining );
  521. // B! _USHORT( ByteCount );
  522. SMB_WCT_CHECK(5) 0
  523. // UCHAR Buffer[1];
  524. );
  525. }
  526. break;
  527. case SMB_COM_READ_ANDX:
  528. {
  529. PNT_SMB_HEADER NtSmbHeader = (PNT_SMB_HEADER)(StufferState->BufferBase);
  530. BOOLEAN UseNtVersion;
  531. ULONG Timeout = 0;
  532. UseNtVersion = BooleanFlagOn(pServer->DialectFlags,DF_NT_SMBS);
  533. if (UseNtVersion &&
  534. FlagOn(
  535. LowIoContext->ParamsFor.ReadWrite.Flags,
  536. LOWIO_READWRITEFLAG_PAGING_IO)) {
  537. SmbPutAlignedUshort(
  538. &NtSmbHeader->Flags2,
  539. SmbGetAlignedUshort(&NtSmbHeader->Flags2) | SMB_FLAGS2_PAGING_IO );
  540. }
  541. // below, we just set mincount==maxcount. rdr1 did this.......
  542. MRxSmbStuffSMB (
  543. StufferState,
  544. "XwdwWdw",
  545. // X UCHAR WordCount;
  546. // UCHAR AndXCommand;
  547. // UCHAR AndXReserved;
  548. // _USHORT( AndXOffset );
  549. smbSrvOpen->Fid, // w _USHORT( Fid );
  550. OffsetLow, // d _ULONG( Offset );
  551. rw->ThisByteCount, // w _USHORT( MaxCount );
  552. SMB_OFFSET_CHECK(READ_ANDX,MinCount)
  553. rw->ThisByteCount, // W _USHORT( MinCount );
  554. Timeout, // d _ULONG( Timeout );
  555. rw->RemainingByteCount, // w _USHORT( Remaining );
  556. StufferCondition(UseNtVersion), "D",
  557. SMB_OFFSET_CHECK(NT_READ_ANDX,OffsetHigh)
  558. OffsetHigh, // D NTonly _ULONG( OffsetHigh );
  559. //
  560. STUFFER_CTL_NORMAL, "B!",
  561. // B! _USHORT( ByteCount );
  562. SMB_WCT_CHECK(((UseNtVersion)?12:10)) 0
  563. // UCHAR Buffer[1];
  564. );
  565. }
  566. break;
  567. default:
  568. break;
  569. }
  570. if (Status == STATUS_SUCCESS) {
  571. MRxSmbDumpStufferState(
  572. 700,
  573. "SMB w/ READ after stuffing",
  574. StufferState);
  575. InterlockedIncrement(&MRxSmbStatistics.SmallReadSmbs);
  576. }
  577. return Status;
  578. }
  579.