dll: FspMountBroadcastDriveChange

Broadcast WM_DEVICECHANGE asynchronously.
This commit is contained in:
Bill Zissimopoulos 2022-06-07 14:06:13 +01:00
parent 0a919d317a
commit 22bf0b09ef

View File

@ -393,6 +393,39 @@ struct FspMountBroadcastDriveChangeData
}; };
static DWORD WINAPI FspMountBroadcastDriveChangeThread(PVOID Data0) static DWORD WINAPI FspMountBroadcastDriveChangeThread(PVOID Data0)
{
struct FspMountBroadcastDriveChangeData *Data = Data0;
HMODULE Module = Data->Module;
WPARAM WParam = Data->WParam;
PWSTR MountPoint = Data->MountPoint;
BOOLEAN IsLocalSystem;
DEV_BROADCAST_VOLUME DriveChange;
DWORD Recipients;
FspServiceContextCheck(0, &IsLocalSystem);
memset(&DriveChange, 0, sizeof DriveChange);
DriveChange.dbcv_size = sizeof DriveChange;
DriveChange.dbcv_devicetype = DBT_DEVTYP_VOLUME;
DriveChange.dbcv_flags = DBTF_NET;
DriveChange.dbcv_unitmask = 1 << ((MountPoint[0] | 0x20) - 'a');
Recipients = BSM_APPLICATIONS | (IsLocalSystem ? BSM_ALLDESKTOPS : 0);
BroadcastSystemMessageW(
BSF_POSTMESSAGE,
&Recipients,
WM_DEVICECHANGE,
WParam,
(LPARAM)&DriveChange);
MemFree(Data);
FreeLibraryAndExitThread(Module, 0);
return 0;
}
static NTSTATUS FspMountBroadcastDriveChange(PWSTR MountPoint, WPARAM WParam)
{ {
/* /*
* DefineDosDeviceW (either directly or via the CSRSS) broadcasts a WM_DEVICECHANGE message * DefineDosDeviceW (either directly or via the CSRSS) broadcasts a WM_DEVICECHANGE message
@ -409,37 +442,9 @@ static DWORD WINAPI FspMountBroadcastDriveChangeThread(PVOID Data0)
* *
* To resolve this we simply call BroadcastSystemMessage with BSF_POSTMESSAGE. (It would work * To resolve this we simply call BroadcastSystemMessage with BSF_POSTMESSAGE. (It would work
* with BSF_NOHANG | BSF_FORCEIFHUNG and without NOTIMEOUTIFNOTHUNG, but BSF_POSTMESSAGE is * with BSF_NOHANG | BSF_FORCEIFHUNG and without NOTIMEOUTIFNOTHUNG, but BSF_POSTMESSAGE is
* faster). * faster). We do this in a separate thread to avoid blocking caller's thread.
*/ */
struct FspMountBroadcastDriveChangeData *Data = Data0;
BOOLEAN IsLocalSystem;
DEV_BROADCAST_VOLUME DriveChange;
DWORD Recipients;
FspServiceContextCheck(0, &IsLocalSystem);
memset(&DriveChange, 0, sizeof DriveChange);
DriveChange.dbcv_size = sizeof DriveChange;
DriveChange.dbcv_devicetype = DBT_DEVTYP_VOLUME;
DriveChange.dbcv_flags = DBTF_NET;
DriveChange.dbcv_unitmask = 1 << ((Data->MountPoint[0] | 0x20) - 'a');
Recipients = BSM_APPLICATIONS | (IsLocalSystem ? BSM_ALLDESKTOPS : 0);
BroadcastSystemMessageW(
BSF_POSTMESSAGE,
&Recipients,
WM_DEVICECHANGE,
Data->WParam,
(LPARAM)&DriveChange);
FreeLibraryAndExitThread(Data->Module, 0);
return 0;
}
static NTSTATUS FspMountBroadcastDriveChange(PWSTR MountPoint, WPARAM WParam)
{
NTSTATUS Result; NTSTATUS Result;
HMODULE Module; HMODULE Module;
HANDLE Thread; HANDLE Thread;