ReactOS  0.4.15-dev-985-gd905dd5
devname.c File Reference
#include <ntddk.h>
#include <ntddsnd.h>
#include <sndnames.h>
#include <sndtypes.h>
#include <debug.h>
Include dependency graph for devname.c:

Go to the source code of this file.

Classes

struct  _DEVICE_NAME_GROUP
 

Typedefs

typedef struct _DEVICE_NAME_GROUP DEVICE_NAME_GROUP
 

Functions

NTSTATUS ConstructDeviceName (IN PCWSTR Path, IN UCHAR Index, OUT PUNICODE_STRING DeviceName)
 
VOID FreeUnicodeStringBuffer (IN PUNICODE_STRING String)
 
NTSTATUS GetDefaultSoundDeviceNameBodies (IN UCHAR DeviceType, OUT PCWSTR *DeviceNameBody, OUT PCWSTR *DosDeviceNameBody)
 
NTSTATUS ConstructSoundDeviceNames (IN PCWSTR DeviceNameBody, IN PCWSTR DosDeviceNameBody, IN UCHAR Index, OUT PUNICODE_STRING FullDeviceName, OUT PUNICODE_STRING FullDosDeviceName)
 
NTSTATUS CreateSoundDevice (IN PDRIVER_OBJECT DriverObject, IN PCWSTR WideDeviceName, IN PCWSTR WideDosDeviceName, IN UCHAR Index, IN ULONG ExtensionSize, OUT PDEVICE_OBJECT *DeviceObject)
 
NTSTATUS CreateSoundDeviceWithDefaultName (IN PDRIVER_OBJECT DriverObject, IN UCHAR DeviceType, IN UCHAR Index, IN ULONG ExtensionSize, OUT PDEVICE_OBJECT *DeviceObject)
 
NTSTATUS DestroySoundDevice (IN PDEVICE_OBJECT DeviceObject, IN PCWSTR WideDosDeviceName, IN UCHAR Index)
 
NTSTATUS DestroySoundDeviceWithDefaultName (IN PDEVICE_OBJECT DeviceObject, IN UCHAR DeviceType, IN UCHAR Index)
 

Variables

DEVICE_NAME_GROUP SoundDeviceNameBodies [6]
 

Typedef Documentation

◆ DEVICE_NAME_GROUP

Function Documentation

◆ ConstructDeviceName()

NTSTATUS ConstructDeviceName ( IN PCWSTR  Path,
IN UCHAR  Index,
OUT PUNICODE_STRING  DeviceName 
)

Definition at line 73 of file devname.c.

