From 67d5c92a2f5ac9a94d73861035141db5466e7004 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sat, 27 Jul 2024 17:50:22 +0300 Subject: [PATCH] Use filesystem name mapping on FreeBSD (#105417) --- src/native/libs/System.Native/pal_io.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/native/libs/System.Native/pal_io.c b/src/native/libs/System.Native/pal_io.c index 4051656d35ac0..0b6eab7e8c22b 100644 --- a/src/native/libs/System.Native/pal_io.c +++ b/src/native/libs/System.Native/pal_io.c @@ -1575,7 +1575,7 @@ static int16_t ConvertLockType(int16_t managedLockType) } } -#if !HAVE_NON_LEGACY_STATFS || defined(__APPLE__) +#if !HAVE_NON_LEGACY_STATFS || defined(TARGET_APPLE) || defined(TARGET_FREEBSD) static uint32_t MapFileSystemNameToEnum(const char* fileSystemName) { uint32_t result = 0; @@ -1722,8 +1722,11 @@ uint32_t SystemNative_GetFileSystemType(intptr_t fd) while ((statfsRes = fstatfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; if (statfsRes == -1) return 0; -#if defined(__APPLE__) - // On OSX-like systems, f_type is version-specific. Don't use it, just map the name. +#if defined(TARGET_APPLE) || defined(TARGET_FREEBSD) + // * On OSX-like systems, f_type is version-specific. Don't use it, just map the name. + // * Specifically, on FreeBSD with ZFS, f_type may return a value like 0xDE when emulating + // FreeBSD on macOS (e.g., FreeBSD-x64 on macOS ARM64). Therefore, we use f_fstypename to + // get the correct filesystem type. return MapFileSystemNameToEnum(statfsArgs.f_fstypename); #else // On Linux, f_type is signed. This causes some filesystem types to be represented as