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.

506 lines
14 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: pbstream.hxx
  7. //
  8. // Contents: CPubStream definition
  9. //
  10. // Classes: CPubStream
  11. //
  12. // History: 16-Jan-92 PhilipLa Created.
  13. // 12-Jun-96 MikeHill Moved the body of the FlushNoException
  14. // method to the new Write method (except for
  15. // the Commit). Made Flush & FlushNoException
  16. // inline.
  17. // 21-Jun-96 MikeHill Declare CPubMappedStream::_pb as based.
  18. // 01-Jul-96 MikeHill - Adjust signatures for Win32 SEH removal.
  19. // - Added _powner member to CPubMappedStream.
  20. // 11-Feb-97 Danl - Make CPubMappedStream inherit from
  21. // IMappedStream and stub IUnknowns.
  22. //
  23. //--------------------------------------------------------------------------
  24. #ifndef __PBSTREAM_HXX__
  25. #define __PBSTREAM_HXX__
  26. #include <msf.hxx>
  27. #include <revert.hxx>
  28. #include <psstream.hxx>
  29. #include <smalloc.hxx>
  30. class CPubDocFile;
  31. class CPubStream;
  32. SAFE_DFBASED_PTR (CBasedPubStreamPtr, CPubStream);
  33. SAFE_DFBASED_PTR (CBasedMappedStreamPtr, IMappedStream);
  34. //+--------------------------------------------------------------
  35. //
  36. // Class: CPubMappedStream
  37. //
  38. // Purpose: Structure that lives in shared memory for
  39. // mapped stream implementation.
  40. //
  41. // History: 1-May-95 BillMo Created.
  42. //
  43. // Notes:
  44. //
  45. //---------------------------------------------------------------
  46. #ifdef NEWPROPS
  47. class CPubMappedStream
  48. {
  49. public:
  50. CPubMappedStream(CPubStream *pst)
  51. {
  52. _pb = NULL;
  53. _cbUsed = 0;
  54. _cbOriginalStreamSize = 0;
  55. _fDirty = FALSE;
  56. _fLowMem = FALSE;
  57. _fChangePending = FALSE;
  58. _pst = P_TO_BP(CBasedPubStreamPtr, pst);
  59. _powner = NULL;
  60. }
  61. ~CPubMappedStream()
  62. {
  63. msfAssert(_pb == NULL);
  64. }
  65. VOID Open(IN NTPROP np, OUT LONG *phr);
  66. VOID Close(OUT LONG *phr);
  67. VOID ReOpen(IN OUT VOID **ppv, OUT LONG *phr);
  68. VOID Quiesce(VOID);
  69. VOID Map(IN BOOLEAN fCreate, OUT VOID **ppv);
  70. VOID Unmap(IN BOOLEAN fFlush, IN OUT VOID **ppv);
  71. VOID Flush(OUT LONG *phr);
  72. ULONG GetSize(OUT LONG *phr);
  73. VOID SetSize(IN ULONG cb, IN BOOLEAN fPersistent, IN OUT VOID **ppv, OUT LONG *phr);
  74. NTSTATUS Lock(IN BOOLEAN fExclusive);
  75. NTSTATUS Unlock(VOID);
  76. VOID QueryTimeStamps(OUT STATPROPSETSTG *pspss, BOOLEAN fNonSimple) const;
  77. BOOLEAN QueryModifyTime(OUT LONGLONG *pll) const;
  78. BOOLEAN QuerySecurity(OUT ULONG *pul) const;
  79. BOOLEAN IsWriteable(VOID) const;
  80. BOOLEAN IsModified(VOID) const;
  81. VOID SetModified(OUT LONG *phr);
  82. HANDLE GetHandle(VOID) const;
  83. #if DBG
  84. BOOLEAN SetChangePending(BOOLEAN fChangePending);
  85. BOOLEAN IsNtMappedStream(VOID) const;
  86. #endif
  87. inline IMalloc * GetMalloc(VOID);
  88. inline VOID Cleanup(VOID);
  89. HRESULT Write ();
  90. #if DBG
  91. inline ULONG BytesCommitted(VOID) { return _cbUsed; }
  92. VOID DfpdbgFillUnusedMemory(VOID);
  93. VOID DfpdbgCheckUnusedMemory(VOID);
  94. #else
  95. VOID DfpdbgFillUnusedMemory(VOID) {}
  96. VOID DfpdbgCheckUnusedMemory(VOID) {}
  97. #endif
  98. private:
  99. CBasedPubStreamPtr _pst;
  100. CBasedBytePtr _pb;
  101. ULONG _cbUsed;
  102. ULONG _cbOriginalStreamSize;
  103. BOOLEAN _fDirty;
  104. BOOLEAN _fLowMem;
  105. BOOLEAN _fChangePending;
  106. CBasedBytePtr _powner; // Owner of this mapped stream.
  107. }; // class CPubMappedstream
  108. #endif
  109. //+--------------------------------------------------------------
  110. //
  111. // Class: CPubStream
  112. //
  113. // Purpose: Public stream interface
  114. //
  115. // Interface: See below
  116. //
  117. // History: 16-Jan-92 PhilipLa Created.
  118. //
  119. //---------------------------------------------------------------
  120. class CPubStream : public PRevertable
  121. {
  122. public:
  123. CPubStream(CPubDocFile *ppdf,
  124. DFLAGS df,
  125. CDfName const *pdfn);
  126. ~CPubStream();
  127. void Init(PSStream *psParent,
  128. DFLUID dlLUID);
  129. inline void vAddRef(void);
  130. void vRelease(void);
  131. // PRevertable
  132. void RevertFromAbove(void);
  133. #ifdef NEWPROPS
  134. SCODE FlushBufferedData(int recursionlevel);
  135. #endif
  136. SCODE Stat(STATSTGW *pstatstg, DWORD grfStatFlag);
  137. #ifdef LARGE_STREAMS
  138. inline SCODE ReadAt(ULONGLONG ulOffset,
  139. #else
  140. inline SCODE ReadAt(ULONG ulOffset,
  141. #endif
  142. VOID *pb,
  143. ULONG cb,
  144. ULONG STACKBASED *pcbRead);
  145. #ifdef LARGE_STREAMS
  146. inline SCODE WriteAt(ULONGLONG ulOffset,
  147. #else
  148. inline SCODE WriteAt(ULONG ulOffset,
  149. #endif
  150. VOID const HUGEP *pb,
  151. ULONG cb,
  152. ULONG STACKBASED *pcbWritten);
  153. #ifdef LARGE_STREAMS
  154. inline SCODE GetSize(ULONGLONG *pcb);
  155. inline SCODE SetSize(ULONGLONG cb);
  156. #else
  157. inline SCODE GetSize(ULONG *pcb);
  158. inline SCODE SetSize(ULONG cb);
  159. #endif
  160. inline PSStream *GetSt(void) const;
  161. #ifdef NEWPROPS
  162. inline CPubMappedStream & GetMappedStream(void);
  163. inline const CPubMappedStream & GetConstMappedStream(void);
  164. #endif
  165. inline SCODE CheckReverted(void) const;
  166. inline ULONG GetTransactedDepth () const;
  167. inline void SetClean(void);
  168. inline void SetDirty(void);
  169. SCODE Commit(DWORD dwFlags);
  170. inline void EmptyCache ();
  171. private:
  172. CBasedSStreamPtr _psParent;
  173. CBasedPubDocFilePtr _ppdfParent;
  174. BOOL _fDirty;
  175. LONG _cReferences;
  176. #ifdef NEWPROPS
  177. CPubMappedStream _PubMappedStream;
  178. #endif
  179. };
  180. //+--------------------------------------------------------------
  181. //
  182. // Member: CPubStream::CheckReverted, public
  183. //
  184. // Synopsis: Returns revertedness
  185. //
  186. // History: 11-Aug-92 DrewB Created
  187. //
  188. //---------------------------------------------------------------
  189. inline SCODE CPubStream::CheckReverted(void) const
  190. {
  191. return P_REVERTED(_df) ? STG_E_REVERTED : S_OK;
  192. }
  193. //+--------------------------------------------------------------
  194. //
  195. // Member: CPubStream::AddRef, public
  196. //
  197. // Synopsis: Increments the ref count
  198. //
  199. // History: 26-Feb-92 DrewB Created
  200. //
  201. //---------------------------------------------------------------
  202. inline void CPubStream::vAddRef(void)
  203. {
  204. InterlockedIncrement(&_cReferences);
  205. }
  206. //+--------------------------------------------------------------
  207. //
  208. // Member: CPubStream::GetSt, public
  209. //
  210. // Synopsis: Returns _psParent
  211. //
  212. // History: 26-Feb-92 DrewB Created
  213. //
  214. //---------------------------------------------------------------
  215. inline PSStream *CPubStream::GetSt(void) const
  216. {
  217. return BP_TO_P(PSStream *, _psParent);
  218. }
  219. //+--------------------------------------------------------------
  220. //
  221. // Member: CPubStream::GetMappedStream, public
  222. //
  223. // Synopsis: Returns this as a CPubMappedStream
  224. //
  225. // History: 26-May-95 BillMo Created
  226. //
  227. //---------------------------------------------------------------
  228. #ifdef NEWPROPS
  229. inline CPubMappedStream & CPubStream::GetMappedStream(void)
  230. {
  231. return _PubMappedStream;
  232. }
  233. inline const CPubMappedStream & CPubStream::GetConstMappedStream(void)
  234. {
  235. return _PubMappedStream;
  236. }
  237. #endif
  238. //+---------------------------------------------------------------------------
  239. //
  240. // Member: CPubStream::SetClean, public
  241. //
  242. // Synopsis: Resets the dirty flag
  243. //
  244. // History: 11-Nov-92 DrewB Created
  245. //
  246. //----------------------------------------------------------------------------
  247. inline void CPubStream::SetClean(void)
  248. {
  249. _fDirty = FALSE;
  250. }
  251. //+---------------------------------------------------------------------------
  252. //
  253. // Member: CPubStream::SetDirty, public
  254. //
  255. // Synopsis: Sets the dirty flag
  256. //
  257. // History: 11-Nov-92 DrewB Created
  258. //
  259. //----------------------------------------------------------------------------
  260. inline void CPubStream::SetDirty(void)
  261. {
  262. _fDirty = TRUE;
  263. _ppdfParent->SetDirty();
  264. }
  265. //+-------------------------------------------------------------------------
  266. //
  267. // Method: CPubStream::ReadAt, public
  268. //
  269. // Synopsis: Read from a stream
  270. //
  271. // Arguments: [ulOffset] - Byte offset to read from
  272. // [pb] - Buffer
  273. // [cb] - Count of bytes to read
  274. // [pcbRead] - Return number of bytes actually read
  275. //
  276. // Returns: Appropriate status code
  277. //
  278. // Modifies: [pcbRead]
  279. //
  280. // History: 16-Jan-92 PhilipLa Created.
  281. //
  282. //--------------------------------------------------------------------------
  283. #ifdef LARGE_STREAMS
  284. inline SCODE CPubStream::ReadAt(ULONGLONG ulOffset,
  285. #else
  286. inline SCODE CPubStream::ReadAt(ULONG ulOffset,
  287. #endif
  288. VOID *pb,
  289. ULONG cb,
  290. ULONG STACKBASED *pcbRead)
  291. {
  292. SCODE sc;
  293. if (SUCCEEDED(sc = CheckReverted()))
  294. if (!P_READ(_df))
  295. sc = STG_E_ACCESSDENIED;
  296. else
  297. sc = _psParent->ReadAt(ulOffset,pb,cb,pcbRead);
  298. return sc;
  299. }
  300. //+-------------------------------------------------------------------------
  301. //
  302. // Method: CPubStream::WriteAt, public
  303. //
  304. // Synopsis: Write to a stream
  305. //
  306. // Arguments: [ulOffset] - Byte offset to write at
  307. // [pb] - Buffer
  308. // [cb] - Count of bytes to write
  309. // [pcbWritten] - Return number of bytes actually written
  310. //
  311. // Returns: Appropriate status code
  312. //
  313. // Modifies: [pcbWritten]
  314. //
  315. // History: 16-Jan-92 PhilipLa Created.
  316. //
  317. //--------------------------------------------------------------------------
  318. #ifdef LARGE_STREAMS
  319. inline SCODE CPubStream::WriteAt(ULONGLONG ulOffset,
  320. #else
  321. inline SCODE CPubStream::WriteAt(ULONG ulOffset,
  322. #endif
  323. VOID const HUGEP *pb,
  324. ULONG cb,
  325. ULONG STACKBASED *pcbWritten)
  326. {
  327. SCODE sc;
  328. if (SUCCEEDED(sc = CheckReverted()))
  329. if (!P_WRITE(_df))
  330. sc = STG_E_ACCESSDENIED;
  331. else
  332. {
  333. sc = _psParent->WriteAt(ulOffset,pb,cb,pcbWritten);
  334. if (SUCCEEDED(sc))
  335. SetDirty();
  336. }
  337. return sc;
  338. }
  339. //+--------------------------------------------------------------
  340. //
  341. // Member: CPubStream::GetSize, public
  342. //
  343. // Synopsis: Gets the size of the stream
  344. //
  345. // Arguments: [pcb] - Stream size return
  346. //
  347. // Returns: Appropriate status code
  348. //
  349. // Modifies: [pcb]
  350. //
  351. // History: 30-Apr-92 DrewB Created
  352. //
  353. //---------------------------------------------------------------
  354. #ifdef LARGE_STREAMS
  355. inline SCODE CPubStream::GetSize(ULONGLONG *pcb)
  356. #else
  357. inline SCODE CPubStream::GetSize(ULONG *pcb)
  358. #endif
  359. {
  360. SCODE sc;
  361. if (SUCCEEDED(sc = CheckReverted()))
  362. _psParent->GetSize(pcb);
  363. return sc;
  364. }
  365. //+-------------------------------------------------------------------------
  366. //
  367. // Member: CPubStream::SetSize, public
  368. //
  369. // Synposis: Set the size of a linear stream
  370. //
  371. // Arguments: [ulNewSize] -- New size for stream
  372. //
  373. // Returns: Error code returned by MStream call.
  374. //
  375. // Algorithm: Pass call up to parent.
  376. //
  377. // History: 29-Jul-91 PhilipLa Created.
  378. // 16-Jan-92 PhilipLa Moved from CSStream to CPubStream
  379. //
  380. //---------------------------------------------------------------------------
  381. #ifdef LARGE_STREAMS
  382. inline SCODE CPubStream::SetSize(ULONGLONG ulNewSize)
  383. #else
  384. inline SCODE CPubStream::SetSize(ULONG ulNewSize)
  385. #endif
  386. {
  387. SCODE sc;
  388. if (SUCCEEDED(sc = CheckReverted()))
  389. if (!P_WRITE(_df))
  390. sc = STG_E_ACCESSDENIED;
  391. else
  392. {
  393. sc = _psParent->SetSize(ulNewSize);
  394. if (SUCCEEDED(sc))
  395. SetDirty();
  396. }
  397. return sc;
  398. }
  399. //+-------------------------------------------------------------------------
  400. //
  401. // Member: CPubStream::EmptyCache, public
  402. //
  403. // Synposis: empties the stream cache for compaction
  404. //
  405. // History: 29-Jul-99 HenryLee Created.
  406. //
  407. //---------------------------------------------------------------------------
  408. inline void CPubStream::EmptyCache ()
  409. {
  410. _psParent->EmptyCache();
  411. }
  412. //+--------------------------------------------------------------
  413. //
  414. // Member: CPubStream::GetTransactedDepth, public
  415. //
  416. // Synopsis: Returns transaction depth level from parent
  417. //
  418. // History: 11-Aug-92 DrewB Created
  419. //
  420. //---------------------------------------------------------------
  421. inline ULONG CPubStream::GetTransactedDepth() const
  422. {
  423. return _ppdfParent->GetTransactedDepth();
  424. }
  425. //+-------------------------------------------------------------------------
  426. //
  427. // Member: CPubMappedStream::GetMalloc, public
  428. //
  429. // Synposis: Get the allocator for the stream.
  430. //
  431. //---------------------------------------------------------------------------
  432. #ifdef NEWPROPS
  433. inline IMalloc * CPubMappedStream::GetMalloc(void)
  434. {
  435. return &g_smAllocator;
  436. }
  437. inline VOID CPubMappedStream::Cleanup(VOID)
  438. {
  439. if (!_fLowMem)
  440. GetMalloc()->Free(BP_TO_P(BYTE *, _pb));
  441. _pb = NULL;
  442. }
  443. #endif
  444. #endif //__PBSTREAM_HXX__