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.

544 lines
18 KiB

  1. /************ DAE: OS/2 Database Access Engine *************/
  2. /************ daedef.h: DAE Global Definitions *************/
  3. /***********************************************************/
  4. /******************* fundamental types *********************/
  5. /***********************************************************/
  6. #include "os.h"
  7. /***********************************************************/
  8. /****************** global configuration macros ************/
  9. /***********************************************************/
  10. #ifndef WIN16 /* for OS/2 or Win32 */
  11. #define ASYNC_IO_PROC /* asynchronous IO */
  12. #define ASYNC_LOG_FLUSH /* asynchronous LOG FLUSH */
  13. #define ASYNC_BF_CLEANUP /* asynchorouse Buffer clean up */
  14. #define ASYNC_VER_CLEANUP /* asynchronous Bucket clean up */
  15. #define ASYNC_BM_CLEANUP /* asynchorouse Bookmark clean up */
  16. #endif
  17. #define CHECKSUM /* check sum for read/write page validation */
  18. //#define PERFCNT /* enable performance counter */
  19. //#define NOLOG /* Log disabled? */
  20. #define REUSEDBID /* Reuse DBID */
  21. //#define RFS2
  22. //#define MEM_CHECK /* Check for resource and memory leakage */
  23. //#define KEYCHANGED
  24. #define BULK_INSERT_ITEM
  25. #define MOVEABLEDATANODE
  26. /***********************************************************/
  27. /******************* declaration macros ********************/
  28. /***********************************************************/
  29. #ifdef JETINTERNAL /* Start of definitions copied from vtapi.h */
  30. #ifndef NJETNT
  31. #ifdef WIN32 /* 0:32 Flat Model (Intel 80x86) */
  32. #define VTAPI __cdecl
  33. #elif defined(M_MRX000) /* 0:32 Flat Model (MIPS Rx000) */
  34. #define VTAPI
  35. #else /* WIN16 */ /* 16:16 Segmented Model */
  36. #define VTAPI __far __pascal
  37. #endif
  38. #endif
  39. #endif /* End of definitions copied from vtapi.h */
  40. #include "daedebug.h"
  41. #define LOCAL static
  42. #ifdef DEBUG
  43. #define INLINE
  44. #else
  45. #define INLINE __inline
  46. #endif
  47. /***********************************************************/
  48. /************ global types and associated macros ***********/
  49. /***********************************************************/
  50. typedef struct _res /* resource, defined in sysinit.c and daeutil.h */
  51. {
  52. const INT cbSize;
  53. INT cblockAlloc;
  54. BYTE *pbAlloc;
  55. INT cblockAvail;
  56. BYTE *pbAvail;
  57. INT iblockCommit;
  58. INT iblockFail;
  59. } RES;
  60. typedef struct _pib PIB;
  61. typedef struct _ssib SSIB;
  62. typedef struct _fucb FUCB;
  63. typedef struct _csr CSR;
  64. typedef struct _fcb FCB;
  65. typedef struct _fdb FDB;
  66. typedef struct _idb IDB;
  67. typedef struct _dib DIB;
  68. typedef struct _scb SCB;
  69. typedef struct _rcehead RCEHEAD;
  70. typedef struct _rce RCE;
  71. typedef struct _bucket BUCKET;
  72. typedef struct _dab DAB;
  73. typedef struct _rmpage RMPAGE;
  74. typedef struct _bmfix BMFIX;
  75. typedef unsigned short LANGID;
  76. typedef ULONG LRID;
  77. #if WIN32
  78. typedef ULONG PROCID;
  79. #else
  80. typedef TID PROCID;
  81. #endif
  82. #define pNil ((void *)0)
  83. #define pbNil ((BYTE *)0)
  84. #define plineNil ((LINE *)0)
  85. #define pkeyNil ((KEY *)0)
  86. #define ppibNil ((PIB *)0)
  87. #define pwaitNil ((WAIT *)0)
  88. #define pssibNil ((SSIB *)0)
  89. #define pfucbNil ((FUCB *)0)
  90. #define pcsrNil ((CSR *)0)
  91. #define pfcbNil ((FCB *)0)
  92. #define pfdbNil ((FDB *)0)
  93. #define pfieldNil ((FIELD *)0)
  94. #define pidbNil ((IDB *)0)
  95. #define pscbNil ((SCB *)0)
  96. #define procidNil ((PROCID) 0xffff)
  97. #define pbucketNil ((BUCKET *)0)
  98. #define prceheadNil ((RCEHEAD *)0)
  99. #define prceNil ((RCE *)0)
  100. #define pdabNil ((DAB *)0)
  101. #define prmpageNil ((RMPAGE *) 0)
  102. typedef unsigned long PGNO;
  103. typedef unsigned long PGDISCONT;
  104. typedef unsigned long PN;
  105. #define pnNull ((PN) 0)
  106. #define pgnoNull ((PGNO) 0)
  107. /* UNDONE: should be in storage.h */
  108. #define FVersionPage(pbf) (pbf->ppage->pghdr.cVersion)
  109. #define CPG LONG /* count of pages */
  110. typedef BYTE LEVEL; /* transaction levels */
  111. #define levelNil ((LEVEL)0xff) /* flag for inactive PIB */
  112. typedef WORD DBID;
  113. typedef WORD FID;
  114. typedef SHORT IDXSEG;
  115. /* Standard Record IDs */
  116. typedef ULONG SRID; /* standard record id */
  117. typedef ULONG LINK;
  118. #define PgnoOfSrid(srid) ((srid)>>8)
  119. #define ItagOfSrid(srid) ((BYTE)((srid) & 0x000000FF))
  120. #define SridOfPgnoItag(pgno, itag) ((pgno)<<8 | (LONG)(itag))
  121. #define itagNil ((INT)0x0fff)
  122. #define sridNull SridOfPgnoItag(pgnoNull, ((BYTE)itagNil))
  123. #define sridNullLink 0
  124. /* position within current series
  125. * note order of field is of the essence as log position used by
  126. * storage as timestamp, must in ib, isec, usGen order so that we can
  127. * use long value compare.
  128. */
  129. typedef struct
  130. {
  131. USHORT ib; /* must be the last so that lgpos can */
  132. USHORT isec; /* index of disksec starting logsec */
  133. USHORT usGeneration; /* generation of logsec */
  134. } LGPOS; /* be casted to TIME. */
  135. extern LGPOS lgposMax;
  136. extern LGPOS lgposMin;
  137. extern INT fRecovering; /* to turn off logging during Redo */
  138. /***********************************************************/
  139. /*********************** DAE macros ************************/
  140. /***********************************************************/
  141. /* per database operation counter, ulDBTime is logged, used to compare
  142. * with the ulDBTime of a page to decide if a redo of the logged operation
  143. * is necessary.
  144. */
  145. #define ulDBTimeMin (0x00000000)
  146. #define ulDBTimeMax (0xffffffff)
  147. /* Transaction counter, used to keep track of the oldest transaction.
  148. */
  149. typedef ULONG TRX;
  150. #define trxMin 0
  151. #define trxMax (0xffffffff)
  152. typedef struct
  153. {
  154. ULONG cb;
  155. BYTE *pb;
  156. } LINE;
  157. #define FLineNull(pline) \
  158. ((pline) == NULL || (pline)->cb == 0 || (pline)->pb == NULL)
  159. #define LineCopy(plineTo, plineFrom) \
  160. { \
  161. (plineTo)->cb = (plineFrom)->cb; \
  162. memcpy((plineTo)->pb, (plineFrom)->pb, (plineFrom)->cb); \
  163. }
  164. #define CbLine(pline) ((pline) ? (pline)->cb : 0)
  165. typedef LINE KEY; // Directory Key
  166. #define FKeyNull(pkey) FLineNull(pkey)
  167. #define KeyCopy(pkeyTo, pkeyFrom) LineCopy(pkeyTo, pkeyFrom)
  168. #define CbKey(pkey) CbLine(pkey)
  169. typedef struct
  170. {
  171. ULONG cbMax; // size of buffer
  172. ULONG cbActual; // true size of return value
  173. ULONG cbReturned; // length of value returned
  174. BYTE *pb; // pointer to buffer for return value
  175. } OUTLINE;
  176. typedef struct _threebytes { BYTE b[3]; } THREEBYTES;
  177. #define ThreeBytesFromL(tb, l) \
  178. { \
  179. ULONG DAE_ul = l; \
  180. BYTE *DAE_ptb = (BYTE *)&(tb); \
  181. *DAE_ptb = (BYTE)DAE_ul; \
  182. *++DAE_ptb = (BYTE)( DAE_ul >>= 8 ); \
  183. *++DAE_ptb = (BYTE)( DAE_ul >>= 8 ); \
  184. }
  185. #define LFromThreeBytes(l, tb) \
  186. { \
  187. ULONG DAE_ul; \
  188. BYTE *DAE_ptb = (BYTE *)&(tb) + 2; \
  189. DAE_ul = (ULONG) *DAE_ptb; \
  190. DAE_ul <<= 8; \
  191. DAE_ul |= *--DAE_ptb; \
  192. DAE_ul <<=8; \
  193. DAE_ul |= *--DAE_ptb; \
  194. l = DAE_ul; \
  195. }
  196. #define TbKeyFromPgno(tbLast, pgno) \
  197. { \
  198. ULONG DAE_ul = pgno; \
  199. BYTE * DAE_ptb = ((BYTE *)&(tbLast)) + 2; \
  200. *DAE_ptb = (BYTE) (DAE_ul); \
  201. *--DAE_ptb = (BYTE) (DAE_ul >>= 8); \
  202. *--DAE_ptb = (BYTE) (DAE_ul >>= 8); \
  203. }
  204. #define PgnoFromTbKey(pgno, tbKey) \
  205. { \
  206. ULONG DAE_ul; \
  207. BYTE * DAE_ptb = (BYTE *) & (tbKey); \
  208. DAE_ul = (ULONG) *DAE_ptb; \
  209. DAE_ul <<= 8; \
  210. DAE_ul |= *++DAE_ptb; \
  211. DAE_ul <<= 8; \
  212. DAE_ul |= *++DAE_ptb; \
  213. pgno = DAE_ul; \
  214. }
  215. #define Pb4ByteAlign( pb ) ( ((LONG)pb + 3) & 0xfffffffc )
  216. #define Pb4ByteTruncate( pb ) ( (LONG)pb & 0xfffffffc )
  217. /***********************************************************/
  218. /******************** general C macros *********************/
  219. /***********************************************************/
  220. #define forever for(;;)
  221. #ifdef DEBUG
  222. #ifdef RFS2
  223. /* RFS/JET call logging
  224. /*
  225. /* RFS allocator: returns 0 if allocation is disallowed. Also handles RFS logging.
  226. /* cRFSAlloc is the global allocation counter. A value of -1 disables RFS in debug mode.
  227. /**/
  228. #define RFSAlloc(type) (UtilRFSAlloc(#type))
  229. /* RFS disable/enable macros */
  230. #define RFSDisable() (fDisableRFS = 1)
  231. #define RFSEnable() (fDisableRFS = 0)
  232. /* JET call logging (log on failure)
  233. /**/
  234. #define LogJETCall(func,err) (UtilRFSLogJETCall(#func,err,szAssertFilename,__LINE__))
  235. /* JET call macros
  236. /**/
  237. #define Call(func) {LogJETCall(func,err = (func)); if (err < 0) {goto HandleError;}}
  238. #define CallR(func) {LogJETCall(func,err = (func)); if (err < 0) {return err;}}
  239. #define CallJ(func,label) {LogJETCall(func,err = (func)); if (err < 0) {goto label;}}
  240. #define CallS(func) {ERR errT; LogJETCall(func,errT = (func)); Assert(errT == JET_errSuccess);}
  241. /* JET inline error logging (logging controlled by JET call flags)
  242. /**/
  243. #define LogJETErr(err,label) (UtilRFSLogJETErr(err,#label,szAssertFilename,__LINE__))
  244. /* JET inline error macros
  245. /**/
  246. #define Error(errT,label) {LogJETErr(errT,label); err = (errT); goto label;}
  247. #else
  248. #define RFSAlloc(type) (1)
  249. #define RFSDisable() (1)
  250. #define RFSEnable() (0)
  251. #define Call(func) {if ((err = (func)) < 0) {goto HandleError;}}
  252. #define CallR(func) {if ((err = (func)) < 0) {return err;}}
  253. #define CallJ( func, label ) {if ((err = (func)) < 0) goto label;}
  254. #define Error( errToReturn, label ) {err = errToReturn; goto label;}
  255. #define CallS(func) { ERR errT; Assert( (errT = (func)) == JET_errSuccess ); }
  256. #endif
  257. #else
  258. #define RFSAlloc(type) (1)
  259. #define RFSDisable() (1)
  260. #define RFSEnable() (0)
  261. #define Call(func) {if ((err = (func)) < 0) {goto HandleError;}}
  262. #define CallR(func) {if ((err = (func)) < 0) {return err;}}
  263. #define CallJ(func,label) {if ((err = (func)) < 0) {goto label;}}
  264. #define CallS(func) {ERR errT; errT = (func);}
  265. #define Error(errT,label) {err = (errT); goto label;}
  266. #endif
  267. #define NotUsed(p) (p)
  268. /***********************************************************/
  269. /***** include Jet Project prototypes and constants ********/
  270. /***********************************************************/
  271. #include "jet.h"
  272. #include "_jet.h"
  273. #include "_jetstr.h"
  274. #include "jetdef.h"
  275. #include "sesmgr.h"
  276. #include "isamapi.h"
  277. #include "vdbapi.h"
  278. #include "vtapi.h"
  279. #include "disp.h"
  280. #include "taskmgr.h"
  281. #include "vdbmgr.h"
  282. extern CODECONST(VDBFNDEF) vdbfndefIsam;
  283. #include "vtmgr.h"
  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. JET_TABLEID TableidOfVtid( FUCB *pfucb );
  290. ERR VTAPI ErrDispPrepareUpdate( JET_SESID sesid, JET_TABLEID tableid,
  291. JET_GRBIT grbit );
  292. ERR VTAPI ErrDispSetColumn( JET_SESID sesid, JET_TABLEID tableid,
  293. JET_COLUMNID columnid, const void *pb, unsigned long cb, JET_GRBIT grbit,
  294. JET_SETINFO *psetinfo );
  295. ERR VTAPI ErrDispCloseTable( JET_SESID sesid, JET_TABLEID tableid );
  296. ERR VTAPI ErrDispUpdate( JET_SESID sesid, JET_TABLEID tableid, void *pb,
  297. unsigned long cbMax, unsigned long *pcbActual );
  298. ERR VTAPI ErrDispMove( JET_SESID sesid, JET_TABLEID tableid, long crows, JET_GRBIT grbit );
  299. /***********************************************************/
  300. /******************* mutual exclusion **********************/
  301. /***********************************************************/
  302. typedef void * SEM;
  303. typedef void * SIG;
  304. typedef void * CRIT;
  305. /* enable multiple MUTEX resource
  306. /**/
  307. #ifdef WIN16
  308. #define SemDefine( s )
  309. #define ErrSemCreate( s, sz ) JET_errSuccess
  310. #define SemRequest( s ) 0
  311. #define SemRelease( s ) 0
  312. #define SemAssert( s ) 0
  313. #define ErrSignalCreate( s, sz ) JET_errSuccess
  314. #define ErrSignalCreateAutoReset( s, sz ) JET_errSuccess
  315. #define SignalReset( s ) 0
  316. #define SignalSend( s ) 0
  317. #define SignalWait( s, t ) 0
  318. #define SignalWaitEx( s, t ) 0
  319. #define MultipleSignalWait( i, rg, f, t ) 0
  320. #define SignalClose( s ) 0
  321. #define ErrInitializeCriticalSection( s ) JET_errSuccess
  322. #define EnterCriticalSection( s ) 0
  323. #define LeaveCriticalSection( s ) 0
  324. #define EnterNestableCriticalSection( s ) 0
  325. #define LeaveNestableCriticalSection( s ) 0
  326. #define AssertCriticalSection( s ) 0
  327. #define DeleteCriticalSection( s ) 0
  328. #define SgSemDefine( s )
  329. #define SgErrSemCreate( s, sz ) JET_errSuccess
  330. #define SgSemRequest( s ) 0
  331. #define SgSemRelease( s ) 0
  332. #define SgSemAssert( s ) 0
  333. #define LgSemDefine( s )
  334. #define LgErrSemCreate( s, sz ) JET_errSuccess
  335. #define LgSemRequest( s ) 0
  336. #define LgSemRelease( s ) 0
  337. #define LgSemAssert( s ) 0
  338. #define LgErrInitializeCriticalSection( s, c ) JET_errSuccess
  339. #define LgEnterCriticalSection( s ) 0
  340. #define LgLeaveCriticalSection( s ) 0
  341. #define LgEnterNestableCriticalSection( s ) 0
  342. #define LgLeaveNestableCriticalSection( s ) 0
  343. #define LgAssertCriticalSection( s ) 0
  344. #define LgDeleteCriticalSection( s ) 0
  345. #else /* !WIN16 */
  346. #ifdef SGSEM /* small grain */
  347. #define SemDefine( s ) __near SEM s
  348. #define ErrSemCreate( s, sz ) UtilSemCreate( s )
  349. #define SemRequest( s ) UtilSemRequest( s )
  350. #define SemRelease( s ) UtilSemRelease( s )
  351. #define SemAssert( s ) UtilAssertSEM( s )
  352. #define ErrSignalCreate( s, sz ) ErrUtilSignalCreate( s, sz )
  353. #define ErrSignalCreateAutoReset( s, sz ) ErrUtilSignalCreateAutoReset( s, sz )
  354. #define SignalReset( s ) UtilSignalReset( s )
  355. #define SignalSend( s ) UtilSignalSend( s )
  356. #define SignalWait( s, t ) UtilSignalWait( s, t )
  357. #define SignalWaitEx( s, t, f ) UtilSignalWaitEx( s, t, f )
  358. #define MultipleSignalWait( i, rg, f, t ) UtilMultipleSignalWait( i, rg, f, t )
  359. #define SignalClose( s ) UtilCloseSignal( s )
  360. #define ErrInitializeCriticalSection( s ) ErrUtilInitializeCriticalSection( s )
  361. #define EnterCriticalSection( s ) UtilEnterCriticalSection( s )
  362. #define LeaveCriticalSection( s ) UtilLeaveCriticalSection( s )
  363. #define EnterNestableCriticalSection( s ) UtilEnterNestableCriticalSection( s )
  364. #define LeaveNestableCriticalSection( s ) UtilLeaveNestableCriticalSection( s )
  365. #define AssertCriticalSection( s ) UtilAssertCrit( s )
  366. #define HoldCriticalSection( s ) \
  367. { \
  368. UtilAssertCrit( s ); \
  369. UtilHoldCriticalSection( s ); \
  370. }
  371. #define ReleaseCriticalSection( s )
  372. { \
  373. UtilAssertCrit( s ); \
  374. UtilReleaseCriticalSection( s );\
  375. }
  376. #define DeleteCriticalSection( s ) UtilDeleteCriticalSection( s )
  377. #define SgSemDefine( s ) __near SEM s
  378. #define SgErrSemCreate( s, sz ) UtilSemCreate( s, sz )
  379. #define SgSemRequest( s ) UtilSemRequest( s )
  380. #define SgSemRelease( s ) UtilSemRelease( s )
  381. #define SgSemAssert( s ) UtilAssertSEM( s )
  382. #define LgSemDefine( s )
  383. #define LgErrSemCreate( s, sz ) 0
  384. #define LgSemRequest( s ) 0
  385. #define LgSemRelease( s ) 0
  386. #define LgSemAssert( s ) 0
  387. #define LgErrInitializeCriticalSection( s ) JET_errSuccess
  388. #define LgEnterCriticalSection( s ) 0
  389. #define LgLeaveCriticalSection( s ) 0
  390. #define LgEnterNestableCriticalSection( s ) 0
  391. #define LgLeaveNestableCriticalSection( s ) 0
  392. #define LgAssertCriticalSection( s ) 0
  393. #define LgDeleteCriticalSection( s ) 0
  394. #else /* !SGSEM */
  395. #define SemDefine( s ) __near SEM s
  396. #define SemErrCreate( s, sz ) UtilSemCreate( s, sz )
  397. #define SemRequest( s ) UtilSemRequest( s )
  398. #define SemRelease( s ) UtilSemRelease( s )
  399. #define SemAssert( s ) UtilAssertSEM( s )
  400. #define ErrSignalCreate( s, sz ) ErrUtilSignalCreate( s, sz )
  401. #define ErrSignalCreateAutoReset( s, sz ) ErrUtilSignalCreateAutoReset( s, sz )
  402. #define SignalReset( s ) UtilSignalReset( s )
  403. #define SignalSend( s ) UtilSignalSend( s )
  404. #define SignalWait( s, t ) UtilSignalWait( s, t )
  405. #define SignalWaitEx( s, t, f ) UtilSignalWaitEx( s, t, f )
  406. #define MultipleSignalWait( i, rg, f, t ) UtilMultipleSignalWait( i, rg, f, t )
  407. #define SignalClose( s ) UtilCloseSignal( s )
  408. #define ErrInitializeCriticalSection( s ) ErrUtilInitializeCriticalSection( s )
  409. #define EnterCriticalSection( s ) UtilEnterCriticalSection( s )
  410. #define LeaveCriticalSection( s ) UtilLeaveCriticalSection( s )
  411. #define EnterNestableCriticalSection( s ) UtilEnterNestableCriticalSection( s )
  412. #define LeaveNestableCriticalSection( s ) UtilLeaveNestableCriticalSection( s )
  413. #define AssertCriticalSection( s ) UtilAssertCrit( s )
  414. #define HoldCriticalSection( s ) \
  415. { \
  416. UtilAssertCrit( s ); \
  417. UtilHoldCriticalSection( s ); \
  418. }
  419. #define ReleaseCriticalSection( s ) \
  420. { \
  421. UtilAssertCrit( s ); \
  422. UtilReleaseCriticalSection( s );\
  423. }
  424. #define DeleteCriticalSection( s ) UtilDeleteCriticalSection( s )
  425. #define SgSemDefine( s )
  426. #define SgErrSemCreate( s, sz ) 0
  427. #define SgSemRequest( s ) UtilAssertCrit( critJet )
  428. #define SgSemRelease( s ) UtilAssertCrit( critJet )
  429. #define SgSemAssert( s ) UtilAssertCrit( critJet )
  430. #define LgSemDefine( s ) __near SEM s;
  431. #define LgErrSemCreate( s, sz ) SemCreate( s, sz )
  432. #define LgSemRequest( s ) SemRequest( s )
  433. #define LgSemRelease( s ) SemRelease( s )
  434. #define LgSemAssert( s ) UtilAssertCrit( s )
  435. #define LgErrInitializeCriticalSection( s ) ErrUtilInitializeCriticalSection( s )
  436. #define LgEnterCriticalSection( s ) UtilEnterCriticalSection( s )
  437. #define LgLeaveCriticalSection( s ) UtilLeaveCriticalSection( s )
  438. #define LgEnterNestableCriticalSection( s ) UtilEnterNestableCriticalSection( s )
  439. #define LgLeaveNestableCriticalSection( s ) UtilLeaveNestableCriticalSection( s )
  440. #define LgAssertCriticalSection( s ) UtilAssertCrit( s )
  441. #define LgDeleteCriticalSection( s ) UtilDeleteCriticalSection( s )
  442. #endif /* !SGSEM */
  443. #endif /* !WIN16 */
  444. /* include other global DAE headers
  445. /**/
  446. #include "sys.h"
  447. #include "err.h"
  448. #include "daeconst.h"
  449. #define fSTInitNotDone 0
  450. #define fSTInitInProgress 1
  451. #define fSTInitDone 2
  452. extern BOOL __near fSTInit;
  453.