...

Source file src/internal/syscall/windows/reparse_windows.go

     1	// Copyright 2016 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	package windows
     6	
     7	import (
     8		"syscall"
     9		"unsafe"
    10	)
    11	
    12	const (
    13		FSCTL_SET_REPARSE_POINT    = 0x000900A4
    14		IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003
    15	
    16		SYMLINK_FLAG_RELATIVE = 1
    17	)
    18	
    19	// These structures are described
    20	// in https://msdn.microsoft.com/en-us/library/cc232007.aspx
    21	// and https://msdn.microsoft.com/en-us/library/cc232006.aspx.
    22	
    23	type REPARSE_DATA_BUFFER struct {
    24		ReparseTag        uint32
    25		ReparseDataLength uint16
    26		Reserved          uint16
    27		DUMMYUNIONNAME    byte
    28	}
    29	
    30	// REPARSE_DATA_BUFFER_HEADER is a common part of REPARSE_DATA_BUFFER structure.
    31	type REPARSE_DATA_BUFFER_HEADER struct {
    32		ReparseTag uint32
    33		// The size, in bytes, of the reparse data that follows
    34		// the common portion of the REPARSE_DATA_BUFFER element.
    35		// This value is the length of the data starting at the
    36		// SubstituteNameOffset field.
    37		ReparseDataLength uint16
    38		Reserved          uint16
    39	}
    40	
    41	type SymbolicLinkReparseBuffer struct {
    42		// The integer that contains the offset, in bytes,
    43		// of the substitute name string in the PathBuffer array,
    44		// computed as an offset from byte 0 of PathBuffer. Note that
    45		// this offset must be divided by 2 to get the array index.
    46		SubstituteNameOffset uint16
    47		// The integer that contains the length, in bytes, of the
    48		// substitute name string. If this string is null-terminated,
    49		// SubstituteNameLength does not include the Unicode null character.
    50		SubstituteNameLength uint16
    51		// PrintNameOffset is similar to SubstituteNameOffset.
    52		PrintNameOffset uint16
    53		// PrintNameLength is similar to SubstituteNameLength.
    54		PrintNameLength uint16
    55		// Flags specifies whether the substitute name is a full path name or
    56		// a path name relative to the directory containing the symbolic link.
    57		Flags      uint32
    58		PathBuffer [1]uint16
    59	}
    60	
    61	// Path returns path stored in rb.
    62	func (rb *SymbolicLinkReparseBuffer) Path() string {
    63		p := (*[0xffff]uint16)(unsafe.Pointer(&rb.PathBuffer[0]))
    64		return syscall.UTF16ToString(p[rb.SubstituteNameOffset/2 : (rb.SubstituteNameOffset+rb.SubstituteNameLength)/2])
    65	}
    66	
    67	type MountPointReparseBuffer struct {
    68		// The integer that contains the offset, in bytes,
    69		// of the substitute name string in the PathBuffer array,
    70		// computed as an offset from byte 0 of PathBuffer. Note that
    71		// this offset must be divided by 2 to get the array index.
    72		SubstituteNameOffset uint16
    73		// The integer that contains the length, in bytes, of the
    74		// substitute name string. If this string is null-terminated,
    75		// SubstituteNameLength does not include the Unicode null character.
    76		SubstituteNameLength uint16
    77		// PrintNameOffset is similar to SubstituteNameOffset.
    78		PrintNameOffset uint16
    79		// PrintNameLength is similar to SubstituteNameLength.
    80		PrintNameLength uint16
    81		PathBuffer      [1]uint16
    82	}
    83	
    84	// Path returns path stored in rb.
    85	func (rb *MountPointReparseBuffer) Path() string {
    86		p := (*[0xffff]uint16)(unsafe.Pointer(&rb.PathBuffer[0]))
    87		return syscall.UTF16ToString(p[rb.SubstituteNameOffset/2 : (rb.SubstituteNameOffset+rb.SubstituteNameLength)/2])
    88	}
    89	

View as plain text