Leaked source code of windows server 2003
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.

314 lines
8.9 KiB

  1. #include <stdlib.h> /* for _MAX_PATH */
  2. #include <time.h>
  3. #pragma pack(1)
  4. extern BOOL fLGIgnoreVersion;
  5. extern BOOL fBackupInProgress;
  6. extern CHAR szDrive[];
  7. extern CHAR szDir[];
  8. extern CHAR szExt[];
  9. extern CHAR szFName[];
  10. extern CHAR szLogName[];
  11. extern CHAR *szLogCurrent;
  12. extern CHAR szLogFilePath[];
  13. //extern BOOL fDoNotOverWriteLogFilePath; /* do not load log file path from log file */
  14. extern CHAR szRestorePath[];
  15. extern CHAR szRecovery[];
  16. extern CHAR szNewDestination[];
  17. extern LONG cbSec; // minimum disk Read/Write unit.
  18. extern LONG csecHeader;
  19. #define cbMaxLogFileName (8 + 1 + 3 + 1) /* null at the end */
  20. #define PbSecAligned(pb) ((((pb)-pbLGBufMin) / cbSec) * cbSec + pbLGBufMin)
  21. //------ types ----------------------------------------------------------
  22. #define FSameTime( ptm1, ptm2 ) (memcmp((ptm1), (ptm2), sizeof(LOGTIME)) == 0)
  23. VOID LGGetDateTime( LOGTIME *plogtm );
  24. // UNDONE: allow larger attach sizes to support greater number of
  25. // attached databases.
  26. #define cbLogFileHeader 4096 // big enough to hold cbAttach
  27. #define cbCheckpoint 4096 // big enough to hold cbAttach
  28. #define cbAttach 2048
  29. #define cbLGMSOverhead ( sizeof( LRMS ) + sizeof( LRTYP ) )
  30. /* log file header
  31. /**/
  32. typedef struct
  33. {
  34. ULONG ulChecksum; // must be the first 4 bytes
  35. LONG lGeneration; // current log generation.
  36. /* log consistency check
  37. /**/
  38. LOGTIME tmCreate; // date time log file creation
  39. LOGTIME tmPrevGen; // date time prev log file creation
  40. ULONG ulMajor; // major version number
  41. ULONG ulMinor; // minor version number
  42. ULONG ulUpdate; // update version number
  43. LONG cbSec;
  44. LONG csecLGFile; // log file size.
  45. SIGNATURE signLog; // log gene
  46. /* run-time evironment
  47. /**/
  48. DBMS_PARAM dbms_param;
  49. } LGFILEHDR_FIXED;
  50. typedef struct
  51. {
  52. LGFILEHDR_FIXED;
  53. /* run-time environment
  54. /**/
  55. BYTE rgbAttach[cbAttach];
  56. /* padding to cbSec
  57. /**/
  58. BYTE rgb[cbLogFileHeader - sizeof(LGFILEHDR_FIXED) - cbAttach];
  59. } LGFILEHDR;
  60. typedef struct
  61. {
  62. ULONG ulChecksum;
  63. LGPOS lgposLastFullBackupCheckpoint; // checkpoint of last full backup
  64. LGPOS lgposCheckpoint;
  65. SIGNATURE signLog; // log gene
  66. DBMS_PARAM dbms_param;
  67. /* debug fields
  68. /**/
  69. LGPOS lgposFullBackup;
  70. LOGTIME logtimeFullBackup;
  71. LGPOS lgposIncBackup;
  72. LOGTIME logtimeIncBackup;
  73. } CHECKPOINT_FIXED;
  74. typedef struct
  75. {
  76. CHECKPOINT_FIXED;
  77. /* run-time environment
  78. /**/
  79. BYTE rgbAttach[cbAttach];
  80. /* padding to cbSec
  81. /**/
  82. BYTE rgb[cbCheckpoint - sizeof(CHECKPOINT_FIXED) - cbAttach];
  83. } CHECKPOINT;
  84. typedef struct tagLGSTATUSINFO
  85. {
  86. ULONG cSectorsSoFar; // Sectors already processed in current gen.
  87. ULONG cSectorsExpected; // Sectors expected in current generation.
  88. ULONG cGensSoFar; // Generations already processed.
  89. ULONG cGensExpected; // Generations expected.
  90. BOOL fCountingSectors; // Are we counting bytes as well as generations?
  91. JET_PFNSTATUS pfnStatus; // Status callback function.
  92. JET_SNPROG snprog; // Progress notification structure.
  93. } LGSTATUSINFO;
  94. typedef struct _rstmap
  95. {
  96. CHAR *szDatabaseName;
  97. CHAR *szNewDatabaseName;
  98. CHAR *szGenericName;
  99. CHAR *szPatchPath;
  100. BOOL fPatched;
  101. BOOL fDestDBReady; /* non-ext-restore, dest db copied? */
  102. } RSTMAP;
  103. #pragma pack()
  104. //------ variables ----------------------------------------------------------
  105. /****** globals declared in log.c, shared by logapi.c redo.c *******/
  106. /*** checkpoint file infor ***/
  107. extern CHECKPOINT *pcheckpointGlobal;
  108. /*** log file infor ***/
  109. extern HANDLE hfLog; /* logfile handle */
  110. extern INT csecLGFile;
  111. extern LGFILEHDR *plgfilehdrGlobal; /* cached current log file header */
  112. extern LGFILEHDR *plgfilehdrGlobalT; /* read cached of log file header */
  113. /*** in memory log buffer ***/
  114. extern INT csecLGBuf; /* available buffer, exclude the shadow sec */
  115. extern CHAR *pbLGBufMin;
  116. extern CHAR *pbLGBufMax;
  117. extern BYTE *pbLGFileEnd;
  118. extern LONG isecLGFileEnd;
  119. extern CHAR *pbLastMSFlush; /* to LGBuf where last multi-sec flush LogRec sit*/
  120. extern LGPOS lgposLastMSFlush;
  121. extern BYTE *pbEntry;
  122. extern BYTE *pbWrite;
  123. extern INT isecWrite; /* next disk to write. */
  124. extern BYTE *pbNext;
  125. extern BYTE *pbRead;
  126. extern INT isecRead; /* next disk to Read. */
  127. extern LGPOS lgposLastRec; /* setinal for last log record for redo */
  128. /*** log record position ***/
  129. extern LGPOS lgposLogRec; /* last log record entry, updated by ErrLGLogRec */
  130. extern LGPOS lgposToFlush; /* next point starting the flush. Right after */
  131. /* lgposLogRec. */
  132. extern LGPOS lgposRedo; /* redo log record entry */
  133. extern LGPOS lgposFullBackup;
  134. extern LOGTIME logtimeFullBackup;
  135. extern LGPOS lgposIncBackup;
  136. extern LOGTIME logtimeIncBackup;
  137. extern RSTMAP *rgrstmapGlobal;
  138. extern INT irstmapGlobalMac;
  139. extern LGPOS lgposStart; /* last log start position */
  140. // logging MUTEX
  141. extern CRIT critLGFlush;
  142. extern CRIT critLGBuf;
  143. extern CRIT critCheckpoint;
  144. extern CRIT critLGWaitQ;
  145. extern SIG sigLogFlush;
  146. // logging EVENT
  147. extern SIG sigLGFlush;
  148. //------ log.c --------------------------------------------------------------
  149. ERR ErrLGOpenJetLog( VOID );
  150. ERR ErrLGWrite( int isecOffset, BYTE *pbData, int csecData );
  151. ERR ErrLGRead( HANDLE hfLog, int ibOffset, BYTE *pbData, int csec );
  152. #define fCheckLogID fTrue
  153. #define fNoCheckLogID fFalse
  154. ERR ErrLGReadFileHdr( HANDLE hfLog, LGFILEHDR *plgfilehdr, BOOL fNeedToCheckLogID );
  155. VOID LGSzFromLogId( CHAR *rgbLogFileName, LONG lgen );
  156. #define fLGOldLogExists (1<<0)
  157. #define fLGOldLogNotExists (1<<1)
  158. #define fLGOldLogInBackup (1<<2)
  159. #define fLGReserveLogs (1<<3)
  160. ERR ErrLGNewLogFile( LONG lgen, BOOL fLGFlags );
  161. ULONG LGFlushLog( VOID );
  162. #ifdef PERFCNT
  163. ERR ErrLGFlushLog( int tidCaller );
  164. #else
  165. ERR ErrLGFlushLog( );
  166. #endif
  167. STATIC INLINE QWORD CbOffsetLgpos( LGPOS lgpos1, LGPOS lgpos2 )
  168. {
  169. // take difference of byte offsets, then
  170. // log sectors, and finally generations
  171. return (QWORD) ( lgpos1.ib - lgpos2.ib )
  172. + cbSec * (QWORD) ( lgpos1.isec - lgpos2.isec )
  173. + csecLGFile * cbSec * (QWORD) ( lgpos1.lGeneration - lgpos2.lGeneration );
  174. }
  175. //------ redo.c -------------------------------------------------------------
  176. /* corresponding pointer to process information block
  177. /**/
  178. typedef struct
  179. {
  180. PROCID procid;
  181. PIB *ppib;
  182. FUCB *rgpfucbOpen[dbidMax];
  183. } CPPIB;
  184. extern CPPIB *rgcppib; /* array of pibs-procids during Redo */
  185. /* Patch in-memory structure.
  186. */
  187. #define cppatchlstHash 577
  188. #define IppatchlstHash( pn ) ( (pn) % cppatchlstHash )
  189. typedef struct _patch {
  190. DBID dbid;
  191. QWORD qwDBTime;
  192. INT ipage;
  193. struct _patch *ppatch;
  194. } PATCH;
  195. typedef struct _patchlst {
  196. PN pn;
  197. PATCH *ppatch;
  198. struct _patchlst *ppatchlst;
  199. } PATCHLST;
  200. PATCH *PpatchLGSearch( QWORD qwDBTimeRedo, PN pn );
  201. ERR ErrLGPatchPage( PIB *ppib, PN pn, PATCH *ppatch );
  202. ERR ErrLGPatchDatabase( DBID dbid, INT irstmap );
  203. //------ debug code --------------------------------------------------------
  204. #ifdef DEBUG
  205. #define FlagUsed( pb, cb ) memset( pb, 'x', cb )
  206. #else /* !DEBUG */
  207. #define FlagUsed( pb, cb )
  208. #endif /* !DEBUG */
  209. //------ function headers ---------------------------------------------------
  210. VOID LGFirstGeneration( CHAR *szSearchPath, LONG *plgen );
  211. ERR ErrLGRedoable( PIB *ppib, PN pn, QWORD qwDBTime, BF **ppbf, BOOL *pfRedoable );
  212. INT IrstmapLGGetRstMapEntry( CHAR *szName );
  213. ERR ErrLGGetDestDatabaseName( CHAR *szDatabaseName, INT *pirstmap, LGSTATUSINFO *plgstat );
  214. ERR ErrLGRedo( CHECKPOINT *pcheckpoint, LGSTATUSINFO *plgstat );
  215. ERR ErrLGRedoOperations( LGPOS *plgposRedoFrom, LGSTATUSINFO *plgstat );
  216. INT CbLGSizeOfRec( LR * );
  217. ERR ErrLGCheckReadLastLogRecord( BOOL *pfCloseNormally );
  218. ERR ErrLGLocateFirstRedoLogRec( LGPOS *plgposRedo, BYTE **ppbLR );
  219. ERR ErrLGGetNextRec( BYTE ** );
  220. VOID LGLastGeneration( CHAR *szSearchPath, LONG *plgen );
  221. VOID AddLogRec( BYTE *pb, INT cb, BYTE **ppbET);
  222. VOID GetLgpos( BYTE *pb, LGPOS *plgpos );
  223. #define GetLgposOfPbEntry( plgpos ) GetLgpos( pbEntry, plgpos )
  224. VOID GetLgposOfPbNext(LGPOS *plgpos);
  225. VOID LGFullNameCheckpoint( CHAR *szFullName );
  226. ERR ErrLGIReadCheckpoint( CHAR *szCheckpointFile, CHECKPOINT *pcheckpoint );
  227. ERR ErrLGIWriteCheckpoint( CHAR *szCheckpointFile, CHECKPOINT *pcheckpoint );
  228. VOID LGUpdateCheckpointFile( BOOL fUpdatedAttachment );
  229. VOID LGLoadAttachmentsFromFMP( BYTE *pbBuf, INT cb );
  230. ERR ErrLGLoadFMPFromAttachments( BYTE *pbAttach );
  231. #define fNoProperLogFile 1
  232. #define fRedoLogFile 2
  233. #define fNormalClose 3
  234. ERR ErrLGOpenRedoLogFile( LGPOS *plgposRedoFrom, int *pfStatus );
  235. ERR ErrLGWriteFileHdr(LGFILEHDR *plgfilehdr);
  236. ULONG UlLGHdrChecksum( LGFILEHDR *plgfilehdr );
  237. #ifdef DEBUG
  238. BOOL FLGDebugLogRec( LR *plr );
  239. VOID ShowData( BYTE *pbData, INT cbData );
  240. VOID PrintLgposReadLR(VOID);
  241. VOID ShowLR( LR *plr );
  242. #else
  243. #define ShowLR( plr ) 0
  244. #endif /* !DEBUG */
  245.