Skip to content

Commit

Permalink
Exercise DecodeReparsePoint while testing mounts APIs
Browse files Browse the repository at this point in the history
This trivially demonstrates the difference between DecodeReparsePoint
and GetVolumeNameForVolumeMountPoint.

Signed-off-by: Paul "TBBle" Hampson <[email protected]>
  • Loading branch information
TBBle committed Jan 12, 2021
1 parent 1cd279f commit 8b3cf83
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/volmount/volmount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"syscall"
"testing"

"github.com/Microsoft/go-winio"
"github.com/Microsoft/go-winio/vhd"
"github.com/hpe-storage/common-host-libs/windows/wmi"
"github.com/pkg/errors"
Expand Down Expand Up @@ -105,6 +106,29 @@ func turnRawDiskIntoAVolume(physPath string) (string, error) {
return volumePath, nil
}

func readReparsePoint(t *testing.T, path string) []byte {
rpFile, err := winio.OpenForBackup(path, 0, 0, syscall.OPEN_EXISTING)
if err != nil {
t.Fatal(err)
}
defer func() {
closeErr := rpFile.Close()
if closeErr != nil {
// Assuming if we're already failing, failing more isn't wrong.
t.Fatal(closeErr)
}
}()

rdbbuf := make([]byte, syscall.MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
var bytesReturned uint32
err = syscall.DeviceIoControl(syscall.Handle(rpFile.Fd()), syscall.FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil)
if err != nil {
t.Fatal(err)
}

return rdbbuf
}

func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) {
err := os.MkdirAll(mountPoint, 0)
if err != nil {
Expand Down Expand Up @@ -133,6 +157,22 @@ func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) {
if mountPointVolumePath != volumePath {
t.Fatalf("Mount read-back incorrectly, expected %s; got %s", volumePath, mountPointVolumePath)
}

rpBuff := readReparsePoint(t, mountPoint)

rp, err := winio.DecodeReparsePoint(rpBuff)
if err != nil {
t.Fatal(err)
}

if !rp.IsMountPoint {
t.Fatal("Mount point read as reparse point did not decode as mount point")
}

// volumePath starts with \\?\ but the reparse point data starts with \??\
if rp.Target[0:4] != "\\??\\" || rp.Target[4:] != volumePath[4:] {
t.Fatalf("Mount read as reparse point incorrectly, expected \\??\\%s; got %s", volumePath[4:], rp.Target)
}
}

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

0 comments on commit 8b3cf83

Please sign in to comment.