|
9 | 9 | "syscall" |
10 | 10 | "testing" |
11 | 11 |
|
| 12 | + "github.com/Microsoft/go-winio" |
12 | 13 | "github.com/Microsoft/go-winio/vhd" |
13 | 14 | "github.com/hpe-storage/common-host-libs/windows/wmi" |
14 | 15 | "github.com/pkg/errors" |
@@ -105,6 +106,29 @@ func turnRawDiskIntoAVolume(physPath string) (string, error) { |
105 | 106 | return volumePath, nil |
106 | 107 | } |
107 | 108 |
|
| 109 | +func readReparsePoint(t *testing.T, path string) []byte { |
| 110 | + rpFile, err := winio.OpenForBackup(path, 0, 0, syscall.OPEN_EXISTING) |
| 111 | + if err != nil { |
| 112 | + t.Fatal(err) |
| 113 | + } |
| 114 | + defer func() { |
| 115 | + closeErr := rpFile.Close() |
| 116 | + if closeErr != nil { |
| 117 | + // Assuming if we're already failing, failing more isn't wrong. |
| 118 | + t.Fatal(closeErr) |
| 119 | + } |
| 120 | + }() |
| 121 | + |
| 122 | + rdbbuf := make([]byte, syscall.MAXIMUM_REPARSE_DATA_BUFFER_SIZE) |
| 123 | + var bytesReturned uint32 |
| 124 | + err = syscall.DeviceIoControl(syscall.Handle(rpFile.Fd()), syscall.FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil) |
| 125 | + if err != nil { |
| 126 | + t.Fatal(err) |
| 127 | + } |
| 128 | + |
| 129 | + return rdbbuf |
| 130 | +} |
| 131 | + |
108 | 132 | func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) { |
109 | 133 | err := os.MkdirAll(mountPoint, 0) |
110 | 134 | if err != nil { |
@@ -133,6 +157,22 @@ func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) { |
133 | 157 | if mountPointVolumePath != volumePath { |
134 | 158 | t.Fatalf("Mount read-back incorrectly, expected %s; got %s", volumePath, mountPointVolumePath) |
135 | 159 | } |
| 160 | + |
| 161 | + rpBuff := readReparsePoint(t, mountPoint) |
| 162 | + |
| 163 | + rp, err := winio.DecodeReparsePoint(rpBuff) |
| 164 | + if err != nil { |
| 165 | + t.Fatal(err) |
| 166 | + } |
| 167 | + |
| 168 | + if !rp.IsMountPoint { |
| 169 | + t.Fatal("Mount point read as reparse point did not decode as mount point") |
| 170 | + } |
| 171 | + |
| 172 | + // volumePath starts with \\?\ but the reparse point data starts with \??\ |
| 173 | + if rp.Target[0:4] != "\\??\\" || rp.Target[4:] != volumePath[4:] { |
| 174 | + t.Fatalf("Mount read as reparse point incorrectly, expected \\??\\%s; got %s", volumePath[4:], rp.Target) |
| 175 | + } |
136 | 176 | } |
137 | 177 |
|
138 | 178 | // TestVolumeMountAPIs creates and attaches a small VHD, and then exercises the |
|
0 commit comments