ReactOS  0.4.15-dev-5606-gf34e425
settings.c
Go to the documentation of this file.
1 /*
2  *
3  * COPYRIGHT: See COPYING in the top level directory
4  * PROJECT: ReactOS kernel
5  * FILE: drivers/dd/sndblst/settings.c
6  * PURPOSE: MPU-401 MIDI device driver setting management
7  * PROGRAMMER: Andrew Greenwood
8  * UPDATE HISTORY:
9  * Sept 28, 2003: Created
10  */
11 
12 #include <ntddk.h>
13 #include "sndblst.h"
14 #include "sbdebug.h" // our own debug helper
15 
16 
17 #if 0
19 OpenDevicesKey(
21  OUT PHANDLE Key)
22 /*
23  Description:
24  Create a volatile key under this driver's Services node to contain
25  the device name list.
26 
27  Parameters:
28  RegistryPath The location of the registry entry
29  Key The key in the registry
30 
31  Return Value:
32  NT status STATUS_SUCCESS if successful (duh...)
33 */
34 {
35  NTSTATUS s;
36  HANDLE hKey;
38  UNICODE_STRING uStr;
39 
40  // Attempt to open the key
41 
43 
46 
47  s = ZwOpenKey(&hKey, KEY_CREATE_SUB_KEY, &oa);
48 
49  if (! NT_SUCCESS(s))
50  return s; // Problem
51 
52 
53  // Now create sub key
54 
56 
59 
60  s = ZwCreateKey(Key, KEY_ALL_ACCESS, &oa, 0, NULL, REG_OPTION_VOLATILE,
61  NULL);
62 
63  ZwClose(hKey);
64 
65  return s;
66 }
67 #endif
68 
69 
72  IN PWSTR SubKey,
75 /*
76  Description:
77  Enumerate the device subkeys in the driver's registry entry, and
78  call the specified callback routine for each device.
79 
80  Parameters:
81  RegistryPath The location of the registry entry
82  Subkey The device's subkey
83  Callback A routine called for each device
84  Context ???
85 
86  Return Value:
87  NT status STATUS_SUCCESS if successful
88 */
89 {
90  NTSTATUS s;
92  HANDLE hKey, hSubKey;
94  ULONG i;
95 
96  // Attempt to open the key
97 
100 
101  s = ZwOpenKey(&hKey, KEY_READ, &oa);
102 
103  TEST_STATUS(s); // debugging
104 
105  if (! NT_SUCCESS(s))
106  return s; // Problem
107 
109 
110  DPRINT("Subkey: %wZ\n", &SubkeyName);
111 
114 
115  s = ZwOpenKey(&hSubKey, KEY_ENUMERATE_SUB_KEYS, &oa);
116 
117  ZwClose(hKey);
118 
119  TEST_STATUS(s); // debugging
120 
121  if (! NT_SUCCESS(s))
122  return s;
123 
124 
125  // And now, the enumeration
126 
127  for (i = 0;; i ++)
128  {
131  ULONG ResultLength = 0;
132  ULONG Size = 0;
133  PWSTR Pos;
134  PWSTR Name;
135 
136  // Find the length of the subkey data
137 
138 // Info.NameLength = 0; // TEMPORARY!
139 
140  s = ZwEnumerateKey(hSubKey, i, KeyBasicInformation, &Info,
141  sizeof(Info), &ResultLength);
142 
143  if (s == STATUS_NO_MORE_ENTRIES)
144  break;
145 
146  DPRINT("Found an entry, allocating memory...\n");
147 
148 // Size = Info.NameLength + FIELD_OFFSET(KEY_BASIC_INFORMATION, Name[0]);
150 
151  DPRINT("Size is %d\n", Size);
152 
154 
155  if (pInfo == NULL)
156  {
157  DPRINT("INSUFFICIENT RESOURCES!\n");
159  break;
160  }
161 
162  DPRINT("Re-enumerating...\n");
163 
164  s = ZwEnumerateKey(hSubKey, i, KeyBasicInformation, pInfo, Size,
165  &ResultLength);
166 
167 // TEST_STATUS(s); // debugging
168 
169  if (! NT_SUCCESS(s))
170  {
171  ExFreePool((PVOID) pInfo);
173  break;
174  }
175 
176  DPRINT("Allocating memory for name...\n");
177 
179  RegistryPath->Length + sizeof(WCHAR) +
180  SubkeyName.Length + sizeof(WCHAR) +
181  pInfo->NameLength + sizeof(UNICODE_NULL));
182 
183  if (Name == NULL)
184  {
185  DPRINT("INSUFFICIENT RESOURCES!");
186  ExFreePool((PVOID) pInfo);
188  }
189 
190  // Copy the key name
191  RtlCopyMemory((PVOID)Name, (PVOID)RegistryPath->Buffer, RegistryPath->Length);
192  Pos = Name + (RegistryPath->Length / sizeof(WCHAR));
193  Pos[0] = '\\';
194  Pos++;
195 
196  // Copy the parameters sub key name
197  RtlCopyMemory((PVOID)Pos, (PVOID)SubKey, SubkeyName.Length); //SubkeyName?
198  Pos += SubkeyName.Length / sizeof(WCHAR);
199  Pos[0] = '\\';
200  Pos ++;
201 
202  // Copy the device sub key name
203  RtlCopyMemory((PVOID)Pos, (PVOID)pInfo->Name, pInfo->NameLength);
204  Pos += pInfo->NameLength / sizeof(WCHAR);
205  Pos[0] = UNICODE_NULL;
206 
207  ExFreePool((PVOID)pInfo);
208 
209  DPRINT("Calling callback...\n");
210 
211  s = (*Callback)(Name, Context);
212 
213  if (! NT_SUCCESS(s))
214  { DPRINT("Callback FAILED\n");
215  break;}
216  }
217 
218  ZwClose(hSubKey);
219 
220  DPRINT("%d device registry keys found\n", i);
221 
222  if ((i == 0) && (s == STATUS_NO_MORE_ENTRIES))
224 
226 }
227 
228 
229 
235  IN PVOID Context,
237 /*
238  Description:
239  Read the settings for a particular device
240 
241  Parameters:
242  ValueName The value to read from the registry
243  ValueType ?
244  ValueData ?
245  ValueLength ?
246  Context The configuration structure to write to
247  EntryContext ?
248 
249  Return Value:
250  NT status STATUS_SUCCESS if successful
251 */
252 {
254 
255  if (ValueType == REG_DWORD)
256  {
258  {
259  DeviceInfo->Port = *(PULONG) ValueData;
260  DPRINT("Registry port = 0x%x\n", DeviceInfo->Port);
261  }
262 
263  // More to come... (config.c)
264  }
265 
266  else
267  {
268  // ?
269  }
270 
271  return STATUS_SUCCESS;
272 }
273 
274 
275 #if 0
278  IN ULONG Port,
279  IN ULONG IRQ,
280  IN ULONG DMA)
281 /*
282  Description:
283  Saves the settings for a particular device
284 
285  Parameters:
286  RegistryPath Where to save the settings to
287  Port The device's port number
288  IRQ The device's interrupt number
289  DMA The device's DMA channel
290 
291  Return Value:
292  NT status STATUS_SUCCESS if successful
293 */
294 {
295  DPRINT("SaveSettings() unimplemented\n");
296 
297 // UNIMPLEMENTED;
298 
299  return STATUS_SUCCESS;
300 }
301 #endif
CPPORT Port[4]
Definition: headless.c:35
#define IN
Definition: typedefs.h:39
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
ush Pos
Definition: deflate.h:92
enum TestStatus TEST_STATUS
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define UNICODE_NULL
struct NameRec_ * Name
Definition: cdprocs.h:459
struct _KEY_BASIC_INFORMATION * PKEY_BASIC_INFORMATION
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4196
NTSTATUS NTAPI EnumDeviceKeys(IN PUNICODE_STRING RegistryPath, IN PWSTR SubKey, IN PREGISTRY_CALLBACK_ROUTINE Callback, IN PVOID Context)
Definition: settings.c:73
REGISTRY_CALLBACK_ROUTINE * PREGISTRY_CALLBACK_ROUTINE
Definition: mpu401.h:121
void SaveSettings(void)
Definition: settings.c:115
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
GLdouble s
Definition: gl.h:2039
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FxAutoRegKey hKey
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define DEVICE_SUBKEY
Definition: mpu401.h:22
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
_In_opt_ PWSTR SubkeyName
Definition: cdrom.h:960
struct tagContext Context
Definition: acpixf.h:1038
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#define STATUS_SUCCESS
Definition: shellext.h:65
#define REGISTRY_PORT
Definition: mpu401.h:25
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define DPRINT
Definition: sndvol32.h:71
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
#define REG_DWORD
Definition: sdbapi.c:596
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
void LoadSettings(void)
Definition: settings.c:53
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271