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.

2002 lines
34 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. PLOGON
  621. FindUserByName(
  622. IN PUNICODE_STRING UserName
  623. );
  624. VOID
  625. LazySetShareable(
  626. PIRP_CONTEXT IrpContext,
  627. PICB pIcb,
  628. PFCB pFcb
  629. );
  630. NTSTATUS
  631. RegisterWithMup(
  632. VOID
  633. );
  634. VOID
  635. DeregisterWithMup(
  636. VOID
  637. );
  638. // FspDisp.c
  639. VOID
  640. NwFspDispatch (
  641. IN PVOID Context
  642. );
  643. NTSTATUS
  644. NwPostToFsp (
  645. IN PIRP_CONTEXT IrpContext,
  646. IN BOOLEAN MarkIrpPending
  647. );
  648. // hack.c
  649. NTSTATUS
  650. _cdecl
  651. BuildNcpResponse(
  652. PIRP_CONTEXT pIrpC,
  653. char* f,
  654. char Error,
  655. char Status,
  656. ...
  657. );
  658. NTSTATUS
  659. HackSendMessage(
  660. PIRP_CONTEXT pIrpContext
  661. );
  662. NTSTATUS
  663. _cdecl
  664. HackParseResponse(
  665. PUCHAR Response,
  666. char* FormatString,
  667. ... // format specific parameters
  668. );
  669. // Ipx.c
  670. NTSTATUS
  671. IpxOpenHandle(
  672. OUT PHANDLE pHandle,
  673. OUT PDEVICE_OBJECT* ppDeviceObject,
  674. OUT PFILE_OBJECT* pFileObject,
  675. IN PVOID EaBuffer OPTIONAL,
  676. IN ULONG EaLength
  677. );
  678. NTSTATUS
  679. IpxOpen(
  680. VOID
  681. );
  682. VOID
  683. IpxClose(
  684. VOID
  685. );
  686. VOID
  687. BuildIpxAddress(
  688. IN ULONG NetworkAddress,
  689. IN PUCHAR NodeAddress,
  690. IN USHORT Socket,
  691. OUT PTA_IPX_ADDRESS NetworkName
  692. );
  693. VOID
  694. BuildIpxAddressEa (
  695. IN ULONG NetworkAddress,
  696. IN PUCHAR NodeAddress,
  697. IN USHORT Socket,
  698. OUT PVOID NetworkName
  699. );
  700. NTSTATUS
  701. SetEventHandler (
  702. IN PIRP_CONTEXT pIrpC,
  703. IN PNW_TDI_STRUCT pTdiStruc,
  704. IN ULONG EventType,
  705. IN PVOID pEventHandler,
  706. IN PVOID pContext
  707. );
  708. NTSTATUS
  709. GetMaximumPacketSize(
  710. IN PIRP_CONTEXT pIrpContext,
  711. IN PNW_TDI_STRUCT pTdiStruct,
  712. OUT PULONG pMaximumPacketSize
  713. );
  714. NTSTATUS
  715. GetNewRoute(
  716. IN PIRP_CONTEXT pIrpContext
  717. );
  718. NTSTATUS
  719. GetTickCount(
  720. IN PIRP_CONTEXT pIrpContext,
  721. OUT PUSHORT HopCount
  722. );
  723. #ifndef QFE_BUILD
  724. NTSTATUS
  725. SubmitLineChangeRequest(
  726. VOID
  727. );
  728. #endif
  729. VOID
  730. FspProcessLineChange(
  731. IN PVOID Context
  732. );
  733. // Lock.c
  734. NTSTATUS
  735. NwFsdLockControl (
  736. IN PDEVICE_OBJECT DeviceObject,
  737. IN PIRP Irp
  738. );
  739. VOID
  740. NwFreeLocksForIcb(
  741. PIRP_CONTEXT pIrpContext,
  742. PICB Icb
  743. );
  744. // Lockcode.c
  745. VOID
  746. NwReferenceUnlockableCodeSection (
  747. VOID
  748. );
  749. VOID
  750. NwDereferenceUnlockableCodeSection (
  751. VOID
  752. );
  753. BOOLEAN
  754. NwUnlockCodeSections(
  755. BOOLEAN BlockIndefinitely
  756. );
  757. // Pid.c
  758. BOOLEAN
  759. NwInitializePidTable(
  760. // VOID
  761. IN PNONPAGED_SCB pNpScb
  762. );
  763. NTSTATUS
  764. NwMapPid(
  765. IN PNONPAGED_SCB pNpScb,
  766. IN ULONG_PTR Pid32,
  767. OUT PUCHAR Pid8
  768. );
  769. VOID
  770. NwSetEndOfJobRequired(
  771. IN PNONPAGED_SCB pNpScb,
  772. IN UCHAR Pid8
  773. );
  774. VOID
  775. NwUnmapPid(
  776. IN PNONPAGED_SCB pNpScb,
  777. IN UCHAR Pid8,
  778. IN PIRP_CONTEXT IrpContext OPTIONAL
  779. );
  780. VOID
  781. NwUninitializePidTable(
  782. IN PNONPAGED_SCB pNpScb
  783. // VOID
  784. );
  785. // Read.c
  786. NTSTATUS
  787. NwFsdRead(
  788. IN PDEVICE_OBJECT DeviceObject,
  789. IN PIRP Irp
  790. );
  791. VOID
  792. BurstReadTimeout(
  793. PIRP_CONTEXT IrpContext
  794. );
  795. NTSTATUS
  796. ResubmitBurstRead (
  797. IN PIRP_CONTEXT IrpContext
  798. );
  799. #if NWFASTIO
  800. BOOLEAN
  801. NwFastRead (
  802. IN PFILE_OBJECT FileObject,
  803. IN PLARGE_INTEGER FileOffset,
  804. IN ULONG Length,
  805. IN BOOLEAN Wait,
  806. IN ULONG LockKey,
  807. OUT PVOID Buffer,
  808. OUT PIO_STATUS_BLOCK IoStatus,
  809. IN PDEVICE_OBJECT DeviceObject
  810. );
  811. #endif
  812. // Scavenger.c
  813. VOID
  814. DisconnectTimedOutScbs(
  815. LARGE_INTEGER Now
  816. );
  817. VOID
  818. NwScavengerRoutine(
  819. IN PWORK_QUEUE_ITEM WorkItem
  820. );
  821. BOOLEAN
  822. NwAllocateExtraIrpContext(
  823. OUT PIRP_CONTEXT *ppIrpContext,
  824. IN PNONPAGED_SCB pScb
  825. );
  826. VOID
  827. NwFreeExtraIrpContext(
  828. IN PIRP_CONTEXT pIrpContext
  829. );
  830. VOID
  831. CleanupScbs(
  832. LARGE_INTEGER Now
  833. );
  834. VOID
  835. CleanupSupplementalCredentials(
  836. LARGE_INTEGER Now,
  837. BOOLEAN bShuttingDown
  838. );
  839. // Security.c
  840. VOID
  841. CreateAnsiUid(
  842. OUT PCHAR aUid,
  843. IN PLARGE_INTEGER Uid
  844. );
  845. NTSTATUS
  846. MakeUidServer(
  847. PUNICODE_STRING UidServer,
  848. PLARGE_INTEGER Uid,
  849. PUNICODE_STRING Server
  850. );
  851. NTSTATUS
  852. Logon(
  853. IN PIRP_CONTEXT IrpContext
  854. );
  855. VOID
  856. FreeLogon(
  857. IN PLOGON Logon
  858. );
  859. NTSTATUS
  860. Logoff(
  861. IN PIRP_CONTEXT IrpContext
  862. );
  863. PVCB *
  864. GetDriveMapTable (
  865. IN LARGE_INTEGER Uid
  866. );
  867. NTSTATUS
  868. UpdateUsersPassword(
  869. IN PUNICODE_STRING UserName,
  870. IN PUNICODE_STRING Password,
  871. OUT PLARGE_INTEGER Uid
  872. );
  873. NTSTATUS
  874. UpdateServerPassword(
  875. PIRP_CONTEXT IrpContext,
  876. IN PUNICODE_STRING ServerName,
  877. IN PUNICODE_STRING UserName,
  878. IN PUNICODE_STRING Password,
  879. IN PLARGE_INTEGER Uid
  880. );
  881. // String.c
  882. NTSTATUS
  883. DuplicateStringWithString (
  884. OUT PSTRING DestinationString,
  885. IN PSTRING SourceString,
  886. IN POOL_TYPE PoolType
  887. );
  888. NTSTATUS
  889. DuplicateUnicodeStringWithString (
  890. OUT PUNICODE_STRING DestinationString,
  891. IN PUNICODE_STRING SourceString,
  892. IN POOL_TYPE PoolType
  893. );
  894. NTSTATUS
  895. SetUnicodeString (
  896. IN PUNICODE_STRING Destination,
  897. IN ULONG Length,
  898. IN PWCHAR Source
  899. );
  900. VOID
  901. MergeStrings(
  902. IN PUNICODE_STRING Destination,
  903. IN PUNICODE_STRING S1,
  904. IN PUNICODE_STRING S2,
  905. IN ULONG Type
  906. );
  907. // Strucsup.c
  908. VOID
  909. NwInitializeRcb (
  910. IN PRCB Rcb
  911. );
  912. VOID
  913. NwDeleteRcb (
  914. IN PRCB Rcb
  915. );
  916. PFCB
  917. NwCreateFcb (
  918. IN PUNICODE_STRING FileName,
  919. IN PSCB Scb,
  920. IN PVCB Vcb
  921. );
  922. PFCB
  923. NwFindFcb (
  924. IN PSCB Scb,
  925. IN PVCB Vcb,
  926. IN PUNICODE_STRING FileName,
  927. IN PDCB Dcb OPTIONAL
  928. );
  929. VOID
  930. NwDereferenceFcb (
  931. IN PIRP_CONTEXT IrpContext,
  932. IN PFCB Fcb
  933. );
  934. PICB
  935. NwCreateIcb (
  936. IN USHORT Type,
  937. IN PVOID Associate
  938. );
  939. VOID
  940. NwVerifyIcb (
  941. IN PICB Icb
  942. );
  943. VOID
  944. NwVerifyIcbSpecial(
  945. IN PICB Icb
  946. );
  947. VOID
  948. NwVerifyScb (
  949. IN PSCB Scb
  950. );
  951. VOID
  952. NwDeleteIcb (
  953. IN PIRP_CONTEXT IrpContext OPTIONAL,
  954. IN PICB Icb
  955. );
  956. PVCB
  957. NwFindVcb (
  958. IN PIRP_CONTEXT IrpContext,
  959. IN PUNICODE_STRING VolumeName,
  960. IN ULONG ShareType,
  961. IN WCHAR DriveLetter,
  962. IN BOOLEAN ExplicitConnection,
  963. IN BOOLEAN FindExisting
  964. );
  965. PVCB
  966. NwCreateVcb (
  967. IN PIRP_CONTEXT IrpContext,
  968. IN PSCB Scb,
  969. IN PUNICODE_STRING VolumeName,
  970. IN ULONG ShareType,
  971. IN WCHAR DriveLetter,
  972. IN BOOLEAN ExplicitConnection
  973. );
  974. VOID
  975. NwDereferenceVcb (
  976. IN PVCB Vcb,
  977. IN PIRP_CONTEXT IrpContext OPTIONAL,
  978. IN BOOLEAN OwnRcb
  979. );
  980. VOID
  981. NwCleanupVcb(
  982. IN PVCB pVcb,
  983. IN PIRP_CONTEXT pIrpContext
  984. );
  985. VOID
  986. NwCloseAllVcbs(
  987. PIRP_CONTEXT pIrpContext
  988. );
  989. VOID
  990. NwReopenVcbHandlesForScb (
  991. IN PIRP_CONTEXT IrpContext,
  992. IN PSCB Scb
  993. );
  994. VOID
  995. NwReopenVcbHandle(
  996. IN PIRP_CONTEXT IrpContext,
  997. IN PVCB Vcb
  998. );
  999. ULONG
  1000. NwInvalidateAllHandles (
  1001. PLARGE_INTEGER Uid,
  1002. PIRP_CONTEXT IrpContext
  1003. );
  1004. ULONG
  1005. NwInvalidateAllHandlesForScb (
  1006. PSCB Scb
  1007. );
  1008. BOOLEAN
  1009. IsFatNameValid (
  1010. IN PUNICODE_STRING FileName
  1011. );
  1012. VOID
  1013. NwFreeDirCacheForIcb(
  1014. IN PICB Icb
  1015. );
  1016. // Timer.c
  1017. VOID
  1018. StartTimer(
  1019. );
  1020. VOID
  1021. StopTimer(
  1022. );
  1023. // Util.c
  1024. VOID
  1025. CopyBufferToMdl(
  1026. PMDL DestinationMdl,
  1027. ULONG DataOffset,
  1028. PVOID SourceData,
  1029. ULONG SourceByteCount
  1030. );
  1031. NTSTATUS
  1032. GetCredentialFromServerName(
  1033. IN PUNICODE_STRING puServerName,
  1034. OUT PUNICODE_STRING puCredentialName
  1035. );
  1036. NTSTATUS
  1037. BuildExCredentialServerName(
  1038. IN PUNICODE_STRING puServerName,
  1039. IN PUNICODE_STRING puUserName,
  1040. OUT PUNICODE_STRING puExCredServerName
  1041. );
  1042. NTSTATUS
  1043. UnmungeCredentialName(
  1044. IN PUNICODE_STRING puCredName,
  1045. OUT PUNICODE_STRING puServerName
  1046. );
  1047. BOOLEAN
  1048. IsCredentialName(
  1049. IN PUNICODE_STRING puObjectName
  1050. );
  1051. NTSTATUS
  1052. ExCreateReferenceCredentials(
  1053. PIRP_CONTEXT pIrpContext,
  1054. PUNICODE_STRING puResource
  1055. );
  1056. NTSTATUS
  1057. ExCreateDereferenceCredentials(
  1058. PIRP_CONTEXT pIrpContext,
  1059. PNDS_SECURITY_CONTEXT pNdsCredentials
  1060. );
  1061. // VolInfo.c
  1062. NTSTATUS
  1063. NwFsdQueryVolumeInformation (
  1064. IN PDEVICE_OBJECT DeviceObject,
  1065. IN PIRP Irp
  1066. );
  1067. NTSTATUS
  1068. NwFsdSetVolumeInformation (
  1069. IN PDEVICE_OBJECT DeviceObject,
  1070. IN PIRP Irp
  1071. );
  1072. // WorkQue.c
  1073. PIRP_CONTEXT
  1074. AllocateIrpContext (
  1075. PIRP pIrp
  1076. );
  1077. VOID
  1078. FreeIrpContext (
  1079. PIRP_CONTEXT IrpContext
  1080. );
  1081. VOID
  1082. InitializeIrpContext (
  1083. VOID
  1084. );
  1085. VOID
  1086. UninitializeIrpContext (
  1087. VOID
  1088. );
  1089. VOID
  1090. NwCompleteRequest (
  1091. PIRP_CONTEXT IrpContext,
  1092. NTSTATUS Status
  1093. );
  1094. VOID
  1095. NwAppendToQueueAndWait(
  1096. PIRP_CONTEXT IrpContext
  1097. );
  1098. VOID
  1099. NwDequeueIrpContext(
  1100. IN PIRP_CONTEXT IrpContext,
  1101. IN BOOLEAN OwnSpinLock
  1102. );
  1103. VOID
  1104. NwCancelIrp (
  1105. IN PDEVICE_OBJECT DeviceObject,
  1106. IN PIRP Irp
  1107. );
  1108. PIRP
  1109. NwAllocateSendIrp (
  1110. PIRP_CONTEXT IrpContext
  1111. );
  1112. PMINI_IRP_CONTEXT
  1113. AllocateMiniIrpContext (
  1114. PIRP_CONTEXT IrpContext
  1115. );
  1116. VOID
  1117. FreeMiniIrpContext (
  1118. PMINI_IRP_CONTEXT MiniIrpContext
  1119. );
  1120. PWORK_CONTEXT
  1121. AllocateWorkContext (
  1122. VOID
  1123. );
  1124. VOID
  1125. FreeWorkContext (
  1126. PWORK_CONTEXT
  1127. );
  1128. VOID
  1129. SpawnWorkerThread (
  1130. VOID
  1131. );
  1132. VOID
  1133. WorkerThread (
  1134. VOID
  1135. );
  1136. VOID
  1137. TerminateWorkerThread (
  1138. VOID
  1139. );
  1140. // Write.c
  1141. NTSTATUS
  1142. NwFsdWrite(
  1143. IN PDEVICE_OBJECT DeviceObject,
  1144. IN PIRP Irp
  1145. );
  1146. NTSTATUS
  1147. DoWrite(
  1148. PIRP_CONTEXT IrpContext,
  1149. LARGE_INTEGER ByteOffset,
  1150. ULONG BufferLength,
  1151. PVOID WriteBuffer,
  1152. PMDL WriteMdl
  1153. );
  1154. NTSTATUS
  1155. NwFsdFlushBuffers(
  1156. IN PDEVICE_OBJECT DeviceObject,
  1157. IN PIRP Irp
  1158. );
  1159. NTSTATUS
  1160. ResubmitBurstWrite(
  1161. PIRP_CONTEXT IrpContext
  1162. );
  1163. #if NWFASTIO
  1164. BOOLEAN
  1165. NwFastWrite (
  1166. IN PFILE_OBJECT FileObject,
  1167. IN PLARGE_INTEGER FileOffset,
  1168. IN ULONG Length,
  1169. IN BOOLEAN Wait,
  1170. IN ULONG LockKey,
  1171. OUT PVOID Buffer,
  1172. OUT PIO_STATUS_BLOCK IoStatus,
  1173. IN PDEVICE_OBJECT DeviceObject
  1174. );
  1175. #endif
  1176. #ifdef _PNP_POWER_
  1177. //
  1178. // NwPnP.C
  1179. //
  1180. NTSTATUS
  1181. StartRedirector(
  1182. PIRP_CONTEXT IrpContext
  1183. );
  1184. NTSTATUS
  1185. StopRedirector(
  1186. IN PIRP_CONTEXT IrpContext
  1187. );
  1188. NTSTATUS
  1189. RegisterTdiPnPEventHandlers(
  1190. IN PIRP_CONTEXT IrpContext
  1191. );
  1192. NTSTATUS
  1193. PnPSetPower(
  1194. PNET_PNP_EVENT pEvent,
  1195. PTDI_PNP_CONTEXT pContext1,
  1196. PTDI_PNP_CONTEXT pContext2
  1197. );
  1198. NTSTATUS
  1199. PnPQueryPower(
  1200. PNET_PNP_EVENT pEvent,
  1201. PTDI_PNP_CONTEXT pContext1,
  1202. PTDI_PNP_CONTEXT pContext2
  1203. );
  1204. NTSTATUS
  1205. PnPQueryRemove(
  1206. PNET_PNP_EVENT pEvent,
  1207. PTDI_PNP_CONTEXT pContext1,
  1208. PTDI_PNP_CONTEXT pContext2
  1209. );
  1210. NTSTATUS
  1211. PnPCancelRemove(
  1212. PNET_PNP_EVENT pEvent,
  1213. PTDI_PNP_CONTEXT pContext1,
  1214. PTDI_PNP_CONTEXT pContext2
  1215. );
  1216. ULONG
  1217. PnPCountActiveHandles(
  1218. VOID
  1219. );
  1220. NTSTATUS
  1221. NwFsdProcessPnpIrp(
  1222. IN PDEVICE_OBJECT DeviceObject,
  1223. IN PIRP Irp
  1224. );
  1225. NTSTATUS
  1226. PnpIrpCompletion(
  1227. PDEVICE_OBJECT pDeviceObject,
  1228. PIRP pIrp,
  1229. PVOID pContext
  1230. );
  1231. NTSTATUS
  1232. NwCommonProcessPnpIrp (
  1233. IN PIRP_CONTEXT IrpContext
  1234. );
  1235. #endif
  1236. //
  1237. // A function that returns finished denotes if it was able to complete the
  1238. // operation (TRUE) or could not complete the operation (FALSE) because the
  1239. // wait value stored in the irp context was false and we would have had
  1240. // to block for a resource or I/O
  1241. //
  1242. typedef BOOLEAN FINISHED;
  1243. //
  1244. // Miscellaneous support routines
  1245. //
  1246. //
  1247. // This macro returns TRUE if a flag in a set of flags is on and FALSE
  1248. // otherwise. It is followed by two macros for setting and clearing
  1249. // flags
  1250. //
  1251. #ifndef BooleanFlagOn
  1252. #define BooleanFlagOn(Flags,SingleFlag) ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))
  1253. #endif
  1254. #ifndef SetFlag
  1255. #define SetFlag(Flags,SingleFlag) { \
  1256. (Flags) |= (SingleFlag); \
  1257. }
  1258. #endif
  1259. #ifndef ClearFlag
  1260. #define ClearFlag(Flags,SingleFlag) { \
  1261. (Flags) &= ~(SingleFlag); \
  1262. }
  1263. #endif
  1264. //
  1265. // The following macro is used to determine if an FSD thread can block
  1266. // for I/O or wait for a resource. It returns TRUE if the thread can
  1267. // block and FALSE otherwise. This attribute can then be used to call
  1268. // the FSD & FSP common work routine with the proper wait value.
  1269. //
  1270. #define CanFsdWait(IRP) IoIsOperationSynchronous(IRP)
  1271. //
  1272. // This macro takes a pointer (or ulong) and returns its rounded up word
  1273. // value
  1274. //
  1275. #define WordAlign(Ptr) ( \
  1276. ((((ULONG)(Ptr)) + 1) & 0xfffffffe) \
  1277. )
  1278. //
  1279. // This macro takes a pointer (or ulong) and returns its rounded up longword
  1280. // value
  1281. //
  1282. #define LongAlign(Ptr) ( \
  1283. ((((ULONG)(Ptr)) + 3) & 0xfffffffc) \
  1284. )
  1285. //
  1286. // This macro takes a pointer (or ulong) and returns its rounded up quadword
  1287. // value
  1288. //
  1289. #define QuadAlign(Ptr) ( \
  1290. ((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
  1291. )
  1292. //
  1293. // The following two macro are used by the Fsd/Fsp exception handlers to
  1294. // process an exception. The first macro is the exception filter used in the
  1295. // Fsd/Fsp to decide if an exception should be handled at this level.
  1296. // The second macro decides if the exception is to be finished off by
  1297. // completing the IRP, and cleaning up the Irp Context, or if we should
  1298. // bugcheck. Exception values such as STATUS_FILE_INVALID (raised by
  1299. // VerfySup.c) cause us to complete the Irp and cleanup, while exceptions
  1300. // such as accvio cause us to bugcheck.
  1301. //
  1302. // The basic structure for fsd/fsp exception handling is as follows:
  1303. //
  1304. // NwFsdXxx(...)
  1305. // {
  1306. // try {
  1307. //
  1308. // ...
  1309. //
  1310. // } except(NwExceptionFilter( IrpContext, GetExceptionCode() )) {
  1311. //
  1312. // Status = NwProcessException( IrpContext, Irp, GetExceptionCode() );
  1313. // }
  1314. //
  1315. // Return Status;
  1316. // }
  1317. //
  1318. // To explicitly raise an exception that we expect, such as
  1319. // STATUS_FILE_INVALID, use the below macro NwRaiseStatus(). To raise a
  1320. // status from an unknown origin (such as CcFlushCache()), use the macro
  1321. // NwNormalizeAndRaiseStatus. This will raise the status if it is expected,
  1322. // or raise STATUS_UNEXPECTED_IO_ERROR if it is not.
  1323. //
  1324. // Note that when using these two macros, the original status is placed in
  1325. // IrpContext->ExceptionStatus, signaling NwExceptionFilter and
  1326. // NwProcessException that the status we actually raise is by definition
  1327. // expected.
  1328. //
  1329. LONG
  1330. NwExceptionFilter (
  1331. IN PIRP Irp,
  1332. IN PEXCEPTION_POINTERS ExceptionPointer
  1333. );
  1334. NTSTATUS
  1335. NwProcessException (
  1336. IN PIRP_CONTEXT IrpContext,
  1337. IN NTSTATUS ExceptionCode
  1338. );
  1339. //
  1340. // VOID
  1341. // NwRaiseStatus (
  1342. // IN NT_STATUS Status
  1343. // );
  1344. //
  1345. //
  1346. #define NwRaiseStatus(IRPCONTEXT,STATUS) { \
  1347. ExRaiseStatus( (STATUS) ); \
  1348. KeBugCheck( NW_FILE_SYSTEM ); \
  1349. }
  1350. //
  1351. // VOID
  1352. // NwNormalAndRaiseStatus (
  1353. // IN NT_STATUS Status
  1354. // );
  1355. //
  1356. #define NwNormalizeAndRaiseStatus(IRPCONTEXT,STATUS) { \
  1357. if ((STATUS) == STATUS_VERIFY_REQUIRED) { ExRaiseStatus((STATUS)); } \
  1358. ExRaiseStatus(FsRtlNormalizeNtstatus((STATUS),STATUS_UNEXPECTED_IO_ERROR)); \
  1359. KeBugCheck( NW_FILE_SYSTEM ); \
  1360. }
  1361. //
  1362. // The Following routine makes a popup
  1363. //
  1364. #define NwRaiseInformationalHardError(STATUS,NAME) { \
  1365. UNICODE_STRING Name; \
  1366. if (NT_SUCCESS(RtlOemStringToCountedUnicodeString(&Name, (NAME), TRUE))) { \
  1367. IoRaiseInformationalHardError(Status, &Name, (Irp == NULL ?\
  1368. NULL : &(Irp->Tail.Overlay.Thread)->Tcb)); \
  1369. RtlFreeUnicodeString(&Name); \
  1370. } \
  1371. }
  1372. //
  1373. // The following macros are used to establish the semantics needed
  1374. // to do a return from within a try-finally clause. As a rule every
  1375. // try clause must end with a label call try_exit. For example,
  1376. //
  1377. // try {
  1378. // :
  1379. // :
  1380. //
  1381. // try_exit: NOTHING;
  1382. // } finally {
  1383. //
  1384. // :
  1385. // :
  1386. // }
  1387. //
  1388. // Every return statement executed inside of a try clause should use the
  1389. // try_return macro. If the compiler fully supports the try-finally construct
  1390. // then the macro should be
  1391. //
  1392. // #define try_return(S) { return(S); }
  1393. //
  1394. // If the compiler does not support the try-finally construct then the macro
  1395. // should be
  1396. //
  1397. // #define try_return(S) { S; goto try_exit; }
  1398. //
  1399. #define try_return(S) { S; goto try_exit; }
  1400. #if NWDBG
  1401. #define InternalError(String) { \
  1402. DbgPrint("Internal NetWare Redirector Error "); \
  1403. DbgPrint String; \
  1404. DbgPrint("\nFile %s, Line %d\n", __FILE__, __LINE__); \
  1405. ASSERT(FALSE); \
  1406. }
  1407. #else
  1408. #define InternalError(String) {NOTHING;}
  1409. #endif
  1410. #define DbgPrintf DbgPrint
  1411. //
  1412. // Reference and dereference Macros.
  1413. //
  1414. VOID
  1415. RefDbgTrace (
  1416. PVOID Resource,
  1417. DWORD Count,
  1418. BOOLEAN Reference,
  1419. PBYTE FileName,
  1420. UINT Line
  1421. );
  1422. #ifdef NWDBG
  1423. VOID
  1424. ChkNwReferenceScb(
  1425. PNONPAGED_SCB pNpScb,
  1426. PBYTE FileName,
  1427. UINT Line,
  1428. BOOLEAN Silent
  1429. );
  1430. VOID
  1431. ChkNwDereferenceScb(
  1432. PNONPAGED_SCB pNpScb,
  1433. PBYTE FileName,
  1434. UINT Line,
  1435. BOOLEAN Silent
  1436. );
  1437. #define NwReferenceScb( pNpScb ) \
  1438. ChkNwReferenceScb( pNpScb, __FILE__, __LINE__, FALSE )
  1439. #define NwQuietReferenceScb( pNpScb ) \
  1440. ChkNwReferenceScb( pNpScb, __FILE__, __LINE__, TRUE )
  1441. #define NwDereferenceScb( pNpScb ) \
  1442. ChkNwDereferenceScb( pNpScb, __FILE__, __LINE__, FALSE )
  1443. #define NwQuietDereferenceScb( pNpScb ) \
  1444. ChkNwDereferenceScb( pNpScb, __FILE__, __LINE__, TRUE )
  1445. #else
  1446. #define NwReferenceScb( pNpScb ) \
  1447. InterlockedIncrement( &(pNpScb)->Reference )
  1448. #define NwQuietReferenceScb( pNpScb ) \
  1449. InterlockedIncrement( &(pNpScb)->Reference )
  1450. #define NwDereferenceScb( pNpScb ) \
  1451. InterlockedDecrement( &(pNpScb)->Reference )
  1452. #define NwQuietDereferenceScb( pNpScb ) \
  1453. InterlockedDecrement( &(pNpScb)->Reference )
  1454. #endif
  1455. //
  1456. // Irpcontext event macro.
  1457. //
  1458. #define NwSetIrpContextEvent( pIrpContext ) \
  1459. DebugTrace( 0, DEBUG_TRACE_WORKQUE, "Set event for IrpC = %08lx\n", pIrpContext ); \
  1460. DebugTrace( 0, DEBUG_TRACE_WORKQUE, "IrpC->pNpScb = %08lx\n", pIrpContext->pNpScb ); \
  1461. KeSetEvent( &pIrpContext->Event, 0, FALSE )
  1462. //
  1463. // VCB macros must be called with the RCB resource held.
  1464. //
  1465. #if NWDBG
  1466. VOID
  1467. NwReferenceVcb (
  1468. IN PVCB Vcb
  1469. );
  1470. #else
  1471. #define NwReferenceVcb( pVcb ) ++(pVcb)->Reference;
  1472. #endif
  1473. //
  1474. // Resource acquisition and release macros
  1475. //
  1476. #if NWDBG
  1477. VOID
  1478. NwAcquireExclusiveRcb(
  1479. PRCB Rcb,
  1480. BOOLEAN Wait
  1481. );
  1482. VOID
  1483. NwAcquireSharedRcb(
  1484. PRCB Rcb,
  1485. BOOLEAN Wait
  1486. );
  1487. VOID
  1488. NwReleaseRcb(
  1489. PRCB Rcb
  1490. );
  1491. VOID
  1492. NwAcquireExclusiveFcb(
  1493. PNONPAGED_FCB pFcb,
  1494. BOOLEAN Wait
  1495. );
  1496. VOID
  1497. NwAcquireSharedFcb(
  1498. PNONPAGED_FCB pFcb,
  1499. BOOLEAN Wait
  1500. );
  1501. VOID
  1502. NwReleaseFcb(
  1503. PNONPAGED_FCB pFcb
  1504. );
  1505. VOID
  1506. NwAcquireOpenLock(
  1507. VOID
  1508. );
  1509. VOID
  1510. NwReleaseOpenLock(
  1511. VOID
  1512. );
  1513. #else
  1514. #define NwAcquireExclusiveRcb( Rcb, Wait ) \
  1515. ExAcquireResourceExclusiveLite( &((Rcb)->Resource), Wait )
  1516. #define NwAcquireSharedRcb( Rcb, Wait ) \
  1517. ExAcquireResourceSharedLite( &((Rcb)->Resource), Wait )
  1518. #define NwReleaseRcb( Rcb ) \
  1519. ExReleaseResourceLite( &((Rcb)->Resource) )
  1520. #define NwAcquireExclusiveFcb( pFcb, Wait ) \
  1521. ExAcquireResourceExclusiveLite( &((pFcb)->Resource), Wait )
  1522. #define NwAcquireSharedFcb( pFcb, Wait ) \
  1523. ExAcquireResourceSharedLite( &((pFcb)->Resource), Wait )
  1524. #define NwReleaseFcb( pFcb ) \
  1525. ExReleaseResourceLite( &((pFcb)->Resource) )
  1526. #define NwAcquireOpenLock( ) \
  1527. ExAcquireResourceExclusiveLite( &NwOpenResource, TRUE )
  1528. #define NwReleaseOpenLock( ) \
  1529. ExReleaseResourceLite( &NwOpenResource )
  1530. #endif
  1531. #define NwReleaseFcbForThread( pFcb, pThread ) \
  1532. ExReleaseResourceForThreadLite( &((pFcb)->Resource), pThread )
  1533. //
  1534. // Memory allocation and deallocation macros
  1535. //
  1536. #ifdef NWDBG
  1537. #define ALLOCATE_POOL_EX( Type, Size ) NwAllocatePool( Type, Size, TRUE )
  1538. #define ALLOCATE_POOL( Type, Size ) NwAllocatePool( Type, Size, FALSE )
  1539. #define FREE_POOL( Buffer ) NwFreePool( Buffer )
  1540. #define ALLOCATE_IRP( Size, ChargeQuota ) \
  1541. NwAllocateIrp( Size, ChargeQuota )
  1542. #define FREE_IRP( Irp ) NwFreeIrp( Irp )
  1543. #define ALLOCATE_MDL( Va, Length, Secondary, ChargeQuota, Irp ) \
  1544. NwAllocateMdl(Va, Length, Secondary, ChargeQuota, Irp, __FILE__, __LINE__ )
  1545. #define FREE_MDL( Mdl ) NwFreeMdl( Mdl )
  1546. #else
  1547. #define ALLOCATE_POOL_EX( Type, Size ) FsRtlAllocatePoolWithTag( Type, Size, 'scwn' )
  1548. #ifndef QFE_BUILD
  1549. #define ALLOCATE_POOL( Type, Size ) ExAllocatePoolWithTag( Type, Size, 'scwn' )
  1550. #else
  1551. #define ALLOCATE_POOL( Type, Size ) ExAllocatePool( Type, Size )
  1552. #endif
  1553. #define FREE_POOL( Buffer ) ExFreePool( Buffer )
  1554. #define ALLOCATE_IRP( Size, ChargeQuota ) \
  1555. IoAllocateIrp( Size, ChargeQuota )
  1556. #define FREE_IRP( Irp ) IoFreeIrp( Irp )
  1557. #define ALLOCATE_MDL( Va, Length, Secondary, ChargeQuota, Irp ) \
  1558. IoAllocateMdl(Va, Length, Secondary, ChargeQuota, Irp )
  1559. #define FREE_MDL( Mdl ) IoFreeMdl( Mdl )
  1560. #endif
  1561. //
  1562. // Useful macros
  1563. //
  1564. #define MIN(a,b) ((a)<(b) ? (a):(b))
  1565. #define MAX(a,b) ((a)>(b) ? (a):(b))
  1566. #define DIFFERENT_PAGES( START, SIZE ) \
  1567. (((ULONG)START & ~(4096-1)) != (((ULONG)START + SIZE) & ~(4096-1)))
  1568. #define UP_LEVEL_SERVER( Scb ) \
  1569. ( ( Scb->MajorVersion >= 4 ) || \
  1570. ( Scb->MajorVersion == 3 && Scb->MinorVersion >= 12 ) )
  1571. #define LFN_SUPPORTED( Scb ) \
  1572. ( ( Scb->MajorVersion >= 4 ) || \
  1573. ( Scb->MajorVersion == 3 && Scb->MinorVersion >= 11 ) )
  1574. #define LongByteSwap( l1, l2 ) \
  1575. { \
  1576. PUCHAR c1 = (PUCHAR)&l1; \
  1577. PUCHAR c2 = (PUCHAR)&l2; \
  1578. c1[0] = c2[3]; \
  1579. c1[1] = c2[2]; \
  1580. c1[2] = c2[1]; \
  1581. c1[3] = c2[0]; \
  1582. }
  1583. #define ShortByteSwap( s1, s2 ) \
  1584. { \
  1585. PUCHAR c1 = (PUCHAR)&s1; \
  1586. PUCHAR c2 = (PUCHAR)&s2; \
  1587. c1[0] = c2[1]; \
  1588. c1[1] = c2[0]; \
  1589. }
  1590. #define CanLogTimeOutEvent( LastTime, CurrentTime ) \
  1591. ( ( CurrentTime.QuadPart ) - ( LastTime.QuadPart ) >= 0 )
  1592. #define UpdateNextEventTime( LastTime, CurrentTime, TimeOutEventInterval ) \
  1593. ( LastTime.QuadPart ) = ( CurrentTime.QuadPart ) + \
  1594. ( TimeOutEventInterval.QuadPart )
  1595. //
  1596. // Macros to isolate NT 3.1 and NT 3.5 differences.
  1597. //
  1598. #ifdef QFE_BUILD
  1599. #define NwGetTopLevelIrp() (PIRP)(PsGetCurrentThread()->TopLevelIrp)
  1600. #define NwSetTopLevelIrp(Irp) (PIRP)(PsGetCurrentThread())->TopLevelIrp = Irp;
  1601. #else
  1602. #define NwGetTopLevelIrp() IoGetTopLevelIrp()
  1603. #define NwSetTopLevelIrp(Irp) IoSetTopLevelIrp(Irp)
  1604. #endif
  1605. //
  1606. // David Goebel - pls figure out which file below should come from
  1607. // io.h cannot be included successfully
  1608. //
  1609. NTKERNELAPI
  1610. VOID
  1611. IoRemoveShareAccess(
  1612. IN PFILE_OBJECT FileObject,
  1613. IN OUT PSHARE_ACCESS ShareAccess
  1614. );
  1615. // now all SKUs have TerminalServer flag. If App Server is enabled, SingleUserTS flag is cleared
  1616. #define IsTerminalServer() !(ExVerifySuite(SingleUserTS))
  1617. #endif // _NWPROCS_