-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
In #69484 I've tried to add the following line:
Debug.Assert(Enum.IsDefined(fileSystemType) || fstatfsResult == 0, $"GetFileSystemType returned {fstatfsResult}");it turned out, that this assert was failing for some Apple OSes:
Process terminated. Assertion failed.
GetFileSystemType returned 19
at Interop.Sys.TryGetFileSystemType(SafeFileHandle fd, UnixFileSystemTypes& fileSystemType) in /_/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs:line 158
Based on this StackOverflow question I can see that file system ids are version-specific (how cool is that?). Moreover, the official docs say:
Filesystem type numbers are an old construct; most filesystems just get a number assigned based on the order in which they are registered with the system.
We most likely need to use the BSD approach:
runtime/src/native/libs/System.Native/pal_io.c
Lines 1489 to 1497 in 008f128
| #elif !HAVE_NON_LEGACY_STATFS | |
| int statfsRes; | |
| struct statvfs statfsArgs; | |
| while ((statfsRes = fstatvfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; | |
| if (statfsRes == -1) return (int64_t)-1; | |
| int64_t result = -1; | |
| if (strcmp(statfsArgs.f_basetype, "adfs") == 0) result = 0xADF5; |
and extend it with Apple file system names (hfs, autofs, apfs) and our "made up" ids (to have a proper way to map to managed enum).
Usually I would address it as part of #69484 but since I've started my honemoon last Friday, I am creating this issue to track it and reverting the Debug.Assert added to the original PR.