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.

191 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: msf.cxx
  7. //
  8. // Contents: Entry points for MSF DLL
  9. //
  10. // Classes: None.
  11. //
  12. // Functions: DllMuliStreamFromStream
  13. // DllConvertStreamToMultiStream
  14. // DllReleaseMultiStream
  15. // DllGetScratchMultiStream
  16. // DllIsMultiStream
  17. //
  18. //--------------------------------------------------------------------------
  19. #include "msfhead.cxx"
  20. #include "h/handle.hxx"
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Function: DllMultiStreamFromStrea
  24. //
  25. // Synopsis: Create a new multistream instance from an existing stream.
  26. // This is used to reopen a stored multi-stream.
  27. //
  28. // Effects: Creates a new CMStream instance
  29. //
  30. // Arguments: [ppms] -- Pointer to storage for return of multistream
  31. // [pplstStream] -- Stream to be used by multi-stream for
  32. // reads and writes
  33. // [dwFlags] - Startup flags
  34. //
  35. // Returns: STG_E_INVALIDHEADER if signature on pStream does not
  36. // match.
  37. // STG_E_UNKNOWN if there was a problem in setup.
  38. // S_OK if call completed OK.
  39. //
  40. // Algorithm: Check the signature on the pStream and on the contents
  41. // of the pStream. If either is a mismatch, return
  42. // STG_E_INVALIDHEADER.
  43. // Create a new CMStream instance and run the setup function.
  44. // If the setup function fails, return STG_E_UNKNOWN.
  45. // Otherwise, return S_OK.
  46. //
  47. // Notes:
  48. //
  49. //--------------------------------------------------------------------------
  50. SCODE DllMultiStreamFromStream(CMStream **ppms,
  51. ILockBytes **pplstStream,
  52. DWORD dwFlags)
  53. {
  54. SCODE sc;
  55. CMStream *temp;
  56. BOOL fConvert = ((dwFlags & RSF_CONVERT) != 0);
  57. BOOL fTruncate = ((dwFlags & RSF_TRUNCATE) != 0);
  58. BOOL fCreate = ((dwFlags & RSF_CREATE) != 0);
  59. msfDebugOut((DEB_ITRACE,"In DllMultiStreamFromStream\n"));
  60. msfMem(temp = new CMStream(pplstStream, SECTORSHIFT));
  61. STATSTG stat;
  62. (*pplstStream)->Stat(&stat, STATFLAG_NONAME);
  63. msfAssert(ULIGetHigh(stat.cbSize) == 0);
  64. msfDebugOut((DEB_ITRACE,"Size is: %lu\n",ULIGetLow(stat.cbSize)));
  65. do
  66. {
  67. if ((ULIGetLow(stat.cbSize) != 0) && (fConvert))
  68. {
  69. msfChk(temp->InitConvert());
  70. break;
  71. }
  72. if (((ULIGetLow(stat.cbSize) == 0) && fCreate) || (fTruncate))
  73. {
  74. msfChk(temp->InitNew());
  75. break;
  76. }
  77. msfChk(temp->Init());
  78. }
  79. while (FALSE);
  80. *ppms = temp;
  81. msfDebugOut((DEB_ITRACE,"Leaving DllMultiStreamFromStream\n"));
  82. if (fConvert && ULIGetLow(stat.cbSize))
  83. {
  84. return STG_S_CONVERTED;
  85. }
  86. return S_OK;
  87. Err:
  88. delete temp;
  89. return sc;
  90. }
  91. //+-------------------------------------------------------------------------
  92. //
  93. // Function: DllReleaseMultiStream
  94. //
  95. // Synopsis: Release a CMStream instance
  96. //
  97. // Effects: Deletes a multi-stream instance
  98. //
  99. // Arguments: [pms] -- pointer to object to be deleted
  100. //
  101. // Returns: S_OK.
  102. //
  103. // Modifies: Deletes the object pointed to by pMultiStream
  104. //
  105. // Algorithm: Delete the passed in pointer.
  106. //
  107. // Notes:
  108. //
  109. //--------------------------------------------------------------------------
  110. void DllReleaseMultiStream(CMStream *pms)
  111. {
  112. msfDebugOut((DEB_TRACE,"In DllReleaseMultiStream(%p)\n",pms));
  113. delete pms;
  114. msfDebugOut((DEB_TRACE,"Out DllReleaseMultiStream()\n"));
  115. }
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Function: DllIsMultiStream
  119. //
  120. // Synopsis: Check a given Lstream to determine if it is a valid
  121. // multistream.
  122. //
  123. // Arguments: [plst] -- Pointer to lstream to check
  124. //
  125. // Returns: S_OK if lstream is a valid multistream
  126. // STG_E_UNKNOWN otherwise
  127. //
  128. // Notes:
  129. //
  130. //--------------------------------------------------------------------------
  131. SCODE DllIsMultiStream(ILockBytes *plst)
  132. {
  133. SCODE sc;
  134. CMSFHeader *phdr;
  135. msfMem(phdr = new CMSFHeader(SECTORSHIFT));
  136. ULONG ulTemp;
  137. ULARGE_INTEGER ulOffset;
  138. ULISet32(ulOffset, 0);
  139. msfHChk(plst->ReadAt(ulOffset, phdr, sizeof(CMSFHeader), &ulTemp));
  140. phdr->ByteSwap(); // swap to machine format if neccessary
  141. if (ulTemp != sizeof(CMSFHeader))
  142. {
  143. msfErr(Err, STG_E_UNKNOWN);
  144. }
  145. msfChk(phdr->Validate());
  146. Err:
  147. delete phdr;
  148. return sc;
  149. }
  150. #if DEVL == 1
  151. //The following is a private function so I can set the debug level easily.
  152. VOID SetInfoLevel(ULONG x)
  153. {
  154. msfInfoLevel=x;
  155. }
  156. #endif