2008-01-04 13:07:05 +01:00
|
|
|
/*
|
|
|
|
* Mount manager service implementation
|
|
|
|
*
|
|
|
|
* Copyright 2008 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2008-10-21 15:01:52 +02:00
|
|
|
#include "mountmgr.h"
|
2008-01-04 14:27:53 +01:00
|
|
|
#include "winreg.h"
|
2008-01-04 13:07:05 +01:00
|
|
|
#include "wine/library.h"
|
2008-10-17 20:09:31 +02:00
|
|
|
#include "wine/list.h"
|
2008-10-21 15:01:52 +02:00
|
|
|
#include "wine/unicode.h"
|
2008-01-04 13:07:05 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
|
|
|
|
|
2008-10-17 19:57:43 +02:00
|
|
|
#define MIN_ID_LEN 4
|
2008-01-04 14:24:59 +01:00
|
|
|
|
|
|
|
struct mount_point
|
|
|
|
{
|
2008-10-17 20:09:31 +02:00
|
|
|
struct list entry; /* entry in mount points list */
|
|
|
|
DEVICE_OBJECT *device; /* disk device */
|
2008-10-17 20:01:23 +02:00
|
|
|
UNICODE_STRING name; /* device name */
|
2008-01-04 14:24:59 +01:00
|
|
|
UNICODE_STRING link; /* DOS device symlink */
|
|
|
|
void *id; /* device unique id */
|
|
|
|
unsigned int id_len;
|
|
|
|
};
|
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
static struct list mount_points_list = LIST_INIT(mount_points_list);
|
2008-01-04 14:27:53 +01:00
|
|
|
static HKEY mount_key;
|
2008-01-04 14:24:59 +01:00
|
|
|
|
2008-10-21 15:02:10 +02:00
|
|
|
void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len )
|
2008-10-17 19:57:43 +02:00
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount->id );
|
|
|
|
mount->id_len = max( MIN_ID_LEN, id_len );
|
|
|
|
if ((mount->id = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, mount->id_len )))
|
|
|
|
{
|
|
|
|
memcpy( mount->id, id, id_len );
|
|
|
|
RegSetValueExW( mount_key, mount->link.Buffer, 0, REG_BINARY, mount->id, mount->id_len );
|
|
|
|
}
|
|
|
|
else mount->id_len = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
static struct mount_point *add_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name,
|
2009-07-20 21:00:33 +02:00
|
|
|
const WCHAR *link )
|
2008-10-17 20:09:31 +02:00
|
|
|
{
|
|
|
|
struct mount_point *mount;
|
|
|
|
WCHAR *str;
|
2008-10-17 20:01:23 +02:00
|
|
|
UINT len = (strlenW(link) + 1) * sizeof(WCHAR) + device_name->Length + sizeof(WCHAR);
|
2008-10-17 20:09:31 +02:00
|
|
|
|
|
|
|
if (!(mount = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*mount) + len ))) return NULL;
|
|
|
|
|
|
|
|
str = (WCHAR *)(mount + 1);
|
|
|
|
strcpyW( str, link );
|
|
|
|
RtlInitUnicodeString( &mount->link, str );
|
2008-10-17 20:01:23 +02:00
|
|
|
str += strlenW(str) + 1;
|
|
|
|
memcpy( str, device_name->Buffer, device_name->Length );
|
|
|
|
str[device_name->Length / sizeof(WCHAR)] = 0;
|
|
|
|
mount->name.Buffer = str;
|
|
|
|
mount->name.Length = device_name->Length;
|
|
|
|
mount->name.MaximumLength = device_name->Length + sizeof(WCHAR);
|
2008-10-17 20:09:31 +02:00
|
|
|
mount->device = device;
|
|
|
|
mount->id = NULL;
|
|
|
|
list_add_tail( &mount_points_list, &mount->entry );
|
|
|
|
|
|
|
|
IoCreateSymbolicLink( &mount->link, device_name );
|
|
|
|
|
|
|
|
TRACE( "created %s id %s for %s\n", debugstr_w(mount->link.Buffer),
|
2008-10-17 20:01:23 +02:00
|
|
|
debugstr_a(mount->id), debugstr_w(mount->name.Buffer) );
|
2008-10-17 20:09:31 +02:00
|
|
|
return mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the DosDevices mount point symlink for a new device */
|
2009-07-20 21:00:33 +02:00
|
|
|
struct mount_point *add_dosdev_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name, int drive )
|
2008-01-04 14:24:59 +01:00
|
|
|
{
|
|
|
|
static const WCHAR driveW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','%','c',':',0};
|
2008-10-17 20:09:31 +02:00
|
|
|
WCHAR link[sizeof(driveW)];
|
|
|
|
|
|
|
|
sprintfW( link, driveW, 'A' + drive );
|
2009-07-20 21:00:33 +02:00
|
|
|
return add_mount_point( device, device_name, link );
|
2008-10-17 20:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create the Volume mount point symlink for a new device */
|
2008-10-21 15:02:10 +02:00
|
|
|
struct mount_point *add_volume_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name,
|
2009-07-20 21:00:33 +02:00
|
|
|
const GUID *guid )
|
2008-10-17 20:09:31 +02:00
|
|
|
{
|
2008-01-04 14:24:59 +01:00
|
|
|
static const WCHAR volumeW[] = {'\\','?','?','\\','V','o','l','u','m','e','{',
|
|
|
|
'%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
|
|
|
|
'%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
|
|
|
|
'%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
|
2008-10-17 20:09:31 +02:00
|
|
|
WCHAR link[sizeof(volumeW)];
|
2008-01-04 14:24:59 +01:00
|
|
|
|
2009-07-20 16:05:04 +02:00
|
|
|
sprintfW( link, volumeW, guid->Data1, guid->Data2, guid->Data3,
|
|
|
|
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
|
|
|
|
guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
|
2009-07-20 21:00:33 +02:00
|
|
|
return add_mount_point( device, device_name, link );
|
2008-01-04 14:24:59 +01:00
|
|
|
}
|
|
|
|
|
2008-10-21 15:20:09 +02:00
|
|
|
/* delete the mount point symlinks when a device goes away */
|
|
|
|
void delete_mount_point( struct mount_point *mount )
|
|
|
|
{
|
|
|
|
TRACE( "deleting %s\n", debugstr_w(mount->link.Buffer) );
|
|
|
|
list_remove( &mount->entry );
|
|
|
|
RegDeleteValueW( mount_key, mount->link.Buffer );
|
|
|
|
IoDeleteSymbolicLink( &mount->link );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount->id );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount );
|
|
|
|
}
|
|
|
|
|
2008-01-04 14:28:47 +01:00
|
|
|
/* check if a given mount point matches the requested specs */
|
|
|
|
static BOOL matching_mount_point( const struct mount_point *mount, const MOUNTMGR_MOUNT_POINT *spec )
|
|
|
|
{
|
|
|
|
if (spec->SymbolicLinkNameOffset)
|
|
|
|
{
|
|
|
|
const WCHAR *name = (const WCHAR *)((const char *)spec + spec->SymbolicLinkNameOffset);
|
|
|
|
if (spec->SymbolicLinkNameLength != mount->link.Length) return FALSE;
|
2019-05-07 18:31:21 +02:00
|
|
|
if (strncmpiW( name, mount->link.Buffer, mount->link.Length/sizeof(WCHAR)))
|
2008-01-04 14:28:47 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (spec->DeviceNameOffset)
|
|
|
|
{
|
|
|
|
const WCHAR *name = (const WCHAR *)((const char *)spec + spec->DeviceNameOffset);
|
2008-10-17 20:01:23 +02:00
|
|
|
if (spec->DeviceNameLength != mount->name.Length) return FALSE;
|
2019-05-07 18:31:21 +02:00
|
|
|
if (strncmpiW( name, mount->name.Buffer, mount->name.Length/sizeof(WCHAR)))
|
2008-01-04 14:28:47 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (spec->UniqueIdOffset)
|
|
|
|
{
|
|
|
|
const void *id = ((const char *)spec + spec->UniqueIdOffset);
|
|
|
|
if (spec->UniqueIdLength != mount->id_len) return FALSE;
|
|
|
|
if (memcmp( id, mount->id, mount->id_len )) return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* implementation of IOCTL_MOUNTMGR_QUERY_POINTS */
|
2011-11-01 13:03:12 +01:00
|
|
|
static NTSTATUS query_mount_points( void *buff, SIZE_T insize,
|
|
|
|
SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
2008-01-04 14:28:47 +01:00
|
|
|
{
|
2008-10-17 20:09:31 +02:00
|
|
|
UINT count, pos, size;
|
2011-11-01 13:03:12 +01:00
|
|
|
MOUNTMGR_MOUNT_POINT *input = buff;
|
|
|
|
MOUNTMGR_MOUNT_POINTS *info;
|
2008-10-17 20:09:31 +02:00
|
|
|
struct mount_point *mount;
|
2008-01-04 14:28:47 +01:00
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength > insize ||
|
|
|
|
input->UniqueIdOffset + input->UniqueIdLength > insize ||
|
|
|
|
input->DeviceNameOffset + input->DeviceNameLength > insize ||
|
|
|
|
input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength < input->SymbolicLinkNameOffset ||
|
|
|
|
input->UniqueIdOffset + input->UniqueIdLength < input->UniqueIdOffset ||
|
|
|
|
input->DeviceNameOffset + input->DeviceNameLength < input->DeviceNameOffset)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
count = size = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( mount, &mount_points_list, struct mount_point, entry )
|
2008-01-04 14:28:47 +01:00
|
|
|
{
|
2008-10-17 20:09:31 +02:00
|
|
|
if (!matching_mount_point( mount, input )) continue;
|
2008-10-17 20:01:23 +02:00
|
|
|
size += mount->name.Length;
|
2008-10-17 20:09:31 +02:00
|
|
|
size += mount->link.Length;
|
|
|
|
size += mount->id_len;
|
2008-10-15 20:12:49 +02:00
|
|
|
size = (size + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
2008-10-17 20:09:31 +02:00
|
|
|
count++;
|
2008-01-04 14:28:47 +01:00
|
|
|
}
|
2008-10-17 20:09:31 +02:00
|
|
|
pos = FIELD_OFFSET( MOUNTMGR_MOUNT_POINTS, MountPoints[count] );
|
2008-01-04 14:28:47 +01:00
|
|
|
size += pos;
|
|
|
|
|
|
|
|
if (size > outsize)
|
|
|
|
{
|
2011-11-01 13:03:12 +01:00
|
|
|
info = buff;
|
2008-01-04 14:28:47 +01:00
|
|
|
if (size >= sizeof(info->Size)) info->Size = size;
|
|
|
|
iosb->Information = sizeof(info->Size);
|
|
|
|
return STATUS_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
2011-11-01 13:03:12 +01:00
|
|
|
input = HeapAlloc( GetProcessHeap(), 0, insize );
|
|
|
|
if (!input)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
memcpy( input, buff, insize );
|
|
|
|
info = buff;
|
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
info->NumberOfMountPoints = count;
|
|
|
|
count = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( mount, &mount_points_list, struct mount_point, entry )
|
2008-01-04 14:28:47 +01:00
|
|
|
{
|
2008-10-17 20:09:31 +02:00
|
|
|
if (!matching_mount_point( mount, input )) continue;
|
2008-01-04 14:28:47 +01:00
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
info->MountPoints[count].DeviceNameOffset = pos;
|
2008-10-17 20:01:23 +02:00
|
|
|
info->MountPoints[count].DeviceNameLength = mount->name.Length;
|
2011-11-01 13:03:12 +01:00
|
|
|
memcpy( (char *)buff + pos, mount->name.Buffer, mount->name.Length );
|
2008-10-17 20:01:23 +02:00
|
|
|
pos += mount->name.Length;
|
2008-01-04 14:28:47 +01:00
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
info->MountPoints[count].SymbolicLinkNameOffset = pos;
|
|
|
|
info->MountPoints[count].SymbolicLinkNameLength = mount->link.Length;
|
2011-11-01 13:03:12 +01:00
|
|
|
memcpy( (char *)buff + pos, mount->link.Buffer, mount->link.Length );
|
2008-10-17 20:09:31 +02:00
|
|
|
pos += mount->link.Length;
|
2008-10-15 20:12:49 +02:00
|
|
|
|
2008-10-17 20:09:31 +02:00
|
|
|
info->MountPoints[count].UniqueIdOffset = pos;
|
|
|
|
info->MountPoints[count].UniqueIdLength = mount->id_len;
|
2011-11-01 13:03:12 +01:00
|
|
|
memcpy( (char *)buff + pos, mount->id, mount->id_len );
|
2008-10-17 20:09:31 +02:00
|
|
|
pos += mount->id_len;
|
2008-10-15 20:12:49 +02:00
|
|
|
pos = (pos + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
2008-10-17 20:09:31 +02:00
|
|
|
count++;
|
2008-01-04 14:28:47 +01:00
|
|
|
}
|
|
|
|
info->Size = pos;
|
|
|
|
iosb->Information = pos;
|
2011-11-01 13:03:12 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, input );
|
2008-01-04 14:28:47 +01:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-10-23 15:48:08 +02:00
|
|
|
/* implementation of IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE */
|
|
|
|
static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
|
|
|
|
{
|
|
|
|
const struct mountmgr_unix_drive *input = in_buff;
|
|
|
|
const char *mount_point = NULL, *device = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
WCHAR letter = tolowerW( input->letter );
|
|
|
|
|
|
|
|
if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
|
|
|
|
if (input->type > DRIVE_RAMDISK) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (input->mount_point_offset > insize || input->device_offset > insize)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* make sure string are null-terminated */
|
|
|
|
if (input->mount_point_offset)
|
|
|
|
{
|
|
|
|
mount_point = (const char *)in_buff + input->mount_point_offset;
|
|
|
|
for (i = input->mount_point_offset; i < insize; i++)
|
|
|
|
if (!*((const char *)in_buff + i)) break;
|
|
|
|
if (i >= insize) return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
if (input->device_offset)
|
|
|
|
{
|
|
|
|
device = (const char *)in_buff + input->device_offset;
|
|
|
|
for (i = input->device_offset; i < insize; i++)
|
|
|
|
if (!*((const char *)in_buff + i)) break;
|
|
|
|
if (i >= insize) return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->type != DRIVE_NO_ROOT_DIR)
|
|
|
|
{
|
2008-11-12 10:47:49 +01:00
|
|
|
enum device_type type = DEVICE_UNKNOWN;
|
|
|
|
|
2008-10-23 15:48:08 +02:00
|
|
|
TRACE( "defining %c: dev %s mount %s type %u\n",
|
|
|
|
letter, debugstr_a(device), debugstr_a(mount_point), input->type );
|
2008-11-12 10:47:49 +01:00
|
|
|
switch (input->type)
|
|
|
|
{
|
|
|
|
case DRIVE_REMOVABLE: type = (letter >= 'c') ? DEVICE_HARDDISK : DEVICE_FLOPPY; break;
|
|
|
|
case DRIVE_REMOTE: type = DEVICE_NETWORK; break;
|
|
|
|
case DRIVE_CDROM: type = DEVICE_CDROM; break;
|
|
|
|
case DRIVE_RAMDISK: type = DEVICE_RAMDISK; break;
|
2009-06-04 10:14:56 +02:00
|
|
|
case DRIVE_FIXED: type = DEVICE_HARDDISK_VOL; break;
|
2008-11-12 10:47:49 +01:00
|
|
|
}
|
2019-11-25 18:40:34 +01:00
|
|
|
return add_dos_device( letter - 'a', NULL, device, mount_point, type, NULL, NULL );
|
2008-10-23 15:48:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "removing %c:\n", letter );
|
|
|
|
return remove_dos_device( letter - 'a', NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-23 15:52:39 +02:00
|
|
|
/* implementation of IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE */
|
2011-11-01 13:03:12 +01:00
|
|
|
static NTSTATUS query_unix_drive( void *buff, SIZE_T insize,
|
|
|
|
SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
2008-10-23 15:52:39 +02:00
|
|
|
{
|
2011-11-01 13:03:12 +01:00
|
|
|
const struct mountmgr_unix_drive *input = buff;
|
|
|
|
struct mountmgr_unix_drive *output = NULL;
|
2009-07-22 21:02:47 +02:00
|
|
|
char *device, *mount_point;
|
2008-10-23 15:52:39 +02:00
|
|
|
int letter = tolowerW( input->letter );
|
|
|
|
NTSTATUS status;
|
2008-12-04 14:32:21 +01:00
|
|
|
DWORD size, type = DEVICE_UNKNOWN;
|
2008-11-12 10:47:49 +01:00
|
|
|
enum device_type device_type;
|
2008-10-23 15:52:39 +02:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2008-11-12 10:47:49 +01:00
|
|
|
if ((status = query_dos_device( letter - 'a', &device_type, &device, &mount_point ))) return status;
|
|
|
|
switch (device_type)
|
|
|
|
{
|
|
|
|
case DEVICE_UNKNOWN: type = DRIVE_UNKNOWN; break;
|
|
|
|
case DEVICE_HARDDISK: type = DRIVE_REMOVABLE; break;
|
|
|
|
case DEVICE_HARDDISK_VOL: type = DRIVE_FIXED; break;
|
|
|
|
case DEVICE_FLOPPY: type = DRIVE_REMOVABLE; break;
|
|
|
|
case DEVICE_CDROM: type = DRIVE_CDROM; break;
|
2011-02-08 23:12:54 +01:00
|
|
|
case DEVICE_DVD: type = DRIVE_CDROM; break;
|
2008-11-12 10:47:49 +01:00
|
|
|
case DEVICE_NETWORK: type = DRIVE_REMOTE; break;
|
|
|
|
case DEVICE_RAMDISK: type = DRIVE_RAMDISK; break;
|
|
|
|
}
|
2008-10-23 15:52:39 +02:00
|
|
|
|
|
|
|
size = sizeof(*output);
|
|
|
|
if (device) size += strlen(device) + 1;
|
|
|
|
if (mount_point) size += strlen(mount_point) + 1;
|
|
|
|
|
2011-11-01 13:03:12 +01:00
|
|
|
input = NULL;
|
|
|
|
output = buff;
|
|
|
|
|
2008-10-23 15:52:39 +02:00
|
|
|
if (size > outsize)
|
|
|
|
{
|
2008-11-10 16:11:05 +01:00
|
|
|
iosb->Information = 0;
|
2008-10-23 15:52:39 +02:00
|
|
|
if (size >= FIELD_OFFSET( struct mountmgr_unix_drive, size ) + sizeof(output->size))
|
2008-11-10 16:11:05 +01:00
|
|
|
{
|
2008-10-23 15:52:39 +02:00
|
|
|
output->size = size;
|
2008-11-10 16:11:05 +01:00
|
|
|
iosb->Information = FIELD_OFFSET( struct mountmgr_unix_drive, size ) + sizeof(output->size);
|
|
|
|
}
|
|
|
|
if (size >= FIELD_OFFSET( struct mountmgr_unix_drive, type ) + sizeof(output->type))
|
|
|
|
{
|
|
|
|
output->type = type;
|
|
|
|
iosb->Information = FIELD_OFFSET( struct mountmgr_unix_drive, type ) + sizeof(output->type);
|
|
|
|
}
|
2009-07-22 21:02:47 +02:00
|
|
|
status = STATUS_MORE_ENTRIES;
|
|
|
|
goto done;
|
2008-10-23 15:52:39 +02:00
|
|
|
}
|
|
|
|
output->size = size;
|
|
|
|
output->letter = letter;
|
|
|
|
output->type = type;
|
|
|
|
ptr = (char *)(output + 1);
|
|
|
|
|
|
|
|
if (mount_point)
|
|
|
|
{
|
|
|
|
output->mount_point_offset = ptr - (char *)output;
|
|
|
|
strcpy( ptr, mount_point );
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
}
|
|
|
|
else output->mount_point_offset = 0;
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
output->device_offset = ptr - (char *)output;
|
|
|
|
strcpy( ptr, device );
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
}
|
|
|
|
else output->device_offset = 0;
|
|
|
|
|
|
|
|
TRACE( "returning %c: dev %s mount %s type %u\n",
|
|
|
|
letter, debugstr_a(device), debugstr_a(mount_point), type );
|
|
|
|
|
|
|
|
iosb->Information = ptr - (char *)output;
|
2009-07-22 21:02:47 +02:00
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, device );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount_point );
|
|
|
|
return status;
|
2008-10-23 15:52:39 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 14:44:58 +01:00
|
|
|
/* implementation of IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS */
|
|
|
|
static NTSTATUS query_dhcp_request_params( void *buff, SIZE_T insize,
|
|
|
|
SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
|
|
|
{
|
|
|
|
struct mountmgr_dhcp_request_params *query = buff;
|
|
|
|
ULONG i, offset;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]) > insize ||
|
|
|
|
!memchrW( query->adapter, 0, ARRAY_SIZE(query->adapter) )) return STATUS_INVALID_PARAMETER;
|
|
|
|
for (i = 0; i < query->count; i++)
|
|
|
|
if (query->params[i].offset + query->params[i].size > insize) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]);
|
|
|
|
for (i = 0; i < query->count; i++)
|
|
|
|
{
|
|
|
|
offset += get_dhcp_request_param( query->adapter, &query->params[i], buff, offset, outsize - offset );
|
|
|
|
if (offset > outsize)
|
|
|
|
{
|
|
|
|
if (offset >= sizeof(query->size)) query->size = offset;
|
|
|
|
iosb->Information = sizeof(query->size);
|
|
|
|
return STATUS_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iosb->Information = offset;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-01-04 13:07:05 +01:00
|
|
|
/* handler for ioctls on the mount manager device */
|
|
|
|
static NTSTATUS WINAPI mountmgr_ioctl( DEVICE_OBJECT *device, IRP *irp )
|
|
|
|
{
|
2010-03-23 17:08:03 +01:00
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
2008-01-04 13:07:05 +01:00
|
|
|
|
|
|
|
TRACE( "ioctl %x insize %u outsize %u\n",
|
|
|
|
irpsp->Parameters.DeviceIoControl.IoControlCode,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength );
|
|
|
|
|
|
|
|
switch(irpsp->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
{
|
2008-01-04 14:28:47 +01:00
|
|
|
case IOCTL_MOUNTMGR_QUERY_POINTS:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(MOUNTMGR_MOUNT_POINT))
|
2011-11-01 13:03:22 +01:00
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 13:03:12 +01:00
|
|
|
irp->IoStatus.u.Status = query_mount_points( irp->AssociatedIrp.SystemBuffer,
|
2008-01-04 14:28:47 +01:00
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
|
|
|
break;
|
2008-10-23 15:48:08 +02:00
|
|
|
case IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
|
2011-11-01 13:03:22 +01:00
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2008-10-23 15:48:08 +02:00
|
|
|
irp->IoStatus.Information = 0;
|
2011-11-01 13:03:12 +01:00
|
|
|
irp->IoStatus.u.Status = define_unix_drive( irp->AssociatedIrp.SystemBuffer,
|
2008-10-23 15:48:08 +02:00
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength );
|
|
|
|
break;
|
2008-10-23 15:52:39 +02:00
|
|
|
case IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
|
2011-11-01 13:03:22 +01:00
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 13:03:12 +01:00
|
|
|
irp->IoStatus.u.Status = query_unix_drive( irp->AssociatedIrp.SystemBuffer,
|
2008-10-23 15:52:39 +02:00
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
|
|
|
break;
|
2019-11-19 14:44:58 +01:00
|
|
|
case IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_dhcp_request_params))
|
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
irp->IoStatus.u.Status = query_dhcp_request_params( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
|
|
|
break;
|
2008-01-04 13:07:05 +01:00
|
|
|
default:
|
|
|
|
FIXME( "ioctl %x not supported\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
|
|
|
|
irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-23 17:08:03 +01:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2015-03-04 14:18:04 +01:00
|
|
|
return STATUS_SUCCESS;
|
2008-01-04 13:07:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* main entry point for the mount point manager driver */
|
|
|
|
NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
|
|
|
|
{
|
2008-10-21 15:02:10 +02:00
|
|
|
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};
|
2008-01-04 13:07:05 +01:00
|
|
|
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};
|
|
|
|
static const WCHAR link_mountmgrW[] = {'\\','?','?','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
|
2008-01-04 14:21:27 +01:00
|
|
|
static const WCHAR harddiskW[] = {'\\','D','r','i','v','e','r','\\','H','a','r','d','d','i','s','k',0};
|
2017-04-26 05:18:35 +02:00
|
|
|
static const WCHAR driver_serialW[] = {'\\','D','r','i','v','e','r','\\','S','e','r','i','a','l',0};
|
2017-04-26 05:18:36 +02:00
|
|
|
static const WCHAR driver_parallelW[] = {'\\','D','r','i','v','e','r','\\','P','a','r','a','l','l','e','l',0};
|
2019-11-25 18:40:34 +01:00
|
|
|
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};
|
2008-01-04 13:07:05 +01:00
|
|
|
|
2017-10-29 21:58:52 +01:00
|
|
|
#ifdef _WIN64
|
|
|
|
static const WCHAR qualified_ports_keyW[] = {'\\','R','E','G','I','S','T','R','Y','\\',
|
|
|
|
'M','A','C','H','I','N','E','\\','S','o','f','t','w','a','r','e','\\',
|
|
|
|
'W','i','n','e','\\','P','o','r','t','s'}; /* no null terminator */
|
|
|
|
static const WCHAR wow64_ports_keyW[] = {'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'W','o','w','6','4','3','2','N','o','d','e','\\','W','i','n','e','\\',
|
|
|
|
'P','o','r','t','s',0};
|
|
|
|
static const WCHAR symbolic_link_valueW[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e',0};
|
|
|
|
HKEY wow64_ports_key = NULL;
|
|
|
|
#endif
|
|
|
|
|
2008-01-04 13:07:05 +01:00
|
|
|
UNICODE_STRING nameW, linkW;
|
|
|
|
DEVICE_OBJECT *device;
|
2019-11-25 18:40:34 +01:00
|
|
|
HKEY devicemap_key;
|
2008-01-04 13:07:05 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "%s\n", debugstr_w(path->Buffer) );
|
|
|
|
|
|
|
|
driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = mountmgr_ioctl;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, device_mountmgrW );
|
|
|
|
RtlInitUnicodeString( &linkW, link_mountmgrW );
|
|
|
|
if (!(status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device )))
|
|
|
|
status = IoCreateSymbolicLink( &linkW, &nameW );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
FIXME( "failed to create device error %x\n", status );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-10-21 15:02:10 +02:00
|
|
|
RegCreateKeyExW( HKEY_LOCAL_MACHINE, mounted_devicesW, 0, NULL,
|
|
|
|
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &mount_key, NULL );
|
2008-03-04 07:58:32 +01:00
|
|
|
|
2019-11-25 18:40:34 +01:00
|
|
|
if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE, devicemapW, 0, NULL, REG_OPTION_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS, NULL, &devicemap_key, NULL ))
|
|
|
|
RegCloseKey( devicemap_key );
|
|
|
|
|
2008-01-04 14:21:27 +01:00
|
|
|
RtlInitUnicodeString( &nameW, harddiskW );
|
|
|
|
status = IoCreateDriver( &nameW, harddisk_driver_entry );
|
|
|
|
|
2011-12-20 11:04:18 +01:00
|
|
|
initialize_dbus();
|
2008-10-21 15:02:10 +02:00
|
|
|
initialize_diskarbitration();
|
|
|
|
|
2017-10-29 21:58:52 +01:00
|
|
|
#ifdef _WIN64
|
|
|
|
/* create a symlink so that the Wine port overrides key can be edited with 32-bit reg or regedit */
|
|
|
|
RegCreateKeyExW( HKEY_LOCAL_MACHINE, wow64_ports_keyW, 0, NULL, REG_OPTION_CREATE_LINK,
|
|
|
|
KEY_SET_VALUE, NULL, &wow64_ports_key, NULL );
|
|
|
|
RegSetValueExW( wow64_ports_key, symbolic_link_valueW, 0, REG_LINK,
|
|
|
|
(BYTE *)qualified_ports_keyW, sizeof(qualified_ports_keyW) );
|
|
|
|
RegCloseKey( wow64_ports_key );
|
|
|
|
#endif
|
|
|
|
|
2017-04-26 05:18:35 +02:00
|
|
|
RtlInitUnicodeString( &nameW, driver_serialW );
|
|
|
|
IoCreateDriver( &nameW, serial_driver_entry );
|
|
|
|
|
2017-04-26 05:18:36 +02:00
|
|
|
RtlInitUnicodeString( &nameW, driver_parallelW );
|
|
|
|
IoCreateDriver( &nameW, parallel_driver_entry );
|
|
|
|
|
2008-01-04 13:07:05 +01:00
|
|
|
return status;
|
|
|
|
}
|