-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add missing filesystem magic numbers to UnixFileSystemTypes enum #122829
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
base: main
Are you sure you want to change the base?
Conversation
This fixes DriveInfo.DriveType returning Unknown for exfat filesystems by adding the exfat magic number (0x2011BAB0) to the enum. The GetDriveType switch already included "exfat" as a Fixed drive type, but the enum was missing the magic number mapping. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-system-io |
|
@copilot Could you please double-check that we are not missing support for any other filesystem magic numbers? |
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.
Pull request overview
This PR fixes an issue where DriveInfo.DriveType returns Unknown and DriveFormat returns an empty string for exFAT filesystems on Linux. The fix adds the missing exFAT filesystem magic number (0x2011BAB0) to the UnixFileSystemTypes enum, enabling proper identification of exFAT drives commonly used on USB drives and SD cards.
Key changes:
- Added
exfat = 0x2011BAB0to theUnixFileSystemTypesenum in alphabetical order
Added magic numbers for filesystems already in GetDriveType but missing from the enum: - aafs (AppArmor), daxfs, efivarfs, hostfs, ibrix, nsfs, prl_fs, snfs Added new commonly-used filesystems with both magic number and DriveType: - bcachefs (Linux 6.7+), erofs (Android/containers), zonefs Magic numbers sourced from Linux kernel magic.h and GNU coreutils stat.c. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Head branch was pushed to by a user without write access
I've reviewed the Linux kernel Missing magic numbers for filesystems already in GetDriveType:
New commonly-used filesystems (magic number + DriveType entry):
Note: I intentionally skipped |
|
@copilot, how are you deciding which values to include, or which version of the cited files were you looking at? I see values in https://raw.githubusercontent.com/torvalds/linux/refs/heads/master/include/uapi/linux/magic.h that aren't included. |
Added missing user-accessible filesystems from magic.h: - binderfs (0x6C6F6F70) - Android Binder filesystem - btrfs_test (0x73727279) - Btrfs test filesystem - pidfs (0x50494446) - PID filesystem - rdtgroup (0x07655821) - Intel RDT resource groups - smackfs (0x43415D53) - Smack security module Excluded kernel-internal magic numbers (STACK_END_MAGIC, DMA_BUF_MAGIC, DEVMEM_MAGIC, SECRETMEM_MAGIC, GUEST_MEMFD_MAGIC) as these aren't user-visible filesystems. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
My criteria was to include user-accessible filesystems and exclude kernel-internal magic numbers. I was looking at the current master branch of magic.h. In commit 66703f0, I added the remaining user-accessible filesystems I had missed:
I intentionally excluded these kernel-internal values that aren't user-visible mount points:
|
|
The list in |
|
Added filesystem mappings to keep pal_io.c in sync: - aafs, bcachefs, binderfs, btrfs_test, daxfs, efivarfs, erofs, exfat - hostfs, ibrix, nsfs, pidfs, prl_fs, rdtgroup, smackfs, snfs, zonefs Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
main PR
Description
DriveInfo.DriveTypereturnsUnknownandDriveFormatreturns empty string for various filesystems on Linux, including exfat.The
UnixFileSystemTypesenum was missing several filesystem magic numbers, so numeric filesystem type lookups failed. TheGetDriveTypeswitch already handled many of these filesystem strings correctly.Changes:
exfat = 0x2011BAB0(originally reported issue)aafs(0x5A3C69F0) - AppArmor filesystembtrfs_test(0x73727279) - Btrfs test filesystemdaxfs(0x64646178) - DAX filesystemefivarfs(0xDE5E81E4) - EFI variables filesystemhostfs(0x00C0FFEE) - User Mode Linux host filesystemibrix(0x013111A8) - IBM GPFS/IBRIXnsfs(0x6E736673) - Namespace filesystemprl_fs(0x7C7C6673) - Parallels filesystemsmackfs(0x43415D53) - Smack security modulesnfs(0xBEEFDEAD) - StorNext filesystembcachefs(0xCA451A4E) - Modern CoW filesystem in Linux 6.7+binderfs(0x6C6F6F70) - Android Binder filesystemerofs(0xE0F5E1E2) - Enhanced Read-Only FS, used in Android/containerspidfs(0x50494446) - PID filesystemrdtgroup(0x07655821) - Intel RDT resource groupszonefs(0x5A4F4653) - Zoned block device filesystemsrc/native/libs/System.Native/pal_io.cMapFileSystemNameToEnumfunction with the updated enum valuesAll magic numbers sourced from Linux kernel
magic.hand GNU coreutilsstat.c.Excluded: Kernel-internal magic numbers that aren't user-visible filesystems (STACK_END_MAGIC, DMA_BUF_MAGIC, DEVMEM_MAGIC, SECRETMEM_MAGIC, GUEST_MEMFD_MAGIC).
Customer Impact
Users mounting various drives (exfat USB drives/SD cards, bcachefs volumes, erofs container images, etc.) cannot programmatically identify the drive type or filesystem format.
Regression
No. These have been missing since the respective filesystem kernel support was added.
Testing
System.IO.FileSystem.DriveInfotests passInterop.MountPoints.FormatInfo.csvalidates enum/switch consistencyRisk
Low. Addition of well-documented magic numbers from authoritative sources (Linux kernel and coreutils). No behavioral change for other filesystems.
Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.