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.

260 lines
10 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. MTFSessn.h
  5. Abstract:
  6. Definition of the CMTFSession class
  7. Author:
  8. Brian Dodd [brian] 25-Nov-1997
  9. Revision History:
  10. --*/
  11. #if !defined(MTFSessn_H)
  12. #define MTFSessn_H
  13. #if _MSC_VER >= 1000
  14. #pragma once
  15. #endif // _MSC_VER >= 1000
  16. #include "resource.h" // main symbols
  17. #include "mtfapi.h"
  18. //
  19. // REMOTE_STORAGE_MTF_VENDOR_ID - This is the unique vendor Id assigned for Microsoft Remote Storage.
  20. // Used in Whistler (NT 5.1) and beyond
  21. //
  22. // REMOTE_STORAGE_WIN2K_MTF_VENDOR_ID - This is the unique vendor Id assigned
  23. // to Eastman Software (Spring, 1997), by Seagate.
  24. // Used in Win2K (NT 5.0) Remote Storage
  25. //
  26. #define REMOTE_STORAGE_WIN2K_MTF_VENDOR_ID 0x1300
  27. #define REMOTE_STORAGE_MTF_VENDOR_ID 0x1515
  28. //
  29. // REMOTE_STORAGE_MTF_VENDOR_NAME -- This is the vendor name used for MTF labels.
  30. //
  31. #define REMOTE_STORAGE_MTF_VENDOR_NAME OLESTR("Microsoft Corporation")
  32. //
  33. // REMOTE_STORAGE_MTF_SOFTWARE_VERSION_MJ -- This the the major version number
  34. // for Remote Storage
  35. //
  36. #define REMOTE_STORAGE_MTF_SOFTWARE_VERSION_MJ 1
  37. //
  38. // REMOTE_STORAGE_MTF_SOFTWARE_VERSION_MN -- This the the minor version number
  39. // for Remote Storage
  40. //
  41. #define REMOTE_STORAGE_MTF_SOFTWARE_VERSION_MN 0
  42. /*++
  43. Enumeration Name:
  44. MTFSessionType
  45. Description:
  46. Specifies a type of data set.
  47. --*/
  48. typedef enum MTFSessionType {
  49. MTFSessionTypeTransfer = 0,
  50. MTFSessionTypeCopy,
  51. MTFSessionTypeNormal,
  52. MTFSessionTypeDifferential,
  53. MTFSessionTypeIncremental,
  54. MTFSessionTypeDaily,
  55. };
  56. //
  57. // MVR_DEBUG_OUTPUT - Special flag used for outputing extra debug info
  58. //
  59. #ifdef DBG
  60. #define MVR_DEBUG_OUTPUT TRUE
  61. #else
  62. #define MVR_DEBUG_OUTPUT FALSE
  63. #endif
  64. //
  65. // MrvInjectError - Special macro for allowing test running to inject
  66. // device errors at specific location throughout the
  67. // data mover.
  68. //
  69. /*++
  70. Macro Name:
  71. MrvInjectError
  72. Macro Description:
  73. Special macro for allowing test running to inject device errors
  74. at specific location throughout the data mover.
  75. Arguments:
  76. injectPoint - A UNICODE string describing the injection point.
  77. --*/
  78. #ifdef DBG
  79. #define MvrInjectError(injectPoint) \
  80. { \
  81. DWORD size; \
  82. OLECHAR tmpString[256]; \
  83. if (SUCCEEDED(WsbGetRegistryValueString(NULL, RMS_REGISTRY_STRING, injectPoint, tmpString, 256, &size))) { \
  84. DWORD injectHr; \
  85. injectHr = wcstoul(tmpString, NULL, 16); \
  86. if (injectHr) { \
  87. WsbTrace(OLESTR("%ls - Injecting Error <%ls>\n"), injectPoint, WsbHrAsString(injectHr)); \
  88. if (IDOK == MessageBox(NULL, L"Inject error, then press OK. Cancel skips over this injection point.", injectPoint, MB_OKCANCEL)) { \
  89. if (injectHr != S_FALSE) { \
  90. WsbThrow(injectHr); \
  91. } \
  92. } \
  93. } \
  94. } \
  95. }
  96. #else
  97. #define MvrInjectError(injectPoint)
  98. #endif
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CMTFSession
  101. class CMTFSession
  102. {
  103. public:
  104. CMTFSession();
  105. ~CMTFSession();
  106. // TODO: Add SetStream() for m_pStream, and replace m_sHints with object that supports IRemoteStorageHint
  107. CComPtr<IStream> m_pStream; // Stream used for I/O.
  108. MVR_REMOTESTORAGE_HINTS m_sHints; // We keep the information need for
  109. // optimized retrieval of the file/data.
  110. HRESULT SetBlockSize(UINT32 blockSize);
  111. HRESULT SetUseFlatFileStructure(BOOL val);
  112. HRESULT SetUseSoftFilemarks(BOOL val);
  113. HRESULT SetUseCaseSensitiveSearch(BOOL val);
  114. HRESULT SetCommitFile(BOOL val);
  115. // MTF Formatting methods
  116. HRESULT InitCommonHeader(void);
  117. HRESULT DoTapeDblk(IN WCHAR* szLabel, IN ULONG maxIdSize, IN OUT BYTE* pIdentifier, IN OUT ULONG* pIdSize, IN OUT ULONG* pIdType);
  118. HRESULT DoSSETDblk(IN WCHAR* szSessionName, IN WCHAR* szSessionDescription, IN MTFSessionType type, IN USHORT nDataSetNumber);
  119. HRESULT DoVolumeDblk(IN WCHAR* szPath);
  120. HRESULT DoDataSet(IN WCHAR* szPath);
  121. HRESULT DoParentDirectories(IN WCHAR* szPath);
  122. HRESULT DoDirectoryDblk(IN WCHAR* szPath, IN WIN32_FIND_DATAW* pFindData);
  123. HRESULT DoFileDblk(IN WCHAR* szPath, IN WIN32_FIND_DATAW* pFindData);
  124. HRESULT DoDataStream(IN HANDLE hStream);
  125. HRESULT DoEndOfDataSet(IN USHORT nDataSetNumber);
  126. HRESULT ExtendLastPadToNextPBA(void);
  127. // Read methods
  128. HRESULT ReadTapeDblk(OUT WCHAR **pszLabel);
  129. // Validate methods (for Recovery usage)
  130. HRESULT SkipOverTapeDblk(void);
  131. HRESULT SkipOverSSETDblk(OUT USHORT* pDataSetNumber);
  132. HRESULT SkipToDataSet(void);
  133. HRESULT SkipOverDataSet(void);
  134. HRESULT SkipOverEndOfDataSet(void);
  135. HRESULT PrepareForEndOfDataSet(void);
  136. private:
  137. HRESULT PadToNextPBA(void);
  138. HRESULT PadToNextFLA(BOOL flush);
  139. // For Recovery usage
  140. HRESULT SkipOverStreams(IN UINT64 uOffsetToFirstStream);
  141. private:
  142. enum { // Class specific constants:
  143. //
  144. Version = 1, // Class version, this should be
  145. // incremented each time the
  146. // the class definition changes.
  147. };
  148. // Session data
  149. UINT32 m_nCurrentBlockId; // Used for "control_block_id" in common header.
  150. // We increment this for each dblk written.
  151. UINT32 m_nDirectoryId; // Tracks the directory id used in DIRB and FILE
  152. // DBLKs. We increment this for each directory
  153. // written.
  154. UINT32 m_nFileId; // Tracks the file id used in FILE dblks. We
  155. // increment this for each file written.
  156. UINT64 m_nFormatLogicalAddress;// We need to keep track of how many alignment
  157. // indicies we are away from the SSET, as this
  158. // info is used in the common block headers.
  159. // We increment this for each alignment index
  160. // written, including streams, to the device.
  161. UINT64 m_nPhysicalBlockAddress;// Hold onto the PBA of the beginning of the SSET.
  162. UINT32 m_nBlockSize; // Physical Block Size of the media used.
  163. MTF_DBLK_SFMB_INFO* m_pSoftFilemarks; // Holds Soft Filemark information.
  164. MTF_DBLK_HDR_INFO m_sHeaderInfo; // We keep one header info struct here,
  165. // fill it in once, and then just make
  166. // changes as necessary as we supply it
  167. // to MTF_Write... calls.
  168. MTF_DBLK_SSET_INFO m_sSetInfo; // We keep the data set info struct to handle
  169. // special case DBLK formatting.
  170. MTF_DBLK_VOLB_INFO m_sVolInfo; // We keep the volume info struct to handle
  171. // special case DBLK formatting.
  172. BYTE * m_pBuffer; // The buffer used to format data (with virtual address aligend to sectore size)
  173. BYTE * m_pRealBuffer; // The actual buffer
  174. size_t m_nBufUsed; // The number of bytes in the buffer with valid data.
  175. size_t m_nBufSize; // The size of the buffer.
  176. size_t m_nStartOfPad; // Holds the location within the transfer buffer
  177. // of the last SPAD.
  178. BOOL m_bUseFlatFileStructure;// If TRUE, Directory information is not written to
  179. // the MTF session, and filenames are mangled
  180. // to preserve uniqueness.
  181. BOOL m_bUseSoftFilemarks; // If TRUE, filemark emulation is turned on.
  182. BOOL m_bUseCaseSensitiveSearch; // If TRUE, all filename queries are case sensitve (i.e. Posix Semantics)
  183. BOOL m_bCommitFile; // If TRUE, flushes devices buffers after file is
  184. // written to the data set.
  185. BOOL m_bSetInitialized; // If TRUE, sSet was initialized (for detecting Recovery)
  186. FILE_BASIC_INFORMATION m_SaveBasicInformation; // Basic info for last file/dir (see notes on CloseStream).
  187. void * m_pvReadContext; // Holds BackupRead context info.
  188. CMTFApi * m_pMTFApi; // Object that implements internal MTF details
  189. // MTF I/O abstracton methods
  190. HRESULT OpenStream(IN WCHAR* szPath, OUT HANDLE *pStreamHandle);
  191. HRESULT CloseStream(IN HANDLE hStream);
  192. HRESULT WriteToDataSet(IN BYTE* pBuffer, IN ULONG nBytesToWrite, OUT ULONG* pBytesWritten);
  193. HRESULT ReadFromDataSet(IN BYTE* pBuffer, IN ULONG nBytesToRead, OUT ULONG* pBytesRead);
  194. HRESULT FlushBuffer(IN BYTE* pBuffer, IN OUT size_t* pBufPosition);
  195. HRESULT WriteFilemarks(IN ULONG count);
  196. HRESULT GetCurrentPBA(OUT UINT64* pPosition);
  197. HRESULT SetCurrentPBA(IN UINT64 position);
  198. HRESULT SpaceToEOD(void);
  199. HRESULT SpaceToBOD(void);
  200. };
  201. #endif // !defined(MTFSessn_H)