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.

116 lines
3.3 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // File: chkdsk.cxx
  4. //
  5. // Contents: Sanity checking and recovery mechanism for multistream files
  6. //
  7. // Argument:
  8. //
  9. // History: August-21-92 t-chrisy Created.
  10. //------------------------------------------------------------------------
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <msf.hxx>
  14. #include <filest.hxx>
  15. #include <header.hxx>
  16. #include <fat.hxx>
  17. #include <wchar.h>
  18. #include <handle.hxx>
  19. #include <dfmsp.hxx>
  20. #include <dir.hxx>
  21. #define INVALID_DOCFILE 1
  22. #define FAIL_CREATE_MULTISTREAM 2
  23. #define INVALID_ARG 3
  24. #define FAIL_CREATE_ILB 4
  25. #define NONE 0
  26. #define TABLE_SIZE (SECTORSIZE/sizeof(SECT))
  27. //+-------------------------------------------------------------------------
  28. //
  29. // Function: DllMultiStreamFromCorruptedStream
  30. //
  31. // Synopsis: Create a new multistream instance from an existing stream.
  32. // This is used to reopen a stored multi-stream.
  33. //
  34. // Effects: Creates a new CMStream instance
  35. //
  36. // Arguments: [ppms] -- Pointer to storage for return of multistream
  37. // [pplstStream] -- Stream to be used by multi-stream for
  38. // reads and writes
  39. // [dwFlags] - Startup flags
  40. //
  41. // Returns: STG_E_INVALIDHEADER if signature on pStream does not
  42. // match.
  43. // STG_E_UNKNOWN if there was a problem in setup.
  44. // S_OK if call completed OK.
  45. //
  46. // Algorithm: Check the signature on the pStream and on the contents
  47. // of the pStream. If either is a mismatch, return
  48. // STG_E_INVALIDHEADER.
  49. // Create a new CMStream instance and run the setup function.
  50. // If the setup function fails, return STG_E_UNKNOWN.
  51. // Otherwise, return S_OK.
  52. //
  53. // History: 17-Aug-91 PhilipLa Created.
  54. // 26-Aug-92 t-chrisy modifed to reduce ErrJmp
  55. // Notes:
  56. //
  57. //--------------------------------------------------------------------------
  58. SCODE DllMultiStreamFromCorruptedStream(CMStream MSTREAM_NEAR **ppms,
  59. ILockBytes **pplstStream,
  60. DWORD dwFlags)
  61. {
  62. SCODE sc;
  63. CMStream MSTREAM_NEAR *temp;
  64. BOOL fConvert = ((dwFlags & RSF_CONVERT) != 0);
  65. BOOL fDelay = ((dwFlags & RSF_DELAY) != 0);
  66. BOOL fTruncate = ((dwFlags & RSF_TRUNCATE) != 0);
  67. msfDebugOut((DEB_ITRACE,"In DllMultiStreamFromStream\n"));
  68. msfMem(temp = new CMStream(pplstStream, NULL, SECTORSHIFT));
  69. ULARGE_INTEGER ulSize;
  70. (*pplstStream)->GetSize(&ulSize);
  71. msfAssert(ULIGetHigh(ulSize) == 0);
  72. msfDebugOut((DEB_ITRACE,"Size is: %lu\n",ULIGetLow(ulSize)));
  73. do
  74. {
  75. if ((ULIGetLow(ulSize) != 0) && (fConvert))
  76. {
  77. msfChk(temp->InitConvert(fDelay));
  78. break;
  79. }
  80. if ((ULIGetLow(ulSize) == 0) || (fTruncate))
  81. {
  82. msfChk(temp->InitNew(fDelay));
  83. break;
  84. }
  85. msfChk(temp->Init());
  86. if (FAILED(sc))
  87. msfDebugOut((DEB_ITRACE,"Fail to initialize multistream.\n"));
  88. }
  89. while (FALSE);
  90. *ppms = temp;
  91. msfDebugOut((DEB_ITRACE,"Leaving DllMultiStreamFromStream\n"));
  92. if (fConvert && ULIGetLow(ulSize) && !fDelay)
  93. return STG_I_CONVERTED;
  94. return S_OK;
  95. Err:
  96. delete temp;
  97. return sc;
  98. }