Windows: allow cancelling long mount operations

Add a root-driver abort IOCTL that bypasses the mount control mutex and sets cooperative KDF abort flags for the active mount.

Restrict abort requests to privileged callers or to the user that initiated the pending mount, and retry early wait-dialog cancel requests until the driver has registered the cancellable mount context.

Wire the wait dialog Cancel button to send the abort request through a fresh driver handle, and propagate ERR_USER_ABORT through header/cache processing.

Add a /cancelmount command-line switch that sends the same abort request without displaying UI, so users can cancel hidden-wait-dialog mount operations from another process.
This commit is contained in:
Mounir IDRASSI
2026-06-07 23:39:52 +09:00
parent 105425ebb0
commit 1871765a76
13 changed files with 437 additions and 23 deletions
+11 -1
View File
@@ -103,6 +103,7 @@ enum hidden_os_read_only_notif_mode
#define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10
#define TIMER_INTERVAL_UPDATE_DEVICE_LIST 1000
#define TIMER_INTERVAL_CHECK_FOREGROUND 500
#define TC_COMMAND_CANCEL_MOUNT L"/cancelmount"
BootEncryption *BootEncObj = NULL;
BootEncryptionStatus BootEncStatus;
@@ -5502,7 +5503,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, wchar_t *szVolFileName, int pi
NormalCursor ();
if (mounted)
if (mounted > 0)
{
// Check for problematic file extensions (exe, dll, sys)
@@ -9558,6 +9559,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
OptionEnableMemoryProtection,
OptionEnableScreenProtection,
OptionSignalExit,
CommandCancelMount,
CommandUnmount,
};
@@ -9591,6 +9593,8 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE },
{ OptionEnableScreenProtection, L"/protectScreen", NULL, FALSE },
{ OptionSignalExit, L"/signalExit", NULL, FALSE },
// Add /cancelmount to the command table so it appears in /help.
{ CommandCancelMount, TC_COMMAND_CANCEL_MOUNT, NULL, FALSE },
{ CommandUnmount, L"/unmount", L"/u", FALSE },
};
@@ -10588,6 +10592,12 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz
for (int i = 0; argv && i < argc; i++)
{
if (_wcsicmp (argv[i], TC_COMMAND_CANCEL_MOUNT) == 0)
{
BOOL abortSent = AbortMountOperation (-1);
LocalFree (argv); // free memory allocated by CommandLineToArgvW
return abortSent ? 0 : 1;
}
if (_wcsicmp (argv[i], L"/protectScreen") == 0)
{
if ((i < argc - 1) && _wcsicmp (argv[i + 1], L"no") == 0)