Skip to content

Commit 8b3cf83

Browse files
committed
Exercise DecodeReparsePoint while testing mounts APIs
This trivially demonstrates the difference between DecodeReparsePoint and GetVolumeNameForVolumeMountPoint. Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
1 parent 1cd279f commit 8b3cf83

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

pkg/volmount/volmount_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"syscall"
1010
"testing"
1111

12+
"github.com/Microsoft/go-winio"
1213
"github.com/Microsoft/go-winio/vhd"
1314
"github.com/hpe-storage/common-host-libs/windows/wmi"
1415
"github.com/pkg/errors"
@@ -105,6 +106,29 @@ func turnRawDiskIntoAVolume(physPath string) (string, error) {
105106
return volumePath, nil
106107
}
107108

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+
108132
func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) {
109133
err := os.MkdirAll(mountPoint, 0)
110134
if err != nil {
@@ -133,6 +157,22 @@ func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) {
133157
if mountPointVolumePath != volumePath {
134158
t.Fatalf("Mount read-back incorrectly, expected %s; got %s", volumePath, mountPointVolumePath)
135159
}
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+
}
136176
}
137177

138178
// TestVolumeMountAPIs creates and attaches a small VHD, and then exercises the

0 commit comments

Comments
 (0)