github.com/bir3/gocompiler@v0.9.2202/src/internal/syscall/windows/reparse_windows.go (about) 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 IO_REPARSE_TAG_DEDUP = 0x80000013 16 17 SYMLINK_FLAG_RELATIVE = 1 18 ) 19 20 // These structures are described 21 // in https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/ca069dad-ed16-42aa-b057-b6b207f447cc 22 // and https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/b41f1cbf-10df-4a47-98d4-1c52a833d913. 23 24 type REPARSE_DATA_BUFFER struct { 25 ReparseTag uint32 26 ReparseDataLength uint16 27 Reserved uint16 28 DUMMYUNIONNAME byte 29 } 30 31 // REPARSE_DATA_BUFFER_HEADER is a common part of REPARSE_DATA_BUFFER structure. 32 type REPARSE_DATA_BUFFER_HEADER struct { 33 ReparseTag uint32 34 // The size, in bytes, of the reparse data that follows 35 // the common portion of the REPARSE_DATA_BUFFER element. 36 // This value is the length of the data starting at the 37 // SubstituteNameOffset field. 38 ReparseDataLength uint16 39 Reserved uint16 40 } 41 42 type SymbolicLinkReparseBuffer struct { 43 // The integer that contains the offset, in bytes, 44 // of the substitute name string in the PathBuffer array, 45 // computed as an offset from byte 0 of PathBuffer. Note that 46 // this offset must be divided by 2 to get the array index. 47 SubstituteNameOffset uint16 48 // The integer that contains the length, in bytes, of the 49 // substitute name string. If this string is null-terminated, 50 // SubstituteNameLength does not include the Unicode null character. 51 SubstituteNameLength uint16 52 // PrintNameOffset is similar to SubstituteNameOffset. 53 PrintNameOffset uint16 54 // PrintNameLength is similar to SubstituteNameLength. 55 PrintNameLength uint16 56 // Flags specifies whether the substitute name is a full path name or 57 // a path name relative to the directory containing the symbolic link. 58 Flags uint32 59 PathBuffer [1]uint16 60 } 61 62 // Path returns path stored in rb. 63 func (rb *SymbolicLinkReparseBuffer) Path() string { 64 n1 := rb.SubstituteNameOffset / 2 65 n2 := (rb.SubstituteNameOffset + rb.SubstituteNameLength) / 2 66 return syscall.UTF16ToString((*[0xffff]uint16)(unsafe.Pointer(&rb.PathBuffer[0]))[n1:n2:n2]) 67 } 68 69 type MountPointReparseBuffer struct { 70 // The integer that contains the offset, in bytes, 71 // of the substitute name string in the PathBuffer array, 72 // computed as an offset from byte 0 of PathBuffer. Note that 73 // this offset must be divided by 2 to get the array index. 74 SubstituteNameOffset uint16 75 // The integer that contains the length, in bytes, of the 76 // substitute name string. If this string is null-terminated, 77 // SubstituteNameLength does not include the Unicode null character. 78 SubstituteNameLength uint16 79 // PrintNameOffset is similar to SubstituteNameOffset. 80 PrintNameOffset uint16 81 // PrintNameLength is similar to SubstituteNameLength. 82 PrintNameLength uint16 83 PathBuffer [1]uint16 84 } 85 86 // Path returns path stored in rb. 87 func (rb *MountPointReparseBuffer) Path() string { 88 n1 := rb.SubstituteNameOffset / 2 89 n2 := (rb.SubstituteNameOffset + rb.SubstituteNameLength) / 2 90 return syscall.UTF16ToString((*[0xffff]uint16)(unsafe.Pointer(&rb.PathBuffer[0]))[n1:n2:n2]) 91 }