public void Write(ref ReparseDataBuffer buffer) { // set simple fields buffer.ReparseTag = ReparseTag; buffer.Reserved = 0; StringBuilder sb = new StringBuilder(); sb.Append(SubstituteName); sb.Append('\0'); sb.Append(PrintName); sb.Append('\0'); // set subname buffer.SubstituteNameOffset = 0; buffer.SubstituteNameLength = (ushort)(SubstituteName != null ? SubstituteName.Length * sizeof(char) : 0); // set printname buffer.PrintNameOffset = (ushort)(buffer.SubstituteNameLength + 2); buffer.PrintNameLength = (ushort)(PrintName != null ? PrintName.Length * sizeof(char) : 0); // set length buffer.ReparseDataLength = (ushort)(sb.Length * sizeof(char) + 8); buffer.PathBuffer = sb.ToString(); }
public static bool GetReparseInformation(this FileSystemInfo dir, out ReparseDataBuffer buffer) { using (SafeFileHandle hFile = dir.GetHandle()) { using (HG<ReparseDataBuffer> hg = new HG<ReparseDataBuffer>()) { int bytesReturned = 0; bool rc = Kernel32.DeviceIoControl( hFile, EIOControlCode.FsctlGetReparsePoint, IntPtr.Zero, 0, hg.Pointer, hg.SizeOf, ref bytesReturned, IntPtr.Zero); buffer = hg.Structure; return rc; } } }
public static bool SetReparseInformation(this FileSystemInfo dir, ReparseDataBuffer buffer) { using (SafeFileHandle hFile = dir.GetHandle()) { using (HG<ReparseDataBuffer> hg = new HG<ReparseDataBuffer>(buffer)) { int bytesReturned = 0; bool rc = Kernel32.DeviceIoControl( hFile, EIOControlCode.FsctlSetReparsePoint, hg.Pointer, (int)(buffer.ReparseDataLength + Constants.REPARSE_MOUNTPOINT_HEADER_SIZE), IntPtr.Zero, 0, ref bytesReturned, IntPtr.Zero); return rc; } } }
public void Read(ref ReparseDataBuffer buffer) { ReparseTag = buffer.ReparseTag; SubstituteName = buffer.PathBuffer.Substring(buffer.SubstituteNameOffset, buffer.SubstituteNameLength / sizeof(char)); PrintName = buffer.PathBuffer.Substring(buffer.PrintNameOffset, buffer.PrintNameLength / sizeof(char)); }
public ReparseDataBuffer Build() { ReparseDataBuffer buffer = new ReparseDataBuffer(); Write(ref buffer); return buffer; }