Skip to content

Commit

Permalink
Ignore ACCESS_DENIED on volume scanning
Browse files Browse the repository at this point in the history
To avoid need to escalate privilege when a machine has container volumes.
  • Loading branch information
erikmav authored Sep 11, 2023
1 parent 9e96689 commit b2b9ebd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PropertyGroup>

<!-- DOCSYNC: When changing version number update README.md -->
<Version>0.3.6.0</Version>
<Version>0.3.7.0</Version>
<AssemblyVersion>0.9.9999.0</AssemblyVersion>

<Company>Microsoft</Company>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ File clones on Windows do not actually allocate space on-drive for the clone. Th

[![NuGet version (CopyOnWrite)](https://img.shields.io/nuget/v/CopyOnWrite?style=plastic)](https://www.nuget.org/packages/CopyOnWrite)

* 0.3.7 September 2023: Fix #30 - ignore ACCESS_DENIED on volume enumeration to avoid need to escalate privilege on Windows.
* 0.3.6 July 2023: Set AssemblyVersion to 0.9.9999.0 to allow mixing different minor-version binaries from different packages in the same appdomain/process.
* 0.3.5 July 2023: Set AssemblyVersion to 0.0.0.1 to allow mixing different minor-version binaries from different packages in the same appdomain/process.
* 0.3.4 July 2023: Handle locked BitLocker volume during volume scan.
Expand Down
11 changes: 8 additions & 3 deletions lib/Windows/VolumeInfoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public VolumeInfo GetVolumeForPath(string path)
"If the drive was added recently you may need to recreate the filesystem cache.");
}

private const int ERROR_ACCESS_DENIED = 5;
private const int ERROR_NOT_READY = 21;
private const int ERROR_INVALID_PARAMETER = 87;
private const int ERROR_UNRECOGNIZED_VOLUME = 1005;
Expand All @@ -123,12 +124,16 @@ public VolumeInfo GetVolumeForPath(string path)
{
int lastErr = Marshal.GetLastWin32Error();

// Some SD Card readers show a drive letter even when empty, and BitLocker can have a volume locked.
// Instead of erroring out, let's just ignore those.
// Ignore:
// - Some SD Card readers show a drive letter even when empty.
// - BitLocker can have a volume locked.
// - Access denied can imply a volume needing escalated privilege to get its metadata,
// sometimes indicating a Windows container volume.
if (lastErr == ERROR_UNRECOGNIZED_VOLUME ||
lastErr == ERROR_NOT_READY ||
lastErr == ERROR_INVALID_PARAMETER ||
lastErr == FVE_E_LOCKED_VOLUME)
lastErr == FVE_E_LOCKED_VOLUME ||
lastErr == ERROR_ACCESS_DENIED)
{
return null;
}
Expand Down

0 comments on commit b2b9ebd

Please sign in to comment.