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.

2005 lines
36 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Procs.h
  5. Abstract:
  6. This module defines all of the globally used procedures in the NetWare
  7. redirector.
  8. Author:
  9. Colin Watson [ColinW] 15-Dec-1992
  10. Revision History:
  11. --*/
  12. #ifndef _NWPROCS_
  13. #define _NWPROCS_
  14. #ifndef QFE_BUILD
  15. #define IFS 1
  16. #define NWFASTIO 1
  17. #endif
  18. #ifdef IFS
  19. #include <ntifs.h>
  20. #include <ntddmup.h>
  21. #else
  22. #include <ntioapi.h>
  23. #include <zwapi.h>
  24. #include <FsRtl.h>
  25. #endif
  26. #include <string.h>
  27. #include <Tdi.h>
  28. #include <TdiKrnl.h>
  29. #include <Status.h>
  30. #include <nwstatus.h>
  31. // Netware and Netware redirector specific includes
  32. #ifndef DBG
  33. #define DBG 0
  34. #endif
  35. #if !DBG
  36. #undef NWDBG
  37. #endif
  38. #if NWDBG
  39. #define PAGED_DBG 1
  40. #endif
  41. #ifdef PAGED_DBG
  42. #undef PAGED_CODE
  43. #define PAGED_CODE() \
  44. struct { ULONG bogus; } ThisCodeCantBePaged; \
  45. ThisCodeCantBePaged; \
  46. if (KeGetCurrentIrql() > APC_LEVEL) { \
  47. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  48. ASSERT(FALSE); \
  49. }
  50. #define PAGED_CODE_CHECK() if (ThisCodeCantBePaged) ;
  51. extern ULONG ThisCodeCantBePaged;
  52. #else
  53. #define PAGED_CODE_CHECK()
  54. #endif
  55. #include <NtDDNwfs.h>
  56. #include "Const.h"
  57. #include "Nodetype.h"
  58. #include "ncp.h"
  59. #include "Struct.h"
  60. #include "Data.h"
  61. #include "Exchange.h"
  62. #include <NwEvent.h>
  63. //
  64. // NDS Additions.
  65. //
  66. #include <nds.h>
  67. #include "ndsprocs.h"
  68. // Attach.c
  69. NTSTATUS
  70. ConnectToServer(
  71. IN PIRP_CONTEXT pIrpContext,
  72. OUT PSCB *pScbCollision
  73. );
  74. NTSTATUS
  75. ProcessFindNearest(
  76. IN struct _IRP_CONTEXT* pIrpContext,
  77. IN ULONG BytesAvailable,
  78. IN PUCHAR RspData
  79. );
  80. NTSTATUS
  81. CrackPath (
  82. IN PUNICODE_STRING BaseName,
  83. OUT PUNICODE_STRING DriveName,
  84. OUT PWCHAR DriveLetter,
  85. OUT PUNICODE_STRING ServerName,
  86. OUT PUNICODE_STRING VolumeName,
  87. OUT PUNICODE_STRING PathName,
  88. OUT PUNICODE_STRING FileName,
  89. OUT PUNICODE_STRING FullName OPTIONAL
  90. );
  91. NTSTATUS
  92. CheckScbSecurity(
  93. IN PIRP_CONTEXT pIrpContext,
  94. IN PSCB pScb,
  95. IN PUNICODE_STRING puUserName,
  96. IN PUNICODE_STRING puPassword,
  97. IN BOOLEAN fDeferLogon
  98. );
  99. NTSTATUS
  100. ConnectScb(
  101. IN PSCB *Scb,
  102. IN PIRP_CONTEXT pIrpContext,
  103. IN PUNICODE_STRING Server,
  104. IN IPXaddress *pServerAddress,
  105. IN PUNICODE_STRING UserName,
  106. IN PUNICODE_STRING Password,
  107. IN BOOLEAN DeferLogon,
  108. IN BOOLEAN DeleteConnection,
  109. IN BOOLEAN ExistingScb
  110. );
  111. #define IS_ANONYMOUS_SCB( pScb ) \
  112. ( (pScb->UidServerName).Length == 0 )
  113. NTSTATUS
  114. CreateScb(
  115. OUT PSCB *Scb,
  116. IN PIRP_CONTEXT pIrpC,
  117. IN PUNICODE_STRING Server,
  118. IN IPXaddress *pServerAddress,
  119. IN PUNICODE_STRING UserName,
  120. IN PUNICODE_STRING Password,
  121. IN BOOLEAN DeferLogon,
  122. IN BOOLEAN DeleteConnection
  123. );
  124. VOID
  125. DestroyAllScb(
  126. VOID
  127. );
  128. VOID
  129. InitializeAttach (
  130. VOID
  131. );
  132. NTSTATUS
  133. OpenScbSockets(
  134. PIRP_CONTEXT pIrpC,
  135. PNONPAGED_SCB pNpScb
  136. );
  137. PNONPAGED_SCB
  138. SelectConnection(
  139. PNONPAGED_SCB NpScb
  140. );
  141. VOID
  142. NwLogoffAndDisconnect(
  143. PIRP_CONTEXT pIrpContext,
  144. PNONPAGED_SCB pNpScb
  145. );
  146. VOID
  147. NwLogoffAllServers(
  148. PIRP_CONTEXT pIrpContext,
  149. PLARGE_INTEGER Uid
  150. );
  151. VOID
  152. NwDeleteScb(
  153. PSCB pScb
  154. );
  155. NTSTATUS
  156. NegotiateBurstMode(
  157. PIRP_CONTEXT pIrpContext,
  158. PNONPAGED_SCB pNpScb,
  159. BOOLEAN *LIPNegotiated
  160. );
  161. VOID
  162. RenegotiateBurstMode(
  163. PIRP_CONTEXT pIrpContext,
  164. PNONPAGED_SCB pNpScb
  165. );
  166. BOOLEAN
  167. NwFindScb(
  168. OUT PSCB *ppScb,
  169. IN PIRP_CONTEXT pIrpContext,
  170. IN PUNICODE_STRING UidServerName,
  171. IN PUNICODE_STRING ServerName
  172. );
  173. NTSTATUS
  174. QueryServersAddress(
  175. PIRP_CONTEXT pIrpContext,
  176. PNONPAGED_SCB pNearestScb,
  177. PUNICODE_STRING pServerName,
  178. IPXaddress *pServerAddress
  179. );
  180. VOID
  181. TreeConnectScb(
  182. IN PSCB Scb
  183. );
  184. NTSTATUS
  185. TreeDisconnectScb(
  186. IN PIRP_CONTEXT IrpContext,
  187. IN PSCB Scb
  188. );
  189. VOID
  190. ReconnectScb(
  191. IN PIRP_CONTEXT IrpContext,
  192. IN PSCB pScb
  193. );
  194. // Cache.c
  195. ULONG
  196. CacheRead(
  197. IN PNONPAGED_FCB NpFcb,
  198. IN ULONG FileOffset,
  199. IN ULONG BytesToRead,
  200. IN PVOID UserBuffer
  201. #if NWFASTIO
  202. , IN BOOLEAN WholeBufferOnly
  203. #endif
  204. );
  205. BOOLEAN
  206. CacheWrite(
  207. IN PIRP_CONTEXT IrpContext,
  208. IN PNONPAGED_FCB NpFcb,
  209. IN ULONG FileOffset,
  210. IN ULONG BytesToWrite,
  211. IN PVOID UserBuffer
  212. );
  213. ULONG
  214. CalculateReadAheadSize(
  215. IN PIRP_CONTEXT IrpContext,
  216. IN PNONPAGED_FCB NpFcb,
  217. IN ULONG CacheReadSize,
  218. IN ULONG FileOffset,
  219. IN ULONG ByteCount
  220. );
  221. NTSTATUS
  222. FlushCache(
  223. PIRP_CONTEXT IrpContext,
  224. PNONPAGED_FCB NpFcb
  225. );
  226. NTSTATUS
  227. AcquireFcbAndFlushCache(
  228. PIRP_CONTEXT IrpContext,
  229. PNONPAGED_FCB NpFcb
  230. );
  231. VOID
  232. FlushAllBuffers(
  233. PIRP_CONTEXT pIrpContext
  234. );
  235. // Callback.c
  236. NTSTATUS
  237. SynchronousResponseCallback (
  238. IN PIRP_CONTEXT pIrpContext,
  239. IN ULONG BytesAvailable,
  240. IN PUCHAR RspData
  241. );
  242. NTSTATUS
  243. AsynchResponseCallback (
  244. IN PIRP_CONTEXT pIrpContext,
  245. IN ULONG BytesAvailable,
  246. IN PUCHAR RspData
  247. );
  248. NTSTATUS
  249. NcpSearchFileCallback (
  250. IN PIRP_CONTEXT pIrpContext,
  251. IN ULONG BytesIndicated,
  252. IN ULONG BytesAvailable,
  253. OUT ULONG *BytesTaken,
  254. IN PUCHAR RspData
  255. );
  256. // Cleanup.c
  257. NTSTATUS
  258. NwFsdCleanup (
  259. IN PDEVICE_OBJECT DeviceObject,
  260. IN PIRP Irp
  261. );
  262. // Close.c
  263. NTSTATUS
  264. NwFsdClose (
  265. IN PDEVICE_OBJECT DeviceObject,
  266. IN PIRP Irp
  267. );
  268. // Create.c
  269. NTSTATUS
  270. NwFsdCreate (
  271. IN PDEVICE_OBJECT DeviceObject,
  272. IN PIRP Irp
  273. );
  274. NTSTATUS
  275. ReadAttachEas(
  276. IN PIRP Irp,
  277. OUT PUNICODE_STRING UserName,
  278. OUT PUNICODE_STRING Password,
  279. OUT PULONG ShareType,
  280. OUT PDWORD CredentialExtension
  281. );
  282. // Convert.c
  283. NTSTATUS
  284. pNwErrorToNtStatus(
  285. UCHAR Error
  286. );
  287. NTSTATUS
  288. NwBurstResultToNtStatus(
  289. ULONG Result
  290. );
  291. #define NwErrorToNtStatus( STATUS ) \
  292. (STATUS == 0 )? STATUS_SUCCESS : pNwErrorToNtStatus(STATUS)
  293. NTSTATUS
  294. NwConnectionStatusToNtStatus(
  295. UCHAR NwStatus
  296. );
  297. UCHAR
  298. NtAttributesToNwAttributes(
  299. ULONG FileAttributes
  300. );
  301. UCHAR
  302. NtToNwShareFlags(
  303. ULONG DesiredAccess,
  304. ULONG NtShareFlags
  305. );
  306. LARGE_INTEGER
  307. NwDateTimeToNtTime(
  308. USHORT Date,
  309. USHORT Time
  310. );
  311. NTSTATUS
  312. NwNtTimeToNwDateTime (
  313. IN LARGE_INTEGER NtTime,
  314. IN PUSHORT NwDate,
  315. IN PUSHORT NwTime
  316. );
  317. // Data.c
  318. VOID
  319. NwInitializeData(
  320. VOID
  321. );
  322. // Debug.c
  323. #ifdef NWDBG
  324. ULONG
  325. NwMemDbg (
  326. IN PCH Format,
  327. ...
  328. );
  329. VOID
  330. RealDebugTrace(
  331. IN LONG Indent,
  332. IN ULONG Level,
  333. IN PCH Message,
  334. IN PVOID Parameter
  335. );
  336. VOID
  337. dump(
  338. IN ULONG Level,
  339. IN PVOID far_p,
  340. IN ULONG len
  341. );
  342. VOID
  343. dumpMdl(
  344. IN ULONG Level,
  345. IN PMDL Mdl
  346. );
  347. VOID
  348. DumpIcbs(
  349. VOID
  350. ) ;
  351. PVOID
  352. NwAllocatePool(
  353. ULONG Type,
  354. ULONG Size,
  355. BOOLEAN RaiseStatus
  356. );
  357. VOID
  358. NwFreePool(
  359. PVOID Buffer
  360. );
  361. PIRP
  362. NwAllocateIrp(
  363. CCHAR Size,
  364. BOOLEAN ChargeQuota
  365. );
  366. VOID
  367. NwFreeIrp(
  368. PIRP Irp
  369. );
  370. PMDL
  371. NwAllocateMdl(
  372. PVOID Va,
  373. ULONG Length,
  374. BOOLEAN Secondary,
  375. BOOLEAN ChargeQuota,
  376. PIRP Irp,
  377. PUCHAR FileName,
  378. int Line
  379. );
  380. VOID
  381. NwFreeMdl(
  382. PMDL Mdl
  383. );
  384. #else
  385. #define dump( level, pointer, length ) { NOTHING;}
  386. #endif
  387. // Deviosup.c
  388. VOID
  389. NwMapUserBuffer (
  390. IN OUT PIRP Irp,
  391. IN KPROCESSOR_MODE AccessMode,
  392. OUT PVOID *UserBuffer
  393. );
  394. VOID
  395. NwLockUserBuffer (
  396. IN OUT PIRP Irp,
  397. IN LOCK_OPERATION Operation,
  398. IN ULONG BufferLength
  399. );
  400. // Dir.c
  401. NTSTATUS
  402. NwFsdDirectoryControl (
  403. IN PDEVICE_OBJECT DeviceObject,
  404. IN PIRP Irp
  405. );
  406. // Encrypt.c
  407. VOID
  408. RespondToChallenge(
  409. IN PUCHAR achObjectId,
  410. IN POEM_STRING Password,
  411. IN PUCHAR pChallenge,
  412. OUT PUCHAR pResponse
  413. );
  414. // Exchange.c
  415. BOOLEAN
  416. AppendToScbQueue(
  417. IN PIRP_CONTEXT IrpContext,
  418. IN PNONPAGED_SCB NpScb
  419. );
  420. VOID
  421. PreparePacket(
  422. PIRP_CONTEXT pIrpContext,
  423. PIRP pOriginalIrp,
  424. PMDL pMdl
  425. );
  426. NTSTATUS
  427. PrepareAndSendPacket(
  428. PIRP_CONTEXT pIrpContext
  429. );
  430. NTSTATUS
  431. SendPacket(
  432. PIRP_CONTEXT pIrpContext,
  433. PNONPAGED_SCB pNpScb
  434. );
  435. VOID
  436. SendNow(
  437. IN PIRP_CONTEXT IrpContext
  438. );
  439. VOID
  440. SetEvent(
  441. IN PIRP_CONTEXT IrpContext
  442. );
  443. NTSTATUS
  444. _cdecl
  445. ExchangeWithWait(
  446. PIRP_CONTEXT pIrpContext,
  447. PEX pEx,
  448. char* f,
  449. ... // format specific parameters
  450. );
  451. NTSTATUS
  452. _cdecl
  453. BuildRequestPacket(
  454. PIRP_CONTEXT pIrpContext,
  455. PEX pEx,
  456. char* f,
  457. ... // format specific parameters
  458. );
  459. NTSTATUS
  460. _cdecl
  461. ParseResponse(
  462. PIRP_CONTEXT IrpContext,
  463. PUCHAR RequestHeader,
  464. ULONG RequestLength,
  465. char* f,
  466. ... // format specific parameters
  467. );
  468. NTSTATUS
  469. ParseNcpResponse(
  470. PIRP_CONTEXT IrpContext,
  471. PNCP_RESPONSE Response
  472. );
  473. BOOLEAN
  474. VerifyResponse(
  475. PIRP_CONTEXT pIrpContext,
  476. PVOID Response
  477. );
  478. VOID
  479. FreeReceiveIrp(
  480. PIRP_CONTEXT IrpContext
  481. );
  482. NTSTATUS
  483. NewRouteRetry(
  484. IN PIRP_CONTEXT pIrpContext
  485. );
  486. NTSTATUS
  487. NewRouteBurstRetry(
  488. IN PIRP_CONTEXT pIrpContext
  489. );
  490. VOID
  491. ReconnectRetry(
  492. PIRP_CONTEXT pIrpContext
  493. );
  494. ULONG
  495. MdlLength (
  496. register IN PMDL Mdl
  497. );
  498. VOID
  499. NwProcessSendBurstFailure(
  500. PNONPAGED_SCB NpScb,
  501. USHORT MissingFragmentCount
  502. );
  503. VOID
  504. NwProcessSendBurstSuccess(
  505. PNONPAGED_SCB NpScb
  506. );
  507. VOID
  508. NwProcessReceiveBurstFailure(
  509. PNONPAGED_SCB NpScb,
  510. USHORT MissingFragmentCount
  511. );
  512. VOID
  513. NwProcessReceiveBurstSuccess(
  514. PNONPAGED_SCB NpScb
  515. );
  516. VOID
  517. NwProcessPositiveAck(
  518. PNONPAGED_SCB NpScb
  519. );
  520. // Errorlog.c
  521. VOID
  522. _cdecl
  523. Error(
  524. IN ULONG UniqueErrorCode,
  525. IN NTSTATUS NtStatusCode,
  526. IN PVOID ExtraInformationBuffer,
  527. IN USHORT ExtraInformationLength,
  528. IN USHORT NumberOfInsertionStrings,
  529. ...
  530. );
  531. // FileInfo.c
  532. NTSTATUS
  533. NwFsdQueryInformation (
  534. IN PDEVICE_OBJECT DeviceObject,
  535. IN PIRP Irp
  536. );
  537. NTSTATUS
  538. NwFsdSetInformation (
  539. IN PDEVICE_OBJECT DeviceObject,
  540. IN PIRP Irp
  541. );
  542. NTSTATUS
  543. NwDeleteFile(
  544. IN PIRP_CONTEXT pIrpContext
  545. );
  546. ULONG
  547. OccurenceCount (
  548. IN PUNICODE_STRING String,
  549. IN WCHAR SearchChar
  550. );
  551. #if NWFASTIO
  552. BOOLEAN
  553. NwFastQueryBasicInfo (
  554. IN PFILE_OBJECT FileObject,
  555. IN BOOLEAN Wait,
  556. IN OUT PFILE_BASIC_INFORMATION Buffer,
  557. OUT PIO_STATUS_BLOCK IoStatus,
  558. IN PDEVICE_OBJECT DeviceObject
  559. );
  560. BOOLEAN
  561. NwFastQueryStandardInfo (
  562. IN PFILE_OBJECT FileObject,
  563. IN BOOLEAN Wait,
  564. IN OUT PFILE_STANDARD_INFORMATION Buffer,
  565. OUT PIO_STATUS_BLOCK IoStatus,
  566. IN PDEVICE_OBJECT DeviceObject
  567. );
  568. #endif
  569. // Filobsup.c
  570. VOID
  571. NwSetFileObject (
  572. IN PFILE_OBJECT FileObject OPTIONAL,
  573. IN PVOID FsContext,
  574. IN PVOID FsContext2
  575. );
  576. NODE_TYPE_CODE
  577. NwDecodeFileObject (
  578. IN PFILE_OBJECT FileObject,
  579. OUT PVOID *FsContext,
  580. OUT PVOID *FsContext2
  581. );
  582. BOOLEAN
  583. NwIsIrpTopLevel (
  584. IN PIRP Irp
  585. );
  586. // Fsctl.c
  587. NTSTATUS
  588. NwFsdFileSystemControl (
  589. IN PDEVICE_OBJECT DeviceObject,
  590. IN PIRP Irp
  591. );
  592. NTSTATUS
  593. NwCommonFileSystemControl (
  594. IN PIRP_CONTEXT IrpContext
  595. );
  596. NTSTATUS
  597. NwFsdDeviceIoControl (
  598. IN PDEVICE_OBJECT DeviceObject,
  599. IN PIRP Irp
  600. );
  601. #ifndef _PNP_POWER_
  602. VOID
  603. HandleTdiBindMessage(
  604. IN PUNICODE_STRING DeviceName
  605. );
  606. VOID
  607. HandleTdiUnbindMessage(
  608. IN PUNICODE_STRING DeviceName
  609. );
  610. #endif
  611. PLOGON
  612. FindUser(
  613. IN PLARGE_INTEGER Uid,
  614. IN BOOLEAN ExactMatch
  615. );
  616. LARGE_INTEGER
  617. GetUid(
  618. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext
  619. );
  620. BOOL
  621. IsSystemLuid();
  622. PLOGON
  623. FindUserByName(
  624. IN PUNICODE_STRING UserName
  625. );
  626. VOID
  627. LazySetShareable(
  628. PIRP_CONTEXT IrpContext,
  629. PICB pIcb,
  630. PFCB pFcb
  631. );
  632. NTSTATUS
  633. RegisterWithMup(
  634. VOID
  635. );
  636. VOID
  637. DeregisterWithMup(
  638. VOID
  639. );
  640. // FspDisp.c
  641. VOID
  642. NwFspDispatch (
  643. IN PVOID Context
  644. );
  645. NTSTATUS
  646. NwPostToFsp (
  647. IN PIRP_CONTEXT IrpContext,
  648. IN BOOLEAN MarkIrpPending
  649. );
  650. // hack.c
  651. NTSTATUS
  652. _cdecl
  653. BuildNcpResponse(
  654. PIRP_CONTEXT pIrpC,
  655. char* f,
  656. char Error,
  657. char Status,
  658. ...
  659. );
  660. NTSTATUS
  661. HackSendMessage(
  662. PIRP_CONTEXT pIrpContext
  663. );
  664. NTSTATUS
  665. _cdecl
  666. HackParseResponse(
  667. PUCHAR Response,
  668. char* FormatString,
  669. ... // format specific parameters
  670. );
  671. // Ipx.c
  672. NTSTATUS
  673. IpxOpenHandle(
  674. OUT PHANDLE pHandle,
  675. OUT PDEVICE_OBJECT* ppDeviceObject,
  676. OUT PFILE_OBJECT* pFileObject,
  677. IN PVOID EaBuffer OPTIONAL,
  678. IN ULONG EaLength
  679. );
  680. NTSTATUS
  681. IpxOpen(
  682. VOID
  683. );
  684. VOID
  685. IpxClose(
  686. VOID
  687. );
  688. VOID
  689. BuildIpxAddress(
  690. IN ULONG NetworkAddress,
  691. IN PUCHAR NodeAddress,
  692. IN USHORT Socket,
  693. OUT PTA_IPX_ADDRESS NetworkName
  694. );
  695. VOID
  696. BuildIpxAddressEa (
  697. IN ULONG NetworkAddress,
  698. IN PUCHAR NodeAddress,
  699. IN USHORT Socket,
  700. OUT PVOID NetworkName
  701. );
  702. NTSTATUS
  703. SetEventHandler (
  704. IN PIRP_CONTEXT pIrpC,
  705. IN PNW_TDI_STRUCT pTdiStruc,
  706. IN ULONG EventType,
  707. IN PVOID pEventHandler,
  708. IN PVOID pContext
  709. );
  710. NTSTATUS
  711. GetMaximumPacketSize(
  712. IN PIRP_CONTEXT pIrpContext,
  713. IN PNW_TDI_STRUCT pTdiStruct,
  714. OUT PULONG pMaximumPacketSize
  715. );
  716. NTSTATUS
  717. GetNewRoute(
  718. IN PIRP_CONTEXT pIrpContext
  719. );
  720. NTSTATUS
  721. GetTickCount(
  722. IN PIRP_CONTEXT pIrpContext,
  723. OUT PUSHORT HopCount
  724. );
  725. #ifndef QFE_BUILD
  726. NTSTATUS
  727. SubmitLineChangeRequest(
  728. VOID
  729. );
  730. #endif
  731. VOID
  732. FspProcessLineChange(
  733. IN PVOID Context
  734. );
  735. // Lock.c
  736. NTSTATUS
  737. NwFsdLockControl (
  738. IN PDEVICE_OBJECT DeviceObject,
  739. IN PIRP Irp
  740. );
  741. VOID
  742. NwFreeLocksForIcb(
  743. PIRP_CONTEXT pIrpContext,
  744. PICB Icb
  745. );
  746. // Lockcode.c
  747. VOID
  748. NwReferenceUnlockableCodeSection (
  749. VOID
  750. );
  751. VOID
  752. NwDereferenceUnlockableCodeSection (
  753. VOID
  754. );
  755. BOOLEAN
  756. NwUnlockCodeSections(
  757. BOOLEAN BlockIndefinitely
  758. );
  759. // Pid.c
  760. BOOLEAN
  761. NwInitializePidTable(
  762. // VOID
  763. IN PNONPAGED_SCB pNpScb
  764. );
  765. NTSTATUS
  766. NwMapPid(
  767. IN PNONPAGED_SCB pNpScb,
  768. IN ULONG_PTR Pid32,
  769. OUT PUCHAR Pid8
  770. );
  771. VOID
  772. NwSetEndOfJobRequired(
  773. IN PNONPAGED_SCB pNpScb,
  774. IN UCHAR Pid8
  775. );
  776. VOID
  777. NwUnmapPid(
  778. IN PNONPAGED_SCB pNpScb,
  779. IN UCHAR Pid8,
  780. IN PIRP_CONTEXT IrpContext OPTIONAL
  781. );
  782. VOID
  783. NwUninitializePidTable(
  784. IN PNONPAGED_SCB pNpScb
  785. // VOID
  786. );
  787. // Read.c
  788. NTSTATUS
  789. NwFsdRead(
  790. IN PDEVICE_OBJECT DeviceObject,
  791. IN PIRP Irp
  792. );
  793. VOID
  794. BurstReadTimeout(
  795. PIRP_CONTEXT IrpContext
  796. );
  797. NTSTATUS
  798. ResubmitBurstRead (
  799. IN PIRP_CONTEXT IrpContext
  800. );
  801. #if NWFASTIO
  802. BOOLEAN
  803. NwFastRead (
  804. IN PFILE_OBJECT FileObject,
  805. IN PLARGE_INTEGER FileOffset,
  806. IN ULONG Length,
  807. IN BOOLEAN Wait,
  808. IN ULONG LockKey,
  809. OUT PVOID Buffer,
  810. OUT PIO_STATUS_BLOCK IoStatus,
  811. IN PDEVICE_OBJECT DeviceObject
  812. );
  813. #endif
  814. // Scavenger.c
  815. VOID
  816. DisconnectTimedOutScbs(
  817. LARGE_INTEGER Now
  818. );
  819. VOID
  820. NwScavengerRoutine(
  821. IN PWORK_QUEUE_ITEM WorkItem
  822. );
  823. BOOLEAN
  824. NwAllocateExtraIrpContext(
  825. OUT PIRP_CONTEXT *ppIrpContext,
  826. IN PNONPAGED_SCB pScb
  827. );
  828. VOID
  829. NwFreeExtraIrpContext(
  830. IN PIRP_CONTEXT pIrpContext
  831. );
  832. VOID
  833. CleanupScbs(
  834. LARGE_INTEGER Now
  835. );
  836. VOID
  837. CleanupSupplementalCredentials(
  838. LARGE_INTEGER Now,
  839. BOOLEAN bShuttingDown
  840. );
  841. // Security.c
  842. VOID
  843. CreateAnsiUid(
  844. OUT PCHAR aUid,
  845. IN PLARGE_INTEGER Uid
  846. );
  847. NTSTATUS
  848. MakeUidServer(
  849. PUNICODE_STRING UidServer,
  850. PLARGE_INTEGER Uid,
  851. PUNICODE_STRING Server
  852. );
  853. NTSTATUS
  854. Logon(
  855. IN PIRP_CONTEXT IrpContext
  856. );
  857. VOID
  858. FreeLogon(
  859. IN PLOGON Logon
  860. );
  861. NTSTATUS
  862. Logoff(
  863. IN PIRP_CONTEXT IrpContext
  864. );
  865. PVCB *
  866. GetDriveMapTable (
  867. IN LARGE_INTEGER Uid
  868. );
  869. NTSTATUS
  870. UpdateUsersPassword(
  871. IN PUNICODE_STRING UserName,
  872. IN PUNICODE_STRING Password,
  873. OUT PLARGE_INTEGER Uid
  874. );
  875. NTSTATUS
  876. UpdateServerPassword(
  877. PIRP_CONTEXT IrpContext,
  878. IN PUNICODE_STRING ServerName,
  879. IN PUNICODE_STRING UserName,
  880. IN PUNICODE_STRING Password,
  881. IN PLARGE_INTEGER Uid
  882. );
  883. // String.c
  884. NTSTATUS
  885. DuplicateStringWithString (
  886. OUT PSTRING DestinationString,
  887. IN PSTRING SourceString,
  888. IN POOL_TYPE PoolType
  889. );
  890. NTSTATUS
  891. DuplicateUnicodeStringWithString (
  892. OUT PUNICODE_STRING DestinationString,
  893. IN PUNICODE_STRING SourceString,
  894. IN POOL_TYPE PoolType
  895. );
  896. NTSTATUS
  897. SetUnicodeString (
  898. IN PUNICODE_STRING Destination,
  899. IN ULONG Length,
  900. IN PWCHAR Source
  901. );
  902. VOID
  903. MergeStrings(
  904. IN PUNICODE_STRING Destination,
  905. IN PUNICODE_STRING S1,
  906. IN PUNICODE_STRING S2,
  907. IN ULONG Type
  908. );
  909. // Strucsup.c
  910. VOID
  911. NwInitializeRcb (
  912. IN PRCB Rcb
  913. );
  914. VOID
  915. NwDeleteRcb (
  916. IN PRCB Rcb
  917. );
  918. PFCB
  919. NwCreateFcb (
  920. IN PUNICODE_STRING FileName,
  921. IN PSCB Scb,
  922. IN PVCB Vcb
  923. );
  924. PFCB
  925. NwFindFcb (
  926. IN PSCB Scb,
  927. IN PVCB Vcb,
  928. IN PUNICODE_STRING FileName,
  929. IN PDCB Dcb OPTIONAL
  930. );
  931. VOID
  932. NwDereferenceFcb (
  933. IN PIRP_CONTEXT IrpContext,
  934. IN PFCB Fcb
  935. );
  936. PICB
  937. NwCreateIcb (
  938. IN USHORT Type,
  939. IN PVOID Associate
  940. );
  941. VOID
  942. NwVerifyIcb (
  943. IN PICB Icb
  944. );
  945. VOID
  946. NwVerifyIcbSpecial(
  947. IN PICB Icb
  948. );
  949. VOID
  950. NwVerifyScb (
  951. IN PSCB Scb
  952. );
  953. VOID
  954. NwDeleteIcb (
  955. IN PIRP_CONTEXT IrpContext OPTIONAL,
  956. IN PICB Icb
  957. );
  958. PVCB
  959. NwFindVcb (
  960. IN PIRP_CONTEXT IrpContext,
  961. IN PUNICODE_STRING VolumeName,
  962. IN ULONG ShareType,
  963. IN WCHAR DriveLetter,
  964. IN BOOLEAN ExplicitConnection,
  965. IN BOOLEAN FindExisting
  966. );
  967. PVCB
  968. NwCreateVcb (
  969. IN PIRP_CONTEXT IrpContext,
  970. IN PSCB Scb,
  971. IN PUNICODE_STRING VolumeName,
  972. IN ULONG ShareType,
  973. IN WCHAR DriveLetter,
  974. IN BOOLEAN ExplicitConnection
  975. );
  976. VOID
  977. NwDereferenceVcb (
  978. IN PVCB Vcb,
  979. IN PIRP_CONTEXT IrpContext OPTIONAL,
  980. IN BOOLEAN OwnRcb
  981. );
  982. VOID
  983. NwCleanupVcb(
  984. IN PVCB pVcb,
  985. IN PIRP_CONTEXT pIrpContext
  986. );
  987. VOID
  988. NwCloseAllVcbs(
  989. PIRP_CONTEXT pIrpContext
  990. );
  991. VOID
  992. NwReopenVcbHandlesForScb (
  993. IN PIRP_CONTEXT IrpContext,
  994. IN PSCB Scb
  995. );
  996. VOID
  997. NwReopenVcbHandle(
  998. IN PIRP_CONTEXT IrpContext,
  999. IN PVCB Vcb
  1000. );
  1001. ULONG
  1002. NwInvalidateAllHandles (
  1003. PLARGE_INTEGER Uid,
  1004. PIRP_CONTEXT IrpContext
  1005. );
  1006. ULONG
  1007. NwInvalidateAllHandlesForScb (
  1008. PSCB Scb
  1009. );
  1010. BOOLEAN
  1011. IsFatNameValid (
  1012. IN PUNICODE_STRING FileName
  1013. );
  1014. VOID
  1015. NwFreeDirCacheForIcb(
  1016. IN PICB Icb
  1017. );
  1018. // Timer.c
  1019. VOID
  1020. StartTimer(
  1021. );
  1022. VOID
  1023. StopTimer(
  1024. );
  1025. // Util.c
  1026. VOID
  1027. CopyBufferToMdl(
  1028. PMDL DestinationMdl,
  1029. ULONG DataOffset,
  1030. PVOID SourceData,
  1031. ULONG SourceByteCount
  1032. );
  1033. NTSTATUS
  1034. GetCredentialFromServerName(
  1035. IN PUNICODE_STRING puServerName,
  1036. OUT PUNICODE_STRING puCredentialName
  1037. );
  1038. NTSTATUS
  1039. BuildExCredentialServerName(
  1040. IN PUNICODE_STRING puServerName,
  1041. IN PUNICODE_STRING puUserName,
  1042. OUT PUNICODE_STRING puExCredServerName
  1043. );
  1044. NTSTATUS
  1045. UnmungeCredentialName(
  1046. IN PUNICODE_STRING puCredName,
  1047. OUT PUNICODE_STRING puServerName
  1048. );
  1049. BOOLEAN
  1050. IsCredentialName(
  1051. IN PUNICODE_STRING puObjectName
  1052. );
  1053. NTSTATUS
  1054. ExCreateReferenceCredentials(
  1055. PIRP_CONTEXT pIrpContext,
  1056. PUNICODE_STRING puResource
  1057. );
  1058. NTSTATUS
  1059. ExCreateDereferenceCredentials(
  1060. PIRP_CONTEXT pIrpContext,
  1061. PNDS_SECURITY_CONTEXT pNdsCredentials
  1062. );
  1063. // VolInfo.c
  1064. NTSTATUS
  1065. NwFsdQueryVolumeInformation (
  1066. IN PDEVICE_OBJECT DeviceObject,
  1067. IN PIRP Irp
  1068. );
  1069. NTSTATUS
  1070. NwFsdSetVolumeInformation (
  1071. IN PDEVICE_OBJECT DeviceObject,
  1072. IN PIRP Irp
  1073. );
  1074. // WorkQue.c
  1075. PIRP_CONTEXT
  1076. AllocateIrpContext (
  1077. PIRP pIrp
  1078. );
  1079. VOID
  1080. FreeIrpContext (
  1081. PIRP_CONTEXT IrpContext
  1082. );
  1083. VOID
  1084. InitializeIrpContext (
  1085. VOID
  1086. );
  1087. VOID
  1088. UninitializeIrpContext (
  1089. VOID
  1090. );
  1091. VOID
  1092. NwCompleteRequest (
  1093. PIRP_CONTEXT IrpContext,
  1094. NTSTATUS Status
  1095. );
  1096. VOID
  1097. NwAppendToQueueAndWait(
  1098. PIRP_CONTEXT IrpContext
  1099. );
  1100. VOID
  1101. NwDequeueIrpContext(
  1102. IN PIRP_CONTEXT IrpContext,
  1103. IN BOOLEAN OwnSpinLock
  1104. );
  1105. VOID
  1106. NwCancelIrp (
  1107. IN PDEVICE_OBJECT DeviceObject,
  1108. IN PIRP Irp
  1109. );
  1110. PIRP
  1111. NwAllocateSendIrp (
  1112. PIRP_CONTEXT IrpContext
  1113. );
  1114. PMINI_IRP_CONTEXT
  1115. AllocateMiniIrpContext (
  1116. PIRP_CONTEXT IrpContext
  1117. );
  1118. VOID
  1119. FreeMiniIrpContext (
  1120. PMINI_IRP_CONTEXT MiniIrpContext
  1121. );
  1122. PWORK_CONTEXT
  1123. AllocateWorkContext (
  1124. VOID
  1125. );
  1126. VOID
  1127. FreeWorkContext (
  1128. PWORK_CONTEXT
  1129. );
  1130. VOID
  1131. SpawnWorkerThread (
  1132. VOID
  1133. );
  1134. VOID
  1135. WorkerThread (
  1136. VOID
  1137. );
  1138. VOID
  1139. TerminateWorkerThread (
  1140. VOID
  1141. );
  1142. // Write.c
  1143. NTSTATUS
  1144. NwFsdWrite(
  1145. IN PDEVICE_OBJECT DeviceObject,
  1146. IN PIRP Irp
  1147. );
  1148. NTSTATUS
  1149. DoWrite(
  1150. PIRP_CONTEXT IrpContext,
  1151. LARGE_INTEGER ByteOffset,
  1152. ULONG BufferLength,
  1153. PVOID WriteBuffer,
  1154. PMDL WriteMdl
  1155. );
  1156. NTSTATUS
  1157. NwFsdFlushBuffers(
  1158. IN PDEVICE_OBJECT DeviceObject,
  1159. IN PIRP Irp
  1160. );
  1161. NTSTATUS
  1162. ResubmitBurstWrite(
  1163. PIRP_CONTEXT IrpContext
  1164. );
  1165. #if NWFASTIO
  1166. BOOLEAN
  1167. NwFastWrite (
  1168. IN PFILE_OBJECT FileObject,
  1169. IN PLARGE_INTEGER FileOffset,
  1170. IN ULONG Length,
  1171. IN BOOLEAN Wait,
  1172. IN ULONG LockKey,
  1173. OUT PVOID Buffer,
  1174. OUT PIO_STATUS_BLOCK IoStatus,
  1175. IN PDEVICE_OBJECT DeviceObject
  1176. );
  1177. #endif
  1178. #ifdef _PNP_POWER_
  1179. //
  1180. // NwPnP.C
  1181. //
  1182. NTSTATUS
  1183. StartRedirector(
  1184. PIRP_CONTEXT IrpContext
  1185. );
  1186. NTSTATUS
  1187. StopRedirector(
  1188. IN PIRP_CONTEXT IrpContext
  1189. );
  1190. NTSTATUS
  1191. RegisterTdiPnPEventHandlers(
  1192. IN PIRP_CONTEXT IrpContext
  1193. );
  1194. NTSTATUS
  1195. PnPSetPower(
  1196. PNET_PNP_EVENT pEvent,
  1197. PTDI_PNP_CONTEXT pContext1,
  1198. PTDI_PNP_CONTEXT pContext2
  1199. );
  1200. NTSTATUS
  1201. PnPQueryPower(
  1202. PNET_PNP_EVENT pEvent,
  1203. PTDI_PNP_CONTEXT pContext1,
  1204. PTDI_PNP_CONTEXT pContext2
  1205. );
  1206. NTSTATUS
  1207. PnPQueryRemove(
  1208. PNET_PNP_EVENT pEvent,
  1209. PTDI_PNP_CONTEXT pContext1,
  1210. PTDI_PNP_CONTEXT pContext2
  1211. );
  1212. NTSTATUS
  1213. PnPCancelRemove(
  1214. PNET_PNP_EVENT pEvent,
  1215. PTDI_PNP_CONTEXT pContext1,
  1216. PTDI_PNP_CONTEXT pContext2
  1217. );
  1218. ULONG
  1219. PnPCountActiveHandles(
  1220. VOID
  1221. );
  1222. NTSTATUS
  1223. NwFsdProcessPnpIrp(
  1224. IN PDEVICE_OBJECT DeviceObject,
  1225. IN PIRP Irp
  1226. );
  1227. NTSTATUS
  1228. PnpIrpCompletion(
  1229. PDEVICE_OBJECT pDeviceObject,
  1230. PIRP pIrp,
  1231. PVOID pContext
  1232. );
  1233. NTSTATUS
  1234. NwCommonProcessPnpIrp (
  1235. IN PIRP_CONTEXT IrpContext
  1236. );
  1237. #endif
  1238. //
  1239. // A function that returns finished denotes if it was able to complete the
  1240. // operation (TRUE) or could not complete the operation (FALSE) because the
  1241. // wait value stored in the irp context was false and we would have had
  1242. // to block for a resource or I/O
  1243. //
  1244. typedef BOOLEAN FINISHED;
  1245. //
  1246. // Miscellaneous support routines
  1247. //
  1248. //
  1249. // This macro returns TRUE if a flag in a set of flags is on and FALSE
  1250. // otherwise. It is followed by two macros for setting and clearing
  1251. // flags
  1252. //
  1253. #ifndef BooleanFlagOn
  1254. #define BooleanFlagOn(Flags,SingleFlag) ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))
  1255. #endif
  1256. #ifndef SetFlag
  1257. #define SetFlag(Flags,SingleFlag) { \
  1258. (Flags) |= (SingleFlag); \
  1259. }
  1260. #endif
  1261. #ifndef ClearFlag
  1262. #define ClearFlag(Flags,SingleFlag) { \
  1263. (Flags) &= ~(SingleFlag); \
  1264. }
  1265. #endif
  1266. //
  1267. // The following macro is used to determine if an FSD thread can block
  1268. // for I/O or wait for a resource. It returns TRUE if the thread can
  1269. // block and FALSE otherwise. This attribute can then be used to call
  1270. // the FSD & FSP common work routine with the proper wait value.
  1271. //
  1272. #define CanFsdWait(IRP) IoIsOperationSynchronous(IRP)
  1273. //
  1274. // This macro takes a pointer (or ulong) and returns its rounded up word
  1275. // value
  1276. //
  1277. #define WordAlign(Ptr) ( \
  1278. ((((ULONG)(Ptr)) + 1) & 0xfffffffe) \
  1279. )
  1280. //
  1281. // This macro takes a pointer (or ulong) and returns its rounded up longword
  1282. // value
  1283. //
  1284. #define LongAlign(Ptr) ( \
  1285. ((((ULONG)(Ptr)) + 3) & 0xfffffffc) \
  1286. )
  1287. //
  1288. // This macro takes a pointer (or ulong) and returns its rounded up quadword
  1289. // value
  1290. //
  1291. #define QuadAlign(Ptr) ( \
  1292. ((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
  1293. )
  1294. //
  1295. // The following two macro are used by the Fsd/Fsp exception handlers to
  1296. // process an exception. The first macro is the exception filter used in the
  1297. // Fsd/Fsp to decide if an exception should be handled at this level.
  1298. // The second macro decides if the exception is to be finished off by
  1299. // completing the IRP, and cleaning up the Irp Context, or if we should
  1300. // bugcheck. Exception values such as STATUS_FILE_INVALID (raised by
  1301. // VerfySup.c) cause us to complete the Irp and cleanup, while exceptions
  1302. // such as accvio cause us to bugcheck.
  1303. //
  1304. // The basic structure for fsd/fsp exception handling is as follows:
  1305. //
  1306. // NwFsdXxx(...)
  1307. // {
  1308. // try {
  1309. //
  1310. // ...
  1311. //
  1312. // } except(NwExceptionFilter( IrpContext, GetExceptionCode() )) {
  1313. //
  1314. // Status = NwProcessException( IrpContext, Irp, GetExceptionCode() );
  1315. // }
  1316. //
  1317. // Return Status;
  1318. // }
  1319. //
  1320. // To explicitly raise an exception that we expect, such as
  1321. // STATUS_FILE_INVALID, use the below macro NwRaiseStatus(). To raise a
  1322. // status from an unknown origin (such as CcFlushCache()), use the macro
  1323. // NwNormalizeAndRaiseStatus. This will raise the status if it is expected,
  1324. // or raise STATUS_UNEXPECTED_IO_ERROR if it is not.
  1325. //
  1326. // Note that when using these two macros, the original status is placed in
  1327. // IrpContext->ExceptionStatus, signaling NwExceptionFilter and
  1328. // NwProcessException that the status we actually raise is by definition
  1329. // expected.
  1330. //
  1331. LONG
  1332. NwExceptionFilter (
  1333. IN PIRP Irp,
  1334. IN PEXCEPTION_POINTERS ExceptionPointer
  1335. );
  1336. NTSTATUS
  1337. NwProcessException (
  1338. IN PIRP_CONTEXT IrpContext,
  1339. IN NTSTATUS ExceptionCode
  1340. );
  1341. //
  1342. // VOID
  1343. // NwRaiseStatus (
  1344. // IN NT_STATUS Status
  1345. // );
  1346. //
  1347. //
  1348. #define NwRaiseStatus(IRPCONTEXT,STATUS) { \
  1349. ExRaiseStatus( (STATUS) ); \
  1350. KeBugCheck( NW_FILE_SYSTEM ); \
  1351. }
  1352. //
  1353. // VOID
  1354. // NwNormalAndRaiseStatus (
  1355. // IN NT_STATUS Status
  1356. // );
  1357. //
  1358. #define NwNormalizeAndRaiseStatus(IRPCONTEXT,STATUS) { \
  1359. if ((STATUS) == STATUS_VERIFY_REQUIRED) { ExRaiseStatus((STATUS)); } \
  1360. ExRaiseStatus(FsRtlNormalizeNtstatus((STATUS),STATUS_UNEXPECTED_IO_ERROR)); \
  1361. KeBugCheck( NW_FILE_SYSTEM ); \
  1362. }
  1363. //
  1364. // The Following routine makes a popup
  1365. //
  1366. #define NwRaiseInformationalHardError(STATUS,NAME) { \
  1367. UNICODE_STRING Name; \
  1368. if (NT_SUCCESS(RtlOemStringToCountedUnicodeString(&Name, (NAME), TRUE))) { \
  1369. IoRaiseInformationalHardError(Status, &Name, (Irp == NULL ?\
  1370. NULL : &(Irp->Tail.Overlay.Thread)->Tcb)); \
  1371. RtlFreeUnicodeString(&Name); \
  1372. } \
  1373. }
  1374. //
  1375. // The following macros are used to establish the semantics needed
  1376. // to do a return from within a try-finally clause. As a rule every
  1377. // try clause must end with a label call try_exit. For example,
  1378. //
  1379. // try {
  1380. // :
  1381. // :
  1382. //
  1383. // try_exit: NOTHING;
  1384. // } finally {
  1385. //
  1386. // :
  1387. // :
  1388. // }
  1389. //
  1390. // Every return statement executed inside of a try clause should use the
  1391. // try_return macro. If the compiler fully supports the try-finally construct
  1392. // then the macro should be
  1393. //
  1394. // #define try_return(S) { return(S); }
  1395. //
  1396. // If the compiler does not support the try-finally construct then the macro
  1397. // should be
  1398. //
  1399. // #define try_return(S) { S; goto try_exit; }
  1400. //
  1401. #define try_return(S) { S; goto try_exit; }
  1402. #if NWDBG
  1403. #define InternalError(String) { \
  1404. DbgPrint("Internal NetWare Redirector Error "); \
  1405. DbgPrint String; \
  1406. DbgPrint("\nFile %s, Line %d\n", __FILE__, __LINE__); \
  1407. ASSERT(FALSE); \
  1408. }
  1409. #else
  1410. #define InternalError(String) {NOTHING;}
  1411. #endif
  1412. #define DbgPrintf DbgPrint
  1413. //
  1414. // Reference and dereference Macros.
  1415. //
  1416. VOID
  1417. RefDbgTrace (
  1418. PVOID Resource,
  1419. DWORD Count,
  1420. BOOLEAN Reference,
  1421. PBYTE FileName,
  1422. UINT Line
  1423. );
  1424. #ifdef NWDBG
  1425. VOID
  1426. ChkNwReferenceScb(
  1427. PNONPAGED_SCB pNpScb,
  1428. PBYTE FileName,
  1429. UINT Line,
  1430. BOOLEAN Silent
  1431. );
  1432. VOID
  1433. ChkNwDereferenceScb(
  1434. PNONPAGED_SCB pNpScb,
  1435. PBYTE FileName,
  1436. UINT Line,
  1437. BOOLEAN Silent
  1438. );
  1439. #define NwReferenceScb( pNpScb ) \
  1440. ChkNwReferenceScb( pNpScb, __FILE__, __LINE__, FALSE )
  1441. #define NwQuietReferenceScb( pNpScb ) \
  1442. ChkNwReferenceScb( pNpScb, __FILE__, __LINE__, TRUE )
  1443. #define NwDereferenceScb( pNpScb ) \
  1444. ChkNwDereferenceScb( pNpScb, __FILE__, __LINE__, FALSE )
  1445. #define NwQuietDereferenceScb( pNpScb ) \
  1446. ChkNwDereferenceScb( pNpScb, __FILE__, __LINE__, TRUE )
  1447. #else
  1448. #define NwReferenceScb( pNpScb ) \
  1449. InterlockedIncrement( &(pNpScb)->Reference )
  1450. #define NwQuietReferenceScb( pNpScb ) \
  1451. InterlockedIncrement( &(pNpScb)->Reference )
  1452. #define NwDereferenceScb( pNpScb ) \
  1453. InterlockedDecrement( &(pNpScb)->Reference )
  1454. #define NwQuietDereferenceScb( pNpScb ) \
  1455. InterlockedDecrement( &(pNpScb)->Reference )
  1456. #endif
  1457. //
  1458. // Irpcontext event macro.
  1459. //
  1460. #define NwSetIrpContextEvent( pIrpContext ) \
  1461. DebugTrace( 0, DEBUG_TRACE_WORKQUE, "Set event for IrpC = %08lx\n", pIrpContext ); \
  1462. DebugTrace( 0, DEBUG_TRACE_WORKQUE, "IrpC->pNpScb = %08lx\n", pIrpContext->pNpScb ); \
  1463. KeSetEvent( &pIrpContext->Event, 0, FALSE )
  1464. //
  1465. // VCB macros must be called with the RCB resource held.
  1466. //
  1467. #if NWDBG
  1468. VOID
  1469. NwReferenceVcb (
  1470. IN PVCB Vcb
  1471. );
  1472. #else
  1473. #define NwReferenceVcb( pVcb ) ++(pVcb)->Reference;
  1474. #endif
  1475. //
  1476. // Resource acquisition and release macros
  1477. //
  1478. #if NWDBG
  1479. VOID
  1480. NwAcquireExclusiveRcb(
  1481. PRCB Rcb,
  1482. BOOLEAN Wait
  1483. );
  1484. VOID
  1485. NwAcquireSharedRcb(
  1486. PRCB Rcb,
  1487. BOOLEAN Wait
  1488. );
  1489. VOID
  1490. NwReleaseRcb(
  1491. PRCB Rcb
  1492. );
  1493. VOID
  1494. NwAcquireExclusiveFcb(
  1495. PNONPAGED_FCB pFcb,
  1496. BOOLEAN Wait
  1497. );
  1498. VOID
  1499. NwAcquireSharedFcb(
  1500. PNONPAGED_FCB pFcb,
  1501. BOOLEAN Wait
  1502. );
  1503. VOID
  1504. NwReleaseFcb(
  1505. PNONPAGED_FCB pFcb
  1506. );
  1507. VOID
  1508. NwAcquireOpenLock(
  1509. VOID
  1510. );
  1511. VOID
  1512. NwReleaseOpenLock(
  1513. VOID
  1514. );
  1515. #else
  1516. #define NwAcquireExclusiveRcb( Rcb, Wait ) \
  1517. ExAcquireResourceExclusiveLite( &((Rcb)->Resource), Wait )
  1518. #define NwAcquireSharedRcb( Rcb, Wait ) \
  1519. ExAcquireResourceSharedLite( &((Rcb)->Resource), Wait )
  1520. #define NwReleaseRcb( Rcb ) \
  1521. ExReleaseResourceLite( &((Rcb)->Resource) )
  1522. #define NwAcquireExclusiveFcb( pFcb, Wait ) \
  1523. ExAcquireResourceExclusiveLite( &((pFcb)->Resource), Wait )
  1524. #define NwAcquireSharedFcb( pFcb, Wait ) \
  1525. ExAcquireResourceSharedLite( &((pFcb)->Resource), Wait )
  1526. #define NwReleaseFcb( pFcb ) \
  1527. ExReleaseResourceLite( &((pFcb)->Resource) )
  1528. #define NwAcquireOpenLock( ) \
  1529. ExAcquireResourceExclusiveLite( &NwOpenResource, TRUE )
  1530. #define NwReleaseOpenLock( ) \
  1531. ExReleaseResourceLite( &NwOpenResource )
  1532. #endif
  1533. #define NwReleaseFcbForThread( pFcb, pThread ) \
  1534. ExReleaseResourceForThreadLite( &((pFcb)->Resource), pThread )
  1535. //
  1536. // Memory allocation and deallocation macros
  1537. //
  1538. #ifdef NWDBG
  1539. #define ALLOCATE_POOL_EX( Type, Size ) NwAllocatePool( Type, Size, TRUE )
  1540. #define ALLOCATE_POOL( Type, Size ) NwAllocatePool( Type, Size, FALSE )
  1541. #define FREE_POOL( Buffer ) NwFreePool( Buffer )
  1542. #define ALLOCATE_IRP( Size, ChargeQuota ) \
  1543. NwAllocateIrp( Size, ChargeQuota )
  1544. #define FREE_IRP( Irp ) NwFreeIrp( Irp )
  1545. #define ALLOCATE_MDL( Va, Length, Secondary, ChargeQuota, Irp ) \
  1546. NwAllocateMdl(Va, Length, Secondary, ChargeQuota, Irp, __FILE__, __LINE__ )
  1547. #define FREE_MDL( Mdl ) NwFreeMdl( Mdl )
  1548. #else
  1549. #define ALLOCATE_POOL_EX( Type, Size ) FsRtlAllocatePoolWithTag( Type, Size, 'scwn' )
  1550. #ifndef QFE_BUILD
  1551. #define ALLOCATE_POOL( Type, Size ) ExAllocatePoolWithTag( Type, Size, 'scwn' )
  1552. #else
  1553. #define ALLOCATE_POOL( Type, Size ) ExAllocatePool( Type, Size )
  1554. #endif
  1555. #define FREE_POOL( Buffer ) ExFreePool( Buffer )
  1556. #define ALLOCATE_IRP( Size, ChargeQuota ) \
  1557. IoAllocateIrp( Size, ChargeQuota )
  1558. #define FREE_IRP( Irp ) IoFreeIrp( Irp )
  1559. #define ALLOCATE_MDL( Va, Length, Secondary, ChargeQuota, Irp ) \
  1560. IoAllocateMdl(Va, Length, Secondary, ChargeQuota, Irp )
  1561. #define FREE_MDL( Mdl ) IoFreeMdl( Mdl )
  1562. #endif
  1563. //
  1564. // Useful macros
  1565. //
  1566. #define MIN(a,b) ((a)<(b) ? (a):(b))
  1567. #define MAX(a,b) ((a)>(b) ? (a):(b))
  1568. #define DIFFERENT_PAGES( START, SIZE ) \
  1569. (((ULONG)START & ~(4096-1)) != (((ULONG)START + SIZE) & ~(4096-1)))
  1570. #define UP_LEVEL_SERVER( Scb ) \
  1571. ( ( Scb->MajorVersion >= 4 ) || \
  1572. ( Scb->MajorVersion == 3 && Scb->MinorVersion >= 12 ) )
  1573. #define LFN_SUPPORTED( Scb ) \
  1574. ( ( Scb->MajorVersion >= 4 ) || \
  1575. ( Scb->MajorVersion == 3 && Scb->MinorVersion >= 11 ) )
  1576. #define LongByteSwap( l1, l2 ) \
  1577. { \
  1578. PUCHAR c1 = (PUCHAR)&l1; \
  1579. PUCHAR c2 = (PUCHAR)&l2; \
  1580. c1[0] = c2[3]; \
  1581. c1[1] = c2[2]; \
  1582. c1[2] = c2[1]; \
  1583. c1[3] = c2[0]; \
  1584. }
  1585. #define ShortByteSwap( s1, s2 ) \
  1586. { \
  1587. PUCHAR c1 = (PUCHAR)&s1; \
  1588. PUCHAR c2 = (PUCHAR)&s2; \
  1589. c1[0] = c2[1]; \
  1590. c1[1] = c2[0]; \
  1591. }
  1592. #define CanLogTimeOutEvent( LastTime, CurrentTime ) \
  1593. ( ( CurrentTime.QuadPart ) - ( LastTime.QuadPart ) >= 0 )
  1594. #define UpdateNextEventTime( LastTime, CurrentTime, TimeOutEventInterval ) \
  1595. ( LastTime.QuadPart ) = ( CurrentTime.QuadPart ) + \
  1596. ( TimeOutEventInterval.QuadPart )
  1597. //
  1598. // Macros to isolate NT 3.1 and NT 3.5 differences.
  1599. //
  1600. #ifdef QFE_BUILD
  1601. #define NwGetTopLevelIrp() (PIRP)(PsGetCurrentThread()->TopLevelIrp)
  1602. #define NwSetTopLevelIrp(Irp) (PIRP)(PsGetCurrentThread())->TopLevelIrp = Irp;
  1603. #else
  1604. #define NwGetTopLevelIrp() IoGetTopLevelIrp()
  1605. #define NwSetTopLevelIrp(Irp) IoSetTopLevelIrp(Irp)
  1606. #endif
  1607. //
  1608. // David Goebel - pls figure out which file below should come from
  1609. // io.h cannot be included successfully
  1610. //
  1611. NTKERNELAPI
  1612. VOID
  1613. IoRemoveShareAccess(
  1614. IN PFILE_OBJECT FileObject,
  1615. IN OUT PSHARE_ACCESS ShareAccess
  1616. );
  1617. // now all SKUs have TerminalServer flag. If App Server is enabled, SingleUserTS flag is cleared
  1618. #define IsTerminalServer() !(ExVerifySuite(SingleUserTS))
  1619. #endif // _NWPROCS_