Windows NT 4.0 source code leak
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.

575 lines
13 KiB

4 years ago
  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992, Microsoft Corporation.
  4. //
  5. // File: dfsstruc.h
  6. //
  7. // Contents:
  8. // This module defines the data structures that make up the major internal
  9. // part of the DFS file system.
  10. //
  11. // Functions:
  12. //
  13. // History: 12 Nov 1991 AlanW Created from CDFS souce.
  14. // 8 May 1992 PeterCo Removed all EP related stuff
  15. // Added stuff to support PKT
  16. // 11 May 1992 PeterCo Added support for attached devices
  17. // 24 April 1993 SudK Added support for KernelToUserMode calls
  18. // Added support for timer functionality.
  19. //-----------------------------------------------------------------------------
  20. #ifndef _DFSSTRUC_
  21. #define _DFSSTRUC_
  22. typedef enum {
  23. DFS_UNKNOWN = 0,
  24. DFS_CLIENT = 1,
  25. DFS_SERVER = 2,
  26. DFS_ROOT_SERVER = 3,
  27. } DFS_MACHINE_STATE;
  28. typedef enum {
  29. LV_UNINITIALIZED = 0,
  30. LV_INITSCHEDULED,
  31. LV_INITINPROGRESS,
  32. LV_INITIALIZED,
  33. LV_VALIDATED
  34. } DFS_LV_STATE;
  35. //
  36. // The DFS_DATA record is the top record in the DFS file system in-memory
  37. // data structure. This structure must be allocated from non-paged pool.
  38. //
  39. typedef struct _DFS_DATA {
  40. //
  41. // The type and size of this record (must be DSFS_NTC_DATA_HEADER)
  42. //
  43. NODE_TYPE_CODE NodeTypeCode;
  44. NODE_BYTE_SIZE NodeByteSize;
  45. //
  46. // A queue of all the logical roots that are known by the file system.
  47. //
  48. LIST_ENTRY VcbQueue;
  49. //
  50. // A list of all the deleted logical roots that still have files open
  51. // on them.
  52. //
  53. LIST_ENTRY DeletedVcbQueue;
  54. //
  55. // A list of all the user-defined credentials
  56. //
  57. LIST_ENTRY Credentials;
  58. //
  59. // A list of all the deleted credentials. They will be destroyed once
  60. // their ref count goes to 0
  61. //
  62. LIST_ENTRY DeletedCredentials;
  63. //
  64. // A pointer to the Driver object we were initialized with
  65. //
  66. PDRIVER_OBJECT DriverObject;
  67. //
  68. // A pointer to the \Dfs device object
  69. //
  70. PDEVICE_OBJECT FileSysDeviceObject;
  71. //
  72. // A pointer to an array of provider records
  73. //
  74. struct _PROVIDER_DEF *pProvider;
  75. int cProvider, maxProvider;
  76. //
  77. // A resource variable to control access to the global data record
  78. //
  79. ERESOURCE Resource;
  80. //
  81. // A spin lock to control access to the global data record; handy for
  82. // Interlocked operations.
  83. //
  84. KSPIN_LOCK DfsLock;
  85. //
  86. // A pointer to our EPROCESS struct, which is a required input to the
  87. // Cache Management subsystem. This field is simply set each time an
  88. // FSP thread is started, since it is easiest to do while running in the
  89. // Fsp.
  90. //
  91. PEPROCESS OurProcess;
  92. //
  93. // The following two fields are used to allocate IRP context structures
  94. // using the zone allocator. The spinlock protects access to the zone
  95. // and the zone variable denotes the zone itself
  96. //
  97. KSPIN_LOCK IrpContextSpinLock;
  98. ZONE_HEADER IrpContextZone;
  99. //
  100. // Device name prefix for the logical root devices.
  101. // E.g., `\Device\WinDfs\'.
  102. //
  103. UNICODE_STRING LogRootDevName;
  104. //
  105. // The state of the machine - DC, Server, Client etc.
  106. //
  107. DFS_MACHINE_STATE MachineState;
  108. //
  109. // The system wide Partition Knowledge Table (PKT)
  110. //
  111. DFS_PKT Pkt;
  112. //
  113. // DNR has been designed so that resources (like the Pkt above) are not
  114. // locked across network calls. This is critical to prevent inter-machine
  115. // deadlocks and for other functionality. To regulate access to these
  116. // resources, we use the following two events.
  117. //
  118. // This notify event is used to indicate that some thread is waiting to
  119. // write into the Pkt. If this event is !RESET!, it means that a thread
  120. // is waiting to write, and other threads trying to enter DNR should
  121. // hold off.
  122. //
  123. KEVENT PktWritePending;
  124. //
  125. // This semaphone is used to indicate that some thread(s) have currently
  126. // gone to get a referral. Another thread that wants to get a referral
  127. // should wait till this semaphone is SIGNALLED before attempting to go
  128. // get its own referral.
  129. //
  130. KSEMAPHORE PktReferralRequests;
  131. //
  132. // A hash table for associating DFS_FCBs with file objects
  133. //
  134. struct _FCB_HASH_TABLE *FcbHashTable;
  135. } DFS_DATA, *PDFS_DATA;
  136. #define MAX_PROVIDERS 5 // number of pre-allocated provider records
  137. //
  138. // A PROVIDER_DEF is a structure that abstracts an underlying redirector.
  139. //
  140. typedef struct _PROVIDER_DEF {
  141. //
  142. // The type and size of this record (must be DSFS_NTC_PROVIDER)
  143. //
  144. NODE_TYPE_CODE NodeTypeCode;
  145. NODE_BYTE_SIZE NodeByteSize;
  146. //
  147. // Provider ID and Capabilities, same as in the DS_REFERRAL structure.
  148. //
  149. USHORT eProviderId;
  150. USHORT fProvCapability;
  151. //
  152. // The following field gives the name of the device for the provider.
  153. //
  154. UNICODE_STRING DeviceName;
  155. //
  156. // Referenced pointers to the associated file and device objects
  157. //
  158. PDEVICE_OBJECT DeviceObject;
  159. PFILE_OBJECT FileObject;
  160. } PROVIDER_DEF, *PPROVIDER_DEF;
  161. //
  162. // The Vcb (Volume Control Block) record corresponds to every volume
  163. // (ie, a net use) mounted by the file system. They are ordered in a
  164. // queue off of DfsData.VcbQueue.
  165. //
  166. // For the DFS file system, `volumes' correspond to DFS logical roots.
  167. // These records are an extension of a corresponding device object.
  168. //
  169. typedef struct _DFS_VCB {
  170. //
  171. // The type and size of this record (must be DSFS_NTC_VCB)
  172. //
  173. NODE_TYPE_CODE NodeTypeCode;
  174. NODE_BYTE_SIZE NodeByteSize;
  175. //
  176. // The links for the device queue off of DfsData.VcbQueue
  177. //
  178. LIST_ENTRY VcbLinks;
  179. //
  180. // The internal state of the device. This is a collection of FSD device
  181. // state flags.
  182. //
  183. USHORT VcbState;
  184. //
  185. // The logical root corresponding to this volume. Forms part of the
  186. // path name in the NT object name space. This string will be something
  187. // like L"org", or L"dom" etc.
  188. //
  189. UNICODE_STRING LogicalRoot;
  190. //
  191. // The LogRootPrefix has a prefix that needs to be prepended to file
  192. // names being opened via this logical root before their name can
  193. // be resolved.
  194. //
  195. UNICODE_STRING LogRootPrefix;
  196. //
  197. // The credentials associated with this logical root
  198. //
  199. struct _DFS_CREDENTIALS *Credentials;
  200. //
  201. // A count of the number of file objects that have opened the volume
  202. // for direct access, and their share access state.
  203. //
  204. CLONG DirectAccessOpenCount;
  205. SHARE_ACCESS ShareAccess;
  206. //
  207. // A count of the number of file objects that have any file/directory
  208. // opened on this volume, not including direct access.
  209. //
  210. CLONG OpenFileCount;
  211. PFILE_OBJECT FileObjectWithVcbLocked;
  212. } DFS_VCB;
  213. typedef DFS_VCB *PDFS_VCB;
  214. #define VCB_STATE_FLAG_LOCKED (0x0001)
  215. #define VCB_STATE_FLAG_ALLOC_FCB (0x0002)
  216. //#define VCB_STATE_FLAG_DEVICE_ONLY (0x0008)
  217. //
  218. // A CREDENTIAL_RECORD is a user-supplied set of credentials that should
  219. // be used when accessing a particular Dfs. They are ordered in a queue
  220. // off of DfsData.Credentials;
  221. //
  222. typedef struct _DFS_CREDENTIALS {
  223. //
  224. // The links for the credentials queue off of DfsData.Credentials
  225. //
  226. LIST_ENTRY Link;
  227. //
  228. // A flags field to keep state about this credential record.
  229. //
  230. ULONG Flags;
  231. //
  232. // A ref count to keep this credential record from going away while
  233. // it is being used.
  234. //
  235. ULONG RefCount;
  236. //
  237. // A count of the number of net uses that refer to these credentials
  238. //
  239. ULONG NetUseCount;
  240. //
  241. // The root of the Dfs for which these credentials apply.
  242. //
  243. UNICODE_STRING ServerName;
  244. UNICODE_STRING ShareName;
  245. //
  246. // The domain name, user name and password to use when accessing the
  247. // Dfs rooted at ServerName\ShareName
  248. //
  249. UNICODE_STRING DomainName;
  250. UNICODE_STRING UserName;
  251. UNICODE_STRING Password;
  252. //
  253. // When setting up a Tree connect using these credentials, we'll need
  254. // to form an EA Buffer to pass in with the ZwCreateFile call. So, we
  255. // form one here.
  256. //
  257. ULONG EaLength;
  258. PUCHAR EaBuffer[1];
  259. } DFS_CREDENTIALS;
  260. typedef DFS_CREDENTIALS *PDFS_CREDENTIALS;
  261. #define CRED_HAS_DEVICE 0x1
  262. #define CRED_IS_DEVICELESS 0x2
  263. //
  264. // The DFS_FCB record corresponds to every open file and directory.
  265. //
  266. typedef struct _DFS_FCB {
  267. //
  268. // Type and size of this record (must be DSFS_NTC_FCB or DSFS_NTC_DCB)
  269. //
  270. NODE_TYPE_CODE NodeTypeCode;
  271. NODE_BYTE_SIZE NodeByteSize;
  272. //
  273. // A list entry for the hash table chain.
  274. //
  275. LIST_ENTRY HashChain;
  276. //
  277. // A pointer to the Logical root device, through which this DFS_FCB
  278. // was opened.
  279. //
  280. PDFS_VCB Vcb;
  281. //
  282. // The following field is the fully qualified file name for this DFS_FCB/DCB
  283. // starting from the logical root.
  284. //
  285. UNICODE_STRING FullFileName;
  286. UNICODE_STRING AlternateFileName;
  287. //
  288. // The following fields give the file and devices on which this DFS_FCB
  289. // have been opened. The DFS driver will pass through requests for
  290. // the file object to the target device below.
  291. //
  292. PFILE_OBJECT FileObject;
  293. //
  294. // The destinatation FSD device object through which I/O will be done.
  295. //
  296. PDEVICE_OBJECT TargetDevice;
  297. //
  298. // The provider def that opened this file
  299. //
  300. USHORT ProviderId;
  301. //
  302. // The DFS_MACHINE_ENTRY through which this file was opened. We need
  303. // to maintain a reference for each file on a DFS_MACHINE_ENTRY in
  304. // case we have authenticated connections to the server; we don't want
  305. // to tear down the authenticated connection if files are open.
  306. //
  307. PDFS_MACHINE_ENTRY DfsMachineEntry;
  308. } DFS_FCB, *PDFS_FCB;
  309. //
  310. // The Logical Root Device Object is an I/O system device object
  311. // created as a result of creating a DFS logical root.
  312. // Logical roots are in many ways analogous to volumes
  313. // for a local file system.
  314. //
  315. // There is a DFS_VCB record appended to the end.
  316. //
  317. typedef struct _LOGICAL_ROOT_DEVICE_OBJECT {
  318. DEVICE_OBJECT DeviceObject;
  319. //
  320. // This is the file system specific volume control block.
  321. //
  322. DFS_VCB Vcb;
  323. } LOGICAL_ROOT_DEVICE_OBJECT, *PLOGICAL_ROOT_DEVICE_OBJECT;
  324. //
  325. // The Irp Context record is allocated for every orginating Irp. It
  326. // is created by the Fsd dispatch routines, and deallocated by the
  327. // DfsCompleteRequest routine
  328. //
  329. typedef struct _IRP_CONTEXT {
  330. //
  331. // Type and size of this record (must be DSFS_NTC_IRP_CONTEXT)
  332. //
  333. NODE_TYPE_CODE NodeTypeCode;
  334. NODE_BYTE_SIZE NodeByteSize;
  335. //
  336. // This structure is used for posting to the Ex worker threads.
  337. //
  338. WORK_QUEUE_ITEM WorkQueueItem;
  339. //
  340. // A pointer to the originating Irp.
  341. //
  342. PIRP OriginatingIrp;
  343. //
  344. // A pointer to function dependent context.
  345. //
  346. PVOID Context;
  347. //
  348. // Major and minor function codes copied from the Irp
  349. //
  350. UCHAR MajorFunction;
  351. UCHAR MinorFunction;
  352. //
  353. // The following flags field indicates if we can wait/block for a resource
  354. // or I/O, if we are to do everything write through, and if this
  355. // entry into the Fsd is a recursive call
  356. //
  357. USHORT Flags;
  358. //
  359. // The following field contains the NTSTATUS value used when we are
  360. // unwinding due to an exception
  361. //
  362. NTSTATUS ExceptionStatus;
  363. } IRP_CONTEXT;
  364. typedef IRP_CONTEXT *PIRP_CONTEXT;
  365. //
  366. // Values for the Irp context Flags field.
  367. //
  368. #define IRP_CONTEXT_FLAG_FROM_POOL (0x00000001)
  369. #define IRP_CONTEXT_FLAG_WAIT (0x00000002)
  370. #define IRP_CONTEXT_FLAG_IN_FSD (0x00000004)
  371. //
  372. // This context is used by the DfsIoTimer routine. We can expand on this
  373. // whenever new functionality needs to be added to the Timer function.
  374. //
  375. typedef struct _DFS_TIMER_CONTEXT {
  376. //
  377. // TickCount. To keep track of how many times the timer routine was
  378. // called. The timer uses this to do things at a coarser granularity.
  379. //
  380. ULONG TickCount;
  381. //
  382. // InUse. This field is used to denote that this CONTEXT is in use
  383. // by some function to which the Timer routine has passed it off. This
  384. // is used in a simple way to control access to this context.
  385. //
  386. BOOLEAN InUse;
  387. //
  388. // ValidateLocalPartitions. This field is used to denote that the
  389. // local volumes should be validated at this time.
  390. //
  391. BOOLEAN ValidateLocalPartitions;
  392. //
  393. // This is used to schedule DfsAgePktEntries.
  394. //
  395. WORK_QUEUE_ITEM WorkQueueItem;
  396. //
  397. // This is used to schedule DfsDeleteDevices.
  398. //
  399. WORK_QUEUE_ITEM DeleteQueueItem;
  400. } DFS_TIMER_CONTEXT, *PDFS_TIMER_CONTEXT;
  401. //
  402. // The following constant is the number of seconds between any two scans
  403. // through the PKT to get rid of old PKT entries.
  404. //
  405. #define DFS_MAX_TICKS 240
  406. //
  407. // The following constant is the number of seconds that a referral will
  408. // remain in cache (PKT).
  409. //
  410. #define MAX_REFERRAL_LIFE_TIME 300
  411. #endif // _DFSSTRUC_