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.

184 lines
5.6 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: wdfstrm.cxx
  7. //
  8. // Contents: CWrappedDocFile stream methods
  9. //
  10. // History: 22-Jan-92 DrewB Created
  11. //
  12. //---------------------------------------------------------------
  13. #include <dfhead.cxx>
  14. #pragma hdrstop
  15. #include <tstream.hxx>
  16. //+--------------------------------------------------------------
  17. //
  18. // Member: CWrappedDocFile::CreateStream, public
  19. //
  20. // Synopsis: Creates a wrapped stream
  21. //
  22. // Arguments: [pdfnName] - Name
  23. // [df] - Transactioning flags
  24. // [dlSet] - LUID to set or DF_NOLUID
  25. // [pppstStream] - Stream return
  26. //
  27. // Returns: Appropriate status code
  28. //
  29. // Modifies: [pppstStream]
  30. //
  31. // History: 09-Jan-92 DrewB Created
  32. //
  33. //---------------------------------------------------------------
  34. SCODE CWrappedDocFile::CreateStream(CDfName const *pdfnName,
  35. DFLAGS const df,
  36. DFLUID dlSet,
  37. PSStream **ppsstStream)
  38. {
  39. SEntryBuffer eb;
  40. SCODE sc;
  41. CTransactedStream *pstWrapped;
  42. CUpdate *pud = NULL;
  43. olDebugOut((DEB_ITRACE, "In CWrappedDocFile::CreateStream("
  44. "%ws, %X, %lu, %p)\n", pdfnName, df, dlSet,
  45. ppsstStream));
  46. if (SUCCEEDED(IsEntry(pdfnName, &eb)))
  47. olErr(EH_Err, STG_E_FILEALREADYEXISTS);
  48. olAssert(P_TRANSACTED(_df));
  49. if (dlSet == DF_NOLUID)
  50. dlSet = CTransactedStream::GetNewLuid(_pdfb->GetMalloc());
  51. pstWrapped = GetReservedStream(pdfnName, dlSet, _df);
  52. if (!P_NOUPDATE(df))
  53. {
  54. olMemTo(EH_pstWrapped,
  55. (pud = _ulChanged.Add(_pdfb->GetMalloc(),
  56. pdfnName, NULL, dlSet,
  57. STGTY_STREAM, pstWrapped)));
  58. }
  59. if (pstWrapped != NULL)
  60. {
  61. olChkTo(EH_pud, pstWrapped->Init(NULL));
  62. _ppubdf->AddXSMember(this, pstWrapped, dlSet);
  63. }
  64. *ppsstStream = pstWrapped;
  65. olDebugOut((DEB_ITRACE, "Out CWrappedDocFile::CreateStream => %p\n",
  66. *ppsstStream));
  67. return S_OK;
  68. EH_pud:
  69. if (pud)
  70. _ulChanged.Delete(pud);
  71. EH_pstWrapped:
  72. pstWrapped->ReturnToReserve(BP_TO_P(CDFBasis *, _pdfb));
  73. EH_Err:
  74. return sc;
  75. }
  76. //+--------------------------------------------------------------
  77. //
  78. // Member: CWrappedDocFile::GetStream, public
  79. //
  80. // Synopsis: Instantiates a wrapped stream
  81. //
  82. // Arguments: [pdfnName] - Name
  83. // [df] - Permissions
  84. // [pppstStream] - Stream return
  85. //
  86. // Returns: Appropriate status code
  87. //
  88. // Modifies: [pppstStream]
  89. //
  90. // History: 09-Jan-92 DrewB Created
  91. //
  92. //---------------------------------------------------------------
  93. SCODE CWrappedDocFile::GetStream(CDfName const *pdfnName,
  94. DFLAGS const df,
  95. PSStream **ppsstStream)
  96. {
  97. PSStream *psstNew;
  98. PTSetMember *ptsm;
  99. CTransactedStream *pstWrapped;
  100. SCODE sc;
  101. olDebugOut((DEB_ITRACE, "In CWrappedDocFile::GetStream("
  102. "%ws, %X, %p)\n", pdfnName, df, ppsstStream));
  103. olAssert(P_TRANSACTED(_df));
  104. // Look for this name in this level transaction set
  105. if ((ptsm = _ppubdf->FindXSMember(pdfnName, GetName())) != NULL)
  106. {
  107. if (ptsm->ObjectType() != STGTY_STREAM)
  108. olErr(EH_Err, STG_E_FILENOTFOUND);
  109. ptsm->AddRef();
  110. *ppsstStream = (CTransactedStream *)ptsm;
  111. }
  112. else if (_pdfBase == NULL ||
  113. _ulChanged.IsEntry(pdfnName, NULL) == UIE_ORIGINAL)
  114. {
  115. // named entry has been renamed or deleted
  116. // (we can't have a rename or delete without a base)
  117. olErr(EH_Err, STG_E_FILENOTFOUND);
  118. }
  119. else
  120. {
  121. // We didn't find it here, so we need to ask our parent
  122. // Find the right name to ask of the parent
  123. CDfName const *pdfnRealName = pdfnName;
  124. CUpdate *pud;
  125. if (_ulChanged.IsEntry(pdfnName, &pud) == UIE_CURRENT &&
  126. pud->IsRename())
  127. {
  128. pdfnRealName = pud->GetCurrentName();
  129. // We don't have to worry about picking up creates
  130. // because any create would have an XSM that would
  131. // be detected above
  132. olVerify(_ulChanged.FindBase(pud, &pdfnRealName) == NULL);
  133. }
  134. olAssert(_pdfBase != NULL);
  135. olChk(_pdfBase->GetStream(pdfnRealName, df, &psstNew));
  136. olAssert(psstNew->GetLuid() != DF_NOLUID &&
  137. aMsg("Stream id is DF_NOLUID!"));
  138. #ifdef USE_NOSCRATCH
  139. olMemTo(EH_Get, pstWrapped = new(_pdfb->GetMalloc())
  140. CTransactedStream(pdfnName, psstNew->GetLuid(), _df,
  141. _pdfb->GetBaseMultiStream(),
  142. _pdfb->GetScratch()));
  143. #else
  144. olMemTo(EH_Get, pstWrapped = new(_pdfb->GetMalloc())
  145. CTransactedStream(pdfnName, psstNew->GetLuid(), _df,
  146. _pdfb->GetScratch()));
  147. #endif
  148. olChkTo(EH_pstWrapped, pstWrapped->Init(psstNew));
  149. *ppsstStream = pstWrapped;
  150. _ppubdf->AddXSMember(this, pstWrapped, pstWrapped->GetLuid());
  151. }
  152. olDebugOut((DEB_ITRACE, "Out CWrappedDocFile::GetStream => %p\n",
  153. *ppsstStream));
  154. return S_OK;
  155. EH_pstWrapped:
  156. delete pstWrapped;
  157. EH_Get:
  158. psstNew->Release();
  159. EH_Err:
  160. return sc;
  161. }