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.

235 lines
10 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. jet.h
  5. Abstract:
  6. Some macros for use with Frs Jet Table routines.
  7. Author:
  8. David Orbits (davidor) - 7-Mar-1997
  9. Revision History:
  10. --*/
  11. #include <esent.h>
  12. #include <dns.h>
  13. #include <md5.h>
  14. #include "schema.h"
  15. #define CONSTANT_UNICODE_STRING(s) { sizeof( s ) - sizeof( WCHAR ), sizeof( s ), s }
  16. #define OFFSET(type, field) ((LONG)((ULONG_PTR)&((type *)0)->field))
  17. #define SIZEOF(type, field) ((LONG)(sizeof(((type *)0)->field)))
  18. #define RECORD_FIELD(type, field, _dt) ((LONG)((ULONG_PTR)&((type *)0)->field)) , \
  19. (USHORT)(_dt) , \
  20. ((LONG)(sizeof(((type *)0)->field)))
  21. #define JET_COLUMN_ID_NIL 0xFFFFFFFF
  22. //
  23. // DbsRecordOperation options and special cases.
  24. //
  25. #define ROP_SEEK 0x00000000
  26. #define ROP_READ 0x00000001
  27. #define ROP_DELETE 0x00000002
  28. #define DbsSeekRecord(_threadctx, _key, _index, _tablectx) \
  29. ( DbsRecordOperation(_threadctx, ROP_SEEK, _key, _index, _tablectx) )
  30. #define DbsReadRecord(_threadctx, _key, _index, _tablectx) \
  31. ( DbsRecordOperation(_threadctx, ROP_READ, _key, _index, _tablectx) )
  32. #define DbsDeleteRecord(_threadctx, _key, _index, _tablectx) \
  33. ( DbsRecordOperation(_threadctx, ROP_DELETE, _key, _index, _tablectx) )
  34. //
  35. // This macro closes a table and resets the TableCtx Tid and Sessid to Nil.
  36. // It first checks for a mismatch between the current session ID and the ID
  37. // in the TableCtx struct.
  38. //
  39. #define DbsCloseTable(_jerr, _Sesid, _TableCtx) \
  40. \
  41. if ((_TableCtx->Tid != JET_tableidNil) && \
  42. IS_REPLICA_TABLE(_TableCtx->TableType)) { \
  43. DPRINT4(5,"DbsCloseTable (%s%05d) Tid, Sesid = %08x, %08x\n", \
  44. _TableCtx->pJetTableCreate->szTableName, \
  45. _TableCtx->ReplicaNumber, \
  46. _TableCtx->Tid, \
  47. _Sesid); \
  48. \
  49. if (_Sesid != _TableCtx->Sesid) { \
  50. DPRINT4(0, "++ DbsCloseTable (%s%05d) bad sesid : %d should be %d\n", \
  51. _TableCtx->pJetTableCreate->szTableName, \
  52. _TableCtx->ReplicaNumber, \
  53. _Sesid, \
  54. _TableCtx->Sesid); \
  55. _jerr = JET_errInvalidSesid; \
  56. } else { \
  57. _jerr = JetCloseTable(_Sesid, _TableCtx->Tid); \
  58. _TableCtx->Tid = JET_tableidNil; \
  59. _TableCtx->Sesid = JET_sesidNil; \
  60. } \
  61. } else { \
  62. DPRINT4(5,"ERROR - DbsCloseTable -- Table Already Closed or invalid tablectx." \
  63. " TableType (%d) ReplicaNum (%d) Tid (%08x) Sesid (%08x)\n", \
  64. _TableCtx->TableType, \
  65. _TableCtx->ReplicaNumber, \
  66. _TableCtx->Tid, \
  67. _Sesid); \
  68. _jerr = JET_errSuccess; \
  69. }
  70. #define DBS_OPEN_TABLE(_ThreadCtx, _TableCtx, _ReplicaNumber, _TableName, _Tid) \
  71. (FrsOpenTableSaveTid = (_TableCtx)->Tid , \
  72. DbsOpenTable0((_ThreadCtx), (_TableCtx), (_ReplicaNumber), (_TableName), (_Tid))); \
  73. \
  74. if (FrsOpenTableSaveTid == JET_tableidNil) { \
  75. DPRINT3(3,"FrsOpenTable (%20s) Tid, Sesid = %08x, %08x\n", \
  76. _TableName, \
  77. _TableCtx->Tid, \
  78. _TableCtx->Sesid); \
  79. }
  80. //
  81. // Macros to reference fields in the Jet Ret/Set Column structs via a TableCtx.
  82. //
  83. #define FRS_GET_RFIELD_LENGTH_ACTUAL(_TableCtx, _Field) (_TableCtx->pJetRetCol[_Field].cbActual)
  84. #define FRS_GET_RFIELD_LENGTH_LIMIT( _TableCtx, _Field) (_TableCtx->pJetRetCol[_Field].cbData)
  85. #define FRS_GET_RFIELD_ERROR( _TableCtx, _Field) (_TableCtx->pJetRetCol[_Field].err)
  86. #define FRS_GET_RFIELD_ADDRESS( _TableCtx, _Field) (_TableCtx->pJetRetCol[_Field].pvData)
  87. #define FRS_GET_RFIELD_COLUMNID( _TableCtx, _Field) (_TableCtx->pJetRetCol[_Field].columnid)
  88. #define FRS_GET_SFIELD_LENGTH_ACTUAL(_TableCtx, _Field) (_TableCtx->pJetSetCol[_Field].cbData)
  89. #define FRS_GET_SFIELD_LENGTH_LIMIT( _TableCtx, _Field) (_TableCtx->pJetSetCol[_Field].cbData)
  90. #define FRS_GET_SFIELD_ERROR( _TableCtx, _Field) (_TableCtx->pJetSetCol[_Field].err)
  91. #define FRS_GET_SFIELD_ADDRESS( _TableCtx, _Field) (_TableCtx->pJetSetCol[_Field].pvData)
  92. #define FRS_GET_SFIELD_COLUMNID( _TableCtx, _Field) (_TableCtx->pJetSetCol[_Field].columnid)
  93. #if DBG
  94. #define DBS_DISPLAY_RECORD_SEV(_Severity, _TableCtx, _Read) \
  95. DbsDisplayRecord(_Severity, _TableCtx, _Read, DEBSUB, __LINE__, NULL, 0);
  96. #define DBS_DISPLAY_RECORD_SEV_COLS(_Severity, _TableCtx, _Read, _Cols, _NumCols) \
  97. DbsDisplayRecord(_Severity, _TableCtx, _Read, DEBSUB, __LINE__, _Cols, _NumCols);
  98. #define FRS_DISPLAY_RECORD(_TableCtx, _Read) \
  99. DbsDisplayRecord(0, _TableCtx, _Read, DEBSUB, __LINE__, NULL, 0);
  100. #else DBG
  101. #define DBS_DISPLAY_RECORD_SEV(_Severity, _TableCtx, _Read)
  102. #define DBS_DISPLAY_RECORD_SEV_COLS(_Severity, _TableCtx, _Read, _Cols, _NumCols)
  103. #define FRS_DISPLAY_RECORD(_TableCtx, _Read)
  104. #endif DBG
  105. #define JET_SUCCESS(_Status) ((_Status) == JET_errSuccess)
  106. //
  107. // Debug macro for table ctx struct.
  108. //
  109. #define DUMP_TABLE_CTX(_TableCtx) \
  110. DPRINT2(5,"++ TableCtx: %s, pTableCtx %08x\n", _TableCtx->pJetTableCreate->szTableName, _TableCtx); \
  111. DPRINT1(5,"++ Sesid = %8d\n", _TableCtx->Sesid); \
  112. DPRINT1(5,"++ Tid = %8d\n", _TableCtx->Tid); \
  113. DPRINT1(5,"++ ReplicaNumber = %8d\n", _TableCtx->ReplicaNumber); \
  114. DPRINT1(5,"++ TableType = %8d\n", _TableCtx->TableType); \
  115. DPRINT1(5,"++ PropertyFlags = %08x\n", _TableCtx->PropertyFlags); \
  116. DPRINT1(5,"++ pJetTableCreate = %08x\n", _TableCtx->pJetTableCreate); \
  117. DPRINT1(5,"++ pRecordFields = %08x\n", _TableCtx->pRecordFields); \
  118. DPRINT1(5,"++ pJetSetCol = %08x\n", _TableCtx->pJetSetCol); \
  119. DPRINT1(5,"++ pJetRetCol = %08x\n", _TableCtx->pJetRetCol); \
  120. DPRINT1(5,"++ pDataRecord = %08x\n", _TableCtx->pDataRecord); \
  121. DPRINT1(5,"++ cColumns = %8d\n", _TableCtx->pJetTableCreate->cColumns); \
  122. DPRINT1(5,"++ rgcolumncreate = %08x\n", _TableCtx->pJetTableCreate->rgcolumncreate);\
  123. DPRINT1(5,"++ ulPages = %8d\n", _TableCtx->pJetTableCreate->ulPages); \
  124. DPRINT1(5,"++ ulDensity = %8d\n", _TableCtx->pJetTableCreate->ulDensity); \
  125. DPRINT1(5,"++ cIndexes = %8d\n", _TableCtx->pJetTableCreate->cIndexes); \
  126. DPRINT1(5,"++ rgindexcreate = %08x\n", _TableCtx->pJetTableCreate->rgindexcreate); \
  127. DPRINT1(5,"++ grbit = %08x\n", _TableCtx->pJetTableCreate->grbit); \
  128. DPRINT1(5,"++ tableid = %8d\n", _TableCtx->pJetTableCreate->tableid); \
  129. DPRINT1(5,"++ cCreated objects= %8d\n", _TableCtx->pJetTableCreate->cCreated); \
  130. DPRINT1(5,"++ TemplateTableName= %s\n", _TableCtx->pJetTableCreate->szTemplateTableName);
  131. #if 0
  132. //
  133. // for future use. from ntfsprop.h
  134. //
  135. //
  136. // VARIABLE_STRUCTURE_SIZE returns the size of a structure S that contains
  137. // an array of C structures V
  138. //
  139. #define VARIABLE_STRUCTURE_SIZE(S,V,C) ((int)sizeof( S ) + ((C) - 1) * (int)sizeof( V ))
  140. typedef struct _PROPERTY_SPECIFIER
  141. {
  142. ULONG Variant; // Distinguish the type
  143. union { // Switch on Variant
  144. PROPID Id; // Property ID
  145. ULONG NameOffset; // Offset to COUNTED_STRING
  146. };
  147. } PROPERTY_SPECIFIER, *PPROPERTY_SPECIFIER;
  148. //
  149. // PROPERTY_SPECIFICATIONS is a serialized form of an array PROPERTY_SPECIFIERs.
  150. // Immediately following PROPERTY_SPECIFICATIONS on a USHORT boundary are
  151. // of the name strings. Each name string is a COUNTED_STRING
  152. //
  153. typedef struct _PROPERTY_SPECIFICATIONS {
  154. ULONG Length; // Length in bytes of structure and name strings
  155. ULONG Count; // Count of PROPERTY_SPECIFIERS
  156. PROPERTY_SPECIFIER Specifiers[1]; // Array of actual specifiers, length Count
  157. } PROPERTY_SPECIFICATIONS, *PPROPERTY_SPECIFICATIONS;
  158. #define PROPERTY_SPECIFICATIONS_SIZE(c) \
  159. (VARIABLE_STRUCTURE_SIZE( PROPERTY_SPECIFICATIONS, PROPERTY_SPECIFIER, (c) ))
  160. #define PROPERTY_SPECIFIER_ID(PS,I) \
  161. ((PS)->Specifiers[(I)].Id)
  162. #define PROPERTY_SPECIFIER_COUNTED_STRING(PS,I) \
  163. ((PCOUNTED_STRING)Add2Ptr( (PS), (PS)->Specifiers[(I)].NameOffset))
  164. #define PROPERTY_SPECIFIER_NAME(PS,I) \
  165. (&PROPERTY_SPECIFIER_COUNTED_STRING( PS, I )->Text[0])
  166. #define PROPERTY_SPECIFIER_NAME_LENGTH(PS,I) \
  167. (PROPERTY_SPECIFIER_COUNTED_STRING( PS, I )->Length)
  168. #endif