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.

364 lines
8.7 KiB

  1. #ifndef _LMP_H
  2. #define _LMP_H
  3. /*++
  4. Copyright (c) 1992-1997 Microsoft Corporation
  5. Module Name:
  6. lmp.h
  7. Abstract:
  8. Private header file for quorum logging
  9. Author:
  10. John Vert (jvert) 15-Dec-1995
  11. Revision History:
  12. --*/
  13. #include "windows.h"
  14. #include "service.h"
  15. #include "imagehlp.h"
  16. #define LOG_CURRENT_MODULE LOG_MODULE_LM
  17. //
  18. // Definitions for the behavior of the logger
  19. //
  20. #define MAXNUMPAGES_PER_RECORD 16
  21. #define GROWTH_CHUNK (MAXNUMPAGES_PER_RECORD * 2 * 1024) // size to grow file by when we need to reserve space
  22. #define SECTOR_SIZE 1024
  23. #define LOG_MANAGE_INTERVAL (2 * 60 * 1000) //1 minute..log management functions are performed
  24. //
  25. // Definitions of on-disk structures. The first sector of a log
  26. // file is a LOG_HEADER structure, followed by a sequence of LOGPAGE structures.
  27. // Each LOGPAGE is a size that is a multiple of the sector
  28. // size of the drive. Each LOGPAGE contains a series of LOG_RECORDs, which
  29. // contain the data logged by the client.
  30. //
  31. //
  32. // Define log structure
  33. //
  34. #define LOG_HEADER_SIG 'GOLC' // "CLOG"
  35. #define LOG_SIG 'GOLH' // "HLOG"
  36. #define LOGREC_SIG 'SAQS' // "random"
  37. #define XSACTION_SIG 'CASX' // "XSAC"
  38. #define CHKSUM_SIG L"SKHC" // "CHKS"
  39. //SS:size of logrecord is 48 bytes
  40. typedef struct _LOGRECORD {
  41. DWORD Signature; //we need the signature to validate the record
  42. LSN CurrentLsn;
  43. LSN PreviousLsn;
  44. DWORD RecordSize;
  45. RMID ResourceManager;
  46. TRID Transaction;
  47. TRTYPE XsactionType;
  48. DWORD Flags;
  49. FILETIME Timestamp;
  50. DWORD NumPages; // set to 1 if not a large record, else set to the number of pages required by the large record.
  51. DWORD DataSize; //date size
  52. BYTE Data[];
  53. } LOGRECORD, *PLOGRECORD;
  54. typedef struct _LOGPAGE {
  55. DWORD Offset;
  56. DWORD Size;
  57. LOGRECORD FirstRecord;
  58. } LOGPAGE, *PLOGPAGE;
  59. //
  60. // LOG_HEADER structure is the first 512 bytes of every log
  61. // file. The structure below is carefully computed to be 512
  62. // bytes long.
  63. //
  64. typedef struct _LOG_HEADER {
  65. DWORD Signature; // LOG_HEADER_SIG = "CLOG"
  66. DWORD HeaderSize;
  67. FILETIME CreateTime;
  68. LSN LastChkPtLsn; //points to the lsn of the endchkpt record of the last lsn
  69. WCHAR FileName[256-(sizeof(DWORD)*2+sizeof(LSN)+sizeof(FILETIME))];
  70. } LOG_HEADER, *PLOG_HEADER;
  71. typedef struct _LOG_CHKPTINFO{
  72. WCHAR szFileName[LOG_MAX_FILENAME_LENGTH];
  73. LSN ChkPtBeginLsn; //points to the lsn of the begin chkptrecord for this chkpt.
  74. DWORD dwCheckSum; //checksum for the checkpoint file
  75. }LOG_CHKPTINFO,*PLOG_CHKPTINFO;
  76. //
  77. // Define in-memory structure used to contain current log data
  78. // The HLOG returned to callers by LogCreate is actually a pointer
  79. // to this structure.
  80. //
  81. typedef struct _LOG {
  82. DWORD LogSig; // "HLOG"
  83. LPWSTR FileName;
  84. HANDLE FileHandle;
  85. DWORD SectorSize;
  86. PLOGPAGE ActivePage;
  87. LSN NextLsn;
  88. LSN FlushedLsn;
  89. DWORD FileSize; // physical size of file
  90. DWORD FileAlloc; // total filespace used (always <= FileSize)
  91. DWORD MaxFileSize;
  92. PLOG_GETCHECKPOINT_CALLBACK pfnGetChkPtCb;
  93. PVOID pGetChkPtContext; //this is passed back to the checkpoint callback function.
  94. OVERLAPPED Overlapped; // use for overlapped I/O
  95. CRITICAL_SECTION Lock;
  96. HANDLE hTimer; //timer for managing this lock
  97. } LOG, *PLOG;
  98. typedef struct _XSACTION{
  99. DWORD XsactionSig; //signature for this structure
  100. LSN StartLsn; //the LSN for the start xsaction record
  101. TRID TrId; //the transaction id for the LSN
  102. RMID RmId; //the id of the resource Manager
  103. } XSACTION, *PXSACTION;
  104. //
  105. // Define macros for creating and translating LSNs
  106. //
  107. //
  108. // LSN
  109. // MAKELSN(
  110. // IN PLOGPAGE Page,
  111. // IN PLOGRECORD Pointer
  112. // );
  113. //
  114. // Given a pointer to a page, and a pointer to a log record within that page, generates
  115. // the LSN.
  116. //
  117. #define MAKELSN(Page,Pointer) (LSN)((Page)->Offset + ((ULONG_PTR)Pointer - (ULONG_PTR)Page))
  118. //
  119. // DWORD
  120. // LSNTOPAGE(
  121. // IN LSN Lsn
  122. // );
  123. //
  124. // Given an LSN returns the page that contains it.
  125. //
  126. #define LSNTOPAGE(Lsn) ((Lsn) >> 10)
  127. //
  128. // GETLOG(
  129. // PLOG pLog,
  130. // HLOG hLog
  131. // );
  132. //
  133. // Translates an HLOG handle to a pointer to a LOG structure
  134. //
  135. #define GETLOG(plog, hlog) (plog) = (PLOG)(hlog); \
  136. CL_ASSERT((plog)->LogSig == LOG_SIG)
  137. // Given a pointer to a record, it fetches the LSN of the next or
  138. // previous record
  139. //
  140. #define GETNEXTLSN(pLogRecord,ScanForward) ((ScanForward) ? \
  141. (pLogRecord->CurrentLsn + pLogRecord->RecordSize) : \
  142. (pLogRecord->PreviousLsn))
  143. //
  144. // GETXSACTION(
  145. // PXSACTION pXsaction,
  146. // HXSACTION hXsaction
  147. // );
  148. //
  149. // Translates an HLOG handle to a pointer to a LOG structure
  150. //
  151. #define GETXSACTION(pXsaction, hXsaction) (pXsaction) = (PXSACTION)(hXsaction); \
  152. CL_ASSERT((pXsaction)->XsactionSig == XSACTION_SIG)
  153. // given the header of the log file, check its validity.
  154. //
  155. #define ISVALIDHEADER(Header) ((Header).Signature == LOG_HEADER_SIG)
  156. //
  157. // Private helper macros
  158. //
  159. #define CrAlloc(size) LocalAlloc(LMEM_FIXED, (size))
  160. #define CrFree(size) LocalFree((size))
  161. #define AlignAlloc(size) VirtualAlloc(NULL, (size), MEM_COMMIT, PAGE_READWRITE)
  162. #define AlignFree(ptr) VirtualFree((ptr), 0, MEM_RELEASE)
  163. //Timeractivity related stuff
  164. #define MAX_TIMER_ACTIVITIES 5
  165. #define TIMER_ACTIVITY_SHUTDOWN 1
  166. #define TIMER_ACTIVITY_CHANGE 2
  167. //state values for timer activity structure management
  168. #define ACTIVITY_STATE_READY 1 //AddTimerActivity sets it to ready
  169. #define ACTIVITY_STATE_DELETE 2 //RemoveTimerActivity sets it to delete
  170. #define ACTIVITY_STATE_PAUSED 3 //PauseTimerActivity sets it to pause
  171. typedef struct _TIMER_ACTIVITY {
  172. LIST_ENTRY ListEntry;
  173. DWORD dwState;
  174. HANDLE hWaitableTimer;
  175. LARGE_INTEGER Interval;
  176. PVOID pContext;
  177. PFN_TIMER_CALLBACK pfnTimerCb;
  178. }TIMER_ACTIVITY, *PTIMER_ACTIVITY;
  179. //
  180. // Extern variables
  181. //
  182. extern BOOL bLogExceedsMaxSzWarning;
  183. //inline functions
  184. _inline
  185. DWORD
  186. LSNOFFSETINPAGE(
  187. IN PLOGPAGE Page,
  188. IN LSN Lsn
  189. );
  190. //_inline
  191. DWORD
  192. RECORDOFFSETINPAGE(
  193. IN PLOGPAGE Page,
  194. IN PLOGRECORD LogRecord
  195. );
  196. //_inline
  197. PLOGRECORD
  198. LSNTORECORD(
  199. IN PLOGPAGE Page,
  200. IN LSN Lsn
  201. );
  202. //
  203. // Define function prototypes local to this module
  204. //
  205. PLOG
  206. LogpCreate(
  207. IN LPWSTR lpFileName,
  208. IN DWORD dwMaxFileSize,
  209. IN PLOG_GETCHECKPOINT_CALLBACK CallbackRoutine,
  210. IN PVOID pGetChkPtContext,
  211. IN BOOL bForceReset,
  212. OPTIONAL OUT LSN *LastLsn
  213. );
  214. DWORD
  215. LogpMountLog(
  216. IN PLOG Log
  217. );
  218. DWORD
  219. LogpInitLog(
  220. IN PLOG Log
  221. );
  222. DWORD
  223. LogpGrowLog(
  224. IN PLOG Log,
  225. IN DWORD GrowthSize
  226. );
  227. PLOGPAGE
  228. LogpAppendPage(
  229. IN PLOG Log,
  230. IN DWORD Size,
  231. OUT PLOGRECORD *Record,
  232. OUT BOOL *pbMaxFileSizeReached,
  233. OUT DWORD *pdwNumPages
  234. );
  235. DWORD
  236. LogpRead(IN PLOG pLog,
  237. OUT PVOID pBuf,
  238. IN DWORD dwBytesToRead,
  239. OUT PDWORD pdwBytesRead
  240. );
  241. DWORD
  242. LogpWrite(
  243. IN PLOG pLog,
  244. IN PVOID pData,
  245. IN DWORD dwBytesToWrite,
  246. IN DWORD *pdwBytesWritten);
  247. void WINAPI
  248. LogpManage(
  249. IN HANDLE hTimer,
  250. IN PVOID pContext);
  251. DWORD
  252. LogpWriteLargeRecordData(
  253. IN PLOG pLog,
  254. IN PLOGRECORD pLogRecord,
  255. IN PVOID pLogData,
  256. IN DWORD dwDataSize);
  257. DWORD LogpCheckFileHeader(
  258. IN PLOG pLog,
  259. OUT LPDWORD pdwHeaderSize,
  260. OUT FILETIME *HeaderCreateTime,
  261. OUT LSN *pChkPtLsn
  262. );
  263. DWORD LogpValidateChkPoint(
  264. IN PLOG pLog,
  265. IN LSN ChkPtLsn,
  266. IN LSN LastChkPtLsn
  267. );
  268. DWORD LogpValidateLargeRecord(
  269. IN PLOG pLog,
  270. IN PLOGRECORD pRecord,
  271. OUT LSN *pNextLsn
  272. ) ;
  273. DWORD LogpInvalidatePrevRecord(
  274. IN PLOG pLog,
  275. IN PLOGRECORD pRecord
  276. );
  277. DWORD LogpEnsureSize(
  278. IN PLOG pLog,
  279. IN DWORD dwTotalSize,
  280. IN BOOL bForce
  281. );
  282. DWORD LogpReset(
  283. IN PLOG Log,
  284. IN LPCWSTR lpszInChkPtFile
  285. );
  286. VOID
  287. LogpWriteWarningToEvtLog(
  288. IN DWORD dwWarningType,
  289. IN LPCWSTR lpszLogFileName
  290. );
  291. //timer activity functions
  292. DWORD
  293. TimerActInitialize(VOID);
  294. DWORD
  295. TimerActShutdown(VOID);
  296. #endif //_LMP_H