ReactOS 0.4.15-dev-7788-g1ad9096
deviceio.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/kernel32/client/file/deviceio.c
5 * PURPOSE: Device I/O Base Client Functionality
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <k32.h>
12
13#include <ntddbeep.h>
14
15#define NDEBUG
16#include <debug.h>
17
18/* FUNCTIONS ******************************************************************/
19
20VOID
23{
24 BASE_API_MESSAGE ApiMessage;
25 PBASE_SOUND_SENTRY SoundSentryRequest = &ApiMessage.Data.SoundSentryRequest;
26
27 /* Get the video mode */
28 if (!GetConsoleDisplayMode(&SoundSentryRequest->VideoMode))
29 {
30 SoundSentryRequest->VideoMode = 0;
31 }
32
33 /* Make sure it's not fullscreen, and send the message if not */
34 if (SoundSentryRequest->VideoMode == 0)
35 {
37 NULL,
39 sizeof(*SoundSentryRequest));
40 }
41}
42
43/*
44 * @implemented
45 */
46BOOL
48Beep(IN DWORD dwFreq,
49 IN DWORD dwDuration)
50{
52 UNICODE_STRING BeepDevice;
55 BEEP_SET_PARAMETERS BeepSetParameters;
57
58 //
59 // On TS systems, we need to Load Winsta.dll and call WinstationBeepOpen
60 // after doing a GetProcAddress for it
61 //
62
63 /* Open the device */
64 RtlInitUnicodeString(&BeepDevice, L"\\Device\\Beep");
70 NULL,
71 0,
74 0,
75 NULL,
76 0);
77 if (!NT_SUCCESS(Status))
78 {
80 return FALSE;
81 }
82
83 /* check the parameters */
84 if ((dwFreq >= 0x25 && dwFreq <= 0x7FFF) ||
85 (dwFreq == 0x0 && dwDuration == 0x0))
86 {
87 /* Set beep data */
88 BeepSetParameters.Frequency = dwFreq;
89 BeepSetParameters.Duration = dwDuration;
90
91 /* Send the beep */
93 NULL,
94 NULL,
95 NULL,
98 &BeepSetParameters,
99 sizeof(BeepSetParameters),
100 NULL,
101 0);
102 }
103 else
104 {
105 /* We'll fail the call, but still notify the sound sentry */
107 }
108
109 /* Notify the sound sentry */
111
112 /* Bail out if the hardware beep failed */
113 if (!NT_SUCCESS(Status))
114 {
115 NtClose(hBeep);
117 return FALSE;
118 }
119
120 /* If an actual beep was emitted, wait for it */
121 if (((dwFreq != 0x0) || (dwDuration != 0x0)) && (dwDuration != MAXDWORD))
122 {
123 SleepEx(dwDuration, TRUE);
124 }
125
126 /* Close the handle and return success */
127 NtClose(hBeep);
128 return TRUE;
129}
130
131/*
132 * @implemented
133 */
134BOOL
135WINAPI
138 IN LPVOID lpInBuffer OPTIONAL,
139 IN DWORD nInBufferSize OPTIONAL,
140 OUT LPVOID lpOutBuffer OPTIONAL,
141 IN DWORD nOutBufferSize OPTIONAL,
144{
145 BOOL FsIoCtl;
149
150 //
151 // Note: on a TS Machine, we should call IsTSAppCompatEnabled and unless the
152 // IOCTLs are IOCTL_STORAGE_EJECT_MEDIA, IOCTL_DISK_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME
153 // we should call IsCallerAdminOrSystem and return STATUS_ACCESS_DENIED for
154 // any other IOCTLs.
155 //
156
157 /* Check what kind of IOCTL to send */
158 FsIoCtl = ((dwIoControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM);
159
160 /* CHeck for async */
161 if (lpOverlapped != NULL)
162 {
163 /* Set pending status */
164 lpOverlapped->Internal = STATUS_PENDING;
165
166 /* Check if there's an APC context */
167 ApcContext = (((ULONG_PTR)lpOverlapped->hEvent & 0x1) ? NULL : lpOverlapped);
168
169 /* Send file system control? */
170 if (FsIoCtl)
171 {
172 /* Send it */
173 Status = NtFsControlFile(hDevice,
174 lpOverlapped->hEvent,
175 NULL,
179 lpInBuffer,
180 nInBufferSize,
181 lpOutBuffer,
182 nOutBufferSize);
183 }
184 else
185 {
186 /* Otherwise send a device control */
188 lpOverlapped->hEvent,
189 NULL,
193 lpInBuffer,
194 nInBufferSize,
195 lpOutBuffer,
196 nOutBufferSize);
197 }
198
199 /* Check for or information instead of failure */
200 if (!(NT_ERROR(Status)) && (lpBytesReturned))
201 {
202 /* Protect with SEH */
204 {
205 /* Return the bytes */
206 *lpBytesReturned = lpOverlapped->InternalHigh;
207 }
209 {
210 /* Return zero bytes */
211 *lpBytesReturned = 0;
212 }
213 _SEH2_END;
214 }
215
216 /* Now check for any kind of failure except pending*/
217 if (!(NT_SUCCESS(Status)) || (Status == STATUS_PENDING))
218 {
219 /* Fail */
221 return FALSE;
222 }
223 }
224 else
225 {
226 /* Sync case -- send file system code? */
227 if (FsIoCtl)
228 {
229 /* Do it */
230 Status = NtFsControlFile(hDevice,
231 NULL,
232 NULL,
233 NULL,
234 &Iosb,
236 lpInBuffer,
237 nInBufferSize,
238 lpOutBuffer,
239 nOutBufferSize);
240 }
241 else
242 {
243 /* Send device code instead */
245 NULL,
246 NULL,
247 NULL,
248 &Iosb,
250 lpInBuffer,
251 nInBufferSize,
252 lpOutBuffer,
253 nOutBufferSize);
254 }
255
256 /* Now check if the operation isn't done yet */
257 if (Status == STATUS_PENDING)
258 {
259 /* Wait for it and get the final status */
261 if (NT_SUCCESS(Status)) Status = Iosb.Status;
262 }
263
264 /* Check for success */
265 if (NT_SUCCESS(Status))
266 {
267 /* Return the byte count */
268 *lpBytesReturned = Iosb.Information;
269 }
270 else
271 {
272 /* Check for informational or warning failure */
273 if (!NT_ERROR(Status)) *lpBytesReturned = Iosb.Information;
274
275 /* Return a failure */
277 return FALSE;
278 }
279 }
280
281 /* Return success */
282 return TRUE;
283}
284
285/*
286 * @implemented
287 */
288BOOL
289WINAPI
291{
294
296 if (!NT_SUCCESS(Status))
297 {
299 return FALSE;
300 }
301
302 return TRUE;
303}
304
305/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
@ BasepSoundSentryNotification
Definition: basemsg.h:42
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
BOOL WINAPI CancelIo(IN HANDLE hFile)
Definition: deviceio.c:290
BOOL WINAPI Beep(IN DWORD dwFreq, IN DWORD dwDuration)
Definition: deviceio.c:48
VOID WINAPI NotifySoundSentry(VOID)
Definition: deviceio.c:22
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI GetConsoleDisplayMode(LPDWORD lpModeFlags)
Definition: console.c:526
return Iosb
Definition: create.c:4402
#define ULONG_PTR
Definition: config.h:101
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_OPEN_IF
Definition: from_kernel.h:56
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:727
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define MAXDWORD
#define IOCTL_BEEP_SET
Definition: ntddbeep.h:31
NTSTATUS NTAPI NtCancelIoFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: file.c:4019
#define STATUS_PENDING
Definition: ntstatus.h:82
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_FILE_SYSTEM
Definition: winioctl.h:115
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
Definition: connect.c:366
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
BASE_SOUND_SENTRY SoundSentryRequest
Definition: basemsg.h:298
union _BASE_API_MESSAGE::@3533 Data
static HANDLE hBeep
Definition: speaker.c:28
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:802
uint32_t * LPDWORD
Definition: typedefs.h:59
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define NT_ERROR(Status)
Definition: umtypes.h:106
_In_ DWORD _In_ DWORD _In_ DWORD _Out_ LPDWORD lpBytesReturned
Definition: winddi.h:1705
_In_ DWORD dwIoControlCode
Definition: winddi.h:1700
#define WINAPI
Definition: msvc.h:6