Source code of Windows XP (NT5)
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.

1259 lines
25 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. NpProcs.h
  5. Abstract:
  6. This module defines all of the globally used procedures in the Named
  7. Pipe file system.
  8. Author:
  9. Gary Kimura [GaryKi] 20-Aug-1990
  10. Revision History:
  11. --*/
  12. #ifndef _NPPROCS_
  13. #define _NPPROCS_
  14. #define _NTSRV_
  15. #define _NTDDK_
  16. #include <Ntos.h>
  17. #include <FsRtl.h>
  18. #include <String.h>
  19. //
  20. // This macro returns TRUE if a flag in a set of flags is on and FALSE
  21. // otherwise
  22. //
  23. #define FlagOn(Flags,SingleFlag) ((Flags) & (SingleFlag))
  24. #include "NodeType.h"
  25. #include "NpStruc.h"
  26. #include "NpData.h"
  27. //
  28. // Tag all of our allocations if tagging is turned on
  29. //
  30. #undef FsRtlAllocatePool
  31. #undef FsRtlAllocatePoolWithQuota
  32. #define FsRtlAllocatePool(a,b) FsRtlAllocatePoolWithTag(a,b,'sfpN')
  33. #define FsRtlAllocatePoolWithQuota(a,b) FsRtlAllocatePoolWithQuotaTag(a,b,'sfpN')
  34. //
  35. // Data queue support routines, implemented in DataSup.c
  36. //
  37. NTSTATUS
  38. NpInitializeDataQueue (
  39. IN PDATA_QUEUE DataQueue,
  40. IN ULONG Quota
  41. );
  42. VOID
  43. NpUninitializeDataQueue (
  44. IN PDATA_QUEUE DataQueue
  45. );
  46. NTSTATUS
  47. NpAddDataQueueEntry (
  48. IN NAMED_PIPE_END NamedPipeEnd,
  49. IN PCCB Ccb,
  50. IN PDATA_QUEUE DataQueue,
  51. IN QUEUE_STATE Who,
  52. IN DATA_ENTRY_TYPE Type,
  53. IN ULONG DataSize,
  54. IN PIRP Irp OPTIONAL,
  55. IN PVOID DataPointer OPTIONAL,
  56. IN ULONG ByteOffset
  57. );
  58. PIRP
  59. NpRemoveDataQueueEntry (
  60. IN PDATA_QUEUE DataQueue,
  61. IN BOOLEAN CompletedFlushes,
  62. IN PLIST_ENTRY DeferredList
  63. );
  64. VOID
  65. NpCompleteStalledWrites (
  66. IN PDATA_QUEUE DataQueue,
  67. IN PLIST_ENTRY DeferredList
  68. );
  69. //PDATA_ENTRY
  70. //NpGetNextDataQueueEntry (
  71. // IN PDATA_QUEUE DataQueue,
  72. // IN PDATA_ENTRY PreviousDataEntry OPTIONAL
  73. // );
  74. #define NpGetNextDataQueueEntry(_dq,_pde) \
  75. ((_pde) != NULL ? (PDATA_ENTRY)(((PDATA_ENTRY)(_pde))->Queue.Flink) : \
  76. (PDATA_ENTRY)(((PDATA_QUEUE)(_dq))->Queue.Flink))
  77. PDATA_ENTRY
  78. NpGetNextRealDataQueueEntry (
  79. IN PDATA_QUEUE DataQueue,
  80. IN PLIST_ENTRY DeferredList
  81. );
  82. //BOOLEAN
  83. //NpIsDataQueueEmpty (
  84. // IN PDATA_QUEUE DataQueue
  85. // );
  86. #define NpIsDataQueueEmpty(_dq) ((_dq)->QueueState == Empty)
  87. //BOOLEAN
  88. //NpIsDataQueueReaders (
  89. // IN PDATA_QUEUE DataQueue
  90. // );
  91. #define NpIsDataQueueReaders(_dq) ((_dq)->QueueState == ReadEntries)
  92. //BOOLEAN
  93. //NpIsDataQueueWriters (
  94. // IN PDATA_QUEUE DataQueue
  95. // );
  96. #define NpIsDataQueueWriters(_dq) ((_dq)->QueueState == WriteEntries)
  97. //
  98. // The following routines are used to manipulate the input buffers and are
  99. // implemented in DevioSup.c
  100. //
  101. //PVOID
  102. //NpMapUserBuffer (
  103. // IN OUT PIRP Irp
  104. // );
  105. #define NpMapUserBuffer(_irp) \
  106. (Irp->MdlAddress == NULL ? Irp->UserBuffer : \
  107. MmGetSystemAddressForMdl( Irp->MdlAddress ))
  108. VOID
  109. NpLockUserBuffer (
  110. IN OUT PIRP Irp,
  111. IN LOCK_OPERATION Operation,
  112. IN ULONG BufferLength
  113. );
  114. //
  115. // The event support routines, implemented in EventSup.c
  116. //
  117. RTL_GENERIC_COMPARE_RESULTS
  118. NpEventTableCompareRoutine (
  119. IN PRTL_GENERIC_TABLE EventTable,
  120. IN PVOID FirstStruct,
  121. IN PVOID SecondStruct
  122. );
  123. PVOID
  124. NpEventTableAllocate (
  125. IN PRTL_GENERIC_TABLE EventTable,
  126. IN CLONG ByteSize
  127. );
  128. VOID
  129. NpEventTableDeallocate (
  130. IN PRTL_GENERIC_TABLE EventTable,
  131. IN PVOID Buffer
  132. );
  133. //
  134. // VOID
  135. // NpInitializeEventTable (
  136. // IN PEVENT_TABLE EventTable
  137. // );
  138. //
  139. #define NpInitializeEventTable(_et) { \
  140. RtlInitializeGenericTable( &(_et)->Table, \
  141. NpEventTableCompareRoutine, \
  142. NpEventTableAllocate, \
  143. NpEventTableDeallocate, \
  144. NULL ); \
  145. }
  146. //VOID
  147. //NpUninitializeEventTable (
  148. // IN PEVENT_TABLE EventTable
  149. // );
  150. #define NpUninitializeEventTable(_et) NOTHING
  151. NTSTATUS
  152. NpAddEventTableEntry (
  153. IN PEVENT_TABLE EventTable,
  154. IN PCCB Ccb,
  155. IN NAMED_PIPE_END NamedPipeEnd,
  156. IN HANDLE EventHandle,
  157. IN ULONG KeyValue,
  158. IN PEPROCESS Process,
  159. IN KPROCESSOR_MODE PreviousMode,
  160. OUT PEVENT_TABLE_ENTRY *ppEventTableEntry
  161. );
  162. VOID
  163. NpDeleteEventTableEntry (
  164. IN PEVENT_TABLE EventTable,
  165. IN PEVENT_TABLE_ENTRY Template
  166. );
  167. // VOID
  168. // NpSignalEventTableEntry (
  169. // IN PEVENT_TABLE_ENTRY EventTableEntry OPTIONAL
  170. // );
  171. #define NpSignalEventTableEntry(_ete) \
  172. if (ARGUMENT_PRESENT(_ete)) { \
  173. KeSetEvent((PKEVENT)(_ete)->Event, 0, FALSE); \
  174. }
  175. PEVENT_TABLE_ENTRY
  176. NpGetNextEventTableEntry (
  177. IN PEVENT_TABLE EventTable,
  178. IN PVOID *RestartKey
  179. );
  180. //
  181. // The following routines are used to manipulate the fscontext fields of
  182. // a file object, implemented in FilObSup.c
  183. //
  184. VOID
  185. NpSetFileObject (
  186. IN PFILE_OBJECT FileObject OPTIONAL,
  187. IN PVOID FsContext,
  188. IN PVOID FsContext2,
  189. IN NAMED_PIPE_END NamedPipeEnd
  190. );
  191. NODE_TYPE_CODE
  192. NpDecodeFileObject (
  193. IN PFILE_OBJECT FileObject,
  194. OUT PFCB *Fcb OPTIONAL,
  195. OUT PCCB *Ccb,
  196. OUT PNAMED_PIPE_END NamedPipeEnd OPTIONAL
  197. );
  198. //
  199. // Largest matching prefix searching routines, implemented in PrefxSup.c
  200. //
  201. PFCB
  202. NpFindPrefix (
  203. IN PUNICODE_STRING String,
  204. IN BOOLEAN CaseInsensitive,
  205. OUT PUNICODE_STRING RemainingPart
  206. );
  207. NTSTATUS
  208. NpFindRelativePrefix (
  209. IN PDCB Dcb,
  210. IN PUNICODE_STRING String,
  211. IN BOOLEAN CaseInsensitive,
  212. OUT PUNICODE_STRING RemainingPart,
  213. OUT PFCB *ppFcb
  214. );
  215. //
  216. // Pipe name aliases, implemented in AliasSup.c
  217. //
  218. NTSTATUS
  219. NpInitializeAliases (
  220. VOID
  221. );
  222. VOID
  223. NpUninitializeAliases (
  224. VOID
  225. );
  226. NTSTATUS
  227. NpTranslateAlias (
  228. IN OUT PUNICODE_STRING String
  229. );
  230. //
  231. // The follow routine provides common read data queue support
  232. // for buffered read, unbuffered read, peek, and transceive
  233. //
  234. IO_STATUS_BLOCK
  235. NpReadDataQueue (
  236. IN PDATA_QUEUE ReadQueue,
  237. IN BOOLEAN PeekOperation,
  238. IN BOOLEAN ReadOverflowOperation,
  239. IN PUCHAR ReadBuffer,
  240. IN ULONG ReadLength,
  241. IN READ_MODE ReadMode,
  242. IN PCCB Ccb,
  243. IN PLIST_ENTRY DeferredList
  244. );
  245. //
  246. // The following routines are used for setting and manipulating the
  247. // security fields in the data entry, and nonpaged ccb, implemented in
  248. // SecurSup.c
  249. //
  250. NTSTATUS
  251. NpInitializeSecurity (
  252. IN PCCB Ccb,
  253. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  254. IN PETHREAD UserThread
  255. );
  256. VOID
  257. NpUninitializeSecurity (
  258. IN PCCB Ccb
  259. );
  260. NTSTATUS
  261. NpGetClientSecurityContext (
  262. IN NAMED_PIPE_END NamedPipeEnd,
  263. IN PCCB Ccb,
  264. IN PETHREAD UserThread,
  265. OUT PSECURITY_CLIENT_CONTEXT *ppSecurityContext
  266. );
  267. VOID
  268. NpFreeClientSecurityContext (
  269. IN PSECURITY_CLIENT_CONTEXT SecurityContext
  270. );
  271. VOID
  272. NpCopyClientContext (
  273. IN PCCB Ccb,
  274. IN PDATA_ENTRY DataEntry
  275. );
  276. NTSTATUS
  277. NpImpersonateClientContext (
  278. IN PCCB Ccb
  279. );
  280. //
  281. // The following routines are used to manipulate the named pipe state
  282. // implemented in StateSup.c
  283. //
  284. VOID
  285. NpInitializePipeState (
  286. IN PCCB Ccb,
  287. IN PFILE_OBJECT ServerFileObject
  288. );
  289. VOID
  290. NpUninitializePipeState (
  291. IN PCCB Ccb
  292. );
  293. NTSTATUS
  294. NpSetListeningPipeState (
  295. IN PCCB Ccb,
  296. IN PIRP Irp,
  297. IN PLIST_ENTRY DeferredList
  298. );
  299. NTSTATUS
  300. NpSetConnectedPipeState (
  301. IN PCCB Ccb,
  302. IN PFILE_OBJECT ClientFileObject,
  303. IN PLIST_ENTRY DeferredList
  304. );
  305. NTSTATUS
  306. NpSetClosingPipeState (
  307. IN PCCB Ccb,
  308. IN PIRP Irp,
  309. IN NAMED_PIPE_END NamedPipeEnd,
  310. IN PLIST_ENTRY DeferredList
  311. );
  312. NTSTATUS
  313. NpSetDisconnectedPipeState (
  314. IN PCCB Ccb,
  315. IN PLIST_ENTRY DeferredList
  316. );
  317. //
  318. // Internal Named Pipe data Structure Routines, implemented in StrucSup.c.
  319. //
  320. // These routines maniuplate the in memory data structures.
  321. //
  322. VOID
  323. NpInitializeVcb (
  324. VOID
  325. );
  326. VOID
  327. NpDeleteVcb (
  328. IN PLIST_ENTRY DeferredList
  329. );
  330. NTSTATUS
  331. NpCreateRootDcb (
  332. VOID
  333. );
  334. VOID
  335. NpDeleteRootDcb (
  336. IN PROOT_DCB Dcb,
  337. IN PLIST_ENTRY DeferredList
  338. );
  339. NTSTATUS
  340. NpCreateFcb (
  341. IN PDCB ParentDcb,
  342. IN PUNICODE_STRING FileName,
  343. IN ULONG MaximumInstances,
  344. IN LARGE_INTEGER DefaultTimeOut,
  345. IN NAMED_PIPE_CONFIGURATION NamedPipeConfiguration,
  346. IN NAMED_PIPE_TYPE NamedPipeType,
  347. OUT PFCB *ppFcb
  348. );
  349. VOID
  350. NpDeleteFcb (
  351. IN PFCB Fcb,
  352. IN PLIST_ENTRY DeferredList
  353. );
  354. NTSTATUS
  355. NpCreateCcb (
  356. IN PFCB Fcb,
  357. IN PFILE_OBJECT ServerFileObject,
  358. IN NAMED_PIPE_STATE NamedPipeState,
  359. IN READ_MODE ServerReadMode,
  360. IN COMPLETION_MODE ServerCompletionMode,
  361. IN ULONG InBoundQuota,
  362. IN ULONG OutBoundQuota,
  363. OUT PCCB *ppCcb
  364. );
  365. NTSTATUS
  366. NpCreateRootDcbCcb (
  367. OUT PROOT_DCB_CCB *ppCcb
  368. );
  369. VOID
  370. NpDeleteCcb (
  371. IN PCCB Ccb,
  372. IN PLIST_ENTRY DeferredList
  373. );
  374. //
  375. // Waiting for a named pipe support routines, implemented in WaitSup.c
  376. //
  377. VOID
  378. NpInitializeWaitQueue (
  379. IN PWAIT_QUEUE WaitQueue
  380. );
  381. VOID
  382. NpUninitializeWaitQueue (
  383. IN PWAIT_QUEUE WaitQueue
  384. );
  385. NTSTATUS
  386. NpAddWaiter (
  387. IN PWAIT_QUEUE WaitQueue,
  388. IN LARGE_INTEGER DefaultTimeOut,
  389. IN PIRP Irp,
  390. IN PUNICODE_STRING TranslatedString
  391. );
  392. NTSTATUS
  393. NpCancelWaiter (
  394. IN PWAIT_QUEUE WaitQueue,
  395. IN PUNICODE_STRING NameOfPipe,
  396. IN NTSTATUS CompletionStatus,
  397. IN PLIST_ENTRY DeferredList
  398. );
  399. //
  400. // The follow routine provides common write data queue support
  401. // for buffered write, unbuffered write, peek, and transceive
  402. //
  403. NTSTATUS
  404. NpWriteDataQueue ( // implemented in WriteSup.c
  405. IN PDATA_QUEUE WriteQueue,
  406. IN READ_MODE ReadMode,
  407. IN PUCHAR WriteBuffer,
  408. IN ULONG WriteLength,
  409. IN NAMED_PIPE_TYPE PipeType,
  410. OUT PULONG WriteRemaining,
  411. IN PCCB Ccb,
  412. IN NAMED_PIPE_END NamedPipeEnd,
  413. IN PETHREAD UserThread,
  414. IN PLIST_ENTRY DeferredList
  415. );
  416. //
  417. // Miscellaneous support routines
  418. //
  419. #define BooleanFlagOn(F,SF) ( \
  420. (BOOLEAN)(((F) & (SF)) != 0) \
  421. )
  422. //
  423. // This macro takes a pointer (or ulong) and returns its rounded up word
  424. // value
  425. //
  426. #define WordAlign(Ptr) ( \
  427. ((((ULONG)(Ptr)) + 1) & 0xfffffffe) \
  428. )
  429. //
  430. // This macro takes a pointer (or ulong) and returns its rounded up longword
  431. // value
  432. //
  433. #define LongAlign(Ptr) ( \
  434. ((((ULONG)(Ptr)) + 3) & 0xfffffffc) \
  435. )
  436. //
  437. // This macro takes a pointer (or ulong) and returns its rounded up quadword
  438. // value
  439. //
  440. #define QuadAlign(Ptr) ( \
  441. ((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
  442. )
  443. //
  444. // The following types and macros are used to help unpack the packed and
  445. // misaligned fields found in the Bios parameter block
  446. //
  447. typedef union _UCHAR1 {
  448. UCHAR Uchar[1];
  449. UCHAR ForceAlignment;
  450. } UCHAR1, *PUCHAR1;
  451. typedef union _UCHAR2 {
  452. UCHAR Uchar[2];
  453. USHORT ForceAlignment;
  454. } UCHAR2, *PUCHAR2;
  455. typedef union _UCHAR4 {
  456. UCHAR Uchar[4];
  457. ULONG ForceAlignment;
  458. } UCHAR4, *PUCHAR4;
  459. //
  460. // This macro copies an unaligned src byte to an aligned dst byte
  461. //
  462. #define CopyUchar1(Dst,Src) { \
  463. *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
  464. }
  465. //
  466. // This macro copies an unaligned src word to an aligned dst word
  467. //
  468. #define CopyUchar2(Dst,Src) { \
  469. *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
  470. }
  471. //
  472. // This macro copies an unaligned src longword to an aligned dsr longword
  473. //
  474. #define CopyUchar4(Dst,Src) { \
  475. *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
  476. }
  477. //
  478. // VOID
  479. // NpAcquireExclusiveVcb (
  480. // );
  481. //
  482. // VOID
  483. // NpAcquireSharedVcb (
  484. // );
  485. //
  486. // VOID
  487. // NpReleaseVcb (
  488. // );
  489. //
  490. #define NpAcquireExclusiveVcb() (VOID)ExAcquireResourceExclusiveLite( &NpVcb->Resource, TRUE )
  491. #define NpAcquireSharedVcb() (VOID)ExAcquireResourceSharedLite( &NpVcb->Resource, TRUE )
  492. #define NpReleaseVcb() ExReleaseResourceLite( &NpVcb->Resource )
  493. #define NpAcquireExclusiveCcb(Ccb) ExAcquireResourceExclusiveLite(&Ccb->NonpagedCcb->Resource,TRUE);
  494. #define NpReleaseCcb(Ccb) ExReleaseResourceLite(&Ccb->NonpagedCcb->Resource);
  495. #define NpIsAcquiredExclusiveVcb(VCB) ExIsResourceAcquiredExclusiveLite( &(VCB)->Resource )
  496. //
  497. // The FSD Level dispatch routines. These routines are called by the
  498. // I/O system via the dispatch table in the Driver Object.
  499. //
  500. // They each accept as input a pointer to a device object (actually most
  501. // expect an npfs device object), and a pointer to the IRP.
  502. //
  503. NTSTATUS
  504. NpFsdCreate ( // implemented in Create.c
  505. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  506. IN PIRP Irp
  507. );
  508. NTSTATUS
  509. NpFsdCreateNamedPipe ( // implemented in CreateNp.c
  510. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  511. IN PIRP Irp
  512. );
  513. NTSTATUS
  514. NpFsdClose ( // implemented in Close.c
  515. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  516. IN PIRP Irp
  517. );
  518. NTSTATUS
  519. NpFsdRead ( // implemented in Read.c
  520. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  521. IN PIRP Irp
  522. );
  523. NTSTATUS
  524. NpFsdWrite ( // implemented in Write.c
  525. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  526. IN PIRP Irp
  527. );
  528. NTSTATUS
  529. NpFsdQueryInformation ( // implemented in FileInfo.c
  530. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  531. IN PIRP Irp
  532. );
  533. NTSTATUS
  534. NpFsdSetInformation ( // implemented in FileInfo.c
  535. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  536. IN PIRP Irp
  537. );
  538. NTSTATUS
  539. NpFsdCleanup ( // implemented in Cleanup.c
  540. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  541. IN PIRP Irp
  542. );
  543. NTSTATUS
  544. NpFsdFlushBuffers ( // implemented in Flush.c
  545. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  546. IN PIRP Irp
  547. );
  548. NTSTATUS
  549. NpFsdDirectoryControl ( // implemented in Dir.c
  550. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  551. IN PIRP Irp
  552. );
  553. NTSTATUS
  554. NpFsdFileSystemControl ( // implemented in FsContrl.c
  555. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  556. IN PIRP Irp
  557. );
  558. NTSTATUS
  559. NpFsdSetSecurityInfo ( // implemented in SeInfo.c
  560. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  561. IN PIRP Irp
  562. );
  563. NTSTATUS
  564. NpFsdQuerySecurityInfo ( // implemented in SeInfo.c
  565. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  566. IN PIRP Irp
  567. );
  568. NTSTATUS
  569. NpFsdQueryVolumeInformation ( // implemented in VolInfo.c
  570. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  571. IN PIRP Irp
  572. );
  573. NTSTATUS
  574. NpCommonFileSystemControl (
  575. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  576. IN PIRP Irp
  577. );
  578. NTSTATUS
  579. NpAssignEvent (
  580. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  581. IN PIRP Irp
  582. );
  583. NTSTATUS
  584. NpDisconnect (
  585. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  586. IN PIRP Irp,
  587. IN PLIST_ENTRY DeferredList
  588. );
  589. NTSTATUS
  590. NpListen (
  591. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  592. IN PIRP Irp,
  593. IN PLIST_ENTRY DeferredList
  594. );
  595. NTSTATUS
  596. NpPeek (
  597. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  598. IN PIRP Irp,
  599. IN PLIST_ENTRY DeferredList
  600. );
  601. NTSTATUS
  602. NpQueryEvent (
  603. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  604. IN PIRP Irp
  605. );
  606. NTSTATUS
  607. NpTransceive (
  608. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  609. IN PIRP Irp,
  610. IN PLIST_ENTRY DeferredList
  611. );
  612. NTSTATUS
  613. NpWaitForNamedPipe (
  614. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  615. IN PIRP Irp
  616. );
  617. NTSTATUS
  618. NpImpersonate (
  619. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  620. IN PIRP Irp
  621. );
  622. NTSTATUS
  623. NpInternalRead (
  624. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  625. IN PIRP Irp,
  626. IN BOOLEAN ReadOverflowOperation,
  627. IN PLIST_ENTRY DeferredList
  628. );
  629. NTSTATUS
  630. NpInternalWrite (
  631. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  632. IN PIRP Irp,
  633. IN PLIST_ENTRY DeferredList
  634. );
  635. NTSTATUS
  636. NpInternalTransceive (
  637. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  638. IN PIRP Irp,
  639. IN PLIST_ENTRY DeferredList
  640. );
  641. NTSTATUS
  642. NpQueryClientProcess (
  643. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  644. IN PIRP Irp
  645. );
  646. NTSTATUS
  647. NpSetClientProcess (
  648. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  649. IN PIRP Irp
  650. );
  651. NTSTATUS
  652. NpCompleteTransceiveIrp (
  653. IN PDEVICE_OBJECT DeviceObject,
  654. IN PIRP Irp,
  655. IN PVOID Context
  656. );
  657. //
  658. // The following procedures are callbacks used to do fast I/O
  659. //
  660. BOOLEAN
  661. NpFastRead (
  662. IN PFILE_OBJECT FileObject,
  663. IN PLARGE_INTEGER FileOffset,
  664. IN ULONG Length,
  665. IN BOOLEAN Wait,
  666. IN ULONG LockKey,
  667. OUT PVOID Buffer,
  668. OUT PIO_STATUS_BLOCK IoStatus,
  669. IN PDEVICE_OBJECT DeviceObject
  670. );
  671. BOOLEAN
  672. NpFastWrite (
  673. IN PFILE_OBJECT FileObject,
  674. IN PLARGE_INTEGER FileOffset,
  675. IN ULONG Length,
  676. IN BOOLEAN Wait,
  677. IN ULONG LockKey,
  678. IN PVOID Buffer,
  679. OUT PIO_STATUS_BLOCK IoStatus,
  680. IN PDEVICE_OBJECT DeviceObject
  681. );
  682. BOOLEAN
  683. NpCommonWrite (
  684. IN PFILE_OBJECT FileObject,
  685. IN PVOID WriteBuffer,
  686. IN ULONG WriteLength,
  687. IN PETHREAD UserThread,
  688. OUT PIO_STATUS_BLOCK Iosb,
  689. IN PIRP Irp OPTIONAL,
  690. IN PLIST_ENTRY DeferredList
  691. );
  692. //
  693. // Miscellaneous routines.
  694. //
  695. VOID
  696. NpCheckForNotify ( // implemented in Dir.c
  697. IN PDCB Dcb,
  698. IN BOOLEAN CheckAllOutstandingIrps,
  699. IN PLIST_ENTRY DeferredList
  700. );
  701. NTSTATUS
  702. NpCommonQueryInformation (
  703. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  704. IN PIRP Irp
  705. );
  706. NTSTATUS
  707. NpCommonSetInformation (
  708. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  709. IN PIRP Irp,
  710. IN PLIST_ENTRY DeferredList
  711. );
  712. NTSTATUS
  713. NpQueryBasicInfo (
  714. IN PCCB Ccb,
  715. IN PFILE_BASIC_INFORMATION Buffer,
  716. IN OUT PULONG Length
  717. );
  718. NTSTATUS
  719. NpQueryStandardInfo (
  720. IN PCCB Ccb,
  721. IN PFILE_STANDARD_INFORMATION Buffer,
  722. IN OUT PULONG Length,
  723. IN NAMED_PIPE_END NamedPipeEnd
  724. );
  725. NTSTATUS
  726. NpQueryInternalInfo (
  727. IN PCCB Ccb,
  728. IN PFILE_INTERNAL_INFORMATION Buffer,
  729. IN OUT PULONG Length
  730. );
  731. NTSTATUS
  732. NpQueryEaInfo (
  733. IN PCCB Ccb,
  734. IN PFILE_EA_INFORMATION Buffer,
  735. IN OUT PULONG Length
  736. );
  737. NTSTATUS
  738. NpQueryNameInfo (
  739. IN PCCB Ccb,
  740. IN PFILE_NAME_INFORMATION Buffer,
  741. IN OUT PULONG Length
  742. );
  743. NTSTATUS
  744. NpQueryPositionInfo (
  745. IN PCCB Ccb,
  746. IN PFILE_POSITION_INFORMATION Buffer,
  747. IN OUT PULONG Length,
  748. IN NAMED_PIPE_END NamedPipeEnd
  749. );
  750. NTSTATUS
  751. NpQueryPipeInfo (
  752. IN PFCB Fcb,
  753. IN PCCB Ccb,
  754. IN PFILE_PIPE_INFORMATION Buffer,
  755. IN OUT PULONG Length,
  756. IN NAMED_PIPE_END NamedPipeEnd
  757. );
  758. NTSTATUS
  759. NpQueryPipeLocalInfo (
  760. IN PFCB Fcb,
  761. IN PCCB Ccb,
  762. IN PFILE_PIPE_LOCAL_INFORMATION Buffer,
  763. IN OUT PULONG Length,
  764. IN NAMED_PIPE_END NamedPipeEnd
  765. );
  766. NTSTATUS
  767. NpSetBasicInfo (
  768. IN PCCB Ccb,
  769. IN PFILE_BASIC_INFORMATION Buffer
  770. );
  771. NTSTATUS
  772. NpSetPipeInfo (
  773. IN PFCB Fcb,
  774. IN PCCB Ccb,
  775. IN PFILE_PIPE_INFORMATION Buffer,
  776. IN NAMED_PIPE_END NamedPipeEnd,
  777. IN PLIST_ENTRY DeferredList
  778. );
  779. NTSTATUS
  780. NpCommonCreate (
  781. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  782. IN PIRP Irp
  783. );
  784. IO_STATUS_BLOCK
  785. NpCreateClientEnd(
  786. IN PFCB Fcb,
  787. IN PFILE_OBJECT FileObject,
  788. IN ACCESS_MASK DesiredAccess,
  789. IN USHORT ShareAccess,
  790. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  791. IN PACCESS_STATE AccessState,
  792. IN KPROCESSOR_MODE RequestorMode,
  793. IN PETHREAD UserThread,
  794. IN PLIST_ENTRY DeferredList
  795. );
  796. IO_STATUS_BLOCK
  797. NpOpenNamedPipeFileSystem (
  798. IN PFILE_OBJECT FileObject,
  799. IN ACCESS_MASK DesiredAccess,
  800. IN USHORT ShareAccess
  801. );
  802. IO_STATUS_BLOCK
  803. NpOpenNamedPipeRootDirectory (
  804. IN PROOT_DCB RootDcb,
  805. IN PFILE_OBJECT FileObject,
  806. IN ACCESS_MASK DesiredAccess,
  807. IN USHORT ShareAccess,
  808. IN PLIST_ENTRY DeferredList
  809. );
  810. NTSTATUS
  811. NpCommonCreateNamedPipe (
  812. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  813. IN PIRP Irp
  814. );
  815. IO_STATUS_BLOCK
  816. NpCreateNewNamedPipe (
  817. IN PROOT_DCB RootDcb,
  818. IN PFILE_OBJECT FileObject,
  819. IN UNICODE_STRING FileName,
  820. IN ACCESS_MASK DesiredAccess,
  821. IN PACCESS_STATE AccessState,
  822. IN ULONG CreateDisposition,
  823. IN USHORT ShareAccess,
  824. IN NAMED_PIPE_TYPE NamedPipeType,
  825. IN READ_MODE ServerReadMode,
  826. IN COMPLETION_MODE ServerCompletionMode,
  827. IN ULONG MaximumInstances,
  828. IN ULONG InboundQuota,
  829. IN ULONG OutboundQuota,
  830. IN LARGE_INTEGER DefaultTimeout,
  831. IN BOOLEAN TimeoutSpecified,
  832. IN PEPROCESS CreatorProcess,
  833. IN PLIST_ENTRY DeferredList
  834. );
  835. IO_STATUS_BLOCK
  836. NpCreateExistingNamedPipe (
  837. IN PFCB Fcb,
  838. IN PFILE_OBJECT FileObject,
  839. IN ACCESS_MASK DesiredAccess,
  840. IN PACCESS_STATE AccessState,
  841. IN KPROCESSOR_MODE RequestorMode,
  842. IN ULONG CreateDisposition,
  843. IN USHORT ShareAccess,
  844. IN READ_MODE ServerReadMode,
  845. IN COMPLETION_MODE ServerCompletionMode,
  846. IN ULONG InboundQuota,
  847. IN ULONG OutboundQuota,
  848. IN PEPROCESS CreatorProcess,
  849. IN PLIST_ENTRY DeferredList
  850. );
  851. NTSTATUS
  852. NpCommonDirectoryControl (
  853. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  854. IN PIRP Irp
  855. );
  856. NTSTATUS
  857. NpQueryDirectory (
  858. IN PROOT_DCB RootDcb,
  859. IN PROOT_DCB_CCB Ccb,
  860. IN PIRP Irp
  861. );
  862. NTSTATUS
  863. NpNotifyChangeDirectory (
  864. IN PROOT_DCB RootDcb,
  865. IN PROOT_DCB_CCB Ccb,
  866. IN PIRP Irp
  867. );
  868. VOID
  869. NpCancelChangeNotifyIrp (
  870. IN PDEVICE_OBJECT DeviceObject,
  871. IN PIRP Irp
  872. );
  873. VOID
  874. NpTimerDispatch(
  875. IN PKDPC Dpc,
  876. IN PVOID Contxt,
  877. IN PVOID SystemArgument1,
  878. IN PVOID SystemArgument2
  879. );
  880. VOID
  881. NpCancelWaitQueueIrp(
  882. IN PDEVICE_OBJECT DeviceObject,
  883. IN PIRP Irp
  884. );
  885. //
  886. // The following macro is used by the FSD routines to complete
  887. // an IRP.
  888. //
  889. #define NpCompleteRequest(IRP,STATUS) FsRtlCompleteRequest( (IRP), (STATUS) );
  890. #define NpDeferredCompleteRequest(IRP,STATUS,LIST) { \
  891. (IRP)->IoStatus.Status = STATUS; \
  892. InsertTailList ((LIST), &(IRP)->Tail.Overlay.ListEntry); \
  893. }
  894. VOID
  895. FORCEINLINE
  896. NpCompleteDeferredIrps (
  897. IN PLIST_ENTRY DeferredList
  898. )
  899. {
  900. PIRP Irp;
  901. PLIST_ENTRY Entry, NextEntry;
  902. Entry = DeferredList->Flink;
  903. while (Entry != DeferredList) {
  904. Irp = CONTAINING_RECORD (Entry, IRP, Tail.Overlay.ListEntry);
  905. NextEntry = Entry->Flink;
  906. NpCompleteRequest (Irp, Irp->IoStatus.Status);
  907. Entry = NextEntry;
  908. }
  909. }
  910. //
  911. // The following macros are used to establish the semantics needed
  912. // to do a return from within a try-finally clause. As a rule every
  913. // try clause must end with a label call try_exit. For example,
  914. //
  915. // try {
  916. // :
  917. // :
  918. //
  919. // try_exit: NOTHING;
  920. // } finally {
  921. //
  922. // :
  923. // :
  924. // }
  925. //
  926. // Every return statement executed inside of a try clause should use the
  927. // try_return macro. If the compiler fully supports the try-finally construct
  928. // then the macro should be
  929. //
  930. // #define try_return(S) { return(S); }
  931. //
  932. // If the compiler does not support the try-finally construct then the macro
  933. // should be
  934. //
  935. // #define try_return(S) { S; goto try_exit; }
  936. //
  937. #define try_return(S) { S; goto try_exit; }
  938. //
  939. // PVOID
  940. // NpAllocatePagedPool (
  941. // IN ULONG Size,
  942. // IN ULONG Tag)
  943. // Routine Description:
  944. //
  945. // This routine will return a pointer to paged pool or NULL if no memory exists.
  946. //
  947. // Arguments:
  948. //
  949. // Size - Size of memory to allocate
  950. // Tag - Tag to use for the pool allocation
  951. //
  952. // Return Value:
  953. //
  954. // PVOID - pointer to allocated memory or null
  955. //
  956. #define NpAllocatePagedPool( Size, Tag) \
  957. ExAllocatePoolWithTag( PagedPool, Size, Tag )
  958. //
  959. // PVOID
  960. // NpAllocateNonPagedPool (
  961. // IN ULONG Size,
  962. // IN ULONG Tag)
  963. // Routine Description:
  964. //
  965. // This routine will return a pointer to paged pool or NULL if no memory exists.
  966. //
  967. // Arguments:
  968. //
  969. // Size - Size of memory to allocate
  970. // Tag - Tag to use for the pool allocation
  971. //
  972. // Return Value:
  973. //
  974. // PVOID - pointer to allocated memory or null
  975. //
  976. #define NpAllocateNonPagedPool( Size, Tag) \
  977. ExAllocatePoolWithTag( NonPagedPool, Size, Tag )
  978. //
  979. // PVOID
  980. // NpAllocatePagedPoolWithQuota (
  981. // IN ULONG Size,
  982. // IN ULONG Tag)
  983. // Routine Description:
  984. //
  985. // This routine will return a pointer to charged paged pool or NULL if no memory exists.
  986. //
  987. // Arguments:
  988. //
  989. // Size - Size of memory to allocate
  990. // Tag - Tag to use for the pool allocation
  991. //
  992. // Return Value:
  993. //
  994. // PVOID - pointer to allocated memory or null
  995. //
  996. #define NpAllocatePagedPoolWithQuota( Size, Tag) \
  997. ExAllocatePoolWithQuotaTag( PagedPool|POOL_QUOTA_FAIL_INSTEAD_OF_RAISE, Size, Tag )
  998. #define NpAllocatePagedPoolWithQuotaCold( Size, Tag) \
  999. ExAllocatePoolWithQuotaTag( PagedPool|POOL_QUOTA_FAIL_INSTEAD_OF_RAISE|POOL_COLD_ALLOCATION, Size, Tag )
  1000. //
  1001. // PVOID
  1002. // NpAllocateNonPagedPoolWithQuota (
  1003. // IN ULONG Size,
  1004. // IN ULONG Tag)
  1005. // Routine Description:
  1006. //
  1007. // This routine will return a charged pointer to non-paged pool or NULL if no memory exists.
  1008. //
  1009. // Arguments:
  1010. //
  1011. // Size - Size of memory to allocate
  1012. // Tag - Tag to use for the pool allocation
  1013. //
  1014. // Return Value:
  1015. //
  1016. // PVOID - pointer to allocated memory or null
  1017. //
  1018. #define NpAllocateNonPagedPoolWithQuota( Size, Tag) \
  1019. ExAllocatePoolWithQuotaTag( NonPagedPool|POOL_QUOTA_FAIL_INSTEAD_OF_RAISE, Size, Tag )
  1020. //
  1021. // VOID
  1022. // NpFreePool (
  1023. // IN PVOID Mem)
  1024. //
  1025. // Routine Description:
  1026. //
  1027. //
  1028. //
  1029. // Arguments:
  1030. //
  1031. // Mem - Memory to be freed
  1032. //
  1033. // Return Value:
  1034. //
  1035. // None
  1036. //
  1037. #define NpFreePool(Mem) ExFreePool (Mem)
  1038. #define NpIrpWaitQueue(Irp) (Irp->Tail.Overlay.DriverContext[0])
  1039. #define NpIrpWaitContext(Irp) (Irp->Tail.Overlay.DriverContext[1])
  1040. #define NpIrpDataQueue(Irp) (Irp->Tail.Overlay.DriverContext[2])
  1041. #define NpIrpDataEntry(Irp) (Irp->Tail.Overlay.DriverContext[3])
  1042. #define NpConvertFsctlToWrite(Irp) (Irp->Flags &= ~IRP_INPUT_OPERATION)
  1043. #endif // _NPPROCS_