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.

467 lines
11 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 structure must be allocated at the start of the structure being
  65. // protected.
  66. //
  67. #if !defined( _AUTOCHECK_ )
  68. typedef struct _MULTI_SECTOR_HEADER {
  69. //
  70. // Space for a four-character signature
  71. //
  72. UCHAR Signature[4];
  73. //
  74. // Offset to Update Sequence Array, from start of structure. The Update
  75. // Sequence Array must end before the last USHORT in the first "sector"
  76. // of size SEQUENCE_NUMBER_STRIDE. (I.e., with the current constants,
  77. // the sum of the next two fields must be <= 510.)
  78. //
  79. USHORT UpdateSequenceArrayOffset;
  80. //
  81. // Size of Update Sequence Array (from above formula)
  82. //
  83. USHORT UpdateSequenceArraySize;
  84. } MULTI_SECTOR_HEADER, *PMULTI_SECTOR_HEADER;
  85. #endif
  86. //
  87. // This array must be present at the offset described above.
  88. //
  89. typedef UPDATE_SEQUENCE_NUMBER UPDATE_SEQUENCE_ARRAY[1];
  90. typedef UPDATE_SEQUENCE_ARRAY *PUPDATE_SEQUENCE_ARRAY;
  91. //
  92. // The following structure is allocated in the file system's Vcb and
  93. // its address is passed to Lfs during log file initialization. It
  94. // contains the offset of the current write as well as the system
  95. // page size being used by Lfs.
  96. //
  97. typedef struct _LFS_WRITE_DATA {
  98. LONGLONG FileOffset;
  99. ULONG Length;
  100. ULONG LfsStructureSize;
  101. PVOID Lfcb;
  102. } LFS_WRITE_DATA, *PLFS_WRITE_DATA;
  103. //
  104. // The following structure is used to identify a log record by a log
  105. // sequence number.
  106. //
  107. typedef LARGE_INTEGER LSN, *PLSN;
  108. //
  109. // The following Lsn will never occur in a file, it is used to indicate
  110. // a non-lsn.
  111. //
  112. extern LSN LfsZeroLsn;
  113. //
  114. // We set the default page size to 4K
  115. //
  116. #define LFS_DEFAULT_LOG_PAGE_SIZE (0x1000)
  117. //
  118. // The following type defines the different log record types.
  119. //
  120. typedef enum _LFS_RECORD_TYPE {
  121. LfsClientRecord = 1,
  122. LfsClientRestart
  123. } LFS_RECORD_TYPE, *PLFS_RECORD_TYPE;
  124. //
  125. // The following search modes are supported.
  126. //
  127. typedef enum _LFS_CONTEXT_MODE {
  128. LfsContextUndoNext = 1,
  129. LfsContextPrevious,
  130. LfsContextForward
  131. } LFS_CONTEXT_MODE, *PLFS_CONTEXT_MODE;
  132. typedef ULONG TRANSACTION_ID, *PTRANSACTION_ID;
  133. typedef enum _TRANSACTION_STATE {
  134. TransactionUninitialized = 0,
  135. TransactionActive,
  136. TransactionPrepared,
  137. TransactionCommitted
  138. } TRANSACTION_STATE, *PTRANSACTION_STATE;
  139. //
  140. // Information conduit back and forth between
  141. // LFS and its client.
  142. //
  143. typedef enum _LFS_CLIENT_INFO {
  144. LfsUseUsa = 1,
  145. LfsPackLog,
  146. LfsFixedPageSize
  147. } LFS_CLIENT_INFO;
  148. typedef struct _LFS_INFO {
  149. LOGICAL ReadOnly;
  150. LOGICAL InRestart;
  151. LOGICAL BadRestart;
  152. LFS_CLIENT_INFO LfsClientInfo;
  153. } LFS_INFO, *PLFS_INFO;
  154. typedef PVOID LFS_LOG_HANDLE, *PLFS_LOG_HANDLE;
  155. typedef PVOID LFS_LOG_CONTEXT, *PLFS_LOG_CONTEXT;
  156. //
  157. // Write Entry for LfsWrite and LfsForceWrite. The interface to these
  158. // routines takes a pointer to a Write Entry along with a count of how
  159. // many Write Entries to expect to describe pieces of the caller's buffer
  160. // which are supposed to be copied in sequence to the log file.
  161. //
  162. typedef struct _LFS_WRITE_ENTRY {
  163. PVOID Buffer;
  164. ULONG ByteLength;
  165. } LFS_WRITE_ENTRY, *PLFS_WRITE_ENTRY;
  166. //
  167. // Global Maintenance routines
  168. //
  169. BOOLEAN
  170. LfsInitializeLogFileService (
  171. VOID
  172. );
  173. //
  174. // Log File Registration routines
  175. //
  176. typedef struct _LOG_FILE_INFORMATION {
  177. //
  178. // This is the total useable space in the log file after space for
  179. // headers and Lfs Restart Areas.
  180. //
  181. LONGLONG TotalAvailable;
  182. //
  183. // This is the useable space in the log file from the current position
  184. // in the log file to the lowest BaseLsn. This total as returned is not
  185. // yet reduced for undo commitments, returned separately below.
  186. //
  187. LONGLONG CurrentAvailable;
  188. //
  189. // This is the total undo commitment for all clients of the log file.
  190. // LfsWrite requests are refused when the sum of the write size of the
  191. // request plus the UndoRequirement for the request plus the TotalUndoCommitment
  192. // are greater than the CurrentAvailable.
  193. //
  194. LONGLONG TotalUndoCommitment;
  195. //
  196. // This is the total undo commitment for this client.
  197. //
  198. LONGLONG ClientUndoCommitment;
  199. //
  200. // Current system Lsn's. Includes the Oldest, LastFlushed and current
  201. // Lsn.
  202. //
  203. LSN OldestLsn;
  204. LSN LastFlushedLsn;
  205. LSN LastLsn;
  206. } LOG_FILE_INFORMATION, *PLOG_FILE_INFORMATION;
  207. VOID
  208. LfsInitializeLogFile (
  209. IN PFILE_OBJECT LogFile,
  210. IN USHORT MaximumClients,
  211. IN ULONG LogPageSize OPTIONAL,
  212. IN LONGLONG FileSize,
  213. OUT PLFS_WRITE_DATA WriteData
  214. );
  215. ULONG
  216. LfsOpenLogFile (
  217. IN PFILE_OBJECT LogFile,
  218. IN UNICODE_STRING ClientName,
  219. IN USHORT MaximumClients,
  220. IN ULONG LogPageSize OPTIONAL,
  221. IN LONGLONG FileSize,
  222. IN OUT PLFS_INFO LfsInfo,
  223. OUT PLFS_LOG_HANDLE LogHandle,
  224. OUT PLFS_WRITE_DATA WriteData
  225. );
  226. VOID
  227. LfsCloseLogFile (
  228. IN LFS_LOG_HANDLE LogHandle
  229. );
  230. VOID
  231. LfsDeleteLogHandle (
  232. IN LFS_LOG_HANDLE LogHandle
  233. );
  234. VOID
  235. LfsReadLogFileInformation (
  236. IN LFS_LOG_HANDLE LogHandle,
  237. IN PLOG_FILE_INFORMATION Buffer,
  238. IN OUT PULONG Length
  239. );
  240. BOOLEAN
  241. LfsVerifyLogFile (
  242. IN LFS_LOG_HANDLE LogHandle,
  243. IN PVOID LogFileHeader,
  244. IN ULONG Length
  245. );
  246. //
  247. // Log File Client Restart routines
  248. //
  249. NTSTATUS
  250. LfsReadRestartArea (
  251. IN LFS_LOG_HANDLE LogHandle,
  252. IN OUT PULONG BufferLength,
  253. IN PVOID Buffer,
  254. OUT PLSN Lsn
  255. );
  256. VOID
  257. LfsWriteRestartArea (
  258. IN LFS_LOG_HANDLE LogHandle,
  259. IN ULONG BufferLength,
  260. IN PVOID Buffer,
  261. IN LOGICAL CleanShutdown,
  262. OUT PLSN Lsn
  263. );
  264. VOID
  265. LfsSetBaseLsn (
  266. IN LFS_LOG_HANDLE LogHandle,
  267. IN LSN BaseLsn
  268. );
  269. //
  270. // If ResetTotal is positive, then NumberRecords and ResetTotal set the absolute
  271. // values for the client. If ResetTotal is negative, then they are adjustments
  272. // to the totals for this client.
  273. //
  274. VOID
  275. LfsResetUndoTotal (
  276. IN LFS_LOG_HANDLE LogHandle,
  277. IN ULONG NumberRecords,
  278. IN LONG ResetTotal
  279. );
  280. //
  281. // Log File Write routines
  282. //
  283. VOID
  284. LfsGetActiveLsnRange (
  285. IN LFS_LOG_HANDLE LogHandle,
  286. OUT PLSN OldestLsn,
  287. OUT PLSN NextLsn
  288. );
  289. BOOLEAN
  290. LfsWrite (
  291. IN LFS_LOG_HANDLE LogHandle,
  292. IN ULONG NumberOfWriteEntries,
  293. IN PLFS_WRITE_ENTRY WriteEntries,
  294. IN LFS_RECORD_TYPE RecordType,
  295. IN TRANSACTION_ID *TransactionId OPTIONAL,
  296. IN LSN UndoNextLsn,
  297. IN LSN PreviousLsn,
  298. IN LONG UndoRequirement,
  299. IN ULONG Flags,
  300. OUT PLSN Lsn
  301. );
  302. #define LFS_WRITE_FLAG_WRITE_AT_FRONT 1
  303. BOOLEAN
  304. LfsForceWrite (
  305. IN LFS_LOG_HANDLE LogHandle,
  306. IN ULONG NumberOfWriteEntries,
  307. IN PLFS_WRITE_ENTRY WriteEntries,
  308. IN LFS_RECORD_TYPE RecordType,
  309. IN TRANSACTION_ID *TransactionId OPTIONAL,
  310. IN LSN UndoNextLsn,
  311. IN LSN PreviousLsn,
  312. IN LONG UndoRequirement,
  313. OUT PLSN Lsn
  314. );
  315. VOID
  316. LfsFlushToLsn (
  317. IN LFS_LOG_HANDLE LogHandle,
  318. IN LSN Lsn
  319. );
  320. VOID
  321. LfsCheckWriteRange (
  322. IN PLFS_WRITE_DATA WriteData,
  323. IN OUT PLONGLONG FlushOffset,
  324. IN OUT PULONG FlushLength
  325. );
  326. //
  327. // Log File Query Record routines
  328. //
  329. VOID
  330. LfsReadLogRecord (
  331. IN LFS_LOG_HANDLE LogHandle,
  332. IN LSN FirstLsn,
  333. IN LFS_CONTEXT_MODE ContextMode,
  334. OUT PLFS_LOG_CONTEXT Context,
  335. OUT PLFS_RECORD_TYPE RecordType,
  336. OUT TRANSACTION_ID *TransactionId,
  337. OUT PLSN UndoNextLsn,
  338. OUT PLSN PreviousLsn,
  339. OUT PULONG BufferLength,
  340. OUT PVOID *Buffer
  341. );
  342. BOOLEAN
  343. LfsReadNextLogRecord (
  344. IN LFS_LOG_HANDLE LogHandle,
  345. IN OUT LFS_LOG_CONTEXT Context,
  346. OUT PLFS_RECORD_TYPE RecordType,
  347. OUT TRANSACTION_ID *TransactionId,
  348. OUT PLSN UndoNextLsn,
  349. OUT PLSN PreviousLsn,
  350. OUT PLSN Lsn,
  351. OUT PULONG BufferLength,
  352. OUT PVOID *Buffer
  353. );
  354. VOID
  355. LfsTerminateLogQuery (
  356. IN LFS_LOG_HANDLE LogHandle,
  357. IN LFS_LOG_CONTEXT Context
  358. );
  359. LSN
  360. LfsQueryLastLsn (
  361. IN LFS_LOG_HANDLE LogHandle
  362. );
  363. #endif // LFS