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.

614 lines
15 KiB

4 years ago
  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. LfsStruc.h
  5. Abstract:
  6. This module defines the data structures that make up the major internal
  7. part of the Log File Service.
  8. Author:
  9. Brian Andrew [BrianAn] 13-June-1991
  10. Revision History:
  11. --*/
  12. #ifndef _LFSSTRUC_
  13. #define _LFSSTRUC_
  14. typedef PVOID PBCB; //**** Bcb's are now part of the cache module
  15. //
  16. // Log Context Block. A pointer to this structure is returned to the user
  17. // when a client is reading a particular set of log records from the log
  18. // file.
  19. //
  20. typedef struct _LCB {
  21. //
  22. // The type and size of this record (must be LFS_NTC_LCB)
  23. //
  24. NODE_TYPE_CODE NodeTypeCode;
  25. NODE_BYTE_SIZE NodeByteSize;
  26. //
  27. // Log record header. This is the mapped log record header and bcb
  28. // for the record header of the current Lsn.
  29. //
  30. struct _LFS_RECORD_HEADER *RecordHeader;
  31. PBCB RecordHeaderBcb;
  32. //
  33. // Context Mode. This is the mode governing the log record lookup. We
  34. // can look backwards via the ClientUndoNextLsn or ClientPreviousLsn.
  35. // We can also look forwards by walking through all the log records and
  36. // comparing ClientId fields.
  37. //
  38. LFS_CONTEXT_MODE ContextMode;
  39. //
  40. // Client Id. This is the client ID for the log records being returned.
  41. //
  42. LFS_CLIENT_ID ClientId;
  43. //
  44. // Log record pointer. This is the address returned to the user as the
  45. // log record referred to by CurrentLsn. If we allocated a buffer to
  46. // hold the record, we need to deallocate it as necessary.
  47. //
  48. // This field is either the actual mapped log record or a pointer to
  49. // an auxilary buffer allocated by the Lfs.
  50. //
  51. PVOID CurrentLogRecord;
  52. BOOLEAN AuxilaryBuffer;
  53. } LCB, *PLCB;
  54. //
  55. // Lfcb synchronization. This is the synchronization structure used by the Lfcb.
  56. //
  57. typedef struct _LFCB_SYNC {
  58. //
  59. // Principal Lfcb Resource.
  60. //
  61. ERESOURCE Resource;
  62. //
  63. // Notification Event. This event is set to the Signalled state when
  64. // pages are flushed to the cache file. Any waiters will then check
  65. // to see if the Lsn they're waiting for made it to disk.
  66. //
  67. KEVENT Event;
  68. //
  69. // User Count. Number of clients using this structure. We will deallocate
  70. // when all clients are gone.
  71. //
  72. ULONG UserCount;
  73. } LFCB_SYNC, *PLFCB_SYNC;
  74. //
  75. // Log Client Structure. The Lfs allocates one of these for each active
  76. // client. The address of this structure will be returned to the user
  77. // as a log handle.
  78. //
  79. typedef struct _LCH {
  80. //
  81. // The type and size of this record (must be LFS_NTC_LCH)
  82. //
  83. NODE_TYPE_CODE NodeTypeCode;
  84. NODE_BYTE_SIZE NodeByteSize;
  85. //
  86. // Links for all the client handles on an Lfcb.
  87. //
  88. LIST_ENTRY LchLinks;
  89. //
  90. // Log File Control Block. This is the log file for this log handle.
  91. //
  92. struct _LFCB *Lfcb;
  93. //
  94. // Client Id. This refers to the client record for this client in the
  95. // Lfs restart area.
  96. //
  97. LFS_CLIENT_ID ClientId;
  98. //
  99. // The following is the number of bytes this client has asked to
  100. // have reserved in the log file. It includes the space
  101. // for the log record headers.
  102. //
  103. LONGLONG ClientUndoCommitment;
  104. //
  105. // Byte offset in the client array.
  106. //
  107. ULONG ClientArrayByteOffset;
  108. //
  109. // Pointer to the resource in the Lfcb. We access the resource with
  110. // this pointer for the times when the lfcb has been deleted.
  111. //
  112. PLFCB_SYNC Sync;
  113. } LCH, *PLCH;
  114. //
  115. // Log Buffer Control Block. A buffer control block is associated with
  116. // each of the log buffers. They are used to serialize access to the
  117. // log file.
  118. //
  119. typedef struct _LBCB {
  120. //
  121. // The type and size of this record (must be LFS_NTC_LBCB)
  122. //
  123. NODE_TYPE_CODE NodeTypeCode;
  124. NODE_BYTE_SIZE NodeByteSize;
  125. //
  126. // Buffer Block Links. These fields are used to link the buffer blocks
  127. // together.
  128. //
  129. LIST_ENTRY WorkqueLinks;
  130. LIST_ENTRY ActiveLinks;
  131. //
  132. // Log file position and length. This is the location in the log file to write
  133. // out this buffer.
  134. //
  135. LONGLONG FileOffset;
  136. LONGLONG Length;
  137. //
  138. // Sequence number. This is the sequence number for log records which
  139. // begin on this page.
  140. //
  141. LONGLONG SeqNumber;
  142. //
  143. // Next Offset. This is the next offset to write a log record in the
  144. // this log page. Stored as a large integer to facilitate large
  145. // integer operations.
  146. //
  147. LONGLONG BufferOffset;
  148. //
  149. // Buffer. This field points to the buffer containing the log page
  150. // for this block. For a log record page this is a pointer to
  151. // a pinned cache buffer, for a log restart page, this is a pointer
  152. // to an auxilary buffer.
  153. //
  154. PVOID PageHeader;
  155. //
  156. // Bcb for Log Page Block. This is the Bcb for the pinned data.
  157. // If this buffer block describes an Lfs restart area, this field is NULL.
  158. //
  159. PBCB LogPageBcb;
  160. //
  161. // Last Lsn. This is the Lsn for the last log record on this page. We delay
  162. // writing it until the page is flushed, storing it here instead.
  163. //
  164. LSN LastLsn;
  165. //
  166. // Last complete Lsn. This is the Lsn for the last log record which ends
  167. // on this page.
  168. //
  169. LSN LastEndLsn;
  170. //
  171. // Page Flags. These are the flags associated with this log page.
  172. // We store them in the Lbcb until the page is written. They flags
  173. // to use are the same as in the log record page header.
  174. //
  175. // LOG_PAGE_LOG_RECORD_END - Page contains the end of a log record
  176. // LOG_PAGE_PACKED - Page contains packed log records
  177. // LOG_PAGE_TAIL_COPY - Page is a copy of the log file end
  178. //
  179. ULONG Flags;
  180. //
  181. // Lbcb flags. These are flags used to describe this Lbcb.
  182. //
  183. // LBCB_LOG_WRAPPED - Lbcb has wrapped the log file
  184. // LBCB_ON_ACTIVE_QUEUE - Lbcb is on the active queue
  185. // LBCB_NOT_EMPTY - Page has existing log record
  186. // LBCB_FLUSH_COPY - Write copy of this page first
  187. // LBCB_RESTART_LBCB - This Lbcb contains a restart page
  188. //
  189. ULONG LbcbFlags;
  190. //
  191. // This is the thread which has locked the log page.
  192. //
  193. ERESOURCE_THREAD ResourceThread;
  194. } LBCB, *PLBCB;
  195. #define LBCB_LOG_WRAPPED (0x00000001)
  196. #define LBCB_ON_ACTIVE_QUEUE (0x00000002)
  197. #define LBCB_NOT_EMPTY (0x00000004)
  198. #define LBCB_FLUSH_COPY (0x00000008)
  199. #define LBCB_RESTART_LBCB (0x00000020)
  200. //
  201. // Log file data. This data structure is used on a per-log file basis.
  202. //
  203. typedef enum _LFS_IO_STATE {
  204. LfsNoIoInProgress = 0,
  205. LfsClientThreadIo
  206. } LFS_IO_STATE;
  207. typedef struct _LFCB {
  208. //
  209. // The type and size of this record (must be LFS_NTC_LFCB)
  210. //
  211. NODE_TYPE_CODE NodeTypeCode;
  212. NODE_BYTE_SIZE NodeByteSize;
  213. //
  214. // Lfcb Links. The following links the file control blocks to the
  215. // global data structure.
  216. //
  217. LIST_ENTRY LfcbLinks;
  218. //
  219. // Lch Links. The following links all of the handles for the Lfcb.
  220. //
  221. LIST_ENTRY LchLinks;
  222. //
  223. //
  224. // File Object. This is the file object for the log file.
  225. //
  226. PFILE_OBJECT FileObject;
  227. //
  228. // Log File Size. This is the size of the log file.
  229. // The second value is the size proposed by this open.
  230. //
  231. LONGLONG FileSize;
  232. //
  233. // System page size and masks.
  234. //
  235. LONGLONG SystemPageSize;
  236. ULONG SystemPageMask;
  237. ULONG SystemPageInverseMask;
  238. //
  239. // Log page size, masks and shift count to do multiplication and division
  240. // of log pages.
  241. //
  242. LONGLONG LogPageSize;
  243. ULONG LogPageMask;
  244. ULONG LogPageInverseMask;
  245. ULONG LogPageShift;
  246. //
  247. // First log page. This is the offset in the file of the first
  248. // log page with log records.
  249. //
  250. LONGLONG FirstLogPage;
  251. //
  252. // Next log page offset. This is the offset of the next log page to use.
  253. // If we are reusing this page we store the offset to begin with.
  254. //
  255. LONGLONG NextLogPage;
  256. ULONG ReusePageOffset;
  257. //
  258. // Data Offset. This is the offset within a log page of the data that
  259. // appears on that page. This will be the actual restart data for
  260. // an Lfs restart page, or the beginning of log record data for a log
  261. // record page.
  262. //
  263. ULONG RestartDataOffset;
  264. LONGLONG LogPageDataOffset;
  265. //
  266. // Data Size. This is the amount of data that may be stored on a
  267. // log page. It is included here because it is frequently used. It
  268. // is simply the log page size minus the data offset.
  269. //
  270. ULONG RestartDataSize;
  271. LONGLONG LogPageDataSize;
  272. //
  273. // Record header size. This is the size to use for the record headers
  274. // when reading the log file.
  275. //
  276. USHORT RecordHeaderLength;
  277. //
  278. // Sequence number. This is the number of times we have cycled through
  279. // the log file. The wrap sequence number is used to confirm that we
  280. // have gone through the entire file at least once. When we write a
  281. // log record page for an Lsn with this sequence number, then we have
  282. // cycled through the file.
  283. //
  284. LONGLONG SeqNumber;
  285. LONGLONG SeqNumberForWrap;
  286. ULONG SeqNumberBits;
  287. ULONG FileDataBits;
  288. //
  289. // Buffer Block Links. The following links the buffer blocks for this
  290. // log file.
  291. //
  292. LIST_ENTRY LbcbWorkque;
  293. LIST_ENTRY LbcbActive;
  294. PLBCB ActiveTail;
  295. PLBCB PrevTail;
  296. //
  297. // The enumerated type indicates if there is an active write for
  298. // this log file and whether it is being done by an Lfs or
  299. // client thread.
  300. //
  301. LFS_IO_STATE LfsIoState;
  302. //
  303. // Current Restart Area. The following is the in-memory image of the
  304. // next restart area. We also store a pointer to the client data
  305. // array in the restart area. The client array offset is from the start of
  306. // the restart area.
  307. //
  308. PLFS_RESTART_AREA RestartArea;
  309. PLFS_CLIENT_RECORD ClientArray;
  310. USHORT ClientArrayOffset;
  311. USHORT ClientNameOffset;
  312. //
  313. // Restart Area size. This is the usable size of the restart area.
  314. //
  315. ULONG RestartAreaSize;
  316. USHORT LogClients;
  317. //
  318. // Initial Restart area. If true, then the in-memory restart area is to
  319. // be written to the first position on the disk.
  320. //
  321. BOOLEAN InitialRestartArea;
  322. //
  323. // The following pseudo Lsn's are used to track when restart areas
  324. // are flushed to the disk.
  325. //
  326. LSN NextRestartLsn;
  327. LSN LastFlushedRestartLsn;
  328. //
  329. // The following is the earliest Lsn we will guarantee is still in the
  330. // log file.
  331. //
  332. LSN OldestLsn;
  333. //
  334. // The following is the file offset of the oldest Lsn in the system.
  335. // We redundantly store it in this form since we will be constantly
  336. // checking if a new log record will write over part of the file
  337. // we are trying to maintain.
  338. //
  339. LONGLONG OldestLsnOffset;
  340. //
  341. // Last Flushed Lsn. The following is the last Lsn guaranteed to
  342. // be flushed to the disk.
  343. //
  344. LSN LastFlushedLsn;
  345. //
  346. //
  347. // The following fields are used to track current usage in the log file.
  348. //
  349. // TotalAvailable - is the total number of bytes available for
  350. // log records. It is the number of log pages times the
  351. // data size of each page.
  352. //
  353. // TotalAvailInPages - is the total number of bytes in the log
  354. // pages for log records. This is TotalAvailable without
  355. // subtracting the size of the page headers.
  356. //
  357. // TotalUndoCommitment - is the number of bytes reserved for
  358. // possible abort operations. This includes space for
  359. // log record headers as well.
  360. //
  361. // MaxCurrentAvail - is the maximum available in all pages
  362. // subtracting the page header and any reserved tail.
  363. //
  364. // CurrentAvailable - is the total number of bytes available in
  365. // unused pages in the log file.
  366. //
  367. // ReservedLogPageSize - is the number of bytes on a page available
  368. // for reservation.
  369. //
  370. LONGLONG TotalAvailable;
  371. LONGLONG TotalAvailInPages;
  372. LONGLONG TotalUndoCommitment;
  373. LONGLONG MaxCurrentAvail;
  374. LONGLONG CurrentAvailable;
  375. LONGLONG ReservedLogPageSize;
  376. //
  377. // The following fields are used to store information about the
  378. // update sequence arrays.
  379. //
  380. USHORT RestartUsaOffset;
  381. USHORT RestartUsaArraySize;
  382. USHORT LogRecordUsaOffset;
  383. USHORT LogRecordUsaArraySize;
  384. //
  385. // Major and minor version numbers.
  386. //
  387. SHORT MajorVersion;
  388. SHORT MinorVersion;
  389. //
  390. // Log File Flags.
  391. //
  392. // LFCB_LOG_WRAPPED - We found an Lbcb which wraps the log file
  393. // LFCB_MULTIPLE_PAGE_IO - Write multiple pages if possible
  394. // LFCB_NO_LAST_LSN - There are no log records to return
  395. // LFCB_PACK_LOG - Pack the records into the pages
  396. // LFCB_REUSE_TAIL - We will be reusing the tail of the log file after restart
  397. // LFCB_NO_OLDEST_LSN - There is no oldest page being reserved
  398. //
  399. ULONG Flags;
  400. //
  401. // The following are the spare Lbcb's for the volume and a field with
  402. // the count for these.
  403. //
  404. ULONG SpareLbcbCount;
  405. LIST_ENTRY SpareLbcbList;
  406. //
  407. // The following structure synchronizes access to this structure.
  408. //
  409. PLFCB_SYNC Sync;
  410. } LFCB, *PLFCB;
  411. #define LFCB_LOG_WRAPPED (0x00000001)
  412. #define LFCB_MULTIPLE_PAGE_IO (0x00000002)
  413. #define LFCB_NO_LAST_LSN (0x00000004)
  414. #define LFCB_PACK_LOG (0x00000008)
  415. #define LFCB_REUSE_TAIL (0x00000010)
  416. #define LFCB_NO_OLDEST_LSN (0x00000020)
  417. #define LFCB_LOG_FILE_CORRUPT (0x00000040)
  418. #define LFCB_FINAL_SHUTDOWN (0x00000080)
  419. #define LFCB_READ_FIRST_RESTART (0x00000100)
  420. #define LFCB_READ_SECOND_RESTART (0x00000200)
  421. #define LFCB_RESERVE_LBCB_COUNT (5)
  422. #define LFCB_MAX_LBCB_COUNT (25)
  423. //
  424. // Global Log Data. The following structure has only one instance and
  425. // maintains global information for the entire logging service.
  426. //
  427. typedef struct _LFS_DATA {
  428. //
  429. // The type and size of this record (must be LFS_NTC_DATA)
  430. //
  431. NODE_TYPE_CODE NodeTypeCode;
  432. NODE_BYTE_SIZE NodeByteSize;
  433. //
  434. // The following field links all of the Log File Control Blocks for
  435. // the logging system.
  436. //
  437. LIST_ENTRY LfcbLinks;
  438. //
  439. // Flag field.
  440. //
  441. ULONG Flags;
  442. //
  443. // The following event controls access to this structure.
  444. //
  445. KEVENT Event;
  446. } LFS_DATA, *PLFS_DATA;
  447. #define LFS_DATA_INIT_FAILED 0x00000001
  448. #define LFS_DATA_INITIALIZED 0x00000002
  449. #endif // _LFSSTRUC_