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.

291 lines
9.9 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. NtTapeIo.h
  5. Abstract:
  6. Definition of the CNtTapeIo class
  7. Author:
  8. Brian Dodd [brian] 01-Apr-1997
  9. Revision History:
  10. --*/
  11. #if !defined(NtTapeIo_H)
  12. #define NtTapeIo_H
  13. #if _MSC_VER >= 1000
  14. #pragma once
  15. #endif // _MSC_VER >= 1000
  16. #include "resource.h" // main symbols
  17. #include "MTFSessn.h" // CMTFSession
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CNtTapeIo
  20. class CNtTapeIo :
  21. public CComDualImpl<IDataMover, &IID_IDataMover, &LIBID_MOVERLib>,
  22. public IStream,
  23. public ISupportErrorInfo,
  24. public IWsbCollectable,
  25. public CComObjectRoot,
  26. public CComCoClass<CNtTapeIo,&CLSID_CNtTapeIo>
  27. {
  28. public:
  29. CNtTapeIo() {}
  30. BEGIN_COM_MAP(CNtTapeIo)
  31. COM_INTERFACE_ENTRY2(IDispatch, IDataMover)
  32. COM_INTERFACE_ENTRY(IDataMover)
  33. COM_INTERFACE_ENTRY(IStream)
  34. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  35. COM_INTERFACE_ENTRY(IWsbCollectable)
  36. END_COM_MAP()
  37. //DECLARE_NOT_AGGREGATABLE(CNtTapeIo)
  38. // Remove the comment from the line above if you don't want your object to
  39. // support aggregation.
  40. DECLARE_REGISTRY_RESOURCEID(IDR_CNtTapeIo)
  41. // ISupportsErrorInfo
  42. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  43. // CComObjectRoot
  44. public:
  45. ULONG InternalAddRef(void);
  46. ULONG InternalRelease(void);
  47. STDMETHOD( FinalConstruct )(void);
  48. STDMETHOD( FinalRelease )(void);
  49. // IWsbCollectable
  50. public:
  51. STDMETHOD(CompareTo)( IN IUnknown *pCollectable, OUT SHORT *pResult);
  52. STDMETHOD(IsEqual)(IUnknown* pCollectable);
  53. // IDataMover
  54. public:
  55. STDMETHOD(GetObjectId)(OUT GUID *pObjectId);
  56. STDMETHOD( BeginSession )(
  57. IN BSTR remoteSessionName,
  58. IN BSTR remoteSessionDescription,
  59. IN SHORT remoteDataSet,
  60. IN DWORD options);
  61. STDMETHOD( EndSession )(void);
  62. STDMETHOD( StoreData )(
  63. IN BSTR localName,
  64. IN ULARGE_INTEGER localDataStart,
  65. IN ULARGE_INTEGER localDataSize,
  66. IN DWORD flags,
  67. OUT ULARGE_INTEGER *pRemoteDataSetStart,
  68. OUT ULARGE_INTEGER *pRemoteFileStart,
  69. OUT ULARGE_INTEGER *pRemoteFileSize,
  70. OUT ULARGE_INTEGER *pRemoteDataStart,
  71. OUT ULARGE_INTEGER *pRemoteDataSize,
  72. OUT DWORD *pRemoteVerificationType,
  73. OUT ULARGE_INTEGER *pRemoteVerificationData,
  74. OUT DWORD *pDatastreamCRCType,
  75. OUT ULARGE_INTEGER *pDatastreamCRC,
  76. OUT ULARGE_INTEGER *pUsn);
  77. STDMETHOD( RecallData )(
  78. IN BSTR localName,
  79. IN ULARGE_INTEGER localDataStart,
  80. IN ULARGE_INTEGER localDataSize,
  81. IN DWORD flags,
  82. IN BSTR migrateSessionName,
  83. IN ULARGE_INTEGER remoteDataSetStart,
  84. IN ULARGE_INTEGER remoteFileStart,
  85. IN ULARGE_INTEGER remoteFileSize,
  86. IN ULARGE_INTEGER remoteDataStart,
  87. IN ULARGE_INTEGER remoteDataSize,
  88. IN DWORD remoteVerificationType,
  89. IN ULARGE_INTEGER remoteVerificationData);
  90. STDMETHOD( FormatLabel )(
  91. IN BSTR displayName,
  92. OUT BSTR *pLabel);
  93. STDMETHOD( WriteLabel )(
  94. IN BSTR label);
  95. STDMETHOD( ReadLabel )(
  96. IN OUT BSTR *pLabel );
  97. STDMETHOD( VerifyLabel )(
  98. IN BSTR label);
  99. STDMETHOD( GetDeviceName )(
  100. OUT BSTR *pName);
  101. STDMETHOD( SetDeviceName )(
  102. IN BSTR name,
  103. IN BSTR unused);
  104. STDMETHOD( GetLargestFreeSpace )(
  105. OUT LONGLONG *pFreeSpace,
  106. OUT LONGLONG *pCapacity,
  107. IN ULONG defaultFreeSpaceLow = 0xFFFFFFFF,
  108. IN LONG defaultFreeSpaceHigh = 0xFFFFFFFF);
  109. STDMETHOD( SetInitialOffset )(
  110. IN ULARGE_INTEGER initialOffset);
  111. STDMETHOD( GetCartridge )(
  112. OUT IRmsCartridge **ptr);
  113. STDMETHOD( SetCartridge )(
  114. IN IRmsCartridge *ptr);
  115. STDMETHOD( Cancel )(void);
  116. STDMETHOD( CreateLocalStream )(
  117. IN BSTR name,
  118. IN DWORD mode,
  119. OUT IStream **ppStream);
  120. STDMETHOD( CreateRemoteStream )(
  121. IN BSTR name,
  122. IN DWORD mode,
  123. IN BSTR remoteSessionName,
  124. IN BSTR remoteSessionDescription,
  125. IN ULARGE_INTEGER remoteDataSetStart,
  126. IN ULARGE_INTEGER remoteFileStart,
  127. IN ULARGE_INTEGER remoteFileSize,
  128. IN ULARGE_INTEGER remoteDataStart,
  129. IN ULARGE_INTEGER remoteDataSize,
  130. IN DWORD remoteVerificationType,
  131. IN ULARGE_INTEGER remoteVerificationData,
  132. OUT IStream **ppStream);
  133. STDMETHOD( CloseStream )(void);
  134. STDMETHOD( Duplicate )(
  135. IN IDataMover *pDestination,
  136. IN DWORD options,
  137. OUT ULARGE_INTEGER *pBytesCopied,
  138. OUT ULARGE_INTEGER *pBytesReclaimed);
  139. STDMETHOD( FlushBuffers )(void);
  140. STDMETHOD( Recover )(OUT BOOL *pDeleteFile);
  141. // IStream
  142. public:
  143. STDMETHOD( Read )(
  144. OUT void *pv,
  145. IN ULONG cb,
  146. OUT ULONG *pcbRead);
  147. STDMETHOD( Write )(
  148. OUT void const *pv,
  149. IN ULONG cb,
  150. OUT ULONG *pcbWritten);
  151. STDMETHOD( Seek )(
  152. IN LARGE_INTEGER dlibMove,
  153. IN DWORD dwOrigin,
  154. OUT ULARGE_INTEGER *plibNewPosition);
  155. STDMETHOD( SetSize )(
  156. IN ULARGE_INTEGER libNewSize);
  157. STDMETHOD( CopyTo )(
  158. IN IStream *pstm,
  159. IN ULARGE_INTEGER cb,
  160. OUT ULARGE_INTEGER *pcbRead,
  161. OUT ULARGE_INTEGER *pcbWritten);
  162. STDMETHOD( Commit )(
  163. IN DWORD grfCommitFlags);
  164. STDMETHOD( Revert )(void);
  165. STDMETHOD( LockRegion )(
  166. IN ULARGE_INTEGER libOffset,
  167. IN ULARGE_INTEGER cb,
  168. IN DWORD dwLockType);
  169. STDMETHOD( UnlockRegion )(
  170. IN ULARGE_INTEGER libOffset,
  171. IN ULARGE_INTEGER cb,
  172. IN DWORD dwLockType);
  173. STDMETHOD( Stat )(
  174. OUT STATSTG *pstatstg,
  175. IN DWORD grfStatFlag);
  176. STDMETHOD( Clone )(
  177. OUT IStream **ppstm);
  178. private:
  179. enum { // Class specific constants:
  180. //
  181. Version = 1, // Class version, this should be
  182. // incremented each time the
  183. // the class definition changes.
  184. DefaultBlockSize = RMS_DEFAULT_BLOCK_SIZE, // Default block size to use.
  185. DefaultMinBufferSize = RMS_DEFAULT_BUFFER_SIZE, // Default minimum buffer size.
  186. };
  187. GUID m_ObjectId; // Unique ID for this object.
  188. CMTFSession* m_pSession; // Holds all session information.
  189. SHORT m_DataSetNumber; // Holds the current dataset number.
  190. HANDLE m_hTape; // Tape drive handle.
  191. CWsbBstrPtr m_DeviceName; // The name of the tape device.
  192. DWORD m_Flags; // Holds data transfer type flag.
  193. CWsbBstrPtr m_LastVolume; // Name of the last volume backed up.
  194. CWsbBstrPtr m_LastPath; // Name of the last directory backed up.
  195. BOOL m_ValidLabel; // True if the label is valid, the flag
  196. // knocked down on BUS_RESET and Medium
  197. // errors, and assumed valid at initialization.
  198. TAPE_GET_MEDIA_PARAMETERS m_sMediaParameters; // We store media and drive parameters
  199. // here when we open up the tape device...
  200. TAPE_GET_DRIVE_PARAMETERS m_sDriveParameters; //
  201. CWsbBstrPtr m_StreamName; // Stream state information...
  202. ULONG m_Mode; // The kind of I/O. See MVR_MODE_*
  203. ULARGE_INTEGER m_StreamPBA; // The PBA for the current Stream. Used to tell if read ops are aligned with tape.
  204. ULARGE_INTEGER m_StreamOffset; // The Current offset into the data stream
  205. ULARGE_INTEGER m_StreamSize; // The size of the data stream
  206. BYTE * m_pStreamBuf; // Internal stream buffer used to handle I/O for boundary conditions
  207. ULONG m_StreamBufSize; // Max size of the internal stream buffer
  208. ULONG m_StreamBufUsed; // The number of bytes of the internal stream buffer containing valid data
  209. ULONG m_StreamBufPosition; // The current position of the stream pointer.
  210. ULARGE_INTEGER m_StreamBufStartPBA; // The corresponding starting PBA for the internal stream buffer
  211. CComPtr<IRmsCartridge> m_pCartridge; // A reference to the Cartridge in use by the DataMover.
  212. CRITICAL_SECTION m_CriticalSection; // Object sychronization support
  213. BOOL m_bCritSecCreated; // Indicates whether all CritSec were created successfully (for cleanup)
  214. static int s_InstanceCount; // Counter of the number of object instances.
  215. // Tape I/O
  216. HRESULT OpenTape(void);
  217. HRESULT CloseTape(void);
  218. HRESULT WriteBuffer(IN BYTE *pBuffer, IN ULONG nBytesToWrite, OUT ULONG *pBytesWritten);
  219. HRESULT ReadBuffer(IN BYTE *pBuffer, IN ULONG nBytesToRead, OUT ULONG *pBytesRead);
  220. HRESULT WriteFilemarks(IN ULONG count);
  221. HRESULT GetPosition(OUT UINT64 *pPosition);
  222. HRESULT SetPosition(IN UINT64 position);
  223. HRESULT EnsurePosition(IN UINT64 position);
  224. HRESULT SpaceFilemarks(IN LONG count, OUT UINT64 *pPosition);
  225. HRESULT SpaceToEndOfData(OUT UINT64 *pPosition);
  226. HRESULT RewindTape(void);
  227. HRESULT MapTapeError(IN HRESULT hrToMap, IN WCHAR *pAction);
  228. HRESULT IsAccessEnabled(void);
  229. HRESULT Lock(void);
  230. HRESULT Unlock(void);
  231. };
  232. #endif // !defined(NtTapeIo_H)