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.

677 lines
16 KiB

  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 queue of all the DRT (Deviceless roots) that are known.
  56. //
  57. LIST_ENTRY DrtQueue;
  58. //
  59. // A list of all the user-defined credentials
  60. //
  61. LIST_ENTRY Credentials;
  62. //
  63. // A list of all the deleted credentials. They will be destroyed once
  64. // their ref count goes to 0
  65. //
  66. LIST_ENTRY DeletedCredentials;
  67. //
  68. // A list of all the offline roots
  69. //
  70. LIST_ENTRY OfflineRoots;
  71. //
  72. // A pointer to the Driver object we were initialized with
  73. //
  74. PDRIVER_OBJECT DriverObject;
  75. //
  76. // A pointer to the \Dfs device object
  77. //
  78. PDEVICE_OBJECT FileSysDeviceObject;
  79. //
  80. // A pointer to an array of provider records
  81. //
  82. struct _PROVIDER_DEF *pProvider;
  83. int cProvider, maxProvider;
  84. //
  85. // A resource variable to control access to the global data record
  86. //
  87. ERESOURCE Resource;
  88. //
  89. // A spin lock to control access to the global data record; handy for
  90. // Interlocked operations.
  91. //
  92. KSPIN_LOCK DfsLock;
  93. //
  94. // A pointer to our EPROCESS struct, which is a required input to the
  95. // Cache Management subsystem. This field is simply set each time an
  96. // FSP thread is started, since it is easiest to do while running in the
  97. // Fsp.
  98. //
  99. PEPROCESS OurProcess;
  100. //
  101. // Lookaside list for IRP contexts
  102. //
  103. NPAGED_LOOKASIDE_LIST IrpContextLookaside;
  104. //
  105. // Device name prefix for the logical root devices.
  106. // E.g., `\Device\WinDfs\'.
  107. //
  108. UNICODE_STRING LogRootDevName;
  109. //
  110. // The state of the machine - DC, Server, Client etc.
  111. //
  112. DFS_MACHINE_STATE MachineState;
  113. //
  114. // The system wide Partition Knowledge Table (PKT)
  115. //
  116. DFS_PKT Pkt;
  117. //
  118. // DNR has been designed so that resources (like the Pkt above) are not
  119. // locked across network calls. This is critical to prevent inter-machine
  120. // deadlocks and for other functionality. To regulate access to these
  121. // resources, we use the following two events.
  122. //
  123. // This notify event is used to indicate that some thread is waiting to
  124. // write into the Pkt. If this event is !RESET!, it means that a thread
  125. // is waiting to write, and other threads trying to enter DNR should
  126. // hold off.
  127. //
  128. KEVENT PktWritePending;
  129. //
  130. // This semaphone is used to indicate that some thread(s) have currently
  131. // gone to get a referral. Another thread that wants to get a referral
  132. // should wait till this semaphone is SIGNALLED before attempting to go
  133. // get its own referral.
  134. //
  135. KSEMAPHORE PktReferralRequests;
  136. //
  137. // A hash table for associating DFS_FCBs with file objects
  138. //
  139. struct _FCB_HASH_TABLE *FcbHashTable;
  140. //
  141. // EA buffer used to diffrentiate CSC opens from others
  142. //
  143. PFILE_FULL_EA_INFORMATION CSCEaBuffer;
  144. ULONG CSCEaBufferLength;
  145. } DFS_DATA, *PDFS_DATA;
  146. #define MAX_PROVIDERS 5 // number of pre-allocated provider records
  147. //
  148. // A PROVIDER_DEF is a structure that abstracts an underlying redirector.
  149. //
  150. typedef struct _PROVIDER_DEF {
  151. //
  152. // The type and size of this record (must be DSFS_NTC_PROVIDER)
  153. //
  154. NODE_TYPE_CODE NodeTypeCode;
  155. NODE_BYTE_SIZE NodeByteSize;
  156. //
  157. // Provider ID and Capabilities, same as in the DS_REFERRAL structure.
  158. //
  159. USHORT eProviderId;
  160. USHORT fProvCapability;
  161. //
  162. // The following field gives the name of the device for the provider.
  163. //
  164. UNICODE_STRING DeviceName;
  165. //
  166. // Referenced pointers to the associated file and device objects
  167. //
  168. PDEVICE_OBJECT DeviceObject;
  169. PFILE_OBJECT FileObject;
  170. } PROVIDER_DEF, *PPROVIDER_DEF;
  171. //
  172. // The Vcb (Volume Control Block) record corresponds to every volume
  173. // (ie, a net use) mounted by the file system. They are ordered in a
  174. // queue off of DfsData.VcbQueue.
  175. //
  176. // For the DFS file system, `volumes' correspond to DFS logical roots.
  177. // These records are an extension of a corresponding device object.
  178. //
  179. typedef struct _DFS_VCB {
  180. //
  181. // The type and size of this record (must be DSFS_NTC_VCB)
  182. //
  183. NODE_TYPE_CODE NodeTypeCode;
  184. NODE_BYTE_SIZE NodeByteSize;
  185. //
  186. // The links for the device queue off of DfsData.VcbQueue
  187. //
  188. LIST_ENTRY VcbLinks;
  189. //
  190. // The internal state of the device. This is a collection of FSD device
  191. // state flags.
  192. //
  193. USHORT VcbState;
  194. //
  195. // The logical root corresponding to this volume. Forms part of the
  196. // path name in the NT object name space. This string will be something
  197. // like L"org", or L"dom" etc.
  198. //
  199. UNICODE_STRING LogicalRoot;
  200. //
  201. // The LogRootPrefix has a prefix that needs to be prepended to file
  202. // names being opened via this logical root before their name can
  203. // be resolved.
  204. //
  205. UNICODE_STRING LogRootPrefix;
  206. //
  207. // The credentials associated with this logical root
  208. //
  209. struct _DFS_CREDENTIALS *Credentials;
  210. //
  211. // A count of the number of file objects that have opened the volume
  212. // for direct access, and their share access state.
  213. //
  214. CLONG DirectAccessOpenCount;
  215. SHARE_ACCESS ShareAccess;
  216. //
  217. // A count of the number of file objects that have any file/directory
  218. // opened on this volume, not including direct access.
  219. //
  220. CLONG OpenFileCount;
  221. PFILE_OBJECT FileObjectWithVcbLocked;
  222. #ifdef TERMSRV
  223. ULONG SessionID;
  224. #endif // TERMSRV
  225. LUID LogonID;
  226. PDFS_PKT_ENTRY pktEntry;
  227. } DFS_VCB;
  228. typedef DFS_VCB *PDFS_VCB;
  229. #define VCB_STATE_FLAG_LOCKED (0x0001)
  230. #define VCB_STATE_FLAG_ALLOC_FCB (0x0002)
  231. #define VCB_STATE_CSCAGENT_VOLUME (0x0004)
  232. //#define VCB_STATE_FLAG_DEVICE_ONLY (0x0008)
  233. #ifdef TERMSRV
  234. //
  235. // This SessionId indicates that the device name should not be suffixed
  236. // with :SessionID, and that no matching on SessionID should be done.
  237. //
  238. #define INVALID_SESSIONID 0xffffffff
  239. #endif
  240. //
  241. // A CREDENTIAL_RECORD is a user-supplied set of credentials that should
  242. // be used when accessing a particular Dfs. They are ordered in a queue
  243. // off of DfsData.Credentials;
  244. //
  245. typedef struct _DFS_CREDENTIALS {
  246. //
  247. // The links for the credentials queue off of DfsData.Credentials
  248. //
  249. LIST_ENTRY Link;
  250. //
  251. // A flags field to keep state about this credential record.
  252. //
  253. ULONG Flags;
  254. //
  255. // A ref count to keep this credential record from going away while
  256. // it is being used.
  257. //
  258. ULONG RefCount;
  259. //
  260. // A count of the number of net uses that refer to these credentials
  261. //
  262. ULONG NetUseCount;
  263. //
  264. // The root of the Dfs for which these credentials apply.
  265. //
  266. UNICODE_STRING ServerName;
  267. UNICODE_STRING ShareName;
  268. //
  269. // The domain name, user name and password to use when accessing the
  270. // Dfs rooted at ServerName\ShareName
  271. //
  272. UNICODE_STRING DomainName;
  273. UNICODE_STRING UserName;
  274. UNICODE_STRING Password;
  275. #ifdef TERMSRV
  276. ULONG SessionID;
  277. #endif // TERMSRV
  278. LUID LogonID;
  279. //
  280. // When setting up a Tree connect using these credentials, we'll need
  281. // to form an EA Buffer to pass in with the ZwCreateFile call. So, we
  282. // form one here.
  283. //
  284. ULONG EaLength;
  285. PUCHAR EaBuffer[1];
  286. } DFS_CREDENTIALS;
  287. typedef DFS_CREDENTIALS *PDFS_CREDENTIALS;
  288. #define CRED_HAS_DEVICE 0x1
  289. #define CRED_IS_DEVICELESS 0x2
  290. //
  291. // The DFS_FCB record corresponds to every open file and directory.
  292. //
  293. typedef struct _DFS_FCB {
  294. //
  295. // Type and size of this record (must be DSFS_NTC_FCB or DSFS_NTC_DCB)
  296. //
  297. NODE_TYPE_CODE NodeTypeCode;
  298. NODE_BYTE_SIZE NodeByteSize;
  299. //
  300. // A list entry for the hash table chain.
  301. //
  302. LIST_ENTRY HashChain;
  303. //
  304. // A pointer to the Logical root device, through which this DFS_FCB
  305. // was opened.
  306. //
  307. PDFS_VCB Vcb;
  308. //
  309. // The following field is the fully qualified file name for this DFS_FCB/DCB
  310. // starting from the logical root.
  311. //
  312. union {
  313. UNICODE_STRING FullFileName;
  314. DFS_NAME_CONTEXT DfsNameContext;
  315. };
  316. UNICODE_STRING AlternateFileName;
  317. //
  318. // The following fields give the file and devices on which this DFS_FCB
  319. // have been opened. The DFS driver will pass through requests for
  320. // the file object to the target device below.
  321. //
  322. PFILE_OBJECT FileObject;
  323. //
  324. // The destinatation FSD device object through which I/O will be done.
  325. //
  326. PDEVICE_OBJECT TargetDevice;
  327. //
  328. // The provider def that opened this file
  329. //
  330. USHORT ProviderId;
  331. //
  332. // The DFS_MACHINE_ENTRY through which this file was opened. We need
  333. // to maintain a reference for each file on a DFS_MACHINE_ENTRY in
  334. // case we have authenticated connections to the server; we don't want
  335. // to tear down the authenticated connection if files are open.
  336. //
  337. PDFS_MACHINE_ENTRY DfsMachineEntry;
  338. WORK_QUEUE_ITEM WorkQueueItem;
  339. } DFS_FCB, *PDFS_FCB;
  340. //
  341. // The Logical Root Device Object is an I/O system device object
  342. // created as a result of creating a DFS logical root.
  343. // Logical roots are in many ways analogous to volumes
  344. // for a local file system.
  345. //
  346. // There is a DFS_VCB record appended to the end.
  347. //
  348. typedef struct _LOGICAL_ROOT_DEVICE_OBJECT {
  349. DEVICE_OBJECT DeviceObject;
  350. //
  351. // This is the file system specific volume control block.
  352. //
  353. DFS_VCB Vcb;
  354. } LOGICAL_ROOT_DEVICE_OBJECT, *PLOGICAL_ROOT_DEVICE_OBJECT;
  355. //
  356. // The Irp Context record is allocated for every orginating Irp. It
  357. // is created by the Fsd dispatch routines, and deallocated by the
  358. // DfsCompleteRequest routine
  359. //
  360. typedef struct _IRP_CONTEXT {
  361. //
  362. // Type and size of this record (must be DSFS_NTC_IRP_CONTEXT)
  363. //
  364. NODE_TYPE_CODE NodeTypeCode;
  365. NODE_BYTE_SIZE NodeByteSize;
  366. //
  367. // This structure is used for posting to the Ex worker threads.
  368. //
  369. WORK_QUEUE_ITEM WorkQueueItem;
  370. //
  371. // A pointer to the originating Irp.
  372. //
  373. PIRP OriginatingIrp;
  374. //
  375. // A pointer to function dependent context.
  376. //
  377. PVOID Context;
  378. //
  379. // Major and minor function codes copied from the Irp
  380. //
  381. UCHAR MajorFunction;
  382. UCHAR MinorFunction;
  383. //
  384. // The following flags field indicates if we can wait/block for a resource
  385. // or I/O, if we are to do everything write through, and if this
  386. // entry into the Fsd is a recursive call
  387. //
  388. USHORT Flags;
  389. //
  390. // The following field contains the NTSTATUS value used when we are
  391. // unwinding due to an exception
  392. //
  393. NTSTATUS ExceptionStatus;
  394. } IRP_CONTEXT;
  395. typedef IRP_CONTEXT *PIRP_CONTEXT;
  396. //
  397. // Values for the Irp context Flags field.
  398. //
  399. //#define IRP_CONTEXT_FLAG_FROM_POOL (0x00000001) // replaced by lookaside list
  400. #define IRP_CONTEXT_FLAG_WAIT (0x00000002)
  401. #define IRP_CONTEXT_FLAG_IN_FSD (0x00000004)
  402. //
  403. // This context is used by the DfsIoTimer routine. We can expand on this
  404. // whenever new functionality needs to be added to the Timer function.
  405. //
  406. typedef struct _DFS_TIMER_CONTEXT {
  407. //
  408. // TickCount. To keep track of how many times the timer routine was
  409. // called. The timer uses this to do things at a coarser granularity.
  410. //
  411. ULONG TickCount;
  412. //
  413. // InUse. This field is used to denote that this CONTEXT is in use
  414. // by some function to which the Timer routine has passed it off. This
  415. // is used in a simple way to control access to this context.
  416. //
  417. BOOLEAN InUse;
  418. //
  419. // ValidateLocalPartitions. This field is used to denote that the
  420. // local volumes should be validated at this time.
  421. //
  422. BOOLEAN ValidateLocalPartitions;
  423. //
  424. // This is used to schedule DfsAgePktEntries.
  425. //
  426. WORK_QUEUE_ITEM WorkQueueItem;
  427. //
  428. // This is used to schedule DfsDeleteDevices.
  429. //
  430. WORK_QUEUE_ITEM DeleteQueueItem;
  431. } DFS_TIMER_CONTEXT, *PDFS_TIMER_CONTEXT;
  432. //
  433. // The following constant is the number of seconds between any two scans
  434. // through the PKT to get rid of old PKT entries.
  435. //
  436. #define DFS_MAX_TICKS 240
  437. //
  438. // The following constant is the number of seconds that a referral will
  439. // remain in cache (PKT).
  440. //
  441. #define MAX_REFERRAL_LIFE_TIME 300
  442. //
  443. // The followin constants are the starting timeout (in seconds) between
  444. // special referrals. The start value is doubled after every retry until it
  445. // reaches the max.
  446. //
  447. #define SPECIAL_TIMEOUT_START (5*60) // 5 min
  448. #define SPECIAL_TIMEOUT_MAX (60*60) // 60 min
  449. //
  450. // The Drt (Devless Root) record corresponds to every net use.
  451. // They are ordered in a queue off of DfsData.VcbQueue.
  452. //
  453. //
  454. typedef struct _DFS_DEVLESS_ROOT {
  455. //
  456. // The type and size of this record (must be DSFS_NTC_DRT)
  457. //
  458. NODE_TYPE_CODE NodeTypeCode;
  459. NODE_BYTE_SIZE NodeByteSize;
  460. //
  461. // The links for the device queue off of DfsData.DrtQueue
  462. //
  463. LIST_ENTRY DrtLinks;
  464. //
  465. // The pathname corresponding to this entry.
  466. //
  467. UNICODE_STRING DevlessPath;
  468. //
  469. // The credentials associated with this logical root
  470. //
  471. struct _DFS_CREDENTIALS *Credentials;
  472. #ifdef TERMSRV
  473. ULONG SessionID;
  474. #endif // TERMSRV
  475. LUID LogonID;
  476. PDFS_PKT_ENTRY pktEntry;
  477. } DFS_DEVLESS_ROOT;
  478. typedef DFS_DEVLESS_ROOT *PDFS_DEVLESS_ROOT;
  479. #endif // _DFSSTRUC_