Source code of Windows XP (NT5)
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.

610 lines
14 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. LfsDisk.h
  5. Abstract:
  6. This module defines the on-disk structures present in the log file.
  7. Author:
  8. Brian Andrew [BrianAn] 13-June-1991
  9. Revision History:
  10. IMPORTANT NOTE:
  11. The Log File Service will by used on systems that require that on-disk
  12. structures guarantee the natural alignment of all arithmetic quantities
  13. up to and including quad-word (64-bit) numbers. Therefore, all Lfs
  14. on-disk structures are quad-word aligned, etc.
  15. --*/
  16. #ifndef _LFSDISK_
  17. #define _LFSDISK_
  18. #define MINIMUM_LFS_PAGES 0x00000030
  19. #define MINIMUM_LFS_CLIENTS 1
  20. //
  21. // The following macros are used to set and query with respect to the
  22. // update sequence arrays.
  23. //
  24. #define UpdateSequenceStructureSize( MSH ) \
  25. ((((PMULTI_SECTOR_HEADER) (MSH))->UpdateSequenceArraySize - 1) * SEQUENCE_NUMBER_STRIDE)
  26. #define UpdateSequenceArraySize( STRUCT_SIZE ) \
  27. ((STRUCT_SIZE) / SEQUENCE_NUMBER_STRIDE + 1)
  28. #define FIRST_STRIDE \
  29. (SEQUENCE_NUMBER_STRIDE - sizeof( UPDATE_SEQUENCE_NUMBER ))
  30. //
  31. // Log client ID. This is used to uniquely identify a client for a
  32. // particular log file.
  33. //
  34. typedef struct _LFS_CLIENT_ID {
  35. USHORT SeqNumber;
  36. USHORT ClientIndex;
  37. } LFS_CLIENT_ID, *PLFS_CLIENT_ID;
  38. //
  39. // Log Record Header. This is the header that begins every Log Record in
  40. // the log file.
  41. //
  42. typedef struct _LFS_RECORD_HEADER {
  43. //
  44. // Log File Sequence Number of this log record.
  45. //
  46. LSN ThisLsn;
  47. //
  48. // The following fields are used to back link Lsn's. The ClientPrevious
  49. // and ClientUndoNextLsn fields are used by a client to link his log
  50. // records.
  51. //
  52. LSN ClientPreviousLsn;
  53. LSN ClientUndoNextLsn;
  54. //
  55. // The following field is the size of data area for this record. The
  56. // log record header will be padded if necessary to fill to a 64-bit
  57. // boundary, so the client data will begin on a 64-bit boundary to
  58. // insure that all of his data is 64-bit aligned. The below value
  59. // has not been padded to 64 bits however.
  60. //
  61. ULONG ClientDataLength;
  62. //
  63. // Client ID. This identifies the owner of this log record. The owner
  64. // is uniquely identified by his offset in the client array and the
  65. // sequence number associated with that client record.
  66. //
  67. LFS_CLIENT_ID ClientId;
  68. //
  69. // This the Log Record type. This could be a commit protocol record,
  70. // a client restart area or a client update record.
  71. //
  72. LFS_RECORD_TYPE RecordType;
  73. //
  74. // Transaction ID. This is used externally by a client (Transaction
  75. // Manager) to group log file entries.
  76. //
  77. TRANSACTION_ID TransactionId;
  78. //
  79. // Log record flags.
  80. //
  81. USHORT Flags;
  82. //
  83. // Alignment field.
  84. //
  85. USHORT AlignWord;
  86. } LFS_RECORD_HEADER, *PLFS_RECORD_HEADER;
  87. #define LOG_RECORD_MULTI_PAGE (0x0001)
  88. #define LFS_RECORD_HEADER_SIZE QuadAlign( sizeof( LFS_RECORD_HEADER ))
  89. //
  90. // Following are the version specific fields in the record page header.
  91. //
  92. typedef struct _LFS_UNPACKED_RECORD_PAGE {
  93. //
  94. // This gives us the offset of the free space in the page.
  95. //
  96. USHORT NextRecordOffset;
  97. USHORT WordAlign;
  98. //
  99. // Reserved. The following array is reserved for possible future use.
  100. //
  101. USHORT Reserved;
  102. //
  103. // Update Sequence Array. Used to protect the page block.
  104. //
  105. UPDATE_SEQUENCE_ARRAY UpdateSequenceArray;
  106. } LFS_UNPACKED_RECORD_PAGE, *PLFS_UNPACKED_RECORD_PAGE;
  107. typedef struct _LFS_PACKED_RECORD_PAGE {
  108. //
  109. // This gives us the offset of the free space in the page.
  110. //
  111. USHORT NextRecordOffset;
  112. USHORT WordAlign;
  113. ULONG DWordAlign;
  114. //
  115. // The following is the Lsn for the last log record which ends on the page.
  116. //
  117. LSN LastEndLsn;
  118. //
  119. // Update Sequence Array. Used to protect the page block.
  120. //
  121. UPDATE_SEQUENCE_ARRAY UpdateSequenceArray;
  122. } LFS_PACKED_RECORD_PAGE, *PLFS_PACKED_RECORD_PAGE;
  123. //
  124. // Log Record Page Header. This structure is present at the beginning of each
  125. // log file page in the client record section.
  126. //
  127. typedef struct _LFS_RECORD_PAGE_HEADER {
  128. //
  129. // Cache multisector protection header.
  130. //
  131. MULTI_SECTOR_HEADER MultiSectorHeader;
  132. union {
  133. //
  134. // Highest Lsn in this log file page. This field is only for
  135. // regular log pages.
  136. //
  137. LSN LastLsn;
  138. //
  139. // Log file offset. This is for the tail copies and indicates the
  140. // location in the file where the original lays. In this case the
  141. // LastLsn field above can be obtained from the last ending Lsn
  142. // field in the PACKED_RECORD_PAGE structure.
  143. //
  144. LONGLONG FileOffset;
  145. } Copy;
  146. //
  147. // Page Header Flags. These are the same flags that are stored in the
  148. // Lbcb->Flags field.
  149. //
  150. // LOG_PAGE_LOG_RECORD_END - Page contains the end of a log record
  151. //
  152. ULONG Flags;
  153. //
  154. // I/O Page Position. The following fields are used to determine
  155. // where this log page resides within a Lfs I/O transfer.
  156. //
  157. USHORT PageCount;
  158. USHORT PagePosition;
  159. //
  160. // The following is the difference between version 1.1 and earlier.
  161. //
  162. union {
  163. LFS_UNPACKED_RECORD_PAGE Unpacked;
  164. LFS_PACKED_RECORD_PAGE Packed;
  165. } Header;
  166. } LFS_RECORD_PAGE_HEADER, *PLFS_RECORD_PAGE_HEADER;
  167. #define LOG_PAGE_LOG_RECORD_END (0x00000001)
  168. #define LFS_UNPACKED_RECORD_PAGE_HEADER_SIZE ( \
  169. FIELD_OFFSET( LFS_RECORD_PAGE_HEADER, Header.Unpacked.UpdateSequenceArray ) \
  170. )
  171. #define LFS_PACKED_RECORD_PAGE_HEADER_SIZE ( \
  172. FIELD_OFFSET( LFS_RECORD_PAGE_HEADER, Header.Packed.UpdateSequenceArray ) \
  173. )
  174. //
  175. // Log Restart Page Header. This structure is at the head of the restart
  176. // areas in a log file.
  177. //
  178. typedef struct _LFS_RESTART_PAGE_HEADER {
  179. //
  180. // Cache multisector protection header.
  181. //
  182. MULTI_SECTOR_HEADER MultiSectorHeader;
  183. //
  184. // This is the last Lsn found by checkdisk for this volume.
  185. //
  186. LSN ChkDskLsn;
  187. //
  188. // System page size. This is the page size of the system which
  189. // initialized the log file. Unless the log file has been gracefully
  190. // shutdown (there are no clients with restart areas), it is a fatal
  191. // error to attempt to write to a log file on a system with a differen
  192. // page size.
  193. //
  194. ULONG SystemPageSize;
  195. //
  196. // Log Page Size. This is the log page size used for this log file.
  197. // The entire Lfs restart area must fit on a single log page.
  198. //
  199. ULONG LogPageSize;
  200. //
  201. // Lfs restart area offset. This is the offset from the start of this
  202. // structure to the Lfs restart area.
  203. //
  204. USHORT RestartOffset;
  205. //
  206. // The indicates major and minor versions. Note that the pre-release versions
  207. // have -1 in both positions. Major version 0 indicates the transition
  208. // from Beta to USA support.
  209. //
  210. // Major Version
  211. //
  212. // -1 Beta Version
  213. // 0 Transition
  214. // 1 Update sequence support.
  215. //
  216. SHORT MinorVersion;
  217. SHORT MajorVersion;
  218. //
  219. // Update Sequence Array. Used to protect the page block.
  220. //
  221. UPDATE_SEQUENCE_ARRAY UpdateSequenceArray;
  222. } LFS_RESTART_PAGE_HEADER, *PLFS_RESTART_PAGE_HEADER;
  223. #define LFS_RESTART_PAGE_HEADER_SIZE ( \
  224. FIELD_OFFSET( LFS_RESTART_PAGE_HEADER, UpdateSequenceArray ) \
  225. )
  226. //
  227. // Id strings for the page headers.
  228. //
  229. #define LFS_SIGNATURE_RESTART_PAGE "RSTR"
  230. #define LFS_SIGNATURE_RESTART_PAGE_ULONG 0x52545352
  231. #define LFS_SIGNATURE_RECORD_PAGE "RCRD"
  232. #define LFS_SIGNATURE_RECORD_PAGE_ULONG 0x44524352
  233. #define LFS_SIGNATURE_BAD_USA "BAAD"
  234. #define LFS_SIGNATURE_BAD_USA_ULONG 0x44414142
  235. #define LFS_SIGNATURE_MODIFIED "CHKD"
  236. #define LFS_SIGNATURE_MODIFIED_ULONG 0x444b4843
  237. #define LFS_SIGNATURE_UNINITIALIZED "\377\377\377\377"
  238. #define LFS_SIGNATURE_UNINITIALIZED_ULONG 0xffffffff
  239. //
  240. // Log Client Record. A log client record exists for each client user of
  241. // the log file. One of these is in each Lfs restart area.
  242. //
  243. #define LFS_NO_CLIENT 0xffff
  244. #define LFS_CLIENT_NAME_MAX 64
  245. typedef struct _LFS_CLIENT_RECORD {
  246. //
  247. // Oldest Lsn. This is the oldest Lsn that this client requires to
  248. // be in the log file.
  249. //
  250. LSN OldestLsn;
  251. //
  252. // Client Restart Lsn. This is the Lsn of the latest client restart
  253. // area written to the disk. A reserved Lsn will indicate that no
  254. // restart area exists for this client.
  255. //
  256. LSN ClientRestartLsn;
  257. //
  258. //
  259. // Previous/Next client area. These are the indexes into an array of
  260. // Log Client Records for the previous and next client records.
  261. //
  262. USHORT PrevClient;
  263. USHORT NextClient;
  264. //
  265. // Sequence Number. Incremented whenever this record is reused. This
  266. // will happen whenever a client opens (reopens) the log file and has
  267. // no current restart area.
  268. USHORT SeqNumber;
  269. //
  270. // Alignment field.
  271. //
  272. USHORT AlignWord;
  273. //
  274. // Align the entire record.
  275. //
  276. ULONG AlignDWord;
  277. //
  278. // The following fields are used to describe the client name. A client
  279. // name consists of at most 32 Unicode character (64 bytes). The Log
  280. // file service will treat client names as case sensitive.
  281. //
  282. ULONG ClientNameLength;
  283. WCHAR ClientName[LFS_CLIENT_NAME_MAX];
  284. } LFS_CLIENT_RECORD, *PLFS_CLIENT_RECORD;
  285. //
  286. // Lfs Restart Area. Two copies of these will exist at the beginning of the
  287. // log file.
  288. //
  289. typedef struct _LFS_RESTART_AREA {
  290. //
  291. // Current Lsn. This is periodic snapshot of the current logical end of
  292. // log file to facilitate restart.
  293. //
  294. LSN CurrentLsn;
  295. //
  296. // Number of Clients. This is the maximum number of clients supported
  297. // for this log file.
  298. //
  299. USHORT LogClients;
  300. //
  301. // The following are indexes into the client record arrays. The client
  302. // records are linked into two lists. A free list of client records and
  303. // an in-use list of records.
  304. //
  305. USHORT ClientFreeList;
  306. USHORT ClientInUseList;
  307. //
  308. // Flag field.
  309. //
  310. // RESTART_SINGLE_PAGE_IO All log pages written 1 by 1
  311. // LFS_CLEAN_SHUTDOWN
  312. //
  313. USHORT Flags;
  314. //
  315. // The following is the number of bits to use for the sequence number.
  316. //
  317. ULONG SeqNumberBits;
  318. //
  319. // Length of this restart area.
  320. //
  321. USHORT RestartAreaLength;
  322. //
  323. // Offset from the start of this structure to the client array.
  324. // Ignored in versions prior to 1.1
  325. //
  326. USHORT ClientArrayOffset;
  327. //
  328. // Usable log file size. We will stop sharing the value in the page header.
  329. //
  330. LONGLONG FileSize;
  331. //
  332. // DataLength of last Lsn. This doesn't include the length of
  333. // the Lfs header.
  334. //
  335. ULONG LastLsnDataLength;
  336. //
  337. // The following apply to log pages. This is the log page data offset and
  338. // the length of the log record header. Ignored in versions prior to 1.1
  339. //
  340. USHORT RecordHeaderLength;
  341. USHORT LogPageDataOffset;
  342. //
  343. // Log file open count. Used to determine if there has been a change to the disk.
  344. //
  345. ULONG RestartOpenLogCount;
  346. //
  347. // Track log flush failures
  348. //
  349. ULONG LastFailedFlushStatus;
  350. LONGLONG LastFailedFlushOffset;
  351. LSN LastFailedFlushLsn;
  352. //
  353. // Keep this structure quadword aligned.
  354. //
  355. //
  356. // Client data.
  357. //
  358. LFS_CLIENT_RECORD LogClientArray[1];
  359. } LFS_RESTART_AREA, *PLFS_RESTART_AREA;
  360. #define RESTART_SINGLE_PAGE_IO (0x0001)
  361. #define LFS_CLEAN_SHUTDOWN (0x0002)
  362. #define LFS_RESTART_AREA_SIZE (FIELD_OFFSET( LFS_RESTART_AREA, LogClientArray ))
  363. //
  364. // Remember the old size of the restart area when accessing older disks.
  365. //
  366. typedef struct _LFS_OLD_RESTART_AREA {
  367. //
  368. // Current Lsn. This is periodic snapshot of the current logical end of
  369. // log file to facilitate restart.
  370. //
  371. LSN CurrentLsn;
  372. //
  373. // Number of Clients. This is the maximum number of clients supported
  374. // for this log file.
  375. //
  376. USHORT LogClients;
  377. //
  378. // The following are indexes into the client record arrays. The client
  379. // records are linked into two lists. A free list of client records and
  380. // an in-use list of records.
  381. //
  382. USHORT ClientFreeList;
  383. USHORT ClientInUseList;
  384. //
  385. // Flag field.
  386. //
  387. // RESTART_SINGLE_PAGE_IO All log pages written 1 by 1
  388. //
  389. USHORT Flags;
  390. //
  391. // The following is the number of bits to use for the sequence number.
  392. //
  393. ULONG SeqNumberBits;
  394. //
  395. // Length of this restart area.
  396. //
  397. USHORT RestartAreaLength;
  398. //
  399. // Offset from the start of this structure to the client array.
  400. // Ignored in versions prior to 1.1
  401. //
  402. USHORT ClientArrayOffset;
  403. //
  404. // Usable log file size. We will stop sharing the value in the page header.
  405. //
  406. LONGLONG FileSize;
  407. //
  408. // DataLength of last Lsn. This doesn't include the length of
  409. // the Lfs header.
  410. //
  411. ULONG LastLsnDataLength;
  412. //
  413. // The following apply to log pages. This is the log page data offset and
  414. // the length of the log record header. Ignored in versions prior to 1.1
  415. //
  416. USHORT RecordHeaderLength;
  417. USHORT LogPageDataOffset;
  418. //
  419. // Client data.
  420. //
  421. LFS_CLIENT_RECORD LogClientArray[1];
  422. } LFS_OLD_RESTART_AREA, *PLFS_OLD_RESTART_AREA;
  423. #endif // _LFSDISK_