Skip to content

Use mountinfo for Android drive enumeration - #137815

Merged
jkotas merged 2 commits into
mainfrom
krwq-android-drive-enumeration
Nov 21, 2026
Merged

jkotas merged 2 commits into
mainfrom
krwq-android-drive-enumeration

Conversation

@krwq

@krwq krwq commented Nov 18, 2026

Copy link
Copy Markdown
Member

This is a follow-up to #137195, which fixed escaped Linux mount paths reported in #123347. The original issue is about desktop Linux; the Android gap was found while reviewing that fix, rather than in a separate customer report, and later reproduced using controlled mounts on Android emulators.

Android already uses the shared mountinfo parser for filesystem-format lookup, but drive enumeration still goes through Bionic's native mount reader, which leaves octal escapes intact. Include Android in the existing managed enumeration path so that DriveInfo.GetDrives(), Environment.GetLogicalDrives(), and Directory.GetLogicalDrives() return decoded mount destinations when mountinfo is available.

For example, if an Android process has a mount at /mnt/USB Disk, enumeration should return that path rather than /mnt/USB\040Disk. This is conditional: ordinary Android USB/SD-card paths normally use UUIDs, so a space in a volume label alone does not demonstrate the problem. The native fallback is unchanged when mountinfo is unavailable.

Add 22 regression cases to Common.Tests. A separate test-only helper assembly compiles the actual product helper and decoder with simulated OS checks and temporary mountinfo files. This keeps the substitutes out of other tests and avoids adding a product test hook. The cases cover Android/Linux routing, escaped and literal paths, long records, bind destinations, duplicates, empty tables and native-fallback selection.

Testing

  • New repository regression: 9 of 22 cases fail against the original guard; all 22 pass with the fix. The failing cases are the Android paths that incorrectly select native enumeration.
  • Full Common.Tests on Windows: 1,779 passed, 0 failed or skipped.
  • System.IO.FileSystem.DriveInfo.Tests on Windows: 24 passed, 0 failed or skipped.
  • Android-targeted net12.0-unix managed DriveInfo build: passed with 0 warnings or errors.
  • Real Android 16/API 36 and Android 11/API 30 x64 emulators, normal .NET 10.0.15 Mono app, SELinux enforcing: rebuilt original and changed public DriveInfo libraries were deployed separately, with loaded module IDs checked. DriveInfo.GetDrives() failed before the change and returned usable decoded paths afterward.
  • Ordinary mount sets agreed at 160 entries on Android 16 and 100 on Android 11. Ten additional controlled entries per OS covered spaces, tabs, newlines, backslashes, literal escapes, Unicode, stacked duplicate destinations and a denied mount. Duplicate/top-layer behavior was preserved, and denied file/directory access stayed denied.
  • Controlled empty and unreadable mountinfo files exposed a behavior change: empty mountinfo returns no entries; unreadable mountinfo throws UnauthorizedAccessException. The original native reader still enumerated through /proc/mounts in those controls.

The broader all-target Android cross-build encountered APICompat attribute errors that also reproduce with the fix removed. No suppressions were added.

Performance and limits

BenchmarkDotNet ran the original and changed enumeration helpers in optimized Release Android apps over unchanged ordinary mounts:

Emulator Original Changed Original allocation Changed allocation
Android 16, 160 mounts 253.1 microseconds 460.3 microseconds 18,392 B 66,800 B
Android 11, 100 mounts 201.0 microseconds 379.6 microseconds 10,256 B 43,488 B

The managed route is about 1.8-1.9 times slower and allocates 3.6-4.2 times more in these emulator measurements. Together with the unreadable-mountinfo behavior, this is a trade-off to review before choosing this implementation; the one-line fix is not presented as unconditionally ready to merge.

The public DriveInfo library was rebuilt from product sources against the installed .NET 10 contract. A complete matching .NET 12 runtime/CoreLib was not deployed, so corrected public Environment.GetLogicalDrives() and Directory.GetLogicalDrives() were not tested. The experimental CoreCLR APK built but aborted with a missing native P/Invoke; it is not counted as a pass. No physical device, ordinary USB/SD-card customer scenario, ARM or NativeAOT execution is covered.

Privileged setup was used only to create controlled mounts in the app's namespace. The actual managed queries ran as an ordinary untrusted_app UID with SELinux enforcing. Setup, validation results and limitations are documented in the linked issue.

Fixes #137813

Note

Generated with GitHub Copilot.

Route Android through the existing decoded mountinfo enumeration path and add isolated source-linked regression coverage for routing, escaped destinations and native fallback.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

This comment was marked as off-topic.

@dotnet-policy-service

This comment was marked as off-topic.

@krwq

This comment was marked as off-topic.

@krwq

This comment was marked as off-topic.

@azure-pipelines

This comment was marked as off-topic.

1 similar comment
@azure-pipelines

This comment was marked as off-topic.

@dotnet dotnet deleted a comment from azure-pipelines Bot Nov 18, 2026
@dotnet dotnet deleted a comment from azure-pipelines Bot Nov 18, 2026
@dotnet dotnet deleted a comment from azure-pipelines Bot Nov 18, 2026
Remove the test-only helper project, routing fixture and Common.Tests wiring. Retain the one-line Android enumeration fix and the existing shared mountinfo parser tests.

Co-authored-by: Copilot App <[email protected]>
@krwq

This comment was marked as off-topic.

@krwq

This comment was marked as off-topic.

@azure-pipelines

This comment was marked as off-topic.

1 similar comment
@azure-pipelines

This comment was marked as off-topic.

@jkotas
jkotas merged commit 4a6fc8a into main Nov 21, 2026
72 of 80 checks passed
@jkotas
jkotas deleted the krwq-android-drive-enumeration branch November 21, 2026 06:39
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android drive enumeration returns escaped mount paths that cannot be used with filesystem APIs

2 participants