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.

598 lines
14 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. msstruc.h
  5. Abstract:
  6. This module defines the data structures that make up the major internal
  7. part of the mailslot file system.
  8. Author:
  9. Manny Weiser (mannyw) 7-Jan-1991
  10. Revision History:
  11. --*/
  12. #ifndef _MSSTRUC_
  13. #define _MSSTRUC_
  14. //
  15. // The VCB record is the top record in the mailslot file system in-memory
  16. // data structure. This structure must be allocated from non-paged pool
  17. // and immediately follows (in memory) the Device object for the mailslot
  18. // Structurally the layout of the data structure is as follows
  19. //
  20. // +------------+
  21. // |MSDO |
  22. // | |
  23. // +------------+
  24. // |Vcb |
  25. // | |
  26. // | |
  27. // +------------+
  28. // | ^
  29. // | |
  30. // | |
  31. // v |
  32. // +-------------+
  33. // |RootDcb |
  34. // | |<-+
  35. // +-------------+ |
  36. // : |
  37. // : |
  38. // : |
  39. // v |
  40. // +----------------+ +-------------------+
  41. // |Fcb | |Ccb |
  42. // | |<---| |
  43. // | | | |
  44. // +----------------+ +-------------------+
  45. // ^ ^
  46. // | |
  47. // +---------+ +---------+
  48. // |Server FO| |Client FO|
  49. // | | | |
  50. // +---------+ +---------+
  51. //
  52. //
  53. // Where there is only one VCB for the entire mailslot file system, and
  54. // it contains a single pointer to the root DCB for the file system. Off
  55. // of the DCB is a queue of FCB's. There is one FCB for every mailslot.
  56. // There are also two additional CCB types for the VCB and the root DCB,
  57. // and notify records for the notify change operations.
  58. //
  59. // A newly initialized mailslot file system only contains the VCB and
  60. // the root DCB. A new FCB is created when a new mailslot is created
  61. // The file object for the creater (i.e., server end) points to the FCB
  62. // and indicates that it is the server end. When a user does an open on
  63. // the mailslot its file object is set to point to a CCB which belongs
  64. // to the FCB.
  65. //
  66. // A file object with a null pointer to the FsContext field is a closed or
  67. // disconnected mailslot.
  68. //
  69. //
  70. // Each Fcb has a data queues for holding the outstanding
  71. // read/write requests. The following type is used to determine
  72. // if the data queue contains read requests, write requests, or is empty.
  73. //
  74. typedef enum _QUEUE_STATE {
  75. ReadEntries,
  76. WriteEntries,
  77. Empty
  78. } QUEUE_STATE;
  79. //
  80. // The node state.
  81. //
  82. // Currently only 2 states are defined. When a node is created it's state
  83. // is NodeStateActive. When a cleanup IRP is processed, it set the node
  84. // state of the corresponding node to NodeStateClosing. Only the close
  85. // IRP can get processed on this node.
  86. //
  87. typedef enum _NODE_STATE {
  88. NodeStateActive,
  89. NodeStateClosing
  90. } NODE_STATE;
  91. //
  92. // The types of data entry there are. Each corresponds to an IRP
  93. // that can be added to a data queue.
  94. //
  95. typedef enum _ENTRY_TYPE {
  96. Read,
  97. ReadMailslot,
  98. Write,
  99. WriteMailslot,
  100. Peek
  101. } ENTRY_TYPE;
  102. //
  103. // The data queue is a structure that contains the queue state, quota
  104. // information, and the list head. The quota information is used to
  105. // maintain mailslot quota.
  106. //
  107. typedef struct _DATA_QUEUE {
  108. //
  109. // The current state of what is contained in this data queue,
  110. // how many bytes of read/write data there are, and how many individual
  111. // requests there are in the queue that contain data (includes
  112. // close or flush requests).
  113. //
  114. QUEUE_STATE QueueState;
  115. ULONG BytesInQueue;
  116. ULONG EntriesInQueue;
  117. //
  118. // The following two fields denote who much quota was reserved for
  119. // this mailslot and how much we've used up. This is only
  120. // the creator quota and not the user quota.
  121. //
  122. ULONG Quota;
  123. ULONG QuotaUsed;
  124. //
  125. // The size of the largest message that can be written to
  126. // this data queue.
  127. //
  128. ULONG MaximumMessageSize;
  129. //
  130. // The queue of data entries.
  131. //
  132. LIST_ENTRY DataEntryList;
  133. } DATA_QUEUE, *PDATA_QUEUE;
  134. //
  135. // The following type is used to denote where we got the memory for the
  136. // data entry and possibly the data buffer. We either got the memory
  137. // from the mailslot quota, the user quota, or it is part of the next IRP
  138. // stack location.
  139. //
  140. typedef enum _FROM {
  141. MailslotQuota,
  142. UserQuota,
  143. InIrp
  144. } FROM;
  145. //
  146. // Each entry in the data queue is a data entry. Processing an IRP
  147. // has the potential of creating and inserting a new data entry. If the
  148. // memory for the entry is taken from the IRP we use the current stack
  149. // location.
  150. //
  151. typedef struct _DATA_ENTRY {
  152. //
  153. // Where the data buffer came from
  154. //
  155. UCHAR From;
  156. CHAR Spare1;
  157. USHORT Spare2;
  158. //
  159. // The following field is how we connect into the queue of data entries
  160. //
  161. LIST_ENTRY ListEntry;
  162. //
  163. // The following field indicates if we still have an IRP associated
  164. // with this data entry that need to be completed when the remove
  165. // the data entry. Note that if From is InIrp that this IRP field
  166. // must not be null.
  167. //
  168. PIRP Irp;
  169. //
  170. // The following two fields describe the size and location of the data
  171. // buffer described by this entry. These fields are only used if the
  172. // type is buffered, and are ignored otherwise.
  173. //
  174. ULONG DataSize;
  175. PVOID DataPointer;
  176. //
  177. // Used for read data entries only. A pointer to the work context
  178. // of the time out.
  179. //
  180. struct _WORK_CONTEXT *TimeoutWorkContext;
  181. } DATA_ENTRY, *PDATA_ENTRY;
  182. //
  183. // The node header is used to manage standard nodes within MSFS.
  184. //
  185. typedef struct _NODE_HEADER {
  186. NODE_TYPE_CODE NodeTypeCode; // The node type
  187. NODE_BYTE_SIZE NodeByteSize; // The size of the node
  188. NODE_STATE NodeState; // The current node state
  189. ULONG ReferenceCount; // Number of active references to the node
  190. } NODE_HEADER, *PNODE_HEADER;
  191. typedef struct _VCB {
  192. NODE_HEADER Header;
  193. //
  194. // The filesystem name
  195. //
  196. UNICODE_STRING FileSystemName;
  197. //
  198. // The time we created the volume
  199. //
  200. LARGE_INTEGER CreationTime;
  201. //
  202. // A pointer to the root DCB for this volume
  203. //
  204. struct _FCB *RootDcb;
  205. //
  206. // A prefix table that is used for quick, prefix directed, lookup of
  207. // FCBs/DCBs that are part of this volume
  208. //
  209. UNICODE_PREFIX_TABLE PrefixTable;
  210. //
  211. // A resource variable to control access to the volume specific data
  212. // structures
  213. //
  214. ERESOURCE Resource;
  215. //
  216. // The following field is used to check share access people who want
  217. // to open the mailslot driver
  218. //
  219. SHARE_ACCESS ShareAccess;
  220. } VCB, *PVCB;
  221. //
  222. // The Mailslot Device Object is an I/O system device object with
  223. // additional workqueue parameters appended to the end. There is only
  224. // one of these records created for the entire system during system
  225. // initialization. The workqueue is used by the FSD to post requests to
  226. // the filesystem.
  227. //
  228. typedef struct _MSFS_DEVICE_OBJECT {
  229. DEVICE_OBJECT DeviceObject;
  230. //
  231. // This is the file system specific volume control block.
  232. //
  233. VCB Vcb;
  234. } MSFS_DEVICE_OBJECT, *PMSFS_DEVICE_OBJECT;
  235. //
  236. // The Fcb/Dcb record corresponds to every opened mailslot and directory,
  237. // and to every directory on an opened path.
  238. //
  239. typedef struct _FCB {
  240. //
  241. // Header.NodeTypeCode of this record (must be MSFS_NTC_FCB, or
  242. // MSFS_NTC_ROOT_DCB)
  243. //
  244. NODE_HEADER Header;
  245. //
  246. // The links for the queue of all fcbs for a specific DCB off of
  247. // Dcb.ParentDcbQueue. For the root directory this queue is empty.
  248. //
  249. LIST_ENTRY ParentDcbLinks;
  250. //
  251. // A pointer to the Dcb that is the parent directory containing
  252. // this FCB. If this record itself is the root dcb then this field
  253. // is null.
  254. //
  255. struct _FCB *ParentDcb;
  256. //
  257. // A pointer to the VCB containing this FCB.
  258. //
  259. PVCB Vcb;
  260. //
  261. // Back pointer to the server's file object.
  262. //
  263. PFILE_OBJECT FileObject;
  264. //
  265. // A pointer to the security descriptor for this mailslot.
  266. //
  267. PSECURITY_DESCRIPTOR SecurityDescriptor;
  268. //
  269. // The following union is cased off of the node type code for the FCB.
  270. // is a seperate case for the directory versus file FCBs.
  271. //
  272. union {
  273. //
  274. // A Directory Control Block (DCB)
  275. //
  276. struct {
  277. //
  278. // A queue of the notify IRPs that will be completed when any
  279. // change is made to a file in the directory. Queued using
  280. // the Tail.Overlay.ListEntry of the IRP.
  281. //
  282. LIST_ENTRY NotifyFullQueue;
  283. //
  284. // A queue of the notify IRPs that will be completed only if a
  285. // file is added, deleted, or renamed in the directory. Queued
  286. // using the Tail.Overlay.ListEntry of the IRP.
  287. //
  288. LIST_ENTRY NotifyPartialQueue;
  289. //
  290. // A queue of all the FCBs/DCBs that are opened under this
  291. // DCB.
  292. //
  293. LIST_ENTRY ParentDcbQueue;
  294. //
  295. // Spinlock to protect the queues above that contain cancelable IRPs. We can't
  296. // synchronize with a resource because IoCancelIrp can be called at DISPATCH_LEVEL.
  297. //
  298. KSPIN_LOCK SpinLock;
  299. } Dcb;
  300. //
  301. // A File Control Block (FCB)
  302. //
  303. struct {
  304. //
  305. // The following field is a queue head for a list of CCBs
  306. // that are opened under us.
  307. //
  308. LIST_ENTRY CcbQueue;
  309. //
  310. // The default read timeout. This is always a relative value.
  311. //
  312. LARGE_INTEGER ReadTimeout;
  313. //
  314. // File timestamps.
  315. //
  316. LARGE_INTEGER CreationTime;
  317. LARGE_INTEGER LastModificationTime;
  318. LARGE_INTEGER LastAccessTime;
  319. LARGE_INTEGER LastChangeTime;
  320. } Fcb;
  321. } Specific;
  322. //
  323. // The following field is used to check share access for
  324. // clients that want to open the file/directory.
  325. //
  326. SHARE_ACCESS ShareAccess;
  327. //
  328. // The following field is the fully qualified file name for this FCB/DCB
  329. // starting from the root of the volume, and last file name in the
  330. // fully qualified name.
  331. //
  332. UNICODE_STRING FullFileName;
  333. UNICODE_STRING LastFileName;
  334. //
  335. // The following field contains a prefix table entry that is used when
  336. // searching a volume for a name (or longest matching prefix)
  337. //
  338. UNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry;
  339. //
  340. // The following field is used to remember the process that created this
  341. // mailslot. It is needed to allocate quota and return quota.
  342. //
  343. PEPROCESS CreatorProcess;
  344. //
  345. // The following data queue is used to contain the buffered information
  346. // for the mailslot.
  347. //
  348. DATA_QUEUE DataQueue;
  349. //
  350. // A resource variable to control access to the File specific data
  351. // structures
  352. //
  353. ERESOURCE Resource;
  354. } FCB, DCB, ROOT_DCB, *PFCB, *PDCB, *PROOT_DCB;
  355. //
  356. // The CCB record is allocated for every cliennt side open of a mailslot.
  357. //
  358. typedef struct _CCB {
  359. //
  360. // Header.NodeTypeCode of this record (must be MSFS_NTC_CCB).
  361. //
  362. NODE_HEADER Header;
  363. //
  364. // The following field is a list entry for the list of ccb that we
  365. // are a member of.
  366. //
  367. LIST_ENTRY CcbLinks;
  368. //
  369. // A pointer to the FCB, or VCB that we are tied to
  370. //
  371. PFCB Fcb;
  372. //
  373. // Pointers to the file object of the client has opened this file.
  374. //
  375. PFILE_OBJECT FileObject;
  376. //
  377. // A resource to control access to the CCB.
  378. //
  379. ERESOURCE Resource;
  380. } CCB, *PCCB;
  381. //
  382. // The root DCB CCB record is allocated for every opened instance of the
  383. // root dcb. This record is pointed at by FsContext2.
  384. //
  385. typedef struct _ROOT_DCB_CCB {
  386. //
  387. // Header.NodeTypeCode of this record (must be MSFS_NTC_ROOT_DCB_CCB).
  388. //
  389. NODE_HEADER Header;
  390. //
  391. // A pointer to the VCB containing this CCB.
  392. //
  393. PVCB Vcb;
  394. //
  395. // Pointer to the DCB for this CCB
  396. //
  397. PROOT_DCB Dcb;
  398. //
  399. // The following field is a count of the last index returned
  400. // by query directory.
  401. //
  402. ULONG IndexOfLastCcbReturned;
  403. //
  404. // The following string is used as a query template for directory
  405. // query operations
  406. //
  407. PUNICODE_STRING QueryTemplate;
  408. } ROOT_DCB_CCB, *PROOT_DCB_CCB;
  409. //
  410. // A work context contains the information needed to do read timeouts.
  411. //
  412. typedef struct _WORK_CONTEXT {
  413. //
  414. // Pointer to unload safe work item.
  415. //
  416. PIO_WORKITEM WorkItem;
  417. //
  418. // A pointer to the IRP for this operation.
  419. //
  420. PIRP Irp;
  421. //
  422. // A referenced pointer to the FCB that will process this operation.
  423. //
  424. PFCB Fcb;
  425. //
  426. // A timer and dpc tourine to accomplish the timeout.
  427. //
  428. KTIMER Timer;
  429. KDPC Dpc;
  430. } WORK_CONTEXT, *PWORK_CONTEXT;
  431. #endif // _MSSTRUC_