Debian Codegraph @

libgo/go/internal/syscall/windows/reparse_windows.go

raw
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 n1 := rb.SubstituteNameOffset / 2
64 n2 := (rb.SubstituteNameOffset + rb.SubstituteNameLength) / 2
65 return syscall.UTF16ToString((*[0xffff]uint16)(unsafe.Pointer(&rb.PathBuffer[0]))[n1:n2:n2])
66 }
67
68 type MountPointReparseBuffer struct {
69 // The integer that contains the offset, in bytes,
70 // of the substitute name string in the PathBuffer array,
71 // computed as an offset from byte 0 of PathBuffer. Note that
72 // this offset must be divided by 2 to get the array index.
73 SubstituteNameOffset uint16
74 // The integer that contains the length, in bytes, of the
75 // substitute name string. If this string is null-terminated,
76 // SubstituteNameLength does not include the Unicode null character.
77 SubstituteNameLength uint16
78 // PrintNameOffset is similar to SubstituteNameOffset.
79 PrintNameOffset uint16
80 // PrintNameLength is similar to SubstituteNameLength.
81 PrintNameLength uint16
82 PathBuffer [1]uint16
83 }
84
85 // Path returns path stored in rb.
86 func (rb *MountPointReparseBuffer) Path() string {
87 n1 := rb.SubstituteNameOffset / 2
88 n2 := (rb.SubstituteNameOffset + rb.SubstituteNameLength) / 2
89 return syscall.UTF16ToString((*[0xffff]uint16)(unsafe.Pointer(&rb.PathBuffer[0]))[n1:n2:n2])
90 }