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.

440 lines
12 KiB

  1. #ifndef _JET_H
  2. #define _JET_H
  3. #include <string.h>
  4. #ifndef WIN32_LEAN_AND_MEAN
  5. #define WIN32_LEAN_AND_MEAN
  6. #endif
  7. #include <windows.h>
  8. #undef SPIN_LOCK /* disable SPIN_LOCK even if defined in config.h */
  9. //#define MEM_CHECK /* check for memory leakage */
  10. //#define COSTLY_PERF /* enable costly performance counters */
  11. #define handleNil ((HANDLE)(-1))
  12. #define EXPORT /* Called from assembly code */
  13. #define VARARG _cdecl /* Variable number of arguments */
  14. #ifndef UNALIGNED
  15. #if defined(_MIPS_) || defined(_ALPHA_) || defined(_M_PPC)
  16. #define UNALIGNED __unaligned
  17. #else
  18. #define UNALIGNED
  19. #endif
  20. #endif
  21. #define PUBLIC extern
  22. #define STATIC static
  23. #ifdef DEBUG
  24. #define INLINE
  25. #else
  26. #define INLINE __inline
  27. #endif
  28. #define CODECONST(type) type const
  29. typedef unsigned __int64 QWORD;
  30. typedef union _QWORDX
  31. {
  32. QWORD qw;
  33. struct
  34. {
  35. DWORD l;
  36. DWORD h;
  37. };
  38. } QWORDX;
  39. #define fFalse 0
  40. #define fTrue (!0)
  41. typedef int ERR;
  42. typedef double DATESERIAL;
  43. typedef ULONG OBJID;
  44. typedef unsigned short OBJTYP;
  45. typedef unsigned short COLTYP;
  46. typedef int BOOL;
  47. typedef int (*PFN)();
  48. typedef struct
  49. {
  50. int month;
  51. int day;
  52. int year;
  53. int hour;
  54. int minute;
  55. int second;
  56. } _JET_DATETIME;
  57. /* cbFilenameMost includes the trailing null terminator */
  58. #define cbFilenameMost 260 /* Windows NT limit */
  59. /*** Global system initialization variables ***/
  60. extern BOOL fJetInitialized;
  61. extern BOOL fBackupAllowed;
  62. extern BOOL fTermInProgress;
  63. extern int cSessionInJetAPI;
  64. extern BOOL fGlobalRepair; /* if this is for repair or not */
  65. extern BOOL fGlobalSimulatedRestore;
  66. /* Engine OBJIDs:
  67. 0..0x10000000 reserved for engine use, divided as follows:
  68. 0x00000000..0x0000FFFF reserved for TBLIDs under RED
  69. 0x00000000..0x0EFFFFFF reserved for TBLIDs under BLUE
  70. 0x0F000000..0x0FFFFFFF reserved for container IDs
  71. 0x10000000 reserved for ObjectId of DbObject
  72. Client OBJIDs begin at 0x10000001 and go up from there.
  73. */
  74. #define objidNil ((OBJID) 0x00000000)
  75. #define objidRoot ((OBJID) 0x0F000000)
  76. #define objidTblContainer ((OBJID) 0x0F000001)
  77. #define objidDbContainer ((OBJID) 0x0F000002)
  78. #define objidDbObject ((OBJID) 0x10000000)
  79. /* Start of RELEASE vs DEBUG build definitions */
  80. #define DISPATCHING 1
  81. #ifdef DEBUG
  82. #define PARAMFILL 1
  83. #define RFS2 1
  84. #endif
  85. #ifdef RETAIL
  86. #ifdef RFS2
  87. #define DeclAssertFile static CODECONST(char) szAssertFilename[] = __FILE__
  88. #else
  89. #define DeclAssertFile
  90. #endif
  91. #define Assert(exp) ((void)1)
  92. #define ExpAssert(exp) ((void)1)
  93. #define AssertSz(exp, sz) ((void)1)
  94. #define AssertConst(exp) ((void)1)
  95. #define AssertEq(exp, exp2) (exp)
  96. #define AssertGe(exp, exp2) (exp)
  97. #define AssertNe(exp, exp2) (exp)
  98. #define MarkTableidExported(err,tableid)
  99. #define CheckTableidExported(tableid)
  100. #define AssertValidSesid(sesid) ((void) 1)
  101. #define DebugLogJetOp( sesid, op ) 0
  102. #else /* !RETAIL */
  103. #define DeclAssertFile static CODECONST(char) szAssertFilename[] = __FILE__
  104. #define AssertSz(exp, sz) { \
  105. static CODECONST(char) szMsg[] = sz; \
  106. (exp) ? (void) 0 : AssertFail( szMsg, szAssertFilename, __LINE__ ); \
  107. }
  108. #define Assert( exp ) \
  109. ( (exp) ? (void) 0 : AssertFail( #exp, szAssertFilename, __LINE__) )
  110. #define ExpAssert(exp) Assert(exp)
  111. #define AssertConst(exp) Assert(*szAssertFilename != '\0' && (exp))
  112. #define AssertEq(exp, exp2) Assert((exp) == (exp2))
  113. #define AssertGe(exp, exp2) Assert((exp) >= (exp2))
  114. #define AssertNe(exp, exp2) Assert((exp) != (exp2))
  115. #define AssertValidSesid(sesid) AssertValidSesid(sesid)
  116. BOOL FTableidExported(JET_TABLEID tableid);
  117. void MarkTableidExportedR(JET_TABLEID tableid);
  118. #define MarkTableidExported(err,tableid) \
  119. if (err >= 0) \
  120. MarkTableidExportedR(tableid)
  121. #define CheckTableidExported(tableid) \
  122. if (!FTableidExported(tableid)) \
  123. APIReturn(JET_errInvalidTableId)
  124. void DebugLogJetOp( JET_SESID sesid, int op );
  125. #endif /* !RETAIL */
  126. /* End of RELEASE vs DEBUG build definitions */
  127. #ifdef PARAMFILL
  128. #define FillClientBuffer( pv, cb ) ( (pv) ? memset( (pv), 0x52, (cb) ) : 0 )
  129. #else
  130. #define FillClientBuffer( pv, cb ) ( (void)1 )
  131. #endif
  132. /* apirare.c */
  133. PUBLIC ERR ErrOpenDatabase(JET_SESID sesid, const char *szDatabase,
  134. const char *szConnect, JET_DBID *pdbid, JET_GRBIT grbit);
  135. JET_ERR JET_API ErrGetSystemParameter(JET_SESID sesid, unsigned long paramid,
  136. ULONG_PTR *plParam, char *sz, unsigned long cbMax);
  137. JET_ERR JET_API ErrSetSystemParameter(JET_SESID sesid, unsigned long paramid,
  138. ULONG_PTR lParam, const char *sz);
  139. /* initterm.c */
  140. extern void * critJet;
  141. JET_ERR JET_API ErrInit(BOOL fSkipIsamInit);
  142. #ifdef RFS2
  143. extern unsigned long fLogJETCall;
  144. extern unsigned long fLogRFS;
  145. extern unsigned long cRFSAlloc;
  146. extern unsigned long cRFSIO;
  147. extern unsigned long fDisableRFS;
  148. extern unsigned long fAuxDisableRFS;
  149. #endif /* RFS2 */
  150. #ifndef RETAIL
  151. extern unsigned EXPORT wAssertAction;
  152. extern unsigned EXPORT fAssertActionSet;
  153. #endif /* !RETAIL */
  154. /* util.c */
  155. ERR ErrUTILCheckName( char *szNewName, const char *szName, int cchName );
  156. #ifndef RETAIL
  157. PUBLIC void EXPORT AssertFail( const char *szExpr, const char *szFilename, unsigned Line );
  158. PUBLIC void VARARG DebugPrintf(const char *szFmt, ...);
  159. #endif /* !RETAIL */
  160. #define opIdle 1
  161. #define opGetTableIndexInfo 2
  162. #define opGetIndexInfo 3
  163. #define opGetObjectInfo 4
  164. #define opGetTableInfo 5
  165. #define opCreateObject 6
  166. #define opDeleteObject 7
  167. #define opRenameObject 8
  168. #define opBeginTransaction 9
  169. #define opCommitTransaction 10
  170. #define opRollback 11
  171. #define opOpenTable 12
  172. #define opDupCursor 13
  173. #define opCloseTable 14
  174. #define opGetTableColumnInfo 15
  175. #define opGetColumnInfo 16
  176. #define opRetrieveColumn 17
  177. #define opRetrieveColumns 18
  178. #define opSetColumn 19
  179. #define opSetColumns 20
  180. #define opPrepareUpdate 21
  181. #define opUpdate 22
  182. #define opDelete 23
  183. #define opGetCursorInfo 24
  184. #define opGetCurrentIndex 25
  185. #define opSetCurrentIndex 26
  186. #define opMove 27
  187. #define opMakeKey 28
  188. #define opSeek 29
  189. #define opGetBookmark 30
  190. #define opGotoBookmark 31
  191. #define opGetRecordPosition 32
  192. #define opGotoPosition 33
  193. #define opRetrieveKey 34
  194. #define opCreateDatabase 35
  195. #define opOpenDatabase 36
  196. #define opGetDatabaseInfo 37
  197. #define opCloseDatabase 38
  198. #define opCapability 39
  199. #define opCreateTable 40
  200. #define opRenameTable 41
  201. #define opDeleteTable 42
  202. #define opAddColumn 43
  203. #define opRenameColumn 44
  204. #define opDeleteColumn 45
  205. #define opCreateIndex 46
  206. #define opRenameIndex 47
  207. #define opDeleteIndex 48
  208. #define opComputeStats 49
  209. #define opAttachDatabase 50
  210. #define opDetachDatabase 51
  211. #define opOpenTempTable 52
  212. #define opSetIndexRange 53
  213. #define opIndexRecordCount 54
  214. #define opGetChecksum 55
  215. #define opGetObjidFromName 56
  216. #define opMax 57
  217. extern long lAPICallLogLevel;
  218. /* RFS macros */
  219. #ifdef RFS2
  220. /* RFS/JET call logging
  221. /*
  222. /* RFS allocator: returns 0 if allocation is disallowed. Also handles RFS logging.
  223. /* cRFSAlloc is the global allocation counter. A value of -1 disables RFS in debug mode.
  224. /**/
  225. #define RFSAlloc(type) ( UtilRFSAlloc( #type ,type ) )
  226. /* RFS allocation types
  227. /*
  228. /* Type 0: general allocation
  229. /* 1: IO
  230. /**/
  231. #define CSRAllocResource 0
  232. #define FCBAllocResource 0
  233. #define FUCBAllocResource 0
  234. #define IDBAllocResource 0
  235. #define PIBAllocResource 0
  236. #define SCBAllocResource 0
  237. #define VERAllocResource 0
  238. #define DABAllocResource 0
  239. #define UnknownAllocResource 0
  240. #define SAllocMemory 0
  241. #define LAllocMemory 0
  242. #define PvUtilAllocMemory 0
  243. #define IOOpenReadFile 1
  244. #define IOOpenFile 1
  245. #define IODeleteFile 1
  246. #define IONewFileSize 1
  247. #define IOReadBlock 1
  248. #define IOWriteBlock 1
  249. #define IOReadBlockOverlapped 1
  250. #define IOWriteBlockOverlapped 1
  251. #define IOReadBlockEx 1
  252. #define IOWriteBlockEx 1
  253. #define IOMoveFile 1
  254. #define IOCopyFile 1
  255. /* RFS disable/enable macros */
  256. #define RFSDisable() (fAuxDisableRFS = 1)
  257. #define RFSEnable() (fAuxDisableRFS = 0)
  258. /* JET call logging (log on failure)
  259. /**/
  260. // Do not print out function name because it takes too much string resource
  261. //#define LogJETCall(func,err) (UtilRFSLogJETCall(#func,err,szAssertFilename,__LINE__))
  262. #define LogJETCall(func,err) (UtilRFSLogJETCall("",err,szAssertFilename,__LINE__))
  263. /* JET call macros
  264. /**/
  265. #define Call(func) {LogJETCall(func,err = (func)); if (err < 0) {goto HandleError;}}
  266. #define CallR(func) {LogJETCall(func,err = (func)); if (err < 0) {return err;}}
  267. #define CallJ(func,label) {LogJETCall(func,err = (func)); if (err < 0) {goto label;}}
  268. #define CallS(func) {ERR errT; LogJETCall(func,errT = (func)); Assert(errT == JET_errSuccess);}
  269. /* JET inline error logging (logging controlled by JET call flags)
  270. /**/
  271. #define LogJETErr(err,label) (UtilRFSLogJETErr(err,#label,szAssertFilename,__LINE__))
  272. /* JET inline error macros
  273. /**/
  274. #define Error(errRet,label) {LogJETErr(errRet,label); err = (errRet); goto label;}
  275. #else // !RFS2
  276. #define RFSAlloc(type) (1)
  277. #define RFSDisable() (1)
  278. #define RFSEnable() (0)
  279. #define Call(func) {if ((err = (func)) < 0) {goto HandleError;}}
  280. #define CallR(func) {if ((err = (func)) < 0) {return err;}}
  281. #define CallJ( func, label ) {if ((err = (func)) < 0) goto label;}
  282. #define Error( errRet, label ) {err = errRet; goto label;}
  283. #ifdef DEBUG
  284. #define CallS(func) { ERR errT; Assert( (errT = (func)) == JET_errSuccess ); }
  285. #else // !DEBUG
  286. #define CallS(func) {ERR errT; errT = (func);}
  287. #endif // DEBUG
  288. #endif // RFS2
  289. /* API Enter/Leave macros assuming that critJet has been initialized */
  290. #define APIEnter() { \
  291. if ( fTermInProgress ) return JET_errTermInProgress; \
  292. if ( !fJetInitialized ) return JET_errNotInitialized; \
  293. Assert(critJet != NULL); \
  294. UtilEnterCriticalSection(critJet); \
  295. Assert( cSessionInJetAPI >= 0 ); \
  296. cSessionInJetAPI++; }
  297. #define APIReturn(err) { \
  298. ERR errT = (err); \
  299. Assert(critJet != NULL); \
  300. Assert( cSessionInJetAPI >= 1 ); \
  301. cSessionInJetAPI--; \
  302. Assert( cSessionInJetAPI >= 0 ); \
  303. UtilLeaveCriticalSection(critJet); \
  304. return errT; }
  305. /* APIInitEnter inits critJet (if necessary) on an initializing API call */
  306. #define APIInitEnter() { \
  307. if ( fTermInProgress ) return JET_errTermInProgress; \
  308. if ( critJet == NULL ) \
  309. { \
  310. ERR errT = \
  311. ErrUtilInitializeCriticalSection( &critJet ); \
  312. if ( errT < 0 ) \
  313. return errT; \
  314. Assert( cSessionInJetAPI == 0 ); \
  315. } \
  316. UtilEnterCriticalSection( critJet ); \
  317. Assert( cSessionInJetAPI >= 0 ); \
  318. cSessionInJetAPI++; }
  319. /* APITermReturn frees critJet on return from a terminating API call */
  320. #define APITermReturn(err) { \
  321. ERR errT = (err); \
  322. Assert( critJet != NULL ); \
  323. Assert( cSessionInJetAPI == 1 ); \
  324. cSessionInJetAPI = 0; \
  325. UtilLeaveCriticalSection( critJet ); \
  326. UtilDeleteCriticalSection( critJet ); \
  327. critJet = NULL; \
  328. return errT; }
  329. #define APIForceTermReturn( err ) { \
  330. ERR errT = (err); \
  331. Assert( critJet != NULL ); \
  332. cSessionInJetAPI = 0; \
  333. UtilLeaveCriticalSection( critJet ); \
  334. UtilDeleteCriticalSection( critJet ); \
  335. critJet = NULL; \
  336. return errT; }
  337. #include "isam.h"
  338. #endif /* !_JET_H */