-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix: Fixed issue where BitLocker locked drive wasn't displayed #18468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yair100
merged 1 commit into
files-community:main
from
muko:fix/locked-bitlocker-drive-not-shown
May 13, 2026
+25
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ private void Win32_OnDeviceRemoved(object? sender, DeviceEventArgs e) | |
| private async void Win32_OnDeviceAdded(object? sender, DeviceEventArgs e) | ||
| { | ||
| var driveAdded = new DriveInfo(e.DeviceId); | ||
| if (!driveAdded.IsReady) | ||
| if (!driveAdded.IsReady && !IsUnauthorizedDrive(driveAdded)) | ||
| return; | ||
|
|
||
| var rootAdded = await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(e.DeviceId).AsTask()); | ||
|
|
@@ -101,7 +101,7 @@ private async void Watcher_Added(DeviceWatcher sender, DeviceInformation args) | |
| { | ||
| // Check if this drive is associated with a drive letter | ||
| var driveAdded = new DriveInfo(root.Path); | ||
| if (!driveAdded.IsReady) | ||
| if (!driveAdded.IsReady && !IsUnauthorizedDrive(driveAdded)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| return; | ||
|
|
||
| type = DriveHelpers.GetDriveType(driveAdded); | ||
|
|
@@ -139,5 +139,28 @@ public void Stop() | |
| DeviceManager.Default.DeviceInserted -= Win32_OnDeviceEjectedOrInserted; | ||
| DeviceManager.Default.DeviceEjected -= Win32_OnDeviceEjectedOrInserted; | ||
| } | ||
|
|
||
| private bool IsUnauthorizedDrive(DriveInfo driveInfo) | ||
| { | ||
| try | ||
| { | ||
| _ = Directory.EnumerateFileSystemEntries(driveInfo.Name).FirstOrDefault(); | ||
| return false; | ||
| } | ||
| catch (UnauthorizedAccessException) | ||
| { | ||
| // probably BitLocker locked drive. | ||
| return true; | ||
| } | ||
| catch (IOException ex) when (ex.HResult == unchecked((int)0x80310000)) // FVE_E_LOCKED_VOLUME | ||
| { | ||
| // BitLocker locked drive. | ||
| return true; | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be "or" condition (
||).If the drive is not ready,
IsUnauthorizedDrivewill still be called, causing an exception on an unready driveUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsUnauthorizedDrive()has all code paths wrapped in try-catch, so no exception will be thrown whenIsReady== false.In addition, with
||, a locked BitLocker drive (IsReady== false,IsUnauthorizedDrive()== true) and a normal drive (IsReady == true, IsUnauthorizedDrive() == false) would both incorrectly return early.