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>
26 DWORD dwIoControlCode,
31 LPDWORD lpBytesReturned,
32 LPOVERLAPPED lpOverlapped
37 PIO_STATUS_BLOCK IoStatusBlock;
38 IO_STATUS_BLOCK IIosb;
40 WINBOOL bFsIoControlCode = FALSE;
42 DPRINT("DeviceIoControl(hDevice %x dwIoControlCode %d lpInBuffer %x "
43 "nInBufferSize %d lpOutBuffer %x nOutBufferSize %d "
44 "lpBytesReturned %x lpOverlapped %x)\n",
45 hDevice,dwIoControlCode,lpInBuffer,nInBufferSize,lpOutBuffer,
46 nOutBufferSize,lpBytesReturned,lpOverlapped);
48 if (lpBytesReturned == NULL)
50 DPRINT("DeviceIoControl() - returning STATUS_INVALID_PARAMETER\n");
51 SetLastErrorByStatus (STATUS_INVALID_PARAMETER);
55 // TODO: Review and approve this change by RobD. IoCtrls for Serial.sys were
56 // going to NtFsControlFile instead of NtDeviceIoControlFile.
57 // Don't know at this point if anything else is affected by this change.
59 // if (((dwIoControlCode >> 16) & FILE_DEVICE_FILE_SYSTEM) == FILE_DEVICE_FILE_SYSTEM) {
62 if ((dwIoControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM) {
64 bFsIoControlCode = TRUE;
65 DPRINT("DeviceIoControl() - FILE_DEVICE_FILE_SYSTEM == TRUE %x %x\n", dwIoControlCode, dwIoControlCode >> 16);
67 bFsIoControlCode = FALSE;
68 DPRINT("DeviceIoControl() - FILE_DEVICE_FILE_SYSTEM == FALSE %x %x\n", dwIoControlCode, dwIoControlCode >> 16);
71 if(lpOverlapped != NULL)
73 hEvent = lpOverlapped->hEvent;
74 lpOverlapped->Internal = STATUS_PENDING;
75 IoStatusBlock = (PIO_STATUS_BLOCK)lpOverlapped;
79 IoStatusBlock = &IIosb;
82 if (bFsIoControlCode == TRUE)
84 errCode = NtFsControlFile (hDevice,
97 errCode = NtDeviceIoControlFile (hDevice,
109 if (errCode == STATUS_PENDING)
111 DPRINT("DeviceIoControl() - STATUS_PENDING\n");
112 if (NtWaitForSingleObject(hDevice,FALSE,NULL) < 0)
114 *lpBytesReturned = IoStatusBlock->Information;
115 SetLastErrorByStatus (errCode);
116 DPRINT("DeviceIoControl() - STATUS_PENDING wait failed.\n");
120 else if (!NT_SUCCESS(errCode))
122 SetLastErrorByStatus (errCode);
123 DPRINT("DeviceIoControl() - ERROR: %x\n", errCode);
128 *lpBytesReturned = lpOverlapped->InternalHigh;
130 *lpBytesReturned = IoStatusBlock->Information;
141 GetOverlappedResult (
143 LPOVERLAPPED lpOverlapped,
144 LPDWORD lpNumberOfBytesTransferred,
150 if (lpOverlapped == NULL)
152 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
156 if (lpOverlapped ->Internal == STATUS_PENDING)
158 if (lpNumberOfBytesTransferred == 0)
160 SetLastErrorByStatus (STATUS_PENDING);
163 else if (bWait == TRUE)
165 if (lpOverlapped->hEvent != NULL)
167 WaitStatus = WaitForSingleObject (lpOverlapped->hEvent,
169 if (WaitStatus == STATUS_TIMEOUT)
171 SetLastError (ERROR_IO_INCOMPLETE);
175 return GetOverlappedResult (hFile,
177 lpNumberOfBytesTransferred,
183 *lpNumberOfBytesTransferred = lpOverlapped->InternalHigh;
185 if (lpOverlapped->Internal < 0)
187 SetLastErrorByStatus (lpOverlapped->Internal);