|
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/Microsoft/hcsshim/computestorage" |
14 | 15 | "github.com/pkg/errors" |
@@ -49,6 +50,29 @@ func createNTFSVHD(ctx context.Context, vhdPath string, sizeGB uint32) (err erro |
49 | 50 | return nil |
50 | 51 | } |
51 | 52 |
|
| 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 | + |
52 | 76 | func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) { |
53 | 77 | err := os.MkdirAll(mountPoint, 0) |
54 | 78 | if err != nil { |
@@ -77,6 +101,22 @@ func mountAtAndCheck(t *testing.T, volumePath, mountPoint string) { |
77 | 101 | if mountPointVolumePath != volumePath { |
78 | 102 | t.Fatalf("Mount read-back incorrectly, expected %s; got %s", volumePath, mountPointVolumePath) |
79 | 103 | } |
| 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 | + } |
80 | 120 | } |
81 | 121 |
|
82 | 122 | // TestVolumeMountAPIs creates and attaches a small VHD, and then exercises the |
|
0 commit comments