diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index 609dbbf3..93d5fd71 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -6328,9 +6328,10 @@ retry: return FALSE; memset (&mountList, 0, sizeof (mountList)); - if ( DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL) - && (mountList.ulMountedDrives < (1 << 26)) - ) + status = DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL) + && (dwResult == sizeof (mountList)) + && (mountList.ulMountedDrives < (1 << 26)); + if (status) { // remove any custom label from registry if (prevMountList.ulMountedDrives) @@ -6345,14 +6346,16 @@ retry: } } - BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountList.ulMountedDrives & ~mountList.ulMountedDrives); + // A failed query doesn't mean that every volume was dismounted. + DWORD removedDrives = status ? prevMountList.ulMountedDrives & ~mountList.ulMountedDrives : 0; + if (removedDrives) + BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, removedDrives); /* GH #337, GH #1426: Flush shell notifications synchronously in silent/CLI mode to prevent ghost drive letters when the process exits immediately after dismount. */ if (Silent && !DeviceChangeBroadcastDisabled) { - DWORD removedDrives = prevMountList.ulMountedDrives & ~mountList.ulMountedDrives; for (i = 0; i < 26; i++) { if (removedDrives & (1 << i)) @@ -6405,7 +6408,7 @@ retry: } else { - if (bBeep) + if (bBeep && status) MessageBeep (0xFFFFFFFF); }