ReactOS 0.4.15-dev-7842-g558ab78
vfdlink.c File Reference
#include "imports.h"
#include "vfddrv.h"
#include "vfddbg.h"
Include dependency graph for vfdlink.c:

Go to the source code of this file.

Functions

NTSTATUS VfdSetLink (IN PDEVICE_EXTENSION DeviceExtension, IN CHAR DriveLetter)
 
NTSTATUS VfdLoadLink (IN PDEVICE_EXTENSION DeviceExtension, IN PWSTR RegistryPath)
 
NTSTATUS VfdStoreLink (IN PDEVICE_EXTENSION DeviceExtension)
 

Function Documentation

◆ VfdLoadLink()

NTSTATUS VfdLoadLink ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PWSTR  RegistryPath 
)

Definition at line 135 of file vfdlink.c.

138{
140 WCHAR name_buf[20];
141 ULONG letter;
142 ULONG zero = 0;
144
145 VFDTRACE(VFDINFO, ("[VFD] VfdLoadLink - IN\n"));
146
147 RtlZeroMemory(params, sizeof(params));
148
149#ifndef __REACTOS__
150 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
151
152 _snwprintf(name_buf, sizeof(name_buf) - 1,
154 DeviceExtension->DeviceNumber);
155#else
156 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
157
158 _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
160 DeviceExtension->DeviceNumber);
161#endif
162
164 params[0].Name = name_buf;
165 params[0].EntryContext = &letter;
166 params[0].DefaultType = REG_DWORD;
167 params[0].DefaultData = &zero;
168 params[0].DefaultLength = sizeof(ULONG);
169
173
174 VFDTRACE(VFDINFO,
175 ("[VFD] Drive letter '%wc' loaded from the registry\n",
176 letter ? letter : ' '));
177
178 DeviceExtension->DriveLetter = (CHAR)letter;
179
180 VFDTRACE(VFDINFO,
181 ("[VFD] VfdLoadLink - %s\n", GetStatusName(status)));
182
183 return status;
184}
LONG NTSTATUS
Definition: precomp.h:26
#define CHAR(Char)
#define NULL
Definition: types.h:112
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLenum const GLfloat * params
Definition: glext.h:5645
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define REG_DWORD
Definition: sdbapi.c:596
int zero
Definition: sehframes.cpp:29
Definition: ps.c:97
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define VFD_REG_DRIVE_LETTER
Definition: vfdio.h:30
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by VfdCreateDevice().

◆ VfdSetLink()

NTSTATUS VfdSetLink ( IN PDEVICE_EXTENSION  DeviceExtension,
IN CHAR  DriveLetter 
)

Definition at line 24 of file vfdlink.c.

