Visual C++ backend for rbuild (for now just a hacked mingw backend) and related compi...
[reactos.git] / subsystems / win32 / win32k / eng / device.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: GDI Driver Device Functions
24 * FILE: subsys/win32k/eng/device.c
25 * PROGRAMER: Jason Filby
26 * REVISION HISTORY:
27 * 3/7/1999: Created
28 */
29
30 #include <w32k.h>
31
32 #define NDEBUG
33 #include <debug.h>
34
35 /*
36 * @implemented
37 */
38 DWORD STDCALL
39 EngDeviceIoControl(HANDLE hDevice,
40 DWORD dwIoControlCode,
41 LPVOID lpInBuffer,
42 DWORD nInBufferSize,
43 LPVOID lpOutBuffer,
44 DWORD nOutBufferSize,
45 DWORD *lpBytesReturned)
46 {
47 PIRP Irp;
48 NTSTATUS Status;
49 KEVENT Event;
50 IO_STATUS_BLOCK Iosb;
51 PDEVICE_OBJECT DeviceObject;
52
53 DPRINT("EngDeviceIoControl() called\n");
54
55 KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
56
57 DeviceObject = (PDEVICE_OBJECT) hDevice;
58
59 Irp = IoBuildDeviceIoControlRequest(dwIoControlCode,
60 DeviceObject,
61 lpInBuffer,
62 nInBufferSize,
63 lpOutBuffer,
64 nOutBufferSize, FALSE, &Event, &Iosb);
65
66 Status = IoCallDriver(DeviceObject, Irp);
67
68 if (Status == STATUS_PENDING)
69 {
70 (VOID)KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
71 Status = Iosb.Status;
72 }
73
74 DPRINT("EngDeviceIoControl(): Returning %X/%X\n", Iosb.Status,
75 Iosb.Information);
76
77 /* Return information to the caller about the operation. */
78 *lpBytesReturned = Iosb.Information;
79
80 /* Convert NT status values to win32 error codes. */
81 switch (Status)
82 {
83 case STATUS_INSUFFICIENT_RESOURCES: return ERROR_NOT_ENOUGH_MEMORY;
84 case STATUS_BUFFER_OVERFLOW: return ERROR_MORE_DATA;
85 case STATUS_NOT_IMPLEMENTED: return ERROR_INVALID_FUNCTION;
86 case STATUS_INVALID_PARAMETER: return ERROR_INVALID_PARAMETER;
87 case STATUS_BUFFER_TOO_SMALL: return ERROR_INSUFFICIENT_BUFFER;
88 case STATUS_DEVICE_DOES_NOT_EXIST: return ERROR_DEV_NOT_EXIST;
89 case STATUS_PENDING: return ERROR_IO_PENDING;
90 }
91 return Status;
92 }
93
94 /* EOF */