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.

273 lines
8.4 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #ifndef __CREPOSIT__H_
  5. #define __CREPOSIT__H_
  6. #include <windows.h>
  7. #include <wbemidl.h>
  8. #include <unk.h>
  9. #include <wbemcomn.h>
  10. #include <sync.h>
  11. #include <reposit.h>
  12. #include <wmiutils.h>
  13. #include <filecach.h>
  14. #include <hiecache.h>
  15. #include <corex.h>
  16. #include "a51fib.h"
  17. #include "lock.h"
  18. #include <statsync.h>
  19. extern CLock g_readWriteLock;
  20. extern bool g_bShuttingDown;
  21. /* ===================================================================================
  22. * A51_REP_FS_VERSION
  23. *
  24. * 1 - Original A51 file-based repository
  25. * 2 - All Objects stored in single file (Whistler Beta 1)
  26. * 3 - BTree added
  27. * 4 - System Class optimisation - put all system classes in __SYSTEMCLASS namespace
  28. * 5 - Change to system classes in __SYSTEMCLASS namespace - need to propagate change
  29. * to all namespaces as there may be instances of these classes.
  30. * 6 - XFiles: New page based heap. Transacted page manager sitting under new heap and
  31. * BTree. Instance indexing improved so instance queries are faster
  32. * 7 - Locale Upgrade run on repository
  33. * ===================================================================================
  34. */
  35. #define A51_REP_FS_VERSION 7
  36. /* =================================================================================
  37. *
  38. * See sample_layout.txt for an example of the raw data!
  39. * See sample_layout_translated.txt for a version with hashes converted to appropriate classes/keys/namespaces
  40. *
  41. * <full repository path> - Stripped out in the INDEX.CPP layer... c:\windows\system32\wbem\repository\fs
  42. * \NS_<full_namespace> - one for each namespace, hashed on full NS path
  43. *
  44. * \CD_<class name>.x.y.z - Class definition, hash on class name, object location appended
  45. * \CR_<parent_class_name>\C_<class_name> - parent/child class relationship
  46. * \CR_<reference_class_name>\R_<class_name> - class reference to another class
  47. *
  48. * \KI_<key_root_class_name>\I_<key>.x.y.z - Instance location for all instances sharing key tree
  49. * \CI_<class_name>\IL_<key>.x.y.z - Instance location associated with its own class
  50. *
  51. * \KI_<referenced_key_root_class_name>\IR_<referenced_key>\R_<full_repository_path_of_referencing_KI\I_instance>.x.y.z - instance reference
  52. *
  53. * SC_<hash> - Not used!
  54. *
  55. *
  56. * Class definition object
  57. * DWORD dwSuperclassLen - no NULL terminator
  58. * wchar_t wsSuperclassName[dwSuperclassLen]; - superclass name
  59. * __int64 i64Timestamp - timestamp of last update
  60. * BYTE baUnmergedClass[?] - Unmerged class
  61. *
  62. *
  63. * Instance definition object
  64. * wchar_t wsClassHash[MAX_HASH_LEN]
  65. * __int64 i64InstanceTimestamp
  66. * __int64 i64ClassTimestamp
  67. * BYTE baUnmergedClass[?]
  68. *
  69. *
  70. * Instance Reference definition object -
  71. * NOTE! If an instance has multiple references to the same object, we will only return the last one as each one will get overwritten by
  72. * the last! This is because final R_<HASH> is based on the referring objects full instance path. It does not include the property in the hash!
  73. * DWORD dwNamespaceLen - no NULL terminator
  74. * wchar_t wsNamespace [dwNamespaceLen] - namespace, root\default...
  75. * DWORD dwReferringClassLen - Class name of instance referring to this instance
  76. * wchar_t wsReferringClass[dwReferringClassLen] - no NULL terminator
  77. * DWORD dwReferringPropertyLen - property referring to us from the source object
  78. * wchar_t wsReferringProperty[dwReferringPropertyLen] - no NULL terminator
  79. * DWORD dwReferringFileNameLen - file path of instance referring to this one, minus the full repository path
  80. * wchar_t dwReferringFileName[dwReferringFileNameLen] - (minus c:\windows..., but includes NS_....), not NULL terminated
  81. *
  82. * =================================================================================
  83. */
  84. #define A51_CLASSDEF_FILE_PREFIX L"CD_"
  85. #define A51_CLASSRELATION_DIR_PREFIX L"CR_"
  86. #define A51_CHILDCLASS_FILE_PREFIX L"C_"
  87. #define A51_KEYROOTINST_DIR_PREFIX L"KI_"
  88. #define A51_INSTDEF_FILE_PREFIX L"I_"
  89. #define A51_CLASSINST_DIR_PREFIX L"CI_"
  90. #define A51_INSTLINK_FILE_PREFIX L"IL_"
  91. #define A51_INSTREF_DIR_PREFIX L"IR_"
  92. #define A51_REF_FILE_PREFIX L"R_"
  93. #define A51_SCOPE_DIR_PREFIX L"SC_"
  94. #define A51_SYSTEMCLASS_NS L"__SYSTEMCLASS"
  95. class CGlobals;
  96. extern CGlobals g_Glob;
  97. class CNamespaceHandle;
  98. extern CNamespaceHandle * g_pSystemClassNamespace;
  99. //
  100. // let's count here how many times we fail to recover from a failed transaction
  101. //
  102. /////////////////////////////////////////////////
  103. enum eFailCnt {
  104. FailCntCommit,
  105. FailCntInternalBegin,
  106. FailCntInternalCommit,
  107. FailCntCreateSystem,
  108. FailCntCompactPages,
  109. FailCntLast
  110. };
  111. extern LONG g_RecoverFailureCnt[];
  112. class CForestCache;
  113. class CGlobals
  114. {
  115. private:
  116. BOOL m_bInit;
  117. CStaticCritSec m_cs;
  118. public:
  119. _IWmiCoreServices* m_pCoreServices;
  120. CForestCache m_ForestCache;
  121. CFileCache m_FileCache;
  122. private:
  123. long m_lRootDirLen;
  124. WCHAR m_wszRootDir[MAX_PATH]; // keep this last: be debugger friendly
  125. WCHAR m_ComputerName[MAX_COMPUTERNAME_LENGTH+1];
  126. public:
  127. CGlobals():m_bInit(FALSE){};
  128. ~CGlobals(){};
  129. HRESULT Initialize();
  130. HRESULT Deinitialize();
  131. _IWmiCoreServices * GetCoreSvcs(){if (m_pCoreServices) m_pCoreServices->AddRef();return m_pCoreServices;}
  132. // CForestCache * GetForestCache() { return &m_ForestCache; }
  133. // CFileCache * GetFileCache() { return &m_FileCache; }
  134. WCHAR * GetRootDir() {return (WCHAR *)m_wszRootDir;}
  135. WCHAR * GetComputerName(){ return (WCHAR *)m_ComputerName; };
  136. long GetRootDirLen() {return m_lRootDirLen;};
  137. void SetRootDirLen(long Len) { m_lRootDirLen = Len;};
  138. BOOL IsInit(){ return m_bInit; };
  139. };
  140. HRESULT DoAutoDatabaseRestore();
  141. class CNamespaceHandle;
  142. class CRepository : public CUnkBase<IWmiDbController, &IID_IWmiDbController>
  143. {
  144. private:
  145. CFlexArray m_aSystemClasses; //Used for part of the upgrade process.
  146. static DWORD m_ShutDownFlags;
  147. static HANDLE m_hShutdownEvent;
  148. static HANDLE m_hFlusherThread;
  149. static LONG m_ulReadCount;
  150. static LONG m_ulWriteCount;
  151. static HANDLE m_hWriteEvent;
  152. static HANDLE m_hReadEvent;
  153. static int m_threadState;
  154. static CStaticCritSec m_cs;
  155. static LONG m_threadCount;
  156. static LONG m_nFlushFailureCount;
  157. enum { ThreadStateDead, ThreadStateIdle, ThreadStateFlush, ThreadStateOperationPending};
  158. protected:
  159. HRESULT Initialize();
  160. HRESULT UpgradeRepositoryFormat();
  161. HRESULT GetRepositoryDirectory();
  162. HRESULT InitializeGlobalVariables();
  163. HRESULT InitializeRepositoryVersions();
  164. static DWORD WINAPI _FlusherThread(void *);
  165. public:
  166. HRESULT STDMETHODCALLTYPE Logon(
  167. WMIDB_LOGON_TEMPLATE *pLogonParms,
  168. DWORD dwFlags,
  169. DWORD dwRequestedHandleType,
  170. IWmiDbSession **ppSession,
  171. IWmiDbHandle **ppRootNamespace
  172. );
  173. HRESULT STDMETHODCALLTYPE GetLogonTemplate(
  174. LCID lLocale,
  175. DWORD dwFlags,
  176. WMIDB_LOGON_TEMPLATE **ppLogonTemplate
  177. );
  178. HRESULT STDMETHODCALLTYPE FreeLogonTemplate(
  179. WMIDB_LOGON_TEMPLATE **ppTemplate
  180. );
  181. HRESULT STDMETHODCALLTYPE Shutdown(
  182. DWORD dwFlags
  183. );
  184. HRESULT STDMETHODCALLTYPE SetCallTimeout(
  185. DWORD dwMaxTimeout
  186. );
  187. HRESULT STDMETHODCALLTYPE SetCacheValue(
  188. DWORD dwMaxBytes
  189. );
  190. HRESULT STDMETHODCALLTYPE FlushCache(
  191. DWORD dwFlags
  192. );
  193. HRESULT STDMETHODCALLTYPE GetStatistics(
  194. DWORD dwParameter,
  195. DWORD *pdwValue
  196. );
  197. HRESULT STDMETHODCALLTYPE Backup(
  198. LPCWSTR wszBackupFile,
  199. long lFlags
  200. );
  201. HRESULT STDMETHODCALLTYPE Restore(
  202. LPCWSTR wszBackupFile,
  203. long lFlags
  204. );
  205. HRESULT STDMETHODCALLTYPE LockRepository();
  206. HRESULT STDMETHODCALLTYPE UnlockRepository();
  207. HRESULT STDMETHODCALLTYPE GetRepositoryVersions(DWORD *pdwOldVersion, DWORD *pdwCurrentVersion);
  208. static HRESULT ReadOperationNotification();
  209. static HRESULT WriteOperationNotification();
  210. public:
  211. CRepository(CLifeControl* pControl) : TUnkBase(pControl)
  212. {
  213. }
  214. ~CRepository()
  215. {
  216. }
  217. HRESULT GetNamespaceHandle(LPCWSTR wszNamespaceName,
  218. CNamespaceHandle** ppHandle);
  219. };
  220. #endif /*__CREPOSIT__H_*/