ReactOS 0.4.15-dev-7788-g1ad9096
deviceio.c File Reference
#include <k32.h>
#include <ntddbeep.h>
#include <debug.h>
Include dependency graph for deviceio.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID WINAPI NotifySoundSentry (VOID)
 
BOOL WINAPI Beep (IN DWORD dwFreq, IN DWORD dwDuration)
 
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)
 
BOOL WINAPI CancelIo (IN HANDLE hFile)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file deviceio.c.

Function Documentation

◆ Beep()

BOOL WINAPI Beep ( IN DWORD  dwFreq,
IN DWORD  dwDuration 
)

Definition at line 48 of file deviceio.c.

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}
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
VOID WINAPI NotifySoundSentry(VOID)
Definition: deviceio.c:22
#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
#define FILE_OPEN_IF
Definition: from_kernel.h:56
Status
Definition: gdiplustypes.h:25
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#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
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)
#define MAXDWORD
#define IOCTL_BEEP_SET
Definition: ntddbeep.h:31
#define L(x)
Definition: ntvdm.h:50
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
static HANDLE hBeep
Definition: speaker.c:28
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:802
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by _beep(), CommandChoice(), ConRingBell(), ConWndProc(), PlaySoundRoutine(), and VidBiosPrintCharacter().

◆ CancelIo()

BOOL WINAPI CancelIo ( IN HANDLE  hFile)

Definition at line 290 of file deviceio.c.

291{
294
296 if (!NT_SUCCESS(Status))
297 {
299 return FALSE;
300 }
301
302 return TRUE;
303}
_In_ HANDLE hFile
Definition: mswsock.h:90
NTSTATUS NTAPI NtCancelIoFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: file.c:4019

Referenced by FileAsyncReader_BeginFlush(), overlapped_server(), PipeThreadProc(), CDirectoryWatcher::QuitWatching(), ScmControlService(), ScmSendStartCommand(), ScmWaitForServiceConnect(), tcp_recv(), and tcp_send().

◆ DeviceIoControl()

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 at line 136 of file deviceio.c.

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}
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
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_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
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
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 STATUS_PENDING
Definition: ntstatus.h:82
#define FILE_DEVICE_FILE_SYSTEM
Definition: winioctl.h:115
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#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

Referenced by _tmain(), AddDrive(), AllocAndGetEntityArray(), ata_check_controller(), ata_check_unit(), ata_scan(), ata_send_ioctl(), ata_send_scsi(), AuxGetAudio(), AuxSetAudio(), BasepGetVolumeNameFromReparsePoint(), ClearCommBreak(), ClearCommError(), Control(), count_blocks(), createIpForwardEntry(), CreateJunction(), DECLARE_INTERFACE_(), delegation_return(), deleteIpForwardEntry(), device_io(), DismountMain(), DoEjectDrive(), EjectDrive(), EnableVolumeCompression(), EscapeCommFunction(), FindFirstVolumeW(), get_drive_connection(), get_freespace(), DriveVolume::GetBitmap(), DriveVolume::GetClusterInfo(), GetCommMask(), GetCommModemStatus(), GetCommState(), GetCommTimeouts(), GetDeviceCapabilities(), GetDeviceData(), GetDiskGeometry(), getDriverData(), GetIFEntry(), GetInquiryData(), GetIPSNMPInfo(), GetTdiEntityType(), GetVolumeExtents(), GetVolumeNameForRoot(), GetVolumePathNamesForVolumeNameW(), HandleFile(), hasArp(), HidD_FlushQueue(), HidD_GetAttributes(), HidD_GetConfiguration(), HidD_GetFeature(), HidD_GetIndexedString(), HidD_GetInputReport(), HidD_GetManufacturerString(), HidD_GetMsGenreDescriptor(), HidD_GetNumInputBuffers(), HidD_GetPhysicalDescriptor(), HidD_GetPreparsedData(), HidD_GetProductString(), HidD_GetSerialNumberString(), HidD_SetConfiguration(), HidD_SetFeature(), HidD_SetNumInputBuffers(), HidD_SetOutputReport(), IDirectSoundCaptureBufferImpl_Start(), IsLetterOwned(), IsWlanAdapter(), KmtRunKernelTest(), KmtSendBufferToDriver(), KmtSendStringToDriver(), KmtSendToDriver(), KmtSendUlongToDriver(), KmtSendWStringToDriver(), KmtUserCallbackThread(), CKsInterfaceHandler::KsProcessMediaSamples(), KsSynchronousDeviceControl(), ListTests(), LocalmonGetPrinterDataFromPort(), LockOrUnlockVolume(), main(), DriveVolume::MoveFileDumb(), my_open(), MyLockVolume(), MyUnlockVolume(), NtfsInfoMain(), DriveVolume::ObtainInfo(), OpenAdapterHandle(), OpenDriverHandle(), PerformIO(), PerformMount(), PrimaryDirectSoundBuffer_Write(), PrintDiskData(), PurgeComm(), query_dsym(), QueryDeviceName(), QueryMain(), QuerySuggestedLinkName(), QueryUniqueId(), BtrfsContextMenu::reflink_copy(), reflink_copy2(), RefreshDevicesList(), RemountImage(), RemoveDirectoryW(), RemoveDrive(), RunTest(), SendRequest(), SendTo_NFS41Driver(), ServiceStart(), SetCommBreak(), SetCommMask(), SetCommState(), SetCommTimeouts(), setDriverData(), SetIpNetEntry(), SetMain(), SetupComm(), SetWaveFormat(), START_TEST(), StatisticsMain(), SyncOverlappedDeviceIoControl(), tdiGetMibForIfEntity(), tdiGetMibForIpEntity(), test_AT_ARP_STATS(), test_disk_extents(), test_dvd_read_structure(), test_IF_MIB_STATS(), test_IP_MIB_STATS(), test_junction_points(), TestKs(), thread_main(), TransmitCommChar(), TryToLockOrUnlockDrive(), UDFPhSendIOCTL(), VfdCloseImage(), VfdDismountVolume(), VfdFormatMedia(), VfdGetDeviceName(), VfdGetDeviceNumber(), VfdGetDriverVersion(), VfdGetGlobalLink(), VfdGetImageInfo(), VfdGetMediaState(), VfdOpenImage(), VfdSaveImage(), VfdSetGlobalLink(), VfdWriteProtect(), WahCreateSocketHandle(), WaitCommEvent(), WlanConnect(), WlanDisconnect(), WlanPrintCurrentStatus(), WlanScan(), WriteMidi(), and WSHIoctl_GetInterfaceList().

◆ NotifySoundSentry()

VOID WINAPI NotifySoundSentry ( VOID  )

Definition at line 22 of file deviceio.c.

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}
@ BasepSoundSentryNotification
Definition: basemsg.h:42
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
BOOL WINAPI GetConsoleDisplayMode(LPDWORD lpModeFlags)
Definition: console.c:526
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
BASE_SOUND_SENTRY SoundSentryRequest
Definition: basemsg.h:298
union _BASE_API_MESSAGE::@3533 Data

Referenced by Beep().