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.

275 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. // IFsaResource
  107. public:
  108. STDMETHOD(AddPremigrated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  109. BOOL isWaitingForClose, LONGLONG usn);
  110. STDMETHOD(AddTruncated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size);
  111. STDMETHOD(BeginSession)(OLECHAR* name, ULONG logControl, ULONG runId, ULONG subRunId,
  112. IHsmSession** ppSession);
  113. STDMETHOD(BeginValidate)(void);
  114. STDMETHOD(CompareBy)(FSA_RESOURCE_COMPARE by);
  115. STDMETHOD(CompareToAlternatePath)(OLECHAR* name, SHORT* pResult);
  116. STDMETHOD(CompareToIdentifier)(GUID id, SHORT* pResult);
  117. STDMETHOD(CompareToIResource)(IFsaResource* pResource, SHORT* pResult);
  118. STDMETHOD(CompareToName)(OLECHAR* name, SHORT* pResult);
  119. STDMETHOD(CompareToUserName)(OLECHAR* userName, SHORT* pResult);
  120. STDMETHOD(CompareToPath)(OLECHAR* name, SHORT* pResult);
  121. STDMETHOD(CompareToSerial)(ULONG serial, SHORT* pResult);
  122. STDMETHOD(CompareToStickyName)(OLECHAR* name, SHORT* pResult);
  123. STDMETHOD(CreateDefaultRules)(void);
  124. STDMETHOD(EndSession)(IHsmSession* pSession);
  125. STDMETHOD(EndValidate)(HSM_JOB_STATE state);
  126. STDMETHOD(EnumDefaultRules)(IWsbEnum** ppEnum);
  127. STDMETHOD(FindFirst)(OLECHAR* path, IHsmSession* pSession, IFsaScanItem** ppScanItem);
  128. STDMETHOD(FindFirstInRPIndex)(IHsmSession* pSession, IFsaScanItem** ppScanItem);
  129. STDMETHOD(FindFirstInDbIndex)(IHsmSession* pSession, IFsaScanItem** ppScanItem);
  130. STDMETHOD(FindNext)(IFsaScanItem* pScanItem);
  131. STDMETHOD(FindNextInRPIndex)(IFsaScanItem* pScanItem);
  132. STDMETHOD(FindNextInDbIndex)(IFsaScanItem* pScanItem);
  133. STDMETHOD(FindFileId)(LONGLONG fileId, IHsmSession* pSession,
  134. IFsaScanItem** ppScanItem);
  135. STDMETHOD(FindObjectId)(LONGLONG objIdHi, LONGLONG objIdLo, IHsmSession* pSession,
  136. IFsaScanItem** ppScanItem);
  137. STDMETHOD(GetAlternatePath)(OLECHAR** pPath, ULONG bufferSize);
  138. STDMETHOD(GetDefaultRules)(IWsbCollection** ppCollection);
  139. STDMETHOD(GetDbPath)(OLECHAR** pPath, ULONG bufferSize);
  140. STDMETHOD(GetUnmanageDbPath)(OLECHAR** pPath, ULONG bufferSize);
  141. STDMETHOD(GetFreeLevel)(ULONG* pLevel);
  142. STDMETHOD(GetFsName)(OLECHAR** pName, ULONG bufferSize);
  143. STDMETHOD(GetHsmEngine)(IHsmFsaTskMgr** ppEngine);
  144. STDMETHOD(GetHsmLevel)(ULONG* pLevel);
  145. STDMETHOD(GetIdentifier)(GUID* pId);
  146. STDMETHOD(GetLogicalName)(OLECHAR** pName, ULONG bufferSize);
  147. STDMETHOD(GetManageableItemLogicalSize)(LONGLONG* pSize);
  148. STDMETHOD(GetManageableItemAccessTime)(BOOL* isRelative, FILETIME* pTime);
  149. STDMETHOD(GetManagingHsm)(GUID* pId);
  150. STDMETHOD(GetName)(OLECHAR** pName, ULONG bufferSize);
  151. STDMETHOD(GetOldPath)(OLECHAR** pPath, ULONG bufferSize);
  152. STDMETHOD(GetPath)(OLECHAR** pPath, ULONG bufferSize);
  153. STDMETHOD(GetSerial)(ULONG *serial);
  154. STDMETHOD(GetSizes)(LONGLONG* pTotal, LONGLONG* pFree, LONGLONG* pPremigrated,
  155. LONGLONG* pTruncated);
  156. STDMETHOD(GetTruncator)(IFsaTruncator** ppTruncator);
  157. STDMETHOD(GetUncPath)(OLECHAR** pPath, ULONG bufferSize);
  158. STDMETHOD(GetUserFriendlyName)(OLECHAR** pName, ULONG bufferSize);
  159. STDMETHOD(GetStickyName)(OLECHAR** pName, ULONG bufferSize);
  160. STDMETHOD(IsActive)(void);
  161. STDMETHOD(IsAvailable)(void);
  162. STDMETHOD(IsDeletePending)(void);
  163. STDMETHOD(IsManaged)(void);
  164. STDMETHOD(Manage)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  165. GUID storagePoolId, BOOL truncate);
  166. STDMETHOD(ManagedBy)(GUID hsmId, ULONG hsmLevel, BOOL release);
  167. STDMETHOD(NeedsRepair)(void);
  168. STDMETHOD(ProcessResult)(IFsaPostIt* pResult);
  169. STDMETHOD(Recall)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  170. BOOL deletePlaceholder);
  171. STDMETHOD(RemovePremigrated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size);
  172. STDMETHOD(RemoveTruncated)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size);
  173. STDMETHOD(SetHsmLevel)(ULONG level);
  174. STDMETHOD(SetIsActive)(BOOL isActive);
  175. STDMETHOD(SetIsAvailable)(BOOL isAvailable);
  176. STDMETHOD(SetIsDeletePending)(BOOL isDeletePending);
  177. STDMETHOD(SetManageableItemLogicalSize)(LONGLONG pSize);
  178. STDMETHOD(SetManageableItemAccessTime)(BOOL isRelative, FILETIME pTime);
  179. STDMETHOD(SetSerial)(ULONG serial);
  180. STDMETHOD(StartJob)(OLECHAR* startingPath, IHsmSession* pSession);
  181. STDMETHOD(StartJobSession)(IHsmJob* pJob, ULONG subRunId, IHsmSession** ppSession);
  182. STDMETHOD(Validate)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  183. LONGLONG usn);
  184. STDMETHOD(SetupValidateJob)(SYSTEMTIME runtime);
  185. STDMETHOD(CheckForValidate)(BOOL bForceValidate);
  186. STDMETHOD(GetUsnId)(ULONGLONG *usnId);
  187. STDMETHOD(ValidateForTruncate)(IFsaScanItem* pScanItem, LONGLONG offset, LONGLONG size,
  188. LONGLONG usn);
  189. // Local Methods
  190. void OnStateChange( void );
  191. protected:
  192. STDMETHOD(CheckForJournal)(BOOL *pValidateNeeded);
  193. STDMETHOD(InitializePremigrationList)(BOOL bStartValidateJob);
  194. HRESULT ReadIdentifier(void);
  195. HRESULT WriteIdentifier(void);
  196. protected:
  197. GUID m_id;
  198. CWsbStringPtr m_oldPath; // Previous value for 'm_path'.
  199. CWsbStringPtr m_path; // Drive letter (with backslash) if named
  200. // volume, otherwise same as m_stickyName.
  201. CWsbStringPtr m_alternatePath;
  202. CWsbStringPtr m_name; // Volume name.
  203. CWsbStringPtr m_userName; // Drive letter (with backslash) if named
  204. // volume, otherwise NULL.
  205. CWsbStringPtr m_stickyName; // Long ugly PNP name (without \\?\ prefix)
  206. CWsbStringPtr m_fsName; // File system type (e.g., NTFS).
  207. BOOL m_isActive;
  208. BOOL m_isAvailable; // If volume is manageable.
  209. BOOL m_isDeletePending;
  210. BOOL m_isRecovered;
  211. BOOL m_isDbInitialized;
  212. ULONG m_maxComponentLength;
  213. ULONG m_fsFlags;
  214. FSA_RESOURCE_COMPARE m_compareBy;
  215. GUID m_managingHsm;
  216. ULONG m_hsmLevel;
  217. LONGLONG m_premigratedSize;
  218. LONGLONG m_truncatedSize;
  219. LONGLONG m_oldPremigratedSize;
  220. LONGLONG m_oldTruncatedSize;
  221. BOOL m_isDoingValidate;
  222. LONGLONG m_manageableItemLogicalSize;
  223. BOOL m_manageableItemAccessTimeIsRelative;
  224. FILETIME m_manageableItemAccessTime;
  225. ULONGLONG m_usnJournalId;
  226. LONGLONG m_lastUsnId;
  227. IFsaServer* m_pFsaServer; // Parent Pointer, Weak Reference
  228. // (do not AddRef() it)
  229. unsigned long m_serial; // Serial number of volume
  230. CComPtr<IFsaPremigratedDb> m_pPremigrated;
  231. CComPtr<IHsmFsaTskMgr> m_pHsmEngine;
  232. CComPtr<IFsaTruncator> m_pTruncator;
  233. CComPtr<IWsbCollection> m_pDefaultRules;
  234. CComPtr<IFsaUnmanageDb> m_pUnmanageDb;
  235. BOOL m_isUnmanageDbInitialized;
  236. };
  237. #endif // _FSARSC_