77 {
78  UNICODE_STRING UnicodePath;
79  UNICODE_STRING UnicodeIndex;
80  WCHAR IndexStringBuffer[5];
81  USHORT Size;
82  USHORT LastCharacterIndex;
83 
84  /* Check for NULL parameters */
85  if ( ( ! Path ) || ( ! DeviceName ) )
86  {
87  DPRINT("Unexpected NULL parameter");
89  }
90 
91  /* Range-check */
92  if ( Index >= SOUND_MAX_DEVICES )
93  {
94  DPRINT("Device index %d out of range", Index);
96  }
97 
98  /* Initialise the unicode path string */
99  RtlInitUnicodeString(&UnicodePath, Path);
100 
101  /* Calculate the length to hold the full string */
102  Size = UnicodePath.Length +
103  sizeof(IndexStringBuffer) +
104  sizeof(UNICODE_NULL);
105 
106  /* Allocate memory for DeviceName */
108  DeviceName->MaximumLength = Size;
109 
110  if ( ! DeviceName->Buffer )
111  {
112  DPRINT("Couldn't allocate memory for device name string");
114  }
115 
116  /* Copy the path */
117  RtlCopyUnicodeString(DeviceName, &UnicodePath);
118 
119  /* Convert Index to string and append */
120  UnicodeIndex.Buffer = IndexStringBuffer;
121  UnicodeIndex.MaximumLength = sizeof(IndexStringBuffer);
122 
123  RtlIntegerToUnicodeString((ULONG)Index, 10, &UnicodeIndex);
125 
126  /* Terminate the string */
127  LastCharacterIndex = DeviceName->Length / sizeof(UNICODE_NULL);
128  DeviceName->Buffer[LastCharacterIndex] = UNICODE_NULL;
129 
130  return STATUS_SUCCESS;
131 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
WCHAR DeviceName[]
Definition: adapter.cpp:21
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define UNICODE_NULL
void DPRINT(...)
Definition: polytest.cpp:61
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PRTL_UNICODE_STRING_BUFFER Path
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConstructSoundDeviceNames(), and DestroySoundDevice().

◆ ConstructSoundDeviceNames()

NTSTATUS ConstructSoundDeviceNames ( IN PCWSTR  DeviceNameBody,
IN PCWSTR  DosDeviceNameBody,
IN UCHAR  Index,
OUT PUNICODE_STRING  FullDeviceName,
OUT PUNICODE_STRING  FullDosDeviceName 
)

Definition at line 207 of file devname.c.

213 {
215 
216  /* Check for NULL parameters */
217  if ( ( ! DeviceNameBody ) || ( ! DosDeviceNameBody ) ||
218  ( ! FullDeviceName ) || ( ! FullDosDeviceName ) )
219  {
220  DPRINT("Unexpected NULL parameter");
222  }
223 
224  /* Range-check */
225  if ( Index >= SOUND_MAX_DEVICES )
226  {
227  DPRINT("Device %d exceeds maximum", Index);
229  }
230 
231  Status = ConstructDeviceName(DeviceNameBody, Index, FullDeviceName);
232 
233  if ( ! NT_SUCCESS(Status) )
234  {
235  /* No need to clean up on failure here */
236  return Status;
237  }
238 
239  Status = ConstructDeviceName(DosDeviceNameBody, Index, FullDosDeviceName);
240 
241  if ( ! NT_SUCCESS(Status) )
242  {
243  /* We need to free the string we successfully got earlier */
244  FreeUnicodeStringBuffer(FullDeviceName);
245  return Status;
246  }
247 
248  return STATUS_SUCCESS;
249 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
VOID FreeUnicodeStringBuffer(IN PUNICODE_STRING String)
Definition: devname.c:142
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS ConstructDeviceName(IN PCWSTR Path, IN UCHAR Index, OUT PUNICODE_STRING DeviceName)
Definition: devname.c:73

Referenced by CreateSoundDevice().

◆ CreateSoundDevice()

NTSTATUS CreateSoundDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PCWSTR  WideDeviceName,
IN PCWSTR  WideDosDeviceName,
IN UCHAR  Index,
IN ULONG  ExtensionSize,
OUT PDEVICE_OBJECT DeviceObject 
)

Definition at line 261 of file devname.c.

268 {
270 
273 
274  /* Check for NULL parameters */
275  if ( ( ! DriverObject ) || ( ! DeviceObject ) ||
276  ( ! WideDeviceName ) || ( ! WideDosDeviceName ) )
277  {
278  DPRINT("Unexpected NULL parameter");
280  }
281 
282  /* Range-check */
283  if ( Index >= SOUND_MAX_DEVICES )
284  {
285  DPRINT("Device index %d exceeds maximum", Index);
287  }
288 
289  /* Construct the device and DOS device names */
290  Status = ConstructSoundDeviceNames(WideDeviceName,
291  WideDosDeviceName,
292  Index,
293  &DeviceName,
294  &DosDeviceName);
295 
296  if ( ! NT_SUCCESS(Status) )
297  {
298  return Status;
299  }
300 
301  DPRINT("Creating device %ws\n", DeviceName.Buffer);
302 
303  /* Now create the device */
305  ExtensionSize,
306  &DeviceName,
308  0,
309  FALSE,
310  DeviceObject);
311 
312  if ( ! NT_SUCCESS(Status) )
313  {
314  /* These will have been allocated by ConstructSoundDeviceNames */
317 
318  return Status;
319  }
320 
321  DPRINT("Creating link %ws\n", DosDeviceName.Buffer);
322 
323  /* Create a symbolic link for the DOS deviec name */
325 
326  if ( ! NT_SUCCESS(Status) )
327  {
329 
330  /* These will have been allocated by ConstructSoundDeviceNames */
333 
334  return Status;
335  }
336 
337  return STATUS_SUCCESS;
338 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
VOID FreeUnicodeStringBuffer(IN PUNICODE_STRING String)
Definition: devname.c:142
#define FALSE
Definition: types.h:117
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
static char DosDeviceName[DEVICE_SIZE]
Definition: lsdd.c:26
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
NTSTATUS ConstructSoundDeviceNames(IN PCWSTR DeviceNameBody, IN PCWSTR DosDeviceNameBody, IN UCHAR Index, OUT PUNICODE_STRING FullDeviceName, OUT PUNICODE_STRING FullDosDeviceName)
Definition: devname.c:207
Status
Definition: gdiplustypes.h:24
#define FILE_DEVICE_SOUND
Definition: winioctl.h:134
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CreateSoundDeviceWithDefaultName().

◆ CreateSoundDeviceWithDefaultName()

NTSTATUS CreateSoundDeviceWithDefaultName ( IN PDRIVER_OBJECT  DriverObject,
IN UCHAR  DeviceType,
IN UCHAR  Index,
IN ULONG  ExtensionSize,
OUT PDEVICE_OBJECT DeviceObject 
)

Definition at line 349 of file devname.c.

355 {
357  PCWSTR WideDeviceName = NULL;
358  PCWSTR WideDosDeviceName = NULL;
359 
360  /* Check for NULL parameters */
361  if ( ( ! DriverObject ) || ( ! DeviceObject ) )
362  {
363  DPRINT("Unexpected NULL parameter");
365  }
366 
367  /* Range-check */
368  if ( Index >= SOUND_MAX_DEVICES )
369  {
370  DPRINT("Device index %d exceeds maximum", Index);
372  }
373 
374  /* Look-up the default name based on the device type */
376  &WideDeviceName,
377  &WideDosDeviceName);
378 
379  if ( ! NT_SUCCESS(Status) )
380  {
381  return Status;
382  }
383 
384  /* Go create the device! */
386  WideDeviceName,
387  WideDosDeviceName,
388  Index,
389  ExtensionSize,
390  DeviceObject);
391 
392  if ( ! NT_SUCCESS(Status) )
393  {
394  /* No clean-up to do */
395  return Status;
396  }
397 
398  return STATUS_SUCCESS;
399 }
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
DeviceType
Definition: mmdrv.h:41
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS CreateSoundDevice(IN PDRIVER_OBJECT DriverObject, IN PCWSTR WideDeviceName, IN PCWSTR WideDosDeviceName, IN UCHAR Index, IN ULONG ExtensionSize, OUT PDEVICE_OBJECT *DeviceObject)
Definition: devname.c:261
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
NTSTATUS GetDefaultSoundDeviceNameBodies(IN UCHAR DeviceType, OUT PCWSTR *DeviceNameBody, OUT PCWSTR *DosDeviceNameBody)
Definition: devname.c:167
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ DestroySoundDevice()

