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.

239 lines
7.2 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Lfs.h
  5. Abstract:
  6. This module contains the public data structures and procedure
  7. prototypes for the Log File Service.
  8. Author:
  9. Brian Andrew [BrianAn] 20-June-1991
  10. Revision History:
  11. --*/
  12. #ifndef _LFS_
  13. #define _LFS_
  14. //
  15. // The Multi-Sector Header and Update Sequence Array provide detection of
  16. // incomplete multi-sector transfers for devices which either have a
  17. // physical sector size equal to the Sequence Number Stride or greater, or
  18. // which do not transfer sectors out of order. If a device exists which has
  19. // a sector size smaller than the Sequence Number Stride *and* it sometimes
  20. // transfers sectors out of order, then the Update Sequence Array will not
  21. // provide absolute detection of incomplete transfers. The Sequence Number
  22. // Stride is set to a small enough number to provide absolute protection for
  23. // all known hard disks. It is not set any smaller, in order to avoid
  24. // excessive run time and space overhead.
  25. //
  26. // The Multi-Sector Header contains space for a four-byte signature for the
  27. // convenience of its user. It then provides the offset to and length of the
  28. // the Update Sequence Array. The Update Sequence Array consists of an array
  29. // of n saved USHORTs, where n is the size of the structure being protected
  30. // divided by the sequence number stride. (The size of structure being
  31. // protected must be a nonzero power of 2 times the Sequence Number Stride,
  32. // and less than or equal to the physical page size of the machine.) The
  33. // first word of the Update Sequence Array contains the Update Sequence Number,
  34. // which is a cyclical counter (however 0 is not used) of the number of times
  35. // the containing structure has been written to disk. Following the Update
  36. // Sequence Number are the n saved USHORTs which were overwritten by the
  37. // Update Sequence Number the last time the containing structure was
  38. // written to disk.
  39. //
  40. // In detail, just prior to each time the protected structure is written to
  41. // disk, the last word in each Sequence Number Stride is saved to its
  42. // respective position in the Sequence Number Array, and then it is overwritten
  43. // with the next Update Sequence Number. Just after this write, or whenever
  44. // reading the structure, the saved word from the Sequence Number Array is
  45. // restored to its actual position in the structure. Before restoring the
  46. // saved words on reads, all of the sequence numbers at the end of each
  47. // stride are compared with the actual sequence number at the start of the
  48. // array. If any of these compares come up not equal, then a failed
  49. // multi-sector transfer has been detected.
  50. //
  51. // The size of the array is determined by the size of the containing structure.
  52. // As a C detail, the array is declared here with a size of 1, since its
  53. // actual size can only be determined at runtime.
  54. //
  55. // The Update Sequence Array should be included at the end of the header of
  56. // the structure it is protecting, since it is variable size. Its user must
  57. // insure that the correct size is reserved for it, namely:
  58. //
  59. // (sizeof-structure / SEQUENCE_NUMBER_STRIDE + 1) * sizeof(USHORT)
  60. //
  61. #define SEQUENCE_NUMBER_STRIDE (512)
  62. typedef USHORT UPDATE_SEQUENCE_NUMBER, *PUPDATE_SEQUENCE_NUMBER;
  63. //
  64. // This array must be present at the offset described above.
  65. //
  66. typedef UPDATE_SEQUENCE_NUMBER UPDATE_SEQUENCE_ARRAY[1];
  67. typedef UPDATE_SEQUENCE_ARRAY *PUPDATE_SEQUENCE_ARRAY;
  68. //
  69. // The following structure is used to identify a log record by a log
  70. // sequence number.
  71. //
  72. typedef LARGE_INTEGER LSN, *PLSN;
  73. //
  74. // The following Lsn will never occur in a file, it is used to indicate
  75. // a non-lsn.
  76. //
  77. extern LSN LfsZeroLsn;
  78. //
  79. // The following type defines the different log record types.
  80. //
  81. typedef enum _LFS_RECORD_TYPE {
  82. LfsClientRecord = 1,
  83. LfsClientRestart
  84. } LFS_RECORD_TYPE, *PLFS_RECORD_TYPE;
  85. //
  86. // The following search modes are supported.
  87. //
  88. typedef enum _LFS_CONTEXT_MODE {
  89. LfsContextUndoNext = 1,
  90. LfsContextPrevious,
  91. LfsContextForward
  92. } LFS_CONTEXT_MODE, *PLFS_CONTEXT_MODE;
  93. typedef ULONG TRANSACTION_ID, *PTRANSACTION_ID;
  94. typedef enum _TRANSACTION_STATE {
  95. TransactionUninitialized = 0,
  96. TransactionActive,
  97. TransactionPrepared,
  98. TransactionCommitted
  99. } TRANSACTION_STATE, *PTRANSACTION_STATE;
  100. typedef enum _LFS_INFO {
  101. LfsUseUsa = 1,
  102. LfsPackLog
  103. } LFS_INFO, *PLFS_INFO;
  104. typedef PVOID LFS_LOG_HANDLE, *PLFS_LOG_HANDLE;
  105. typedef PVOID LFS_LOG_CONTEXT, *PLFS_LOG_CONTEXT;
  106. //
  107. // Write Entry for LfsWrite and LfsForceWrite. The interface to these
  108. // routines takes a pointer to a Write Entry along with a count of how
  109. // many Write Entries to expect to describe pieces of the caller's buffer
  110. // which are supposed to be copied in sequence to the log file.
  111. //
  112. typedef struct _LFS_WRITE_ENTRY {
  113. PVOID Buffer;
  114. ULONG ByteLength;
  115. } LFS_WRITE_ENTRY, *PLFS_WRITE_ENTRY;
  116. //
  117. // Global Maintenance routines
  118. //
  119. BOOLEAN
  120. LfsInitializeLogFileService (
  121. );
  122. //
  123. // Log File Registration routines
  124. //
  125. typedef struct _LOG_FILE_INFORMATION {
  126. //
  127. // This is the total useable space in the log file after space for
  128. // headers and Lfs Restart Areas.
  129. //
  130. LONGLONG TotalAvailable;
  131. //
  132. // This is the useable space in the log file from the current position
  133. // in the log file to the lowest BaseLsn. This total as returned is not
  134. // yet reduced for undo commitments, returned separately below.
  135. //
  136. LONGLONG CurrentAvailable;
  137. //
  138. // This is the total undo commitment for all clients of the log file.
  139. // LfsWrite requests are refused when the sum of the write size of the
  140. // request plus the UndoRequirement for the request plus the TotalUndoCommitment
  141. // are greater than the CurrentAvailable.
  142. //
  143. LONGLONG TotalUndoCommitment;
  144. //
  145. // This is the total undo commitment for this client.
  146. //
  147. LONGLONG ClientUndoCommitment;
  148. //
  149. // Current system Lsn's. Includes the Oldest, LastFlushed and current
  150. // Lsn.
  151. //
  152. LSN OldestLsn;
  153. LSN LastFlushedLsn;
  154. LSN LastLsn;
  155. } LOG_FILE_INFORMATION, *PLOG_FILE_INFORMATION;
  156. #define LOG_FILE_DATA_BITS(D) ((sizeof(LSN) * 8) - GetSeqNumberBits(D))
  157. #define LOG_PAGE_MASK(D) (GetLogPageSize(D) - 1)
  158. #define LOG_PAGE_INVERSE_MASK(D) (~LOG_PAGE_MASK(D))
  159. #define LfsLogPageOffset(D, i) ((i) & LOG_PAGE_MASK(D))
  160. #define LfsLsnToPageOffset(D, lsn) (LfsLogPageOffset(D, (lsn).LowPart << three))
  161. extern const int three;
  162. #define LfsLsnToFileOffset(D, LSN) \
  163. /*xxShr*/(((ULONGLONG)/*xxShl*/((LSN).QuadPart << GetSeqNumberBits(D))) >> (GetSeqNumberBits(D) - three))
  164. #define LfsTruncateLsnToLogPage(D, lsn, FO) { \
  165. *(FO) = LfsLsnToFileOffset((D), (lsn)); \
  166. *((PULONG)(FO)) &= LOG_PAGE_INVERSE_MASK(D); \
  167. }
  168. #define LfsLsnToSeqNumber(D, LSN) \
  169. /*xxShr*/((ULONGLONG)/*xxShl*/((LSN).QuadPart) >> LOG_FILE_DATA_BITS(D))
  170. #define LfsFileOffsetToLsn(D, FO, SN) \
  171. ((((ULONGLONG)(FO)) >> three) + ((SN) << LOG_FILE_DATA_BITS(D)))
  172. extern ULONG GetLogPageSize(PLOG_IO_DP_DRIVE);
  173. extern ULONG GetSeqNumberBits(PLOG_IO_DP_DRIVE);
  174. #endif // LFS