2003-08-30 02:49:00 +02:00
|
|
|
/*
|
2004-11-23 14:50:23 +01:00
|
|
|
* Drive management code
|
2003-08-30 02:49:00 +02:00
|
|
|
*
|
|
|
|
* Copyright 2003 Mark Westcott
|
2004-11-23 14:50:23 +01:00
|
|
|
* Copyright 2003-2004 Mike Hearn
|
2004-05-04 04:56:46 +02:00
|
|
|
* Copyright 2004 Chris Morgan
|
2003-08-30 02:49:00 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-30 02:49:00 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-23 16:00:00 +02:00
|
|
|
#include <ntstatus.h>
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
2008-10-23 16:00:00 +02:00
|
|
|
#include <winternl.h>
|
|
|
|
#include <winioctl.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <winreg.h>
|
|
|
|
#include <wine/debug.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
#include <shellapi.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <objbase.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
#include <shlguid.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <shlobj.h>
|
2008-10-23 16:00:00 +02:00
|
|
|
#define WINE_MOUNTMGR_EXTENSIONS
|
|
|
|
#include <ddk/mountmgr.h>
|
2003-08-30 02:49:00 +02:00
|
|
|
|
|
|
|
#include "winecfg.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2003-08-30 02:49:00 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
struct drive drives[26]; /* one for each drive letter */
|
|
|
|
|
|
|
|
static inline int letter_to_index(char letter)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
return (toupper(letter) - 'A');
|
|
|
|
}
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* This function produces a mask for each drive letter that isn't
|
|
|
|
* currently used. Each bit of the long result represents a letter,
|
|
|
|
* with A being the least significant bit, and Z being the most
|
|
|
|
* significant.
|
|
|
|
*
|
|
|
|
* To calculate this, we loop over each letter, and see if we can get
|
|
|
|
* a drive entry for it. If so, we set the appropriate bit. At the
|
|
|
|
* end, we flip each bit, to give the desired result.
|
|
|
|
*
|
|
|
|
* The letter parameter is always marked as being available. This is
|
|
|
|
* so the edit dialog can display the currently used drive letter
|
|
|
|
* alongside the available ones.
|
|
|
|
*/
|
2009-04-02 12:05:35 +02:00
|
|
|
ULONG drive_available_mask(char letter)
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
2009-04-02 12:05:35 +02:00
|
|
|
ULONG result = 0;
|
2004-11-23 14:50:23 +01:00
|
|
|
int i;
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
WINE_TRACE("\n");
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
for(i = 0; i < 26; i++)
|
|
|
|
{
|
|
|
|
if (!drives[i].in_use) continue;
|
2006-02-04 16:58:18 +01:00
|
|
|
result |= (1 << (letter_to_index(drives[i].letter)));
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result = ~result;
|
|
|
|
if (letter) result |= DRIVE_MASK_BIT(letter);
|
|
|
|
|
2022-02-07 08:40:37 +01:00
|
|
|
WINE_TRACE("finished drive letter loop with %lx\n", result);
|
2004-11-23 14:50:23 +01:00
|
|
|
return result;
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2008-10-23 16:19:36 +02:00
|
|
|
BOOL add_drive(char letter, const char *targetpath, const char *device, const WCHAR *label,
|
|
|
|
DWORD serial, DWORD type)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
int driveIndex = letter_to_index(letter);
|
2004-05-13 07:17:41 +02:00
|
|
|
|
|
|
|
if(drives[driveIndex].in_use)
|
2004-05-04 04:56:46 +02:00
|
|
|
return FALSE;
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2022-02-07 08:40:37 +01:00
|
|
|
WINE_TRACE("letter == '%c', unixpath == %s, device == %s, label == %s, serial == %08lx, type == %ld\n",
|
2008-10-23 16:19:36 +02:00
|
|
|
letter, wine_dbgstr_a(targetpath), wine_dbgstr_a(device),
|
|
|
|
wine_dbgstr_w(label), serial, type);
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-05-13 07:17:41 +02:00
|
|
|
drives[driveIndex].letter = toupper(letter);
|
2004-11-23 14:50:23 +01:00
|
|
|
drives[driveIndex].unixpath = strdupA(targetpath);
|
2008-10-23 16:19:36 +02:00
|
|
|
drives[driveIndex].device = device ? strdupA(device) : NULL;
|
|
|
|
drives[driveIndex].label = label ? strdupW(label) : NULL;
|
2008-10-17 13:37:04 +02:00
|
|
|
drives[driveIndex].serial = serial;
|
2004-05-13 07:17:41 +02:00
|
|
|
drives[driveIndex].type = type;
|
|
|
|
drives[driveIndex].in_use = TRUE;
|
2008-10-23 12:15:43 +02:00
|
|
|
drives[driveIndex].modified = TRUE;
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-08-30 02:49:00 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* deallocates the contents of the drive. does not free the drive itself */
|
|
|
|
void delete_drive(struct drive *d)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d->unixpath);
|
2005-02-14 21:54:21 +01:00
|
|
|
d->unixpath = NULL;
|
2008-10-23 16:19:36 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, d->device);
|
|
|
|
d->device = NULL;
|
2004-11-23 14:50:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d->label);
|
2005-02-14 21:54:21 +01:00
|
|
|
d->label = NULL;
|
2008-10-17 13:37:04 +02:00
|
|
|
d->serial = 0;
|
2004-11-23 14:50:23 +01:00
|
|
|
d->in_use = FALSE;
|
2008-10-23 12:15:43 +02:00
|
|
|
d->modified = TRUE;
|
2003-09-10 05:41:44 +02:00
|
|
|
}
|
|
|
|
|
2005-10-20 15:16:46 +02:00
|
|
|
static DWORD get_drive_type( char letter )
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
2021-09-07 17:14:22 +02:00
|
|
|
WCHAR driveValue[4];
|
2005-10-20 15:16:46 +02:00
|
|
|
DWORD ret = DRIVE_UNKNOWN;
|
|
|
|
|
2021-09-07 17:14:22 +02:00
|
|
|
swprintf(driveValue, 4, L"%c:", letter);
|
2005-10-20 15:16:46 +02:00
|
|
|
|
2021-09-07 17:14:22 +02:00
|
|
|
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, L"Software\\Wine\\Drives", &hKey) != ERROR_SUCCESS)
|
2005-10-20 15:16:46 +02:00
|
|
|
WINE_TRACE(" Unable to open Software\\Wine\\Drives\n" );
|
|
|
|
else
|
|
|
|
{
|
2021-09-07 17:14:22 +02:00
|
|
|
WCHAR buffer[80];
|
2021-10-20 04:07:06 +02:00
|
|
|
DWORD size = sizeof(buffer);
|
2005-10-20 15:16:46 +02:00
|
|
|
|
2021-09-07 17:14:22 +02:00
|
|
|
if (!RegQueryValueExW( hKey, driveValue, NULL, NULL, (LPBYTE)buffer, &size ))
|
2005-10-20 15:16:46 +02:00
|
|
|
{
|
2021-09-07 17:14:22 +02:00
|
|
|
WINE_TRACE("Got type %s for %s\n", debugstr_w(buffer), debugstr_w(driveValue) );
|
|
|
|
if (!wcsicmp( buffer, L"hd" )) ret = DRIVE_FIXED;
|
|
|
|
else if (!wcsicmp( buffer, L"network" )) ret = DRIVE_REMOTE;
|
|
|
|
else if (!wcsicmp( buffer, L"floppy" )) ret = DRIVE_REMOVABLE;
|
|
|
|
else if (!wcsicmp( buffer, L"cdrom" )) ret = DRIVE_CDROM;
|
2005-10-20 15:16:46 +02:00
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-21 16:25:27 +01:00
|
|
|
|
2008-10-17 14:11:56 +02:00
|
|
|
static void set_drive_label( char letter, const WCHAR *label )
|
2005-11-21 16:25:27 +01:00
|
|
|
{
|
2008-10-17 14:11:56 +02:00
|
|
|
static const WCHAR emptyW[1];
|
2021-09-07 13:41:35 +02:00
|
|
|
WCHAR device[] = L"a:\\"; /* SetVolumeLabel() requires a trailing slash */
|
2005-11-21 16:25:27 +01:00
|
|
|
device[0] = letter;
|
|
|
|
|
2008-10-17 14:11:56 +02:00
|
|
|
if (!label) label = emptyW;
|
|
|
|
if(!SetVolumeLabelW(device, label))
|
2005-11-21 16:25:27 +01:00
|
|
|
{
|
2008-10-17 14:11:56 +02:00
|
|
|
WINE_WARN("unable to set volume label for devicename of %s, label of %s\n",
|
|
|
|
wine_dbgstr_w(device), wine_dbgstr_w(label));
|
2005-11-21 16:25:27 +01:00
|
|
|
PRINTERROR();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-17 14:11:56 +02:00
|
|
|
WINE_TRACE(" set volume label for devicename of %s, label of %s\n",
|
|
|
|
wine_dbgstr_w(device), wine_dbgstr_w(label));
|
2005-11-21 16:25:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the drive serial number via a .windows-serial file */
|
2012-01-20 12:42:33 +01:00
|
|
|
static void set_drive_serial( WCHAR letter, DWORD serial )
|
2005-11-21 16:25:27 +01:00
|
|
|
{
|
2021-09-07 13:41:35 +02:00
|
|
|
WCHAR filename[] = L"a:\\.windows-serial";
|
2005-11-21 16:25:27 +01:00
|
|
|
HANDLE hFile;
|
|
|
|
|
|
|
|
filename[0] = letter;
|
2022-02-07 08:40:37 +01:00
|
|
|
WINE_TRACE("Putting serial number of %08lX into file %s\n", serial, wine_dbgstr_w(filename));
|
2012-01-20 12:42:33 +01:00
|
|
|
hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
2005-11-21 16:25:27 +01:00
|
|
|
if (hFile != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DWORD w;
|
2008-10-17 13:37:04 +02:00
|
|
|
char buffer[16];
|
|
|
|
|
2022-02-07 08:40:37 +01:00
|
|
|
sprintf( buffer, "%lX\n", serial );
|
2008-10-17 13:37:04 +02:00
|
|
|
WriteFile(hFile, buffer, strlen(buffer), &w, NULL);
|
2005-11-21 16:25:27 +01:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-23 16:00:00 +02:00
|
|
|
static HANDLE open_mountmgr(void)
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
|
|
|
|
if ((ret = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
|
|
|
0, 0 )) == INVALID_HANDLE_VALUE)
|
2022-02-07 08:40:37 +01:00
|
|
|
WINE_ERR( "failed to open mount manager err %lu\n", GetLastError() );
|
2008-10-23 16:00:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* Load currently defined drives into the drives array */
|
2008-10-23 16:29:11 +02:00
|
|
|
BOOL load_drives(void)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2008-10-23 16:29:11 +02:00
|
|
|
DWORD i, size = 1024;
|
|
|
|
HANDLE mgr;
|
2021-09-07 13:41:35 +02:00
|
|
|
WCHAR root[] = L"A:\\";
|
2005-01-09 19:01:00 +01:00
|
|
|
|
2008-10-23 16:29:11 +02:00
|
|
|
if ((mgr = open_mountmgr()) == INVALID_HANDLE_VALUE) return FALSE;
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2008-10-23 16:29:11 +02:00
|
|
|
while (root[0] <= 'Z')
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2008-10-23 16:29:11 +02:00
|
|
|
struct mountmgr_unix_drive input;
|
|
|
|
struct mountmgr_unix_drive *data;
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2008-10-23 16:29:11 +02:00
|
|
|
if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) break;
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2008-10-23 16:29:11 +02:00
|
|
|
memset( &input, 0, sizeof(input) );
|
|
|
|
input.letter = root[0];
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2008-10-23 16:29:11 +02:00
|
|
|
if (DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE, &input, sizeof(input),
|
|
|
|
data, size, NULL, NULL ))
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
2008-10-23 16:29:11 +02:00
|
|
|
char *unixpath = NULL, *device = NULL;
|
|
|
|
WCHAR volname[MAX_PATH];
|
|
|
|
DWORD serial;
|
|
|
|
|
|
|
|
if (data->mount_point_offset) unixpath = (char *)data + data->mount_point_offset;
|
|
|
|
if (data->device_offset) device = (char *)data + data->device_offset;
|
|
|
|
|
2018-05-18 00:17:06 +02:00
|
|
|
if (!GetVolumeInformationW( root, volname, ARRAY_SIZE(volname),
|
2008-10-23 16:29:11 +02:00
|
|
|
&serial, NULL, NULL, NULL, 0 ))
|
|
|
|
{
|
|
|
|
volname[0] = 0;
|
|
|
|
serial = 0;
|
|
|
|
}
|
|
|
|
if (unixpath) /* FIXME: handle unmounted drives too */
|
|
|
|
add_drive( root[0], unixpath, device, volname, serial, get_drive_type(root[0]) );
|
|
|
|
root[0]++;
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
2008-10-23 16:29:11 +02:00
|
|
|
else
|
2004-11-23 14:50:23 +01:00
|
|
|
{
|
2008-10-23 16:29:11 +02:00
|
|
|
if (GetLastError() == ERROR_MORE_DATA) size = data->size;
|
|
|
|
else root[0]++; /* skip this drive */
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
2008-10-23 16:29:11 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
2006-11-16 20:28:49 +01:00
|
|
|
}
|
|
|
|
|
2008-10-23 12:15:43 +02:00
|
|
|
/* reset modified flags */
|
|
|
|
for (i = 0; i < 26; i++) drives[i].modified = FALSE;
|
|
|
|
|
2008-10-23 16:29:11 +02:00
|
|
|
CloseHandle( mgr );
|
|
|
|
return TRUE;
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
/* some of this code appears to be broken by bugs in Wine: the label
|
|
|
|
* setting code has no effect, for instance */
|
2005-06-16 17:52:44 +02:00
|
|
|
void apply_drive_changes(void)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
|
|
|
int i;
|
2008-10-23 16:00:00 +02:00
|
|
|
HANDLE mgr;
|
|
|
|
DWORD len;
|
|
|
|
struct mountmgr_unix_drive *ioctl;
|
2004-05-04 04:56:46 +02:00
|
|
|
|
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
2008-10-23 16:00:00 +02:00
|
|
|
if ((mgr = open_mountmgr()) == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
/* add each drive and remove as we go */
|
|
|
|
for(i = 0; i < 26; i++)
|
|
|
|
{
|
2008-10-23 12:15:43 +02:00
|
|
|
if (!drives[i].modified) continue;
|
|
|
|
drives[i].modified = FALSE;
|
2004-05-04 04:56:46 +02:00
|
|
|
|
2008-10-23 16:00:00 +02:00
|
|
|
len = sizeof(*ioctl);
|
2008-10-23 16:19:36 +02:00
|
|
|
if (drives[i].in_use)
|
|
|
|
{
|
|
|
|
len += strlen(drives[i].unixpath) + 1;
|
|
|
|
if (drives[i].device) len += strlen(drives[i].device) + 1;
|
|
|
|
}
|
2008-10-23 16:00:00 +02:00
|
|
|
if (!(ioctl = HeapAlloc( GetProcessHeap(), 0, len ))) continue;
|
|
|
|
ioctl->size = len;
|
|
|
|
ioctl->letter = 'a' + i;
|
|
|
|
ioctl->device_offset = 0;
|
2008-10-23 12:15:43 +02:00
|
|
|
if (drives[i].in_use)
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2008-10-23 16:19:36 +02:00
|
|
|
char *ptr = (char *)(ioctl + 1);
|
|
|
|
|
2008-10-23 16:00:00 +02:00
|
|
|
ioctl->type = drives[i].type;
|
2008-10-23 16:19:36 +02:00
|
|
|
strcpy( ptr, drives[i].unixpath );
|
|
|
|
ioctl->mount_point_offset = ptr - (char *)ioctl;
|
|
|
|
if (drives[i].device)
|
|
|
|
{
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy( ptr, drives[i].device );
|
|
|
|
ioctl->device_offset = ptr - (char *)ioctl;
|
|
|
|
}
|
2008-10-23 16:00:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ioctl->type = DRIVE_NO_ROOT_DIR;
|
|
|
|
ioctl->mount_point_offset = 0;
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
2008-10-23 16:00:00 +02:00
|
|
|
|
|
|
|
if (DeviceIoControl( mgr, IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE, ioctl, len, NULL, 0, NULL, NULL ))
|
2004-05-04 04:56:46 +02:00
|
|
|
{
|
2008-10-23 16:00:00 +02:00
|
|
|
set_drive_label( drives[i].letter, drives[i].label );
|
|
|
|
if (drives[i].in_use) set_drive_serial( drives[i].letter, drives[i].serial );
|
2022-02-07 08:40:37 +01:00
|
|
|
WINE_TRACE( "set drive %c: to %s type %lu\n", 'a' + i,
|
2008-10-23 16:00:00 +02:00
|
|
|
wine_dbgstr_a(drives[i].unixpath), drives[i].type );
|
2004-11-23 14:50:23 +01:00
|
|
|
}
|
2022-02-07 08:40:37 +01:00
|
|
|
else WINE_WARN( "failed to set drive %c: to %s type %lu err %lu\n", 'a' + i,
|
2008-10-23 16:00:00 +02:00
|
|
|
wine_dbgstr_a(drives[i].unixpath), drives[i].type, GetLastError() );
|
2015-06-27 22:14:11 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, ioctl );
|
2004-05-04 04:56:46 +02:00
|
|
|
}
|
2008-10-23 16:00:00 +02:00
|
|
|
CloseHandle( mgr );
|
2003-09-10 05:41:44 +02:00
|
|
|
}
|
2021-09-07 13:18:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
void query_shell_folder( const WCHAR *path, char *dest, unsigned int len )
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
HANDLE mgr;
|
|
|
|
|
|
|
|
if ((mgr = open_mountmgr()) == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL ))
|
|
|
|
{
|
|
|
|
CloseHandle( mgr );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_SHELL_FOLDER, nt_name.Buffer, nt_name.Length,
|
|
|
|
dest, len, NULL, NULL );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_shell_folder( const WCHAR *path, const char *dest )
|
|
|
|
{
|
|
|
|
struct mountmgr_shell_folder *ioctl;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
HANDLE mgr;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if ((mgr = open_mountmgr()) == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL ))
|
|
|
|
{
|
|
|
|
CloseHandle( mgr );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = sizeof(*ioctl) + nt_name.Length;
|
|
|
|
if (dest) len += strlen(dest) + 1;
|
|
|
|
|
|
|
|
if (!(ioctl = HeapAlloc( GetProcessHeap(), 0, len ))) return;
|
2021-09-17 16:49:30 +02:00
|
|
|
ioctl->create_backup = TRUE;
|
2021-09-07 13:18:37 +02:00
|
|
|
ioctl->folder_offset = sizeof(*ioctl);
|
|
|
|
ioctl->folder_size = nt_name.Length;
|
|
|
|
memcpy( (char *)ioctl + ioctl->folder_offset, nt_name.Buffer, nt_name.Length );
|
|
|
|
if (dest)
|
|
|
|
{
|
|
|
|
ioctl->symlink_offset = ioctl->folder_offset + ioctl->folder_size;
|
|
|
|
strcpy( (char *)ioctl + ioctl->symlink_offset, dest );
|
|
|
|
}
|
|
|
|
else ioctl->symlink_offset = 0;
|
|
|
|
|
|
|
|
DeviceIoControl( mgr, IOCTL_MOUNTMGR_DEFINE_SHELL_FOLDER, ioctl, len, NULL, 0, NULL, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, ioctl );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
}
|