ReactOS  0.4.15-dev-439-g292f67a
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
21 static NTSTATUS
22 OpenDevicesKey(
24  OUT PHANDLE Key)
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;
39  HANDLE hKey;
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 
66  ZwClose(hKey);
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 
116  hKey, (PSECURITY_DESCRIPTOR)NULL);
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  {
134  ULONG ResultLength = 0;
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 
146  if (s == STATUS_NO_MORE_ENTRIES)
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 
238  IN PVOID Context,
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
279 static NTSTATUS SaveSettings(
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 
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
CPPORT Port[4]
Definition: headless.c:34
#define IN
Definition: typedefs.h:39
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:193
#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:55
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4062
LONG NTSTATUS
Definition: precomp.h:26
ush Pos
Definition: deflate.h:92
enum TestStatus TEST_STATUS
struct TraceInfo Info
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
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
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:464
struct _KEY_BASIC_INFORMATION * PKEY_BASIC_INFORMATION
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4050
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
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
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
GLdouble s
Definition: gl.h:2039
_In_opt_ PWSTR SubkeyName
Definition: classpnp.h:1209
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define DEVICE_SUBKEY
Definition: mpu401.h:22
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int * PULONG
Definition: retypes.h:1
#define OUT
Definition: typedefs.h:40
struct tagContext Context
Definition: acpixf.h:1034
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
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
#define REGISTRY_PORT
Definition: mpu401.h:25
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:605
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define REG_DWORD
Definition: sdbapi.c:596
LPFNPSPCALLBACK Callback
Definition: desk.c:112
#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