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.

277 lines
12 KiB

  1. #ifndef _FSARSC_
  2. #define _FSARSC_
  3. /*++
  4. 1998 Seagate Software, Inc. All rights reserved.
  5. Module Name:
  6. fsarsc.h
  7. Abstract:
  8. This module represents a file system resource (i.e. volume)
  9. for NTFS 5.0.
  10. Author:
  11. Chuck Bardeen [cbardeen] 1-Dec-1996
  12. Revision History:
  13. --*/
  14. #include "resource.h" // main symbols
  15. #include "fsa.h"
  16. #include "task.h"
  17. #define FSA_VALIDATE_LOG_KEY_NAME OLESTR("SYSTEM\\CurrentControlSet\\Services\\Remote_Storage_File_System_Agent\\Validate")
  18. // Usn journal Registry parameters
  19. #define FSA_USN_MIN_SIZE OLESTR("UsnMinSize")
  20. #define FSA_USN_MAX_SIZE OLESTR("UsnMaxSize")
  21. #define FSA_USN_FREE_SPACE_FRACTION OLESTR("UsnSizeFreeSpaceFraction")
  22. #define FSA_USN_TOTAL_SPACE_FRACTION OLESTR("UsnSizeTotalSpaceFraction")
  23. // Usn journal defaults
  24. #define FSA_USN_MIN_SIZE_DEFAULT 100 // in MB
  25. #define FSA_USN_MAX_SIZE_DEFAULT 4096 // in MB (4 GB)
  26. #define FSA_USN_FREE_SPACE_FRACTION_DEFAULT 64 // 1/64 out of current free space
  27. #define FSA_USN_TOTAL_SPACE_FRACTION_DEFAULT 64 // 1/64 out of total volume space
  28. #define UNMANAGE_DB_PREFIX OLESTR("Unmanage_")
  29. /*++
  30. Class Name:
  31. CFsaResource
  32. Class Description:
  33. This class represents a file system resource (i.e. volume)
  34. for NTFS 5.0.
  35. --*/
  36. class CFsaResource :
  37. public CWsbCollectable,
  38. public IFsaResource,
  39. public IFsaResourcePriv,
  40. public IConnectionPointContainerImpl<CFsaResource>,
  41. public IConnectionPointImpl<CFsaResource, &IID_IHsmEvent, CComDynamicUnkArray>,
  42. public CComCoClass<CFsaResource,&CLSID_CFsaResourceNTFS>
  43. {
  44. public:
  45. CFsaResource() {}
  46. BEGIN_COM_MAP(CFsaResource)
  47. COM_INTERFACE_ENTRY(IFsaResource)
  48. COM_INTERFACE_ENTRY(IFsaResourcePriv)
  49. COM_INTERFACE_ENTRY2(IPersist, IPersistStream)
  50. COM_INTERFACE_ENTRY(IPersistStream)
  51. COM_INTERFACE_ENTRY(IWsbCollectable)
  52. COM_INTERFACE_ENTRY(IWsbTestable)
  53. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  54. END_COM_MAP()
  55. DECLARE_REGISTRY_RESOURCEID(IDR_FsaResource)
  56. // Connection Point
  57. BEGIN_CONNECTION_POINT_MAP(CFsaResource)
  58. CONNECTION_POINT_ENTRY(IID_IHsmEvent)
  59. END_CONNECTION_POINT_MAP()
  60. // CComObjectRoot
  61. public:
  62. STDMETHOD(FinalConstruct)(void);
  63. STDMETHOD(FinalRelease)(void);
  64. // IWsbCollectable
  65. public:
  66. STDMETHOD(CompareTo)(IUnknown* pUnknown, SHORT* pResult);
  67. // IPersist
  68. public:
  69. STDMETHOD(GetClassID)(LPCLSID pClsid);
  70. // IPersistStream
  71. public:
  72. STDMETHOD(GetSizeMax)(ULARGE_INTEGER* pSize);
  73. STDMETHOD(Load)(IStream* pStream);
  74. STDMETHOD(Save)(IStream* pStream, BOOL clearDirty);
  75. // IWsbTestable
  76. STDMETHOD(Test)(USHORT *passed, USHORT* failed);
  77. // IHsmSystemState
  78. STDMETHOD( ChangeSysState )( HSM_SYSTEM_STATE* pSysState );
  79. // IFsaResourcePriv
  80. public:
  81. STDMETHOD(AddPremigratedSize)(LONGLONG size);
  82. STDMETHOD(AddTruncatedSize)(LONGLONG size);
  83. STDMETHOD(DoRecovery)(void);
  84. STDMETHOD(FilterSawOpen)(IHsmSession* pSession, IFsaFilterRecall* pRecall,
  85. OLECHAR* path, LONGLONG fileId,
  86. LONGLONG requestOffset, LONGLONG requestSize,
  87. FSA_PLACEHOLDER* pPlaceholder, ULONG mode,
  88. FSA_RESULT_ACTION resultAction, DWORD threadId);
  89. STDMETHOD(FilterSawDelete)(GUID filterId, OLECHAR* path, LONGLONG size,
  90. FSA_PLACEHOLDER* pPlaceholder);
  91. STDMETHOD(GetPremigrated)(REFIID riid, void** ppDb);
  92. STDMETHOD(GetUnmanageDb)(REFIID riid, void** ppDb);
  93. STDMETHOD(Init)(IFsaServer* pFsaServer, OLECHAR* path, OLECHAR *dosName);
  94. STDMETHOD(RemovePremigratedSize)(LONGLONG size);
  95. STDMETHOD(RemoveTruncatedSize)(LONGLONG size);
  96. STDMETHOD(SetAlternatePath)(OLECHAR* name);
  97. STDMETHOD(SetIdentifier)(GUID id);
  98. STDMETHOD(SetName)(OLECHAR* name);
  99. STDMETHOD(SetOldPath)(OLECHAR* oldPath);
  100. STDMETHOD(SetPath)(OLECHAR* name);
  101. STDMETHOD(SetUserFriendlyName)(OLECHAR* name);
  102. STDMETHOD(SetStickyName)(OLECHAR* name);
  103. STDMETHOD(UpdateFrom)(IFsaServer* pServer, IFsaResource* pResource);
  104. STDMETHOD(InitializeUnmanageDb)(void);
  105. STDMETHOD(TerminateUnmanageDb)(void);
  106. STDMETHOD(GetMaxFileLogicalSize)(LONGLONG* pSize);
  107. // IFsaResource
  108. public:
  109. STDMETHOD(AddPremigrated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  110. BOOL isWaitingForClose, LONGLONG usn);
  111. STDMETHOD(AddTruncated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size);
  112. STDMETHOD(BeginSession)(OLECHAR* name, ULONG logControl, ULONG runId, ULONG subRunId,
  113. IHsmSession** ppSession);
  114. STDMETHOD(BeginValidate)(void);
  115. STDMETHOD(CompareBy)(FSA_RESOURCE_COMPARE by);
  116. STDMETHOD(CompareToAlternatePath)(OLECHAR* name, SHORT* pResult);
  117. STDMETHOD(CompareToIdentifier)(GUID id, SHORT* pResult);
  118. STDMETHOD(CompareToIResource)(IFsaResource* pResource, SHORT* pResult);
  119. STDMETHOD(CompareToName)(OLECHAR* name, SHORT* pResult);
  120. STDMETHOD(CompareToUserName)(OLECHAR* userName, SHORT* pResult);
  121. STDMETHOD(CompareToPath)(OLECHAR* name, SHORT* pResult);
  122. STDMETHOD(CompareToSerial)(ULONG serial, SHORT* pResult);
  123. STDMETHOD(CompareToStickyName)(OLECHAR* name, SHORT* pResult);
  124. STDMETHOD(CreateDefaultRules)(void);
  125. STDMETHOD(EndSession)(IHsmSession* pSession);
  126. STDMETHOD(EndValidate)(HSM_JOB_STATE state);
  127. STDMETHOD(EnumDefaultRules)(IWsbEnum** ppEnum);
  128. STDMETHOD(FindFirst)(OLECHAR* path, IHsmSession* pSession, IFsaScanItem** ppScanItem);
  129. STDMETHOD(FindFirstInRPIndex)(IHsmSession* pSession, IFsaScanItem** ppScanItem);
  130. STDMETHOD(FindFirstInDbIndex)(IHsmSession* pSession, IFsaScanItem** ppScanItem);
  131. STDMETHOD(FindNext)(IFsaScanItem* pScanItem);
  132. STDMETHOD(FindNextInRPIndex)(IFsaScanItem* pScanItem);
  133. STDMETHOD(FindNextInDbIndex)(IFsaScanItem* pScanItem);
  134. STDMETHOD(FindFileId)(LONGLONG fileId, IHsmSession* pSession,
  135. IFsaScanItem** ppScanItem);
  136. STDMETHOD(FindObjectId)(LONGLONG objIdHi, LONGLONG objIdLo, IHsmSession* pSession,
  137. IFsaScanItem** ppScanItem);
  138. STDMETHOD(GetAlternatePath)(OLECHAR** pPath, ULONG bufferSize);
  139. STDMETHOD(GetDefaultRules)(IWsbCollection** ppCollection);
  140. STDMETHOD(GetDbPath)(OLECHAR** pPath, ULONG bufferSize);
  141. STDMETHOD(GetUnmanageDbPath)(OLECHAR** pPath, ULONG bufferSize);
  142. STDMETHOD(GetFreeLevel)(ULONG* pLevel);
  143. STDMETHOD(GetFsName)(OLECHAR** pName, ULONG bufferSize);
  144. STDMETHOD(GetHsmEngine)(IHsmFsaTskMgr** ppEngine);
  145. STDMETHOD(GetHsmLevel)(ULONG* pLevel);
  146. STDMETHOD(GetIdentifier)(GUID* pId);
  147. STDMETHOD(GetLogicalName)(OLECHAR** pName, ULONG bufferSize);
  148. STDMETHOD(GetManageableItemLogicalSize)(LONGLONG* pSize);
  149. STDMETHOD(GetManageableItemAccessTime)(BOOL* isRelative, FILETIME* pTime);
  150. STDMETHOD(GetManagingHsm)(GUID* pId);
  151. STDMETHOD(GetName)(OLECHAR** pName, ULONG bufferSize);
  152. STDMETHOD(GetOldPath)(OLECHAR** pPath, ULONG bufferSize);
  153. STDMETHOD(GetPath)(OLECHAR** pPath, ULONG bufferSize);
  154. STDMETHOD(GetSerial)(ULONG *serial);
  155. STDMETHOD(GetSizes)(LONGLONG* pTotal, LONGLONG* pFree, LONGLONG* pPremigrated,
  156. LONGLONG* pTruncated);
  157. STDMETHOD(GetTruncator)(IFsaTruncator** ppTruncator);
  158. STDMETHOD(GetUncPath)(OLECHAR** pPath, ULONG bufferSize);
  159. STDMETHOD(GetUserFriendlyName)(OLECHAR** pName, ULONG bufferSize);
  160. STDMETHOD(GetStickyName)(OLECHAR** pName, ULONG bufferSize);
  161. STDMETHOD(IsActive)(void);
  162. STDMETHOD(IsAvailable)(void);
  163. STDMETHOD(IsDeletePending)(void);
  164. STDMETHOD(IsManaged)(void);
  165. STDMETHOD(Manage)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  166. GUID storagePoolId, BOOL truncate);
  167. STDMETHOD(ManagedBy)(GUID hsmId, ULONG hsmLevel, BOOL release);
  168. STDMETHOD(NeedsRepair)(void);
  169. STDMETHOD(ProcessResult)(IFsaPostIt* pResult);
  170. STDMETHOD(Recall)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  171. BOOL deletePlaceholder);
  172. STDMETHOD(RemovePremigrated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size);
  173. STDMETHOD(RemoveTruncated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size);
  174. STDMETHOD(SetHsmLevel)(ULONG level);
  175. STDMETHOD(SetIsActive)(BOOL isActive);
  176. STDMETHOD(SetIsAvailable)(BOOL isAvailable);
  177. STDMETHOD(SetIsDeletePending)(BOOL isDeletePending);
  178. STDMETHOD(SetManageableItemLogicalSize)(LONGLONG pSize);
  179. STDMETHOD(SetManageableItemAccessTime)(BOOL isRelative, FILETIME pTime);
  180. STDMETHOD(SetSerial)(ULONG serial);
  181. STDMETHOD(StartJob)(OLECHAR* startingPath, IHsmSession* pSession);
  182. STDMETHOD(StartJobSession)(IHsmJob* pJob, ULONG subRunId, IHsmSession** ppSession);
  183. STDMETHOD(Validate)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  184. LONGLONG usn);
  185. STDMETHOD(SetupValidateJob)(SYSTEMTIME runtime);
  186. STDMETHOD(CheckForValidate)(BOOL bForceValidate);
  187. STDMETHOD(GetUsnId)(ULONGLONG *usnId);
  188. STDMETHOD(ValidateForTruncate)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  189. LONGLONG usn);
  190. // Local Methods
  191. void OnStateChange( void );
  192. protected:
  193. STDMETHOD(CheckForJournal)(BOOL *pValidateNeeded);
  194. STDMETHOD(InitializePremigrationList)(BOOL bStartValidateJob);
  195. HRESULT ReadIdentifier(void);
  196. HRESULT WriteIdentifier(void);
  197. protected:
  198. GUID m_id;
  199. CWsbStringPtr m_oldPath; // Previous value for 'm_path'.
  200. CWsbStringPtr m_path; // Drive letter (with backslash) if named
  201. // volume, otherwise same as m_stickyName.
  202. CWsbStringPtr m_alternatePath;
  203. CWsbStringPtr m_name; // Volume name.
  204. CWsbStringPtr m_userName; // Drive letter (with backslash) if named
  205. // volume, otherwise NULL.
  206. CWsbStringPtr m_stickyName; // Long ugly PNP name (without \\?\ prefix)
  207. CWsbStringPtr m_fsName; // File system type (e.g., NTFS).
  208. BOOL m_isActive;
  209. BOOL m_isAvailable; // If volume is manageable.
  210. BOOL m_isDeletePending;
  211. BOOL m_isRecovered;
  212. BOOL m_isDbInitialized;
  213. ULONG m_maxComponentLength;
  214. ULONG m_fsFlags;
  215. FSA_RESOURCE_COMPARE m_compareBy;
  216. GUID m_managingHsm;
  217. ULONG m_hsmLevel;
  218. LONGLONG m_premigratedSize;
  219. LONGLONG m_truncatedSize;
  220. LONGLONG m_oldPremigratedSize;
  221. LONGLONG m_oldTruncatedSize;
  222. BOOL m_isDoingValidate;
  223. LONGLONG m_manageableItemLogicalSize;
  224. BOOL m_manageableItemAccessTimeIsRelative;
  225. FILETIME m_manageableItemAccessTime;
  226. LONGLONG m_manageableItemMaxSize;
  227. ULONGLONG m_usnJournalId;
  228. LONGLONG m_lastUsnId;
  229. IFsaServer* m_pFsaServer; // Parent Pointer, Weak Reference
  230. // (do not AddRef() it)
  231. unsigned long m_serial; // Serial number of volume
  232. CComPtr<IFsaPremigratedDb> m_pPremigrated;
  233. CComPtr<IHsmFsaTskMgr> m_pHsmEngine;
  234. CComPtr<IFsaTruncator> m_pTruncator;
  235. CComPtr<IWsbCollection> m_pDefaultRules;
  236. CComPtr<IFsaUnmanageDb> m_pUnmanageDb;
  237. BOOL m_isUnmanageDbInitialized;
  238. };
  239. #endif // _FSARSC_