1 /* $Id: deviceio.c,v 1.10 2002/10/03 19:09:04 robd Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/deviceio.c
6 * PURPOSE: Device I/O and Overlapped Result functions
7 * PROGRAMMER: Ariadne (ariadne@xs4all.nl)
12 #include <ddk/ntddk.h>
17 #include <kernel32/kernel32.h>
18 #include <kernel32/error.h>
25 DWORD dwIoControlCode
,
30 LPDWORD lpBytesReturned
,
31 LPOVERLAPPED lpOverlapped
36 PIO_STATUS_BLOCK IoStatusBlock
;
37 IO_STATUS_BLOCK IIosb
;
39 WINBOOL bFsIoControlCode
= FALSE
;
41 DPRINT("DeviceIoControl(hDevice %x dwIoControlCode %d lpInBuffer %x "
42 "nInBufferSize %d lpOutBuffer %x nOutBufferSize %d "
43 "lpBytesReturned %x lpOverlapped %x)\n",
44 hDevice
,dwIoControlCode
,lpInBuffer
,nInBufferSize
,lpOutBuffer
,
45 nOutBufferSize
,lpBytesReturned
,lpOverlapped
);
47 if (lpBytesReturned
== NULL
)
49 DPRINT("DeviceIoControl() - returning STATUS_INVALID_PARAMETER\n");
50 SetLastErrorByStatus (STATUS_INVALID_PARAMETER
);
54 // TODO: Review and approve this change by RobD. IoCtrls for Serial.sys were
55 // going to NtFsControlFile instead of NtDeviceIoControlFile.
56 // Don't know at this point if anything else is affected by this change.
58 // if (((dwIoControlCode >> 16) & FILE_DEVICE_FILE_SYSTEM) == FILE_DEVICE_FILE_SYSTEM) {
61 if ((dwIoControlCode
>> 16) == FILE_DEVICE_FILE_SYSTEM
) {
63 bFsIoControlCode
= TRUE
;
64 DPRINT("DeviceIoControl() - FILE_DEVICE_FILE_SYSTEM == TRUE %x %x\n", dwIoControlCode
, dwIoControlCode
>> 16);
66 bFsIoControlCode
= FALSE
;
67 DPRINT("DeviceIoControl() - FILE_DEVICE_FILE_SYSTEM == FALSE %x %x\n", dwIoControlCode
, dwIoControlCode
>> 16);
70 if(lpOverlapped
!= NULL
)
72 hEvent
= lpOverlapped
->hEvent
;
73 lpOverlapped
->Internal
= STATUS_PENDING
;
74 IoStatusBlock
= (PIO_STATUS_BLOCK
)lpOverlapped
;
78 IoStatusBlock
= &IIosb
;
81 if (bFsIoControlCode
== TRUE
)
83 errCode
= NtFsControlFile (hDevice
,
96 errCode
= NtDeviceIoControlFile (hDevice
,
108 if (errCode
== STATUS_PENDING
)
110 DPRINT("DeviceIoControl() - STATUS_PENDING\n");
111 if (NtWaitForSingleObject(hDevice
,FALSE
,NULL
) < 0)
113 *lpBytesReturned
= IoStatusBlock
->Information
;
114 SetLastErrorByStatus (errCode
);
115 DPRINT("DeviceIoControl() - STATUS_PENDING wait failed.\n");
119 else if (!NT_SUCCESS(errCode
))
121 SetLastErrorByStatus (errCode
);
122 DPRINT("DeviceIoControl() - ERROR: %x\n", errCode
);
127 *lpBytesReturned
= lpOverlapped
->InternalHigh
;
129 *lpBytesReturned
= IoStatusBlock
->Information
;
137 GetOverlappedResult (
139 LPOVERLAPPED lpOverlapped
,
140 LPDWORD lpNumberOfBytesTransferred
,
146 if (lpOverlapped
== NULL
)
148 SetLastErrorByStatus(STATUS_INVALID_PARAMETER
);
152 if (lpOverlapped
->Internal
== STATUS_PENDING
)
154 if (lpNumberOfBytesTransferred
== 0)
156 SetLastErrorByStatus (STATUS_PENDING
);
159 else if (bWait
== TRUE
)
161 if (lpOverlapped
->hEvent
!= NULL
)
163 WaitStatus
= WaitForSingleObject (lpOverlapped
->hEvent
,
165 if (WaitStatus
== STATUS_TIMEOUT
)
167 SetLastError (ERROR_IO_INCOMPLETE
);
171 return GetOverlappedResult (hFile
,
173 lpNumberOfBytesTransferred
,
179 *lpNumberOfBytesTransferred
= lpOverlapped
->InternalHigh
;
181 if (lpOverlapped
->Internal
< 0)
183 SetLastErrorByStatus (lpOverlapped
->Internal
);