ReactOS 0.4.16-dev-197-g92996da
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: services/dd/mpu401/settings.c
6 * PURPOSE: MPU-401 MIDI device driver setting management
7 * PROGRAMMER: Andrew Greenwood
8 * UPDATE HISTORY:
9 * Sept 27, 2003: Created
10 */
11
12#include <ntddk.h>
13
14#include "mpu401.h"
15
16#define NDEBUG
17#include <debug.h>
18#include "sbdebug.h" // our own debug helper
19
20#if 0
21static NTSTATUS
22OpenDevicesKey(
25/*
26 Description:
27 Create a volatile key under this driver's Services node to contain
28 the device name list.
29
30 Parameters:
31 RegistryPath The location of the registry entry
32 Key The key in the registry
33
34 Return Value:
35 NT status STATUS_SUCCESS if successful (duh...)
36*/
37{
38 NTSTATUS s;
41 UNICODE_STRING uStr;
42
43 // Attempt to open the key
44
46
49
50 s = ZwOpenKey(&hKey, KEY_CREATE_SUB_KEY, &oa);
51
52 if (! NT_SUCCESS(s))
53 return s; // Problem
54
55
56 // Now create sub key
57
59
62
63 s = ZwCreateKey(Key, KEY_ALL_ACCESS, &oa, 0, NULL, REG_OPTION_VOLATILE,
64 NULL);
65
67
68 return s;
69}
70#endif
71
72
75 IN PWSTR SubKey,
78/*
79 Description:
80 Enumerate the device subkeys in the driver's registry entry, and
81 call the specified callback routine for each device.
82
83 Parameters:
84 RegistryPath The location of the registry entry
85 Subkey The device's subkey
86 Callback A routine called for each device
87 Context ???
88
89 Return Value:
90 NT status STATUS_SUCCESS if successful
91*/
92{
93 NTSTATUS s;
95 HANDLE hKey, hSubKey;
97 ULONG i;
98
99 // Attempt to open the key
100
103
104 s = ZwOpenKey(&hKey, KEY_READ, &oa);
105
106 TEST_STATUS(s); // debugging
107
108 if (! NT_SUCCESS(s))
109 return s; // Problem
110
112
113 DPRINT("Subkey: %wZ\n", &SubkeyName);
114
117
118 s = ZwOpenKey(&hSubKey, KEY_ENUMERATE_SUB_KEYS, &oa);
119
120 ZwClose(hKey);
121
122 TEST_STATUS(s); // debugging
123
124 if (! NT_SUCCESS(s))
125 return s;
126
127
128 // And now, the enumeration
129
130 for (i = 0;; i ++)
131 {
135 ULONG Size = 0;
136 PWSTR Pos;
137 PWSTR Name;
138
139 // Find the length of the subkey data
140
141// Info.NameLength = 0; // TEMPORARY!
142
143 s = ZwEnumerateKey(hSubKey, i, KeyBasicInformation, &Info,
144 sizeof(Info), &ResultLength);
145
147 break;
148
149 DPRINT("Found an entry, allocating memory...\n");
150
151// Size = Info.NameLength + FIELD_OFFSET(KEY_BASIC_INFORMATION, Name[0]);
153
154 DPRINT("Size is %d\n", Size);
155
157
158 if (pInfo == NULL)
159 {
160 DPRINT("INSUFFICIENT RESOURCES!\n");
162 break;
163 }
164
165 DPRINT("Re-enumerating...\n");
166
167 s = ZwEnumerateKey(hSubKey, i, KeyBasicInformation, pInfo, Size,
168 &ResultLength);
169
170// TEST_STATUS(s); // debugging
171
172 if (! NT_SUCCESS(s))
173 {
174 ExFreePool((PVOID) pInfo);
176 break;
177 }
178
179 DPRINT("Allocating memory for name...\n");
180
182 RegistryPath->Length + sizeof(WCHAR) +
183 SubkeyName.Length + sizeof(WCHAR) +
184 pInfo->NameLength + sizeof(UNICODE_NULL));
185
186 if (Name == NULL)
187 {
188 DPRINT("INSUFFICIENT RESOURCES!");
189 ExFreePool((PVOID) pInfo);
191 }
192
193 // Copy the key name
195 Pos = Name + (RegistryPath->Length / sizeof(WCHAR));
196 Pos[0] = '\\';
197 Pos++;
198
199 // Copy the parameters sub key name
200 RtlCopyMemory((PVOID)Pos, (PVOID)SubKey, SubkeyName.Length); //SubkeyName?
201 Pos += SubkeyName.Length / sizeof(WCHAR);
202 Pos[0] = '\\';
203 Pos ++;
204
205 // Copy the device sub key name
206 RtlCopyMemory((PVOID)Pos, (PVOID)pInfo->Name, pInfo->NameLength);
207 Pos += pInfo->NameLength / sizeof(WCHAR);
208 Pos[0] = UNICODE_NULL;
209
210 ExFreePool((PVOID)pInfo);
211
212 DPRINT("Calling callback...\n");
213
214 s = (*Callback)(Name, Context);
215
216 if (! NT_SUCCESS(s))
217 { DPRINT("Callback FAILED\n");
218 break;}
219 }
220
221 ZwClose(hSubKey);
222
223 DPRINT("%d device registry keys found\n", i);
224
225 if ((i == 0) && (s == STATUS_NO_MORE_ENTRIES))
227
229}
230
231
232
240/*
241 Description:
242 Read the settings for a particular device
243
244 Parameters:
245 ValueName The value to read from the registry
246 ValueType ?
247 ValueData ?
248 ValueLength ?
249 Context The configuration structure to write to
250 EntryContext ?
251
252 Return Value:
253 NT status STATUS_SUCCESS if successful
254*/
255{
257
258 if (ValueType == REG_DWORD)
259 {
261 {
262 DeviceInfo->Port = *(PULONG) ValueData;
263 DPRINT("Registry port = 0x%x\n", DeviceInfo->Port);
264 }
265
266 // More to come... (config.c)
267 }
268
269 else
270 {
271 // ?
272 }
273
274 return STATUS_SUCCESS;
275}
276
277
278#if 0
281 IN ULONG Port,
282 IN ULONG IRQ,
283 IN ULONG DMA)
284/*
285 Description:
286 Saves the settings for a particular device
287
288 Parameters:
289 RegistryPath Where to save the settings to
290 Port The device's port number
291 IRQ The device's interrupt number
292 DMA The device's DMA channel
293
294 Return Value:
295 NT status STATUS_SUCCESS if successful
296*/
297{
298// NTSTATUS s;
299
300 DPRINT("SaveSettings() unimplemented\n");
301
302// UNIMPLEMENTED;
303
304 return STATUS_SUCCESS;
305}
306#endif
307
struct NameRec_ * Name
Definition: cdprocs.h:460
void SaveSettings(void)
Definition: settings.c:115
void LoadSettings(void)
Definition: settings.c:53
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ PWSTR SubkeyName
Definition: cdrom.h:960
ush Pos
Definition: deflate.h:92
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS NTAPI EnumDeviceKeys(IN PUNICODE_STRING RegistryPath, IN PWSTR SubKey, IN PREGISTRY_CALLBACK_ROUTINE Callback, IN PVOID Context)
Definition: settings.c:73
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
FxAutoRegKey hKey
GLdouble s
Definition: gl.h:2039
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
CPPORT Port[4]
Definition: headless.c:35
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REGISTRY_PORT
Definition: mpu401.h:25
REGISTRY_CALLBACK_ROUTINE * PREGISTRY_CALLBACK_ROUTINE
Definition: mpu401.h:121
#define DEVICE_SUBKEY
Definition: mpu401.h:22
#define TEST_STATUS(s)
Definition: sbdebug.h:2
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4219
@ KeyBasicInformation
Definition: nt_native.h:1131
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
struct _KEY_BASIC_INFORMATION * PKEY_BASIC_INFORMATION
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define UNICODE_NULL
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
#define REG_DWORD
Definition: sdbapi.c:596
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
__wchar_t WCHAR
Definition: xmlstorage.h:180