ReactOS  0.4.14-dev-293-g2b39b42
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,
153  VFD_REG_DRIVE_LETTER L"%lu",
154  DeviceExtension->DeviceNumber);
155 #else
156  name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
157 
158  _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
159  VFD_REG_DRIVE_LETTER L"%lu",
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 
172  RegistryPath, &params[0], NULL, NULL);
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 }
#define VFD_REG_DRIVE_LETTER
Definition: vfdio.h:30
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define UNICODE_NULL
GLenum const GLfloat * params
Definition: glext.h:5645
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
static double zero
Definition: j0_y0.c:96
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define REG_DWORD
Definition: sdbapi.c:596
#define CHAR(Char)
static SERVICE_STATUS status
Definition: service.c:31
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
Definition: ps.c:97

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 }
ULONG OsMajorVersion
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define UNICODE_NULL
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

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,
220  VFD_REG_DRIVE_LETTER L"%lu",
221  DeviceExtension->DeviceNumber);
222 #else
223  name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
224 
225  _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
226  VFD_REG_DRIVE_LETTER L"%lu",
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 }
#define VFD_REG_DRIVE_LETTER
Definition: vfdio.h:30
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define UNICODE_NULL
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
static const WCHAR L[]
Definition: oid.c:1250
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
UNICODE_STRING RegistryPath
Definition: vfddrv.h:64
unsigned int ULONG
Definition: retypes.h:1
#define REG_DWORD
Definition: sdbapi.c:596
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by VfdDeviceControl().