NTSTATUS DestroySoundDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PCWSTR  WideDosDeviceName,
IN UCHAR  Index 
)

Definition at line 402 of file devname.c.

406 {
409 
410  /* Check for NULL parameters */
411  if ( ( ! WideDosDeviceName ) || ( ! DeviceObject ) )
412  {
413  DPRINT("Unexpected NULL parameter");
415  }
416 
417  /* Range-check */
418  if ( Index >= SOUND_MAX_DEVICES )
419  {
420  DPRINT("Device %d exceeds maximum", Index);
422  }
423 
424  Status = ConstructDeviceName(WideDosDeviceName, Index, &DosDeviceName);
425 
426  if ( ! NT_SUCCESS(Status) )
427  {
428  return Status;
429  }
430 
431  DPRINT("Deleting symlink %ws\n", DosDeviceName.Buffer);
432 
434  DPRINT("Status of symlink deletion is 0x%08x\n", Status);
435 /*
436  ASSERT(NT_SUCCESS(Status));
437 */
438 
440 
441  return STATUS_SUCCESS;
442 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
static char DosDeviceName[DEVICE_SIZE]
Definition: lsdd.c:26
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS ConstructDeviceName(IN PCWSTR Path, IN UCHAR Index, OUT PUNICODE_STRING DeviceName)
Definition: devname.c:73

Referenced by DestroySoundDeviceWithDefaultName().

◆ DestroySoundDeviceWithDefaultName()

NTSTATUS DestroySoundDeviceWithDefaultName ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  DeviceType,
IN UCHAR  Index 
)

Definition at line 445 of file devname.c.

