Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

85 lignes
5.9 KiB

  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System.Diagnostics.CodeAnalysis;
  22. using System.Runtime.InteropServices;
  23. using System.Security;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. internal static partial class NativeMethods
  27. {
  28. /// <summary>
  29. /// Retrieves information about the specified disk, including the amount of free space on the disk.
  30. /// </summary>
  31. /// <remarks>
  32. /// <para>Symbolic link behavior: If the path points to a symbolic link, the operation is performed on the target.</para>
  33. /// <para>If this parameter is a UNC name, it must include a trailing backslash (for example, "\\MyServer\MyShare\").</para>
  34. /// <para>Furthermore, a drive specification must have a trailing backslash (for example, "C:\").</para>
  35. /// <para>The calling application must have FILE_LIST_DIRECTORY access rights for this directory.</para>
  36. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  37. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  38. /// </remarks>
  39. /// <param name="lpRootPathName">Full pathname of the root file.</param>
  40. /// <param name="lpSectorsPerCluster">[out] The sectors per cluster.</param>
  41. /// <param name="lpBytesPerSector">[out] The bytes per sector.</param>
  42. /// <param name="lpNumberOfFreeClusters">[out] Number of free clusters.</param>
  43. /// <param name="lpTotalNumberOfClusters">[out] The total number of clusters.</param>
  44. /// <returns>
  45. /// <para>If the function succeeds, the return value is nonzero.</para>
  46. /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
  47. /// </returns>
  48. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  49. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetDiskFreeSpaceW"), SuppressUnmanagedCodeSecurity]
  50. [return: MarshalAs(UnmanagedType.Bool)]
  51. internal static extern bool GetDiskFreeSpace([MarshalAs(UnmanagedType.LPWStr)] string lpRootPathName, [MarshalAs(UnmanagedType.U4)] out int lpSectorsPerCluster, [MarshalAs(UnmanagedType.U4)] out int lpBytesPerSector, [MarshalAs(UnmanagedType.U4)] out int lpNumberOfFreeClusters, [MarshalAs(UnmanagedType.U4)] out uint lpTotalNumberOfClusters);
  52. /// <summary>
  53. /// Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space,
  54. /// <para>the total amount of free space, and the total amount of free space available to the user that is associated with the calling
  55. /// thread.</para>
  56. /// </summary>
  57. /// <remarks>
  58. /// <para>Symbolic link behavior: If the path points to a symbolic link, the operation is performed on the target.</para>
  59. /// <para>The GetDiskFreeSpaceEx function returns zero (0) for lpTotalNumberOfFreeBytes and lpFreeBytesAvailable
  60. /// for all CD requests unless the disk is an unwritten CD in a CD-RW drive.</para>
  61. /// <para>If this parameter is a UNC name, it must include a trailing backslash, for example, "\\MyServer\MyShare\".</para>
  62. /// <para>This parameter does not have to specify the root directory on a disk.</para>
  63. /// <para>The function accepts any directory on a disk.</para>
  64. /// <para>The calling application must have FILE_LIST_DIRECTORY access rights for this directory.</para>
  65. /// <para>Minimum supported client: Windows XP [desktop apps | Windows Store apps]</para>
  66. /// <para>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps]</para>
  67. /// </remarks>
  68. /// <param name="lpDirectoryName">Pathname of the directory.</param>
  69. /// <param name="lpFreeBytesAvailable">[out] The free bytes available.</param>
  70. /// <param name="lpTotalNumberOfBytes">[out] The total number of in bytes.</param>
  71. /// <param name="lpTotalNumberOfFreeBytes">[out] The total number of free in bytes.</param>
  72. /// <returns>
  73. /// <para>If the function succeeds, the return value is nonzero.</para>
  74. /// <para>If the function fails, the return value is zero (0). To get extended error information, call GetLastError.</para>
  75. /// </returns>
  76. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  77. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetDiskFreeSpaceExW"), SuppressUnmanagedCodeSecurity]
  78. [return: MarshalAs(UnmanagedType.Bool)]
  79. internal static extern bool GetDiskFreeSpaceEx([MarshalAs(UnmanagedType.LPWStr)] string lpDirectoryName, [MarshalAs(UnmanagedType.U8)] out long lpFreeBytesAvailable, [MarshalAs(UnmanagedType.U8)] out long lpTotalNumberOfBytes, [MarshalAs(UnmanagedType.U8)] out long lpTotalNumberOfFreeBytes);
  80. }
  81. }