Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs (C#)

Code before:
                                                        : SR.IO_DiskFull_Path_AllocationSize,
                                            path, preallocationSize));
                }
            }

            return true;
        }

        private bool CanLockTheFile(Interop.Sys.LockOperations lockOperation, FileAccess access)
        {
            Debug.Assert(lockOperation == Interop.Sys.LockOperations.LOCK_EX || lockOperation == Interop.Sys.LockOperations.LOCK_SH);

            if (DisableFileLocking)
            {
                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
            }

            return Interop.Sys.FileSystemSupportsLocking(this);
        }

        private void FStatCheckIO(string path, ref Interop.Sys.FileStatus status, ref bool statusHasValue)
        {
            if (!statusHasValue)
            {
                if (Interop.Sys.FStat(this, out status) != 0)
                {
                    Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
                    throw Interop.GetExceptionForIoErrno(error, path);
                }

                statusHasValue = true;
            }
        }

        private bool GetCanSeek()
        {
            Debug.Assert(!IsClosed);
            Debug.Assert(!IsInvalid);

            NullableBool canSeek = _canSeek;
            if (canSeek == NullableBool.Undefined)
            {
                _canSeek = canSeek = Interop.Sys.LSeek(this, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0 ? NullableBool.True : NullableBool.False;

Review comment (suggestion):
```suggestion
            // LOCK_SH does not work well for write access in some file systems. For example, writes are dropped silently.
            // We try to detect the problematic cases and disable use of  LOCK_SH for write access for them.
            // See https://github.com/dotnet/runtime/issues/44546 and https://github.com/dotnet/runtime/issues/53182
            return Interop.Sys.FileSystemSupportsLocking(this);
```

Code after:
                                                        : SR.IO_DiskFull_Path_AllocationSize,
                                            path, preallocationSize));
                }
            }

            return true;
        }

        private bool CanLockTheFile(Interop.Sys.LockOperations lockOperation, FileAccess access)
        {
            Debug.Assert(lockOperation == Interop.Sys.LockOperations.LOCK_EX || lockOperation == Interop.Sys.LockOperations.LOCK_SH);

            if (DisableFileLocking)
            {
                return false;
            }

            return Interop.Sys.FileSystemSupportsLocking(this, lockOperation, accessWrite: (access & FileAccess.Write) != 0);
        }

        private void FStatCheckIO(string path, ref Interop.Sys.FileStatus status, ref bool statusHasValue)
        {
            if (!statusHasValue)
            {
                if (Interop.Sys.FStat(this, out status) != 0)
                {
                    Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
                    throw Interop.GetExceptionForIoErrno(error, path);
                }

                statusHasValue = true;
            }
        }

        private bool GetCanSeek()
        {
            Debug.Assert(!IsClosed);
            Debug.Assert(!IsInvalid);

            NullableBool canSeek = _canSeek;
            if (canSeek == NullableBool.Undefined)
            {
                _canSeek = canSeek = Interop.Sys.LSeek(this, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0 ? NullableBool.True : NullableBool.False;
            }

            return canSeek == NullableBool.True;
        }

        internal long GetFileLength()
        {
            int result = Interop.Sys.FStat(this, out Interop.Sys.FileStatus status);