Skip to content

Commit 29aa6d0

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 d085a82 commit 29aa6d0

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/Microsoft/hcsshim/computestorage"
1415
"github.com/pkg/errors"
@@ -49,6 +50,29 @@ func createNTFSVHD(ctx context.Context, vhdPath string, sizeGB uint32) (err erro
4950
return nil
5051
}
5152

53+
func readReparsePoint(t *testing.T, path string) []byte {
54+
rpFile, err := winio.OpenForBackup(path, 0, 0, syscall.OPEN_EXISTING)
55+
if err != nil {
56+
t.Fatal(err)
57+
}
58+
defer func() {
59+
closeErr := rpFile.Close()
60+
if closeErr != nil {
61+
// Assuming if we're already failing, failing more isn't wrong.
62+
t.Fatal(closeErr)
63+
}
64+
}()
65+
66+
rdbbuf := make([]byte, syscall.MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
67+
var bytesReturned uint32
68+
err = syscall.DeviceIoControl(syscall.Handle(rpFile.Fd()), syscall.FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil)
69+
if err != nil {
70+
t.Fatal(err)
71+
}
72+
73+
return rdbbuf
74+
}
75+
5276
func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) {
5377
err := os.MkdirAll(mountPoint, 0)
5478
if err != nil {
@@ -77,6 +101,22 @@ func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) {
77101
if mountPointVolumePath != volumePath {
78102
t.Fatalf("Mount read-back incorrectly, expected %s; got %s", volumePath, mountPointVolumePath)
79103
}
104+
105+
rpBuff := readReparsePoint(t, mountPoint)
106+
107+
rp, err := winio.DecodeReparsePoint(rpBuff)
108+
if err != nil {
109+
t.Fatal(err)
110+
}
111+
112+
if !rp.IsMountPoint {
113+
t.Fatal("Mount point read as reparse point did not decode as mount point")
114+
}
115+
116+
// volumePath starts with \\?\ but the reparse point data starts with \??\
117+
if rp.Target[0:4] != "\\??\\" || rp.Target[4:] != volumePath[4:] {
118+
t.Fatalf("Mount read as reparse point incorrectly, expected \\??\\%s; got %s", volumePath[4:], rp.Target)
119+
}
80120
}
81121

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

0 commit comments

Comments
 (0)