internal ReparsePointInfo(REPARSE_DATA_BUFFER buffer) { if (buffer.ReparseTag == 0xa000000c) { this.Target = Encoding.Unicode.GetString(buffer.PathBuffer, buffer.SubstituteNameOffset + 4, buffer.SubstituteNameLength); this.Name = Encoding.Unicode.GetString(buffer.PathBuffer, buffer.PrintNameOffset + 4, buffer.PrintNameLength); this.ReparseType = Microsoft.IO.ReparseType.SymbolicLink; } else if (buffer.ReparseTag == 0xa0000003) { this.Target = Encoding.Unicode.GetString(buffer.PathBuffer, buffer.SubstituteNameOffset, buffer.SubstituteNameLength); this.Name = Encoding.Unicode.GetString(buffer.PathBuffer, buffer.PrintNameOffset, buffer.PrintNameLength); if (this.Target.StartsWith(@"\??\Volume", StringComparison.Ordinal)) { this.Target = @"\\?\Volume" + this.Target.Substring(@"\??\Volume".Length); this.ReparseType = Microsoft.IO.ReparseType.MountPoint; } else { if (this.Target.StartsWith(@"\??\", StringComparison.Ordinal)) { this.Target = this.Target.Substring(@"\??\".Length); } this.ReparseType = Microsoft.IO.ReparseType.JunctionPoint; } } else { this.ReparseType = Microsoft.IO.ReparseType.Unknown; } }
public static void Create(string emptyFolder, string targetFolder) { if (emptyFolder == null) { throw new ArgumentNullException("emptyFolder"); } if (emptyFolder == string.Empty) { throw new ArgumentException("String is empty.", "emptyFolder"); } if (targetFolder == null) { throw new ArgumentNullException("targetFolder"); } if (targetFolder == string.Empty) { throw new ArgumentException("String is empty.", "targetFolder"); } if (string.IsNullOrEmpty(Path.GetPathRoot(targetFolder))) { throw new ArgumentException("targetFolder is not full quilified folder path.", "targetFolder"); } using (SafeFileHandle handle = OpenReparsePoint(emptyFolder, FileAccess.Write)) { REPARSE_DATA_BUFFER structure = new REPARSE_DATA_BUFFER { ReparseTag = 0xa0000003 }; StringBuilder builder = new StringBuilder(@"\??\"); builder.Append(targetFolder); if (builder[builder.Length - 1] != Path.DirectorySeparatorChar) { builder.Append(Path.DirectorySeparatorChar); } structure.PathBuffer = new byte[0x3ff0]; structure.SubstituteNameLength = (ushort) Encoding.Unicode.GetBytes(builder.ToString(), 0, builder.Length, structure.PathBuffer, 0); structure.SubstituteNameOffset = 0; structure.ReparseDataLength = (ushort) (structure.SubstituteNameLength + 12); structure.PrintNameOffset = (ushort) (structure.SubstituteNameLength + 2); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(structure)); try { uint num; Marshal.StructureToPtr(structure, ptr, false); if (!Microsoft.Win32.IOCTL.IOCTL.DeviceIoControl(handle, FSCTL.FSCTL_SET_REPARSE_POINT, ptr, structure.SubstituteNameLength + 20, IntPtr.Zero, 0, out num, IntPtr.Zero)) { throw IoHelper.GetIOException(); } } finally { Marshal.FreeHGlobal(ptr); } } }