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.

220 lines
6.1 KiB

  1. #include <stdlib.h> /* for _MAX_PATH */
  2. #include <time.h>
  3. #pragma pack(1)
  4. //#define OVERLAPPED_LOGGING /* which Logging to use? */
  5. #define CHECK_LG_VERSION
  6. extern BOOL fLGIgnoreVersion;
  7. extern CHAR szDrive[];
  8. extern CHAR szDir[];
  9. extern CHAR szExt[];
  10. extern CHAR szFName[];
  11. extern CHAR szLogName[];
  12. extern CHAR *szLogCurrent;
  13. extern CHAR szLogFilePath[];
  14. extern CHAR szRestorePath[];
  15. extern CHAR szRecovery[];
  16. extern OLP rgolpLog[];
  17. extern SIG rgsig[];
  18. extern CODECONST(char) szJet[];
  19. extern CODECONST(char) szJetTmp[];
  20. extern CODECONST(char) szLogExt[];
  21. #define cbMaxLogFileName (8 + 1 + 3 + 1) /* null at the end */
  22. #define PbSecAligned(pb) ((((pb)-pbLGBufMin) / cbSec) * cbSec + pbLGBufMin)
  23. //------ types ----------------------------------------------------------
  24. #define MAX_COMPUTERNAME_LENGTH 15
  25. typedef struct
  26. {
  27. BYTE bSeconds; // 0 - 60
  28. BYTE bMinutes; // 0 - 60
  29. BYTE bHours; // 0 - 24
  30. BYTE bDay; // 1 - 31
  31. BYTE bMonth; // 0 - 11
  32. BYTE bYear; // Current year - 1900
  33. } LOGTIME;
  34. #define FSameTime( ptm1, ptm2 ) (memcmp((ptm1), (ptm2), sizeof(LOGTIME)) == 0)
  35. VOID LGGetDateTime( LOGTIME *plogtm );
  36. /* log file header */
  37. typedef struct
  38. {
  39. ULONG ulChecksum; // Must be the first 4 bytes
  40. LGPOS lgposFirst; // 1st log record starts.
  41. LGPOS lgposLastMS; // last recorded multi-sec flush LogRec
  42. LGPOS lgposFirstMS; // 1st recorded multi-sec flush LogRec
  43. LGPOS lgposCheckpoint; // check point
  44. BOOL fEndWithMS; // normal end of a generation.
  45. LOGTIME tmCreate; // date time log file creation
  46. LOGTIME tmPrevGen; // date time prev log file creation
  47. ULONG ulRup; // typically 2000
  48. ULONG ulVersion; // of format: 125.1
  49. BYTE szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  50. DBENV dbenv;
  51. LGPOS lgposFullBackup;
  52. LOGTIME logtimeFullBackup;
  53. LGPOS lgposIncBackup;
  54. LOGTIME logtimeIncBackup;
  55. } FHDRUSED;
  56. typedef struct
  57. {
  58. FHDRUSED;
  59. BYTE rgb[ cbSec - sizeof( FHDRUSED ) ];
  60. } LGFILEHDR;
  61. //------ variables ----------------------------------------------------------
  62. /****** globals declared in log.c, shared by logapi.c redo.c *******/
  63. /*** log file infor ***/
  64. extern HANDLE hfLog; /* logfile handle */
  65. extern INT csecLGFile;
  66. extern LGFILEHDR *plgfilehdrGlobal; /* cached current log file header */
  67. /*** in memory log buffer ***/
  68. extern INT csecLGBuf; /* available buffer, exclude the shadow sec */
  69. extern CHAR *pbLGBufMin;
  70. extern CHAR *pbLGBufMax;
  71. extern CHAR *pbLastMSFlush; /* to LGBuf where last multi-sec flush LogRec sit*/
  72. extern LGPOS lgposLastMSFlush;
  73. extern BYTE *pbEntry;
  74. extern BYTE *pbWrite;
  75. extern INT isecWrite; /* next disk to write. */
  76. extern BYTE *pbNext;
  77. extern BYTE *pbRead;
  78. extern INT isecRead; /* next disk to Read. */
  79. extern LGPOS lgposLastRec; /* setinal for last log record for redo */
  80. /*** log record position ***/
  81. extern LGPOS lgposLogRec; /* last log record entry, updated by ErrLGLogRec */
  82. extern LGPOS lgposToFlush; /* next point starting the flush. Right after */
  83. /* lgposLogRec. */
  84. extern LGPOS lgposFullBackup;
  85. extern LOGTIME logtimeFullBackup;
  86. extern LGPOS lgposIncBackup;
  87. extern LOGTIME logtimeIncBackup;
  88. extern LGPOS lgposStart; /* last log start position */
  89. // logging MUTEX
  90. extern CRIT __near critLGFlush;
  91. extern CRIT __near critLGBuf;
  92. extern CRIT __near critLGWaitQ;
  93. extern SIG __near sigLogFlush;
  94. // logging EVENT
  95. extern SIG __near sigLGFlush;
  96. //------ log.c --------------------------------------------------------------
  97. ERR ErrLGWrite( int isecOffset, BYTE *pbData, int csecData );
  98. ERR ErrLGRead( HANDLE hfLog, int ibOffset, BYTE *pbData, int csec );
  99. ERR ErrLGReadFileHdr( HANDLE hfLog, LGFILEHDR *plgfilehdr );
  100. VOID LGSzFromLogId( CHAR *rgbLogFileName, int usGeneration );
  101. extern BOOL fJetLogGeneratedDuringSoftStart;
  102. #define fOldLogExists 1
  103. #define fOldLogNotExists 2
  104. #define fOldLogInBackup 4
  105. ERR ErrLGNewLogFile( int usGeneration, BOOL fOldLog );
  106. VOID LGFlushLog( VOID );
  107. #ifdef PERFCNT
  108. ERR ErrLGFlushLog( int tidCaller );
  109. #else
  110. ERR ErrLGFlushLog( VOID );
  111. #endif
  112. //------ redo.c -------------------------------------------------------------
  113. /* corresponding pointer to process information block
  114. /**/
  115. typedef struct
  116. {
  117. PROCID procid;
  118. PIB *ppib;
  119. FUCB *rgpfucbOpen[dbidUserMax];
  120. } CPPIB;
  121. extern CPPIB *rgcppib; /* array of pibs-procids during Redo */
  122. //------ macros -----------------------------------------------------
  123. /* redo operations are valid on the system database on the first
  124. /* pass. Redo operations are valid on any database for which the
  125. /* flag is 0 or greater. This is to handle the case where
  126. /* 1) plain log records are found ( 0 )
  127. /* 2) create for the first time ( 1 )
  128. /* 3) detach and attach/create ( 0 )
  129. /**/
  130. #define FValidDatabase( dbid ) \
  131. ( dbid == dbidSystemDatabase || rgfDatabase[dbid] > 0 || fHardRestore )
  132. //------ debug code --------------------------------------------------------
  133. #ifdef DEBUG
  134. #define FlagUsed( pb, cb ) memset( pb, 'x', cb )
  135. #else /* !DEBUG */
  136. #define FlagUsed( pb, cb )
  137. #endif /* !DEBUG */
  138. //------ function headers ---------------------------------------------------
  139. ERR ErrLGRedoable( PIB *ppib, PN pn, ULONG ulDBTime, BF **ppbf, BOOL *pfRedoable );
  140. ERR ErrLGRedo1( LGPOS *plgposRedoFrom );
  141. ERR ErrLGRedo2( LGPOS *plgposRedoFrom );
  142. ERR ErrLGRedoOperations( LGPOS *plgposRedoFrom, BOOL fSysDb );
  143. INT CbLGSizeOfRec( LR * );
  144. ERR ErrLGCheckReadLastLogRecord( LGPOS *plgposLastMS, BOOL *pfCloseNormally );
  145. ERR ErrLGLocateFirstRedoLogRec( LGPOS *plgposLastMS, LGPOS *plgposFirst, BYTE **ppbLR );
  146. ERR ErrLGGetNextRec( BYTE ** );
  147. VOID LGLastGeneration( char *szSearchPath, int *piGeneration );
  148. VOID AddLogRec( BYTE *pb, INT cb, BYTE **ppbET);
  149. VOID LGUpdateCheckpoint( VOID );
  150. VOID GetLgposOfPbEntry( LGPOS *plgpos );
  151. VOID GetLgposOfPbNext(LGPOS *plgpos);
  152. #define fNoProperLogFile 1
  153. #define fRedoLogFile 2
  154. #define fNormalClose 3
  155. ERR ErrOpenRedoLogFile( LGPOS *plgposRedoFrom, int *pfStatus );
  156. ERR ErrLGWriteFileHdr(LGFILEHDR *plgfilehdr);
  157. ERR ErrLGMiniOpenSystemDB();
  158. ULONG UlLGHdrChecksum( LGFILEHDR *plgfilehdr );
  159. #ifdef DEBUG
  160. VOID ShowData( BYTE *pbData, WORD cbData );
  161. VOID PrintLgposReadLR(VOID);
  162. VOID ShowLR( LR *plr );
  163. #else
  164. #define ShowLR( plr ) 0
  165. #endif /* !DEBUG */
  166. #pragma pack()