You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

106 lines
5.4 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 Microsoft.Win32.SafeHandles;
  22. using System.IO;
  23. using System.Security;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. public static partial class File
  27. {
  28. #region GetLinkTargetInfo
  29. /// <summary>[AlphaFS] Gets information about the target of a mount point or symbolic link on an NTFS file system.</summary>
  30. /// <param name="path">The path to the reparse point.</param>
  31. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  32. /// <returns>
  33. /// An instance of <see cref="LinkTargetInfo"/> or <see cref="SymbolicLinkTargetInfo"/> containing information about the symbolic link
  34. /// or mount point pointed to by <paramref name="path"/>.
  35. /// </returns>
  36. [SecurityCritical]
  37. public static LinkTargetInfo GetLinkTargetInfo(string path, PathFormat pathFormat)
  38. {
  39. return GetLinkTargetInfoCore(null, path, pathFormat);
  40. }
  41. /// <summary>[AlphaFS] Gets information about the target of a mount point or symbolic link on an NTFS file system.</summary>
  42. /// <param name="path">The path to the reparse point.</param>
  43. /// <returns>
  44. /// An instance of <see cref="LinkTargetInfo"/> or <see cref="SymbolicLinkTargetInfo"/> containing information about the symbolic link
  45. /// or mount point pointed to by <paramref name="path"/>.
  46. /// </returns>
  47. [SecurityCritical]
  48. public static LinkTargetInfo GetLinkTargetInfo(string path)
  49. {
  50. return GetLinkTargetInfoCore(null, path, PathFormat.RelativePath);
  51. }
  52. /// <summary>[AlphaFS] Gets information about the target of a mount point or symbolic link on an NTFS file system.</summary>
  53. /// <param name="transaction">The transaction.</param>
  54. /// <param name="path">The path to the reparse point.</param>
  55. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  56. /// <returns>
  57. /// An instance of <see cref="LinkTargetInfo"/> or <see cref="SymbolicLinkTargetInfo"/> containing information about the symbolic link
  58. /// or mount point pointed to by <paramref name="path"/>.
  59. /// </returns>
  60. [SecurityCritical]
  61. public static LinkTargetInfo GetLinkTargetInfoTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  62. {
  63. return GetLinkTargetInfoCore(transaction, path, pathFormat);
  64. }
  65. /// <summary>[AlphaFS] Gets information about the target of a mount point or symbolic link on an NTFS file system.</summary>
  66. /// <param name="transaction">The transaction.</param>
  67. /// <param name="path">The path to the reparse point.</param>
  68. /// <returns>
  69. /// An instance of <see cref="LinkTargetInfo"/> or <see cref="SymbolicLinkTargetInfo"/> containing information about the symbolic link
  70. /// or mount point pointed to by <paramref name="path"/>.
  71. /// </returns>
  72. [SecurityCritical]
  73. public static LinkTargetInfo GetLinkTargetInfoTransacted(KernelTransaction transaction, string path)
  74. {
  75. return GetLinkTargetInfoCore(transaction, path, PathFormat.RelativePath);
  76. }
  77. #endregion // GetLinkTargetInfo
  78. #region GetLinkTargetInfoCore
  79. /// <summary>Gets information about the target of a mount point or symbolic link on an NTFS file system.</summary>
  80. /// <param name="transaction">The transaction.</param>
  81. /// <param name="path">The path to the reparse point.</param>
  82. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  83. /// <returns>
  84. /// An instance of <see cref="LinkTargetInfo"/> or <see cref="SymbolicLinkTargetInfo"/> containing information about the symbolic link
  85. /// or mount point pointed to by <paramref name="path"/>.
  86. /// </returns>
  87. [SecurityCritical]
  88. internal static LinkTargetInfo GetLinkTargetInfoCore(KernelTransaction transaction, string path, PathFormat pathFormat)
  89. {
  90. using (SafeFileHandle safeHandle = CreateFileCore(transaction, path, ExtendedFileAttributes.OpenReparsePoint | ExtendedFileAttributes.BackupSemantics, null, FileMode.Open, 0, FileShare.ReadWrite, true, pathFormat))
  91. return Device.GetLinkTargetInfoCore(safeHandle);
  92. }
  93. #endregion // GetLinkTargetInfoCore
  94. }
  95. }