LibraryImports.g.cs (61)
6277internal static partial int Access(string path, global::Interop.Sys.AccessMode mode)
6306static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.AccessMode __mode_native);
6660internal static partial int FLock(global::Microsoft.Win32.SafeHandles.SafeFileHandle fd, global::Interop.Sys.LockOperations operation)
6689static extern unsafe int __PInvoke(nint __fd_native, global::Interop.Sys.LockOperations __operation_native);
6698internal static partial int FLock(nint fd, global::Interop.Sys.LockOperations operation)
6712static extern unsafe int __PInvoke(nint __fd_native, global::Interop.Sys.LockOperations __operation_native);
6797internal static partial double GetCpuUtilization(ref global::Interop.Sys.ProcessCpuInformation previousCpuInfo)
6801fixed (global::Interop.Sys.ProcessCpuInformation* __previousCpuInfo_native = &previousCpuInfo)
6809static extern unsafe double __PInvoke(global::Interop.Sys.ProcessCpuInformation* __previousCpuInfo_native);
7203internal static partial int LockFileRegion(global::System.Runtime.InteropServices.SafeHandle fd, long offset, long length, global::Interop.Sys.LockType lockType)
7232static extern unsafe int __PInvoke(nint __fd_native, long __offset_native, long __length_native, global::Interop.Sys.LockType __lockType_native);
7327internal static partial long LSeek(global::Microsoft.Win32.SafeHandles.SafeFileHandle fd, long offset, global::Interop.Sys.SeekWhence whence)
7356static extern unsafe long __PInvoke(nint __fd_native, long __offset_native, global::Interop.Sys.SeekWhence __whence_native);
7492internal static partial nint MMap(nint addr, ulong len, global::Interop.Sys.MemoryMappedProtections prot, global::Interop.Sys.MemoryMappedFlags flags, global::Microsoft.Win32.SafeHandles.SafeFileHandle fd, long offset)
7521static extern unsafe nint __PInvoke(nint __addr_native, ulong __len_native, global::Interop.Sys.MemoryMappedProtections __prot_native, global::Interop.Sys.MemoryMappedFlags __flags_native, nint __fd_native, long __offset_native);
7530internal static partial nint MMap(nint addr, ulong len, global::Interop.Sys.MemoryMappedProtections prot, global::Interop.Sys.MemoryMappedFlags flags, nint fd, long offset)
7544static extern unsafe nint __PInvoke(nint __addr_native, ulong __len_native, global::Interop.Sys.MemoryMappedProtections __prot_native, global::Interop.Sys.MemoryMappedFlags __flags_native, nint __fd_native, long __offset_native);
7584internal static partial global::Microsoft.Win32.SafeHandles.SafeFileHandle Open(string filename, global::Interop.Sys.OpenFlags flags, int mode)
7628static extern unsafe nint __PInvoke(byte* __filename_native, global::Interop.Sys.OpenFlags __flags_native, int __mode_native);
7637private static partial int PathConf(string path, global::Interop.Sys.PathConfName name)
7666static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.PathConfName __name_native);
7675internal static partial int PosixFAdvise(global::Microsoft.Win32.SafeHandles.SafeFileHandle fd, long offset, long length, global::Interop.Sys.FileAdvice advice)
7700static extern unsafe int __PInvoke(nint __fd_native, long __offset_native, long __length_native, global::Interop.Sys.FileAdvice __advice_native);
7785internal static unsafe partial long PReadV(global::System.Runtime.InteropServices.SafeHandle fd, global::Interop.Sys.IOVector* vectors, int vectorCount, long fileOffset)
7814static extern unsafe long __PInvoke(nint __fd_native, global::Interop.Sys.IOVector* __vectors_native, int __vectorCount_native, long __fileOffset_native);
7861internal static unsafe partial long PWriteV(global::System.Runtime.InteropServices.SafeHandle fd, global::Interop.Sys.IOVector* vectors, int vectorCount, long fileOffset)
7890static extern unsafe long __PInvoke(nint __fd_native, global::Interop.Sys.IOVector* __vectors_native, int __vectorCount_native, long __fileOffset_native);
7975internal static unsafe extern partial int ReadDir(nint dir, global::Interop.Sys.DirectoryEntry* outputEntry);
8147internal static partial int FStat(global::System.Runtime.InteropServices.SafeHandle fd, out global::Interop.Sys.FileStatus output)
8160fixed (global::Interop.Sys.FileStatus* __output_native = &output)
8179static extern unsafe int __PInvoke(nint __fd_native, global::Interop.Sys.FileStatus* __output_native);
8188internal static partial int Stat(string path, out global::Interop.Sys.FileStatus output)
8201fixed (global::Interop.Sys.FileStatus* __output_native = &output)
8220static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.FileStatus* __output_native);
8229internal static partial int LStat(string path, out global::Interop.Sys.FileStatus output)
8242fixed (global::Interop.Sys.FileStatus* __output_native = &output)
8261static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.FileStatus* __output_native);
8270internal static partial int Stat(ref byte path, out global::Interop.Sys.FileStatus output)
8276fixed (global::Interop.Sys.FileStatus* __output_native = &output)
8288static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.FileStatus* __output_native);
8297internal static partial int LStat(ref byte path, out global::Interop.Sys.FileStatus output)
8303fixed (global::Interop.Sys.FileStatus* __output_native = &output)
8315static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.FileStatus* __output_native);
8367internal static partial long SysConf(global::Interop.Sys.SysConfName name)
8381static extern unsafe long __PInvoke(global::Interop.Sys.SysConfName __name_native);
8390internal static partial void SysLog(global::Interop.Sys.SysLogPriority priority, string message, string arg1)
8418static extern unsafe void __PInvoke(global::Interop.Sys.SysLogPriority __priority_native, byte* __message_native, byte* __arg1_native);
8495internal static unsafe partial int UTimensat(string path, global::Interop.Sys.TimeSpec* times)
8524static extern unsafe int __PInvoke(byte* __path_native, global::Interop.Sys.TimeSpec* __times_native);
8533internal static unsafe partial int FUTimens(global::System.Runtime.InteropServices.SafeHandle fd, global::Interop.Sys.TimeSpec* times)
8562static extern unsafe int __PInvoke(nint __fd_native, global::Interop.Sys.TimeSpec* __times_native);
8671internal static unsafe partial int GetPwUidR(uint uid, out global::Interop.Sys.Passwd pwd, byte* buf, int bufLen)
8676fixed (global::Interop.Sys.Passwd* __pwd_native = &pwd)
8684static extern unsafe int __PInvoke(uint __uid_native, global::Interop.Sys.Passwd* __pwd_native, byte* __buf_native, int __bufLen_native);
8693internal static unsafe partial int GetPwNamR(string name, out global::Interop.Sys.Passwd pwd, byte* buf, int bufLen)
8705fixed (global::Interop.Sys.Passwd* __pwd_native = &pwd)
8721static extern unsafe int __PInvoke(byte* __name_native, global::Interop.Sys.Passwd* __pwd_native, byte* __buf_native, int __bufLen_native);
src\libraries\System.Private.CoreLib\src\Microsoft\Win32\SafeHandles\SafeFileHandle.Unix.cs (68)
91private static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int mode, bool failForSymlink, out bool wasSymlink,
92Func<Interop.ErrorInfo, Interop.Sys.OpenFlags, string, Exception?>? createOpenException)
96SafeFileHandle handle = Interop.Sys.Open(path, flags, mode);
101Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
137Interop.Sys.Unlink(_path); // ignore errors; it's valid that the path may no longer exist
147Interop.Sys.FLock(handle, Interop.Sys.LockOperations.LOCK_UN); // ignore any errors
152return Interop.Sys.Close(handle) == 0;
174Func<Interop.ErrorInfo, Interop.Sys.OpenFlags, string, Exception?>? createOpenException = null)
180Func<Interop.ErrorInfo, Interop.Sys.OpenFlags, string, Exception?>? createOpenException = null)
187Func<Interop.ErrorInfo, Interop.Sys.OpenFlags, string, Exception?>? createOpenException = null)
190Interop.Sys.OpenFlags openFlags = PreOpenConfigurationFromOptions(mode, access, share, options, failForSymlink);
233private static Interop.Sys.OpenFlags PreOpenConfigurationFromOptions(FileMode mode, FileAccess access, FileShare share, FileOptions options, bool failForSymlink)
236Interop.Sys.OpenFlags flags = default;
239flags |= Interop.Sys.OpenFlags.O_NOFOLLOW;
251flags |= Interop.Sys.OpenFlags.O_TRUNC;
257flags |= Interop.Sys.OpenFlags.O_CREAT;
261flags |= Interop.Sys.OpenFlags.O_CREAT;
264flags |= Interop.Sys.OpenFlags.O_TRUNC;
269flags |= (Interop.Sys.OpenFlags.O_CREAT | Interop.Sys.OpenFlags.O_EXCL);
277flags |= Interop.Sys.OpenFlags.O_RDONLY;
281flags |= Interop.Sys.OpenFlags.O_RDWR;
285flags |= Interop.Sys.OpenFlags.O_WRONLY;
292flags |= Interop.Sys.OpenFlags.O_CLOEXEC;
304flags |= Interop.Sys.OpenFlags.O_SYNC;
313Interop.Sys.FileStatus status = default;
325if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
330if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFREG)
336Debug.Assert(Interop.Sys.LSeek(this, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0);
348Interop.Sys.LockOperations lockOperation = (share == FileShare.None) ? Interop.Sys.LockOperations.LOCK_EX : Interop.Sys.LockOperations.LOCK_SH;
349if (CanLockTheFile(lockOperation, access) && !(_isLocked = Interop.Sys.FLock(this, lockOperation | Interop.Sys.LockOperations.LOCK_NB) >= 0))
355Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
375Interop.Sys.FileStatus pathStatus;
376if (Interop.Sys.Stat(path, out pathStatus) < 0)
381Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
403Interop.Sys.FileAdvice fadv =
404(options & FileOptions.RandomAccess) != 0 ? Interop.Sys.FileAdvice.POSIX_FADV_RANDOM :
405(options & FileOptions.SequentialScan) != 0 ? Interop.Sys.FileAdvice.POSIX_FADV_SEQUENTIAL :
409FileStreamHelpers.CheckFileCall(Interop.Sys.PosixFAdvise(this, 0, 0, fadv), path,
417if (Interop.Sys.FTruncate(this, 0) < 0)
419Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
430if (preallocationSize > 0 && Interop.Sys.FAllocate(this, 0, preallocationSize) < 0)
432Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
442Interop.Sys.Unlink(path);
454private bool CanLockTheFile(Interop.Sys.LockOperations lockOperation, FileAccess access)
456Debug.Assert(lockOperation == Interop.Sys.LockOperations.LOCK_EX || lockOperation == Interop.Sys.LockOperations.LOCK_SH);
462else if (lockOperation == Interop.Sys.LockOperations.LOCK_EX)
471if (!Interop.Sys.TryGetFileSystemType(this, out Interop.Sys.UnixFileSystemTypes unixFileSystemType))
478case Interop.Sys.UnixFileSystemTypes.nfs: // #44546
479case Interop.Sys.UnixFileSystemTypes.smb:
480case Interop.Sys.UnixFileSystemTypes.smb2: // #53182
481case Interop.Sys.UnixFileSystemTypes.cifs:
488private void FStatCheckIO(string path, ref Interop.Sys.FileStatus status, ref bool statusHasValue)
492if (Interop.Sys.FStat(this, out status) != 0)
494Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
510_canSeek = canSeek = Interop.Sys.LSeek(this, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0 ? NullableBool.True : NullableBool.False;
518int result = Interop.Sys.FStat(this, out Interop.Sys.FileStatus status);
src\libraries\System.Private.CoreLib\src\System\IO\FileStatus.Unix.cs (34)
29private Interop.Sys.FileStatus _fileCache;
44return EntryExists && (_fileCache.UserFlags & (uint)Interop.Sys.UserFlags.UF_HIDDEN) == (uint)Interop.Sys.UserFlags.UF_HIDDEN;
106if (_fileCache.Uid == Interop.Sys.GetEUid())
118if (Interop.Sys.IsMemberOfGroup(_fileCache.Gid))
138return EntryExists && (_fileCache.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFLNK;
162if (!Interop.Sys.SupportsHiddenFlag)
246if (Interop.Sys.CanSetHiddenFlag)
251uint flags = hidden ? _fileCache.UserFlags | (uint)Interop.Sys.UserFlags.UF_HIDDEN :
252_fileCache.UserFlags & ~(uint)Interop.Sys.UserFlags.UF_HIDDEN;
253int rv = handle is not null ? Interop.Sys.FChflags(handle, flags) :
254Interop.Sys.LChflags(path!, flags);
277int rv = handle is not null ? Interop.Sys.FChMod(handle, newMode) :
278Interop.Sys.ChMod(path!, newMode);
304if ((_fileCache.Flags & Interop.Sys.FileStatusFlags.HasBirthTime) != 0)
392Interop.Sys.TimeSpec* buf = stackalloc Interop.Sys.TimeSpec[2];
419? Interop.Sys.FUTimens(handle, buf)
420: Interop.Sys.UTimensat(path!, buf);
431bool updateCreationTime = checkCreationTime && (_fileCache.Flags & Interop.Sys.FileStatusFlags.HasBirthTime) != 0 &&
486int rv = handle is not null ? Interop.Sys.FChMod(handle, (int)mode)
487: Interop.Sys.ChMod(path!, (int)mode);
506Interop.Sys.FStat(handle, out _fileCache) :
507Interop.Sys.LStat(Path.TrimEndingDirectorySeparator(path), out _fileCache);
511Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
531int fileType = _fileCache.Mode & Interop.Sys.FileTypes.S_IFMT;
532bool isDirectory = fileType == Interop.Sys.FileTypes.S_IFDIR;
534if (fileType == Interop.Sys.FileTypes.S_IFLNK)
536if (Interop.Sys.Stat(path, out Interop.Sys.FileStatus target) == 0)
538isDirectory = (target.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR;
541_fileCache.Mode = Interop.Sys.FileTypes.S_IFLNK | (target.Mode & (int)FileSystem.ValidUnixFileModes);
src\libraries\System.Private.CoreLib\src\System\IO\FileSystem.Unix.cs (46)
51Interop.CheckIo(Interop.Sys.CopyFile(src, dst, fileLength));
54private static Exception? CreateOpenExceptionForCopyFile(Interop.ErrorInfo error, Interop.Sys.OpenFlags flags, string path)
77if (Interop.Sys.Link(sourceFullPath, destFullPath) >= 0)
87Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
126Interop.CheckIo(Interop.Sys.LStat(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath);
129if ((sourceStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
134Interop.Sys.FileStatus destStat;
135if (Interop.Sys.LStat(destFullPath, out destStat) == 0)
138if ((destStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
154if (Interop.Sys.Unlink(destBackupFullPath) != 0)
156Interop.ErrorInfo errno = Interop.Sys.GetLastErrorInfo();
170if (Interop.Sys.Stat(destFullPath, out _) != 0)
172Interop.ErrorInfo errno = Interop.Sys.GetLastErrorInfo();
181Interop.CheckIo(Interop.Sys.Rename(sourceFullPath, destFullPath));
195if (Interop.Sys.Rename(sourceFullPath, destFullPath) < 0)
197Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
224Interop.Sys.FileStatus sourceStat, destStat;
225if (Interop.Sys.LStat(sourceFullPath, out sourceStat) == 0 && // source file exists
226(Interop.Sys.LStat(destFullPath, out destStat) != 0 || // dest file does not exist
229Interop.Sys.Rename(sourceFullPath, destFullPath) == 0) // try the rename
241if (Interop.Sys.Unlink(fullPath) < 0)
243Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
296int result = Interop.Sys.MkDir(path, (int)unixCreateMode);
302Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
340int result = Interop.Sys.MkDir(mkdirPath, (int)DefaultUnixCreateDirectoryMode);
346Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
373int result = Interop.Sys.MkDir(mkdirPath, (int)mode);
376Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
414if (!isCaseSensitiveRename && Interop.Sys.LStat(destNoDirectorySeparator, out Interop.Sys.FileStatus destFileStatus) >= 0)
419if (Interop.Sys.LStat(srcNoDirectorySeparator, out Interop.Sys.FileStatus sourceFileStatus) < 0)
438else if ((sourceFileStatus.Mode & Interop.Sys.FileTypes.S_IFMT) != Interop.Sys.FileTypes.S_IFDIR
449if (Interop.Sys.Rename(sourceFullPath, destNoDirectorySeparator) < 0)
451Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
527if (Interop.Sys.RmDir(fullPath) < 0)
529Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
662internal static string? GetLinkTarget(ReadOnlySpan<char> linkPath, bool isDirectory) => Interop.Sys.ReadLink(linkPath);
666Interop.CheckIo(Interop.Sys.SymLink(pathToTarget, path), path);
675string? linkTarget = Interop.Sys.ReadLink(linkPath);
679Interop.Error error = Interop.Sys.GetLastError();
708current = Interop.Sys.ReadLink(sb.AsSpan());
src\libraries\System.Private.CoreLib\src\System\IO\RandomAccess.Unix.cs (24)
23FileStreamHelpers.CheckFileCall(Interop.Sys.FTruncate(handle, length), handle.Path);
36result = Interop.Sys.PRead(handle, bufPtr, buffer.Length, fileOffset);
41Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
47result = Interop.Sys.Read(handle, bufPtr, buffer.Length);
53result = Interop.Sys.Read(handle, bufPtr, buffer.Length);
64Span<Interop.Sys.IOVector> vectors = buffers.Count <= IovStackThreshold ? stackalloc Interop.Sys.IOVector[IovStackThreshold] : new Interop.Sys.IOVector[buffers.Count];
74vectors[i] = new Interop.Sys.IOVector { Base = (byte*)memoryHandle.Pointer, Count = (UIntPtr)buffer.Length };
78fixed (Interop.Sys.IOVector* pinnedVectors = &MemoryMarshal.GetReference(vectors))
80result = Interop.Sys.PReadV(handle, pinnedVectors, buffers.Count, fileOffset);
113bytesWritten = Interop.Sys.PWrite(handle, bufPtr, bytesToWrite, fileOffset);
118Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
124bytesWritten = Interop.Sys.Write(handle, bufPtr, bytesToWrite);
130bytesWritten = Interop.Sys.Write(handle, bufPtr, bytesToWrite);
170Span<Interop.Sys.IOVector> vectors = buffersCount <= IovStackThreshold ?
171stackalloc Interop.Sys.IOVector[IovStackThreshold].Slice(0, buffersCount) :
172new Interop.Sys.IOVector[buffersCount];
183vectors[i] = new Interop.Sys.IOVector { Base = (byte*)memoryHandle.Pointer, Count = (UIntPtr)buffer.Length };
191Span<Interop.Sys.IOVector> left = vectors.Slice(buffersOffset);
192fixed (Interop.Sys.IOVector* pinnedVectors = &MemoryMarshal.GetReference(left))
194bytesWritten = Interop.Sys.PWriteV(handle, pinnedVectors, left.Length, fileOffset);
223Interop.Sys.IOVector current = vectors[buffersOffset];
224vectors[buffersOffset] = new Interop.Sys.IOVector
src\libraries\System.Private.CoreLib\src\System\IO\Strategies\FileStreamHelpers.Unix.cs (10)
23Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
34CheckFileCall(Interop.Sys.LSeek(handle, offset, (Interop.Sys.SeekWhence)(int)origin), handle.Path); // SeekOrigin values are the same as Interop.libc.SeekWhence values
42if (Interop.Sys.FSync(handle) < 0)
44Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
66CheckFileCall(Interop.Sys.LockFileRegion(handle, position, length, canWrite ? Interop.Sys.LockType.F_WRLCK : Interop.Sys.LockType.F_RDLCK), handle.Path);
76CheckFileCall(Interop.Sys.LockFileRegion(handle, position, length, Interop.Sys.LockType.F_UNLCK), handle.Path);