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.

287 lines
9.4 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. NtFileIo.h
  5. Abstract:
  6. Definition of the CNtFileIo class
  7. Author:
  8. Brian Dodd [brian] 25-Nov-1997
  9. Revision History:
  10. --*/
  11. #if !defined(NtFileIo_H)
  12. #define NtFileIo_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. // CNtFileIo
  20. class CNtFileIo :
  21. public CComDualImpl<IDataMover, &IID_IDataMover, &LIBID_MOVERLib>,
  22. public IStream,
  23. public ISupportErrorInfo,
  24. public IWsbCollectable,
  25. public CComObjectRoot,
  26. public CComCoClass<CNtFileIo,&CLSID_CNtFileIo>
  27. {
  28. public:
  29. CNtFileIo() {}
  30. BEGIN_COM_MAP(CNtFileIo)
  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(CNtFileIo)
  38. // Remove the comment from the line above if you don't want your object to
  39. // support aggregation.
  40. DECLARE_REGISTRY_RESOURCEID(IDR_CNtFileIo)
  41. // ISupportsErrorInfo
  42. STDMETHOD(InterfaceSupportsErrorInfo)(
  43. IN REFIID riid);
  44. // CComObjectRoot
  45. public:
  46. STDMETHOD(FinalConstruct)(void);
  47. STDMETHOD(FinalRelease)(void);
  48. // IWsbCollectable
  49. public:
  50. STDMETHOD(CompareTo)( IN IUnknown *pCollectable, OUT SHORT *pResult);
  51. STDMETHOD(IsEqual)(IUnknown* pCollectable);
  52. // IDataMover
  53. public:
  54. STDMETHOD(GetObjectId)(OUT GUID *pObjectId);
  55. STDMETHOD( BeginSession )(
  56. IN BSTR remoteSessionName,
  57. IN BSTR remoteSessionDescription,
  58. IN SHORT remoteDataSet,
  59. IN DWORD options);
  60. STDMETHOD( EndSession )(void);
  61. STDMETHOD( StoreData )(
  62. IN BSTR localName,
  63. IN ULARGE_INTEGER localDataStart,
  64. IN ULARGE_INTEGER localDataSize,
  65. IN DWORD flags,
  66. OUT ULARGE_INTEGER *pRemoteDataSetStart,
  67. OUT ULARGE_INTEGER *pRemoteFileStart,
  68. OUT ULARGE_INTEGER *pRemoteFileSize,
  69. OUT ULARGE_INTEGER *pRemoteDataStart,
  70. OUT ULARGE_INTEGER *pRemoteDataSize,
  71. OUT DWORD *pRemoteVerificationType,
  72. OUT ULARGE_INTEGER *pRemoteVerificationData,
  73. OUT DWORD *pDatastreamCRCType,
  74. OUT ULARGE_INTEGER *pDatastreamCRC,
  75. OUT ULARGE_INTEGER *pUsn);
  76. STDMETHOD( RecallData )(
  77. IN BSTR localName,
  78. IN ULARGE_INTEGER localDataStart,
  79. IN ULARGE_INTEGER localDataSize,
  80. IN DWORD flags,
  81. IN BSTR migrateSessionName,
  82. IN ULARGE_INTEGER remoteDataSetStart,
  83. IN ULARGE_INTEGER remoteFileStart,
  84. IN ULARGE_INTEGER remoteFileSize,
  85. IN ULARGE_INTEGER remoteDataStart,
  86. IN ULARGE_INTEGER remoteDataSize,
  87. IN DWORD remoteVerificationType,
  88. IN ULARGE_INTEGER remoteVerificationData);
  89. STDMETHOD( FormatLabel )(
  90. IN BSTR displayName,
  91. OUT BSTR *pLabel);
  92. STDMETHOD( WriteLabel )(
  93. IN BSTR label);
  94. STDMETHOD( ReadLabel )(
  95. IN OUT BSTR *pLabel );
  96. STDMETHOD( VerifyLabel )(
  97. IN BSTR label);
  98. STDMETHOD( GetDeviceName )(
  99. OUT BSTR *pName);
  100. STDMETHOD( SetDeviceName )(
  101. IN BSTR name,
  102. IN BSTR unused);
  103. STDMETHOD( GetLargestFreeSpace )(
  104. OUT LONGLONG *pFreeSpace,
  105. OUT LONGLONG *pCapacity,
  106. IN ULONG defaultFreeSpaceLow = 0xFFFFFFFF,
  107. IN LONG defaultFreeSpaceHigh = 0xFFFFFFFF);
  108. STDMETHOD( SetInitialOffset )(
  109. IN ULARGE_INTEGER initialOffset);
  110. STDMETHOD( GetCartridge )(
  111. OUT IRmsCartridge **ptr);
  112. STDMETHOD( SetCartridge )(
  113. IN IRmsCartridge *ptr);
  114. STDMETHOD( Cancel )(void);
  115. STDMETHOD( CreateLocalStream )(
  116. IN BSTR name,
  117. IN DWORD mode,
  118. OUT IStream **ppStream);
  119. STDMETHOD( CreateRemoteStream )(
  120. IN BSTR name,
  121. IN DWORD mode,
  122. IN BSTR remoteSessionName,
  123. IN BSTR remoteSessionDescription,
  124. IN ULARGE_INTEGER remoteDataSetStart,
  125. IN ULARGE_INTEGER remoteFileStart,
  126. IN ULARGE_INTEGER remoteFileSize,
  127. IN ULARGE_INTEGER remoteDataStart,
  128. IN ULARGE_INTEGER remoteDataSize,
  129. IN DWORD remoteVerificationType,
  130. IN ULARGE_INTEGER remoteVerificationData,
  131. OUT IStream **ppStream);
  132. STDMETHOD( CloseStream )(void);
  133. STDMETHOD( Duplicate )(
  134. IN IDataMover *pDestination,
  135. IN DWORD options,
  136. OUT ULARGE_INTEGER *pBytesCopied,
  137. OUT ULARGE_INTEGER *pBytesReclaimed);
  138. STDMETHOD( FlushBuffers )(void);
  139. STDMETHOD( Recover )(OUT BOOL *pDeleteFile);
  140. // IStream
  141. public:
  142. STDMETHOD( Read )(
  143. OUT void *pv,
  144. IN ULONG cb,
  145. OUT ULONG *pcbRead);
  146. STDMETHOD( Write )(
  147. IN void const *pv,
  148. IN ULONG cb,
  149. OUT ULONG *pcbWritten);
  150. STDMETHOD( Seek )(
  151. IN LARGE_INTEGER dlibMove,
  152. IN DWORD dwOrigin,
  153. OUT ULARGE_INTEGER *plibNewPosition);
  154. STDMETHOD( SetSize )(
  155. IN ULARGE_INTEGER libNewSize);
  156. STDMETHOD( CopyTo )(
  157. IN IStream *pstm,
  158. IN ULARGE_INTEGER cb,
  159. OUT ULARGE_INTEGER *pcbRead,
  160. OUT ULARGE_INTEGER *pcbWritten);
  161. STDMETHOD( Commit )(
  162. IN DWORD grfCommitFlags);
  163. STDMETHOD( Revert )(void);
  164. STDMETHOD( LockRegion )(
  165. IN ULARGE_INTEGER libOffset,
  166. IN ULARGE_INTEGER cb,
  167. IN DWORD dwLockType);
  168. STDMETHOD( UnlockRegion )(
  169. IN ULARGE_INTEGER libOffset,
  170. IN ULARGE_INTEGER cb,
  171. IN DWORD dwLockType);
  172. STDMETHOD( Stat )(
  173. OUT STATSTG *pstatstg,
  174. IN DWORD grfStatFlag);
  175. STDMETHOD( Clone )(
  176. OUT IStream **ppstm);
  177. private:
  178. enum { // Class specific constants:
  179. //
  180. Version = 1, // Class version, this should be
  181. // incremented each time the
  182. // the class definition changes.
  183. DefaultBlockSize = 512, // Default block size to use.
  184. DefaultMinBufferSize = RMS_DEFAULT_BUFFER_SIZE, // Default minimum buffer size.
  185. };
  186. GUID m_ObjectId; // Unique ID for this object.
  187. CMTFSession* m_pSession; // Holds all session information.
  188. SHORT m_DataSetNumber; // Holds the current dataset number.
  189. HANDLE m_hFile; // Tape drive handle.
  190. CWsbBstrPtr m_DeviceName; // The name of the tape device.
  191. DWORD m_Flags; // Holds data transfer type flag.
  192. CWsbBstrPtr m_LastVolume; // Name of the last volume backed up.
  193. CWsbBstrPtr m_LastPath; // Name of the last directory backed up.
  194. BOOL m_ValidLabel; // True if the label is valid, the flag
  195. // knocked down on BUS_RESET and Medium
  196. // errors, and assumed valid at initialization.
  197. CWsbBstrPtr m_StreamName; // Stream state information...
  198. ULONG m_Mode; // The kind of I/O. See MVR_MODE_*, MVR_FLAG_*
  199. ULARGE_INTEGER m_StreamOffset; // Unformatted mode: The (absolute) current offset into the data stream
  200. // HSM Semantics mode: The offset into the remote file itself from the beginning of the file
  201. ULARGE_INTEGER m_StreamSize; // The size of the data stream
  202. CComPtr<IRmsCartridge> m_pCartridge; // A reference to the Cartridge in use by the DataMover.
  203. BOOL m_isLocalStream; // Either local and remote stream is created
  204. ULONG m_OriginalAttributes; // The original attributes of the local file.
  205. DWORD m_BlockSize; // The read/write blocking factor.
  206. static int s_InstanceCount; // Counter of the number of object instances.
  207. // File I/O
  208. HRESULT WriteBuffer(IN BYTE *pBuffer, IN ULONG nBytesToWrite, OUT ULONG *pBytesWritten);
  209. HRESULT ReadBuffer(IN BYTE *pBuffer, IN ULONG nBytesToRead, OUT ULONG *pBytesRead);
  210. HRESULT InternalCopyFile(IN WCHAR *pOriginalFileName, IN WCHAR *pCopyFileName, IN BOOL bFailIfExists);
  211. // Block Positioning
  212. HRESULT GetPosition(OUT UINT64 *pPosition);
  213. HRESULT SetPosition(IN UINT64 position);
  214. HRESULT EnsurePosition(IN UINT64 position);
  215. // Utililties
  216. HRESULT GetRemotePath(OUT BSTR *pDestinationString);
  217. HRESULT DeleteAllData(void);
  218. HRESULT FormatDrive(IN BSTR label);
  219. HRESULT DoRecovery (void);
  220. HRESULT CreateRecoveryIndicator (IN WCHAR *pFileName);
  221. HRESULT DeleteRecoveryIndicator (IN WCHAR *pFileName);
  222. HRESULT TestRecoveryIndicatorAndDeleteFile (IN WCHAR *pFileName);
  223. HRESULT MapFileError(IN HRESULT hrToMap, IN WCHAR *pAction);
  224. };
  225. #endif // !defined(NtFileIo_H)