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.

604 lines
17 KiB

  1. #ifndef _DAEDEF_H
  2. #define _DAEDEF_H
  3. /* redirect Asserts in inline code to seem to fire from this file
  4. /**/
  5. #define szAssertFilename __FILE__
  6. #include "config.h"
  7. /***********************************************************/
  8. /****************** global configuration macros ************/
  9. /***********************************************************/
  10. #define CHECKSUM /* check sum for read/write page validation */
  11. //#define PERFCNT /* enable performance counter */
  12. //#define NO_LOG /* log disable */
  13. #define REUSE_DBID /* reuse detached database DBIDs */
  14. //#define CHECK_LOG_VERSION
  15. #define PCACHE_OPTIMIZATION /* enable all cache optimizations */
  16. #define PREREAD /* try to preread pages when we read in one direction */
  17. #ifdef DEBUG
  18. #ifdef PREREAD
  19. //#define PREREAD_DEBUG
  20. #endif // PREREAD
  21. #endif // DEBUG
  22. /***********************************************************/
  23. /******************* declaration macros ********************/
  24. /***********************************************************/
  25. #define VTAPI
  26. #include "daedebug.h"
  27. #ifndef PROFILE
  28. #define LOCAL static
  29. #else
  30. #define LOCAL
  31. #endif
  32. // Hack for OLE-DB - make all functions global and non-inline
  33. #ifdef USE_OLEDB
  34. #undef LOCAL
  35. #undef INLINE
  36. #define LOCAL
  37. #define INLINE
  38. #endif
  39. /***********************************************************/
  40. /************ global types and associated macros ***********/
  41. /***********************************************************/
  42. typedef struct _res /* resource, defined in sysinit.c and daeutil.h */
  43. {
  44. const INT cbSize;
  45. INT cblockAlloc;
  46. BYTE *pbAlloc;
  47. INT cblockAvail;
  48. BYTE *pbAvail;
  49. INT iblockCommit;
  50. INT iblockFail;
  51. BYTE *pbPreferredThreshold;
  52. } RES;
  53. typedef struct _pib PIB;
  54. typedef struct _ssib SSIB;
  55. typedef struct _fucb FUCB;
  56. typedef struct _csr CSR;
  57. typedef struct _fcb FCB;
  58. typedef struct _fdb FDB;
  59. typedef struct _idb IDB;
  60. typedef struct _dib DIB;
  61. typedef struct _rcehead RCEHEAD;
  62. typedef struct _rce RCE;
  63. typedef struct _bucket BUCKET;
  64. typedef struct _dab DAB;
  65. typedef struct _rmpage RMPAGE;
  66. typedef struct _bmfix BMFIX;
  67. typedef unsigned short LANGID;
  68. typedef ULONG LRID;
  69. typedef ULONG PROCID;
  70. #define pNil ((void *)0)
  71. #define pbNil ((BYTE *)0)
  72. #define plineNil ((LINE *)0)
  73. #define pkeyNil ((KEY *)0)
  74. #define ppibNil ((PIB *)0)
  75. #define pwaitNil ((WAIT *)0)
  76. #define pssibNil ((SSIB *)0)
  77. #define pfucbNil ((FUCB *)0)
  78. #define pcsrNil ((CSR *)0)
  79. #define pfcbNil ((FCB *)0)
  80. #define pfdbNil ((FDB *)0)
  81. #define pfieldNil ((FIELD *)0)
  82. #define pidbNil ((IDB *)0)
  83. #define pscbNil ((SCB *)0)
  84. #define procidNil ((PROCID) 0xffff)
  85. #define pbucketNil ((BUCKET *)0)
  86. #define prceheadNil ((RCEHEAD *)0)
  87. #define prceNil ((RCE *)0)
  88. #define pdabNil ((DAB *)0)
  89. #define prmpageNil ((RMPAGE *) 0)
  90. typedef unsigned long PGNO;
  91. typedef unsigned long PGDISCONT;
  92. typedef unsigned long PN;
  93. #define pnNull ((PN) 0)
  94. #define pgnoNull ((PGNO) 0)
  95. /* UNDONE: should be in storage.h */
  96. #define FVersionPage(pbf) (pbf->ppage->cVersion)
  97. #define CPG LONG /* count of pages */
  98. typedef BYTE LEVEL; /* transaction levels */
  99. #define levelNil ((LEVEL)0xff) /* flag for inactive PIB */
  100. typedef WORD DBID;
  101. typedef WORD FID;
  102. typedef SHORT IDXSEG;
  103. typedef ULONG SRID;
  104. typedef ULONG LINK;
  105. STATIC INLINE PGNO PgnoOfSrid( SRID const srid )
  106. {
  107. return srid >> 8;
  108. }
  109. STATIC INLINE BYTE ItagOfSrid( SRID const srid )
  110. {
  111. return *( (BYTE *) &srid );
  112. }
  113. STATIC INLINE SRID SridOfPgnoItag( PGNO const pgno, LONG const itag )
  114. {
  115. return (SRID) ( ( pgno << 8 ) | (BYTE) itag );
  116. }
  117. #define itagNil ( 0x0FFF )
  118. #define sridNull ( 0x000000FF )
  119. #define sridNullLink ( 0 )
  120. /* position within current series
  121. * note order of field is of the essence as log position used by
  122. * storage as timestamp, must in ib, isec, lGen order so that we can
  123. * use little endian integer comparisons.
  124. */
  125. typedef struct
  126. {
  127. USHORT ib; /* must be the last so that lgpos can */
  128. USHORT isec; /* index of disksec starting logsec */
  129. LONG lGeneration; /* generation of logsec */
  130. } LGPOS; /* be casted to TIME. */
  131. extern LGPOS lgposMax;
  132. extern LGPOS lgposMin;
  133. extern INT fRecovering; /* to turn off logging during Redo */
  134. #define fRecoveringNone 0
  135. #define fRecoveringRedo 1
  136. #define fRecoveringUndo 2
  137. extern INT fRecoveringMode; /* where we are in recovering? Redo or Undo phase */
  138. extern char szBaseName[];
  139. extern char szSystemPath[];
  140. extern int fTempPathSet;
  141. extern char szTempPath[];
  142. extern char szJet[];
  143. extern char szJetLog[];
  144. extern char szJetLogNameTemplate[];
  145. extern char szJetTmp[];
  146. extern char szJetTmpLog[];
  147. extern char szMdbExt[];
  148. extern char szJetTxt[];
  149. /***********************************************************/
  150. /*********************** DAE macros ************************/
  151. /***********************************************************/
  152. /* these are needed for setting columns and tracking indexes
  153. /**/
  154. #define cbitFixed 32
  155. #define cbitVariable 32
  156. #define cbitFixedVariable (cbitFixed + cbitVariable)
  157. #define cbitTagged 192
  158. #define fidFixedLeast 1
  159. #define fidFixedMost (fidVarLeast-1)
  160. #define fidVarLeast 128
  161. #define fidVarMost (fidTaggedLeast-1)
  162. #define fidTaggedLeast 256
  163. #define fidTaggedMost (0x7ffe)
  164. #define fidMax (0x7fff)
  165. #define FFixedFid(fid) ((fid)<=fidFixedMost && (fid)>=fidFixedLeast)
  166. #define FVarFid(fid) ((fid)<=fidVarMost && (fid)>=fidVarLeast)
  167. #define FTaggedFid(fid) ((fid)<=fidTaggedMost && (fid)>=fidTaggedLeast)
  168. STATIC INLINE INT IbFromFid ( FID fid )
  169. {
  170. INT ib;
  171. if ( FFixedFid( fid ) )
  172. {
  173. ib = ((fid - fidFixedLeast) % cbitFixed) / 8;
  174. }
  175. else if ( FVarFid( fid ) )
  176. {
  177. ib = (((fid - fidVarLeast) % cbitVariable) + cbitFixed) / 8;
  178. }
  179. else
  180. {
  181. Assert( FTaggedFid( fid ) );
  182. ib = (((fid - fidTaggedLeast) % cbitTagged) + cbitFixedVariable) / 8;
  183. }
  184. Assert( ib >= 0 && ib < 32 );
  185. return ib;
  186. }
  187. STATIC INLINE INT IbitFromFid ( FID fid )
  188. {
  189. INT ibit;
  190. if ( FFixedFid( fid ) )
  191. {
  192. ibit = 1 << ((fid - fidFixedLeast) % 8 );
  193. }
  194. else if ( FVarFid( fid ) )
  195. {
  196. ibit = 1 << ((fid - fidVarLeast) % 8);
  197. }
  198. else
  199. {
  200. Assert( FTaggedFid( fid ) );
  201. ibit = 1 << ((fid - fidTaggedLeast) % 8);
  202. }
  203. return ibit;
  204. }
  205. /* per database operation counter, qwDBTime is logged, used to compare
  206. * with the ulDBTime of a page to decide if a redo of the logged operation
  207. * is necessary.
  208. */
  209. #define qwDBTimeMin (0x0000000000000000)
  210. #define qwDBTimeMax (0x0000000fffffffff)
  211. /* Transaction counter, used to keep track of the oldest transaction.
  212. */
  213. typedef ULONG TRX;
  214. #define trxMin 0
  215. #define trxMax (0xffffffff)
  216. typedef struct
  217. {
  218. ULONG cb;
  219. BYTE *pb;
  220. } LINE;
  221. STATIC INLINE BOOL FLineNull( LINE const *pline )
  222. {
  223. return !pline || !pline->cb || !pline->pb;
  224. }
  225. STATIC INLINE VOID LineCopy( LINE *plineTo, LINE const *plineFrom )
  226. {
  227. plineTo->cb = plineFrom->cb;
  228. memcpy( plineTo->pb, plineFrom->pb, plineFrom->cb );
  229. }
  230. STATIC INLINE ULONG CbLine( LINE const *pline )
  231. {
  232. return pline ? pline->cb : 0;
  233. }
  234. typedef LINE KEY;
  235. #define FKeyNull FLineNull
  236. #define KeyCopy LineCopy
  237. #define CbKey CbLine
  238. STATIC INLINE BYTE *Pb4ByteAlign( BYTE const *pb )
  239. {
  240. return (BYTE *) ( ( (LONG_PTR) pb + 3 ) & ~3 );
  241. }
  242. STATIC INLINE BYTE *Pb4ByteTruncate( BYTE const *pb )
  243. {
  244. return (BYTE *) ( (LONG_PTR) pb & ~3 );
  245. }
  246. typedef struct _threebytes { BYTE b[3]; } THREEBYTES;
  247. /***BEGIN MACHINE DEPENDANT***/
  248. STATIC INLINE VOID ThreeBytesFromL( THREEBYTES *ptb, LONG const l )
  249. {
  250. memcpy( ptb, &l, sizeof(THREEBYTES) );
  251. }
  252. STATIC INLINE VOID LFromThreeBytes( LONG *pl, THREEBYTES *ptb )
  253. {
  254. *pl = 0;
  255. memcpy( pl, ptb, sizeof(THREEBYTES) );
  256. }
  257. STATIC INLINE VOID KeyFromLong( BYTE *rgbKey, ULONG const ul )
  258. {
  259. BYTE *rgbul = (BYTE *) &ul;
  260. rgbKey[3] = rgbul[0];
  261. rgbKey[2] = rgbul[1];
  262. rgbKey[1] = rgbul[2];
  263. rgbKey[0] = rgbul[3];
  264. }
  265. STATIC INLINE VOID LongFromKey( ULONG *pul, BYTE const *rgbKey )
  266. {
  267. BYTE *rgbul = (BYTE *) pul;
  268. rgbul[3] = rgbKey[0];
  269. rgbul[2] = rgbKey[1];
  270. rgbul[1] = rgbKey[2];
  271. rgbul[0] = rgbKey[3];
  272. }
  273. /***END MACHINE DEPENDANT***/
  274. /***********************************************************/
  275. /******************** general C macros *********************/
  276. /***********************************************************/
  277. #define forever for(;;)
  278. #define NotUsed(p) ( p==p )
  279. /***********************************************************/
  280. /***** include Jet Project prototypes and constants ********/
  281. /***********************************************************/
  282. #define VOID void
  283. #define VDBAPI
  284. extern CODECONST(VTFNDEF) vtfndefIsam;
  285. extern CODECONST(VTFNDEF) vtfndefIsamInfo;
  286. extern CODECONST(VTFNDEF) vtfndefTTSortIns;
  287. extern CODECONST(VTFNDEF) vtfndefTTSortRet;
  288. extern CODECONST(VTFNDEF) vtfndefTTBase;
  289. #ifdef DEBUG
  290. JET_TABLEID TableidOfVtid( FUCB *pfucb );
  291. #else
  292. #define TableidOfVtid( pfucb ) ( (pfucb)->tableid )
  293. #endif
  294. ERR VTAPI ErrDispPrepareUpdate( JET_SESID sesid, JET_TABLEID tableid,
  295. JET_GRBIT grbit );
  296. ERR VTAPI ErrDispSetColumn( JET_SESID sesid, JET_TABLEID tableid,
  297. JET_COLUMNID columnid, const void *pb, unsigned long cb, JET_GRBIT grbit,
  298. JET_SETINFO *psetinfo );
  299. JET_VSESID UtilGetVSesidOfSesidTableid( JET_SESID sesid, JET_TABLEID tableid );
  300. ERR VTAPI ErrDispCloseTable( JET_SESID sesid, JET_TABLEID tableid );
  301. ERR VTAPI ErrDispUpdate( JET_SESID sesid, JET_TABLEID tableid, void *pb,
  302. unsigned long cbMax, unsigned long *pcbActual );
  303. ERR VTAPI ErrDispMove( JET_SESID sesid, JET_TABLEID tableid, long crows, JET_GRBIT grbit );
  304. /***********************************************************/
  305. /******************* mutual exclusion **********************/
  306. /***********************************************************/
  307. typedef void * SIG;
  308. typedef void * CRIT;
  309. /* enable multiple MUTEX resource
  310. /**/
  311. #ifdef SGMUTEX /* small grain */
  312. #define ErrSignalCreate( s, sz ) ErrUtilSignalCreate( s, sz )
  313. #define ErrSignalCreateAutoReset( s, sz ) ErrUtilSignalCreateAutoReset( s, sz )
  314. #define SignalReset( s ) UtilSignalReset( s )
  315. #define SignalSend( s ) UtilSignalSend( s )
  316. #define SignalWait( s, t ) UtilSignalWait( s, t )
  317. #define SignalWaitEx( s, t, f ) UtilSignalWaitEx( s, t, f )
  318. #define MultipleSignalWait( i, rg, f, t ) UtilMultipleSignalWait( i, rg, f, t )
  319. #define SignalClose( s ) UtilCloseSignal( s )
  320. #define ErrInitializeCriticalSection( s ) ErrUtilInitializeCriticalSection( s )
  321. #define EnterCriticalSection( s ) UtilEnterCriticalSection( s )
  322. #define LeaveCriticalSection( s ) UtilLeaveCriticalSection( s )
  323. #define EnterNestableCriticalSection( s ) UtilEnterNestableCriticalSection( s )
  324. #define LeaveNestableCriticalSection( s ) UtilLeaveNestableCriticalSection( s )
  325. #define AssertCriticalSection( s ) UtilAssertCrit( s )
  326. #define AssertNotInCriticalSection( s ) UtilAssertNotInCrit( s )
  327. #define DeleteCriticalSection( s ) UtilDeleteCriticalSection( s )
  328. #define LgErrInitializeCriticalSection( s ) JET_errSuccess
  329. #define LgEnterCriticalSection( s ) 0
  330. #define LgLeaveCriticalSection( s ) 0
  331. #define LgEnterNestableCriticalSection( s ) 0
  332. #define LgLeaveNestableCriticalSection( s ) 0
  333. #define LgAssertCriticalSection( s ) 0
  334. #define LgAssertNotInCriticalSection( s ) 0
  335. #define LgDeleteCriticalSection( s ) 0
  336. #define HoldCriticalSection( s ) 0
  337. #define ReleaseCriticalSection( s ) 0
  338. #define SgErrInitializeCriticalSection ErrInitalizeCriticalSection
  339. #define SgEnterCriticalSection EnterCriticalSection
  340. #define SgLeaveCriticalSection LeaveCriticalSection
  341. #define SgEnterNestableCriticalSection EnterNestableCriticalSection
  342. #define SgLeaveNestableCriticalSection LeaveNestableCriticalSection
  343. #define SgAssertCriticalSection AssertCriticalSection
  344. #define SgAssertNotInCriticalSection AssertNotInCriticalSection
  345. #define SgDeleteCriticalSection DeleteCriticalSection
  346. #else /* !SGMUTEX */
  347. #define ErrSignalCreate( s, sz ) ErrUtilSignalCreate( s, sz )
  348. #define ErrSignalCreateAutoReset( s, sz ) ErrUtilSignalCreateAutoReset( s, sz )
  349. #define SignalReset( s ) UtilSignalReset( s )
  350. #define SignalSend( s ) UtilSignalSend( s )
  351. #define SignalWait( s, t ) UtilSignalWait( s, t )
  352. #define SignalWaitEx( s, t, f ) UtilSignalWaitEx( s, t, f )
  353. #define MultipleSignalWait( i, rg, f, t ) UtilMultipleSignalWait( i, rg, f, t )
  354. #define SignalClose( s ) UtilCloseSignal( s )
  355. #define ErrInitializeCriticalSection( s ) ErrUtilInitializeCriticalSection( s )
  356. #define EnterCriticalSection( s ) UtilEnterCriticalSection( s )
  357. #define LeaveCriticalSection( s ) UtilLeaveCriticalSection( s )
  358. #define EnterNestableCriticalSection( s ) UtilEnterNestableCriticalSection( s )
  359. #define LeaveNestableCriticalSection( s ) UtilLeaveNestableCriticalSection( s )
  360. #define AssertCriticalSection( s ) UtilAssertCrit( s )
  361. #define AssertNotInCriticalSection( s ) UtilAssertNotInCrit( s )
  362. #define DeleteCriticalSection( s ) UtilDeleteCriticalSection( s )
  363. #define LgErrInitializeCriticalSection ErrUtilInitializeCriticalSection
  364. #define LgEnterCriticalSection UtilEnterCriticalSection
  365. #define LgLeaveCriticalSection UtilLeaveCriticalSection
  366. #define LgEnterNestableCriticalSection UtilEnterNestableCriticalSection
  367. #define LgLeaveNestableCriticalSection UtilLeaveNestableCriticalSection
  368. #define LgAssertCriticalSection UtilAssertCrit
  369. #define LgAssertNotInCriticalSection UtilAssertNotInCrit
  370. #define LgDeleteCriticalSection UtilDeleteCriticalSection
  371. #define LgHoldCriticalSection( s ) \
  372. { \
  373. UtilAssertCrit( s ); \
  374. UtilHoldCriticalSection( s ); \
  375. }
  376. #define LgReleaseCriticalSection( s ) \
  377. { \
  378. UtilAssertCrit( s ); \
  379. UtilReleaseCriticalSection( s ); \
  380. }
  381. #define SgErrInitializeCriticalSection( s ) JET_errSuccess
  382. #define SgEnterCriticalSection( s ) 0
  383. #define SgLeaveCriticalSection( s ) 0
  384. #define SgEnterNestableCriticalSection( s ) 0
  385. #define SgLeaveNestableCriticalSection( s ) 0
  386. #define SgAssertCriticalSection( s ) 0
  387. #define SgAssertNotInCriticalSection( s ) 0
  388. #define SgDeleteCriticalSection( s ) 0
  389. #endif /* !SGMUTEX */
  390. /* include other global DAE headers
  391. /**/
  392. #include "daeconst.h"
  393. #define fSTInitNotDone 0
  394. #define fSTInitInProgress 1
  395. #define fSTInitDone 2
  396. extern BOOL fSTInit;
  397. #pragma pack(1)
  398. typedef struct
  399. {
  400. ULONG cDiscont;
  401. ULONG cUnfixedMessyPage;
  402. } P_OLC_DATA;
  403. #define MAX_COMPUTERNAME_LENGTH 15
  404. typedef struct
  405. {
  406. BYTE bSeconds; // 0 - 60
  407. BYTE bMinutes; // 0 - 60
  408. BYTE bHours; // 0 - 24
  409. BYTE bDay; // 1 - 31
  410. BYTE bMonth; // 0 - 11
  411. BYTE bYear; // current year - 1900
  412. BYTE bFiller1;
  413. BYTE bFiller2;
  414. } LOGTIME;
  415. typedef struct _signiture
  416. {
  417. ULONG ulRandom; /* a random number */
  418. LOGTIME logtimeCreate; /* time db created, in logtime format */
  419. BYTE szComputerName[ MAX_COMPUTERNAME_LENGTH + 1 ]; /* where db is created */
  420. } SIGNATURE;
  421. typedef struct _bkinfo
  422. {
  423. LGPOS lgposMark; /* id for this backup */
  424. LOGTIME logtimeMark;
  425. ULONG genLow;
  426. ULONG genHigh;
  427. } BKINFO;
  428. /* Magic number used in database header for integrity checking
  429. /**/
  430. #define ulDAEMagic 0x89abcdef
  431. #define ulDAEVersion 0x00000500
  432. #define ulDAEPrevVersion 0x00000400 /* temporary to make exchange compatible */
  433. #define fDBStateJustCreated 1
  434. #define fDBStateInconsistent 2
  435. #define fDBStateConsistent 3
  436. typedef struct _dbfilehdr_fixed
  437. {
  438. ULONG ulChecksum; /* checksum of the 4k page */
  439. ULONG ulMagic; /* Magic number */
  440. ULONG ulVersion; /* version of DAE the db created */
  441. SIGNATURE signDb; /* signature of the db (incl. creation time). */
  442. ULONG grbitAttributes;/* attributes of the db */
  443. ULONG ulDBTimeLow; /* low ulDBTime of this database */
  444. /* keep it here for backward compatibility */
  445. ULONG fDBState; /* consistent/inconsistent state */
  446. LGPOS lgposConsistent;/* null if in inconsistent state */
  447. LOGTIME logtimeConsistent;/* null if in inconsistent state */
  448. LOGTIME logtimeAttach; /* Last attach time. */
  449. LGPOS lgposAttach;
  450. LOGTIME logtimeDetach; /* Last detach time. */
  451. LGPOS lgposDetach;
  452. DBID dbid; /* current db attachment. */
  453. SIGNATURE signLog; /* log signature for this attachments */
  454. BKINFO bkinfoFullPrev; /* Last successful full backup. */
  455. BKINFO bkinfoIncPrev; /* Last successful Incremental backup. */
  456. /* Reset when bkinfoFullPrev is set */
  457. BKINFO bkinfoFullCur; /* current backup. Succeed if a */
  458. /* corresponding pat file generated. */
  459. ULONG ulDBTimeHigh; /* DBTime */
  460. } DBFILEHDR_FIXED;
  461. #define cbPage 4096 // database logical page size
  462. typedef struct _dbfilehdr
  463. {
  464. DBFILEHDR_FIXED;
  465. BYTE rgbFiller[ cbPage - sizeof( DBFILEHDR_FIXED ) ];
  466. } DBFILEHDR;
  467. #pragma pack()
  468. STATIC INLINE VOID DBHDRSetDBTime( DBFILEHDR *pdbfilehdr, QWORD qwDBTime )
  469. {
  470. QWORDX qwx;
  471. qwx.qw = qwDBTime;
  472. pdbfilehdr->ulDBTimeLow = qwx.l;
  473. pdbfilehdr->ulDBTimeHigh = qwx.h;
  474. }
  475. STATIC INLINE QWORD QwDBHDRDBTime( DBFILEHDR *pdbfilehdr )
  476. {
  477. QWORDX qwx;
  478. qwx.l = pdbfilehdr->ulDBTimeLow;
  479. qwx.h = pdbfilehdr->ulDBTimeHigh;
  480. return qwx.qw;
  481. }
  482. // #define TEST_WRAP_AROUND 1
  483. STATIC INLINE VOID DBHDRIncDBTime( DBFILEHDR *pdbfilehdr )
  484. {
  485. QWORD qw;
  486. qw = QwDBHDRDBTime( pdbfilehdr );
  487. #ifdef TEST_WRAP_AROUND
  488. if ( qw < 0x00000000fffc0000 )
  489. qw = 0x00000000fffc0000;
  490. #endif
  491. qw++;
  492. DBHDRSetDBTime( pdbfilehdr, qw );
  493. }
  494. #undef szAssertFilename
  495. #endif // _DAEDEF_H