summaryrefslogtreecommitdiff
path: root/vendor/github.com/Microsoft/go-winio
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-23 17:04:40 +0100
committerGitHub <noreply@github.com>2020-12-23 17:04:40 +0100
commit8544bb57fe5e9222509827a7f5aa648516b9cd98 (patch)
tree2dcda2b058ca07b180ea1f017933c57dca033af8 /vendor/github.com/Microsoft/go-winio
parent0778c114d3001bdd4f40fe46283457481d983b64 (diff)
parent057faea5c185d24cda40d310b0a80763ee46f4cc (diff)
downloadpodman-8544bb57fe5e9222509827a7f5aa648516b9cd98.tar.gz
podman-8544bb57fe5e9222509827a7f5aa648516b9cd98.tar.bz2
podman-8544bb57fe5e9222509827a7f5aa648516b9cd98.zip
Merge pull request #8813 from containers/dependabot/go_modules/github.com/containers/storage-1.24.4
Bump github.com/containers/storage from 1.24.3 to 1.24.4
Diffstat (limited to 'vendor/github.com/Microsoft/go-winio')
-rw-r--r--vendor/github.com/Microsoft/go-winio/go.mod2
-rw-r--r--vendor/github.com/Microsoft/go-winio/go.sum6
-rw-r--r--vendor/github.com/Microsoft/go-winio/pipe.go4
-rw-r--r--vendor/github.com/Microsoft/go-winio/pkg/security/grantvmgroupaccess.go159
-rw-r--r--vendor/github.com/Microsoft/go-winio/pkg/security/syscall_windows.go7
-rw-r--r--vendor/github.com/Microsoft/go-winio/pkg/security/zsyscall_windows.go81
-rw-r--r--vendor/github.com/Microsoft/go-winio/vhd/vhd.go341
-rw-r--r--vendor/github.com/Microsoft/go-winio/vhd/zvhd.go54
8 files changed, 549 insertions, 105 deletions
diff --git a/vendor/github.com/Microsoft/go-winio/go.mod b/vendor/github.com/Microsoft/go-winio/go.mod
index 50b9d6e2e..a2eb6496c 100644
--- a/vendor/github.com/Microsoft/go-winio/go.mod
+++ b/vendor/github.com/Microsoft/go-winio/go.mod
@@ -3,7 +3,7 @@ module github.com/Microsoft/go-winio
go 1.12
require (
- github.com/pkg/errors v0.8.1
+ github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.4.1
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3
)
diff --git a/vendor/github.com/Microsoft/go-winio/go.sum b/vendor/github.com/Microsoft/go-winio/go.sum
index 209aa8cf4..6da76a492 100644
--- a/vendor/github.com/Microsoft/go-winio/go.sum
+++ b/vendor/github.com/Microsoft/go-winio/go.sum
@@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
-github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
@@ -12,7 +12,5 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA=
-golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3 h1:7TYNF4UdlohbFwpNH04CoPMp1cHUZgO1Ebq5r2hIjfo=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
diff --git a/vendor/github.com/Microsoft/go-winio/pipe.go b/vendor/github.com/Microsoft/go-winio/pipe.go
index ff96dff1c..96700a73d 100644
--- a/vendor/github.com/Microsoft/go-winio/pipe.go
+++ b/vendor/github.com/Microsoft/go-winio/pipe.go
@@ -429,10 +429,10 @@ type PipeConfig struct {
// when the pipe is in message mode.
MessageMode bool
- // InputBufferSize specifies the size the input buffer, in bytes.
+ // InputBufferSize specifies the size of the input buffer, in bytes.
InputBufferSize int32
- // OutputBufferSize specifies the size the input buffer, in bytes.
+ // OutputBufferSize specifies the size of the output buffer, in bytes.
OutputBufferSize int32
}
diff --git a/vendor/github.com/Microsoft/go-winio/pkg/security/grantvmgroupaccess.go b/vendor/github.com/Microsoft/go-winio/pkg/security/grantvmgroupaccess.go
new file mode 100644
index 000000000..2df31b660
--- /dev/null
+++ b/vendor/github.com/Microsoft/go-winio/pkg/security/grantvmgroupaccess.go
@@ -0,0 +1,159 @@
+package security
+
+import (
+ "os"
+ "syscall"
+ "unsafe"
+
+ "github.com/pkg/errors"
+)
+
+type (
+ accessMask uint32
+ accessMode uint32
+ desiredAccess uint32
+ inheritMode uint32
+ objectType uint32
+ shareMode uint32
+ securityInformation uint32
+ trusteeForm uint32
+ trusteeType uint32
+
+ explicitAccess struct {
+ accessPermissions accessMask
+ accessMode accessMode
+ inheritance inheritMode
+ trustee trustee
+ }
+
+ trustee struct {
+ multipleTrustee *trustee
+ multipleTrusteeOperation int32
+ trusteeForm trusteeForm
+ trusteeType trusteeType
+ name uintptr
+ }
+)
+
+const (
+ accessMaskDesiredPermission accessMask = 1 << 31 // GENERIC_READ
+
+ accessModeGrant accessMode = 1
+
+ desiredAccessReadControl desiredAccess = 0x20000
+ desiredAccessWriteDac desiredAccess = 0x40000
+
+ gvmga = "GrantVmGroupAccess:"
+
+ inheritModeNoInheritance inheritMode = 0x0
+ inheritModeSubContainersAndObjectsInherit inheritMode = 0x3
+
+ objectTypeFileObject objectType = 0x1
+
+ securityInformationDACL securityInformation = 0x4
+
+ shareModeRead shareMode = 0x1
+ shareModeWrite shareMode = 0x2
+
+ sidVmGroup = "S-1-5-83-0"
+
+ trusteeFormIsSid trusteeForm = 0
+
+ trusteeTypeWellKnownGroup trusteeType = 5
+)
+
+// GrantVMGroupAccess sets the DACL for a specified file or directory to
+// include Grant ACE entries for the VM Group SID. This is a golang re-
+// implementation of the same function in vmcompute, just not exported in
+// RS5. Which kind of sucks. Sucks a lot :/
+func GrantVmGroupAccess(name string) error {
+ // Stat (to determine if `name` is a directory).
+ s, err := os.Stat(name)
+ if err != nil {
+ return errors.Wrapf(err, "%s os.Stat %s", gvmga, name)
+ }
+
+ // Get a handle to the file/directory. Must defer Close on success.
+ fd, err := createFile(name, s.IsDir())
+ if err != nil {
+ return err // Already wrapped
+ }
+ defer syscall.CloseHandle(fd)
+
+ // Get the current DACL and Security Descriptor. Must defer LocalFree on success.
+ ot := objectTypeFileObject
+ si := securityInformationDACL
+ sd := uintptr(0)
+ origDACL := uintptr(0)
+ if err := getSecurityInfo(fd, uint32(ot), uint32(si), nil, nil, &origDACL, nil, &sd); err != nil {
+ return errors.Wrapf(err, "%s GetSecurityInfo %s", gvmga, name)
+ }
+ defer syscall.LocalFree((syscall.Handle)(unsafe.Pointer(sd)))
+
+ // Generate a new DACL which is the current DACL with the required ACEs added.
+ // Must defer LocalFree on success.
+ newDACL, err := generateDACLWithAcesAdded(name, s.IsDir(), origDACL)
+ if err != nil {
+ return err // Already wrapped
+ }
+ defer syscall.LocalFree((syscall.Handle)(unsafe.Pointer(newDACL)))
+
+ // And finally use SetSecurityInfo to apply the updated DACL.
+ if err := setSecurityInfo(fd, uint32(ot), uint32(si), uintptr(0), uintptr(0), newDACL, uintptr(0)); err != nil {
+ return errors.Wrapf(err, "%s SetSecurityInfo %s", gvmga, name)
+ }
+
+ return nil
+}
+
+// createFile is a helper function to call [Nt]CreateFile to get a handle to
+// the file or directory.
+func createFile(name string, isDir bool) (syscall.Handle, error) {
+ namep := syscall.StringToUTF16(name)
+ da := uint32(desiredAccessReadControl | desiredAccessWriteDac)
+ sm := uint32(shareModeRead | shareModeWrite)
+ fa := uint32(syscall.FILE_ATTRIBUTE_NORMAL)
+ if isDir {
+ fa = uint32(fa | syscall.FILE_FLAG_BACKUP_SEMANTICS)
+ }
+ fd, err := syscall.CreateFile(&namep[0], da, sm, nil, syscall.OPEN_EXISTING, fa, 0)
+ if err != nil {
+ return 0, errors.Wrapf(err, "%s syscall.CreateFile %s", gvmga, name)
+ }
+ return fd, nil
+}
+
+// generateDACLWithAcesAdded generates a new DACL with the two needed ACEs added.
+// The caller is responsible for LocalFree of the returned DACL on success.
+func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintptr, error) {
+ // Generate pointers to the SIDs based on the string SIDs
+ sid, err := syscall.StringToSid(sidVmGroup)
+ if err != nil {
+ return 0, errors.Wrapf(err, "%s syscall.StringToSid %s %s", gvmga, name, sidVmGroup)
+ }
+
+ inheritance := inheritModeNoInheritance
+ if isDir {
+ inheritance = inheritModeSubContainersAndObjectsInherit
+ }
+
+ eaArray := []explicitAccess{
+ explicitAccess{
+ accessPermissions: accessMaskDesiredPermission,
+ accessMode: accessModeGrant,
+ inheritance: inheritance,
+ trustee: trustee{
+ trusteeForm: trusteeFormIsSid,
+ trusteeType: trusteeTypeWellKnownGroup,
+ name: uintptr(unsafe.Pointer(sid)),
+ },
+ },
+ }
+
+ modifiedDACL := uintptr(0)
+ if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil {
+ return 0, errors.Wrapf(err, "%s SetEntriesInAcl %s", gvmga, name)
+ }
+
+ return modifiedDACL, nil
+}
diff --git a/vendor/github.com/Microsoft/go-winio/pkg/security/syscall_windows.go b/vendor/github.com/Microsoft/go-winio/pkg/security/syscall_windows.go
new file mode 100644
index 000000000..c40c2739b
--- /dev/null
+++ b/vendor/github.com/Microsoft/go-winio/pkg/security/syscall_windows.go
@@ -0,0 +1,7 @@
+package security
+
+//go:generate go run mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go
+
+//sys getSecurityInfo(handle syscall.Handle, objectType uint32, si uint32, ppsidOwner **uintptr, ppsidGroup **uintptr, ppDacl *uintptr, ppSacl *uintptr, ppSecurityDescriptor *uintptr) (err error) [failretval!=0] = advapi32.GetSecurityInfo
+//sys setSecurityInfo(handle syscall.Handle, objectType uint32, si uint32, psidOwner uintptr, psidGroup uintptr, pDacl uintptr, pSacl uintptr) (err error) [failretval!=0] = advapi32.SetSecurityInfo
+//sys setEntriesInAcl(count uintptr, pListOfEEs uintptr, oldAcl uintptr, newAcl *uintptr) (err error) [failretval!=0] = advapi32.SetEntriesInAclW
diff --git a/vendor/github.com/Microsoft/go-winio/pkg/security/zsyscall_windows.go b/vendor/github.com/Microsoft/go-winio/pkg/security/zsyscall_windows.go
new file mode 100644
index 000000000..0f0c0deff
--- /dev/null
+++ b/vendor/github.com/Microsoft/go-winio/pkg/security/zsyscall_windows.go
@@ -0,0 +1,81 @@
+// Code generated mksyscall_windows.exe DO NOT EDIT
+
+package security
+
+import (
+ "syscall"
+ "unsafe"
+
+ "golang.org/x/sys/windows"
+)
+
+var _ unsafe.Pointer
+
+// Do the interface allocations only once for common
+// Errno values.
+const (
+ errnoERROR_IO_PENDING = 997
+)
+
+var (
+ errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
+)
+
+// errnoErr returns common boxed Errno values, to prevent
+// allocations at runtime.
+func errnoErr(e syscall.Errno) error {
+ switch e {
+ case 0:
+ return nil
+ case errnoERROR_IO_PENDING:
+ return errERROR_IO_PENDING
+ }
+ // TODO: add more here, after collecting data on the common
+ // error values see on Windows. (perhaps when running
+ // all.bat?)
+ return e
+}
+
+var (
+ modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
+
+ procGetSecurityInfo = modadvapi32.NewProc("GetSecurityInfo")
+ procSetSecurityInfo = modadvapi32.NewProc("SetSecurityInfo")
+ procSetEntriesInAclW = modadvapi32.NewProc("SetEntriesInAclW")
+)
+
+func getSecurityInfo(handle syscall.Handle, objectType uint32, si uint32, ppsidOwner **uintptr, ppsidGroup **uintptr, ppDacl *uintptr, ppSacl *uintptr, ppSecurityDescriptor *uintptr) (err error) {
+ r1, _, e1 := syscall.Syscall9(procGetSecurityInfo.Addr(), 8, uintptr(handle), uintptr(objectType), uintptr(si), uintptr(unsafe.Pointer(ppsidOwner)), uintptr(unsafe.Pointer(ppsidGroup)), uintptr(unsafe.Pointer(ppDacl)), uintptr(unsafe.Pointer(ppSacl)), uintptr(unsafe.Pointer(ppSecurityDescriptor)), 0)
+ if r1 != 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func setSecurityInfo(handle syscall.Handle, objectType uint32, si uint32, psidOwner uintptr, psidGroup uintptr, pDacl uintptr, pSacl uintptr) (err error) {
+ r1, _, e1 := syscall.Syscall9(procSetSecurityInfo.Addr(), 7, uintptr(handle), uintptr(objectType), uintptr(si), uintptr(psidOwner), uintptr(psidGroup), uintptr(pDacl), uintptr(pSacl), 0, 0)
+ if r1 != 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func setEntriesInAcl(count uintptr, pListOfEEs uintptr, oldAcl uintptr, newAcl *uintptr) (err error) {
+ r1, _, e1 := syscall.Syscall6(procSetEntriesInAclW.Addr(), 4, uintptr(count), uintptr(pListOfEEs), uintptr(oldAcl), uintptr(unsafe.Pointer(newAcl)), 0, 0)
+ if r1 != 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
diff --git a/vendor/github.com/Microsoft/go-winio/vhd/vhd.go b/vendor/github.com/Microsoft/go-winio/vhd/vhd.go
index 229ac2556..91083a388 100644
--- a/vendor/github.com/Microsoft/go-winio/vhd/vhd.go
+++ b/vendor/github.com/Microsoft/go-winio/vhd/vhd.go
@@ -2,150 +2,323 @@
package vhd
-import "syscall"
+import (
+ "fmt"
+ "syscall"
+
+ "github.com/Microsoft/go-winio/pkg/guid"
+ "github.com/pkg/errors"
+ "golang.org/x/sys/windows"
+)
//go:generate go run mksyscall_windows.go -output zvhd.go vhd.go
-//sys createVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *syscall.Overlapped, handle *syscall.Handle) (err error) [failretval != 0] = VirtDisk.CreateVirtualDisk
-//sys openVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) [failretval != 0] = VirtDisk.OpenVirtualDisk
-//sys detachVirtualDisk(handle syscall.Handle, flags uint32, providerSpecificFlags uint32) (err error) [failretval != 0] = VirtDisk.DetachVirtualDisk
-
-type virtualStorageType struct {
- DeviceID uint32
- VendorID [16]byte
-}
+//sys createVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, createVirtualDiskFlags uint32, providerSpecificFlags uint32, parameters *CreateVirtualDiskParameters, overlapped *syscall.Overlapped, handle *syscall.Handle) (err error) [failretval != 0] = virtdisk.CreateVirtualDisk
+//sys openVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, openVirtualDiskFlags uint32, parameters *OpenVirtualDiskParameters, handle *syscall.Handle) (err error) [failretval != 0] = virtdisk.OpenVirtualDisk
+//sys attachVirtualDisk(handle syscall.Handle, securityDescriptor *uintptr, attachVirtualDiskFlag uint32, providerSpecificFlags uint32, parameters *AttachVirtualDiskParameters, overlapped *syscall.Overlapped) (err error) [failretval != 0] = virtdisk.AttachVirtualDisk
+//sys detachVirtualDisk(handle syscall.Handle, detachVirtualDiskFlags uint32, providerSpecificFlags uint32) (err error) [failretval != 0] = virtdisk.DetachVirtualDisk
+//sys getVirtualDiskPhysicalPath(handle syscall.Handle, diskPathSizeInBytes *uint32, buffer *uint16) (err error) [failretval != 0] = virtdisk.GetVirtualDiskPhysicalPath
type (
- createVirtualDiskFlag uint32
- VirtualDiskAccessMask uint32
+ CreateVirtualDiskFlag uint32
VirtualDiskFlag uint32
+ AttachVirtualDiskFlag uint32
+ DetachVirtualDiskFlag uint32
+ VirtualDiskAccessMask uint32
)
-const (
- // Flags for creating a VHD (not exported)
- createVirtualDiskFlagNone createVirtualDiskFlag = 0
- createVirtualDiskFlagFullPhysicalAllocation createVirtualDiskFlag = 1
- createVirtualDiskFlagPreventWritesToSourceDisk createVirtualDiskFlag = 2
- createVirtualDiskFlagDoNotCopyMetadataFromParent createVirtualDiskFlag = 4
-
- // Access Mask for opening a VHD
- VirtualDiskAccessNone VirtualDiskAccessMask = 0
- VirtualDiskAccessAttachRO VirtualDiskAccessMask = 65536
- VirtualDiskAccessAttachRW VirtualDiskAccessMask = 131072
- VirtualDiskAccessDetach VirtualDiskAccessMask = 262144
- VirtualDiskAccessGetInfo VirtualDiskAccessMask = 524288
- VirtualDiskAccessCreate VirtualDiskAccessMask = 1048576
- VirtualDiskAccessMetaOps VirtualDiskAccessMask = 2097152
- VirtualDiskAccessRead VirtualDiskAccessMask = 851968
- VirtualDiskAccessAll VirtualDiskAccessMask = 4128768
- VirtualDiskAccessWritable VirtualDiskAccessMask = 3276800
-
- // Flags for opening a VHD
- OpenVirtualDiskFlagNone VirtualDiskFlag = 0
- OpenVirtualDiskFlagNoParents VirtualDiskFlag = 0x1
- OpenVirtualDiskFlagBlankFile VirtualDiskFlag = 0x2
- OpenVirtualDiskFlagBootDrive VirtualDiskFlag = 0x4
- OpenVirtualDiskFlagCachedIO VirtualDiskFlag = 0x8
- OpenVirtualDiskFlagCustomDiffChain VirtualDiskFlag = 0x10
- OpenVirtualDiskFlagParentCachedIO VirtualDiskFlag = 0x20
- OpenVirtualDiskFlagVhdSetFileOnly VirtualDiskFlag = 0x40
- OpenVirtualDiskFlagIgnoreRelativeParentLocator VirtualDiskFlag = 0x80
- OpenVirtualDiskFlagNoWriteHardening VirtualDiskFlag = 0x100
-)
+type VirtualStorageType struct {
+ DeviceID uint32
+ VendorID guid.GUID
+}
-type createVersion2 struct {
- UniqueID [16]byte // GUID
+type CreateVersion2 struct {
+ UniqueID guid.GUID
MaximumSize uint64
BlockSizeInBytes uint32
SectorSizeInBytes uint32
+ PhysicalSectorSizeInByte uint32
ParentPath *uint16 // string
SourcePath *uint16 // string
OpenFlags uint32
- ParentVirtualStorageType virtualStorageType
- SourceVirtualStorageType virtualStorageType
- ResiliencyGUID [16]byte // GUID
+ ParentVirtualStorageType VirtualStorageType
+ SourceVirtualStorageType VirtualStorageType
+ ResiliencyGUID guid.GUID
}
-type createVirtualDiskParameters struct {
+type CreateVirtualDiskParameters struct {
Version uint32 // Must always be set to 2
- Version2 createVersion2
+ Version2 CreateVersion2
}
-type openVersion2 struct {
- GetInfoOnly int32 // bool but 4-byte aligned
- ReadOnly int32 // bool but 4-byte aligned
- ResiliencyGUID [16]byte // GUID
+type OpenVersion2 struct {
+ GetInfoOnly bool
+ ReadOnly bool
+ ResiliencyGUID guid.GUID
}
-type openVirtualDiskParameters struct {
+type OpenVirtualDiskParameters struct {
Version uint32 // Must always be set to 2
- Version2 openVersion2
+ Version2 OpenVersion2
}
-// CreateVhdx will create a simple vhdx file at the given path using default values.
-func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error {
- var (
- defaultType virtualStorageType
- handle syscall.Handle
- )
+type AttachVersion2 struct {
+ RestrictedOffset uint64
+ RestrictedLength uint64
+}
+
+type AttachVirtualDiskParameters struct {
+ Version uint32 // Must always be set to 2
+ Version2 AttachVersion2
+}
+
+const (
+ VIRTUAL_STORAGE_TYPE_DEVICE_VHDX = 0x3
+
+ // Access Mask for opening a VHD
+ VirtualDiskAccessNone VirtualDiskAccessMask = 0x00000000
+ VirtualDiskAccessAttachRO VirtualDiskAccessMask = 0x00010000
+ VirtualDiskAccessAttachRW VirtualDiskAccessMask = 0x00020000
+ VirtualDiskAccessDetach VirtualDiskAccessMask = 0x00040000
+ VirtualDiskAccessGetInfo VirtualDiskAccessMask = 0x00080000
+ VirtualDiskAccessCreate VirtualDiskAccessMask = 0x00100000
+ VirtualDiskAccessMetaOps VirtualDiskAccessMask = 0x00200000
+ VirtualDiskAccessRead VirtualDiskAccessMask = 0x000d0000
+ VirtualDiskAccessAll VirtualDiskAccessMask = 0x003f0000
+ VirtualDiskAccessWritable VirtualDiskAccessMask = 0x00320000
- parameters := createVirtualDiskParameters{
+ // Flags for creating a VHD
+ CreateVirtualDiskFlagNone CreateVirtualDiskFlag = 0x0
+ CreateVirtualDiskFlagFullPhysicalAllocation CreateVirtualDiskFlag = 0x1
+ CreateVirtualDiskFlagPreventWritesToSourceDisk CreateVirtualDiskFlag = 0x2
+ CreateVirtualDiskFlagDoNotCopyMetadataFromParent CreateVirtualDiskFlag = 0x4
+ CreateVirtualDiskFlagCreateBackingStorage CreateVirtualDiskFlag = 0x8
+ CreateVirtualDiskFlagUseChangeTrackingSourceLimit CreateVirtualDiskFlag = 0x10
+ CreateVirtualDiskFlagPreserveParentChangeTrackingState CreateVirtualDiskFlag = 0x20
+ CreateVirtualDiskFlagVhdSetUseOriginalBackingStorage CreateVirtualDiskFlag = 0x40
+ CreateVirtualDiskFlagSparseFile CreateVirtualDiskFlag = 0x80
+ CreateVirtualDiskFlagPmemCompatible CreateVirtualDiskFlag = 0x100
+ CreateVirtualDiskFlagSupportCompressedVolumes CreateVirtualDiskFlag = 0x200
+
+ // Flags for opening a VHD
+ OpenVirtualDiskFlagNone VirtualDiskFlag = 0x00000000
+ OpenVirtualDiskFlagNoParents VirtualDiskFlag = 0x00000001
+ OpenVirtualDiskFlagBlankFile VirtualDiskFlag = 0x00000002
+ OpenVirtualDiskFlagBootDrive VirtualDiskFlag = 0x00000004
+ OpenVirtualDiskFlagCachedIO VirtualDiskFlag = 0x00000008
+ OpenVirtualDiskFlagCustomDiffChain VirtualDiskFlag = 0x00000010
+ OpenVirtualDiskFlagParentCachedIO VirtualDiskFlag = 0x00000020
+ OpenVirtualDiskFlagVhdsetFileOnly VirtualDiskFlag = 0x00000040
+ OpenVirtualDiskFlagIgnoreRelativeParentLocator VirtualDiskFlag = 0x00000080
+ OpenVirtualDiskFlagNoWriteHardening VirtualDiskFlag = 0x00000100
+ OpenVirtualDiskFlagSupportCompressedVolumes VirtualDiskFlag = 0x00000200
+
+ // Flags for attaching a VHD
+ AttachVirtualDiskFlagNone AttachVirtualDiskFlag = 0x00000000
+ AttachVirtualDiskFlagReadOnly AttachVirtualDiskFlag = 0x00000001
+ AttachVirtualDiskFlagNoDriveLetter AttachVirtualDiskFlag = 0x00000002
+ AttachVirtualDiskFlagPermanentLifetime AttachVirtualDiskFlag = 0x00000004
+ AttachVirtualDiskFlagNoLocalHost AttachVirtualDiskFlag = 0x00000008
+ AttachVirtualDiskFlagNoSecurityDescriptor AttachVirtualDiskFlag = 0x00000010
+ AttachVirtualDiskFlagBypassDefaultEncryptionPolicy AttachVirtualDiskFlag = 0x00000020
+ AttachVirtualDiskFlagNonPnp AttachVirtualDiskFlag = 0x00000040
+ AttachVirtualDiskFlagRestrictedRange AttachVirtualDiskFlag = 0x00000080
+ AttachVirtualDiskFlagSinglePartition AttachVirtualDiskFlag = 0x00000100
+ AttachVirtualDiskFlagRegisterVolume AttachVirtualDiskFlag = 0x00000200
+
+ // Flags for detaching a VHD
+ DetachVirtualDiskFlagNone DetachVirtualDiskFlag = 0x0
+)
+
+// CreateVhdx is a helper function to create a simple vhdx file at the given path using
+// default values.
+func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error {
+ params := CreateVirtualDiskParameters{
Version: 2,
- Version2: createVersion2{
+ Version2: CreateVersion2{
MaximumSize: uint64(maxSizeInGb) * 1024 * 1024 * 1024,
BlockSizeInBytes: blockSizeInMb * 1024 * 1024,
},
}
- if err := createVirtualDisk(
- &defaultType,
- path,
- uint32(VirtualDiskAccessNone),
- nil,
- uint32(createVirtualDiskFlagNone),
- 0,
- &parameters,
- nil,
- &handle); err != nil {
+ handle, err := CreateVirtualDisk(path, VirtualDiskAccessNone, CreateVirtualDiskFlagNone, &params)
+ if err != nil {
return err
}
if err := syscall.CloseHandle(handle); err != nil {
return err
}
+ return nil
+}
+// DetachVirtualDisk detaches a virtual hard disk by handle.
+func DetachVirtualDisk(handle syscall.Handle) (err error) {
+ if err := detachVirtualDisk(handle, 0, 0); err != nil {
+ return errors.Wrap(err, "failed to detach virtual disk")
+ }
return nil
}
-// DetachVhd detaches a mounted container layer vhd found at `path`.
+// DetachVhd detaches a vhd found at `path`.
func DetachVhd(path string) error {
handle, err := OpenVirtualDisk(
path,
VirtualDiskAccessNone,
- OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator)
+ OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator,
+ )
+ if err != nil {
+ return err
+ }
+ defer syscall.CloseHandle(handle)
+ return DetachVirtualDisk(handle)
+}
+
+// AttachVirtualDisk attaches a virtual hard disk for use.
+func AttachVirtualDisk(handle syscall.Handle, attachVirtualDiskFlag AttachVirtualDiskFlag, parameters *AttachVirtualDiskParameters) (err error) {
+ if parameters.Version != 2 {
+ return fmt.Errorf("only version 2 VHDs are supported, found version: %d", parameters.Version)
+ }
+ if err := attachVirtualDisk(
+ handle,
+ nil,
+ uint32(attachVirtualDiskFlag),
+ 0,
+ parameters,
+ nil,
+ ); err != nil {
+ return errors.Wrap(err, "failed to attach virtual disk")
+ }
+ return nil
+}
+// AttachVhd attaches a virtual hard disk at `path` for use.
+func AttachVhd(path string) (err error) {
+ handle, err := OpenVirtualDisk(
+ path,
+ VirtualDiskAccessNone,
+ OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator,
+ )
if err != nil {
return err
}
+
defer syscall.CloseHandle(handle)
- return detachVirtualDisk(handle, 0, 0)
+ params := AttachVirtualDiskParameters{Version: 2}
+ if err := AttachVirtualDisk(
+ handle,
+ AttachVirtualDiskFlagNone,
+ &params,
+ ); err != nil {
+ return errors.Wrap(err, "failed to attach virtual disk")
+ }
+ return nil
}
// OpenVirtualDisk obtains a handle to a VHD opened with supplied access mask and flags.
-func OpenVirtualDisk(path string, accessMask VirtualDiskAccessMask, flag VirtualDiskFlag) (syscall.Handle, error) {
+func OpenVirtualDisk(vhdPath string, virtualDiskAccessMask VirtualDiskAccessMask, openVirtualDiskFlags VirtualDiskFlag) (syscall.Handle, error) {
+ parameters := OpenVirtualDiskParameters{Version: 2}
+ handle, err := OpenVirtualDiskWithParameters(
+ vhdPath,
+ virtualDiskAccessMask,
+ openVirtualDiskFlags,
+ &parameters,
+ )
+ if err != nil {
+ return 0, err
+ }
+ return handle, nil
+}
+
+// OpenVirtualDiskWithParameters obtains a handle to a VHD opened with supplied access mask, flags and parameters.
+func OpenVirtualDiskWithParameters(vhdPath string, virtualDiskAccessMask VirtualDiskAccessMask, openVirtualDiskFlags VirtualDiskFlag, parameters *OpenVirtualDiskParameters) (syscall.Handle, error) {
var (
- defaultType virtualStorageType
handle syscall.Handle
+ defaultType VirtualStorageType
)
- parameters := openVirtualDiskParameters{Version: 2}
+ if parameters.Version != 2 {
+ return handle, fmt.Errorf("only version 2 VHDs are supported, found version: %d", parameters.Version)
+ }
if err := openVirtualDisk(
&defaultType,
+ vhdPath,
+ uint32(virtualDiskAccessMask),
+ uint32(openVirtualDiskFlags),
+ parameters,
+ &handle,
+ ); err != nil {
+ return 0, errors.Wrap(err, "failed to open virtual disk")
+ }
+ return handle, nil
+}
+
+// CreateVirtualDisk creates a virtual harddisk and returns a handle to the disk.
+func CreateVirtualDisk(path string, virtualDiskAccessMask VirtualDiskAccessMask, createVirtualDiskFlags CreateVirtualDiskFlag, parameters *CreateVirtualDiskParameters) (syscall.Handle, error) {
+ var (
+ handle syscall.Handle
+ defaultType VirtualStorageType
+ )
+ if parameters.Version != 2 {
+ return handle, fmt.Errorf("only version 2 VHDs are supported, found version: %d", parameters.Version)
+ }
+
+ if err := createVirtualDisk(
+ &defaultType,
path,
- uint32(accessMask),
- uint32(flag),
- &parameters,
- &handle); err != nil {
- return 0, err
+ uint32(virtualDiskAccessMask),
+ nil,
+ uint32(createVirtualDiskFlags),
+ 0,
+ parameters,
+ nil,
+ &handle,
+ ); err != nil {
+ return handle, errors.Wrap(err, "failed to create virtual disk")
}
return handle, nil
}
+
+// GetVirtualDiskPhysicalPath takes a handle to a virtual hard disk and returns the physical
+// path of the disk on the machine. This path is in the form \\.\PhysicalDriveX where X is an integer
+// that represents the particular enumeration of the physical disk on the caller's system.
+func GetVirtualDiskPhysicalPath(handle syscall.Handle) (_ string, err error) {
+ var (
+ diskPathSizeInBytes uint32 = 256 * 2 // max path length 256 wide chars
+ diskPhysicalPathBuf [256]uint16
+ )
+ if err := getVirtualDiskPhysicalPath(
+ handle,
+ &diskPathSizeInBytes,
+ &diskPhysicalPathBuf[0],
+ ); err != nil {
+ return "", errors.Wrap(err, "failed to get disk physical path")
+ }
+ return windows.UTF16ToString(diskPhysicalPathBuf[:]), nil
+}
+
+// CreateDiffVhd is a helper function to create a differencing virtual disk.
+func CreateDiffVhd(diffVhdPath, baseVhdPath string, blockSizeInMB uint32) error {
+ // Setting `ParentPath` is how to signal to create a differencing disk.
+ createParams := &CreateVirtualDiskParameters{
+ Version: 2,
+ Version2: CreateVersion2{
+ ParentPath: windows.StringToUTF16Ptr(baseVhdPath),
+ BlockSizeInBytes: blockSizeInMB * 1024 * 1024,
+ OpenFlags: uint32(OpenVirtualDiskFlagCachedIO),
+ },
+ }
+
+ vhdHandle, err := CreateVirtualDisk(
+ diffVhdPath,
+ VirtualDiskAccessNone,
+ CreateVirtualDiskFlagNone,
+ createParams,
+ )
+ if err != nil {
+ return fmt.Errorf("failed to create differencing vhd: %s", err)
+ }
+ if err := syscall.CloseHandle(vhdHandle); err != nil {
+ return fmt.Errorf("failed to close differencing vhd handle: %s", err)
+ }
+ return nil
+}
diff --git a/vendor/github.com/Microsoft/go-winio/vhd/zvhd.go b/vendor/github.com/Microsoft/go-winio/vhd/zvhd.go
index 00599ea49..54c94db77 100644
--- a/vendor/github.com/Microsoft/go-winio/vhd/zvhd.go
+++ b/vendor/github.com/Microsoft/go-winio/vhd/zvhd.go
@@ -37,24 +37,26 @@ func errnoErr(e syscall.Errno) error {
}
var (
- modVirtDisk = windows.NewLazySystemDLL("VirtDisk.dll")
+ modvirtdisk = windows.NewLazySystemDLL("virtdisk.dll")
- procCreateVirtualDisk = modVirtDisk.NewProc("CreateVirtualDisk")
- procOpenVirtualDisk = modVirtDisk.NewProc("OpenVirtualDisk")
- procDetachVirtualDisk = modVirtDisk.NewProc("DetachVirtualDisk")
+ procCreateVirtualDisk = modvirtdisk.NewProc("CreateVirtualDisk")
+ procOpenVirtualDisk = modvirtdisk.NewProc("OpenVirtualDisk")
+ procAttachVirtualDisk = modvirtdisk.NewProc("AttachVirtualDisk")
+ procDetachVirtualDisk = modvirtdisk.NewProc("DetachVirtualDisk")
+ procGetVirtualDiskPhysicalPath = modvirtdisk.NewProc("GetVirtualDiskPhysicalPath")
)
-func createVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *syscall.Overlapped, handle *syscall.Handle) (err error) {
+func createVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, createVirtualDiskFlags uint32, providerSpecificFlags uint32, parameters *CreateVirtualDiskParameters, overlapped *syscall.Overlapped, handle *syscall.Handle) (err error) {
var _p0 *uint16
_p0, err = syscall.UTF16PtrFromString(path)
if err != nil {
return
}
- return _createVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, securityDescriptor, flags, providerSpecificFlags, parameters, o, handle)
+ return _createVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, securityDescriptor, createVirtualDiskFlags, providerSpecificFlags, parameters, overlapped, handle)
}
-func _createVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *syscall.Overlapped, handle *syscall.Handle) (err error) {
- r1, _, e1 := syscall.Syscall9(procCreateVirtualDisk.Addr(), 9, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(unsafe.Pointer(securityDescriptor)), uintptr(flags), uintptr(providerSpecificFlags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(handle)))
+func _createVirtualDisk(virtualStorageType *VirtualStorageType, path *uint16, virtualDiskAccessMask uint32, securityDescriptor *uintptr, createVirtualDiskFlags uint32, providerSpecificFlags uint32, parameters *CreateVirtualDiskParameters, overlapped *syscall.Overlapped, handle *syscall.Handle) (err error) {
+ r1, _, e1 := syscall.Syscall9(procCreateVirtualDisk.Addr(), 9, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(unsafe.Pointer(securityDescriptor)), uintptr(createVirtualDiskFlags), uintptr(providerSpecificFlags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(handle)))
if r1 != 0 {
if e1 != 0 {
err = errnoErr(e1)
@@ -65,17 +67,17 @@ func _createVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, vi
return
}
-func openVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) {
+func openVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, openVirtualDiskFlags uint32, parameters *OpenVirtualDiskParameters, handle *syscall.Handle) (err error) {
var _p0 *uint16
_p0, err = syscall.UTF16PtrFromString(path)
if err != nil {
return
}
- return _openVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, flags, parameters, handle)
+ return _openVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, openVirtualDiskFlags, parameters, handle)
}
-func _openVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) {
- r1, _, e1 := syscall.Syscall6(procOpenVirtualDisk.Addr(), 6, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(flags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(handle)))
+func _openVirtualDisk(virtualStorageType *VirtualStorageType, path *uint16, virtualDiskAccessMask uint32, openVirtualDiskFlags uint32, parameters *OpenVirtualDiskParameters, handle *syscall.Handle) (err error) {
+ r1, _, e1 := syscall.Syscall6(procOpenVirtualDisk.Addr(), 6, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(openVirtualDiskFlags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(handle)))
if r1 != 0 {
if e1 != 0 {
err = errnoErr(e1)
@@ -86,8 +88,32 @@ func _openVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, virt
return
}
-func detachVirtualDisk(handle syscall.Handle, flags uint32, providerSpecificFlags uint32) (err error) {
- r1, _, e1 := syscall.Syscall(procDetachVirtualDisk.Addr(), 3, uintptr(handle), uintptr(flags), uintptr(providerSpecificFlags))
+func attachVirtualDisk(handle syscall.Handle, securityDescriptor *uintptr, attachVirtualDiskFlag uint32, providerSpecificFlags uint32, parameters *AttachVirtualDiskParameters, overlapped *syscall.Overlapped) (err error) {
+ r1, _, e1 := syscall.Syscall6(procAttachVirtualDisk.Addr(), 6, uintptr(handle), uintptr(unsafe.Pointer(securityDescriptor)), uintptr(attachVirtualDiskFlag), uintptr(providerSpecificFlags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(overlapped)))
+ if r1 != 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func detachVirtualDisk(handle syscall.Handle, detachVirtualDiskFlags uint32, providerSpecificFlags uint32) (err error) {
+ r1, _, e1 := syscall.Syscall(procDetachVirtualDisk.Addr(), 3, uintptr(handle), uintptr(detachVirtualDiskFlags), uintptr(providerSpecificFlags))
+ if r1 != 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func getVirtualDiskPhysicalPath(handle syscall.Handle, diskPathSizeInBytes *uint32, buffer *uint16) (err error) {
+ r1, _, e1 := syscall.Syscall(procGetVirtualDiskPhysicalPath.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(diskPathSizeInBytes)), uintptr(unsafe.Pointer(buffer)))
if r1 != 0 {
if e1 != 0 {
err = errnoErr(e1)