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.

245 lines
8.3 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name :
  4. device.h
  5. Abstract:
  6. Device object handles one redirected device
  7. Revision History:
  8. --*/
  9. #pragma once
  10. class DrSession;
  11. class DrExchange;
  12. typedef enum enmDeviceStatus { // ds
  13. dsAvailable,
  14. dsDisabled,
  15. dsConnected
  16. } DEVICE_STATUS;
  17. class DrDevice : public RefCount, public IExchangeUser
  18. {
  19. protected:
  20. SmartPtr<DrSession> _Session;
  21. ULONG _DeviceId;
  22. ULONG _DeviceType;
  23. UCHAR _PreferredDosName[PREFERRED_DOS_NAME_SIZE];
  24. DEVICE_STATUS _DeviceStatus;
  25. BOOL MarkBusy(SmartPtr<DrExchange> &Exchange);
  26. VOID MarkIdle(SmartPtr<DrExchange> &Exchange);
  27. BOOL MarkTimedOut(SmartPtr<DrExchange> &Exchange);
  28. NTSTATUS VerifyCreateSecurity(PRX_CONTEXT RxContext, ULONG CurrentSessionId);
  29. VOID FinishCreate(PRX_CONTEXT RxContext);
  30. NTSTATUS SendIoRequest(IN OUT PRX_CONTEXT RxContext,
  31. PRDPDR_IOREQUEST_PACKET IoRequest, ULONG Length,
  32. BOOLEAN Synchronous, PLARGE_INTEGER TimeOut = NULL,
  33. BOOL LowPrioSend = FALSE);
  34. static NTSTATUS NTAPI MinirdrCancelRoutine(PRX_CONTEXT RxContext);
  35. VOID CompleteBusyExchange(SmartPtr<DrExchange> &Exchange,
  36. NTSTATUS Status, ULONG Information);
  37. static VOID CompleteRxContext(PRX_CONTEXT RxContext, NTSTATUS Status,
  38. ULONG Information);
  39. VOID DiscardBusyExchange(SmartPtr<DrExchange> &Exchange);
  40. virtual NTSTATUS CreateDevicePath(PUNICODE_STRING DevicePath);
  41. virtual NTSTATUS CreateDosDevicePath(PUNICODE_STRING DosDevicePath,
  42. PUNICODE_STRING DosDeviceName);
  43. NTSTATUS CreateDosSymbolicLink(PUNICODE_STRING DosDeviceName);
  44. virtual BOOL IsDeviceNameValid() {return TRUE;}
  45. public:
  46. #if DBG
  47. BOOL _VNetRootFinalized;
  48. PVOID _VNetRoot;
  49. #endif
  50. DrDevice(SmartPtr<DrSession> &Session, ULONG DeviceType, ULONG DeviceId, PUCHAR PreferredDosName);
  51. virtual ~DrDevice();
  52. virtual NTSTATUS Initialize(PRDPDR_DEVICE_ANNOUNCE DeviceAnnounce, ULONG Length);
  53. virtual BOOL ShouldCreateDevice();
  54. VOID CreateReferenceString(
  55. IN OUT PUNICODE_STRING refString
  56. );
  57. virtual VOID Remove();
  58. virtual BOOL SupportDiscon() {
  59. return FALSE;
  60. }
  61. virtual void Disconnect() { }
  62. virtual NTSTATUS OnDevMgmtEventCompletion(PVOID event)
  63. {
  64. return STATUS_SUCCESS;
  65. }
  66. virtual NTSTATUS OnDevMgmtEventCompletion(IN PDEVICE_OBJECT DeviceObject, PVOID event)
  67. {
  68. return STATUS_SUCCESS;
  69. }
  70. virtual BOOL IsAvailable()
  71. {
  72. return _DeviceStatus == dsAvailable;
  73. }
  74. void SetDeviceStatus(DEVICE_STATUS dsStatus)
  75. {
  76. _DeviceStatus = dsStatus;
  77. }
  78. ULONG GetDeviceId()
  79. {
  80. return _DeviceId;
  81. }
  82. UCHAR* GetDeviceDosName()
  83. {
  84. return _PreferredDosName;
  85. }
  86. ULONG GetDeviceType()
  87. {
  88. return _DeviceType;
  89. }
  90. SmartPtr<DrSession> GetSession()
  91. {
  92. return _Session;
  93. }
  94. virtual NTSTATUS Create(IN OUT PRX_CONTEXT RxContext);
  95. NTSTATUS Flush(IN OUT PRX_CONTEXT RxContext);
  96. virtual NTSTATUS Write(IN OUT PRX_CONTEXT RxContext, IN BOOL LowPrioSend = FALSE);
  97. NTSTATUS Read(IN OUT PRX_CONTEXT RxContext);
  98. virtual NTSTATUS IoControl(IN OUT PRX_CONTEXT RxContext);
  99. virtual NTSTATUS Close(IN OUT PRX_CONTEXT RxContext);
  100. NTSTATUS Cleanup(IN OUT PRX_CONTEXT RxContext);
  101. //
  102. // These are file system specific functions.
  103. //
  104. virtual NTSTATUS Locks(IN OUT PRX_CONTEXT RxContext) {
  105. return STATUS_NOT_IMPLEMENTED;
  106. }
  107. virtual NTSTATUS QueryDirectory(IN OUT PRX_CONTEXT RxContext) {
  108. return STATUS_NOT_IMPLEMENTED;
  109. }
  110. virtual NTSTATUS NotifyChangeDirectory(IN OUT PRX_CONTEXT RxContext) {
  111. return STATUS_NOT_IMPLEMENTED;
  112. }
  113. virtual NTSTATUS QueryVolumeInfo(IN OUT PRX_CONTEXT RxContext) {
  114. return STATUS_NOT_IMPLEMENTED;
  115. }
  116. virtual NTSTATUS SetVolumeInfo(IN OUT PRX_CONTEXT RxContext) {
  117. return STATUS_NOT_IMPLEMENTED;
  118. }
  119. virtual NTSTATUS QueryFileInfo(IN OUT PRX_CONTEXT RxContext) {
  120. return STATUS_NOT_IMPLEMENTED;
  121. }
  122. virtual NTSTATUS SetFileInfo(IN OUT PRX_CONTEXT RxContext) {
  123. return STATUS_NOT_IMPLEMENTED;
  124. }
  125. virtual NTSTATUS QuerySdInfo(IN OUT PRX_CONTEXT RxContext) {
  126. return STATUS_NOT_IMPLEMENTED;
  127. }
  128. virtual NTSTATUS SetSdInfo(IN OUT PRX_CONTEXT RxContext) {
  129. return STATUS_NOT_IMPLEMENTED;
  130. }
  131. virtual VOID NotifyClose();
  132. //
  133. // IExchangeUser methods
  134. //
  135. virtual VOID OnIoDisconnected(SmartPtr<DrExchange> &Exchange);
  136. virtual NTSTATUS OnStartExchangeCompletion(SmartPtr<DrExchange> &Exchange,
  137. PIO_STATUS_BLOCK IoStatusBlock);
  138. virtual NTSTATUS OnDeviceIoCompletion(
  139. PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  140. BOOL *DoDefaultRead, SmartPtr<DrExchange> &Exchange);
  141. NTSTATUS OnCreateCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  142. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange);
  143. NTSTATUS OnWriteCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  144. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange);
  145. NTSTATUS OnReadCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  146. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange);
  147. virtual NTSTATUS OnDeviceControlCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  148. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange);
  149. //
  150. // These are file system specific functions
  151. //
  152. virtual NTSTATUS OnLocksCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  153. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  154. ASSERT(FALSE);
  155. return STATUS_DEVICE_PROTOCOL_ERROR;
  156. }
  157. virtual NTSTATUS OnDirectoryControlCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  158. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  159. ASSERT(FALSE);
  160. return STATUS_DEVICE_PROTOCOL_ERROR;
  161. }
  162. virtual NTSTATUS OnQueryVolumeInfoCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  163. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  164. ASSERT(FALSE);
  165. return STATUS_DEVICE_PROTOCOL_ERROR;
  166. }
  167. virtual NTSTATUS OnSetVolumeInfoCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  168. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  169. ASSERT(FALSE);
  170. return STATUS_DEVICE_PROTOCOL_ERROR;
  171. }
  172. virtual NTSTATUS OnQueryFileInfoCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  173. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  174. ASSERT(FALSE);
  175. return STATUS_DEVICE_PROTOCOL_ERROR;
  176. }
  177. virtual NTSTATUS OnSetFileInfoCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  178. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  179. ASSERT(FALSE);
  180. return STATUS_DEVICE_PROTOCOL_ERROR;
  181. }
  182. virtual NTSTATUS OnQuerySdInfoCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  183. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  184. ASSERT(FALSE);
  185. return STATUS_DEVICE_PROTOCOL_ERROR;
  186. }
  187. virtual NTSTATUS OnSetSdInfoCompletion(PRDPDR_IOCOMPLETION_PACKET CompletionPacket, ULONG cbPacket,
  188. BOOL *DoDefaultRead, SmartPtr<DrExchange> Exchange) {
  189. ASSERT(FALSE);
  190. return STATUS_DEVICE_PROTOCOL_ERROR;
  191. }
  192. };
  193. class DrIoContext : public TopObj
  194. {
  195. public:
  196. DrIoContext(PRX_CONTEXT RxContext, SmartPtr<DrDevice> &Device);
  197. SmartPtr<DrDevice> _Device;
  198. BOOL _Busy;
  199. BOOL _Cancelled;
  200. BOOL _Disconnected;
  201. BOOL _TimedOut;
  202. ULONG _DataCopied;
  203. PRX_CONTEXT _RxContext;
  204. UCHAR _MajorFunction;
  205. UCHAR _MinorFunction;
  206. #define DRIOCONTEXT_SUBTAG 'CIrD'
  207. //
  208. // Memory Management Operators
  209. //
  210. inline void *__cdecl operator new(size_t sz)
  211. {
  212. return DRALLOCATEPOOL(NonPagedPool, sz, DRIOCONTEXT_SUBTAG);
  213. }
  214. inline void __cdecl operator delete(void *ptr)
  215. {
  216. DRFREEPOOL(ptr);
  217. }
  218. };