Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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
{
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_FileSystemSupportsLocking")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool FileSystemSupportsLocking(SafeFileHandle fd, LockOperations lockOperation, [MarshalAs(UnmanagedType.Bool)] bool accessWrite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ internal static partial class Interop
{
internal static partial class Sys
{
#if DEBUG
static Sys()
{
foreach (string name in Enum.GetNames<UnixFileSystemTypes>())
{
System.Diagnostics.Debug.Assert(GetDriveType(name) != DriveType.Unknown,
$"Expected {nameof(UnixFileSystemTypes)}.{name} to have an entry in {nameof(GetDriveType)}.");
}
}
#endif

private const int MountPointFormatBufferSizeInBytes = 32;

[StructLayout(LayoutKind.Sequential)]
Expand Down Expand Up @@ -60,8 +49,7 @@ internal static unsafe Error GetFileSystemTypeNameForMountPoint(string name, out
int result = GetFileSystemTypeNameForMountPoint(name, formatBuffer, MountPointFormatBufferSizeInBytes, &formatType);
if (result == 0)
{
format = formatType == -1 ? Utf8StringMarshaller.ConvertToManaged(formatBuffer)!
: (Enum.GetName(typeof(UnixFileSystemTypes), formatType) ?? "");
format = formatType == -1 ? Utf8StringMarshaller.ConvertToManaged(formatBuffer)! : "";
return Error.SUCCESS;
}
else
Expand Down Expand Up @@ -93,7 +81,6 @@ private static DriveType GetDriveType(string fileSystemName)
// This list is based primarily on "man fs", "man mount", "mntent.h", "/proc/filesystems", coreutils "stat.c",
// and "wiki.debian.org/FileSystem". It can be extended over time as we find additional file systems that should
// be recognized as a particular drive type.
// Keep this in sync with the UnixFileSystemTypes enum in Interop.UnixFileSystemTypes.cs
switch (fileSystemName)
{
case "cddafs":
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions src/libraries/Common/tests/Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@
Link="System\PasteArguments.Windows.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'">
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs"
Link="Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs" />
<Compile Include="Tests\System\IO\PathInternal.Unix.Tests.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.Unix.cs"
Link="System\IO\PathInternal.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@
Link="Common\Interop\Linux\procfs\Interop.ProcMountInfo.cs" />
<Compile Include="$(CommonPath)Interop\Linux\procfs\Interop.ProcMountInfo.TryParseMountInfoLine.cs"
Link="Common\Interop\Linux\procfs\Interop.ProcMountInfo.TryParseMountInfoLine.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs"
Link="Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs" />
<Compile Include="$(CommonPath)Interop\Linux\procfs\Interop.ProcFsStat.cs"
Link="Common\Interop\Linux\Interop.ProcFsStat.cs" />
<Compile Include="$(CommonPath)Interop\Linux\procfs\Interop.ProcFsStat.ParseMapModules.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs"
Link="Common\Interop\Unix\Interop.UnixFileSystemTypes.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.IOErrors.cs"
Link="Common\Interop\Unix\Interop.IOErrors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.PathConf.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,30 +462,8 @@ private bool CanLockTheFile(Interop.Sys.LockOperations lockOperation, FileAccess
{
return false;
}
else if (lockOperation == Interop.Sys.LockOperations.LOCK_EX)
{
return true; // LOCK_EX is always OK
}
else if ((access & FileAccess.Write) == 0)
{
return true; // LOCK_SH is always OK when reading
}

if (!Interop.Sys.TryGetFileSystemType(this, out Interop.Sys.UnixFileSystemTypes unixFileSystemType))
{
return false; // assume we should not acquire the lock if we don't know the File System
}

switch (unixFileSystemType)
{
case Interop.Sys.UnixFileSystemTypes.nfs: // #44546
case Interop.Sys.UnixFileSystemTypes.smb:
case Interop.Sys.UnixFileSystemTypes.smb2: // #53182
case Interop.Sys.UnixFileSystemTypes.cifs:
return false; // LOCK_SH is not OK when writing to NFS, CIFS or SMB
default:
return true; // in all other situations it should be OK
}
return Interop.Sys.FileSystemSupportsLocking(this, lockOperation, accessWrite: (access & FileAccess.Write) != 0);
}

private void FStatCheckIO(string path, ref Interop.Sys.FileStatus status, ref bool statusHasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,8 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ErrNo.cs">
<Link>Common\Interop\Unix\System.Native\Interop.ErrNo.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs">
<Link>Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs</Link>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.FileSystemSupportsLocking.cs">
<Link>Common\Interop\Unix\System.Native\Interop.FileSystemSupportsLocking.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.FLock.cs">
<Link>Common\Interop\Unix\System.Native\Interop.FLock.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@
Link="Common\Interop\Unix\System.Native\Interop.MountPoints.FormatInfo.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.RealPath.cs"
Link="Common\Interop\Unix\Interop.RealPath.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs"
Link="Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/native/libs/System.Native/entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_INotifyRemoveWatch)
DllImportEntry(SystemNative_RealPath)
DllImportEntry(SystemNative_GetPeerID)
DllImportEntry(SystemNative_GetFileSystemType)
DllImportEntry(SystemNative_FileSystemSupportsLocking)
DllImportEntry(SystemNative_LockFileRegion)
DllImportEntry(SystemNative_LChflags)
DllImportEntry(SystemNative_LChflagsCanSetHiddenFlag)
Expand Down
Loading
Loading