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.

475 lines
14 KiB

  1. // LockBytes.h -- Class declaration for IFSLockBytes
  2. #ifndef __LOCKBYTE_H__
  3. #define __LOCKBYTE_H__
  4. /*
  5. This file defines three implementations of the ILockBytes interface:
  6. 1. CFSLockBytes -- which represents a file as a LockBytes object.
  7. 2. CSegmentLockBytes -- which manages a LockBytes object as a sub-span of a
  8. containing LockBytes object.
  9. 3. CTransformedLockBytes -- which manages a LockBytes object above a set of
  10. data transformations. See MSITStg for a complete
  11. discussion of data transformations. In general
  12. you'd use transforms to apply data compression
  13. methods and enciphering algorithms.
  14. LockBytes segments and LockBytes transforms use CStorage and CXStorage objects,
  15. respectively, to manage their name and data space bindings within the Tome file.
  16. */
  17. ILockBytes *STDMETHODCALLTYPE FindMatchingLockBytes(const WCHAR *pwcsPath, CImpITUnknown *pLkb);
  18. class CSegmentLockBytes;
  19. class CFSLockBytes : public CITUnknown
  20. {
  21. public:
  22. // Destructor:
  23. ~CFSLockBytes(void);
  24. // Creation:
  25. static HRESULT Create(IUnknown *punkOuter, const WCHAR * pwszFileName,
  26. DWORD grfMode, ILockBytes **pplkb
  27. );
  28. static HRESULT CreateTemp(IUnknown *punkOuter, ILockBytes **pplkb);
  29. static HRESULT Open(IUnknown *punkOuter, const WCHAR * pwszFileName,
  30. DWORD grfMode, ILockBytes **pplkb
  31. );
  32. CFSLockBytes(IUnknown *pUnkOuter);
  33. class CImpILockBytes : public IITLockBytes
  34. {
  35. public:
  36. // Constructor and Destructor:
  37. CImpILockBytes(CFSLockBytes *pBackObj, IUnknown *punkOuter);
  38. ~CImpILockBytes(void);
  39. // Initialing routines:
  40. HRESULT InitCreateLockBytesOnFS(const WCHAR * pwszFileName,
  41. DWORD grfMode
  42. );
  43. HRESULT InitOpenLockBytesOnFS(const WCHAR * pwszFileName,
  44. DWORD grfMode
  45. );
  46. static DWORD STGErrorFromFSError(DWORD fsError);
  47. static ILockBytes *FindFSLockBytes(const WCHAR * pwszFileName);
  48. HRESULT __stdcall SetTimes
  49. (FILETIME const * pctime,
  50. FILETIME const * patime,
  51. FILETIME const * pmtime
  52. );
  53. // ILockBytes methods:
  54. HRESULT STDMETHODCALLTYPE ReadAt(
  55. /* [in] */ ULARGE_INTEGER ulOffset,
  56. /* [length_is][size_is][out] */ void __RPC_FAR *pv,
  57. /* [in] */ ULONG cb,
  58. /* [out] */ ULONG __RPC_FAR *pcbRead);
  59. HRESULT STDMETHODCALLTYPE WriteAt(
  60. /* [in] */ ULARGE_INTEGER ulOffset,
  61. /* [size_is][in] */ const void __RPC_FAR *pv,
  62. /* [in] */ ULONG cb,
  63. /* [out] */ ULONG __RPC_FAR *pcbWritten);
  64. HRESULT STDMETHODCALLTYPE Flush( void);
  65. HRESULT STDMETHODCALLTYPE SetSize(
  66. /* [in] */ ULARGE_INTEGER cb);
  67. HRESULT STDMETHODCALLTYPE LockRegion(
  68. /* [in] */ ULARGE_INTEGER libOffset,
  69. /* [in] */ ULARGE_INTEGER cb,
  70. /* [in] */ DWORD dwLockType);
  71. HRESULT STDMETHODCALLTYPE UnlockRegion(
  72. /* [in] */ ULARGE_INTEGER libOffset,
  73. /* [in] */ ULARGE_INTEGER cb,
  74. /* [in] */ DWORD dwLockType);
  75. HRESULT STDMETHODCALLTYPE Stat(
  76. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  77. /* [in] */ DWORD grfStatFlag);
  78. private:
  79. HRESULT OpenOrCreateLockBytesOnFS
  80. (const WCHAR * pwszFileName,
  81. DWORD grfMode,
  82. BOOL fCreate
  83. );
  84. DEBUGDEF(static LONG s_cInCriticalSection) // Lock count
  85. HANDLE m_hFile; // Containing file -- not use for lockbyte segment
  86. BOOL m_fFlushed; // Is the data different from on-disk version.
  87. DWORD m_grfMode; // Permissions, Sharing rules
  88. WCHAR m_awszFileName[MAX_PATH]; // Path name for this lockbyte object
  89. UINT m_cwcFileName; // Length of path name
  90. };
  91. private:
  92. friend CImpILockBytes;
  93. CImpILockBytes m_ImpILockBytes;
  94. };
  95. inline CFSLockBytes::CFSLockBytes(IUnknown *pUnkOuter)
  96. : m_ImpILockBytes(this, pUnkOuter),
  97. CITUnknown(&IID_ILockBytes, 1, &m_ImpILockBytes)
  98. {
  99. }
  100. inline CFSLockBytes::~CFSLockBytes(void)
  101. {
  102. }
  103. class CSegmentLockBytes : public CITUnknown
  104. {
  105. public:
  106. // Destructor:
  107. ~CSegmentLockBytes(void);
  108. // Creation:
  109. static HRESULT OpenSegment(IUnknown *punkOuter, IITFileSystem *pITFS,
  110. ILockBytes *pLKBMedium, PathInfo *pPI,
  111. ILockBytes **pplkb
  112. );
  113. class CImpILockBytes : public IITLockBytes
  114. {
  115. public:
  116. // Constructor and Destructor:
  117. CImpILockBytes(CSegmentLockBytes *pBackObj, IUnknown *punkOuter);
  118. ~CImpILockBytes(void);
  119. // Initialing routines:
  120. HRESULT InitOpenSegment(IITFileSystem *pITFS, ILockBytes *pLKBMedium, PathInfo *pPI);
  121. // ILockBytes methods:
  122. HRESULT STDMETHODCALLTYPE ReadAt(
  123. /* [in] */ ULARGE_INTEGER ulOffset,
  124. /* [length_is][size_is][out] */ void __RPC_FAR *pv,
  125. /* [in] */ ULONG cb,
  126. /* [out] */ ULONG __RPC_FAR *pcbRead);
  127. HRESULT STDMETHODCALLTYPE WriteAt(
  128. /* [in] */ ULARGE_INTEGER ulOffset,
  129. /* [size_is][in] */ const void __RPC_FAR *pv,
  130. /* [in] */ ULONG cb,
  131. /* [out] */ ULONG __RPC_FAR *pcbWritten);
  132. HRESULT STDMETHODCALLTYPE Flush( void);
  133. HRESULT STDMETHODCALLTYPE SetSize(
  134. /* [in] */ ULARGE_INTEGER cb);
  135. HRESULT STDMETHODCALLTYPE LockRegion(
  136. /* [in] */ ULARGE_INTEGER libOffset,
  137. /* [in] */ ULARGE_INTEGER cb,
  138. /* [in] */ DWORD dwLockType);
  139. HRESULT STDMETHODCALLTYPE UnlockRegion(
  140. /* [in] */ ULARGE_INTEGER libOffset,
  141. /* [in] */ ULARGE_INTEGER cb,
  142. /* [in] */ DWORD dwLockType);
  143. HRESULT STDMETHODCALLTYPE Stat(
  144. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  145. /* [in] */ DWORD grfStatFlag);
  146. private:
  147. DEBUGDEF(static LONG s_cInCriticalSection) // Lock count
  148. BOOL m_fFlushed; // Is the data different from on-disk version.
  149. IITFileSystem *m_pITFS; // File system in which this lockbytes exists.
  150. ILockBytes *m_plbMedium; // Container for this lockbytes segment
  151. ILockBytes *m_plbTemp; // Used when we overflow a lockbytes segment
  152. ILockBytes *m_plbLockMgr;// Used to process Lock/Unlock region requests
  153. PathInfo m_PathInfo; // ITFS record for this LockBytes segment
  154. };
  155. private:
  156. CSegmentLockBytes(IUnknown *pUnkOuter);
  157. CImpILockBytes m_ImpILockBytes;
  158. };
  159. inline CSegmentLockBytes::CSegmentLockBytes(IUnknown *pUnkOuter)
  160. : m_ImpILockBytes(this, pUnkOuter),
  161. CITUnknown(&IID_ILockBytes, 1, &m_ImpILockBytes)
  162. {
  163. }
  164. inline CSegmentLockBytes::~CSegmentLockBytes(void)
  165. {
  166. }
  167. #define RW_ACCESS_MASK 0x3
  168. #define SHARE_MASK 0x70
  169. #define SHARE_BIT_SHIFT 4
  170. typedef ITransformInstance *PITransformInstance;
  171. class TransformDescriptor
  172. {
  173. public:
  174. static TransformDescriptor *Create(UINT iDataSpace, UINT cLayers);
  175. ~TransformDescriptor();
  176. UINT iSpace;
  177. CImpITUnknown *pLockBytesChain;
  178. CITCriticalSection cs;
  179. UINT cTransformLayers;
  180. PITransformInstance *apTransformInstance;
  181. private:
  182. TransformDescriptor();
  183. };
  184. typedef TransformDescriptor *PTransformDescriptor;
  185. class CTransformedLockBytes : public CITUnknown
  186. {
  187. public:
  188. // Destructor:
  189. ~CTransformedLockBytes(void);
  190. // Creation:
  191. static HRESULT Open(IUnknown *punkOuter, PathInfo *pPathInfo,
  192. TransformDescriptor *pTransformDescriptor,
  193. IITFileSystem *pITFS,
  194. ILockBytes **ppLockBytes
  195. );
  196. static ILockBytes *FindTransformedLockBytes
  197. (const WCHAR * pwszFileName,
  198. TransformDescriptor *pTransformDescriptor
  199. );
  200. private:
  201. CTransformedLockBytes(IUnknown *pUnkOuter);
  202. class CImpILockBytes : public IITLockBytes
  203. {
  204. public:
  205. // Constructor and Destructor:
  206. CImpILockBytes(CTransformedLockBytes *pBackObj, IUnknown *punkOuter);
  207. ~CImpILockBytes(void);
  208. // Initialing routines:
  209. HRESULT InitOpen(PathInfo *pPathInfo,
  210. TransformDescriptor *pTransformDescriptor,
  211. IITFileSystem *pITFS
  212. );
  213. static ILockBytes *FindTransformedLockBytes
  214. (const WCHAR * pwszFileName,
  215. TransformDescriptor *pTransformDescriptor
  216. );
  217. // ILockBytes methods:
  218. HRESULT STDMETHODCALLTYPE ReadAt(
  219. /* [in] */ ULARGE_INTEGER ulOffset,
  220. /* [length_is][size_is][out] */ void __RPC_FAR *pv,
  221. /* [in] */ ULONG cb,
  222. /* [out] */ ULONG __RPC_FAR *pcbRead);
  223. HRESULT STDMETHODCALLTYPE WriteAt(
  224. /* [in] */ ULARGE_INTEGER ulOffset,
  225. /* [size_is][in] */ const void __RPC_FAR *pv,
  226. /* [in] */ ULONG cb,
  227. /* [out] */ ULONG __RPC_FAR *pcbWritten);
  228. HRESULT STDMETHODCALLTYPE Flush( void);
  229. HRESULT STDMETHODCALLTYPE SetSize(
  230. /* [in] */ ULARGE_INTEGER cb);
  231. HRESULT STDMETHODCALLTYPE LockRegion(
  232. /* [in] */ ULARGE_INTEGER libOffset,
  233. /* [in] */ ULARGE_INTEGER cb,
  234. /* [in] */ DWORD dwLockType);
  235. HRESULT STDMETHODCALLTYPE UnlockRegion(
  236. /* [in] */ ULARGE_INTEGER libOffset,
  237. /* [in] */ ULARGE_INTEGER cb,
  238. /* [in] */ DWORD dwLockType);
  239. HRESULT STDMETHODCALLTYPE Stat(
  240. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  241. /* [in] */ DWORD grfStatFlag);
  242. private:
  243. DEBUGDEF(static LONG s_cInCriticalSection) // Lock count
  244. ITransformInstance *m_pTransformInstance;
  245. IITFileSystem *m_pITFS;
  246. TransformDescriptor *m_pTransformDescriptor;
  247. ILockBytes *m_plbLockMgr;
  248. BOOL m_fFlushed; // Is the data different from on-disk version.
  249. DWORD m_grfMode; // Permissions, Sharing rules
  250. PathInfo m_PathInfo;
  251. };
  252. CImpILockBytes m_ImpILockBytes;
  253. };
  254. inline CTransformedLockBytes::CTransformedLockBytes(IUnknown *pUnkOuter)
  255. : m_ImpILockBytes(this, pUnkOuter),
  256. CITUnknown(&IID_ILockBytes, 1, &m_ImpILockBytes)
  257. {
  258. }
  259. inline CTransformedLockBytes::~CTransformedLockBytes(void)
  260. {
  261. }
  262. inline ILockBytes *CTransformedLockBytes::FindTransformedLockBytes
  263. (const WCHAR * pwszFileName,
  264. TransformDescriptor *pTransformDescriptor
  265. )
  266. {
  267. return CImpILockBytes::FindTransformedLockBytes(pwszFileName, pTransformDescriptor);
  268. }
  269. class CStrmLockBytes : public CITUnknown
  270. {
  271. public:
  272. // Destructor:
  273. ~CStrmLockBytes(void);
  274. // Creation:
  275. static HRESULT OpenUrlStream(const WCHAR *pwszURL, ILockBytes **pplkb);
  276. static HRESULT Create(IUnknown *punkOuter, IStream *pStrm, ILockBytes **pplkb);
  277. private:
  278. CStrmLockBytes(IUnknown *pUnkOuter);
  279. class CImpILockBytes : public IITLockBytes
  280. {
  281. public:
  282. // Constructor and Destructor:
  283. CImpILockBytes(CStrmLockBytes *pBackObj, IUnknown *punkOuter);
  284. ~CImpILockBytes(void);
  285. // Initialing routines:
  286. HRESULT InitUrlStream(const WCHAR *pwszURL);
  287. HRESULT Init(IStream *pStrm);
  288. // Search routine
  289. static ILockBytes *FindStrmLockBytes(const WCHAR * pwszFileName);
  290. // ILockBytes methods:
  291. HRESULT STDMETHODCALLTYPE ReadAt(
  292. /* [in] */ ULARGE_INTEGER ulOffset,
  293. /* [length_is][size_is][out] */ void __RPC_FAR *pv,
  294. /* [in] */ ULONG cb,
  295. /* [out] */ ULONG __RPC_FAR *pcbRead);
  296. HRESULT STDMETHODCALLTYPE WriteAt(
  297. /* [in] */ ULARGE_INTEGER ulOffset,
  298. /* [size_is][in] */ const void __RPC_FAR *pv,
  299. /* [in] */ ULONG cb,
  300. /* [out] */ ULONG __RPC_FAR *pcbWritten);
  301. HRESULT STDMETHODCALLTYPE Flush( void);
  302. HRESULT STDMETHODCALLTYPE SetSize(
  303. /* [in] */ ULARGE_INTEGER cb);
  304. HRESULT STDMETHODCALLTYPE LockRegion(
  305. /* [in] */ ULARGE_INTEGER libOffset,
  306. /* [in] */ ULARGE_INTEGER cb,
  307. /* [in] */ DWORD dwLockType);
  308. HRESULT STDMETHODCALLTYPE UnlockRegion(
  309. /* [in] */ ULARGE_INTEGER libOffset,
  310. /* [in] */ ULARGE_INTEGER cb,
  311. /* [in] */ DWORD dwLockType);
  312. HRESULT STDMETHODCALLTYPE Stat(
  313. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  314. /* [in] */ DWORD grfStatFlag);
  315. private:
  316. DEBUGDEF(static LONG s_cInCriticalSection) // Lock count
  317. IStream *m_pStream;
  318. CITCriticalSection m_cs;
  319. WCHAR m_awszLkBName[MAX_PATH]; // Path name for this lockbyte object
  320. };
  321. CImpILockBytes m_ImpILockBytes;
  322. };
  323. inline CStrmLockBytes::CStrmLockBytes(IUnknown *pUnkOuter)
  324. : m_ImpILockBytes(this, pUnkOuter),
  325. CITUnknown(&IID_ILockBytes, 1, &m_ImpILockBytes)
  326. {
  327. }
  328. inline CStrmLockBytes::~CStrmLockBytes(void)
  329. {
  330. }
  331. #endif // __LOCKBYTE_H__