removable drive seen in debbugger although i filter it.

Dani_S 3,106 Reputation points
2024-05-30T11:56:43.41+00:00

hi,

i used this code and i see removable drive in debugger, why?

I used mac.

DriveInfo[] drives = DriveInfo.GetDrives();

drives = drives.Where(drive=> drive.DriveType != DriveType.Removable && drive.DriveType != DriveType.CDRom).ToArray();

Thanks,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,077 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 59,471 Reputation points
    2024-05-30T18:17:04.4466667+00:00

    DriveInfo.GetDrives() is returning mount information. It list all known mounts (physical or image). the unix call statfs() is used to get the volume information for the mount point.

    the .Name and .RootDirectory will return the mount point. typically "/System/Volumes/<volume name>". but the mount point can be anywhere. a user may create "/System/Volumes/Usb" folder and mount usb drives there. The IOS simulator disk images are mounted under "/Library/Developer/CoreSimulator/Volumes/". would not expect:

    drives = drives.Where(drive=> drive.Name == "//").ToArray();

    to return any values as "//" is not a typical path or mount point.

    the .DriveType is a mapping of the unix file system type. for example "iso", "cd9660" are mapped to DriveType.CDRom. see code:

    https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs#L43

    note: because the file system type is used to determine DriveType.Removable, it is not reliable. a fat formatted usb volume would be .Removable, but an apfs formatted usb volume would not.