27{
28 UNICODE_STRING unicode_name;
29 WCHAR name_buf[15];
31
32 VFDTRACE(VFDINFO, ("[VFD] VfdSetLink - IN\n"));
33
34 // convert lower case into upper case
35
36 if (DriveLetter >= 'a' && DriveLetter <= 'z') {
37 DriveLetter -= ('a' - 'A');
38 }
39
40 // check the drive letter range
41
42 if (DriveLetter != 0 &&
43 (DriveLetter < 'A' || DriveLetter > 'Z')) {
45 }
46
47 if (DeviceExtension->DriveLetter &&
48 DeviceExtension->DriveLetter != DriveLetter) {
49 //
50 // Delete the old drive letter
51 //
52#ifndef __REACTOS__
53 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
54#else
55 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
56#endif
57
58 _snwprintf(name_buf, sizeof(name_buf) - 1,
59 L"\\??\\%wc:", DeviceExtension->DriveLetter);
60
61 RtlInitUnicodeString(&unicode_name, name_buf);
62
63 status = IoDeleteSymbolicLink(&unicode_name);
64
65 if (NT_SUCCESS(status)) {
66 VFDTRACE(VFDINFO,
67 ("[VFD] Link %ws deleted\n", name_buf));
68
69 DeviceExtension->DriveLetter = 0;
70 }
72 // the driver letter did not exist in the first place
73
74 VFDTRACE(VFDINFO,
75 ("[VFD] Link %ws not found\n", name_buf));
76
77 DeviceExtension->DriveLetter = 0;
79 }
80 else {
81 VFDTRACE(VFDWARN,
82 ("[VFD] IoDeleteSymbolicLink %ws - %s\n",
83 name_buf, GetStatusName(status)));
84 }
85 }
86
87 if (NT_SUCCESS(status) && DriveLetter) {
88 //
89 // Create a new drive letter
90 //
91
92#ifndef __REACTOS__
93 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
94
95 _snwprintf(name_buf, sizeof(name_buf) - 1,
96 (OsMajorVersion >= 5) ?
97 L"\\??\\Global\\%wc:" : L"\\??\\%wc:",
98 DriveLetter);
99#else
100 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
101
102 _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
103 (OsMajorVersion >= 5) ?
104 L"\\??\\Global\\%wc:" : L"\\??\\%wc:",
105 DriveLetter);
106#endif
107
108 RtlInitUnicodeString(&unicode_name, name_buf);
109
111 &unicode_name, &(DeviceExtension->DeviceName));
112
113 if (NT_SUCCESS(status)) {
114 VFDTRACE(VFDINFO, ("[VFD] Link %ws created\n", name_buf));
115
116 DeviceExtension->DriveLetter = DriveLetter;
117 }
118 else {
119 VFDTRACE(VFDWARN,
120 ("[VFD] IoCreateSymbolicLink %ws - %s\n",
121 name_buf, GetStatusName(status)));
122 }
123 }
124
125 VFDTRACE(VFDINFO,
126 ("[VFD] VfdSetLink - %s\n", GetStatusName(status)));
127
128 return status;
129}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
ULONG OsMajorVersion

Referenced by VfdDeleteDevice(), VfdDeviceControl(), and VfdReinitialize().

◆ VfdStoreLink()

NTSTATUS VfdStoreLink ( IN PDEVICE_EXTENSION  DeviceExtension)

Definition at line 190 of file vfdlink.c.

192{
193 PVFD_DRIVER_EXTENSION driver_extension;
194 WCHAR name_buf[20];
195 ULONG letter;
197
198 VFDTRACE(VFDINFO, ("[VFD] VfdStoreLink - IN\n"));
199
200#ifdef VFD_PNP
201 driver_extension = IoGetDriverObjectExtension(
202 DeviceExtension->device_object->DriverObject,
203 VFD_DRIVER_EXTENSION_ID);
204#else // VFD_PNP
205 driver_extension = DeviceExtension->DriverExtension;
206#endif // VFD_PNP
207
208 if (!driver_extension ||
209 !driver_extension->RegistryPath.Buffer) {
210
211 VFDTRACE(VFDWARN, ("[VFD] Registry Path not present.\n"));
212 VFDTRACE(VFDINFO, ("[VFD] VfdStoreLinks - OUT\n"));
214 }
215
216#ifndef __REACTOS__
217 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
218
219 _snwprintf(name_buf, sizeof(name_buf) - 1,
221 DeviceExtension->DeviceNumber);
222#else
223 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
224
225 _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
227 DeviceExtension->DeviceNumber);
228#endif
229
230 letter = DeviceExtension->DriveLetter;
231
234 driver_extension->RegistryPath.Buffer,
235 name_buf,
236 REG_DWORD,
237 &letter,
238 sizeof(ULONG));
239
240 if (!NT_SUCCESS(status)) {
241 VFDTRACE(VFDWARN,
242 ("[VFD] RtlWriteRegistryValue - %s\n",
243 GetStatusName(status)));
244 }
245 else {
246 VFDTRACE(VFDINFO,
247 ("[VFD] Drive letter '%wc' stored into the registry\n",
248 letter ? letter : L' '));
249 }
250
251 VFDTRACE(VFDINFO,
252 ("[VFD] VfdStoreLink - %s\n", GetStatusName(status)));
253
254 return status;
255}
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
UNICODE_STRING RegistryPath
Definition: vfddrv.h:64
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177

Referenced by VfdDeviceControl().