mountmgr.sys: Use standard dlopen() instead of the libwine wrappers.
[wine.git] / dlls / mountmgr.sys / mountmgr.c
blob21712dc9cebfc21b449d7df8e143c1eaa348b07a
1 /*
2 * Mount manager service implementation
4 * Copyright 2008 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifdef __APPLE__
22 #include <CoreFoundation/CFString.h>
23 #define LoadResource mac_LoadResource
24 #define GetCurrentThread mac_GetCurrentThread
25 #include <CoreServices/CoreServices.h>
26 #undef LoadResource
27 #undef GetCurrentThread
28 #endif
30 #include <stdarg.h>
31 #include <unistd.h>
33 #define NONAMELESSUNION
35 #include "mountmgr.h"
36 #include "winreg.h"
37 #include "wine/list.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
43 #define MIN_ID_LEN 4
45 struct mount_point
47 struct list entry; /* entry in mount points list */
48 DEVICE_OBJECT *device; /* disk device */
49 UNICODE_STRING name; /* device name */
50 UNICODE_STRING link; /* DOS device symlink */
51 void *id; /* device unique id */
52 unsigned int id_len;
55 static struct list mount_points_list = LIST_INIT(mount_points_list);
56 static HKEY mount_key;
58 void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len )
60 RtlFreeHeap( GetProcessHeap(), 0, mount->id );
61 mount->id_len = max( MIN_ID_LEN, id_len );
62 if ((mount->id = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, mount->id_len )))
64 memcpy( mount->id, id, id_len );
65 RegSetValueExW( mount_key, mount->link.Buffer, 0, REG_BINARY, mount->id, mount->id_len );
67 else mount->id_len = 0;
70 static struct mount_point *add_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name,
71 const WCHAR *link )
73 struct mount_point *mount;
74 WCHAR *str;
75 UINT len = (strlenW(link) + 1) * sizeof(WCHAR) + device_name->Length + sizeof(WCHAR);
77 if (!(mount = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*mount) + len ))) return NULL;
79 str = (WCHAR *)(mount + 1);
80 strcpyW( str, link );
81 RtlInitUnicodeString( &mount->link, str );
82 str += strlenW(str) + 1;
83 memcpy( str, device_name->Buffer, device_name->Length );
84 str[device_name->Length / sizeof(WCHAR)] = 0;
85 mount->name.Buffer = str;
86 mount->name.Length = device_name->Length;
87 mount->name.MaximumLength = device_name->Length + sizeof(WCHAR);
88 mount->device = device;
89 mount->id = NULL;
90 list_add_tail( &mount_points_list, &mount->entry );
92 IoCreateSymbolicLink( &mount->link, device_name );
94 TRACE( "created %s id %s for %s\n", debugstr_w(mount->link.Buffer),
95 debugstr_a(mount->id), debugstr_w(mount->name.Buffer) );
96 return mount;
99 /* create the DosDevices mount point symlink for a new device */
100 struct mount_point *add_dosdev_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name, int drive )
102 static const WCHAR driveW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','%','c',':',0};
103 WCHAR link[sizeof(driveW)];
105 sprintfW( link, driveW, 'A' + drive );
106 return add_mount_point( device, device_name, link );
109 /* create the Volume mount point symlink for a new device */
110 struct mount_point *add_volume_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name,
111 const GUID *guid )
113 static const WCHAR volumeW[] = {'\\','?','?','\\','V','o','l','u','m','e','{',
114 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
115 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
116 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
117 WCHAR link[sizeof(volumeW)];
119 sprintfW( link, volumeW, guid->Data1, guid->Data2, guid->Data3,
120 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
121 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
122 return add_mount_point( device, device_name, link );
125 /* delete the mount point symlinks when a device goes away */
126 void delete_mount_point( struct mount_point *mount )
128 TRACE( "deleting %s\n", debugstr_w(mount->link.Buffer) );
129 list_remove( &mount->entry );
130 RegDeleteValueW( mount_key, mount->link.Buffer );
131 IoDeleteSymbolicLink( &mount->link );
132 RtlFreeHeap( GetProcessHeap(), 0, mount->id );
133 RtlFreeHeap( GetProcessHeap(), 0, mount );
136 /* check if a given mount point matches the requested specs */
137 static BOOL matching_mount_point( const struct mount_point *mount, const MOUNTMGR_MOUNT_POINT *spec )
139 if (spec->SymbolicLinkNameOffset)
141 const WCHAR *name = (const WCHAR *)((const char *)spec + spec->SymbolicLinkNameOffset);
142 if (spec->SymbolicLinkNameLength != mount->link.Length) return FALSE;
143 if (strncmpiW( name, mount->link.Buffer, mount->link.Length/sizeof(WCHAR)))
144 return FALSE;
146 if (spec->DeviceNameOffset)
148 const WCHAR *name = (const WCHAR *)((const char *)spec + spec->DeviceNameOffset);
149 if (spec->DeviceNameLength != mount->name.Length) return FALSE;
150 if (strncmpiW( name, mount->name.Buffer, mount->name.Length/sizeof(WCHAR)))
151 return FALSE;
153 if (spec->UniqueIdOffset)
155 const void *id = ((const char *)spec + spec->UniqueIdOffset);
156 if (spec->UniqueIdLength != mount->id_len) return FALSE;
157 if (memcmp( id, mount->id, mount->id_len )) return FALSE;
159 return TRUE;
162 /* implementation of IOCTL_MOUNTMGR_QUERY_POINTS */
163 static NTSTATUS query_mount_points( void *buff, SIZE_T insize,
164 SIZE_T outsize, IO_STATUS_BLOCK *iosb )
166 UINT count, pos, size;
167 MOUNTMGR_MOUNT_POINT *input = buff;
168 MOUNTMGR_MOUNT_POINTS *info;
169 struct mount_point *mount;
171 /* sanity checks */
172 if (input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength > insize ||
173 input->UniqueIdOffset + input->UniqueIdLength > insize ||
174 input->DeviceNameOffset + input->DeviceNameLength > insize ||
175 input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength < input->SymbolicLinkNameOffset ||
176 input->UniqueIdOffset + input->UniqueIdLength < input->UniqueIdOffset ||
177 input->DeviceNameOffset + input->DeviceNameLength < input->DeviceNameOffset)
178 return STATUS_INVALID_PARAMETER;
180 count = size = 0;
181 LIST_FOR_EACH_ENTRY( mount, &mount_points_list, struct mount_point, entry )
183 if (!matching_mount_point( mount, input )) continue;
184 size += mount->name.Length;
185 size += mount->link.Length;
186 size += mount->id_len;
187 size = (size + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
188 count++;
190 pos = FIELD_OFFSET( MOUNTMGR_MOUNT_POINTS, MountPoints[count] );
191 size += pos;
193 if (size > outsize)
195 info = buff;
196 if (size >= sizeof(info->Size)) info->Size = size;
197 iosb->Information = sizeof(info->Size);
198 return STATUS_MORE_ENTRIES;
201 input = HeapAlloc( GetProcessHeap(), 0, insize );
202 if (!input)
203 return STATUS_NO_MEMORY;
204 memcpy( input, buff, insize );
205 info = buff;
207 info->NumberOfMountPoints = count;
208 count = 0;
209 LIST_FOR_EACH_ENTRY( mount, &mount_points_list, struct mount_point, entry )
211 if (!matching_mount_point( mount, input )) continue;
213 info->MountPoints[count].DeviceNameOffset = pos;
214 info->MountPoints[count].DeviceNameLength = mount->name.Length;
215 memcpy( (char *)buff + pos, mount->name.Buffer, mount->name.Length );
216 pos += mount->name.Length;
218 info->MountPoints[count].SymbolicLinkNameOffset = pos;
219 info->MountPoints[count].SymbolicLinkNameLength = mount->link.Length;
220 memcpy( (char *)buff + pos, mount->link.Buffer, mount->link.Length );
221 pos += mount->link.Length;
223 info->MountPoints[count].UniqueIdOffset = pos;
224 info->MountPoints[count].UniqueIdLength = mount->id_len;
225 memcpy( (char *)buff + pos, mount->id, mount->id_len );
226 pos += mount->id_len;
227 pos = (pos + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
228 count++;
230 info->Size = pos;
231 iosb->Information = pos;
232 HeapFree( GetProcessHeap(), 0, input );
233 return STATUS_SUCCESS;
236 /* implementation of IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE */
237 static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
239 const struct mountmgr_unix_drive *input = in_buff;
240 const char *mount_point = NULL, *device = NULL;
241 unsigned int i;
242 WCHAR letter = tolowerW( input->letter );
244 if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
245 if (input->type > DRIVE_RAMDISK) return STATUS_INVALID_PARAMETER;
246 if (input->mount_point_offset > insize || input->device_offset > insize)
247 return STATUS_INVALID_PARAMETER;
249 /* make sure string are null-terminated */
250 if (input->mount_point_offset)
252 mount_point = (const char *)in_buff + input->mount_point_offset;
253 for (i = input->mount_point_offset; i < insize; i++)
254 if (!*((const char *)in_buff + i)) break;
255 if (i >= insize) return STATUS_INVALID_PARAMETER;
257 if (input->device_offset)
259 device = (const char *)in_buff + input->device_offset;
260 for (i = input->device_offset; i < insize; i++)
261 if (!*((const char *)in_buff + i)) break;
262 if (i >= insize) return STATUS_INVALID_PARAMETER;
265 if (input->type != DRIVE_NO_ROOT_DIR)
267 enum device_type type = DEVICE_UNKNOWN;
269 TRACE( "defining %c: dev %s mount %s type %u\n",
270 letter, debugstr_a(device), debugstr_a(mount_point), input->type );
271 switch (input->type)
273 case DRIVE_REMOVABLE: type = (letter >= 'c') ? DEVICE_HARDDISK : DEVICE_FLOPPY; break;
274 case DRIVE_REMOTE: type = DEVICE_NETWORK; break;
275 case DRIVE_CDROM: type = DEVICE_CDROM; break;
276 case DRIVE_RAMDISK: type = DEVICE_RAMDISK; break;
277 case DRIVE_FIXED: type = DEVICE_HARDDISK_VOL; break;
279 return add_dos_device( letter - 'a', NULL, device, mount_point, type, NULL, NULL );
281 else
283 TRACE( "removing %c:\n", letter );
284 return remove_dos_device( letter - 'a', NULL );
288 /* implementation of IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE */
289 static NTSTATUS query_unix_drive( void *buff, SIZE_T insize,
290 SIZE_T outsize, IO_STATUS_BLOCK *iosb )
292 const struct mountmgr_unix_drive *input = buff;
293 struct mountmgr_unix_drive *output = NULL;
294 char *device, *mount_point;
295 int letter = tolowerW( input->letter );
296 NTSTATUS status;
297 DWORD size, type = DEVICE_UNKNOWN;
298 enum device_type device_type;
299 char *ptr;
301 if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
303 if ((status = query_dos_device( letter - 'a', &device_type, &device, &mount_point ))) return status;
304 switch (device_type)
306 case DEVICE_UNKNOWN: type = DRIVE_UNKNOWN; break;
307 case DEVICE_HARDDISK: type = DRIVE_REMOVABLE; break;
308 case DEVICE_HARDDISK_VOL: type = DRIVE_FIXED; break;
309 case DEVICE_FLOPPY: type = DRIVE_REMOVABLE; break;
310 case DEVICE_CDROM: type = DRIVE_CDROM; break;
311 case DEVICE_DVD: type = DRIVE_CDROM; break;
312 case DEVICE_NETWORK: type = DRIVE_REMOTE; break;
313 case DEVICE_RAMDISK: type = DRIVE_RAMDISK; break;
316 size = sizeof(*output);
317 if (device) size += strlen(device) + 1;
318 if (mount_point) size += strlen(mount_point) + 1;
320 input = NULL;
321 output = buff;
322 output->size = size;
323 output->letter = letter;
324 output->type = type;
325 output->mount_point_offset = 0;
326 output->device_offset = 0;
328 if (size > outsize)
330 iosb->Information = 0;
331 if (size >= FIELD_OFFSET( struct mountmgr_unix_drive, size ) + sizeof(output->size))
333 output->size = size;
334 iosb->Information = FIELD_OFFSET( struct mountmgr_unix_drive, size ) + sizeof(output->size);
336 if (size >= FIELD_OFFSET( struct mountmgr_unix_drive, type ) + sizeof(output->type))
338 output->type = type;
339 iosb->Information = FIELD_OFFSET( struct mountmgr_unix_drive, type ) + sizeof(output->type);
341 status = STATUS_BUFFER_OVERFLOW;
342 goto done;
345 ptr = (char *)(output + 1);
347 if (mount_point)
349 output->mount_point_offset = ptr - (char *)output;
350 strcpy( ptr, mount_point );
351 ptr += strlen(ptr) + 1;
353 else output->mount_point_offset = 0;
355 if (device)
357 output->device_offset = ptr - (char *)output;
358 strcpy( ptr, device );
359 ptr += strlen(ptr) + 1;
361 else output->device_offset = 0;
363 TRACE( "returning %c: dev %s mount %s type %u\n",
364 letter, debugstr_a(device), debugstr_a(mount_point), type );
366 iosb->Information = ptr - (char *)output;
367 done:
368 RtlFreeHeap( GetProcessHeap(), 0, device );
369 RtlFreeHeap( GetProcessHeap(), 0, mount_point );
370 return status;
373 /* implementation of IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS */
374 static NTSTATUS query_dhcp_request_params( void *buff, SIZE_T insize,
375 SIZE_T outsize, IO_STATUS_BLOCK *iosb )
377 struct mountmgr_dhcp_request_params *query = buff;
378 ULONG i, offset;
380 /* sanity checks */
381 if (FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]) > insize ||
382 !memchrW( query->adapter, 0, ARRAY_SIZE(query->adapter) )) return STATUS_INVALID_PARAMETER;
383 for (i = 0; i < query->count; i++)
384 if (query->params[i].offset + query->params[i].size > insize) return STATUS_INVALID_PARAMETER;
386 offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]);
387 for (i = 0; i < query->count; i++)
389 offset += get_dhcp_request_param( query->adapter, &query->params[i], buff, offset, outsize - offset );
390 if (offset > outsize)
392 if (offset >= sizeof(query->size)) query->size = offset;
393 iosb->Information = sizeof(query->size);
394 return STATUS_MORE_ENTRIES;
398 iosb->Information = offset;
399 return STATUS_SUCCESS;
402 /* implementation of Wine extension to use host APIs to find symbol file by GUID */
403 #ifdef __APPLE__
404 static void WINAPI query_symbol_file( TP_CALLBACK_INSTANCE *instance, void *context )
406 IRP *irp = context;
407 MOUNTMGR_TARGET_NAME *result;
408 CFStringRef query_cfstring;
409 WCHAR *unix_buf = NULL;
410 ANSI_STRING unix_path;
411 UNICODE_STRING path;
412 MDQueryRef mdquery;
413 const GUID *id;
414 size_t size;
415 NTSTATUS status = STATUS_NO_MEMORY;
417 static const WCHAR formatW[] = { 'c','o','m','_','a','p','p','l','e','_','x','c','o','d','e',
418 '_','d','s','y','m','_','u','u','i','d','s',' ','=','=',' ',
419 '"','%','0','8','X','-','%','0','4','X','-',
420 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
421 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
422 '%','0','2','X','%','0','2','X','"',0 };
423 WCHAR query_string[ARRAY_SIZE(formatW)];
425 id = irp->AssociatedIrp.SystemBuffer;
426 sprintfW( query_string, formatW, id->Data1, id->Data2, id->Data3,
427 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
428 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
429 if (!(query_cfstring = CFStringCreateWithCharacters(NULL, query_string, lstrlenW(query_string)))) goto done;
431 mdquery = MDQueryCreate(NULL, query_cfstring, NULL, NULL);
432 CFRelease(query_cfstring);
433 if (!mdquery) goto done;
435 MDQuerySetMaxCount(mdquery, 1);
436 TRACE("Executing %s\n", debugstr_w(query_string));
437 if (MDQueryExecute(mdquery, kMDQuerySynchronous))
439 if (MDQueryGetResultCount(mdquery) >= 1)
441 MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(mdquery, 0);
442 CFStringRef item_path = MDItemCopyAttribute(item, kMDItemPath);
444 if (item_path)
446 CFIndex item_path_len = CFStringGetLength(item_path);
447 if ((unix_buf = HeapAlloc(GetProcessHeap(), 0, (item_path_len + 1) * sizeof(WCHAR))))
449 CFStringGetCharacters(item_path, CFRangeMake(0, item_path_len), unix_buf);
450 unix_buf[item_path_len] = 0;
451 TRACE("found %s\n", debugstr_w(unix_buf));
453 CFRelease(item_path);
456 else status = STATUS_NO_MORE_ENTRIES;
458 CFRelease(mdquery);
459 if (!unix_buf) goto done;
461 RtlInitUnicodeString( &path, unix_buf );
462 status = RtlUnicodeStringToAnsiString( &unix_path, &path, TRUE );
463 HeapFree( GetProcessHeap(), 0, unix_buf );
464 if (status) goto done;
466 status = wine_unix_to_nt_file_name( &unix_path, &path );
467 RtlFreeAnsiString( &unix_path );
468 if (status) goto done;
470 result = irp->AssociatedIrp.SystemBuffer;
471 result->DeviceNameLength = path.Length;
472 size = FIELD_OFFSET(MOUNTMGR_TARGET_NAME, DeviceName[path.Length / sizeof(WCHAR)]);
473 if (size <= IoGetCurrentIrpStackLocation(irp)->Parameters.DeviceIoControl.OutputBufferLength)
475 memcpy( result->DeviceName, path.Buffer, path.Length );
476 irp->IoStatus.Information = size;
477 status = STATUS_SUCCESS;
479 else
481 irp->IoStatus.Information = sizeof(*result);
482 status = STATUS_BUFFER_OVERFLOW;
484 RtlFreeUnicodeString( &path );
486 done:
487 irp->IoStatus.u.Status = status;
488 IoCompleteRequest( irp, IO_NO_INCREMENT );
490 #endif /* __APPLE__ */
492 /* handler for ioctls on the mount manager device */
493 static NTSTATUS WINAPI mountmgr_ioctl( DEVICE_OBJECT *device, IRP *irp )
495 IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
497 TRACE( "ioctl %x insize %u outsize %u\n",
498 irpsp->Parameters.DeviceIoControl.IoControlCode,
499 irpsp->Parameters.DeviceIoControl.InputBufferLength,
500 irpsp->Parameters.DeviceIoControl.OutputBufferLength );
502 switch(irpsp->Parameters.DeviceIoControl.IoControlCode)
504 case IOCTL_MOUNTMGR_QUERY_POINTS:
505 if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(MOUNTMGR_MOUNT_POINT))
507 irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
508 break;
510 irp->IoStatus.u.Status = query_mount_points( irp->AssociatedIrp.SystemBuffer,
511 irpsp->Parameters.DeviceIoControl.InputBufferLength,
512 irpsp->Parameters.DeviceIoControl.OutputBufferLength,
513 &irp->IoStatus );
514 break;
515 case IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE:
516 if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
518 irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
519 break;
521 irp->IoStatus.Information = 0;
522 irp->IoStatus.u.Status = define_unix_drive( irp->AssociatedIrp.SystemBuffer,
523 irpsp->Parameters.DeviceIoControl.InputBufferLength );
524 break;
525 case IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE:
526 if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
528 irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
529 break;
531 irp->IoStatus.u.Status = query_unix_drive( irp->AssociatedIrp.SystemBuffer,
532 irpsp->Parameters.DeviceIoControl.InputBufferLength,
533 irpsp->Parameters.DeviceIoControl.OutputBufferLength,
534 &irp->IoStatus );
535 break;
536 case IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS:
537 if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_dhcp_request_params))
539 irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
540 break;
542 irp->IoStatus.u.Status = query_dhcp_request_params( irp->AssociatedIrp.SystemBuffer,
543 irpsp->Parameters.DeviceIoControl.InputBufferLength,
544 irpsp->Parameters.DeviceIoControl.OutputBufferLength,
545 &irp->IoStatus );
546 break;
547 #ifdef __APPLE__
548 case IOCTL_MOUNTMGR_QUERY_SYMBOL_FILE:
549 if (irpsp->Parameters.DeviceIoControl.InputBufferLength != sizeof(GUID)
550 || irpsp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUNTMGR_TARGET_NAME))
552 irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
553 break;
555 if (TrySubmitThreadpoolCallback( query_symbol_file, irp, NULL )) return STATUS_PENDING;
556 irp->IoStatus.u.Status = STATUS_NO_MEMORY;
557 break;
558 #endif
559 default:
560 FIXME( "ioctl %x not supported\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
561 irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
562 break;
564 IoCompleteRequest( irp, IO_NO_INCREMENT );
565 return STATUS_SUCCESS;
568 /* main entry point for the mount point manager driver */
569 NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
571 static const WCHAR mounted_devicesW[] = {'S','y','s','t','e','m','\\','M','o','u','n','t','e','d','D','e','v','i','c','e','s',0};
572 static const WCHAR device_mountmgrW[] = {'\\','D','e','v','i','c','e','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
573 static const WCHAR link_mountmgrW[] = {'\\','?','?','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
574 static const WCHAR harddiskW[] = {'\\','D','r','i','v','e','r','\\','H','a','r','d','d','i','s','k',0};
575 static const WCHAR driver_serialW[] = {'\\','D','r','i','v','e','r','\\','S','e','r','i','a','l',0};
576 static const WCHAR driver_parallelW[] = {'\\','D','r','i','v','e','r','\\','P','a','r','a','l','l','e','l',0};
577 static const WCHAR devicemapW[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
579 #ifdef _WIN64
580 static const WCHAR qualified_ports_keyW[] = {'\\','R','E','G','I','S','T','R','Y','\\',
581 'M','A','C','H','I','N','E','\\','S','o','f','t','w','a','r','e','\\',
582 'W','i','n','e','\\','P','o','r','t','s'}; /* no null terminator */
583 static const WCHAR wow64_ports_keyW[] = {'S','o','f','t','w','a','r','e','\\',
584 'W','o','w','6','4','3','2','N','o','d','e','\\','W','i','n','e','\\',
585 'P','o','r','t','s',0};
586 static const WCHAR symbolic_link_valueW[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e',0};
587 HKEY wow64_ports_key = NULL;
588 #endif
590 UNICODE_STRING nameW, linkW;
591 DEVICE_OBJECT *device;
592 HKEY devicemap_key;
593 NTSTATUS status;
595 TRACE( "%s\n", debugstr_w(path->Buffer) );
597 driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = mountmgr_ioctl;
599 RtlInitUnicodeString( &nameW, device_mountmgrW );
600 RtlInitUnicodeString( &linkW, link_mountmgrW );
601 if (!(status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device )))
602 status = IoCreateSymbolicLink( &linkW, &nameW );
603 if (status)
605 FIXME( "failed to create device error %x\n", status );
606 return status;
609 RegCreateKeyExW( HKEY_LOCAL_MACHINE, mounted_devicesW, 0, NULL,
610 REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &mount_key, NULL );
612 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE, devicemapW, 0, NULL, REG_OPTION_VOLATILE,
613 KEY_ALL_ACCESS, NULL, &devicemap_key, NULL ))
614 RegCloseKey( devicemap_key );
616 RtlInitUnicodeString( &nameW, harddiskW );
617 status = IoCreateDriver( &nameW, harddisk_driver_entry );
619 initialize_dbus();
620 initialize_diskarbitration();
622 #ifdef _WIN64
623 /* create a symlink so that the Wine port overrides key can be edited with 32-bit reg or regedit */
624 RegCreateKeyExW( HKEY_LOCAL_MACHINE, wow64_ports_keyW, 0, NULL, REG_OPTION_CREATE_LINK,
625 KEY_SET_VALUE, NULL, &wow64_ports_key, NULL );
626 RegSetValueExW( wow64_ports_key, symbolic_link_valueW, 0, REG_LINK,
627 (BYTE *)qualified_ports_keyW, sizeof(qualified_ports_keyW) );
628 RegCloseKey( wow64_ports_key );
629 #endif
631 RtlInitUnicodeString( &nameW, driver_serialW );
632 IoCreateDriver( &nameW, serial_driver_entry );
634 RtlInitUnicodeString( &nameW, driver_parallelW );
635 IoCreateDriver( &nameW, parallel_driver_entry );
637 return status;