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.

609 lines
15 KiB

  1. /*++
  2. Copyright (c) 1989 - 1999 Microsoft Corporation
  3. Module Name:
  4. openclos.c
  5. Abstract:
  6. This module implements the mini redirector call down routines pertaining to opening/
  7. closing of file/directories.
  8. --*/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. //
  12. // The debug trace level
  13. //
  14. #define Dbg (DEBUG_TRACE_CREATE)
  15. //
  16. // forwards & pragmas
  17. //
  18. NTSTATUS
  19. NulMRxProcessCreate(
  20. IN PNULMRX_FCB_EXTENSION pFcbExtension,
  21. IN PVOID EaBuffer,
  22. IN ULONG EaLength,
  23. OUT PLONGLONG pEndOfFile,
  24. OUT PLONGLONG pAllocationSize
  25. );
  26. NTSTATUS
  27. NulMRxCreateFileSuccessTail (
  28. PRX_CONTEXT RxContext,
  29. PBOOLEAN MustRegainExclusiveResource,
  30. RX_FILE_TYPE StorageType,
  31. ULONG CreateAction,
  32. FILE_BASIC_INFORMATION* pFileBasicInfo,
  33. FILE_STANDARD_INFORMATION* pFileStandardInfo
  34. );
  35. VOID
  36. NulMRxSetSrvOpenFlags (
  37. PRX_CONTEXT RxContext,
  38. RX_FILE_TYPE StorageType,
  39. PMRX_SRV_OPEN SrvOpen
  40. );
  41. #ifdef ALLOC_PRAGMA
  42. #pragma alloc_text(PAGE, NulMRxCreate)
  43. #pragma alloc_text(PAGE, NulMRxShouldTryToCollapseThisOpen)
  44. #pragma alloc_text(PAGE, NulMRxProcessCreate)
  45. #pragma alloc_text(PAGE, NulMRxCreateFileSuccessTail)
  46. #pragma alloc_text(PAGE, NulMRxSetSrvOpenFlags)
  47. #endif
  48. NTSTATUS
  49. NulMRxShouldTryToCollapseThisOpen (
  50. IN PRX_CONTEXT RxContext
  51. )
  52. /*++
  53. Routine Description:
  54. This routine determines if the mini knows of a good reason not
  55. to try collapsing on this open. Presently, the only reason would
  56. be if this were a copychunk open.
  57. Arguments:
  58. RxContext - the RDBSS context
  59. Return Value:
  60. NTSTATUS - The return status for the operation
  61. SUCCESS --> okay to try collapse
  62. other (MORE_PROCESSING_REQUIRED) --> dont collapse
  63. --*/
  64. {
  65. NTSTATUS Status = STATUS_SUCCESS;
  66. RxCaptureFcb;
  67. PAGED_CODE();
  68. return Status;
  69. }
  70. NTSTATUS
  71. NulMRxCreate(
  72. IN OUT PRX_CONTEXT RxContext
  73. )
  74. /*++
  75. Routine Description:
  76. This routine opens a file across the network
  77. Arguments:
  78. RxContext - the RDBSS context
  79. Return Value:
  80. RXSTATUS - The return status for the operation
  81. --*/
  82. {
  83. NTSTATUS Status = STATUS_SUCCESS;
  84. BOOLEAN fMustRegainExclusiveResource = FALSE;
  85. RX_FILE_TYPE StorageType = FileTypeFile;
  86. ULONG CreateAction = FILE_CREATED;
  87. LARGE_INTEGER liSystemTime;
  88. LONGLONG EndOfFile = 0, AllocationSize = 0;
  89. FILE_BASIC_INFORMATION FileBasicInfo;
  90. FILE_STANDARD_INFORMATION FileStandardInfo;
  91. RxCaptureFcb;
  92. NulMRxGetFcbExtension(capFcb,pFcbExtension);
  93. RX_BLOCK_CONDITION FinalSrvOpenCondition;
  94. PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  95. PMRX_SRV_CALL SrvCall = RxContext->Create.pSrvCall;
  96. PMRX_NET_ROOT NetRoot = capFcb->pNetRoot;
  97. PUNICODE_STRING RemainingName = SrvOpen->pAlreadyPrefixedName;
  98. PVOID EaBuffer = RxContext->Create.EaBuffer;
  99. ULONG EaLength = RxContext->Create.EaLength;
  100. ACCESS_MASK DesiredAccess = RxContext->Create.NtCreateParameters.DesiredAccess;
  101. NulMRxGetNetRootExtension(NetRoot,pNetRootExtension);
  102. RxTraceEnter("NulMRxCreate");
  103. PAGED_CODE();
  104. RxDbgTrace(0, Dbg, (" Attempt to open %wZ Len is %d\n", RemainingName, RemainingName->Length ));
  105. if( NetRoot->Type == NET_ROOT_DISK && NT_SUCCESS(Status) ) {
  106. RxDbgTrace(0, Dbg, ("NulMRxCreate: Type supported \n"));
  107. //
  108. // Squirrel away the scatter list in the FCB extension.
  109. // This is done only for data files.
  110. //
  111. Status = NulMRxProcessCreate(
  112. pFcbExtension,
  113. EaBuffer,
  114. EaLength,
  115. &EndOfFile,
  116. &AllocationSize
  117. );
  118. if( Status != STATUS_SUCCESS ) {
  119. //
  120. // error..
  121. //
  122. RxDbgTrace(0, Dbg, ("Failed to initialize scatter list\n"));
  123. goto Exit;
  124. }
  125. //
  126. // Complete CreateFile contract
  127. //
  128. RxDbgTrace(0,Dbg,("EOF is %d AllocSize is %d\n",(ULONG)EndOfFile,(ULONG)AllocationSize));
  129. FileBasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
  130. KeQuerySystemTime(&liSystemTime);
  131. FileBasicInfo.CreationTime = liSystemTime;
  132. FileBasicInfo.LastAccessTime = liSystemTime;
  133. FileBasicInfo.LastWriteTime = liSystemTime;
  134. FileBasicInfo.ChangeTime = liSystemTime;
  135. FileStandardInfo.AllocationSize.QuadPart = AllocationSize;
  136. FileStandardInfo.EndOfFile.QuadPart = EndOfFile;
  137. FileStandardInfo.NumberOfLinks = 0;
  138. Status = NulMRxCreateFileSuccessTail (
  139. RxContext,
  140. &fMustRegainExclusiveResource,
  141. StorageType,
  142. CreateAction,
  143. &FileBasicInfo,
  144. &FileStandardInfo
  145. );
  146. if( Status != STATUS_SUCCESS ) {
  147. //
  148. // alloc error..
  149. //
  150. RxDbgTrace(0, Dbg, ("Failed to allocate Fobx \n"));
  151. goto Exit;
  152. }
  153. if (!RxIsFcbAcquiredExclusive(capFcb)) {
  154. ASSERT(!RxIsFcbAcquiredShared(capFcb));
  155. RxAcquireExclusiveFcbResourceInMRx( capFcb );
  156. }
  157. } else {
  158. RxDbgTrace(0, Dbg, ("NulMRxCreate: Type not supported or invalid open\n"));
  159. Status = STATUS_NOT_IMPLEMENTED;
  160. }
  161. ASSERT(Status != (STATUS_PENDING));
  162. ASSERT(RxIsFcbAcquiredExclusive( capFcb ));
  163. RxDbgTrace(0, Dbg, ("NetRoot is 0x%x Fcb is 0x%x SrvOpen is 0x%x Fobx is 0x%x\n",
  164. NetRoot,capFcb, SrvOpen,RxContext->pFobx));
  165. RxDbgTrace(0, Dbg, ("NulMRxCreate exit with status=%08lx\n", Status ));
  166. Exit:
  167. RxTraceLeave(Status);
  168. return(Status);
  169. }
  170. NTSTATUS
  171. NulMRxProcessCreate(
  172. IN PNULMRX_FCB_EXTENSION pFcbExtension,
  173. IN PVOID EaBuffer,
  174. IN ULONG EaLength,
  175. OUT PLONGLONG pEndOfFile,
  176. OUT PLONGLONG pAllocationSize
  177. )
  178. /*++
  179. Routine Description:
  180. This routine processes a create calldown.
  181. Arguments:
  182. pFcbExtension - ptr to the FCB extension
  183. EaBuffer - ptr to the EA param buffer
  184. EaLength - len of EaBuffer
  185. pEndOfFile - return end of file value
  186. pAllocationSize - return allocation size (which maybe > EOF)
  187. Notes:
  188. It is possible to create a file with no EAs
  189. Return Value:
  190. None
  191. --*/
  192. {
  193. NTSTATUS Status = STATUS_SUCCESS;
  194. RxDbgTrace(0, Dbg, ("NulMRxInitializeFcbExtension\n"));
  195. *pAllocationSize = *pEndOfFile = 0;
  196. return Status;
  197. }
  198. VOID
  199. NulMRxSetSrvOpenFlags (
  200. PRX_CONTEXT RxContext,
  201. RX_FILE_TYPE StorageType,
  202. PMRX_SRV_OPEN SrvOpen
  203. )
  204. {
  205. PMRX_SRV_CALL SrvCall = (PMRX_SRV_CALL)RxContext->Create.pSrvCall;
  206. //
  207. // set this only if cache manager will be used for mini-rdr handles !
  208. //
  209. SrvOpen->BufferingFlags |= (FCB_STATE_WRITECACHING_ENABLED |
  210. FCB_STATE_FILESIZECACHEING_ENABLED |
  211. FCB_STATE_FILETIMECACHEING_ENABLED |
  212. FCB_STATE_WRITEBUFFERING_ENABLED |
  213. FCB_STATE_LOCK_BUFFERING_ENABLED |
  214. FCB_STATE_READBUFFERING_ENABLED |
  215. FCB_STATE_READCACHING_ENABLED);
  216. }
  217. NTSTATUS
  218. NulMRxCreateFileSuccessTail (
  219. PRX_CONTEXT RxContext,
  220. PBOOLEAN MustRegainExclusiveResource,
  221. RX_FILE_TYPE StorageType,
  222. ULONG CreateAction,
  223. FILE_BASIC_INFORMATION* pFileBasicInfo,
  224. FILE_STANDARD_INFORMATION* pFileStandardInfo
  225. )
  226. /*++
  227. Routine Description:
  228. This routine finishes the initialization of the fcb and srvopen for a
  229. successful open.
  230. Arguments:
  231. Return Value:
  232. RXSTATUS - The return status for the operation
  233. --*/
  234. {
  235. NTSTATUS Status = STATUS_SUCCESS;
  236. RxCaptureFcb;
  237. PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  238. FCB_INIT_PACKET InitPacket;
  239. RxDbgTrace(0, Dbg, ("MRxExCreateFileSuccessTail\n"));
  240. PAGED_CODE();
  241. ASSERT( NodeType(SrvOpen) == RDBSS_NTC_SRVOPEN );
  242. ASSERT( NodeType(RxContext) == RDBSS_NTC_RX_CONTEXT );
  243. if (*MustRegainExclusiveResource) { //this is required because of oplock breaks
  244. RxAcquireExclusiveFcbResourceInMRx( capFcb );
  245. *MustRegainExclusiveResource = FALSE;
  246. }
  247. // This Fobx should be cleaned up by the wrapper
  248. RxContext->pFobx = RxCreateNetFobx( RxContext, SrvOpen);
  249. if( RxContext->pFobx == NULL ) {
  250. return STATUS_INSUFFICIENT_RESOURCES;
  251. }
  252. ASSERT ( RxIsFcbAcquiredExclusive ( capFcb ) );
  253. RxDbgTrace(0, Dbg, ("Storagetype %08lx/Action %08lx\n", StorageType, CreateAction ));
  254. RxContext->Create.ReturnedCreateInformation = CreateAction;
  255. RxFormInitPacket(
  256. InitPacket,
  257. &pFileBasicInfo->FileAttributes,
  258. &pFileStandardInfo->NumberOfLinks,
  259. &pFileBasicInfo->CreationTime,
  260. &pFileBasicInfo->LastAccessTime,
  261. &pFileBasicInfo->LastWriteTime,
  262. &pFileBasicInfo->ChangeTime,
  263. &pFileStandardInfo->AllocationSize,
  264. &pFileStandardInfo->EndOfFile,
  265. &pFileStandardInfo->EndOfFile);
  266. if (capFcb->OpenCount == 0) {
  267. RxFinishFcbInitialization( capFcb,
  268. RDBSS_STORAGE_NTC(StorageType),
  269. &InitPacket
  270. );
  271. } else {
  272. ASSERT( StorageType == 0 || NodeType(capFcb) == RDBSS_STORAGE_NTC(StorageType));
  273. }
  274. NulMRxSetSrvOpenFlags(RxContext,StorageType,SrvOpen);
  275. RxContext->pFobx->OffsetOfNextEaToReturn = 1;
  276. //transition happens later
  277. return Status;
  278. }
  279. NTSTATUS
  280. NulMRxCollapseOpen(
  281. IN OUT PRX_CONTEXT RxContext
  282. )
  283. /*++
  284. Routine Description:
  285. This routine collapses a open locally
  286. Arguments:
  287. RxContext - the RDBSS context
  288. Return Value:
  289. RXSTATUS - The return status for the operation
  290. --*/
  291. {
  292. NTSTATUS Status;
  293. RxCaptureFcb;
  294. RxCaptureRequestPacket;
  295. PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  296. PMRX_SRV_CALL SrvCall = RxContext->Create.pSrvCall;
  297. PMRX_NET_ROOT NetRoot = capFcb->pNetRoot;
  298. RxTraceEnter("NulMRxCollapseOpen");
  299. RxContext->pFobx = (PMRX_FOBX)RxCreateNetFobx( RxContext, SrvOpen);
  300. if (RxContext->pFobx != NULL) {
  301. ASSERT ( RxIsFcbAcquiredExclusive ( capFcb ) );
  302. RxContext->pFobx->OffsetOfNextEaToReturn = 1;
  303. capReqPacket->IoStatus.Information = FILE_OPENED;
  304. Status = STATUS_SUCCESS;
  305. } else {
  306. Status = (STATUS_INSUFFICIENT_RESOURCES);
  307. DbgBreakPoint();
  308. }
  309. RxTraceLeave(Status);
  310. return Status;
  311. }
  312. NTSTATUS
  313. NulMRxComputeNewBufferingState(
  314. IN OUT PMRX_SRV_OPEN pMRxSrvOpen,
  315. IN PVOID pMRxContext,
  316. OUT PULONG pNewBufferingState)
  317. /*++
  318. Routine Description:
  319. This routine maps specific oplock levels into the appropriate RDBSS
  320. buffering state flags
  321. Arguments:
  322. pMRxSrvOpen - the MRX SRV_OPEN extension
  323. pMRxContext - the context passed to RDBSS at Oplock indication time
  324. pNewBufferingState - the place holder for the new buffering state
  325. Return Value:
  326. Notes:
  327. --*/
  328. {
  329. NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
  330. DbgPrint("NulMRxComputeNewBufferingState \n");
  331. return(Status);
  332. }
  333. NTSTATUS
  334. NulMRxDeallocateForFcb (
  335. IN OUT PMRX_FCB pFcb
  336. )
  337. {
  338. NTSTATUS Status = STATUS_SUCCESS;
  339. NulMRxGetFcbExtension(pFcb,pFcbExtension);
  340. PMRX_NET_ROOT pNetRoot = pFcb->pNetRoot;
  341. NulMRxGetNetRootExtension(pNetRoot,pNetRootExtension);
  342. RxTraceEnter("NulMRxDeallocateForFcb\n");
  343. RxTraceLeave(Status);
  344. return(Status);
  345. }
  346. NTSTATUS
  347. NulMRxTruncate(
  348. IN PRX_CONTEXT pRxContext)
  349. /*++
  350. Routine Description:
  351. This routine truncates the contents of a file system object
  352. Arguments:
  353. pRxContext - the RDBSS context
  354. Return Value:
  355. RXSTATUS - The return status for the operation
  356. --*/
  357. {
  358. ASSERT(!"Found a truncate");
  359. return STATUS_NOT_IMPLEMENTED;
  360. }
  361. NTSTATUS
  362. NulMRxCleanupFobx(
  363. IN PRX_CONTEXT RxContext)
  364. /*++
  365. Routine Description:
  366. This routine cleansup a file system object...normally a noop. unless it's a pipe in which case
  367. we do the close at cleanup time and mark the file as being not open.
  368. Arguments:
  369. pRxContext - the RDBSS context
  370. Return Value:
  371. RXSTATUS - The return status for the operation
  372. --*/
  373. {
  374. NTSTATUS Status = STATUS_SUCCESS;
  375. PUNICODE_STRING RemainingName;
  376. RxCaptureFcb; RxCaptureFobx;
  377. NODE_TYPE_CODE TypeOfOpen = NodeType(capFcb);
  378. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  379. BOOLEAN SearchHandleOpen = FALSE;
  380. PAGED_CODE();
  381. ASSERT( NodeType(SrvOpen) == RDBSS_NTC_SRVOPEN );
  382. ASSERT ( NodeTypeIsFcb(capFcb) );
  383. RxDbgTrace( 0, Dbg, ("NulMRxCleanupFobx\n"));
  384. if (FlagOn(capFcb->FcbState,FCB_STATE_ORPHANED)) {
  385. RxDbgTrace( 0, Dbg, ("File orphaned\n"));
  386. return (STATUS_SUCCESS);
  387. }
  388. if ((capFcb->pNetRoot->Type != NET_ROOT_PIPE) && !SearchHandleOpen) {
  389. RxDbgTrace( 0, Dbg, ("File not for closing at cleanup\n"));
  390. return (STATUS_SUCCESS);
  391. }
  392. RxDbgTrace( 0, Dbg, ("NulMRxCleanup exit with status=%08lx\n", Status ));
  393. return(Status);
  394. }
  395. NTSTATUS
  396. NulMRxForcedClose(
  397. IN PMRX_SRV_OPEN pSrvOpen)
  398. /*++
  399. Routine Description:
  400. This routine closes a file system object
  401. Arguments:
  402. pSrvOpen - the instance to be closed
  403. Return Value:
  404. RXSTATUS - The return status for the operation
  405. Notes:
  406. --*/
  407. {
  408. RxDbgTrace( 0, Dbg, ("NulMRxForcedClose\n"));
  409. return STATUS_SUCCESS;
  410. }
  411. //
  412. // The local debug trace level
  413. //
  414. #undef Dbg
  415. #define Dbg (DEBUG_TRACE_CLOSE)
  416. NTSTATUS
  417. NulMRxCloseSrvOpen(
  418. IN PRX_CONTEXT RxContext
  419. )
  420. /*++
  421. Routine Description:
  422. This routine closes a file across the network
  423. Arguments:
  424. RxContext - the RDBSS context
  425. Return Value:
  426. RXSTATUS - The return status for the operation
  427. --*/
  428. {
  429. NTSTATUS Status = STATUS_SUCCESS;
  430. RxCaptureFcb;
  431. RxCaptureFobx;
  432. PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
  433. PUNICODE_STRING RemainingName = pSrvOpen->pAlreadyPrefixedName;
  434. PMRX_SRV_OPEN SrvOpen;
  435. NODE_TYPE_CODE TypeOfOpen = NodeType(capFcb);
  436. PMRX_NET_ROOT pNetRoot = capFcb->pNetRoot;
  437. NulMRxGetNetRootExtension(pNetRoot,pNetRootExtension);
  438. RxDbgTrace( 0, Dbg, ("NulMRxCloseSrvOpen \n"));
  439. SrvOpen = capFobx->pSrvOpen;
  440. return(Status);
  441. }
  442. NTSTATUS
  443. NulMRxDeallocateForFobx (
  444. IN OUT PMRX_FOBX pFobx
  445. )
  446. {
  447. RxDbgTrace( 0, Dbg, ("NulMRxDeallocateForFobx\n"));
  448. return(STATUS_SUCCESS);
  449. }