1999-08-01 11:21:05 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PURPOSE: GDI Driver Device Functions
|
|
|
|
* FILE: subsys/win32k/eng/device.c
|
|
|
|
* PROGRAMER: Jason Filby
|
2009-08-10 15:09:14 +00:00
|
|
|
* Timo Kreuzer
|
1999-08-01 11:21:05 +00:00
|
|
|
*/
|
2005-06-29 07:09:25 +00:00
|
|
|
|
2010-04-26 13:58:46 +00:00
|
|
|
#include <win32k.h>
|
2002-06-14 14:24:28 +00:00
|
|
|
|
2005-06-29 07:09:25 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2009-08-10 15:09:14 +00:00
|
|
|
static
|
2009-08-10 19:26:53 +00:00
|
|
|
NTSTATUS
|
2009-08-10 15:09:14 +00:00
|
|
|
EngpFileIoRequest(
|
|
|
|
PFILE_OBJECT pFileObject,
|
|
|
|
ULONG ulMajorFunction,
|
|
|
|
LPVOID lpBuffer,
|
|
|
|
DWORD nBufferSize,
|
|
|
|
ULONGLONG ullStartOffset,
|
|
|
|
OUT LPDWORD lpInformation)
|
|
|
|
{
|
|
|
|
PDEVICE_OBJECT pDeviceObject;
|
|
|
|
KEVENT Event;
|
|
|
|
PIRP pIrp;
|
|
|
|
IO_STATUS_BLOCK Iosb;
|
|
|
|
NTSTATUS Status;
|
|
|
|
LARGE_INTEGER liStartOffset;
|
|
|
|
|
|
|
|
/* Get corresponding device object */
|
|
|
|
pDeviceObject = IoGetRelatedDeviceObject(pFileObject);
|
|
|
|
if (!pDeviceObject)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize an event */
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
|
|
|
|
/* Build IPR */
|
|
|
|
liStartOffset.QuadPart = ullStartOffset;
|
|
|
|
pIrp = IoBuildSynchronousFsdRequest(ulMajorFunction,
|
|
|
|
pDeviceObject,
|
|
|
|
lpBuffer,
|
|
|
|
nBufferSize,
|
|
|
|
&liStartOffset,
|
|
|
|
&Event,
|
|
|
|
&Iosb);
|
|
|
|
if (!pIrp)
|
|
|
|
{
|
2009-08-10 19:26:53 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2009-08-10 15:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the driver */
|
|
|
|
Status = IoCallDriver(pDeviceObject, pIrp);
|
|
|
|
|
|
|
|
/* Wait if neccessary */
|
|
|
|
if (STATUS_PENDING == Status)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
|
|
|
|
Status = Iosb.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return information to the caller about the operation. */
|
|
|
|
*lpInformation = Iosb.Information;
|
|
|
|
|
2009-08-10 19:26:53 +00:00
|
|
|
/* Return NTSTATUS */
|
|
|
|
return Status;
|
2009-08-10 15:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
APIENTRY
|
|
|
|
EngFileWrite(
|
|
|
|
IN PFILE_OBJECT pFileObject,
|
|
|
|
IN PVOID lpBuffer,
|
|
|
|
IN SIZE_T nLength,
|
|
|
|
IN PSIZE_T lpBytesWritten)
|
|
|
|
{
|
|
|
|
EngpFileIoRequest(pFileObject,
|
|
|
|
IRP_MJ_WRITE,
|
|
|
|
lpBuffer,
|
|
|
|
nLength,
|
|
|
|
0,
|
|
|
|
lpBytesWritten);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
APIENTRY
|
|
|
|
EngFileIoControl(
|
|
|
|
IN PFILE_OBJECT pFileObject,
|
|
|
|
IN DWORD dwIoControlCode,
|
|
|
|
IN PVOID lpInBuffer,
|
|
|
|
IN SIZE_T nInBufferSize,
|
|
|
|
OUT PVOID lpOutBuffer,
|
|
|
|
IN SIZE_T nOutBufferSize,
|
|
|
|
OUT LPDWORD lpInformation)
|
|
|
|
{
|
|
|
|
PDEVICE_OBJECT pDeviceObject;
|
|
|
|
KEVENT Event;
|
|
|
|
PIRP pIrp;
|
|
|
|
IO_STATUS_BLOCK Iosb;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Get corresponding device object */
|
|
|
|
pDeviceObject = IoGetRelatedDeviceObject(pFileObject);
|
|
|
|
if (!pDeviceObject)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize an event */
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
|
|
|
|
/* Build IO control IPR */
|
|
|
|
pIrp = IoBuildDeviceIoControlRequest(dwIoControlCode,
|
|
|
|
pDeviceObject,
|
|
|
|
lpInBuffer,
|
|
|
|
nInBufferSize,
|
|
|
|
lpOutBuffer,
|
|
|
|
nOutBufferSize,
|
|
|
|
FALSE,
|
|
|
|
&Event,
|
|
|
|
&Iosb);
|
|
|
|
if (!pIrp)
|
|
|
|
{
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the driver */
|
|
|
|
Status = IoCallDriver(pDeviceObject, pIrp);
|
|
|
|
|
|
|
|
/* Wait if neccessary */
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
|
|
|
|
Status = Iosb.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return information to the caller about the operation. */
|
|
|
|
*lpInformation = Iosb.Information;
|
|
|
|
|
|
|
|
/* This function returns NTSTATUS */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2003-07-11 15:59:37 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-29 22:48:58 +00:00
|
|
|
DWORD APIENTRY
|
2009-03-17 01:15:26 +00:00
|
|
|
EngDeviceIoControl(
|
|
|
|
HANDLE hDevice,
|
|
|
|
DWORD dwIoControlCode,
|
|
|
|
LPVOID lpInBuffer,
|
|
|
|
DWORD nInBufferSize,
|
|
|
|
LPVOID lpOutBuffer,
|
|
|
|
DWORD nOutBufferSize,
|
|
|
|
DWORD *lpBytesReturned)
|
1999-08-01 11:21:05 +00:00
|
|
|
{
|
2009-03-17 01:15:26 +00:00
|
|
|
PIRP Irp;
|
|
|
|
NTSTATUS Status;
|
|
|
|
KEVENT Event;
|
|
|
|
IO_STATUS_BLOCK Iosb;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2001-03-31 15:35:08 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
DPRINT("EngDeviceIoControl() called\n");
|
2001-03-31 15:35:08 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
2001-03-31 15:35:08 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
DeviceObject = (PDEVICE_OBJECT) hDevice;
|
2002-06-14 14:24:28 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
Irp = IoBuildDeviceIoControlRequest(dwIoControlCode,
|
|
|
|
DeviceObject,
|
|
|
|
lpInBuffer,
|
|
|
|
nInBufferSize,
|
|
|
|
lpOutBuffer,
|
|
|
|
nOutBufferSize, FALSE, &Event, &Iosb);
|
|
|
|
if (!Irp) return ERROR_NOT_ENOUGH_MEMORY;
|
2002-06-14 14:24:28 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
2001-03-31 15:35:08 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
if (Status == STATUS_PENDING)
|
2003-11-05 22:46:05 +00:00
|
|
|
{
|
2009-03-17 01:15:26 +00:00
|
|
|
(VOID)KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
|
|
|
|
Status = Iosb.Status;
|
2003-11-05 22:46:05 +00:00
|
|
|
}
|
2003-06-21 14:25:30 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
DPRINT("EngDeviceIoControl(): Returning %X/%X\n", Iosb.Status,
|
|
|
|
Iosb.Information);
|
2004-03-11 23:07:16 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
/* Return information to the caller about the operation. */
|
|
|
|
*lpBytesReturned = Iosb.Information;
|
2004-03-14 18:36:14 +00:00
|
|
|
|
2009-03-17 01:15:26 +00:00
|
|
|
/* Convert NT status values to win32 error codes. */
|
|
|
|
switch (Status)
|
2004-03-14 18:36:14 +00:00
|
|
|
{
|
2009-03-17 01:15:26 +00:00
|
|
|
case STATUS_INSUFFICIENT_RESOURCES:
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
case STATUS_BUFFER_OVERFLOW:
|
|
|
|
return ERROR_MORE_DATA;
|
|
|
|
|
|
|
|
case STATUS_NOT_IMPLEMENTED:
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
|
|
|
|
case STATUS_INVALID_PARAMETER:
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
case STATUS_BUFFER_TOO_SMALL:
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
case STATUS_DEVICE_DOES_NOT_EXIST:
|
|
|
|
return ERROR_DEV_NOT_EXIST;
|
|
|
|
|
|
|
|
case STATUS_PENDING:
|
|
|
|
return ERROR_IO_PENDING;
|
2004-03-14 18:36:14 +00:00
|
|
|
}
|
2009-03-17 01:15:26 +00:00
|
|
|
|
|
|
|
return Status;
|
1999-08-01 11:21:05 +00:00
|
|
|
}
|
2003-11-05 22:46:05 +00:00
|
|
|
|
2003-05-18 17:16:18 +00:00
|
|
|
/* EOF */
|