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.

442 lines
10 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. NwData.c
  5. Abstract:
  6. This module declares the global data used by the Nw file system.
  7. Author:
  8. Colin Watson [ColinW] 19-Dec-1992
  9. Anoop Anantha [AnoopA] 24-Jun-1998
  10. Revision History:
  11. --*/
  12. #include "Procs.h"
  13. #include <stdlib.h>
  14. //
  15. // The debug trace level
  16. //
  17. #define Dbg (DEBUG_TRACE_CATCH_EXCEPTIONS)
  18. PEPROCESS FspProcess;
  19. PDEVICE_OBJECT FileSystemDeviceObject = NULL;
  20. //
  21. // The volume control block for the redirector device.
  22. //
  23. RCB NwRcb;
  24. //
  25. // The ScbSpinLock protects the entire ScbQueue and the first part of the
  26. // Scb entries on the queue. The first part of the Scb includes the name
  27. // of the server and a reference count
  28. //
  29. KSPIN_LOCK ScbSpinLock;
  30. LIST_ENTRY ScbQueue;
  31. //
  32. // The NwTimerSpinLock protects the Timer and TimerStop flag.
  33. //
  34. KSPIN_LOCK NwTimerSpinLock;
  35. //
  36. // A permanent SCB to synchronize access to the network.
  37. //
  38. NONPAGED_SCB NwPermanentNpScb;
  39. LARGE_INTEGER NwMaxLarge = {MAXULONG,MAXLONG};
  40. //
  41. // tommye MS 90541 / MCS 277
  42. //
  43. // Set NwAbsoluteTotalWaitTime to 200, which is 100 half-seconds (duh). This gets
  44. // referenced in NwProcessPositiveAck, which comes from the TimerDPC about every
  45. // half second or so. This is the longest about of retries that we will send a
  46. // packet that we've gotten a positive ACK on.
  47. //
  48. ULONG NwAbsoluteTotalWaitTime = 200;
  49. TDI_ADDRESS_IPX OurAddress = {0,0,0,0,0,0,0,0};
  50. UNICODE_STRING IpxTransportName;
  51. HANDLE IpxHandle = NULL;
  52. PDEVICE_OBJECT pIpxDeviceObject = NULL;
  53. PFILE_OBJECT pIpxFileObject = NULL;
  54. LIST_ENTRY LogonList;
  55. LOGON Guest;
  56. LARGE_INTEGER DefaultLuid = ANONYMOUS_LOGON_LUID;
  57. //
  58. // A global list of VCBs, and a monotonic increasing VCB entry, used to
  59. // control connection enumeration.
  60. //
  61. LIST_ENTRY GlobalVcbList;
  62. ULONG CurrentVcbEntry;
  63. #if 0
  64. //
  65. // HACKHACK - List of outstanding find notify request
  66. // Protected by NwRcb resource.
  67. //
  68. LIST_ENTRY FnList;
  69. #endif
  70. //
  71. // Drive mapping table of redirected drives. 26 disk drive mappings +
  72. // 10 LPT mappings.
  73. //
  74. // Netware supports 32 disk redirections, but this funkiness is handled
  75. // by the 16-bit code.
  76. //
  77. PVCB GlobalDriveMapTable[DRIVE_MAP_TABLE_SIZE]; //MultiUser
  78. FAST_IO_DISPATCH NwFastIoDispatch;
  79. //
  80. // Scavenger related data
  81. //
  82. ULONG NwScavengerTickCount; // The current tick count
  83. ULONG NwScavengerTickRunCount; // The count at which to run the scavenger routine
  84. KSPIN_LOCK NwScavengerSpinLock; // Lock to protect access to the above.
  85. //
  86. // Worker thread
  87. //
  88. BOOLEAN WorkerThreadRunning = FALSE;
  89. //
  90. // Message queue data
  91. //
  92. LIST_ENTRY NwGetMessageList; // List of Get Message IRP contexts
  93. KSPIN_LOCK NwMessageSpinLock; // Protects the list above.
  94. //
  95. // Pending lock list
  96. //
  97. LIST_ENTRY NwPendingLockList; // List of pending File lock IRP contexts
  98. KSPIN_LOCK NwPendingLockSpinLock;// Protects the list above.
  99. //
  100. // Lock to synchronize all file opens.
  101. //
  102. ERESOURCE NwOpenResource;
  103. //
  104. // Configuration data
  105. //
  106. LONG PreferNDSBrowsing = 0; // when attempting to connect to UNC paths, attempt NDS connection first
  107. BOOLEAN NwBurstModeEnabled = FALSE;
  108. ULONG NwMaxSendSize = 0;
  109. ULONG NwMaxReceiveSize = 0;
  110. ULONG NwPrintOptions = 0x98;
  111. UNICODE_STRING NwProviderName = { 0, 0, NULL };
  112. LONG MaxSendDelay = 50000;
  113. LONG MaxReceiveDelay = 50000;
  114. LONG MinSendDelay = 0;
  115. LONG MinReceiveDelay = 0;
  116. LONG BurstSuccessCount = 1;
  117. LONG BurstSuccessCount2 = 3;
  118. LONG AllowGrowth = 0;
  119. LONG DontShrink = 0;
  120. LONG SendExtraNcp = 1;
  121. LONG DefaultMaxPacketSize = 0;
  122. LONG PacketThreshold = 1500; // Size to use Large vs Small PacketAdjustment
  123. LONG LargePacketAdjustment = 38;
  124. LONG LipPacketAdjustment = 0;
  125. LONG LipAccuracy = BURST_PACKET_SIZE_TOLERANCE;
  126. LONG Japan = 0; // Controls special DBCS translation
  127. LONG Korean = 0; // Controls special Korean translation
  128. LONG DisableReadCache = 0; // disable file i/o read cache
  129. LONG DisableWriteCache = 0; // disable file i/o write cache
  130. LONG FavourLongNames = 1 ; // use LFN where possible
  131. DWORD LongNameFlags = 0; // flags for handling long names
  132. ULONG DirCacheEntries = 1; // number of directory entries we cache
  133. LARGE_INTEGER TimeOutEventInterval = {0, 0};
  134. LONG MaxWriteTimeout = 50 ; // tick counts (see write.c)
  135. LONG MaxReadTimeout = 50 ; // tick counts (see read.c)
  136. LONG WriteTimeoutMultiplier = 100; // expressed as percentage (see write.c)
  137. LONG ReadTimeoutMultiplier = 100; // expressed as percentage (see read.c)
  138. ULONG EnableMultipleConnects = 0;
  139. ULONG AllowSeedServerRedirection = 0;
  140. ULONG ReadExecOnlyFiles = 0;
  141. ULONG DisableAltFileName = 1;
  142. ULONG NdsObjectCacheSize = 0;
  143. ULONG NdsObjectCacheTimeout = 10;
  144. //
  145. // Static storage area for perfmon statistics
  146. //
  147. NW_REDIR_STATISTICS Stats;
  148. ULONG ContextCount = 0;
  149. //
  150. // Data structure used to track discardable code.
  151. //
  152. SECTION_DESCRIPTOR NwSectionDescriptor;
  153. ERESOURCE NwUnlockableCodeResource;
  154. //
  155. // The lock timeout value.
  156. //
  157. ULONG LockTimeoutThreshold = 1;
  158. //
  159. // The Kernel Queue from where the reconnect work items are picked up.
  160. //
  161. KQUEUE KernelQueue;
  162. #ifndef _PNP_POWER_
  163. //
  164. // The TDI PNP Bind handle.
  165. //
  166. HANDLE TdiBindingHandle = NULL;
  167. UNICODE_STRING TdiIpxDeviceName;
  168. WCHAR IpxDevice[] = L"\\Device\\NwlnkIpx";
  169. #endif
  170. //
  171. // We can't have the scavenger and a line change request running
  172. // at the same time since they both run on worker threads and
  173. // walk across all the SCBs. Therefore, when either is running,
  174. // we set the WorkerRunning value used by the scavenger to TRUE.
  175. // If a scavenger run tries to happen while a line change request
  176. // is running, it gets skipped. If a line change request comes in
  177. // while the scavenger is running, we set DelayedProcessLineChange
  178. // to TRUE and run it when the scavenger finishes.
  179. //
  180. // These values are protected by the existing scavenger spin lock.
  181. //
  182. BOOLEAN DelayedProcessLineChange = FALSE;
  183. PIRP DelayedLineChangeIrp = NULL;
  184. #ifdef NWDBG
  185. ULONG NwDebug = 0;
  186. //ULONG NwDebug = 0xffffffbf;
  187. ULONG NwMemDebug = 0xffffffff;
  188. LONG NwDebugTraceIndent = 0;
  189. ULONG NwFsdEntryCount = 0;
  190. ULONG NwFspEntryCount = 0;
  191. ULONG NwIoCallDriverCount = 0;
  192. LONG NwPerformanceTimerLevel = 0x00000000;
  193. ULONG NwTotalTicks[32] = { 0 };
  194. //
  195. // Debug data for tracking pool usage
  196. //
  197. KSPIN_LOCK NwDebugInterlock;
  198. ERESOURCE NwDebugResource;
  199. LIST_ENTRY NwPagedPoolList;
  200. LIST_ENTRY NwNonpagedPoolList;
  201. ULONG MdlCount;
  202. ULONG IrpCount;
  203. #endif // NWDBG
  204. //
  205. // Configurable parameters.
  206. //
  207. SHORT DefaultRetryCount = DEFAULT_RETRY_COUNT;
  208. #ifdef _PNP_POWER_
  209. BOOLEAN fPoweringDown = FALSE;
  210. #endif
  211. #ifdef ALLOC_PRAGMA
  212. #pragma alloc_text( PAGE, NwInitializeData )
  213. #endif
  214. VOID
  215. NwInitializeData(
  216. VOID
  217. )
  218. {
  219. LARGE_INTEGER Now;
  220. PAGED_CODE();
  221. NwRcb.State = RCB_STATE_STOPPED;
  222. #ifdef NWDBG
  223. // Initialize pool before allocating any memory
  224. InitializeListHead( &NwPagedPoolList );
  225. InitializeListHead( &NwNonpagedPoolList );
  226. ExInitializeResourceLite( &NwDebugResource );
  227. KeInitializeSpinLock( &NwDebugInterlock );
  228. MdlCount = 0;
  229. IrpCount = 0;
  230. #endif
  231. ExInitializeResourceLite( &NwOpenResource );
  232. //
  233. // Initialize the scavenger spin lock and run tick count.
  234. //
  235. KeInitializeSpinLock( &NwScavengerSpinLock );
  236. NwScavengerTickRunCount = DEFAULT_SCAVENGER_TICK_RUN_COUNT;
  237. //
  238. // Initialize the timer spin lock.
  239. //
  240. KeInitializeSpinLock( &NwTimerSpinLock );
  241. RtlInitUnicodeString( &IpxTransportName, NULL );
  242. #ifndef _PNP_POWER_
  243. RtlInitUnicodeString( &TdiIpxDeviceName, IpxDevice );
  244. #endif
  245. //
  246. // Allocate a permanent Non-paged SCB. This SCB is used to
  247. // synchronize access to finding the nearest server.
  248. // This initialization must be done before the first possible call
  249. // to UnloadDriver.
  250. //
  251. RtlZeroMemory( &NwPermanentNpScb, sizeof( NONPAGED_SCB ) );
  252. NwPermanentNpScb.NodeTypeCode = NW_NTC_SCBNP;
  253. NwPermanentNpScb.NodeByteSize = sizeof(NONPAGED_SCB);
  254. NwPermanentNpScb.Reference = 1;
  255. InitializeListHead( &NwPermanentNpScb.Requests );
  256. //
  257. // Initialize the logonlist to have a default entry with server NULL,
  258. // username "GUEST" and null password. This will always be the last
  259. // entry on the logonlist so that the workstation service can supply
  260. // an override.
  261. //
  262. InitializeListHead( &LogonList );
  263. Guest.NodeTypeCode = NW_NTC_LOGON;
  264. Guest.NodeByteSize = sizeof(LOGON);
  265. {
  266. //Multi-user. Initialize the DriveMapTable
  267. int i;
  268. for ( i = 0; i < DRIVE_MAP_TABLE_SIZE; i ++ )
  269. Guest.DriveMapTable[i] = NULL;
  270. }
  271. RtlInitUnicodeString( &Guest.ServerName, NULL );
  272. RtlInitUnicodeString( &Guest.PassWord, NULL );
  273. RtlInitUnicodeString( &Guest.UserName, L"GUEST" );
  274. Guest.UserUid = DefaultLuid;
  275. InitializeListHead( &Guest.NdsCredentialList );
  276. InsertTailList( &LogonList, &Guest.Next );
  277. //
  278. // Initialize the global VCB list.
  279. //
  280. InitializeListHead( &GlobalVcbList );
  281. CurrentVcbEntry = 1;
  282. //
  283. // Initialize the Get message queue.
  284. //
  285. InitializeListHead( &NwGetMessageList );
  286. KeInitializeSpinLock( &NwMessageSpinLock );
  287. //
  288. // Initialize the Pending lock queue.
  289. //
  290. InitializeListHead( &NwPendingLockList );
  291. KeInitializeSpinLock( &NwPendingLockSpinLock );
  292. //
  293. // Insert the Permanent SCB in the global list of SCBs.
  294. //
  295. InsertHeadList( &ScbQueue, &NwPermanentNpScb.ScbLinks );
  296. //
  297. // Initialize the Kernel Queue Object. Only one thread has to
  298. // be concurrently active.
  299. //
  300. KeInitializeQueue( &KernelQueue, 1 );
  301. //
  302. // Spawn off our own worker thread which will service reroute and
  303. // reconnect attempts.
  304. //
  305. SpawnWorkerThread();
  306. #if 0
  307. // HACKHACK
  308. InitializeListHead( &FnList );
  309. #endif
  310. //
  311. // Seed the random number generator.
  312. //
  313. KeQuerySystemTime( &Now );
  314. srand( Now.LowPart );
  315. RtlZeroMemory( &Stats, sizeof( NW_REDIR_STATISTICS ) );
  316. ExInitializeResourceLite( &NwUnlockableCodeResource );
  317. NwSectionDescriptor.Base = BurstReadTimeout;
  318. NwSectionDescriptor.Handle = 0;
  319. NwSectionDescriptor.ReferenceCount = 0;
  320. return;
  321. }