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.

1246 lines
31 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. fastio.c
  5. Abstract:
  6. This module performs the hooks for the fast i/o path.
  7. Author:
  8. Paul McDaniel (paulmcd) 01-Mar-2000
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. //
  13. // Private constants.
  14. //
  15. //
  16. // Private types.
  17. //
  18. //
  19. // Private prototypes.
  20. //
  21. //
  22. // linker commands
  23. //
  24. #ifdef ALLOC_PRAGMA
  25. #pragma alloc_text( PAGE, SrFastIoCheckIfPossible )
  26. #pragma alloc_text( PAGE, SrFastIoRead )
  27. #pragma alloc_text( PAGE, SrFastIoWrite )
  28. #pragma alloc_text( PAGE, SrFastIoQueryBasicInfo )
  29. #pragma alloc_text( PAGE, SrFastIoQueryStandardInfo )
  30. #pragma alloc_text( PAGE, SrFastIoLock )
  31. #pragma alloc_text( PAGE, SrFastIoUnlockSingle )
  32. #pragma alloc_text( PAGE, SrFastIoUnlockAll )
  33. #pragma alloc_text( PAGE, SrFastIoUnlockAllByKey )
  34. #pragma alloc_text( PAGE, SrFastIoDeviceControl )
  35. #pragma alloc_text( PAGE, SrPreAcquireForSectionSynchronization )
  36. #pragma alloc_text( PAGE, SrFastIoDetachDevice )
  37. #pragma alloc_text( PAGE, SrFastIoQueryNetworkOpenInfo )
  38. #pragma alloc_text( PAGE, SrFastIoMdlRead )
  39. #pragma alloc_text( PAGE, SrFastIoMdlReadComplete )
  40. #pragma alloc_text( PAGE, SrFastIoPrepareMdlWrite )
  41. #pragma alloc_text( PAGE, SrFastIoMdlWriteComplete )
  42. #pragma alloc_text( PAGE, SrFastIoReadCompressed )
  43. #pragma alloc_text( PAGE, SrFastIoWriteCompressed )
  44. #pragma alloc_text( PAGE, SrFastIoMdlReadCompleteCompressed )
  45. #pragma alloc_text( PAGE, SrFastIoMdlWriteCompleteCompressed )
  46. #pragma alloc_text( PAGE, SrFastIoQueryOpen )
  47. #endif // ALLOC_PRAGMA
  48. //
  49. // Private globals.
  50. //
  51. //
  52. // Public globals.
  53. //
  54. //
  55. // Public functions.
  56. //
  57. //
  58. // Define fast I/O procedure prototypes.
  59. //
  60. // Fast I/O read and write procedures.
  61. //
  62. BOOLEAN
  63. SrFastIoCheckIfPossible (
  64. IN struct _FILE_OBJECT *FileObject,
  65. IN PLARGE_INTEGER FileOffset,
  66. IN ULONG Length,
  67. IN BOOLEAN Wait,
  68. IN ULONG LockKey,
  69. IN BOOLEAN CheckForReadOperation,
  70. OUT PIO_STATUS_BLOCK IoStatus,
  71. IN struct _DEVICE_OBJECT *DeviceObject
  72. )
  73. {
  74. PSR_DEVICE_EXTENSION pExtension;
  75. PFAST_IO_DISPATCH pFastIoDispatch;
  76. //
  77. // < dispatch!
  78. //
  79. PAGED_CODE();
  80. //
  81. // Handle calls to Control Device Object
  82. //
  83. if (DeviceObject->DeviceExtension)
  84. {
  85. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  86. pExtension = DeviceObject->DeviceExtension;
  87. //
  88. // call the next device
  89. //
  90. pFastIoDispatch = pExtension->pTargetDevice->
  91. DriverObject->FastIoDispatch;
  92. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoCheckIfPossible))
  93. {
  94. return pFastIoDispatch->FastIoCheckIfPossible(
  95. FileObject,
  96. FileOffset,
  97. Length,
  98. Wait,
  99. LockKey,
  100. CheckForReadOperation,
  101. IoStatus,
  102. pExtension->pTargetDevice );
  103. }
  104. }
  105. return FALSE;
  106. }
  107. BOOLEAN
  108. SrFastIoRead (
  109. IN struct _FILE_OBJECT *FileObject,
  110. IN PLARGE_INTEGER FileOffset,
  111. IN ULONG Length,
  112. IN BOOLEAN Wait,
  113. IN ULONG LockKey,
  114. OUT PVOID Buffer,
  115. OUT PIO_STATUS_BLOCK IoStatus,
  116. IN struct _DEVICE_OBJECT *DeviceObject
  117. )
  118. {
  119. PSR_DEVICE_EXTENSION pExtension;
  120. PFAST_IO_DISPATCH pFastIoDispatch;
  121. //
  122. // < dispatch!
  123. //
  124. PAGED_CODE();
  125. if (DeviceObject->DeviceExtension)
  126. {
  127. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  128. pExtension = DeviceObject->DeviceExtension;
  129. //
  130. // call the next device
  131. //
  132. pFastIoDispatch = pExtension->pTargetDevice->
  133. DriverObject->FastIoDispatch;
  134. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoRead))
  135. {
  136. return pFastIoDispatch->FastIoRead(
  137. FileObject,
  138. FileOffset,
  139. Length,
  140. Wait,
  141. LockKey,
  142. Buffer,
  143. IoStatus,
  144. pExtension->pTargetDevice );
  145. }
  146. }
  147. return FALSE;
  148. }
  149. BOOLEAN
  150. SrFastIoWrite (
  151. IN struct _FILE_OBJECT *pFileObject,
  152. IN PLARGE_INTEGER FileOffset,
  153. IN ULONG Length,
  154. IN BOOLEAN Wait,
  155. IN ULONG LockKey,
  156. IN PVOID Buffer,
  157. OUT PIO_STATUS_BLOCK IoStatus,
  158. IN struct _DEVICE_OBJECT *DeviceObject
  159. )
  160. {
  161. NTSTATUS eventStatus;
  162. PSR_DEVICE_EXTENSION pExtension;
  163. PFAST_IO_DISPATCH pFastIoDispatch;
  164. //
  165. // < dispatch!
  166. //
  167. PAGED_CODE();
  168. if (DeviceObject->DeviceExtension)
  169. {
  170. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  171. pExtension = DeviceObject->DeviceExtension;
  172. //
  173. // See if logging is enabled
  174. //
  175. if (!SR_LOGGING_ENABLED(pExtension) ||
  176. SR_IS_FS_CONTROL_DEVICE(pExtension))
  177. {
  178. goto CallNextDevice;
  179. }
  180. //
  181. // does this file have a name? skip unnamed files
  182. //
  183. if (FILE_OBJECT_IS_NOT_POTENTIALLY_INTERESTING( pFileObject ))
  184. {
  185. goto CallNextDevice;
  186. }
  187. ASSERT(pFileObject->Vpb != NULL);
  188. //
  189. // is this file already closed? it can be the cache manager calling
  190. // us to do work. we ignore the cache managers work as we monitored
  191. // everything that happned prior to him seeing it.
  192. //
  193. if (FlagOn(pFileObject->Flags, FO_CLEANUP_COMPLETE))
  194. {
  195. goto CallNextDevice;
  196. }
  197. //
  198. // Fire a notification , SrNotify will check for eligibility
  199. //
  200. eventStatus = SrHandleEvent( pExtension,
  201. SrEventStreamChange,
  202. pFileObject,
  203. NULL,
  204. NULL,
  205. NULL );
  206. CHECK_STATUS(eventStatus);
  207. //
  208. // call the next device
  209. //
  210. CallNextDevice:
  211. pFastIoDispatch = pExtension->pTargetDevice->
  212. DriverObject->FastIoDispatch;
  213. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoWrite))
  214. {
  215. return pFastIoDispatch->FastIoWrite( pFileObject,
  216. FileOffset,
  217. Length,
  218. Wait,
  219. LockKey,
  220. Buffer,
  221. IoStatus,
  222. pExtension->pTargetDevice );
  223. }
  224. }
  225. return FALSE;
  226. }
  227. //
  228. // Fast I/O query basic and standard information procedures.
  229. //
  230. BOOLEAN
  231. SrFastIoQueryBasicInfo (
  232. IN struct _FILE_OBJECT *FileObject,
  233. IN BOOLEAN Wait,
  234. OUT PFILE_BASIC_INFORMATION Buffer,
  235. OUT PIO_STATUS_BLOCK IoStatus,
  236. IN struct _DEVICE_OBJECT *DeviceObject
  237. )
  238. {
  239. PSR_DEVICE_EXTENSION pExtension;
  240. PFAST_IO_DISPATCH pFastIoDispatch;
  241. //
  242. // < dispatch!
  243. //
  244. PAGED_CODE();
  245. if (DeviceObject->DeviceExtension)
  246. {
  247. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  248. pExtension = DeviceObject->DeviceExtension;
  249. //
  250. // call the next device
  251. //
  252. pFastIoDispatch = pExtension->pTargetDevice->
  253. DriverObject->FastIoDispatch;
  254. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoQueryBasicInfo))
  255. {
  256. return pFastIoDispatch->FastIoQueryBasicInfo(
  257. FileObject,
  258. Wait,
  259. Buffer,
  260. IoStatus,
  261. pExtension->pTargetDevice );
  262. }
  263. }
  264. return FALSE;
  265. }
  266. BOOLEAN
  267. SrFastIoQueryStandardInfo (
  268. IN struct _FILE_OBJECT *FileObject,
  269. IN BOOLEAN Wait,
  270. OUT PFILE_STANDARD_INFORMATION Buffer,
  271. OUT PIO_STATUS_BLOCK IoStatus,
  272. IN struct _DEVICE_OBJECT *DeviceObject
  273. )
  274. {
  275. PSR_DEVICE_EXTENSION pExtension;
  276. PFAST_IO_DISPATCH pFastIoDispatch;
  277. //
  278. // < dispatch!
  279. //
  280. PAGED_CODE();
  281. if (DeviceObject->DeviceExtension)
  282. {
  283. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  284. pExtension = DeviceObject->DeviceExtension;
  285. //
  286. // call the next device
  287. //
  288. pFastIoDispatch = pExtension->pTargetDevice->
  289. DriverObject->FastIoDispatch;
  290. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoQueryStandardInfo))
  291. {
  292. return pFastIoDispatch->FastIoQueryStandardInfo(
  293. FileObject,
  294. Wait,
  295. Buffer,
  296. IoStatus,
  297. pExtension->pTargetDevice );
  298. }
  299. }
  300. return FALSE;
  301. }
  302. //
  303. // Fast I/O lock and unlock procedures.
  304. //
  305. BOOLEAN
  306. SrFastIoLock (
  307. IN struct _FILE_OBJECT *FileObject,
  308. IN PLARGE_INTEGER FileOffset,
  309. IN PLARGE_INTEGER Length,
  310. PEPROCESS ProcessId,
  311. ULONG Key,
  312. BOOLEAN FailImmediately,
  313. BOOLEAN ExclusiveLock,
  314. OUT PIO_STATUS_BLOCK IoStatus,
  315. IN struct _DEVICE_OBJECT *DeviceObject
  316. )
  317. {
  318. PSR_DEVICE_EXTENSION pExtension;
  319. PFAST_IO_DISPATCH pFastIoDispatch;
  320. //
  321. // < dispatch!
  322. //
  323. PAGED_CODE();
  324. if (DeviceObject->DeviceExtension)
  325. {
  326. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  327. pExtension = DeviceObject->DeviceExtension;
  328. //
  329. // call the next device
  330. //
  331. pFastIoDispatch = pExtension->pTargetDevice->
  332. DriverObject->FastIoDispatch;
  333. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoLock))
  334. {
  335. return pFastIoDispatch->FastIoLock(
  336. FileObject,
  337. FileOffset,
  338. Length,
  339. ProcessId,
  340. Key,
  341. FailImmediately,
  342. ExclusiveLock,
  343. IoStatus,
  344. pExtension->pTargetDevice );
  345. }
  346. }
  347. return FALSE;
  348. }
  349. BOOLEAN
  350. SrFastIoUnlockSingle (
  351. IN struct _FILE_OBJECT *FileObject,
  352. IN PLARGE_INTEGER FileOffset,
  353. IN PLARGE_INTEGER Length,
  354. PEPROCESS ProcessId,
  355. ULONG Key,
  356. OUT PIO_STATUS_BLOCK IoStatus,
  357. IN struct _DEVICE_OBJECT *DeviceObject
  358. )
  359. {
  360. PSR_DEVICE_EXTENSION pExtension;
  361. PFAST_IO_DISPATCH pFastIoDispatch;
  362. //
  363. // < dispatch!
  364. //
  365. PAGED_CODE();
  366. if (DeviceObject->DeviceExtension)
  367. {
  368. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  369. pExtension = DeviceObject->DeviceExtension;
  370. //
  371. // call the next device
  372. //
  373. pFastIoDispatch = pExtension->pTargetDevice->
  374. DriverObject->FastIoDispatch;
  375. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoUnlockSingle))
  376. {
  377. return pFastIoDispatch->FastIoUnlockSingle(
  378. FileObject,
  379. FileOffset,
  380. Length,
  381. ProcessId,
  382. Key,
  383. IoStatus,
  384. pExtension->pTargetDevice );
  385. }
  386. }
  387. return FALSE;
  388. }
  389. BOOLEAN
  390. SrFastIoUnlockAll (
  391. IN struct _FILE_OBJECT *FileObject,
  392. PEPROCESS ProcessId,
  393. OUT PIO_STATUS_BLOCK IoStatus,
  394. IN struct _DEVICE_OBJECT *DeviceObject
  395. )
  396. {
  397. PSR_DEVICE_EXTENSION pExtension;
  398. PFAST_IO_DISPATCH pFastIoDispatch;
  399. //
  400. // < dispatch!
  401. //
  402. PAGED_CODE();
  403. if (DeviceObject->DeviceExtension)
  404. {
  405. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  406. pExtension = DeviceObject->DeviceExtension;
  407. //
  408. // call the next device
  409. //
  410. pFastIoDispatch = pExtension->pTargetDevice->
  411. DriverObject->FastIoDispatch;
  412. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoUnlockAll))
  413. {
  414. return pFastIoDispatch->FastIoUnlockAll(
  415. FileObject,
  416. ProcessId,
  417. IoStatus,
  418. pExtension->pTargetDevice );
  419. }
  420. }
  421. return FALSE;
  422. }
  423. BOOLEAN
  424. SrFastIoUnlockAllByKey (
  425. IN struct _FILE_OBJECT *FileObject,
  426. PVOID ProcessId,
  427. ULONG Key,
  428. OUT PIO_STATUS_BLOCK IoStatus,
  429. IN struct _DEVICE_OBJECT *DeviceObject
  430. )
  431. {
  432. PSR_DEVICE_EXTENSION pExtension;
  433. PFAST_IO_DISPATCH pFastIoDispatch;
  434. //
  435. // < dispatch!
  436. //
  437. PAGED_CODE();
  438. if (DeviceObject->DeviceExtension)
  439. {
  440. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  441. pExtension = DeviceObject->DeviceExtension;
  442. //
  443. // call the next device
  444. //
  445. pFastIoDispatch = pExtension->pTargetDevice->
  446. DriverObject->FastIoDispatch;
  447. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoUnlockAllByKey))
  448. {
  449. return pFastIoDispatch->FastIoUnlockAllByKey(
  450. FileObject,
  451. ProcessId,
  452. Key,
  453. IoStatus,
  454. pExtension->pTargetDevice );
  455. }
  456. }
  457. return FALSE;
  458. }
  459. //
  460. // Fast I/O device control procedure.
  461. //
  462. BOOLEAN
  463. SrFastIoDeviceControl (
  464. IN struct _FILE_OBJECT *FileObject,
  465. IN BOOLEAN Wait,
  466. IN PVOID InputBuffer OPTIONAL,
  467. IN ULONG InputBufferLength,
  468. OUT PVOID OutputBuffer OPTIONAL,
  469. IN ULONG OutputBufferLength,
  470. IN ULONG IoControlCode,
  471. OUT PIO_STATUS_BLOCK IoStatus,
  472. IN struct _DEVICE_OBJECT *DeviceObject
  473. )
  474. {
  475. PSR_DEVICE_EXTENSION pExtension;
  476. PFAST_IO_DISPATCH pFastIoDispatch;
  477. //
  478. // < dispatch!
  479. //
  480. PAGED_CODE();
  481. if (DeviceObject->DeviceExtension)
  482. {
  483. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  484. pExtension = DeviceObject->DeviceExtension;
  485. //
  486. // call the next device
  487. //
  488. pFastIoDispatch = pExtension->pTargetDevice->
  489. DriverObject->FastIoDispatch;
  490. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoDeviceControl))
  491. {
  492. return pFastIoDispatch->FastIoDeviceControl(
  493. FileObject,
  494. Wait,
  495. InputBuffer,
  496. InputBufferLength,
  497. OutputBuffer,
  498. OutputBufferLength,
  499. IoControlCode,
  500. IoStatus,
  501. pExtension->pTargetDevice );
  502. }
  503. }
  504. return FALSE;
  505. }
  506. //
  507. // Define callbacks for NtCreateSection to copy the file if a write section
  508. // is being created on this file.
  509. //
  510. NTSTATUS
  511. SrPreAcquireForSectionSynchronization(
  512. IN PFS_FILTER_CALLBACK_DATA Data,
  513. OUT PVOID *CompletionContext
  514. )
  515. {
  516. NTSTATUS eventStatus;
  517. PFILE_OBJECT pFileObject;
  518. PSR_DEVICE_EXTENSION pExtension;
  519. UNREFERENCED_PARAMETER( CompletionContext );
  520. ASSERT(Data->Operation == FS_FILTER_ACQUIRE_FOR_SECTION_SYNCHRONIZATION);
  521. ASSERT(CompletionContext == NULL);
  522. ASSERT(IS_SR_DEVICE_OBJECT(Data->DeviceObject));
  523. PAGED_CODE();
  524. //
  525. // get the file object and device object
  526. //
  527. pExtension = Data->DeviceObject->DeviceExtension;
  528. ASSERT(IS_VALID_SR_DEVICE_EXTENSION(pExtension));
  529. //
  530. // See if logging is enabled
  531. //
  532. if (!SR_LOGGING_ENABLED(pExtension) ||
  533. SR_IS_FS_CONTROL_DEVICE(pExtension))
  534. {
  535. return STATUS_SUCCESS;
  536. }
  537. pFileObject = Data->FileObject;
  538. ASSERT(IS_VALID_FILE_OBJECT(pFileObject));
  539. //
  540. // If they don't have write access to the section or the file don't worry
  541. // about it.
  542. //
  543. // Is this file already closed? it can be the cache manager calling
  544. // us to do work. we ignore the cache managers work as we monitored
  545. // everything that happned prior to him seeing it.
  546. //
  547. if (!FlagOn(Data->Parameters.AcquireForSectionSynchronization.PageProtection,
  548. (PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)) ||
  549. !pFileObject->WriteAccess ||
  550. FlagOn(pFileObject->Flags, FO_CLEANUP_COMPLETE))
  551. {
  552. return STATUS_SUCCESS;
  553. }
  554. //
  555. // does this file have a name? skip unnamed files
  556. //
  557. if (FILE_OBJECT_IS_NOT_POTENTIALLY_INTERESTING( pFileObject ))
  558. {
  559. return STATUS_SUCCESS;
  560. }
  561. ASSERT(pFileObject->Vpb != NULL);
  562. //
  563. // yep, fire a notification as if a write just happened.
  564. // otherwise he can write to the section and we don't see the write
  565. //
  566. eventStatus = SrHandleEvent( pExtension,
  567. SrEventStreamChange,
  568. pFileObject,
  569. NULL,
  570. NULL,
  571. NULL );
  572. CHECK_STATUS(eventStatus);
  573. //
  574. // we never want to fail the acquire, we are just a silent monitor.
  575. //
  576. return STATUS_SUCCESS;
  577. } // SrPreAcquireForCreateSection
  578. //
  579. // Define callback for drivers that have device objects attached to lower-
  580. // level drivers' device objects. This callback is made when the lower-level
  581. // driver is deleting its device object.
  582. //
  583. VOID
  584. SrFastIoDetachDevice (
  585. IN struct _DEVICE_OBJECT *AttachedDevice,
  586. IN struct _DEVICE_OBJECT *DeviceDeleted
  587. )
  588. {
  589. PSR_DEVICE_EXTENSION pExtension;
  590. UNREFERENCED_PARAMETER( DeviceDeleted );
  591. //
  592. // < dispatch!
  593. //
  594. PAGED_CODE();
  595. ASSERT(IS_SR_DEVICE_OBJECT(AttachedDevice));
  596. pExtension = AttachedDevice->DeviceExtension;
  597. SrTrace(NOTIFY, ("SR!SrFastIoDetachDevice: detaching from %p(%wZ)\n",
  598. DeviceDeleted,
  599. pExtension->pNtVolumeName ));
  600. //
  601. // Detach ourselves from the device.
  602. //
  603. ASSERT(pExtension->pTargetDevice == DeviceDeleted);
  604. SrDetachDevice(AttachedDevice, TRUE);
  605. SrDeleteAttachmentDevice(AttachedDevice);
  606. NULLPTR(AttachedDevice);
  607. } // SrFastIoDetachDevice
  608. //
  609. // This structure is used by the server to quickly get the information needed
  610. // to service a server open call. It is takes what would be two fast io calls
  611. // one for basic information and the other for standard information and makes
  612. // it into one call.
  613. //
  614. BOOLEAN
  615. SrFastIoQueryNetworkOpenInfo (
  616. IN struct _FILE_OBJECT *FileObject,
  617. IN BOOLEAN Wait,
  618. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  619. OUT struct _IO_STATUS_BLOCK *IoStatus,
  620. IN struct _DEVICE_OBJECT *DeviceObject
  621. )
  622. {
  623. PSR_DEVICE_EXTENSION pExtension;
  624. PFAST_IO_DISPATCH pFastIoDispatch;
  625. //
  626. // < dispatch!
  627. //
  628. PAGED_CODE();
  629. if (DeviceObject->DeviceExtension)
  630. {
  631. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  632. pExtension = DeviceObject->DeviceExtension;
  633. //
  634. // call the next device
  635. //
  636. pFastIoDispatch = pExtension->pTargetDevice->
  637. DriverObject->FastIoDispatch;
  638. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoQueryNetworkOpenInfo))
  639. {
  640. return pFastIoDispatch->FastIoQueryNetworkOpenInfo(
  641. FileObject,
  642. Wait,
  643. Buffer,
  644. IoStatus,
  645. pExtension->pTargetDevice );
  646. }
  647. }
  648. return FALSE;
  649. }
  650. //
  651. // Define Mdl-based routines for the server to call
  652. //
  653. BOOLEAN
  654. SrFastIoMdlRead (
  655. IN struct _FILE_OBJECT *FileObject,
  656. IN PLARGE_INTEGER FileOffset,
  657. IN ULONG Length,
  658. IN ULONG LockKey,
  659. OUT PMDL *MdlChain,
  660. OUT PIO_STATUS_BLOCK IoStatus,
  661. IN struct _DEVICE_OBJECT *DeviceObject
  662. )
  663. {
  664. PSR_DEVICE_EXTENSION pExtension;
  665. PFAST_IO_DISPATCH pFastIoDispatch;
  666. //
  667. // < dispatch!
  668. //
  669. PAGED_CODE();
  670. if (DeviceObject->DeviceExtension)
  671. {
  672. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  673. pExtension = DeviceObject->DeviceExtension;
  674. //
  675. // call the next device
  676. //
  677. pFastIoDispatch = pExtension->pTargetDevice->
  678. DriverObject->FastIoDispatch;
  679. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, MdlRead))
  680. {
  681. return pFastIoDispatch->MdlRead(
  682. FileObject,
  683. FileOffset,
  684. Length,
  685. LockKey,
  686. MdlChain,
  687. IoStatus,
  688. pExtension->pTargetDevice );
  689. }
  690. }
  691. return FALSE;
  692. }
  693. BOOLEAN
  694. SrFastIoMdlReadComplete (
  695. IN struct _FILE_OBJECT *FileObject,
  696. IN PMDL MdlChain,
  697. IN struct _DEVICE_OBJECT *DeviceObject
  698. )
  699. {
  700. PSR_DEVICE_EXTENSION pExtension;
  701. PFAST_IO_DISPATCH pFastIoDispatch;
  702. //
  703. // < dispatch!
  704. //
  705. PAGED_CODE();
  706. if (DeviceObject->DeviceExtension)
  707. {
  708. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  709. pExtension = DeviceObject->DeviceExtension;
  710. //
  711. // call the next device
  712. //
  713. pFastIoDispatch = pExtension->pTargetDevice->
  714. DriverObject->FastIoDispatch;
  715. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, MdlReadComplete))
  716. {
  717. return pFastIoDispatch->MdlReadComplete(
  718. FileObject,
  719. MdlChain,
  720. pExtension->pTargetDevice );
  721. }
  722. }
  723. return FALSE;
  724. }
  725. BOOLEAN
  726. SrFastIoPrepareMdlWrite (
  727. IN struct _FILE_OBJECT *FileObject,
  728. IN PLARGE_INTEGER FileOffset,
  729. IN ULONG Length,
  730. IN ULONG LockKey,
  731. OUT PMDL *MdlChain,
  732. OUT PIO_STATUS_BLOCK IoStatus,
  733. IN struct _DEVICE_OBJECT *DeviceObject
  734. )
  735. {
  736. PSR_DEVICE_EXTENSION pExtension;
  737. PFAST_IO_DISPATCH pFastIoDispatch;
  738. //
  739. // < dispatch!
  740. //
  741. PAGED_CODE();
  742. if (DeviceObject->DeviceExtension)
  743. {
  744. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  745. pExtension = DeviceObject->DeviceExtension;
  746. //
  747. // call the next device
  748. //
  749. pFastIoDispatch = pExtension->pTargetDevice->
  750. DriverObject->FastIoDispatch;
  751. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, PrepareMdlWrite))
  752. {
  753. return pFastIoDispatch->PrepareMdlWrite(
  754. FileObject,
  755. FileOffset,
  756. Length,
  757. LockKey,
  758. MdlChain,
  759. IoStatus,
  760. pExtension->pTargetDevice);
  761. }
  762. }
  763. return FALSE;
  764. }
  765. BOOLEAN
  766. SrFastIoMdlWriteComplete (
  767. IN struct _FILE_OBJECT *FileObject,
  768. IN PLARGE_INTEGER FileOffset,
  769. IN PMDL MdlChain,
  770. IN struct _DEVICE_OBJECT *DeviceObject
  771. )
  772. {
  773. PSR_DEVICE_EXTENSION pExtension;
  774. PFAST_IO_DISPATCH pFastIoDispatch;
  775. //
  776. // < dispatch!
  777. //
  778. PAGED_CODE();
  779. if (DeviceObject->DeviceExtension)
  780. {
  781. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  782. pExtension = DeviceObject->DeviceExtension;
  783. //
  784. // call the next device
  785. //
  786. pFastIoDispatch = pExtension->pTargetDevice->
  787. DriverObject->FastIoDispatch;
  788. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, MdlWriteComplete))
  789. {
  790. return pFastIoDispatch->MdlWriteComplete(
  791. FileObject,
  792. FileOffset,
  793. MdlChain,
  794. pExtension->pTargetDevice );
  795. }
  796. }
  797. return FALSE;
  798. }
  799. BOOLEAN
  800. SrFastIoReadCompressed (
  801. IN struct _FILE_OBJECT *FileObject,
  802. IN PLARGE_INTEGER FileOffset,
  803. IN ULONG Length,
  804. IN ULONG LockKey,
  805. OUT PVOID Buffer,
  806. OUT PMDL *MdlChain,
  807. OUT PIO_STATUS_BLOCK IoStatus,
  808. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  809. IN ULONG CompressedDataInfoLength,
  810. IN struct _DEVICE_OBJECT *DeviceObject
  811. )
  812. {
  813. PSR_DEVICE_EXTENSION pExtension;
  814. PFAST_IO_DISPATCH pFastIoDispatch;
  815. //
  816. // < dispatch!
  817. //
  818. PAGED_CODE();
  819. if (DeviceObject->DeviceExtension)
  820. {
  821. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  822. pExtension = DeviceObject->DeviceExtension;
  823. //
  824. // call the next device
  825. //
  826. pFastIoDispatch = pExtension->pTargetDevice->
  827. DriverObject->FastIoDispatch;
  828. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoReadCompressed))
  829. {
  830. return pFastIoDispatch->FastIoReadCompressed(
  831. FileObject,
  832. FileOffset,
  833. Length,
  834. LockKey,
  835. Buffer,
  836. MdlChain,
  837. IoStatus,
  838. CompressedDataInfo,
  839. CompressedDataInfoLength,
  840. pExtension->pTargetDevice );
  841. }
  842. }
  843. return FALSE;
  844. }
  845. BOOLEAN
  846. SrFastIoWriteCompressed (
  847. IN struct _FILE_OBJECT *FileObject,
  848. IN PLARGE_INTEGER FileOffset,
  849. IN ULONG Length,
  850. IN ULONG LockKey,
  851. IN PVOID Buffer,
  852. OUT PMDL *MdlChain,
  853. OUT PIO_STATUS_BLOCK IoStatus,
  854. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  855. IN ULONG CompressedDataInfoLength,
  856. IN struct _DEVICE_OBJECT *DeviceObject
  857. )
  858. {
  859. PSR_DEVICE_EXTENSION pExtension;
  860. PFAST_IO_DISPATCH pFastIoDispatch;
  861. //
  862. // < dispatch!
  863. //
  864. PAGED_CODE();
  865. if (DeviceObject->DeviceExtension)
  866. {
  867. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  868. pExtension = DeviceObject->DeviceExtension;
  869. //
  870. // call the next device
  871. //
  872. pFastIoDispatch = pExtension->pTargetDevice->
  873. DriverObject->FastIoDispatch;
  874. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoWriteCompressed))
  875. {
  876. return pFastIoDispatch->FastIoWriteCompressed(
  877. FileObject,
  878. FileOffset,
  879. Length,
  880. LockKey,
  881. Buffer,
  882. MdlChain,
  883. IoStatus,
  884. CompressedDataInfo,
  885. CompressedDataInfoLength,
  886. pExtension->pTargetDevice );
  887. }
  888. }
  889. return FALSE;
  890. }
  891. BOOLEAN
  892. SrFastIoMdlReadCompleteCompressed (
  893. IN struct _FILE_OBJECT *FileObject,
  894. IN PMDL MdlChain,
  895. IN struct _DEVICE_OBJECT *DeviceObject
  896. )
  897. {
  898. PSR_DEVICE_EXTENSION pExtension;
  899. PFAST_IO_DISPATCH pFastIoDispatch;
  900. //
  901. // < dispatch!
  902. //
  903. PAGED_CODE();
  904. if (DeviceObject->DeviceExtension)
  905. {
  906. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  907. pExtension = DeviceObject->DeviceExtension;
  908. //
  909. // call the next device
  910. //
  911. pFastIoDispatch = pExtension->pTargetDevice->
  912. DriverObject->FastIoDispatch;
  913. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, MdlReadCompleteCompressed))
  914. {
  915. return pFastIoDispatch->MdlReadCompleteCompressed(
  916. FileObject,
  917. MdlChain,
  918. pExtension->pTargetDevice );
  919. }
  920. }
  921. return FALSE;
  922. }
  923. BOOLEAN
  924. SrFastIoMdlWriteCompleteCompressed (
  925. IN struct _FILE_OBJECT *FileObject,
  926. IN PLARGE_INTEGER FileOffset,
  927. IN PMDL MdlChain,
  928. IN struct _DEVICE_OBJECT *DeviceObject
  929. )
  930. {
  931. PSR_DEVICE_EXTENSION pExtension;
  932. PFAST_IO_DISPATCH pFastIoDispatch;
  933. //
  934. // < dispatch!
  935. //
  936. PAGED_CODE();
  937. if (DeviceObject->DeviceExtension)
  938. {
  939. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  940. pExtension = DeviceObject->DeviceExtension;
  941. //
  942. // call the next device
  943. //
  944. pFastIoDispatch = pExtension->pTargetDevice->
  945. DriverObject->FastIoDispatch;
  946. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, MdlWriteCompleteCompressed))
  947. {
  948. return pFastIoDispatch->MdlWriteCompleteCompressed (
  949. FileObject,
  950. FileOffset,
  951. MdlChain,
  952. pExtension->pTargetDevice );
  953. }
  954. }
  955. return FALSE;
  956. }
  957. BOOLEAN
  958. SrFastIoQueryOpen (
  959. IN struct _IRP *pIrp,
  960. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  961. IN struct _DEVICE_OBJECT *DeviceObject
  962. )
  963. {
  964. PSR_DEVICE_EXTENSION pExtension;
  965. PFAST_IO_DISPATCH pFastIoDispatch;
  966. PIO_STACK_LOCATION pIrpSp;
  967. BOOLEAN Result;
  968. //
  969. // < dispatch!
  970. //
  971. PAGED_CODE();
  972. if (DeviceObject->DeviceExtension)
  973. {
  974. ASSERT(IS_SR_DEVICE_OBJECT(DeviceObject));
  975. pExtension = DeviceObject->DeviceExtension;
  976. //
  977. // call the next device
  978. //
  979. pFastIoDispatch = pExtension->pTargetDevice->
  980. DriverObject->FastIoDispatch;
  981. if (VALID_FAST_IO_DISPATCH_HANDLER(pFastIoDispatch, FastIoQueryOpen))
  982. {
  983. //
  984. // normally IoCallDriver would update this field, we should manually
  985. //
  986. pIrpSp = IoGetCurrentIrpStackLocation( pIrp );
  987. pIrpSp->DeviceObject = pExtension->pTargetDevice;
  988. Result = pFastIoDispatch->FastIoQueryOpen ( pIrp,
  989. NetworkInformation,
  990. pExtension->pTargetDevice );
  991. if (!Result)
  992. {
  993. //
  994. // This is ok, fastioquery does not complete the irp ever, and
  995. // false means we are about to come down with an MJ_CREATE so
  996. // we need the proper device object put back in the stack.
  997. //
  998. pIrpSp->DeviceObject = DeviceObject;
  999. }
  1000. return Result;
  1001. }
  1002. }
  1003. return FALSE;
  1004. }