449 {
451  PCWSTR WideDosDeviceName = NULL;
452 
453  /* Check for NULL parameters */
454  if ( ( ! DeviceObject ) )
455  {
456  DPRINT("Unexpected NULL parameter");
458  }
459 
460  /* Range-check */
461  if ( Index >= SOUND_MAX_DEVICES )
462  {
463  DPRINT("Device index %d exceeds maximum", Index);
465  }
466 
467  /* Look-up the default name based on the device type */
469  NULL,
470  &WideDosDeviceName);
471 
472  if ( ! NT_SUCCESS(Status) )
473  {
474  return Status;
475  }
476 
477  DPRINT("DOS device name at %p\n", WideDosDeviceName);
478 
479  DPRINT("DOS device name is based on %ws\n", WideDosDeviceName);
480 
481  return DestroySoundDevice(DeviceObject, WideDosDeviceName, Index);
482 }
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
DeviceType
Definition: mmdrv.h:41
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
Status
Definition: gdiplustypes.h:24
NTSTATUS DestroySoundDevice(IN PDEVICE_OBJECT DeviceObject, IN PCWSTR WideDosDeviceName, IN UCHAR Index)
Definition: devname.c:402
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
NTSTATUS GetDefaultSoundDeviceNameBodies(IN UCHAR DeviceType, OUT PCWSTR *DeviceNameBody, OUT PCWSTR *DosDeviceNameBody)
Definition: devname.c:167

◆ FreeUnicodeStringBuffer()

VOID FreeUnicodeStringBuffer ( IN PUNICODE_STRING  String)

Definition at line 142 of file devname.c.

143 {
144  ASSERT(String != NULL);
145  ASSERT(String->Buffer != NULL);
146 
147  ExFreePool(String->Buffer);
148 
149  String->Buffer = NULL;
150  String->Length = 0;
151  String->MaximumLength = 0;
152 }
static WCHAR String[]
Definition: stringtable.c:55
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by ConstructSoundDeviceNames(), and CreateSoundDevice().

◆ GetDefaultSoundDeviceNameBodies()

NTSTATUS GetDefaultSoundDeviceNameBodies ( IN UCHAR  DeviceType,
OUT PCWSTR DeviceNameBody,
OUT PCWSTR DosDeviceNameBody 
)

Definition at line 167 of file devname.c.

171 {
173  {
174  DPRINT("Invalid device type");
176  }
177 
178  if ( DeviceNameBody )
179  {
180  DPRINT("Reporting device name\n");
181  *DeviceNameBody = SoundDeviceNameBodies[DeviceType].DeviceName;
182  DPRINT("%ws\n", *DeviceNameBody);
183  }
184 
185  if ( DosDeviceNameBody )
186  {
187  DPRINT("Reporting DOS device name\n");
188  *DosDeviceNameBody = SoundDeviceNameBodies[DeviceType].DosDeviceName;
189  DPRINT("%ws\n", *DosDeviceNameBody);
190  }
191 
192  return STATUS_SUCCESS;
193 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
DeviceType
Definition: mmdrv.h:41
PCWSTR DosDeviceName
Definition: devname.c:30
void DPRINT(...)
Definition: polytest.cpp:61
DEVICE_NAME_GROUP SoundDeviceNameBodies[6]
Definition: devname.c:33
#define IS_VALID_SOUND_DEVICE_TYPE(x)
Definition: sndtypes.h:43
return STATUS_SUCCESS
Definition: btrfs.c:3014
PCWSTR DeviceName
Definition: devname.c:29

Referenced by CreateSoundDeviceWithDefaultName(), and DestroySoundDeviceWithDefaultName().

Variable Documentation

◆ SoundDeviceNameBodies

DEVICE_NAME_GROUP SoundDeviceNameBodies[6]
Initial value:
=
{
{
},
{
},
{
},
{
},
{
},
{
}
}
#define DD_MIDI_IN_DOS_DEVICE_NAME_U
Definition: sndnames.h:45
#define DD_MIX_DOS_DEVICE_NAME_U
Definition: sndnames.h:59
#define DD_WAVE_OUT_DEVICE_NAME_U
Definition: sndnames.h:36
#define DD_MIDI_OUT_DEVICE_NAME_U
Definition: sndnames.h:50
#define DD_MIDI_IN_DEVICE_NAME_U
Definition: sndnames.h:43
#define DD_MIDI_OUT_DOS_DEVICE_NAME_U
Definition: sndnames.h:52
#define DD_AUX_DEVICE_NAME_U
Definition: sndnames.h:64
#define DD_WAVE_OUT_DOS_DEVICE_NAME_U
Definition: sndnames.h:38
#define DD_MIX_DEVICE_NAME_U
Definition: sndnames.h:57
#define DD_WAVE_IN_DEVICE_NAME_U
Definition: sndnames.h:29
#define DD_WAVE_IN_DOS_DEVICE_NAME_U
Definition: sndnames.h:31
#define DD_AUX_DOS_DEVICE_NAME_U
Definition: sndnames.h:66

Definition at line 33 of file devname.c.

Referenced by GetDefaultSoundDeviceNameBodies().