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.

523 lines
23 KiB

  1. /*****************************************************************************
  2. * kso.h - WDM Streaming object support
  3. *****************************************************************************
  4. * Copyright (c) 1997-2000 Microsoft Corporation. All rights reserved.
  5. */
  6. #ifndef _KSO_H_
  7. #define _KSO_H_
  8. #include "punknown.h"
  9. #ifdef __cplusplus
  10. extern "C"
  11. {
  12. #include <wdm.h>
  13. }
  14. #else
  15. #include <wdm.h>
  16. #endif
  17. #include <windef.h>
  18. #define NOBITMAP
  19. #include <mmreg.h>
  20. #undef NOBITMAP
  21. #include <ks.h>
  22. /*****************************************************************************
  23. * Interface IDs
  24. */
  25. DEFINE_GUID(IID_IIrpTarget,
  26. 0xb4c90a60, 0x5791, 0x11d0, 0x86, 0xf9, 0x0, 0xa0, 0xc9, 0x11, 0xb5, 0x44);
  27. DEFINE_GUID(IID_IIrpTargetFactory,
  28. 0xb4c90a62, 0x5791, 0x11d0, 0x86, 0xf9, 0x0, 0xa0, 0xc9, 0x11, 0xb5, 0x44);
  29. /*****************************************************************************
  30. * Interfaces
  31. */
  32. /*****************************************************************************
  33. * IIrpTargetFactory
  34. *****************************************************************************
  35. * Interface for objects that create IrpTargets.
  36. */
  37. #if !defined(DEFINE_ABSTRACT_IRPTARGETFACTORY)
  38. #define DEFINE_ABSTRACT_IRPTARGETFACTORY() \
  39. STDMETHOD_(NTSTATUS,NewIrpTarget) \
  40. ( THIS_ \
  41. OUT struct IIrpTarget **IrpTarget, \
  42. OUT BOOLEAN * ReferenceParent, \
  43. IN PUNKNOWN OuterUnknown OPTIONAL, \
  44. IN POOL_TYPE PoolType, \
  45. IN PDEVICE_OBJECT DeviceObject, \
  46. IN PIRP Irp, \
  47. OUT PKSOBJECT_CREATE ObjectCreate \
  48. ) PURE;
  49. #endif //!defined(DEFINE_ABSTRACT_IRPTARGETFACTORY)
  50. DECLARE_INTERFACE_(IIrpTargetFactory,IUnknown)
  51. {
  52. DEFINE_ABSTRACT_UNKNOWN() // For IUnknown
  53. DEFINE_ABSTRACT_IRPTARGETFACTORY() // For IIrpTargetFactory
  54. };
  55. typedef IIrpTargetFactory *PIRPTARGETFACTORY;
  56. #define IMP_IIrpTargetFactory\
  57. STDMETHODIMP_(NTSTATUS) NewIrpTarget\
  58. ( OUT struct IIrpTarget **IrpTarget,\
  59. OUT BOOLEAN * ReferenceParent,\
  60. IN PUNKNOWN OuterUnknown OPTIONAL,\
  61. IN POOL_TYPE PoolType,\
  62. IN PDEVICE_OBJECT DeviceObject,\
  63. IN PIRP Irp,\
  64. OUT PKSOBJECT_CREATE ObjectCreate\
  65. )
  66. /*****************************************************************************
  67. * IIrpTarget
  68. *****************************************************************************
  69. * Interface common to all IRP targets.
  70. */
  71. #if !defined(DEFINE_ABSTRACT_IRPTARGET)
  72. #define DEFINE_ABSTRACT_IRPTARGET() \
  73. STDMETHOD_(NTSTATUS,DeviceIoControl) \
  74. ( THIS_ \
  75. IN PDEVICE_OBJECT DeviceObject, \
  76. IN PIRP Irp \
  77. ) PURE; \
  78. STDMETHOD_(NTSTATUS,Read) \
  79. ( THIS_ \
  80. IN PDEVICE_OBJECT DeviceObject, \
  81. IN PIRP Irp \
  82. ) PURE; \
  83. STDMETHOD_(NTSTATUS,Write) \
  84. ( THIS_ \
  85. IN PDEVICE_OBJECT DeviceObject, \
  86. IN PIRP Irp \
  87. ) PURE; \
  88. STDMETHOD_(NTSTATUS,Flush) \
  89. ( THIS_ \
  90. IN PDEVICE_OBJECT DeviceObject, \
  91. IN PIRP Irp \
  92. ) PURE; \
  93. STDMETHOD_(NTSTATUS,Close) \
  94. ( THIS_ \
  95. IN PDEVICE_OBJECT DeviceObject, \
  96. IN PIRP Irp \
  97. ) PURE; \
  98. STDMETHOD_(NTSTATUS,QuerySecurity) \
  99. ( THIS_ \
  100. IN PDEVICE_OBJECT DeviceObject, \
  101. IN PIRP Irp \
  102. ) PURE; \
  103. STDMETHOD_(NTSTATUS,SetSecurity) \
  104. ( THIS_ \
  105. IN PDEVICE_OBJECT DeviceObject, \
  106. IN PIRP Irp \
  107. ) PURE; \
  108. STDMETHOD_(BOOLEAN,FastDeviceIoControl) \
  109. ( THIS_ \
  110. IN PFILE_OBJECT FileObject, \
  111. IN BOOLEAN Wait, \
  112. IN PVOID InputBuffer OPTIONAL, \
  113. IN ULONG InputBufferLength, \
  114. OUT PVOID OutputBuffer OPTIONAL, \
  115. IN ULONG OutputBufferLength, \
  116. IN ULONG IoControlCode, \
  117. OUT PIO_STATUS_BLOCK IoStatus, \
  118. IN PDEVICE_OBJECT DeviceObject \
  119. ) PURE; \
  120. STDMETHOD_(BOOLEAN,FastRead) \
  121. ( THIS_ \
  122. IN PFILE_OBJECT FileObject, \
  123. IN PLARGE_INTEGER FileOffset, \
  124. IN ULONG Length, \
  125. IN BOOLEAN Wait, \
  126. IN ULONG LockKey, \
  127. OUT PVOID Buffer, \
  128. OUT PIO_STATUS_BLOCK IoStatus, \
  129. IN PDEVICE_OBJECT DeviceObject \
  130. ) PURE; \
  131. STDMETHOD_(BOOLEAN,FastWrite) \
  132. ( THIS_ \
  133. IN PFILE_OBJECT FileObject, \
  134. IN PLARGE_INTEGER FileOffset, \
  135. IN ULONG Length, \
  136. IN BOOLEAN Wait, \
  137. IN ULONG LockKey, \
  138. IN PVOID Buffer, \
  139. OUT PIO_STATUS_BLOCK IoStatus, \
  140. IN PDEVICE_OBJECT DeviceObject \
  141. ) PURE;
  142. #endif //!defined(DEFINE_ABSTRACT_IRPTARGET)
  143. DECLARE_INTERFACE_(IIrpTarget,IIrpTargetFactory)
  144. {
  145. DEFINE_ABSTRACT_UNKNOWN() // For IUnknown
  146. DEFINE_ABSTRACT_IRPTARGETFACTORY() // For IIrpTargetFactory
  147. DEFINE_ABSTRACT_IRPTARGET() // For IIrpTarget
  148. };
  149. typedef IIrpTarget *PIRPTARGET;
  150. #define IMP_IIrpTarget\
  151. IMP_IIrpTargetFactory;\
  152. STDMETHODIMP_(NTSTATUS) DeviceIoControl \
  153. ( \
  154. IN PDEVICE_OBJECT DeviceObject, \
  155. IN PIRP Irp \
  156. ); \
  157. STDMETHODIMP_(NTSTATUS) Read \
  158. ( \
  159. IN PDEVICE_OBJECT DeviceObject, \
  160. IN PIRP Irp \
  161. ); \
  162. STDMETHODIMP_(NTSTATUS) Write \
  163. ( \
  164. IN PDEVICE_OBJECT DeviceObject, \
  165. IN PIRP Irp \
  166. ); \
  167. STDMETHODIMP_(NTSTATUS) Flush \
  168. ( \
  169. IN PDEVICE_OBJECT DeviceObject, \
  170. IN PIRP Irp \
  171. ); \
  172. STDMETHODIMP_(NTSTATUS) Close \
  173. ( \
  174. IN PDEVICE_OBJECT DeviceObject, \
  175. IN PIRP Irp \
  176. ); \
  177. STDMETHODIMP_(NTSTATUS) QuerySecurity \
  178. ( \
  179. IN PDEVICE_OBJECT DeviceObject, \
  180. IN PIRP Irp \
  181. ); \
  182. STDMETHODIMP_(NTSTATUS) SetSecurity \
  183. ( \
  184. IN PDEVICE_OBJECT DeviceObject, \
  185. IN PIRP Irp \
  186. ); \
  187. STDMETHODIMP_(BOOLEAN) FastDeviceIoControl \
  188. ( \
  189. IN PFILE_OBJECT FileObject, \
  190. IN BOOLEAN Wait, \
  191. IN PVOID InputBuffer OPTIONAL, \
  192. IN ULONG InputBufferLength, \
  193. OUT PVOID OutputBuffer OPTIONAL, \
  194. IN ULONG OutputBufferLength, \
  195. IN ULONG IoControlCode, \
  196. OUT PIO_STATUS_BLOCK IoStatus, \
  197. IN PDEVICE_OBJECT DeviceObject \
  198. ); \
  199. STDMETHODIMP_(BOOLEAN) FastRead \
  200. ( \
  201. IN PFILE_OBJECT FileObject, \
  202. IN PLARGE_INTEGER FileOffset, \
  203. IN ULONG Length, \
  204. IN BOOLEAN Wait, \
  205. IN ULONG LockKey, \
  206. OUT PVOID Buffer, \
  207. OUT PIO_STATUS_BLOCK IoStatus, \
  208. IN PDEVICE_OBJECT DeviceObject \
  209. ); \
  210. STDMETHODIMP_(BOOLEAN) FastWrite \
  211. ( \
  212. IN PFILE_OBJECT FileObject, \
  213. IN PLARGE_INTEGER FileOffset, \
  214. IN ULONG Length, \
  215. IN BOOLEAN Wait, \
  216. IN ULONG LockKey, \
  217. IN PVOID Buffer, \
  218. OUT PIO_STATUS_BLOCK IoStatus, \
  219. IN PDEVICE_OBJECT DeviceObject \
  220. )
  221. /*****************************************************************************
  222. * Functions
  223. */
  224. /*****************************************************************************
  225. * KsoSetMajorFunctionHandler()
  226. *****************************************************************************
  227. * Sets up the handler for a major function.
  228. */
  229. NTSTATUS
  230. KsoSetMajorFunctionHandler
  231. (
  232. IN PDRIVER_OBJECT pDriverObject,
  233. IN ULONG ulMajorFunction
  234. );
  235. /*****************************************************************************
  236. * KsoDispatchIrp()
  237. *****************************************************************************
  238. * Dispatch an IRP.
  239. */
  240. NTSTATUS
  241. KsoDispatchIrp
  242. (
  243. IN PDEVICE_OBJECT pDeviceObject,
  244. IN PIRP pIrp
  245. );
  246. /*****************************************************************************
  247. * KsoDispatchCreate()
  248. *****************************************************************************
  249. * Handles object create IRPs using the IIrpTargetFactory interface pointer
  250. * in the Context field of the create item.
  251. */
  252. NTSTATUS
  253. KsoDispatchCreate
  254. (
  255. IN PDEVICE_OBJECT pDeviceObject,
  256. IN PIRP pIrp
  257. );
  258. /*****************************************************************************
  259. * KsoDispatchCreateWithGenericFactory()
  260. *****************************************************************************
  261. * Handles object create IRPs using the IIrpTarget interface pointer in the
  262. * device or object context.
  263. */
  264. NTSTATUS
  265. KsoDispatchCreateWithGenericFactory
  266. (
  267. IN PDEVICE_OBJECT pDeviceObject,
  268. IN PIRP pIrp
  269. );
  270. /*****************************************************************************
  271. * AddIrpTargetFactoryToDevice()
  272. *****************************************************************************
  273. * Adds an IrpTargetFactory to a device's create items list.
  274. */
  275. NTSTATUS
  276. NTAPI
  277. AddIrpTargetFactoryToDevice
  278. (
  279. IN PDEVICE_OBJECT pDeviceObject,
  280. IN PIRPTARGETFACTORY pIrpTargetFactory,
  281. IN PWCHAR pwcObjectClass,
  282. IN PSECURITY_DESCRIPTOR pSecurityDescriptor OPTIONAL
  283. );
  284. /*****************************************************************************
  285. * AddIrpTargetFactoryToObject()
  286. *****************************************************************************
  287. * Adds an IrpTargetFactory to a objects's create items list.
  288. */
  289. NTSTATUS
  290. NTAPI
  291. AddIrpTargetFactoryToObject
  292. (
  293. IN PFILE_OBJECT pFileObject,
  294. IN PIRPTARGETFACTORY pIrpTargetFactory,
  295. IN PWCHAR pwcObjectClass,
  296. IN PSECURITY_DESCRIPTOR pSecurityDescriptor OPTIONAL
  297. );
  298. /*****************************************************************************
  299. * KsoGetIrpTargetFromIrp()
  300. *****************************************************************************
  301. * Extracts the IrpTarget pointer from an IRP.
  302. */
  303. PIRPTARGET
  304. NTAPI
  305. KsoGetIrpTargetFromIrp
  306. (
  307. IN PIRP Irp
  308. );
  309. /*****************************************************************************
  310. * KsoGetIrpTargetFromFileObject()
  311. *****************************************************************************
  312. * Extracts the IrpTarget pointer from a FileObject pointer.
  313. */
  314. PIRPTARGET
  315. NTAPI
  316. KsoGetIrpTargetFromFileObject(
  317. IN PFILE_OBJECT FileObject
  318. );
  319. /*****************************************************************************
  320. * Macros
  321. */
  322. #define DEFINE_INVALID_CREATE(Class) \
  323. STDMETHODIMP_(NTSTATUS) Class::NewIrpTarget \
  324. ( \
  325. OUT PIRPTARGET * IrpTarget, \
  326. OUT BOOLEAN * ReferenceParent, \
  327. IN PUNKNOWN OuterUnknown, \
  328. IN POOL_TYPE PoolType, \
  329. IN PDEVICE_OBJECT DeviceObject, \
  330. IN PIRP Irp, \
  331. OUT PKSOBJECT_CREATE ObjectCreate \
  332. ) \
  333. { \
  334. return STATUS_INVALID_DEVICE_REQUEST; \
  335. }
  336. #define DEFINE_INVALID_DEVICEIOCONTROL(Class) \
  337. STDMETHODIMP_(NTSTATUS) Class::DeviceIoControl \
  338. ( \
  339. IN PDEVICE_OBJECT DeviceObject, \
  340. IN PIRP Irp \
  341. ) \
  342. { \
  343. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  344. }
  345. #define DEFINE_INVALID_READ(Class) \
  346. STDMETHODIMP_(NTSTATUS) Class::Read \
  347. ( \
  348. IN PDEVICE_OBJECT DeviceObject, \
  349. IN PIRP Irp \
  350. ) \
  351. { \
  352. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  353. }
  354. #define DEFINE_INVALID_WRITE(Class) \
  355. STDMETHODIMP_(NTSTATUS) Class::Write \
  356. ( \
  357. IN PDEVICE_OBJECT DeviceObject, \
  358. IN PIRP Irp \
  359. ) \
  360. { \
  361. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  362. }
  363. #define DEFINE_INVALID_FLUSH(Class) \
  364. STDMETHODIMP_(NTSTATUS) Class::Flush \
  365. ( \
  366. IN PDEVICE_OBJECT DeviceObject, \
  367. IN PIRP Irp \
  368. ) \
  369. { \
  370. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  371. }
  372. #define DEFINE_INVALID_CLOSE(Class) \
  373. STDMETHODIMP_(NTSTATUS) Class::Close \
  374. ( \
  375. IN PDEVICE_OBJECT DeviceObject, \
  376. IN PIRP Irp \
  377. ) \
  378. { \
  379. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  380. }
  381. #define DEFINE_INVALID_QUERYSECURITY(Class) \
  382. STDMETHODIMP_(NTSTATUS) Class::QuerySecurity \
  383. ( \
  384. IN PDEVICE_OBJECT DeviceObject, \
  385. IN PIRP Irp \
  386. ) \
  387. { \
  388. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  389. }
  390. #define DEFINE_INVALID_SETSECURITY(Class) \
  391. STDMETHODIMP_(NTSTATUS) Class::SetSecurity \
  392. ( \
  393. IN PDEVICE_OBJECT DeviceObject, \
  394. IN PIRP Irp \
  395. ) \
  396. { \
  397. return KsDispatchInvalidDeviceRequest(DeviceObject,Irp); \
  398. }
  399. #define DEFINE_INVALID_FASTDEVICEIOCONTROL(Class) \
  400. STDMETHODIMP_(BOOLEAN) Class::FastDeviceIoControl \
  401. ( \
  402. IN PFILE_OBJECT FileObject, \
  403. IN BOOLEAN Wait, \
  404. IN PVOID InputBuffer OPTIONAL, \
  405. IN ULONG InputBufferLength, \
  406. OUT PVOID OutputBuffer OPTIONAL, \
  407. IN ULONG OutputBufferLength, \
  408. IN ULONG IoControlCode, \
  409. OUT PIO_STATUS_BLOCK IoStatus, \
  410. IN PDEVICE_OBJECT DeviceObject \
  411. ) \
  412. { \
  413. return FALSE; \
  414. }
  415. #define DEFINE_INVALID_FASTREAD(Class) \
  416. STDMETHODIMP_(BOOLEAN) Class::FastRead \
  417. ( \
  418. IN PFILE_OBJECT FileObject, \
  419. IN PLARGE_INTEGER FileOffset, \
  420. IN ULONG Length, \
  421. IN BOOLEAN Wait, \
  422. IN ULONG LockKey, \
  423. OUT PVOID Buffer, \
  424. OUT PIO_STATUS_BLOCK IoStatus, \
  425. IN PDEVICE_OBJECT DeviceObject \
  426. ) \
  427. { \
  428. return FALSE; \
  429. }
  430. #define DEFINE_INVALID_FASTWRITE(Class) \
  431. STDMETHODIMP_(BOOLEAN) Class::FastWrite \
  432. ( \
  433. IN PFILE_OBJECT FileObject, \
  434. IN PLARGE_INTEGER FileOffset, \
  435. IN ULONG Length, \
  436. IN BOOLEAN Wait, \
  437. IN ULONG LockKey, \
  438. IN PVOID Buffer, \
  439. OUT PIO_STATUS_BLOCK IoStatus, \
  440. IN PDEVICE_OBJECT DeviceObject \
  441. ) \
  442. { \
  443. return FALSE; \
  444. }
  445. #if 0
  446. // 1) Cut and paste these.
  447. // 2) Delete the ones that are implemented.
  448. // 3) Substitute the class name.
  449. DEFINE_INVALID_DEVICEIOCONTROL(Class);
  450. DEFINE_INVALID_READ(Class);
  451. DEFINE_INVALID_WRITE(Class);
  452. DEFINE_INVALID_FLUSH(Class);
  453. DEFINE_INVALID_CLOSE(Class);
  454. DEFINE_INVALID_QUERYSECURITY(Class);
  455. DEFINE_INVALID_SETSECURITY(Class);
  456. DEFINE_INVALID_FASTDEVICEIOCONTROL(Class);
  457. DEFINE_INVALID_FASTREAD(Class);
  458. DEFINE_INVALID_FASTWRITE(Class);
  459. #endif
  460. #endif