-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add required computestorage APIs to allow for running tests of `ResolvePath`. Signed-off-by: Hamza El-Saawy <[email protected]>
- Loading branch information
Showing
8 changed files
with
457 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//go:build windows | ||
|
||
package computestorage | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/sys/windows" | ||
|
||
"github.com/Microsoft/go-winio/internal/interop" | ||
) | ||
|
||
//go:generate go run github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go computestorage.go | ||
|
||
// https://learn.microsoft.com/en-us/virtualization/api/hcs/reference/hcsformatwritablelayervhd | ||
// | ||
//sys hcsFormatWritableLayerVhd(handle windows.Handle) (hr error) = computestorage.HcsFormatWritableLayerVhd? | ||
|
||
// FormatWritableLayerVhd formats a virtual disk for use as a writable container layer. | ||
// | ||
// If the VHD is not mounted it will be temporarily mounted. | ||
// | ||
// NOTE: This API had a breaking change in the operating system after Windows Server 2019. | ||
// On ws2019 the API expects to get passed a file handle from CreateFile for the vhd that | ||
// the caller wants to format. On > ws2019, its expected that the caller passes a vhd handle | ||
// that can be obtained from the virtdisk APIs. | ||
func FormatWritableLayerVhd(vhdHandle windows.Handle) (err error) { | ||
err = hcsFormatWritableLayerVhd(vhdHandle) | ||
if err != nil { | ||
return fmt.Errorf("failed to format writable layer vhd: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
// https://learn.microsoft.com/en-us/virtualization/api/hcs/reference/hcsgetlayervhdmountpath | ||
// | ||
//sys hcsGetLayerVhdMountPath(vhdHandle windows.Handle, mountPath **uint16) (hr error) = computestorage.HcsGetLayerVhdMountPath? | ||
|
||
// GetLayerVhdMountPath returns the volume path for a virtual disk of a writable container layer. | ||
func GetLayerVhdMountPath(vhdHandle windows.Handle) (path string, err error) { | ||
var mountPath *uint16 | ||
err = hcsGetLayerVhdMountPath(vhdHandle, &mountPath) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get vhd mount path: %w", err) | ||
} | ||
path = interop.ConvertAndFreeCoTaskMemString(mountPath) | ||
return path, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package computestorage |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package interop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build windows | ||
|
||
package interop | ||
|
||
import ( | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
//go:generate go run github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go interop.go | ||
|
||
//sys coTaskMemFree(buffer unsafe.Pointer) = api_ms_win_core_com_l1_1_0.CoTaskMemFree | ||
|
||
func ConvertAndFreeCoTaskMemString(buffer *uint16) string { | ||
str := syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(buffer))[:]) | ||
coTaskMemFree(unsafe.Pointer(buffer)) | ||
return str | ||
} | ||
|
||
func Win32FromHresult(hr uintptr) syscall.Errno { | ||
if hr&0x1fff0000 == 0x00070000 { | ||
return syscall.Errno(hr & 0xffff) | ||
} | ||
return syscall.Errno(hr) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.