From 1189b974c610e0c34ac03a36765e96bc485af225 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Tue, 20 Jul 2021 13:46:34 +0300 Subject: [PATCH 1/8] Fix illumos build regressions --- src/coreclr/jit/morph.cpp | 2 ++ src/coreclr/minipal/Unix/doublemapping.cpp | 6 +++++ .../Interop.UnixFileSystemTypes.cs | 13 ---------- .../Interop.UnixFileSystemTypes.statfs.cs | 21 +++++++++++++++ .../Interop.UnixFileSystemTypes.statvfs.cs | 18 +++++++++++++ src/libraries/Native/Unix/CMakeLists.txt | 2 +- .../Native/Unix/System.Native/entrypoints.c | 1 + .../Native/Unix/System.Native/pal_io.c | 26 +++++++++++++++++-- .../Native/Unix/System.Native/pal_io.h | 5 ++++ .../Native/Unix/System.Native/pal_memory.c | 13 +++++----- .../src/System.IO.FileSystem.DriveInfo.csproj | 7 +++++ .../System.Private.CoreLib.Shared.projitems | 9 ++++++- src/native/corehost/bundle/extractor.cpp | 4 +++ 13 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs create mode 100644 src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 057c318e81dcf..a864066194d01 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -12742,6 +12742,8 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) CM_ADD_OP: + FALLTHROUGH; + case GT_OR: case GT_XOR: case GT_AND: diff --git a/src/coreclr/minipal/Unix/doublemapping.cpp b/src/coreclr/minipal/Unix/doublemapping.cpp index 6e0278e3ccd69..1b70d35a070fd 100644 --- a/src/coreclr/minipal/Unix/doublemapping.cpp +++ b/src/coreclr/minipal/Unix/doublemapping.cpp @@ -41,6 +41,12 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu #ifdef TARGET_FREEBSD int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU); +#elif defined(TARGET_SUNOS) // has POSIX implementation + char anonName[24]; + sprintf(anonName, "/shm-dotnet-%d", getpid()); + anonName[sizeof(anonName) - 1] = '\0'; + shm_unlink(anonName); + int fd = shm_open(anonName, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); #else // TARGET_FREEBSD int fd = memfd_create("doublemapper", MFD_CLOEXEC); #endif // TARGET_FREEBSD diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs index fd34f87418223..4c9f0f678e710 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs @@ -1,9 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - internal static partial class Interop { internal static partial class Sys @@ -131,15 +128,5 @@ internal enum UnixFileSystemTypes : long xia = 0x012FD16D, zfs = 0x2FC12FC1, } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")] - private static extern long GetFileSystemType(SafeFileHandle fd); - - internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) - { - long fstatfsResult = GetFileSystemType(fd); - fileSystemType = (UnixFileSystemTypes)fstatfsResult; - return fstatfsResult != -1; - } } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs new file mode 100644 index 0000000000000..6d01a5009eed0 --- /dev/null +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; + +internal static partial class Interop +{ + internal static partial class Sys + { + [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")] + private static extern long GetFileSystemType(SafeFileHandle fd); + + internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) + { + long fstatfsResult = GetFileSystemType(fd); + fileSystemType = (UnixFileSystemTypes)fstatfsResult; + return fstatfsResult != -1; + } + } +} diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs new file mode 100644 index 0000000000000..294b194d569d9 --- /dev/null +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; + +internal static partial class Interop +{ + internal static partial class Sys + { + [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemTypeAsString")] + private static extern string GetFileSystemTypeAsString(SafeFileHandle fd); + + internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) => + Enum.TryParse(GetFileSystemTypeAsString(fd), out fileSystemType); + } +} diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index fcd7964aacbe8..31cea57a62938 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -235,7 +235,7 @@ if(CLR_CMAKE_TARGET_UNIX) else() add_compile_options($<$:-Wa,--noexecstack>) if(CLR_CMAKE_TARGET_SUNOS) - add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS) + add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS -DTARGET_SUNOS) else() # -z,now is required for full relro. # see https://www.redhat.com/en/blog/hardening-elf-binaries-using-relocation-read-only-relro diff --git a/src/libraries/Native/Unix/System.Native/entrypoints.c b/src/libraries/Native/Unix/System.Native/entrypoints.c index c8b678ec08340..26d06b196fd57 100644 --- a/src/libraries/Native/Unix/System.Native/entrypoints.c +++ b/src/libraries/Native/Unix/System.Native/entrypoints.c @@ -105,6 +105,7 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_RealPath) DllImportEntry(SystemNative_GetPeerID) DllImportEntry(SystemNative_GetFileSystemType) + DllImportEntry(SystemNative_GetFileSystemTypeAsString) DllImportEntry(SystemNative_LockFileRegion) DllImportEntry(SystemNative_LChflags) DllImportEntry(SystemNative_LChflagsCanSetHiddenFlag) diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 6534265085639..6165b770b8288 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -39,6 +39,10 @@ #include #elif HAVE_STATFS_MOUNT // BSD #include +#elif !HAVE_NON_LEGACY_STATFS // SunOS +#include +#include +#include #endif #ifdef _AIX @@ -46,7 +50,7 @@ // Somehow, AIX mangles the definition for this behind a C++ def // Redeclare it here extern int getpeereid(int, uid_t *__restrict__, gid_t *__restrict__); -#elif defined(__sun) +#elif defined(TARGET_SUNOS) #ifndef _KERNEL #define _KERNEL #define UNDEF_KERNEL @@ -1406,10 +1410,28 @@ int64_t SystemNative_GetFileSystemType(intptr_t fd) while ((statfsRes = fstatfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; return statfsRes == -1 ? (int64_t)-1 : (int64_t)statfsArgs.f_type; #else - #error "Platform doesn't support fstatfs" + (void)fd; // unused + return -1; #endif } +char* SystemNative_GetFileSystemTypeAsString(intptr_t fd) +{ +#if !HAVE_NON_LEGACY_STATFS + int statfsRes; + struct statvfs statfsArgs; + while ((statfsRes = fstatvfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; + return statfsRes == -1 ? NULL : strdup(statfsArgs.f_basetype); +#else + (void)fd; // unused + return NULL; +#endif +} + +#if !HAVE_STATFS_VFS && !HAVE_STATFS_MOUNT && HAVE_NON_LEGACY_STATFS + #error "Platform doesn't support fstatfs or fstatvfs" +#endif + int32_t SystemNative_LockFileRegion(intptr_t fd, int64_t offset, int64_t length, int16_t lockType) { int16_t unixLockType = ConvertLockType(lockType); diff --git a/src/libraries/Native/Unix/System.Native/pal_io.h b/src/libraries/Native/Unix/System.Native/pal_io.h index 3f0db054d4368..a4a1c37f83393 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.h +++ b/src/libraries/Native/Unix/System.Native/pal_io.h @@ -722,6 +722,11 @@ PALEXPORT int32_t SystemNative_GetPeerID(intptr_t socket, uid_t* euid); */ PALEXPORT int64_t SystemNative_GetFileSystemType(intptr_t fd); +/** +* Returns file system type name on success, or NULL on error. +*/ +PALEXPORT char* SystemNative_GetFileSystemTypeAsString(intptr_t fd); + /** * Attempts to lock/unlock the region of the file "fd" specified by the offset and length. lockType * can be set to F_UNLCK (2) for unlock or F_WRLCK (3) for lock. diff --git a/src/libraries/Native/Unix/System.Native/pal_memory.c b/src/libraries/Native/Unix/System.Native/pal_memory.c index fd6a34de2c39a..eb76650f47b43 100644 --- a/src/libraries/Native/Unix/System.Native/pal_memory.c +++ b/src/libraries/Native/Unix/System.Native/pal_memory.c @@ -10,10 +10,15 @@ #if HAVE_MALLOC_SIZE #include + #define MALLOC_SIZE(s) malloc_size(s) #elif HAVE_MALLOC_USABLE_SIZE #include + #define MALLOC_SIZE(s) malloc_usable_size(s) #elif HAVE_MALLOC_USABLE_SIZE_NP #include + #define MALLOC_SIZE(s) malloc_usable_size(s) +#elif defined(TARGET_SUNOS) + #define MALLOC_SIZE(s) (*((size_t*)(s)-1)) #else #error "Platform doesn't support malloc_usable_size or malloc_size" #endif @@ -67,13 +72,7 @@ void SystemNative_Free(void* ptr) uintptr_t SystemNative_GetUsableSize(void* ptr) { -#if HAVE_MALLOC_SIZE - return malloc_size(ptr); -#elif HAVE_MALLOC_USABLE_SIZE || HAVE_MALLOC_USABLE_SIZE_NP - return malloc_usable_size(ptr); -#else - #error "Platform doesn't support malloc_usable_size or malloc_size" -#endif + return MALLOC_SIZE(ptr); } void* SystemNative_Malloc(uintptr_t size) diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj index d07e89ec979be..c27013f3299ae 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj @@ -3,6 +3,7 @@ true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser enable + true @@ -58,6 +59,12 @@ Link="Common\Interop\Unix\Interop.Errors.cs" /> + + true true true + true $(DefineConstants);BIGENDIAN @@ -1943,6 +1944,12 @@ Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs + + Common\Interop\Unix\System.Native\Interop.FLock.cs @@ -2324,4 +2331,4 @@ - \ No newline at end of file + diff --git a/src/native/corehost/bundle/extractor.cpp b/src/native/corehost/bundle/extractor.cpp index 4e6f439083448..60c2d5389c2f6 100644 --- a/src/native/corehost/bundle/extractor.cpp +++ b/src/native/corehost/bundle/extractor.cpp @@ -7,6 +7,10 @@ #include "pal.h" #include "utils.h" +#ifdef __sun +#include +#endif + #if defined(NATIVE_LIBS_EMBEDDED) extern "C" { From 16664f55ed99ea98569a460c8bc945ffd4184015 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Fri, 30 Jul 2021 17:56:52 +0300 Subject: [PATCH 2/8] Add back build validation in GetFileSystemType --- src/libraries/Native/Unix/System.Native/pal_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 6165b770b8288..49bdc4179f2a5 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -1409,9 +1409,11 @@ int64_t SystemNative_GetFileSystemType(intptr_t fd) // which got deprecated in macOS 10.6, in favor of statfs while ((statfsRes = fstatfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; return statfsRes == -1 ? (int64_t)-1 : (int64_t)statfsArgs.f_type; -#else +#elif defined(TARGET_SUNOS // we use statvfs (see SystemNative_GetFileSystemTypeAsString) on SunOS (void)fd; // unused return -1; +#else + #error "Platform doesn't support fstatfs" #endif } From 181cf8719957175e8ec0de9a24bc1f3f50406b5a Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:53:17 +0300 Subject: [PATCH 3/8] Update src/libraries/Native/Unix/System.Native/pal_io.c Co-authored-by: Stephen Toub --- src/libraries/Native/Unix/System.Native/pal_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 49bdc4179f2a5..61cf3f2a8da72 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -1409,7 +1409,7 @@ int64_t SystemNative_GetFileSystemType(intptr_t fd) // which got deprecated in macOS 10.6, in favor of statfs while ((statfsRes = fstatfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; return statfsRes == -1 ? (int64_t)-1 : (int64_t)statfsArgs.f_type; -#elif defined(TARGET_SUNOS // we use statvfs (see SystemNative_GetFileSystemTypeAsString) on SunOS +#elif defined(TARGET_SUNOS) // we use statvfs (see SystemNative_GetFileSystemTypeAsString) on SunOS (void)fd; // unused return -1; #else From 55e2aef5c0dbc594a625c979f210f6c760cab3dd Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Sat, 31 Jul 2021 00:20:30 +0300 Subject: [PATCH 4/8] Add back some illumos/solaris filesystems --- .../System.Native/Interop.UnixFileSystemTypes.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs index 4c9f0f678e710..6e9db2ace4744 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs @@ -35,8 +35,11 @@ internal enum UnixFileSystemTypes : long coda = 0x73757245, coherent = 0x012FF7B7, configfs = 0x62656570, + cpuset = 0x01021994, // same as tmpfs cramfs = 0x28CD3D45, + ctfs = 0x01021994, // same as tmpfs debugfs = 0x64626720, + dev = 0x1373, // same as devfs devfs = 0x1373, devpts = 0x1CD1, ecryptfs = 0xF15F, @@ -78,6 +81,7 @@ internal enum UnixFileSystemTypes : long minix2 = 0x2468, /* minix V2 */ minix2v2 = 0x2478, /* MINIX V2, 30 char names */ minix3 = 0x4D5A, + mntfs = 0x01021994, // same as tmpfs mqueue = 0x19800202, msdos = 0x4D44, nfs = 0x6969, @@ -85,8 +89,9 @@ internal enum UnixFileSystemTypes : long nilfs = 0x3434, novell = 0x564C, ntfs = 0x5346544E, - openprom = 0x9FA1, + objfs = 0x01021994, // same as tmpfs ocfs2 = 0x7461636F, + openprom = 0x9FA1, omfs = 0xC2993D87, overlay = 0x794C7630, overlayfs = 0x794C764F, @@ -104,6 +109,8 @@ internal enum UnixFileSystemTypes : long samba = 0x517B, securityfs = 0x73636673, selinux = 0xF97CFF8C, + sffs = 0x786F4256, // same as vboxfs + sharefs = 0x01021994, // same as tmpfs smb = 0x517B, smb2 = 0xFE534D42, sockfs = 0x534F434B, @@ -119,6 +126,8 @@ internal enum UnixFileSystemTypes : long ufs2 = 0x19540119, usbdevice = 0x9FA2, v9fs = 0x01021997, + vagrant = 0x786F4256, // same as vboxfs + vboxfs = 0x786F4256, vmhgfs = 0xBACBACBC, vxfs = 0xA501FCF5, vzfs = 0x565A4653, @@ -126,6 +135,7 @@ internal enum UnixFileSystemTypes : long xenix = 0x012FF7B4, xfs = 0x58465342, xia = 0x012FD16D, + udev = 0x01021994, // same as tmpfs zfs = 0x2FC12FC1, } } From 3fe649cd07684677186d3e38694dbe63ffbbdfaf Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Sat, 31 Jul 2021 02:59:42 +0300 Subject: [PATCH 5/8] Sync DriveType and UnixFileSystemTypes --- .../Unix/System.Native/Interop.MountPoints.FormatInfo.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs index 05d74c84e789d..15d6aa3c2f147 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs @@ -165,6 +165,7 @@ private static DriveType GetDriveType(string fileSystemName) case "qnx6": case "reiserfs": case "rpc_pipefs": + case "sffs": case "smackfs": case "squashfs": case "swap": @@ -179,6 +180,8 @@ private static DriveType GetDriveType(string fileSystemName) case "umsdos": case "umview-mod-umfuseext2": case "v9fs": + case "vagrant": + case "vboxfs": case "vxfs": case "vxfs_olt": case "vzfs": @@ -304,6 +307,7 @@ private static DriveType GetDriveType(string fileSystemName) case "sockfs": case "sysfs": case "tmpfs": + case "udev": case "usbdev": case "usbdevfs": return DriveType.Ram; @@ -314,8 +318,8 @@ private static DriveType GetDriveType(string fileSystemName) case "vfat": return DriveType.Removable; - // Categorize as "Unknown" everything else not explicitly - // recognized as a particular drive type. + // Categorize as "Unknown" everything else not explicitly + // recognized as a particular drive type. default: return DriveType.Unknown; } From 02c8670e76e5bb60b0935fd729996dfdb27f83e0 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:50:49 +0300 Subject: [PATCH 6/8] Add FS type mapping for statvfs case --- src/coreclr/minipal/Unix/doublemapping.cpp | 10 +- .../Interop.UnixFileSystemTypes.cs | 13 ++ .../Interop.UnixFileSystemTypes.statfs.cs | 21 --- .../Interop.UnixFileSystemTypes.statvfs.cs | 18 --- .../Native/Unix/System.Native/entrypoints.c | 1 - .../Native/Unix/System.Native/pal_io.c | 146 +++++++++++++++--- .../Native/Unix/System.Native/pal_io.h | 5 - .../src/System.IO.FileSystem.DriveInfo.csproj | 7 - .../System.Private.CoreLib.Shared.projitems | 7 - 9 files changed, 146 insertions(+), 82 deletions(-) delete mode 100644 src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs delete mode 100644 src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs diff --git a/src/coreclr/minipal/Unix/doublemapping.cpp b/src/coreclr/minipal/Unix/doublemapping.cpp index 1b70d35a070fd..6c0c9f47cb0b8 100644 --- a/src/coreclr/minipal/Unix/doublemapping.cpp +++ b/src/coreclr/minipal/Unix/doublemapping.cpp @@ -42,11 +42,11 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu #ifdef TARGET_FREEBSD int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU); #elif defined(TARGET_SUNOS) // has POSIX implementation - char anonName[24]; - sprintf(anonName, "/shm-dotnet-%d", getpid()); - anonName[sizeof(anonName) - 1] = '\0'; - shm_unlink(anonName); - int fd = shm_open(anonName, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); + char name[24]; + sprintf(name, "/shm-dotnet-%d", getpid()); + anonName[sizeof(name) - 1] = '\0'; + shm_unlink(name); + int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); #else // TARGET_FREEBSD int fd = memfd_create("doublemapper", MFD_CLOEXEC); #endif // TARGET_FREEBSD diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs index 6e9db2ace4744..892e5ccaaed33 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs @@ -1,6 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; + internal static partial class Interop { internal static partial class Sys @@ -138,5 +141,15 @@ internal enum UnixFileSystemTypes : long udev = 0x01021994, // same as tmpfs zfs = 0x2FC12FC1, } + + [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")] + private static extern long GetFileSystemType(SafeFileHandle fd); + + internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) + { + long fstatfsResult = GetFileSystemType(fd); + fileSystemType = (UnixFileSystemTypes)fstatfsResult; + return fstatfsResult != -1; + } } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs deleted file mode 100644 index 6d01a5009eed0..0000000000000 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statfs.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")] - private static extern long GetFileSystemType(SafeFileHandle fd); - - internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) - { - long fstatfsResult = GetFileSystemType(fd); - fileSystemType = (UnixFileSystemTypes)fstatfsResult; - return fstatfsResult != -1; - } - } -} diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs deleted file mode 100644 index 294b194d569d9..0000000000000 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.statvfs.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemTypeAsString")] - private static extern string GetFileSystemTypeAsString(SafeFileHandle fd); - - internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) => - Enum.TryParse(GetFileSystemTypeAsString(fd), out fileSystemType); - } -} diff --git a/src/libraries/Native/Unix/System.Native/entrypoints.c b/src/libraries/Native/Unix/System.Native/entrypoints.c index 26d06b196fd57..c8b678ec08340 100644 --- a/src/libraries/Native/Unix/System.Native/entrypoints.c +++ b/src/libraries/Native/Unix/System.Native/entrypoints.c @@ -105,7 +105,6 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_RealPath) DllImportEntry(SystemNative_GetPeerID) DllImportEntry(SystemNative_GetFileSystemType) - DllImportEntry(SystemNative_GetFileSystemTypeAsString) DllImportEntry(SystemNative_LockFileRegion) DllImportEntry(SystemNative_LChflags) DllImportEntry(SystemNative_LChflagsCanSetHiddenFlag) diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 61cf3f2a8da72..2cf1f2cf0161c 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -1409,30 +1409,140 @@ int64_t SystemNative_GetFileSystemType(intptr_t fd) // which got deprecated in macOS 10.6, in favor of statfs while ((statfsRes = fstatfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; return statfsRes == -1 ? (int64_t)-1 : (int64_t)statfsArgs.f_type; -#elif defined(TARGET_SUNOS) // we use statvfs (see SystemNative_GetFileSystemTypeAsString) on SunOS - (void)fd; // unused - return -1; -#else - #error "Platform doesn't support fstatfs" -#endif -} - -char* SystemNative_GetFileSystemTypeAsString(intptr_t fd) -{ -#if !HAVE_NON_LEGACY_STATFS +#elif !HAVE_NON_LEGACY_STATFS int statfsRes; struct statvfs statfsArgs; while ((statfsRes = fstatvfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ; - return statfsRes == -1 ? NULL : strdup(statfsArgs.f_basetype); -#else - (void)fd; // unused - return NULL; -#endif -} + if (statfsRes == -1) return (int64_t)-1; + + int64_t result = -1; + + if (strcmp(statfsArgs.f_basetype, "adfs") == 0) result = 0xADF5; + else if (strcmp(statfsArgs.f_basetype, "affs") == 0) result = 0xADFF; + else if (strcmp(statfsArgs.f_basetype, "afs") == 0) result = 0x5346414F; + else if (strcmp(statfsArgs.f_basetype, "anoninode") == 0) result = 0x09041934; + else if (strcmp(statfsArgs.f_basetype, "aufs") == 0) result = 0x61756673; + else if (strcmp(statfsArgs.f_basetype, "autofs") == 0) result = 0x0187; + else if (strcmp(statfsArgs.f_basetype, "autofs4") == 0) result = 0x6D4A556D; + else if (strcmp(statfsArgs.f_basetype, "befs") == 0) result = 0x42465331; + else if (strcmp(statfsArgs.f_basetype, "bdevfs") == 0) result = 0x62646576; + else if (strcmp(statfsArgs.f_basetype, "bfs") == 0) result = 0x1BADFACE; + else if (strcmp(statfsArgs.f_basetype, "binfmt_misc") == 0) result = 0x42494E4D; + else if (strcmp(statfsArgs.f_basetype, "bootfs") == 0) result = 0xA56D3FF9; + else if (strcmp(statfsArgs.f_basetype, "btrfs") == 0) result = 0x9123683E; + else if (strcmp(statfsArgs.f_basetype, "ceph") == 0) result = 0x00C36400; + else if (strcmp(statfsArgs.f_basetype, "cgroupfs") == 0) result = 0x0027E0EB; + else if (strcmp(statfsArgs.f_basetype, "cgroup2fs") == 0) result = 0x63677270; + else if (strcmp(statfsArgs.f_basetype, "cifs") == 0) result = 0xFF534D42; + else if (strcmp(statfsArgs.f_basetype, "coda") == 0) result = 0x73757245; + else if (strcmp(statfsArgs.f_basetype, "coherent") == 0) result = 0x012FF7B7; + else if (strcmp(statfsArgs.f_basetype, "configfs") == 0) result = 0x62656570; + else if (strcmp(statfsArgs.f_basetype, "cpuset") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "cramfs") == 0) result = 0x28CD3D45; + else if (strcmp(statfsArgs.f_basetype, "ctfs") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "debugfs") == 0) result = 0x64626720; + else if (strcmp(statfsArgs.f_basetype, "dev") == 0) result = 0x1373; + else if (strcmp(statfsArgs.f_basetype, "devfs") == 0) result = 0x1373; + else if (strcmp(statfsArgs.f_basetype, "devpts") == 0) result = 0x1CD1; + else if (strcmp(statfsArgs.f_basetype, "ecryptfs") == 0) result = 0xF15F; + else if (strcmp(statfsArgs.f_basetype, "efs") == 0) result = 0x00414A53; + else if (strcmp(statfsArgs.f_basetype, "exofs") == 0) result = 0x5DF5; + else if (strcmp(statfsArgs.f_basetype, "ext") == 0) result = 0x137D; + else if (strcmp(statfsArgs.f_basetype, "ext2_old") == 0) result = 0xEF51; + else if (strcmp(statfsArgs.f_basetype, "ext2") == 0) result = 0xEF53; + else if (strcmp(statfsArgs.f_basetype, "ext3") == 0) result = 0xEF53; + else if (strcmp(statfsArgs.f_basetype, "ext4") == 0) result = 0xEF53; + else if (strcmp(statfsArgs.f_basetype, "fat") == 0) result = 0x4006; + else if (strcmp(statfsArgs.f_basetype, "fd") == 0) result = 0xF00D1E; + else if (strcmp(statfsArgs.f_basetype, "fhgfs") == 0) result = 0x19830326; + else if (strcmp(statfsArgs.f_basetype, "fuse") == 0) result = 0x65735546; + else if (strcmp(statfsArgs.f_basetype, "fuseblk") == 0) result = 0x65735546; + else if (strcmp(statfsArgs.f_basetype, "fusectl") == 0) result = 0x65735543; + else if (strcmp(statfsArgs.f_basetype, "futexfs") == 0) result = 0x0BAD1DEA; + else if (strcmp(statfsArgs.f_basetype, "gfsgfs2") == 0) result = 0x1161970; + else if (strcmp(statfsArgs.f_basetype, "gfs2") == 0) result = 0x01161970; + else if (strcmp(statfsArgs.f_basetype, "gpfs") == 0) result = 0x47504653; + else if (strcmp(statfsArgs.f_basetype, "hfs") == 0) result = 0x4244; + else if (strcmp(statfsArgs.f_basetype, "hfsplus") == 0) result = 0x482B; + else if (strcmp(statfsArgs.f_basetype, "hpfs") == 0) result = 0xF995E849; + else if (strcmp(statfsArgs.f_basetype, "hugetlbfs") == 0) result = 0x958458F6; + else if (strcmp(statfsArgs.f_basetype, "inodefs") == 0) result = 0x11307854; + else if (strcmp(statfsArgs.f_basetype, "inotifyfs") == 0) result = 0x2BAD1DEA; + else if (strcmp(statfsArgs.f_basetype, "isofs") == 0) result = 0x9660; + else if (strcmp(statfsArgs.f_basetype, "jffs") == 0) result = 0x07C0; + else if (strcmp(statfsArgs.f_basetype, "jffs2") == 0) result = 0x72B6; + else if (strcmp(statfsArgs.f_basetype, "jfs") == 0) result = 0x3153464A; + else if (strcmp(statfsArgs.f_basetype, "kafs") == 0) result = 0x6B414653; + else if (strcmp(statfsArgs.f_basetype, "lofs") == 0) result = 0xEF53; + else if (strcmp(statfsArgs.f_basetype, "logfs") == 0) result = 0xC97E8168; + else if (strcmp(statfsArgs.f_basetype, "lustre") == 0) result = 0x0BD00BD0; + else if (strcmp(statfsArgs.f_basetype, "minix_old") == 0) result = 0x137F; + else if (strcmp(statfsArgs.f_basetype, "minix") == 0) result = 0x138F; + else if (strcmp(statfsArgs.f_basetype, "minix2") == 0) result = 0x2468; + else if (strcmp(statfsArgs.f_basetype, "minix2v2") == 0) result = 0x2478; + else if (strcmp(statfsArgs.f_basetype, "minix3") == 0) result = 0x4D5A; + else if (strcmp(statfsArgs.f_basetype, "mntfs") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "mqueue") == 0) result = 0x19800202; + else if (strcmp(statfsArgs.f_basetype, "msdos") == 0) result = 0x4D44; + else if (strcmp(statfsArgs.f_basetype, "nfs") == 0) result = 0x6969; + else if (strcmp(statfsArgs.f_basetype, "nfsd") == 0) result = 0x6E667364; + else if (strcmp(statfsArgs.f_basetype, "nilfs") == 0) result = 0x3434; + else if (strcmp(statfsArgs.f_basetype, "novell") == 0) result = 0x564C; + else if (strcmp(statfsArgs.f_basetype, "ntfs") == 0) result = 0x5346544E; + else if (strcmp(statfsArgs.f_basetype, "objfs") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "ocfs2") == 0) result = 0x7461636F; + else if (strcmp(statfsArgs.f_basetype, "openprom") == 0) result = 0x9FA1; + else if (strcmp(statfsArgs.f_basetype, "omfs") == 0) result = 0xC2993D87; + else if (strcmp(statfsArgs.f_basetype, "overlay") == 0) result = 0x794C7630; + else if (strcmp(statfsArgs.f_basetype, "overlayfs") == 0) result = 0x794C764F; + else if (strcmp(statfsArgs.f_basetype, "panfs") == 0) result = 0xAAD7AAEA; + else if (strcmp(statfsArgs.f_basetype, "pipefs") == 0) result = 0x50495045; + else if (strcmp(statfsArgs.f_basetype, "proc") == 0) result = 0x9FA0; + else if (strcmp(statfsArgs.f_basetype, "pstorefs") == 0) result = 0x6165676C; + else if (strcmp(statfsArgs.f_basetype, "qnx4") == 0) result = 0x002F; + else if (strcmp(statfsArgs.f_basetype, "qnx6") == 0) result = 0x68191122; + else if (strcmp(statfsArgs.f_basetype, "ramfs") == 0) result = 0x858458F6; + else if (strcmp(statfsArgs.f_basetype, "reiserfs") == 0) result = 0x52654973; + else if (strcmp(statfsArgs.f_basetype, "romfs") == 0) result = 0x7275; + else if (strcmp(statfsArgs.f_basetype, "rootfs") == 0) result = 0x53464846; + else if (strcmp(statfsArgs.f_basetype, "rpc_pipefs") == 0) result = 0x67596969; + else if (strcmp(statfsArgs.f_basetype, "samba") == 0) result = 0x517B; + else if (strcmp(statfsArgs.f_basetype, "securityfs") == 0) result = 0x73636673; + else if (strcmp(statfsArgs.f_basetype, "selinux") == 0) result = 0xF97CFF8C; + else if (strcmp(statfsArgs.f_basetype, "sffs") == 0) result = 0x786F4256; + else if (strcmp(statfsArgs.f_basetype, "sharefs") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "smb") == 0) result = 0x517B; + else if (strcmp(statfsArgs.f_basetype, "smb2") == 0) result = 0xFE534D42; + else if (strcmp(statfsArgs.f_basetype, "sockfs") == 0) result = 0x534F434B; + else if (strcmp(statfsArgs.f_basetype, "squashfs") == 0) result = 0x73717368; + else if (strcmp(statfsArgs.f_basetype, "sysfs") == 0) result = 0x62656572; + else if (strcmp(statfsArgs.f_basetype, "sysv2") == 0) result = 0x012FF7B6; + else if (strcmp(statfsArgs.f_basetype, "sysv4") == 0) result = 0x012FF7B5; + else if (strcmp(statfsArgs.f_basetype, "tmpfs") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "ubifs") == 0) result = 0x24051905; + else if (strcmp(statfsArgs.f_basetype, "udf") == 0) result = 0x15013346; + else if (strcmp(statfsArgs.f_basetype, "ufs") == 0) result = 0x00011954; + else if (strcmp(statfsArgs.f_basetype, "ufscigam") == 0) result = 0x54190100; + else if (strcmp(statfsArgs.f_basetype, "ufs2") == 0) result = 0x19540119; + else if (strcmp(statfsArgs.f_basetype, "usbdevice") == 0) result = 0x9FA2; + else if (strcmp(statfsArgs.f_basetype, "v9fs") == 0) result = 0x01021997; + else if (strcmp(statfsArgs.f_basetype, "vagrant") == 0) result = 0x786F4256; + else if (strcmp(statfsArgs.f_basetype, "vboxfs") == 0) result = 0x786F4256; + else if (strcmp(statfsArgs.f_basetype, "vmhgfs") == 0) result = 0xBACBACBC; + else if (strcmp(statfsArgs.f_basetype, "vxfs") == 0) result = 0xA501FCF5; + else if (strcmp(statfsArgs.f_basetype, "vzfs") == 0) result = 0x565A4653; + else if (strcmp(statfsArgs.f_basetype, "xenfs") == 0) result = 0xABBA1974; + else if (strcmp(statfsArgs.f_basetype, "xenix") == 0) result = 0x012FF7B4; + else if (strcmp(statfsArgs.f_basetype, "xfs") == 0) result = 0x58465342; + else if (strcmp(statfsArgs.f_basetype, "xia") == 0) result = 0x012FD16D; + else if (strcmp(statfsArgs.f_basetype, "udev") == 0) result = 0x01021994; + else if (strcmp(statfsArgs.f_basetype, "zfs") == 0) result = 0x2FC12FC1; -#if !HAVE_STATFS_VFS && !HAVE_STATFS_MOUNT && HAVE_NON_LEGACY_STATFS + return result; +#else #error "Platform doesn't support fstatfs or fstatvfs" #endif +} int32_t SystemNative_LockFileRegion(intptr_t fd, int64_t offset, int64_t length, int16_t lockType) { diff --git a/src/libraries/Native/Unix/System.Native/pal_io.h b/src/libraries/Native/Unix/System.Native/pal_io.h index a4a1c37f83393..3f0db054d4368 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.h +++ b/src/libraries/Native/Unix/System.Native/pal_io.h @@ -722,11 +722,6 @@ PALEXPORT int32_t SystemNative_GetPeerID(intptr_t socket, uid_t* euid); */ PALEXPORT int64_t SystemNative_GetFileSystemType(intptr_t fd); -/** -* Returns file system type name on success, or NULL on error. -*/ -PALEXPORT char* SystemNative_GetFileSystemTypeAsString(intptr_t fd); - /** * Attempts to lock/unlock the region of the file "fd" specified by the offset and length. lockType * can be set to F_UNLCK (2) for unlock or F_WRLCK (3) for lock. diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj index c27013f3299ae..d07e89ec979be 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj @@ -3,7 +3,6 @@ true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser enable - true @@ -59,12 +58,6 @@ Link="Common\Interop\Unix\Interop.Errors.cs" /> - - true true true - true $(DefineConstants);BIGENDIAN @@ -1944,12 +1943,6 @@ Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs - - Common\Interop\Unix\System.Native\Interop.FLock.cs From 2d8972cfdc16712857839685bbcb062bbfa65497 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Tue, 3 Aug 2021 20:39:55 +0300 Subject: [PATCH 7/8] Revert now-unchanged csproj lineending --- .../src/System.Private.CoreLib.Shared.projitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index a687caddc2617..df824ab16bab3 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -2326,4 +2326,4 @@ - + \ No newline at end of file From 71b1d524468a6d140abd519a9d1ad66a7ea52bbf Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 4 Aug 2021 15:46:14 +0300 Subject: [PATCH 8/8] Update src/libraries/Native/Unix/System.Native/pal_io.c Co-authored-by: Adam Sitnik --- src/libraries/Native/Unix/System.Native/pal_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 2cf1f2cf0161c..51d841ffc55bd 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -1538,6 +1538,7 @@ int64_t SystemNative_GetFileSystemType(intptr_t fd) else if (strcmp(statfsArgs.f_basetype, "udev") == 0) result = 0x01021994; else if (strcmp(statfsArgs.f_basetype, "zfs") == 0) result = 0x2FC12FC1; + assert(result != -1); return result; #else #error "Platform doesn't support fstatfs or fstatvfs"