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)
16 #include <kernel32/kernel32.h>
23 DWORD dwIoControlCode,
28 LPDWORD lpBytesReturned,
29 LPOVERLAPPED lpOverlapped
34 PIO_STATUS_BLOCK IoStatusBlock;
35 IO_STATUS_BLOCK IIosb;
37 WINBOOL bFsIoControlCode = FALSE;
39 DPRINT("DeviceIoControl(hDevice %x dwIoControlCode %d lpInBuffer %x "
40 "nInBufferSize %d lpOutBuffer %x nOutBufferSize %d "
41 "lpBytesReturned %x lpOverlapped %x)\n",
42 hDevice,dwIoControlCode,lpInBuffer,nInBufferSize,lpOutBuffer,
43 nOutBufferSize,lpBytesReturned,lpOverlapped);
45 if (lpBytesReturned == NULL)
47 DPRINT("DeviceIoControl() - returning STATUS_INVALID_PARAMETER\n");
48 SetLastErrorByStatus (STATUS_INVALID_PARAMETER);
52 // TODO: Review and approve this change by RobD. IoCtrls for Serial.sys were
53 // going to NtFsControlFile instead of NtDeviceIoControlFile.
54 // Don't know at this point if anything else is affected by this change.
56 // if (((dwIoControlCode >> 16) & FILE_DEVICE_FILE_SYSTEM) == FILE_DEVICE_FILE_SYSTEM) {
59 if ((dwIoControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM) {
61 bFsIoControlCode = TRUE;
62 DPRINT("DeviceIoControl() - FILE_DEVICE_FILE_SYSTEM == TRUE %x %x\n", dwIoControlCode, dwIoControlCode >> 16);
64 bFsIoControlCode = FALSE;
65 DPRINT("DeviceIoControl() - FILE_DEVICE_FILE_SYSTEM == FALSE %x %x\n", dwIoControlCode, dwIoControlCode >> 16);
68 if(lpOverlapped != NULL)
70 hEvent = lpOverlapped->hEvent;
71 lpOverlapped->Internal = STATUS_PENDING;
72 IoStatusBlock = (PIO_STATUS_BLOCK)lpOverlapped;
76 IoStatusBlock = &IIosb;
79 if (bFsIoControlCode == TRUE)
81 errCode = NtFsControlFile (hDevice,
94 errCode = NtDeviceIoControlFile (hDevice,
106 if (errCode == STATUS_PENDING)
108 DPRINT("DeviceIoControl() - STATUS_PENDING\n");
109 if (NtWaitForSingleObject(hDevice,FALSE,NULL) < 0)
111 *lpBytesReturned = IoStatusBlock->Information;
112 SetLastErrorByStatus (errCode);
113 DPRINT("DeviceIoControl() - STATUS_PENDING wait failed.\n");
117 else if (!NT_SUCCESS(errCode))
119 SetLastErrorByStatus (errCode);
120 DPRINT("DeviceIoControl() - ERROR: %x\n", errCode);
125 *lpBytesReturned = lpOverlapped->InternalHigh;
127 *lpBytesReturned = IoStatusBlock->Information;
135 GetOverlappedResult (
137 LPOVERLAPPED lpOverlapped,
138 LPDWORD lpNumberOfBytesTransferred,
144 if (lpOverlapped == NULL)
146 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
150 if (lpOverlapped ->Internal == STATUS_PENDING)
152 if (lpNumberOfBytesTransferred == 0)
154 SetLastErrorByStatus (STATUS_PENDING);
157 else if (bWait == TRUE)
159 if (lpOverlapped->hEvent != NULL)
161 WaitStatus = WaitForSingleObject (lpOverlapped->hEvent,
163 if (WaitStatus == STATUS_TIMEOUT)
165 SetLastError (ERROR_IO_INCOMPLETE);
169 return GetOverlappedResult (hFile,
171 lpNumberOfBytesTransferred,
177 *lpNumberOfBytesTransferred = lpOverlapped->InternalHigh;
179 if (lpOverlapped->Internal < 0)
181 SetLastErrorByStatus (lpOverlapped->Internal);