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.

261 lines
9.7 KiB

  1. //============== DAE: OS/2 Database Access Engine ===================
  2. //============== fcb.h: File Control Block ===================
  3. #ifdef FCB_INCLUDED
  4. #error fcb.h already included
  5. #endif /* FCB_INCLUDED */
  6. #define FCB_INCLUDED
  7. // Database Key
  8. typedef ULONG DBK;
  9. // Flags for FCB
  10. #define fFCBTemporaryTable (1<<0) // This is a temporary file
  11. #define fFCBClusteredIndex (1<<1) // This FCB is for data records.
  12. #define fFCBDenyRead (1<<2) // no other session can read domain
  13. // #define fFCBDenyWrite (1<<3) // no other session can write domain
  14. #define fFCBSentinel (1<<4) // FCB is only flag holder
  15. // #define fFCBDenyDDL (1<<5) // no other transaction can update/delete/replace domain
  16. #define fFCBWait (1<<6) // wait flag
  17. #define fFCBOLCStatsAvail (1<<7) // are OLC Stats available?
  18. #define fFCBOLCStatsChange (1<<8) // have OLC Stats changed since last open?
  19. #define fFCBDeletePending (1<<9) // is a delete pending on this table/index?
  20. #define fFCBDomainOperation (1<<10) // is used to synchronize bm cleanup
  21. // index creation, index deletion and table deletion
  22. #define FFCBDomainOperation( pfcb ) ( (pfcb)->wFlags & fFCBDomainOperation )
  23. #define FCBSetDomainOperation( pfcb ) ( (pfcb)->wFlags |= fFCBDomainOperation )
  24. #define FCBResetDomainOperation( pfcb ) ( (pfcb)->wFlags &= ~(fFCBDomainOperation) )
  25. #define FFCBDeletePending( pfcb ) ( (pfcb)->wFlags & fFCBDeletePending )
  26. #define FCBSetDeletePending( pfcb ) ( (pfcb)->wFlags |= fFCBDeletePending )
  27. #define FCBResetDeletePending( pfcb ) ( (pfcb)->wFlags &= ~(fFCBDeletePending) )
  28. #define FFCBOLCStatsAvail( pfcb ) ( (pfcb)->wFlags & fFCBOLCStatsAvail )
  29. #define FCBSetOLCStatsAvail( pfcb ) ( (pfcb)->wFlags |= fFCBOLCStatsAvail )
  30. #define FCBResetOLCStatsAvail( pfcb ) ( (pfcb)->wFlags &= ~(fFCBOLCStatsAvail) )
  31. #define FFCBOLCStatsChange( pfcb ) ( (pfcb)->wFlags & fFCBOLCStatsChange )
  32. #define FCBSetOLCStatsChange( pfcb ) ( (pfcb)->wFlags |= fFCBOLCStatsChange )
  33. #define FCBResetOLCStatsChange( pfcb ) ( (pfcb)->wFlags &= ~(fFCBOLCStatsChange) )
  34. #define FFCBTemporaryTable( pfcb ) ( (pfcb)->wFlags & fFCBTemporaryTable )
  35. #define FCBSetTemporaryTable( pfcb ) ( (pfcb)->wFlags |= fFCBTemporaryTable )
  36. #define FCBResetTemporaryTable( pfcb ) ( (pfcb)->wFlags &= ~(fFCBTemporaryTable) )
  37. #define FFCBClusteredIndex( pfcb ) ( (pfcb)->wFlags & fFCBClusteredIndex )
  38. #define FCBSetClusteredIndex( pfcb ) ( (pfcb)->wFlags |= fFCBClusteredIndex )
  39. #define FCBResetClusteredIndex( pfcb ) ( (pfcb)->wFlags &= ~(fFCBClusteredIndex) )
  40. #define FFCBDenyWrite( pfcb ) ( (pfcb)->crefDenyWrite > 0 )
  41. #define FCBSetDenyWrite( pfcb ) ( (pfcb)->crefDenyWrite++ )
  42. #define FCBResetDenyWrite( pfcb ) \
  43. { \
  44. Assert( (pfcb)->crefDenyWrite > 0 ); \
  45. --(pfcb)->crefDenyWrite; \
  46. }
  47. #define FFCBDenyRead( pfcb, ppib ) ( (pfcb)->wFlags & fFCBDenyRead && (ppib) != (pfcb)->ppibDenyRead )
  48. #define FCBSetDenyRead( pfcb, ppib ) \
  49. { \
  50. if ( (pfcb)->crefDenyRead++ == 0 ) \
  51. { \
  52. Assert( (pfcb)->ppibDenyRead == ppibNil ); \
  53. (pfcb)->ppibDenyRead = (ppib); \
  54. (pfcb)->wFlags |= fFCBDenyRead; \
  55. } \
  56. }
  57. #define FCBResetDenyRead( pfcb ) \
  58. { \
  59. Assert( (pfcb)->crefDenyRead > 0 ); \
  60. Assert( (pfcb)->ppibDenyRead != ppibNil ); \
  61. if ( --(pfcb)->crefDenyRead == 0 ) \
  62. { \
  63. (pfcb)->wFlags &= ~(fFCBDenyRead); \
  64. (pfcb)->ppibDenyRead = ppibNil; \
  65. } \
  66. }
  67. #define FFCBDenyReadByUs( pfcb, ppib ) ( (pfcb)->wFlags & fFCBDenyRead && (ppib) == (pfcb)->ppibDenyRead )
  68. #define FFCBSentinel( pfcb ) ( (pfcb)->wFlags & fFCBSentinel )
  69. #define FCBSetSentinel( pfcb ) ( (pfcb)->wFlags |= fFCBSentinel )
  70. #define FCBResetSentinel( pfcb ) ( (pfcb)->wFlags &= ~(fFCBSentinel) )
  71. #define FFCBDenyDDL( pfcb, ppib ) ( (pfcb)->crefDenyDDL > 0 && (ppib) != (pfcb)->ppibDDL )
  72. #define FFCBDenyDDLByUs( pfcb, ppib ) ( (pfcb)->crefDenyDDL > 0 && (ppib) == (pfcb)->ppibDDL )
  73. #define FCBSetDenyDDL( pfcb, ppib ) \
  74. { \
  75. if ( (pfcb)->crefDenyDDL++ == 0 ) \
  76. { \
  77. Assert( (pfcb)->ppibDDL == ppibNil ); \
  78. (pfcb)->ppibDDL = (ppib); \
  79. } \
  80. }
  81. #define FCBResetDenyDDL( pfcb ) \
  82. { \
  83. Assert( (pfcb)->crefDenyDDL > 0 ); \
  84. Assert( (pfcb)->ppibDDL != ppibNil ); \
  85. if ( --(pfcb)->crefDenyDDL == 0 ) \
  86. { \
  87. (pfcb)->ppibDDL = ppibNil; \
  88. } \
  89. }
  90. #define FFCBWait( pfcb ) ( (pfcb)->wFlags & fFCBWait )
  91. #define FCBSetWait( pfcb ) \
  92. { \
  93. Assert( !FFCBWait( pfcb ) ); \
  94. (pfcb)->wFlags |= fFCBWait; \
  95. }
  96. #define FCBResetWait( pfcb ) \
  97. { \
  98. Assert( FFCBWait( pfcb ) ); \
  99. (pfcb)->wFlags &= ~(fFCBWait); \
  100. }
  101. #define FCBVersionIncrement( pfcb ) (pfcb)->cVersion++;
  102. #define FCBVersionDecrement( pfcb ) \
  103. { \
  104. Assert( (pfcb)->cVersion > 0 ); \
  105. (pfcb)->cVersion--; \
  106. }
  107. #define CVersionFCB( pfcb ) (pfcb)->cVersion
  108. /* hash table for FCB's -- only FCB's for tables and db's are hashed
  109. /**/
  110. #define cFCBBuckets 256
  111. FCB* pfcbHash[cFCBBuckets];
  112. #define FCBHashInit() \
  113. { \
  114. Assert( pfcbNil == (FCB *) 0 ); \
  115. memset( pfcbHash, '\0', sizeof( pfcbHash ) ); \
  116. }
  117. #define FFCBAvail( pfcb, ppib ) \
  118. ( pfcb->wRefCnt == 0 && \
  119. pfcb->pgnoFDP != 1 && \
  120. !FFCBSentinel( pfcb ) && \
  121. !FFCBDenyRead( pfcb, ppib ) && \
  122. !FFCBWait( pfcb ) && \
  123. ( pfcb->dbid == dbidTemp || FFCBINoVersion( pfcb ) ) )
  124. // File Control Block
  125. //
  126. struct _fcb
  127. {
  128. //--------------------USED BY DATA & INDEX FCB---------------------
  129. struct _fcb *pfcbNextIndex; // chain of indexes for this file
  130. struct _fcb *pfcbNextInHashBucket;
  131. struct _fdb volatile *pfdb; // field descriptors
  132. struct _idb *pidb; // index info (NULL if "seq." file)
  133. FUCB *pfucb; // chain of FUCBs open on this file
  134. PIB *ppibDDL; // ppib of process updating index/adding column
  135. PIB *ppibDenyRead; // ppib of process holding exclusive lock
  136. CRIT critSplit; // per domain split MUTEX
  137. PGNO pgnoFDP; // FDP of this file/index
  138. PGNO pgnoRoot; // pgno of the root of the domain
  139. SRID bmRoot; // bm of root of the domain
  140. // -- useful if Root is movable, e.g, DATA
  141. DBID dbid; // which database
  142. INT itagRoot; // itag of the root of the domain
  143. INT cbDensityFree; // loading density parameter:
  144. // # of bytes free w/o using new page
  145. INT wFlags; // flags for this FCB
  146. INT wRefCnt; // # of FUCBs for this file/index
  147. INT volatile cVersion; // # of RCEs for this file/index
  148. INT crefDenyRead; // # of FUCBs with deny read flag
  149. INT crefDenyWrite; // # of FUCBs with deny write flag
  150. INT crefDenyDDL; // # of FUCBs with deny DDL flag
  151. ULONG cpgCompactFreed;
  152. PERS_OLCSTAT olcStat;
  153. //--------------------USED ONLY BY FCB OF DATA---------------------
  154. CHAR *szFileName; // name of file (for GetTableInfo)
  155. struct _fcb *pfcbNext; // Next data FCB in global list
  156. DBK dbkMost; // Greatest DBK in use
  157. // (if "sequential" file)
  158. ULONG ulLongIdMax; // max long field id
  159. BYTE rgbitAllIndex[32]; // used for clustered index FCB only
  160. BOOL fAllIndexTagged; // used for clustered index FCB only
  161. };
  162. #define FCBInit( pfcb ) \
  163. { \
  164. memset( pfcb, '\0', sizeof( FCB ) ); \
  165. }
  166. #define PfcbMEMAlloc() (FCB*)PbMEMAlloc(iresFCB)
  167. #ifdef DEBUG /* Debug check for illegal use of freed fcb */
  168. #define MEMReleasePfcb(pfcb) \
  169. { \
  170. Assert( PfcbFCBGet( pfcb->dbid, pfcb->pgnoFDP ) != pfcb ); \
  171. MEMRelease( iresFCB, (BYTE*)(pfcb) ); \
  172. pfcb = pfcbNil; \
  173. }
  174. #else
  175. #define MEMReleasePfcb(pfcb) \
  176. { \
  177. Assert( PfcbFCBGet( pfcb->dbid, pfcb->pgnoFDP ) != pfcb ); \
  178. MEMRelease( iresFCB, (BYTE*)(pfcb) ); \
  179. }
  180. #endif
  181. /* if opening domain for read, write or read write, and not with
  182. /* deny read or deny write, and domain does not have deny read or
  183. /* deny write set, then return JET_errSuccess, else call
  184. /* ErrFCBISetMode to determine if lock is by other session or to
  185. /* put lock on domain.
  186. /**/
  187. #define ErrFCBSetMode( ppib, pfcb, grbit ) \
  188. ( ( ( ( grbit & ( JET_bitTableDenyRead | JET_bitTableDenyWrite ) ) == 0 ) && \
  189. ( ( FFCBDenyDDL( pfcb, ppib ) || FFCBDenyRead( pfcb, ppib ) || FFCBDenyWrite( pfcb ) ) == fFalse ) ) ? \
  190. JET_errSuccess : ErrFCBISetMode( ppib, pfcb, grbit ) )
  191. /* reset DDL is same as reset Delete. Both use deny read flags
  192. /* or sentinel.
  193. /**/
  194. #define FCBResetRenameTable FCBResetDeleteTable
  195. extern BYTE * __near rgfcb;
  196. extern FCB * __near pfcbGlobalList;
  197. extern SEM __near semGlobalFCBList;
  198. extern SEM __near semLinkUnlink;
  199. VOID FCBLink( FUCB *pfucb, FCB *pfcb );
  200. VOID FCBRegister( FCB *pfcb );
  201. VOID FCBDiscard( FCB *pfcb );
  202. VOID FCBUnlink( FUCB *pfucb );
  203. FCB *PfcbFCBGet( DBID dbid, PGNO pgnoFDP );
  204. ERR ErrFCBAlloc( PIB *ppib, FCB **ppfcb );
  205. VOID FCBPurgeDatabase( DBID dbid );
  206. VOID FCBPurgeTable( DBID dbid, PGNO pgnoFDP );
  207. ERR ErrFCBNew( PIB *ppib, DBID dbid, PGNO pgno, FCB **ppfcb );
  208. ERR ErrFCBISetMode( PIB *ppib, FCB *pfcb, JET_GRBIT grbit );
  209. VOID FCBResetMode( PIB *ppib, FCB *pfcb, JET_GRBIT grbit );
  210. ERR ErrFCBSetDeleteTable( PIB *ppib, DBID dbid, PGNO pgnoFDP );
  211. VOID FCBResetDeleteTable( DBID dbid, PGNO pgnoFDP );
  212. ERR ErrFCBSetRenameTable( PIB *ppib, DBID dbid, PGNO pgno );
  213. FCB *FCBResetAfterRedo( void );
  214. BOOL FFCBTableOpen ( DBID dbid, PGNO pgno );
  215. VOID FCBLinkIndex( FCB *pfcbTable, FCB *pfcbIndex );
  216. VOID FCBUnlinkIndex( FCB *pfcbTable, FCB *pfcbIndex );
  217. BOOL FFCBUnlinkIndexIfFound( FCB *pfcbTable, FCB *pfcbIndex );
  218. FCB *PfcbFCBUnlinkIndexByName( FCB *pfcb, CHAR *szIndex );
  219. ERR ErrFCBSetDeleteIndex( PIB *ppib, FCB *pfcbTable, CHAR *szIndex );
  220. VOID FCBResetDeleteIndex( FCB *pfcbIndex );