1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System.Runtime.InteropServices;
6 using Microsoft.Win32.SafeHandles;
7 
8 internal static partial class Interop
9 {
10     internal static partial class Sys
11     {
12         internal enum FileAdvice : int
13         {
14             POSIX_FADV_NORMAL       = 0,    /* no special advice, the default value */
15             POSIX_FADV_RANDOM       = 1,    /* random I/O access */
16             POSIX_FADV_SEQUENTIAL   = 2,    /* sequential I/O access */
17             POSIX_FADV_WILLNEED     = 3,    /* will need specified pages */
18             POSIX_FADV_DONTNEED     = 4,    /* don't need the specified pages */
19             POSIX_FADV_NOREUSE      = 5,    /* data will only be accessed once */
20         }
21 
22         /// <summary>
23         /// Notifies the OS kernel that the specified file will be accessed in a particular way soon; this allows the kernel to
24         /// potentially optimize the access pattern of the file.
25         /// </summary>
26         /// <param name="fd">The file descriptor of the file</param>
27         /// <param name="offset">The start of the region to advise about</param>
28         /// <param name="length">The number of bytes of the region (until the end of the file if 0)</param>
29         /// <param name="advice">The type of advice to give the kernel about the specified region</param>
30         /// <returns>
31         /// Returns 0 on success; otherwise, the error code is returned
32         /// </returns>
33         [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PosixFAdvise", SetLastError = false /* this is explicitly called out in the man page */)]
PosixFAdvise(SafeFileHandle fd, long offset, long length, FileAdvice advice)34         internal static extern int PosixFAdvise(SafeFileHandle fd, long offset, long length, FileAdvice advice);
35     }
36 }
37