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.

915 lines
26 KiB

  1. #include <stdlib.h> /* for _MAX_PATH */
  2. typedef enum
  3. {
  4. lsNormal,
  5. lsQuiesce,
  6. lsOutOfDiskSpace
  7. } LS;
  8. //------------------------ system parameters ---------------------------
  9. extern long lMaxSessions;
  10. extern long lMaxOpenTables;
  11. extern long lMaxVerPages;
  12. extern long lMaxCursors;
  13. extern long lMaxBuffers;
  14. extern long lLogBuffers;
  15. extern long lLogFileSize;
  16. extern long lLogFlushThreshold;
  17. extern long lLGCheckPointPeriod;
  18. extern long lWaitLogFlush;
  19. extern long lCommitDefault;
  20. extern long lLogFlushPeriod;
  21. extern long lLGWaitingUserMax;
  22. extern BOOL fLGGlobalCircularLog;
  23. //------ log.c --------------------------------------------------------------
  24. /* flags controlling logging behavior
  25. /**/
  26. extern BOOL fLogDisabled; /* to turn off logging by environment variable */
  27. extern BOOL fFreezeCheckpoint; /* freeze checkpoint when backup occurs. */
  28. extern BOOL fNewLogGeneration;
  29. extern BOOL fNewLogRecordAdded;
  30. extern BOOL fBackupActive;
  31. extern BOOL fLGNoMoreLogWrite;
  32. extern LS lsGlobal;
  33. extern PIB *ppibLGFlushQHead;
  34. extern PIB *ppibLGFlushQTail;
  35. extern INT csecLGThreshold;
  36. extern INT csecLGCheckpointCount;
  37. extern INT csecLGCheckpointPeriod;
  38. extern INT cmsLGFlushPeriod;
  39. extern INT cmsLGFlushStep;
  40. /* flags controlling recovery behavior
  41. /**/
  42. extern BOOL fGlobalExternalRestore;
  43. extern BOOL fHardRestore;
  44. extern ERR errGlobalRedoError;
  45. extern LGPOS lgposRedoShutDownMarkGlobal;
  46. #ifdef DEBUG
  47. extern DWORD dwBMThreadId;
  48. extern DWORD dwLogThreadId;
  49. extern BOOL fDBGTraceLog;
  50. extern BOOL fDBGTraceLogWrite;
  51. extern BOOL fDBGFreezeCheckpoint;
  52. extern BOOL fDBGTraceRedo;
  53. extern BOOL fDBGTraceBR;
  54. #endif
  55. extern LONG cXactPerFlush;
  56. #ifdef PERFCNT
  57. extern BOOL fPERFEnabled;
  58. extern ULONG rgcCommitByUser[10];
  59. extern ULONG rgcCommitByLG[10];
  60. #endif
  61. #pragma pack(1)
  62. typedef struct
  63. {
  64. BYTE szSystemPath[_MAX_PATH + 1];
  65. BYTE szLogFilePath[_MAX_PATH + 1];
  66. ULONG ulMaxSessions;
  67. ULONG ulMaxOpenTables;
  68. ULONG ulMaxVerPages;
  69. ULONG ulMaxCursors;
  70. ULONG ulLogBuffers;
  71. ULONG ulcsecLGFile;
  72. ULONG ulMaxBuffers; /* not used, for ref only */
  73. } DBMS_PARAM;
  74. VOID LGSetDBMSParam( DBMS_PARAM *pdbms_param );
  75. VOID LGRestoreDBMSParam( DBMS_PARAM *pdbms_param );
  76. VOID LGReportEvent( DWORD IDEvent, ERR err );
  77. typedef struct {
  78. WORD ibOffset:12; /* offset to old record. */
  79. WORD f2BytesLength:1; /* if length is 2 bytes? */
  80. WORD fInsert:1; /* insertion or replace */
  81. /* the following 2 bits are mutual exclusive.
  82. */
  83. WORD fInsertWithFill:1; /* insert with junks filled? */
  84. WORD fReplaceWithSameLength:1; /* replace with same length? */
  85. } DIFFHDR;
  86. #ifdef DEBUG
  87. VOID LGDumpDiff( BYTE *pbDiff, INT cb );
  88. #endif
  89. VOID LGSetDiffs( FUCB *pfucb, BYTE *pbDiff, INT *pcbDiff );
  90. VOID LGGetAfterImage( BYTE *pbDiff, INT cbDiff, BYTE *pbOld, INT cbOld, BYTE *pbNew, INT *pcbNew );
  91. BOOL FLGAppendDiff( BYTE **ppbCur, BYTE *pbMax, INT ibOffsetOld, INT cbDataOld, INT cbDataNew,
  92. BYTE *pbDataNew );
  93. extern SIGNATURE signLogGlobal;
  94. extern BOOL fSignLogSetGlobal;
  95. VOID SIGGetSignature( SIGNATURE *psign );
  96. /*
  97. * NOTE: Whenever a new log record type is added or changed, the following
  98. * NOTE: should be udpated too: mplrtypsz in logapi.c, new print function for
  99. * NOTE: the new lrtyp in logapi.c, and mplrtypcb and CbLGSizeOfRec in
  100. * NOTE: redut.c.
  101. */
  102. typedef BYTE LRTYP;
  103. #define lrtypNOP ((LRTYP) 0 ) /* NOP null operation */
  104. #define lrtypInit ((LRTYP) 1 )
  105. #define lrtypTerm ((LRTYP) 2 )
  106. #define lrtypMS ((LRTYP) 3 ) /* mutilsec flush */
  107. #define lrtypEnd ((LRTYP) 4 ) /* end of log generation */
  108. #define lrtypBegin ((LRTYP) 5 )
  109. #define lrtypCommit ((LRTYP) 6 )
  110. #define lrtypRollback ((LRTYP) 7 )
  111. #define lrtypCreateDB ((LRTYP) 8 )
  112. #define lrtypAttachDB ((LRTYP) 9 )
  113. #define lrtypDetachDB ((LRTYP) 10 )
  114. #define lrtypInitFDP ((LRTYP) 11 )
  115. #define lrtypSplit ((LRTYP) 12 )
  116. #define lrtypEmptyPage ((LRTYP) 13 )
  117. #define lrtypMerge ((LRTYP) 14 )
  118. #define lrtypInsertNode ((LRTYP) 15 )
  119. #define lrtypInsertItemList ((LRTYP) 16 )
  120. #define lrtypFlagDelete ((LRTYP) 17 )
  121. #define lrtypReplace ((LRTYP) 18 ) /* replace with full after image */
  122. #define lrtypReplaceD ((LRTYP) 19 ) /* replace with delta'ed after image */
  123. #define lrtypLockBI ((LRTYP) 20 ) /* replace with lock */
  124. #define lrtypDeferredBI ((LRTYP) 21 ) /* deferred before image. */
  125. #define lrtypUpdateHeader ((LRTYP) 22 )
  126. #define lrtypInsertItem ((LRTYP) 23 )
  127. #define lrtypInsertItems ((LRTYP) 24 )
  128. #define lrtypFlagDeleteItem ((LRTYP) 25 )
  129. #define lrtypFlagInsertItem ((LRTYP) 26 )
  130. #define lrtypDeleteItem ((LRTYP) 27 )
  131. #define lrtypSplitItemListNode ((LRTYP) 28 )
  132. #define lrtypDelta ((LRTYP) 29 )
  133. #define lrtypDelete ((LRTYP) 30 )
  134. #define lrtypELC ((LRTYP) 31 )
  135. #define lrtypFreeSpace ((LRTYP) 32 )
  136. #define lrtypUndo ((LRTYP) 33 )
  137. #define lrtypPrecommit ((LRTYP) 34 )
  138. #define lrtypBegin0 ((LRTYP) 35 )
  139. #define lrtypCommit0 ((LRTYP) 36 )
  140. #define lrtypRefresh ((LRTYP) 37 )
  141. /* debug log records
  142. /**/
  143. #define lrtypRecoveryUndo ((LRTYP) 38 )
  144. #define lrtypRecoveryQuit ((LRTYP) 39 )
  145. #define lrtypFullBackup ((LRTYP) 40 )
  146. #define lrtypIncBackup ((LRTYP) 41 )
  147. #define lrtypCheckPage ((LRTYP) 42 )
  148. #define lrtypJetOp ((LRTYP) 43 )
  149. #define lrtypTrace ((LRTYP) 44 )
  150. #define lrtypShutDownMark ((LRTYP) 45 )
  151. #define lrtypMacroBegin ((LRTYP) 46 )
  152. #define lrtypMacroCommit ((LRTYP) 47 )
  153. #define lrtypMacroAbort ((LRTYP) 48 )
  154. #define lrtypMax ((LRTYP) 49 )
  155. /* log record structure ( fixed size portion of log entry )
  156. /**/
  157. typedef struct
  158. {
  159. LRTYP lrtyp;
  160. } LR;
  161. typedef LR LRSHUTDOWNMARK;
  162. typedef struct
  163. {
  164. LRTYP lrtyp;
  165. BYTE itagSon; /* itag of node, used only for verification */
  166. USHORT procid; /* user id of this log record */
  167. ULONG ulDBTimeLow; /* current flush counter of DB operations */
  168. PN pn:27; /* DBTimeHigh + dbid + pgno */
  169. ULONG ulDBTimeHigh:5;
  170. BYTE itagFather; /* itag of father node */
  171. BYTE ibSon; /* position to insert in father son table */
  172. BYTE bHeader; /* node header */
  173. BYTE cbKey; /* key size */
  174. USHORT fDirVersion:1; /* fDIRVersion for insert item list */
  175. USHORT cbData:15; /* data size */
  176. CHAR szKey[0]; /* key and data follow */
  177. } LRINSERTNODE;
  178. typedef struct /* for lrtypReplace lrtypReplaceC lrtypReplaceD */
  179. {
  180. LRTYP lrtyp;
  181. BYTE itag; /* wherereplace occurs */
  182. USHORT procid; /* user id of this log record */
  183. ULONG ulDBTimeLow; /* current flush counter of page */
  184. PN pn:27;
  185. ULONG ulDBTimeHigh:5;
  186. SRID bm; /* bookmark of this replace node */
  187. USHORT fDirVersion:1; /* flags used in original DIR call */
  188. USHORT cb:15; /* data size/diff info */
  189. USHORT cbOldData; /* before image data size, may be 0 */
  190. USHORT cbNewData; /* after image data size, == cb if not replaceC */
  191. CHAR szData[0]; /* made line data for after image follow */
  192. } LRREPLACE;
  193. typedef struct /* for lrtypDeferredBI */
  194. {
  195. LRTYP lrtyp;
  196. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  197. USHORT procid; /* user id of this log record */
  198. SRID bm; /* entry key to version store */
  199. DBID dbid;
  200. USHORT level:4;
  201. USHORT cbData:12; /* data size/diff info */
  202. CHAR rgbData[0]; /* made line data for new record follow */
  203. } LRDEFERREDBI;
  204. typedef struct
  205. {
  206. LRTYP lrtyp;
  207. BYTE itag;
  208. USHORT procid; /* user id of this log record */
  209. ULONG ulDBTimeLow; /* current flush counter of page */
  210. PN pn:27;
  211. ULONG ulDBTimeHigh:5;
  212. SRID bm;
  213. USHORT cbOldData;
  214. } LRLOCKBI;
  215. typedef struct
  216. {
  217. LRTYP lrtyp;
  218. BYTE itag;
  219. USHORT procid; /* user id of this log record */
  220. ULONG ulDBTimeLow; /* current flush counter of page */
  221. PN pn:27;
  222. ULONG ulDBTimeHigh:5;
  223. SRID bm; /* bookmark of this delete node */
  224. BYTE fDirVersion; /* flags used in original DIR call */
  225. } LRFLAGDELETE;
  226. typedef struct
  227. {
  228. LRTYP lrtyp;
  229. BYTE itag;
  230. USHORT procid; /* user id of this log record */
  231. ULONG ulDBTimeLow; /* current flush counter of page */
  232. PN pn:27;
  233. ULONG ulDBTimeHigh:5;
  234. } LRDELETE;
  235. typedef struct
  236. {
  237. LRTYP lrtyp;
  238. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  239. USHORT procid; /* user id of this log record */
  240. ULONG ulDBTimeLow; /* current flush counter of page */
  241. SRID bm;
  242. SRID bmTarget; /* page being updated during undo operation */
  243. WORD dbid:3;
  244. WORD wDBTimeHigh:5;
  245. WORD wFiller:8;
  246. USHORT level:4;
  247. USHORT cbDelta:12;
  248. } LRFREESPACE;
  249. typedef struct
  250. {
  251. LRTYP lrtyp;
  252. BYTE level;
  253. USHORT procid; /* user id of this log record */
  254. ULONG ulDBTimeLow; /* current flush counter of page */
  255. SRID bm;
  256. WORD dbid:3;
  257. WORD wDBTimeHigh:5;
  258. WORD wFiller:8;
  259. USHORT oper; /* no DDL */
  260. SRID item;
  261. SRID bmTarget; /* the page being updated during undo operation */
  262. } LRUNDO;
  263. /* expunge link commit log record
  264. /**/
  265. typedef struct
  266. {
  267. LRTYP lrtyp;
  268. BYTE itag;
  269. USHORT procid; /* user id of this log record */
  270. ULONG ulDBTimeLow; /* current flush counter of page */
  271. PN pn:27;
  272. ULONG ulDBTimeHigh:5;
  273. SRID sridSrc;
  274. } LRELC;
  275. typedef struct
  276. {
  277. LRTYP lrtyp;
  278. BYTE itag;
  279. USHORT procid; /* user id of this log record */
  280. ULONG ulDBTimeLow; /* current flush counter of page */
  281. PN pn:27;
  282. ULONG ulDBTimeHigh:5;
  283. SRID bm; /* bookmark of this udpated node */
  284. BYTE bHeader;
  285. } LRUPDATEHEADER;
  286. typedef struct
  287. {
  288. LRTYP lrtyp;
  289. BYTE itag; /* of item list node */
  290. USHORT procid; /* user id of this log record */
  291. ULONG ulDBTimeLow; /* current flush counter of DB operations */
  292. PN pn:27; /* dbid + pgno */
  293. ULONG ulDBTimeHigh:5;
  294. SRID srid; /* item to insert */
  295. SRID sridItemList; /* bookmark of first item list node */
  296. BYTE fDirVersion; /* so far only one bit is used - fDIRVersion */
  297. } LRINSERTITEM;
  298. typedef struct
  299. {
  300. LRTYP lrtyp;
  301. BYTE itag; /* item list */
  302. USHORT procid; /* user id of this log record */
  303. ULONG ulDBTimeLow; /* current flush counter of DB operations */
  304. PN pn:27; /* ulDBTimeHigh + dbid + pgno */
  305. ULONG ulDBTimeHigh:5;
  306. WORD citem; /* number of items to append */
  307. SRID rgitem[0];
  308. } LRINSERTITEMS;
  309. typedef struct
  310. {
  311. LRTYP lrtyp;
  312. BYTE itag; /* of item list node */
  313. USHORT procid; /* user id of this log record */
  314. ULONG ulDBTimeLow; /* current flush counter of page */
  315. PN pn:27;
  316. ULONG ulDBTimeHigh:5;
  317. SRID srid; /* item to insert */
  318. SRID sridItemList; /* bookmark of first item list node */
  319. } LRFLAGITEM;
  320. typedef struct
  321. {
  322. LRTYP lrtyp;
  323. BYTE itagToSplit; /* used only for verification! */
  324. USHORT procid; /* user id of this log record */
  325. ULONG ulDBTimeLow; /* current flush counter of DB operations */
  326. PN pn:27; /* ulDBTimeHigh + dbid + pgno */
  327. ULONG ulDBTimeHigh:5;
  328. WORD cItem;
  329. BYTE itagFather; /* itag of father */
  330. BYTE ibSon; /* Position to insert in father's son table */
  331. BYTE fDirAppendItem; /* flag to indicate if it is append item */
  332. } LRSPLITITEMLISTNODE;
  333. typedef struct
  334. {
  335. LRTYP lrtyp;
  336. BYTE itag; /* item list */
  337. USHORT procid; /* user id of this log record */
  338. ULONG ulDBTimeLow; /* current flush counter of DB operations */
  339. PN pn:27; /* dbid + pgno */
  340. ULONG ulDBTimeHigh:5;
  341. SRID srid; /* item to insert */
  342. SRID sridItemList; /* bookmark of first item list node */
  343. } LRDELETEITEM;
  344. typedef struct
  345. {
  346. LRTYP lrtyp;
  347. BYTE itag; /* wherereplace occurs */
  348. USHORT procid; /* user id of this log record */
  349. ULONG ulDBTimeLow; /* current flush counter of page */
  350. PN pn:27;
  351. ULONG ulDBTimeHigh:5;
  352. SRID bm; /* bookmark of this replace node */
  353. LONG lDelta;
  354. BYTE fDirVersion; /* flags used in original DIR call */
  355. } LRDELTA;
  356. typedef struct
  357. {
  358. LRTYP lrtyp;
  359. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  360. USHORT procid; /* user id of this log record */
  361. ULONG ulDBTimeLow; /* current flush counter of page */
  362. PN pn:27;
  363. ULONG ulDBTimeHigh:5;
  364. PGNO pgnoFDP;
  365. SHORT cbFree;
  366. SHORT cbUncommitted;
  367. SHORT itagNext;
  368. } LRCHECKPAGE;
  369. typedef struct
  370. {
  371. LRTYP lrtyp;
  372. BYTE levelBegin:4; /* begin transaction level */
  373. BYTE level:4; /* transaction levels */
  374. USHORT procid; /* user id of this log record */
  375. } LRBEGIN;
  376. typedef struct
  377. {
  378. LRBEGIN;
  379. TRX trxBegin0;
  380. } LRBEGIN0;
  381. typedef struct
  382. {
  383. LRTYP lrtyp;
  384. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  385. USHORT procid;
  386. TRX trxBegin0;
  387. } LRREFRESH;
  388. typedef struct
  389. {
  390. LRTYP lrtyp;
  391. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  392. USHORT procid;
  393. } LRPRECOMMIT;
  394. typedef struct
  395. {
  396. LRTYP lrtyp;
  397. BYTE level; /* transaction levels */
  398. USHORT procid; /* user id of this log record */
  399. } LRCOMMIT;
  400. typedef struct
  401. {
  402. LRCOMMIT;
  403. TRX trxCommit0;
  404. } LRCOMMIT0;
  405. typedef struct
  406. {
  407. LRTYP lrtyp;
  408. LEVEL levelRollback; /* transaction level */
  409. USHORT procid; /* user id of this log record */
  410. } LRROLLBACK;
  411. typedef struct
  412. {
  413. LRTYP lrtyp;
  414. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  415. USHORT procid;
  416. } LRMACROBEGIN;
  417. typedef struct
  418. {
  419. LRTYP lrtyp;
  420. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  421. USHORT procid;
  422. } LRMACROEND;
  423. typedef struct
  424. {
  425. LRTYP lrtyp;
  426. BYTE dbid;
  427. USHORT procid; /* user id of this log record, unused in V15 */
  428. JET_GRBIT grbit;
  429. SIGNATURE signDb;
  430. USHORT fLogOn:1;
  431. USHORT cbPath:15; /* data size */
  432. CHAR rgb[0]; /* path name and signiture follows */
  433. } LRCREATEDB;
  434. typedef struct
  435. {
  436. LRTYP lrtyp;
  437. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  438. USHORT procid;
  439. SIGNATURE signDb;
  440. SIGNATURE signLog;
  441. LGPOS lgposConsistent; /* earliest acceptable database consistent time */
  442. DBID dbid;
  443. USHORT fLogOn:1;
  444. USHORT fReadOnly:1;
  445. USHORT fVersioningOff:1;
  446. USHORT cbPath:12; /* data size */
  447. CHAR rgb[0]; /* path name follows */
  448. } LRATTACHDB;
  449. typedef struct
  450. {
  451. LRTYP lrtyp;
  452. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  453. USHORT procid; /* user id of this log record, unused in V15 */
  454. DBID dbid;
  455. USHORT cbPath:15;
  456. USHORT cbDbSig;
  457. CHAR rgb[0]; /* path name follows */
  458. } LRDETACHDB;
  459. typedef struct
  460. {
  461. LRTYP lrtyp;
  462. BYTE splitt; /* split type */
  463. USHORT procid; /* user id of this log record */
  464. ULONG ulDBTimeLow; /* flush counter of page being split */
  465. PN pn:27; /* page (focus) being split, includes dbid */
  466. ULONG ulDBTimeHigh:5;
  467. PGNO pgnoNew; /* newly-allocated page no */
  468. PGNO pgnoNew2; /* newly-allocated page no */
  469. PGNO pgnoNew3; /* newly-allocated page no */
  470. PGNO pgnoSibling; /* newly-allocated page no */
  471. BYTE fLeaf:1; /* split on leaf node */
  472. BYTE pgtyp:7; /* page type of new page */
  473. BYTE itagSplit; /* node at which page is being split */
  474. SHORT ibSonSplit; /* ibSon at which node is being split */
  475. PGNO pgnoFather; /* pgno of father node */
  476. SHORT itagFather; /* itag of father node, could be itagNil (3 bytes) */
  477. SHORT itagGrandFather;/* itag of Grand father node, could be itagNil (3 bytes) */
  478. SHORT cbklnk; /* number of back links */
  479. BYTE ibSonFather;
  480. BYTE cbKey;
  481. BYTE cbKeyMac;
  482. BYTE rgb[0];
  483. } LRSPLIT;
  484. typedef struct
  485. {
  486. LRTYP lrtyp;
  487. BYTE itagFather; /* itag of father of page pointer */
  488. USHORT procid; /* user id of this log record */
  489. ULONG ulDBTimeLow; /* flush counter of page being split */
  490. PN pn:27; /* page pointer of empty page */
  491. ULONG ulDBTimeHigh:5;
  492. PGNO pgnoFather;
  493. PGNO pgnoLeft;
  494. PGNO pgnoRight;
  495. USHORT itag; /* itag of page pointer, could be Nil (itagNil is 3 bytes) */
  496. BYTE ibSon;
  497. } LREMPTYPAGE;
  498. typedef struct
  499. {
  500. LRTYP lrtyp;
  501. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  502. USHORT procid;
  503. PN pn:27; /* page pointer of merged page */
  504. ULONG ulDBTimeHigh:5;
  505. PGNO pgnoRight; /* page appended to */
  506. PGNO pgnoParent;
  507. ULONG ulDBTimeLow;
  508. SHORT itagPagePtr;
  509. SHORT cbKey;
  510. SHORT cbklnk;
  511. BYTE rgb[0];
  512. } LRMERGE;
  513. typedef struct
  514. {
  515. LRTYP lrtyp;
  516. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  517. USHORT procid; /* user id of this log record */
  518. ULONG ulDBTimeLow; /* flush counter of father FDP page */
  519. PN pn:27; /* FDP page */
  520. ULONG ulDBTimeHigh:5;
  521. PGNO pgnoFDPParent; /* parent FDP */
  522. USHORT cpgGot; /* returned number of pages */
  523. USHORT cpgWish; /* request pages */
  524. } LRINITFDP;
  525. typedef struct
  526. {
  527. LRTYP lrtyp;
  528. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  529. USHORT ibForwardLink;
  530. ULONG ulCheckSum;
  531. USHORT isecForwardLink;
  532. } LRMS;
  533. typedef struct
  534. {
  535. LRTYP lrtyp;
  536. BYTE rgbFiller[3]; // UNDONE: remove this when PPC compiler bug fix
  537. DBMS_PARAM dbms_param;
  538. } LRINIT;
  539. typedef struct
  540. {
  541. LRTYP lrtyp;
  542. BYTE fHard;
  543. BYTE rgbFiller[2]; // UNDONE: remove this when PPC compiler bug fix
  544. LGPOS lgpos; /* point back to last beginning of undo */
  545. LGPOS lgposRedoFrom;
  546. } LRTERMREC;
  547. typedef struct
  548. {
  549. LRTYP lrtyp;
  550. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  551. USHORT cbPath; /* backup path/restore path */
  552. BYTE szData[0];
  553. } LRLOGRESTORE;
  554. typedef struct
  555. {
  556. LRTYP lrtyp;
  557. BYTE op; /* jet operation */
  558. USHORT procid; /* user id of this log record */
  559. } LRJETOP;
  560. typedef struct
  561. {
  562. LRTYP lrtyp;
  563. BYTE bFiller; // UNDONE: remove this when PPC compiler bug fix
  564. USHORT procid; /* user id of this log record */
  565. USHORT cb;
  566. BYTE sz[0];
  567. } LRTRACE;
  568. #pragma pack()
  569. #ifdef NOLOG
  570. #define LGDepend( pbf, lgpos )
  571. #define LGDepend2( pbf, lgpos )
  572. #define ErrLGInsert( pfucb, fHeader, pkey, plineData, fDIRFlags ) 0
  573. #define ErrLGInsertItemList( pfucb, fHeader, pkey, plineData ) 0
  574. #define ErrLGReplace( pfucb, plineNew, fDIRFlags, cbOldData, plineDiff ) 0
  575. #define ErrLGDeferredBIWithoutRetry( prce ) 0
  576. #define ErrLGDeferredBI( prce ) 0
  577. #define ErrLGFlagDelete( pfucb, fFlags ) 0
  578. #deinfe ErrLGUpdateHeader( pfucb, bHeader ) 0
  579. #define ErrLGInsertItem( pfucb, fDIRFlags ) 0
  580. #define ErrLGInsertItems( pfucb, rgitem, citem ) 0
  581. #define ErrLGFlagDeleteItem( pfucb ) 0
  582. #define ErrLGSplitItemListNode( pfucb, cItem, itagFather, ibSon, itagToSplit, fFlags) 0
  583. #define ErrLGDeleteItem( pfucb ) 0
  584. #define ErrLGDelta( pfucb, lDelta, fDIRFlags ) 0
  585. #define ErrLGLockBI( pfucb, cbData ) 0
  586. #define ErrLGBeginTransaction( ppib, levelBeginFrom ) 0
  587. #define ErrLGPrecommitTransaction( ppib, &lgposPrecommitRec ) 0
  588. #define ErrLGCommitTransaction( ppib, levelCommitTo ) 0
  589. #define ErrLGRefreshTransaction( ppib ) 0
  590. #define ErrLGRollback( ppib,levelsRollback ) 0
  591. #define ErrLGMacroBegin( ppib ) 0
  592. #define ErrLGMacroCommit( ppib ) 0
  593. #define ErrLGMacroAbort( ppib ) 0
  594. #define ErrLGUndo( prce ) 0
  595. #define ErrLGFreeSpace( pfucb, bm, cbDelta ) 0
  596. #define ErrLGCreateDB( ppib, dbid, grbit, sz, cch, psign, plgposRec ) 0
  597. #define ErrLGAttachDB( ppib, dbid, sz, cch, psign, psignLog, plgposConsistent, plgposRec ) 0
  598. #define ErrLGDetachDB( ppib, dbid, sz, cch, plgposRec ) 0
  599. #define ErrLGMerge( pfucb, psplit ) 0
  600. #define ErrLGSplit( splitt, pfucb, pcsrPagePointer, psplit, pgtypNew ) 0
  601. #define ErrLGEmptyPage( pfucbFather, prmpage ) 0
  602. #define ErrLGInitFDP( pfucb, pgnoFDPParent, pnFDP, cpgGot, cpgWish) 0
  603. #define ErrLGFlagInsertItem(pfucb) 0
  604. #define ErrLGStart() 0
  605. #define ErrLGQuit( plgposRecoveryUndo ) 0
  606. #define ErrLGShutDownMark( plgposLogRec ) 0
  607. #define ErrLGRecoveryQuit( plgposRecoveryUndo ) 0
  608. #define ErrLGRecoveryUndo( szRestorePath ) 0
  609. #define ErrLGFullBackup(szRestorePath, plgposLogRec ) 0
  610. #define ErrLGIncBackup(szRestorePath ) 0
  611. #define ErrLGCheckPage( pfucb, cbFree, cbUncommitted, itagNext, pgnoFDP ) 0
  612. #define ErrLGCheckPage2( ppib, pbf, cbFree, cbUncommited, itagNext, pgnoFDP ) 0
  613. #define ErrLGTrace( ppib, sz ) 0
  614. #define ErrLGTrace2( ppib, sz ) 0
  615. #else /* !NOLOG */
  616. #define ErrLGInsert( pfucb, fHeader, pkey, plineData, fFlags) \
  617. ErrLGInsertNode( lrtypInsertNode, pfucb, fHeader, pkey, plineData, fFlags)
  618. #define ErrLGInsertItemList( pfucb, fHeader, pkey, plineData, fFlags) \
  619. ErrLGInsertNode( lrtypInsertItemList, pfucb, fHeader, pkey, plineData, fFlags)
  620. ERR ErrLGInsertNode( LRTYP lrtyp,
  621. FUCB *pfucb, INT fHeader, KEY *pkey, LINE *plineData, INT fFlags);
  622. ERR ErrLGReplace( FUCB *pfucb, LINE *plineNew, INT fDIRFlags, INT cbOldData, BYTE *pbDiff, INT cbDiff );
  623. ERR ErrLGDeferredBIWithoutRetry( RCE *prce );
  624. ERR ErrLGDeferredBI( RCE *prce );
  625. ERR ErrLGFlagDelete( FUCB *pfucb, INT fFlags);
  626. ERR ErrLGUpdateHeader( FUCB *pfucb, INT bHeader );
  627. ERR ErrLGInsertItem( FUCB *pfucb, INT fDIRFlags );
  628. ERR ErrLGInsertItems( FUCB *pfucb, SRID *rgitem, INT citem );
  629. ERR ErrLGFlagDeleteItem( FUCB *pfucb );
  630. ERR ErrLGSplitItemListNode( FUCB *pfucb, INT cItem, INT itagFather,
  631. INT ibSon, INT itagToSplit, INT fFlags );
  632. ERR ErrLGDelta( FUCB *pfucb, LONG lDelta, INT fDIRFlags );
  633. ERR ErrLGLockBI( FUCB *pfucb, INT cbData );
  634. ERR ErrLGBeginTransaction( PIB *ppib, INT levelBeginFrom );
  635. ERR ErrLGRefreshTransaction( PIB *ppib );
  636. ERR ErrLGPrecommitTransaction( PIB *ppib, LGPOS *plgposRec );
  637. ERR ErrLGCommitTransaction( PIB *ppib, INT levelCommitTo );
  638. ERR ErrLGRollback( PIB *ppib, INT levelsRollback );
  639. ERR ErrLGUndo( RCE *prce );
  640. ERR ErrLGFreeSpace( FUCB *pfucb, SRID bm, INT cbDelta );
  641. ERR ErrLGMacroBegin( PIB *ppib );
  642. ERR ErrLGMacroEnd( PIB *ppib, LRTYP lrtyp );
  643. #define ErrLGMacroCommit( ppib ) ErrLGMacroEnd( ppib, lrtypMacroCommit )
  644. #define ErrLGMacroAbort( ppib ) ErrLGMacroEnd( ppib, lrtypMacroAbort )
  645. ERR ErrLGCreateDB( PIB *ppib, DBID dbid, JET_GRBIT grbit, CHAR *sz, INT cch, SIGNATURE *psignDb, LGPOS *plgposRec );
  646. ERR ErrLGAttachDB( PIB *ppib, DBID dbid, CHAR *sz, INT cch, SIGNATURE *psignDb, SIGNATURE *psignLog, LGPOS *plgposConsistent, LGPOS *plgposRec );
  647. ERR ErrLGDetachDB( PIB *ppib, DBID dbid, CHAR *sz, INT cch, LGPOS *plgposRec );
  648. ERR ErrLGMerge( FUCB *pfucb, struct _split *psplit );
  649. ERR ErrLGSplit( SPLITT splitt, FUCB *pfucb, CSR *pcsrPagePointer,
  650. struct _split *psplit, PGTYP pgtypNew );
  651. ERR ErrLGEmptyPage( FUCB *pfucbFather, RMPAGE *prmpage );
  652. ERR ErrLGInitFDP( FUCB *pfucb, PGNO pgnoFDPParent,
  653. PN pnFDP, INT cpgGot, INT cpgWish);
  654. #define ErrLGFlagDeleteItem(pfucb) ErrLGFlagItem(pfucb, lrtypFlagDeleteItem)
  655. #define ErrLGFlagInsertItem(pfucb) ErrLGFlagItem(pfucb, lrtypFlagInsertItem)
  656. ERR ErrLGFlagItem(FUCB *pfucb, LRTYP lrtyp);
  657. ERR ErrLGDeleteItem( FUCB *pfucb );
  658. ERR ErrLGDelete( FUCB *pfucb );
  659. ERR ErrLGExpungeLinkCommit( FUCB *pfucb, SSIB *pssibSrc, SRID sridSrc );
  660. ERR ErrLGStart();
  661. ERR ErrLGShutDownMark( LGPOS *plgposShutDownMark );
  662. #define ErrLGRecoveryQuit( plgposRecoveryUndo, plgposRedoFrom, fHard ) \
  663. ErrLGQuitRec( lrtypRecoveryQuit, plgposRecoveryUndo, plgposRedoFrom, fHard )
  664. #define ErrLGQuit( plgposStart ) \
  665. ErrLGQuitRec( lrtypTerm, plgposStart, pNil, 0 )
  666. ERR ErrLGQuitRec( LRTYP lrtyp, LGPOS *plgposQuit, LGPOS *plgposRedoFrom, BOOL fHard);
  667. #define ErrLGRecoveryUndo(szRestorePath) \
  668. ErrLGLogRestore(lrtypRecoveryUndo, szRestorePath, fNoNewGen, pNil )
  669. #define ErrLGFullBackup(szRestorePath, plgposLogRec) \
  670. ErrLGLogRestore(lrtypFullBackup, szRestorePath, fCreateNewGen, plgposLogRec )
  671. #define ErrLGIncBackup(szRestorePath, plgposLogRec) \
  672. ErrLGLogRestore(lrtypIncBackup, szRestorePath, fCreateNewGen, plgposLogRec )
  673. ERR ErrLGLogRestore( LRTYP lrtyp, CHAR * szLogRestorePath, BOOL fNewGen, LGPOS *plgposLogRec );
  674. ERR ErrLGCheckPage( FUCB *pfucb, SHORT cbFree, SHORT cbUncommitted, SHORT itagNext, PGNO pgnoFDP );
  675. ERR ErrLGCheckPage2( PIB *ppib, BF *pbf, SHORT cbFree, SHORT cbUncommited, SHORT itagNext, PGNO pgnoFDP );
  676. ERR ErrLGTrace( PIB *ppib, CHAR *sz );
  677. ERR ErrLGTrace2( PIB *ppib, CHAR *sz );
  678. #endif /* logging enabled */
  679. ERR ErrLGSoftStart( BOOL fAllowNoJetLog, BOOL fNewCheckpointFile, BOOL *pfJetLogGeneratedDuringSoftStart );
  680. ERR ErrLGInit( BOOL *pfNewCheckpointFile );
  681. ERR ErrLGTerm( ERR err );
  682. #define fCreateNewGen fTrue
  683. #define fNoNewGen fFalse
  684. ERR ErrLGLogRec( LINE *rgline, INT cline, BOOL fNewGen, LGPOS *plgposLogRec );
  685. ERR ErrLGWaitPrecommit0Flush( PIB *ppib );
  686. #define szAssertFilename __FILE__
  687. STATIC INLINE ErrLGWaitForFlush( PIB *ppib, LGPOS *plgposLogRec )
  688. {
  689. extern SIG sigLogFlush;
  690. ERR err;
  691. AssertCriticalSection( critJet );
  692. if ( fLogDisabled || ( fRecovering && fRecoveringMode != fRecoveringUndo ) )
  693. return JET_errSuccess;
  694. ppib->lgposPrecommit0 = *plgposLogRec;
  695. LeaveCriticalSection( critJet );
  696. SignalSend( sigLogFlush );
  697. err = ErrLGWaitPrecommit0Flush( ppib );
  698. EnterCriticalSection( critJet );
  699. Assert( err >= 0 || ( fLGNoMoreLogWrite && err == JET_errLogWriteFail ) );
  700. return err;
  701. }
  702. #undef szAssertFilename
  703. ERR ErrLGInitLogBuffers( LONG lIntendLogBuffers );
  704. ULONG UlLGMSCheckSum( CHAR *pbLrmsNew );
  705. #define ErrLGCheckState() ( lsGlobal != lsNormal ? \
  706. ErrLGNewReservedLogFile() : \
  707. JET_errSuccess )
  708. #define FLGOn() (!fLogDisabled)
  709. #define FLGOff() (fLogDisabled)
  710. BOOL FIsNullLgpos( LGPOS *plgpos );
  711. VOID LGMakeLogName( CHAR *szLogName, CHAR *szFName );
  712. ERR ErrLGPatchAttachedDB( DBID dbid, JET_RSTMAP *rgrstmap, INT crstmap );
  713. ERR ErrLGNewReservedLogFile();
  714. STATIC INLINE INT CmpLgpos( LGPOS *plgpos1, LGPOS *plgpos2 )
  715. {
  716. BYTE *rgb1 = (BYTE *) plgpos1;
  717. BYTE *rgb2 = (BYTE *) plgpos2;
  718. // perform comparison on LGPOS as if it were a 64 bit integer
  719. #ifdef _X86_
  720. // bytes 7 - 4
  721. if ( *( (DWORD UNALIGNED *) ( rgb1 + 4 ) ) < *( (DWORD UNALIGNED *) ( rgb2 + 4 ) ) )
  722. return -1;
  723. if ( *( (DWORD UNALIGNED *) ( rgb1 + 4 ) ) > *( (DWORD UNALIGNED *) ( rgb2 + 4 ) ) )
  724. return 1;
  725. // bytes 3 - 0
  726. if ( *( (DWORD UNALIGNED *) ( rgb1 + 0 ) ) < *( (DWORD UNALIGNED *) ( rgb2 + 0 ) ) )
  727. return -1;
  728. if ( *( (DWORD UNALIGNED *) ( rgb1 + 0 ) ) > *( (DWORD UNALIGNED *) ( rgb2 + 0 ) ) )
  729. return 1;
  730. #else
  731. // bytes 7 - 0
  732. if ( *( (QWORD UNALIGNED *) ( rgb1 + 0 ) ) < *( (QWORD UNALIGNED *) ( rgb2 + 0 ) ) )
  733. return -1;
  734. if ( *( (QWORD UNALIGNED *) ( rgb1 + 0 ) ) > *( (QWORD UNALIGNED *) ( rgb2 + 0 ) ) )
  735. return 1;
  736. #endif
  737. return 0;
  738. }
  739. /* log checkpoint support
  740. /**/
  741. ERR ErrLGCheckpointInit( BOOL *pfNewCheckpointFile );
  742. VOID LGCheckpointTerm( VOID );
  743. /* database attachments
  744. /**/
  745. ERR ErrLGInitAttachment( VOID );
  746. VOID LGTermAttachment( VOID );
  747. ERR ErrLGLoadAttachmentsFromFMP( VOID );
  748. ERR ErrLGInsertAttachment( DBID dbid, CHAR *szFullPath );
  749. ERR ErrLGDeleteAttachment( DBID dbid );
  750. VOID LGCopyAttachment( BYTE *rgbAttach );