mirror of https://github.com/docker/cli.git
Merge pull request #3150 from thaJeztah/update_deps
Update various dependencies in preparation of updating moby, buildkit, containerd
This commit is contained in:
commit
12e8782c0c
36
vendor.conf
36
vendor.conf
|
@ -2,12 +2,12 @@ cloud.google.com/go ceeb313ad77b789a7fa5287b36a1
|
||||||
github.com/Azure/go-ansiterm d185dfc1b5a126116ea5a19e148e29d16b4574c9
|
github.com/Azure/go-ansiterm d185dfc1b5a126116ea5a19e148e29d16b4574c9
|
||||||
github.com/beorn7/perks 37c8de3658fcb183f997c4e13e8337516ab753e6 # v1.0.1
|
github.com/beorn7/perks 37c8de3658fcb183f997c4e13e8337516ab753e6 # v1.0.1
|
||||||
github.com/cespare/xxhash/v2 d7df74196a9e781ede915320c11c378c1b2f3a1f # v2.1.1
|
github.com/cespare/xxhash/v2 d7df74196a9e781ede915320c11c378c1b2f3a1f # v2.1.1
|
||||||
github.com/containerd/console 5d7e1412f07b502a01029ea20e20e0d2be31fa7c # v1.0.1
|
github.com/containerd/cgroups b9de8a2212026c07cec67baf3323f1fc0121e048 # v1.0.1
|
||||||
|
github.com/containerd/console 2f1e3d2b6afd18e8b2077816c711205a0b4d8769 # v1.0.2
|
||||||
github.com/containerd/containerd 0edc412565dcc6e3d6125ff9e4b009ad4b89c638 # master (v1.5.0-dev)
|
github.com/containerd/containerd 0edc412565dcc6e3d6125ff9e4b009ad4b89c638 # master (v1.5.0-dev)
|
||||||
github.com/containerd/continuity efbc4488d8fe1bdc16bde3b2d2990d9b3a899165
|
github.com/containerd/continuity bce1c3f9669b6f3e7f6656ee715b0b4d75fa64a6 # v0.1.0
|
||||||
github.com/containerd/cgroups 0b889c03f102012f1d93a97ddd3ef71cd6f4f510
|
github.com/containerd/typeurl 5e43fb8b75ed2f2305fc04e6918c8d10636771bc # v1.0.2
|
||||||
github.com/containerd/typeurl cd3ce7159eae562a4f60ceff37dada11a939d247 # v1.0.1
|
github.com/coreos/etcd 2c834459e1aab78a5d5219c7dfe42335fc4b617a # v3.3.25
|
||||||
github.com/coreos/etcd d57e8b8d97adfc4a6c224fe116714bf1a1f3beb9 # v3.3.12
|
|
||||||
github.com/cpuguy83/go-md2man/v2 f79a8a8ca69da163eee19ab442bedad7a35bba5a # v2.0.0
|
github.com/cpuguy83/go-md2man/v2 f79a8a8ca69da163eee19ab442bedad7a35bba5a # v2.0.0
|
||||||
github.com/creack/pty 2a38352e8b4d7ab6c336eef107e42a55e72e7fbc # v1.1.11
|
github.com/creack/pty 2a38352e8b4d7ab6c336eef107e42a55e72e7fbc # v1.1.11
|
||||||
github.com/davecgh/go-spew 8991bc29aa16c548c550c7ff78260e27b9ab7c73 # v1.1.1
|
github.com/davecgh/go-spew 8991bc29aa16c548c550c7ff78260e27b9ab7c73 # v1.1.1
|
||||||
|
@ -25,7 +25,7 @@ github.com/evanphx/json-patch 72bf35d0ff611848c1dc9df0f976
|
||||||
github.com/fvbommel/sortorder 26fad50c6b32a3064c09ed089865c16f2f3615f6 # v1.0.2
|
github.com/fvbommel/sortorder 26fad50c6b32a3064c09ed089865c16f2f3615f6 # v1.0.2
|
||||||
github.com/gofrs/flock 6caa7350c26b838538005fae7dbee4e69d9398db # v0.7.3
|
github.com/gofrs/flock 6caa7350c26b838538005fae7dbee4e69d9398db # v0.7.3
|
||||||
github.com/gogo/googleapis 01e0f9cca9b92166042241267ee2a5cdf5cff46c # v1.3.2
|
github.com/gogo/googleapis 01e0f9cca9b92166042241267ee2a5cdf5cff46c # v1.3.2
|
||||||
github.com/gogo/protobuf 5628607bb4c51c3157aacc3a50f0ab707582b805 # v1.3.1
|
github.com/gogo/protobuf b03c65ea87cdc3521ede29f62fe3ce239267c1bc # v1.3.2
|
||||||
github.com/golang/glog 23def4e6c14b4da8ac2ed8007337bc5eb5007998
|
github.com/golang/glog 23def4e6c14b4da8ac2ed8007337bc5eb5007998
|
||||||
github.com/golang/groupcache 869f871628b6baa9cfbc11732cdf6546b17c1298
|
github.com/golang/groupcache 869f871628b6baa9cfbc11732cdf6546b17c1298
|
||||||
github.com/golang/protobuf 84668698ea25b64748563aa20726db66a6b8d299 # v1.3.5
|
github.com/golang/protobuf 84668698ea25b64748563aa20726db66a6b8d299 # v1.3.5
|
||||||
|
@ -41,21 +41,21 @@ github.com/hashicorp/golang-lru 7f827b33c0f158ec5dfbba01bb0b
|
||||||
github.com/imdario/mergo 1afb36080aec31e0d1528973ebe6721b191b0369 # v0.3.8
|
github.com/imdario/mergo 1afb36080aec31e0d1528973ebe6721b191b0369 # v0.3.8
|
||||||
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0.0
|
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0.0
|
||||||
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
|
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
|
||||||
github.com/json-iterator/go 0ff49de124c6f76f8494e194af75bde0f1a49a29 # 1.1.6
|
github.com/json-iterator/go a1ca0830781e007c66b225121d2cdb3a649421f6 # v1.1.10
|
||||||
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
|
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
|
||||||
github.com/Microsoft/go-winio 5b44b70ab3ab4d291a7c1d28afe7b4afeced0ed4 # v0.4.15
|
github.com/Microsoft/go-winio 5c2e05d71961716a6c392a06ada435aaf5d5302c # v0.4.19
|
||||||
github.com/Microsoft/hcsshim 5bc557dd210ff2caf615e6e22d398123de77fc11 # v0.8.9
|
github.com/Microsoft/hcsshim e811ee705ec77df2ae28857ade553043fb564d91 # v0.8.16
|
||||||
github.com/miekg/pkcs11 210dc1e16747c5ba98a03bcbcf728c38086ea357 # v1.0.3
|
github.com/miekg/pkcs11 210dc1e16747c5ba98a03bcbcf728c38086ea357 # v1.0.3
|
||||||
github.com/mitchellh/mapstructure d16e9488127408e67948eb43b6d3fbb9f222da10 # v1.3.2
|
github.com/mitchellh/mapstructure d16e9488127408e67948eb43b6d3fbb9f222da10 # v1.3.2
|
||||||
github.com/moby/buildkit 8142d66b5ebde79846b869fba30d9d30633e74aa # v0.8.1
|
github.com/moby/buildkit 8142d66b5ebde79846b869fba30d9d30633e74aa # v0.8.1
|
||||||
github.com/moby/sys 1bc8673b57550ddf85262eb0fed0aac651a37dab # symlink/v0.1.0 (latest tag, either mount/vXXX, mountinfo/vXXX or symlink/vXXX)
|
github.com/moby/sys b0f1fd7235275d01bd35cc4421e884e522395f45 # mountinfo/v0.4.1 (latest tag, either mount/vXXX, mountinfo/vXXX or symlink/vXXX)
|
||||||
github.com/moby/term 3f7ff695adc6a35abc925370dd0a4dafb48ec64d
|
github.com/moby/term 3f7ff695adc6a35abc925370dd0a4dafb48ec64d
|
||||||
github.com/modern-go/concurrent bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94 # 1.0.3
|
github.com/modern-go/concurrent bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94 # 1.0.3
|
||||||
github.com/modern-go/reflect2 4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd # 1.0.1
|
github.com/modern-go/reflect2 94122c33edd36123c84d5368cfb2b69df93a0ec8 # v1.0.1
|
||||||
github.com/morikuni/aec 39771216ff4c63d11f5e604076f9c45e8be1067b # v1.0.0
|
github.com/morikuni/aec 39771216ff4c63d11f5e604076f9c45e8be1067b # v1.0.0
|
||||||
github.com/opencontainers/go-digest ea51bea511f75cfa3ef6098cc253c5c3609b037a # v1.0.0
|
github.com/opencontainers/go-digest ea51bea511f75cfa3ef6098cc253c5c3609b037a # v1.0.0
|
||||||
github.com/opencontainers/image-spec d60099175f88c47cd379c4738d158884749ed235 # v1.0.1
|
github.com/opencontainers/image-spec d60099175f88c47cd379c4738d158884749ed235 # v1.0.1
|
||||||
github.com/opencontainers/runc ff819c7e9184c13b7c2607fe6c30ae19403a7aff # v1.0.0-rc92
|
github.com/opencontainers/runc b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7 # v1.0.0-rc95
|
||||||
github.com/opentracing/opentracing-go d34af3eaa63c4d08ab54863a4bdd0daa45212e12 # v1.2.0
|
github.com/opentracing/opentracing-go d34af3eaa63c4d08ab54863a4bdd0daa45212e12 # v1.2.0
|
||||||
github.com/pkg/errors 614d223910a179a466c1767a985424175c39b465 # v0.9.1
|
github.com/pkg/errors 614d223910a179a466c1767a985424175c39b465 # v0.9.1
|
||||||
github.com/prometheus/client_golang 6edbbd9e560190e318cdc5b4d3e630b442858380 # v1.6.0
|
github.com/prometheus/client_golang 6edbbd9e560190e318cdc5b4d3e630b442858380 # v1.6.0
|
||||||
|
@ -68,21 +68,21 @@ github.com/sirupsen/logrus 6699a89a232f3db797f2e2806398
|
||||||
github.com/spf13/cobra 8380ddd3132bdf8fd77731725b550c181dda0aa8 # v1.1.3
|
github.com/spf13/cobra 8380ddd3132bdf8fd77731725b550c181dda0aa8 # v1.1.3
|
||||||
github.com/spf13/pflag 2e9d26c8c37aae03e3f9d4e90b7116f5accb7cab # v1.0.5
|
github.com/spf13/pflag 2e9d26c8c37aae03e3f9d4e90b7116f5accb7cab # v1.0.5
|
||||||
github.com/theupdateframework/notary bf96a202a09a312ae005cd312fc06ff4d2c166ce # v0.7.0-21-gbf96a202
|
github.com/theupdateframework/notary bf96a202a09a312ae005cd312fc06ff4d2c166ce # v0.7.0-21-gbf96a202
|
||||||
github.com/tonistiigi/fsutil 0834f99b7b85462efb69b4f571a4fa3ca7da5ac9
|
github.com/tonistiigi/fsutil d72af97c0eaf93c1d20360e3cb9c63c223675b83
|
||||||
github.com/tonistiigi/go-rosetta f79598599c5d34ea253b56a1d7c89bc6a96de7db
|
github.com/tonistiigi/go-rosetta f79598599c5d34ea253b56a1d7c89bc6a96de7db
|
||||||
github.com/tonistiigi/units 6950e57a87eaf136bbe44ef2ec8e75b9e3569de2
|
github.com/tonistiigi/units 6950e57a87eaf136bbe44ef2ec8e75b9e3569de2
|
||||||
github.com/xeipuuv/gojsonpointer 02993c407bfbf5f6dae44c4f4b1cf6a39b5fc5bb
|
github.com/xeipuuv/gojsonpointer 02993c407bfbf5f6dae44c4f4b1cf6a39b5fc5bb
|
||||||
github.com/xeipuuv/gojsonreference bd5ef7bd5415a7ac448318e64f11a24cd21e594b
|
github.com/xeipuuv/gojsonreference bd5ef7bd5415a7ac448318e64f11a24cd21e594b
|
||||||
github.com/xeipuuv/gojsonschema 82fcdeb203eb6ab2a67d0a623d9c19e5e5a64927 # v1.2.0
|
github.com/xeipuuv/gojsonschema 82fcdeb203eb6ab2a67d0a623d9c19e5e5a64927 # v1.2.0
|
||||||
go.opencensus.io d835ff86be02193d324330acdb7d65546b05f814 # v0.22.3
|
go.opencensus.io d835ff86be02193d324330acdb7d65546b05f814 # v0.22.3
|
||||||
golang.org/x/crypto c1f2f97bffc9c53fc40a1a28a5b460094c0050d9
|
golang.org/x/crypto 0c34fe9e7dc2486962ef9867e3edb3503537209f
|
||||||
golang.org/x/net ab34263943818b32f575efc978a3d24e80b04bd7
|
golang.org/x/net e18ecbb051101a46fc263334b127c89bc7bff7ea
|
||||||
golang.org/x/oauth2 bf48bf16ab8d622ce64ec6ce98d2c98f916b6303
|
golang.org/x/oauth2 bf48bf16ab8d622ce64ec6ce98d2c98f916b6303
|
||||||
golang.org/x/sync cd5d95a43a6e21273425c7ae415d3df9ea832eeb
|
golang.org/x/sync 036812b2e83c0ddf193dd5a34e034151da389d09
|
||||||
golang.org/x/sys 134d130e1a049f4194ae9920ac9f96455cde360d
|
golang.org/x/sys d19ff857e887eacb631721f188c7d365c2331456
|
||||||
golang.org/x/term f5c789dd3221ff39d752ac54467d762de7cfbec6
|
golang.org/x/term f5c789dd3221ff39d752ac54467d762de7cfbec6
|
||||||
golang.org/x/text 23ae387dee1f90d29a23c0e87ee0b46038fbed0e # v0.3.3
|
golang.org/x/text 23ae387dee1f90d29a23c0e87ee0b46038fbed0e # v0.3.3
|
||||||
golang.org/x/time 555d28b269f0569763d25dbe1a237ae74c6bcc82
|
golang.org/x/time 3af7569d3a1e776fc2a3c1cec133b43105ea9c2e
|
||||||
google.golang.org/genproto 3f1135a288c9a07e340ae8ba4cc6c7065a3160e8
|
google.golang.org/genproto 3f1135a288c9a07e340ae8ba4cc6c7065a3160e8
|
||||||
google.golang.org/grpc f495f5b15ae7ccda3b38c53a1bfcde4c1a58a2bc # v1.27.1
|
google.golang.org/grpc f495f5b15ae7ccda3b38c53a1bfcde4c1a58a2bc # v1.27.1
|
||||||
gopkg.in/inf.v0 d2d2541c53f18d2a059457998ce2876cc8e67cbf # v0.9.1
|
gopkg.in/inf.v0 d2d2541c53f18d2a059457998ce2876cc8e67cbf # v0.9.1
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# go-winio
|
# go-winio [![Build Status](https://github.com/microsoft/go-winio/actions/workflows/ci.yml/badge.svg)](https://github.com/microsoft/go-winio/actions/workflows/ci.yml)
|
||||||
|
|
||||||
This repository contains utilities for efficiently performing Win32 IO operations in
|
This repository contains utilities for efficiently performing Win32 IO operations in
|
||||||
Go. Currently, this is focused on accessing named pipes and other file handles, and
|
Go. Currently, this is focused on accessing named pipes and other file handles, and
|
||||||
|
|
|
@ -3,7 +3,7 @@ module github.com/Microsoft/go-winio
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/sirupsen/logrus v1.4.1
|
github.com/sirupsen/logrus v1.7.0
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
package winio
|
package winio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -429,10 +429,10 @@ type PipeConfig struct {
|
||||||
// when the pipe is in message mode.
|
// when the pipe is in message mode.
|
||||||
MessageMode bool
|
MessageMode bool
|
||||||
|
|
||||||
// InputBufferSize specifies the size the input buffer, in bytes.
|
// InputBufferSize specifies the size of the input buffer, in bytes.
|
||||||
InputBufferSize int32
|
InputBufferSize int32
|
||||||
|
|
||||||
// OutputBufferSize specifies the size the input buffer, in bytes.
|
// OutputBufferSize specifies the size of the output buffer, in bytes.
|
||||||
OutputBufferSize int32
|
OutputBufferSize int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
// Package guid provides a GUID type. The backing structure for a GUID is
|
// Package guid provides a GUID type. The backing structure for a GUID is
|
||||||
// identical to that used by the golang.org/x/sys/windows GUID type.
|
// identical to that used by the golang.org/x/sys/windows GUID type.
|
||||||
// There are two main binary encodings used for a GUID, the big-endian encoding,
|
// There are two main binary encodings used for a GUID, the big-endian encoding,
|
||||||
|
|
161
vendor/github.com/Microsoft/go-winio/pkg/security/grantvmgroupaccess.go
generated
vendored
Normal file
161
vendor/github.com/Microsoft/go-winio/pkg/security/grantvmgroupaccess.go
generated
vendored
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
7
vendor/github.com/Microsoft/go-winio/pkg/security/syscall_windows.go
generated
vendored
Normal file
7
vendor/github.com/Microsoft/go-winio/pkg/security/syscall_windows.go
generated
vendored
Normal file
|
@ -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
|
70
vendor/github.com/Microsoft/go-winio/pkg/security/zsyscall_windows.go
generated
vendored
Normal file
70
vendor/github.com/Microsoft/go-winio/pkg/security/zsyscall_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
// Code generated by 'go generate'; 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)
|
||||||
|
errERROR_EINVAL error = syscall.EINVAL
|
||||||
|
)
|
||||||
|
|
||||||
|
// errnoErr returns common boxed Errno values, to prevent
|
||||||
|
// allocations at runtime.
|
||||||
|
func errnoErr(e syscall.Errno) error {
|
||||||
|
switch e {
|
||||||
|
case 0:
|
||||||
|
return errERROR_EINVAL
|
||||||
|
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")
|
||||||
|
procSetEntriesInAclW = modadvapi32.NewProc("SetEntriesInAclW")
|
||||||
|
procSetSecurityInfo = modadvapi32.NewProc("SetSecurityInfo")
|
||||||
|
)
|
||||||
|
|
||||||
|
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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -28,8 +28,9 @@ const (
|
||||||
|
|
||||||
ERROR_NOT_ALL_ASSIGNED syscall.Errno = 1300
|
ERROR_NOT_ALL_ASSIGNED syscall.Errno = 1300
|
||||||
|
|
||||||
SeBackupPrivilege = "SeBackupPrivilege"
|
SeBackupPrivilege = "SeBackupPrivilege"
|
||||||
SeRestorePrivilege = "SeRestorePrivilege"
|
SeRestorePrivilege = "SeRestorePrivilege"
|
||||||
|
SeSecurityPrivilege = "SeSecurityPrivilege"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package winio
|
package winio
|
||||||
|
|
||||||
//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go file.go pipe.go sd.go fileinfo.go privilege.go backup.go hvsock.go
|
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go file.go pipe.go sd.go fileinfo.go privilege.go backup.go hvsock.go
|
||||||
|
|
|
@ -2,150 +2,322 @@
|
||||||
|
|
||||||
package vhd
|
package vhd
|
||||||
|
|
||||||
import "syscall"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
//go:generate go run mksyscall_windows.go -output zvhd.go vhd.go
|
"github.com/Microsoft/go-winio/pkg/guid"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
//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
|
//go:generate go run mksyscall_windows.go -output zvhd_windows.go vhd.go
|
||||||
//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 {
|
//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
|
||||||
DeviceID uint32
|
//sys openVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, openVirtualDiskFlags uint32, parameters *OpenVirtualDiskParameters, handle *syscall.Handle) (err error) [failretval != 0] = virtdisk.OpenVirtualDisk
|
||||||
VendorID [16]byte
|
//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 (
|
type (
|
||||||
createVirtualDiskFlag uint32
|
CreateVirtualDiskFlag uint32
|
||||||
VirtualDiskAccessMask uint32
|
|
||||||
VirtualDiskFlag uint32
|
VirtualDiskFlag uint32
|
||||||
|
AttachVirtualDiskFlag uint32
|
||||||
|
DetachVirtualDiskFlag uint32
|
||||||
|
VirtualDiskAccessMask uint32
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
type VirtualStorageType struct {
|
||||||
// Flags for creating a VHD (not exported)
|
DeviceID uint32
|
||||||
createVirtualDiskFlagNone createVirtualDiskFlag = 0
|
VendorID guid.GUID
|
||||||
createVirtualDiskFlagFullPhysicalAllocation createVirtualDiskFlag = 1
|
}
|
||||||
createVirtualDiskFlagPreventWritesToSourceDisk createVirtualDiskFlag = 2
|
|
||||||
createVirtualDiskFlagDoNotCopyMetadataFromParent createVirtualDiskFlag = 4
|
|
||||||
|
|
||||||
// Access Mask for opening a VHD
|
type CreateVersion2 struct {
|
||||||
VirtualDiskAccessNone VirtualDiskAccessMask = 0
|
UniqueID guid.GUID
|
||||||
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 createVersion2 struct {
|
|
||||||
UniqueID [16]byte // GUID
|
|
||||||
MaximumSize uint64
|
MaximumSize uint64
|
||||||
BlockSizeInBytes uint32
|
BlockSizeInBytes uint32
|
||||||
SectorSizeInBytes uint32
|
SectorSizeInBytes uint32
|
||||||
|
PhysicalSectorSizeInByte uint32
|
||||||
ParentPath *uint16 // string
|
ParentPath *uint16 // string
|
||||||
SourcePath *uint16 // string
|
SourcePath *uint16 // string
|
||||||
OpenFlags uint32
|
OpenFlags uint32
|
||||||
ParentVirtualStorageType virtualStorageType
|
ParentVirtualStorageType VirtualStorageType
|
||||||
SourceVirtualStorageType virtualStorageType
|
SourceVirtualStorageType VirtualStorageType
|
||||||
ResiliencyGUID [16]byte // GUID
|
ResiliencyGUID guid.GUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type createVirtualDiskParameters struct {
|
type CreateVirtualDiskParameters struct {
|
||||||
Version uint32 // Must always be set to 2
|
Version uint32 // Must always be set to 2
|
||||||
Version2 createVersion2
|
Version2 CreateVersion2
|
||||||
}
|
}
|
||||||
|
|
||||||
type openVersion2 struct {
|
type OpenVersion2 struct {
|
||||||
GetInfoOnly int32 // bool but 4-byte aligned
|
GetInfoOnly bool
|
||||||
ReadOnly int32 // bool but 4-byte aligned
|
ReadOnly bool
|
||||||
ResiliencyGUID [16]byte // GUID
|
ResiliencyGUID guid.GUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type openVirtualDiskParameters struct {
|
type OpenVirtualDiskParameters struct {
|
||||||
Version uint32 // Must always be set to 2
|
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.
|
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
|
||||||
|
|
||||||
|
// 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 {
|
func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error {
|
||||||
var (
|
params := CreateVirtualDiskParameters{
|
||||||
defaultType virtualStorageType
|
|
||||||
handle syscall.Handle
|
|
||||||
)
|
|
||||||
|
|
||||||
parameters := createVirtualDiskParameters{
|
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Version2: createVersion2{
|
Version2: CreateVersion2{
|
||||||
MaximumSize: uint64(maxSizeInGb) * 1024 * 1024 * 1024,
|
MaximumSize: uint64(maxSizeInGb) * 1024 * 1024 * 1024,
|
||||||
BlockSizeInBytes: blockSizeInMb * 1024 * 1024,
|
BlockSizeInBytes: blockSizeInMb * 1024 * 1024,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createVirtualDisk(
|
handle, err := CreateVirtualDisk(path, VirtualDiskAccessNone, CreateVirtualDiskFlagNone, ¶ms)
|
||||||
&defaultType,
|
if err != nil {
|
||||||
path,
|
|
||||||
uint32(VirtualDiskAccessNone),
|
|
||||||
nil,
|
|
||||||
uint32(createVirtualDiskFlagNone),
|
|
||||||
0,
|
|
||||||
¶meters,
|
|
||||||
nil,
|
|
||||||
&handle); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syscall.CloseHandle(handle); err != nil {
|
if err := syscall.CloseHandle(handle); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetachVhd detaches a mounted container layer vhd found at `path`.
|
// 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 vhd found at `path`.
|
||||||
func DetachVhd(path string) error {
|
func DetachVhd(path string) error {
|
||||||
handle, err := OpenVirtualDisk(
|
handle, err := OpenVirtualDisk(
|
||||||
path,
|
path,
|
||||||
VirtualDiskAccessNone,
|
VirtualDiskAccessNone,
|
||||||
OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator)
|
OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer syscall.CloseHandle(handle)
|
defer syscall.CloseHandle(handle)
|
||||||
return detachVirtualDisk(handle, 0, 0)
|
return DetachVirtualDisk(handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AttachVirtualDisk attaches a virtual hard disk for use.
|
||||||
|
func AttachVirtualDisk(handle syscall.Handle, attachVirtualDiskFlag AttachVirtualDiskFlag, parameters *AttachVirtualDiskParameters) (err error) {
|
||||||
|
// Supports both version 1 and 2 of the attach parameters as version 2 wasn't present in RS5.
|
||||||
|
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. Attaches using version 2
|
||||||
|
// of the ATTACH_VIRTUAL_DISK_PARAMETERS.
|
||||||
|
func AttachVhd(path string) (err error) {
|
||||||
|
handle, err := OpenVirtualDisk(
|
||||||
|
path,
|
||||||
|
VirtualDiskAccessNone,
|
||||||
|
OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer syscall.CloseHandle(handle)
|
||||||
|
params := AttachVirtualDiskParameters{Version: 2}
|
||||||
|
if err := AttachVirtualDisk(
|
||||||
|
handle,
|
||||||
|
AttachVirtualDiskFlagNone,
|
||||||
|
¶ms,
|
||||||
|
); 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.
|
// 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) {
|
||||||
var (
|
parameters := OpenVirtualDiskParameters{Version: 2}
|
||||||
defaultType virtualStorageType
|
handle, err := OpenVirtualDiskWithParameters(
|
||||||
handle syscall.Handle
|
vhdPath,
|
||||||
)
|
virtualDiskAccessMask,
|
||||||
parameters := openVirtualDiskParameters{Version: 2}
|
openVirtualDiskFlags,
|
||||||
if err := openVirtualDisk(
|
|
||||||
&defaultType,
|
|
||||||
path,
|
|
||||||
uint32(accessMask),
|
|
||||||
uint32(flag),
|
|
||||||
¶meters,
|
¶meters,
|
||||||
&handle); err != nil {
|
)
|
||||||
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return handle, nil
|
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 (
|
||||||
|
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 := 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(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
|
||||||
|
}
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
|
|
||||||
|
|
||||||
package vhd
|
|
||||||
|
|
||||||
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 (
|
|
||||||
modVirtDisk = windows.NewLazySystemDLL("VirtDisk.dll")
|
|
||||||
|
|
||||||
procCreateVirtualDisk = modVirtDisk.NewProc("CreateVirtualDisk")
|
|
||||||
procOpenVirtualDisk = modVirtDisk.NewProc("OpenVirtualDisk")
|
|
||||||
procDetachVirtualDisk = modVirtDisk.NewProc("DetachVirtualDisk")
|
|
||||||
)
|
|
||||||
|
|
||||||
func createVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)))
|
|
||||||
if r1 != 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func openVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, flags 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)))
|
|
||||||
if r1 != 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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))
|
|
||||||
if r1 != 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
// Code generated by 'go generate'; DO NOT EDIT.
|
||||||
|
|
||||||
|
package vhd
|
||||||
|
|
||||||
|
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)
|
||||||
|
errERROR_EINVAL error = syscall.EINVAL
|
||||||
|
)
|
||||||
|
|
||||||
|
// errnoErr returns common boxed Errno values, to prevent
|
||||||
|
// allocations at runtime.
|
||||||
|
func errnoErr(e syscall.Errno) error {
|
||||||
|
switch e {
|
||||||
|
case 0:
|
||||||
|
return errERROR_EINVAL
|
||||||
|
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 (
|
||||||
|
modvirtdisk = windows.NewLazySystemDLL("virtdisk.dll")
|
||||||
|
|
||||||
|
procAttachVirtualDisk = modvirtdisk.NewProc("AttachVirtualDisk")
|
||||||
|
procCreateVirtualDisk = modvirtdisk.NewProc("CreateVirtualDisk")
|
||||||
|
procDetachVirtualDisk = modvirtdisk.NewProc("DetachVirtualDisk")
|
||||||
|
procGetVirtualDiskPhysicalPath = modvirtdisk.NewProc("GetVirtualDiskPhysicalPath")
|
||||||
|
procOpenVirtualDisk = modvirtdisk.NewProc("OpenVirtualDisk")
|
||||||
|
)
|
||||||
|
|
||||||
|
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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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, createVirtualDiskFlags, providerSpecificFlags, parameters, overlapped, 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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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, openVirtualDiskFlags, parameters, 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 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
|
errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
|
||||||
|
errERROR_EINVAL error = syscall.EINVAL
|
||||||
)
|
)
|
||||||
|
|
||||||
// errnoErr returns common boxed Errno values, to prevent
|
// errnoErr returns common boxed Errno values, to prevent
|
||||||
|
@ -26,7 +27,7 @@ var (
|
||||||
func errnoErr(e syscall.Errno) error {
|
func errnoErr(e syscall.Errno) error {
|
||||||
switch e {
|
switch e {
|
||||||
case 0:
|
case 0:
|
||||||
return nil
|
return errERROR_EINVAL
|
||||||
case errnoERROR_IO_PENDING:
|
case errnoERROR_IO_PENDING:
|
||||||
return errERROR_IO_PENDING
|
return errERROR_IO_PENDING
|
||||||
}
|
}
|
||||||
|
@ -37,243 +38,64 @@ func errnoErr(e syscall.Errno) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
|
||||||
modws2_32 = windows.NewLazySystemDLL("ws2_32.dll")
|
|
||||||
modntdll = windows.NewLazySystemDLL("ntdll.dll")
|
|
||||||
modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
|
modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
|
||||||
|
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||||
|
modntdll = windows.NewLazySystemDLL("ntdll.dll")
|
||||||
|
modws2_32 = windows.NewLazySystemDLL("ws2_32.dll")
|
||||||
|
|
||||||
procCancelIoEx = modkernel32.NewProc("CancelIoEx")
|
procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
|
||||||
procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
|
procConvertSecurityDescriptorToStringSecurityDescriptorW = modadvapi32.NewProc("ConvertSecurityDescriptorToStringSecurityDescriptorW")
|
||||||
procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
|
|
||||||
procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
|
|
||||||
procWSAGetOverlappedResult = modws2_32.NewProc("WSAGetOverlappedResult")
|
|
||||||
procConnectNamedPipe = modkernel32.NewProc("ConnectNamedPipe")
|
|
||||||
procCreateNamedPipeW = modkernel32.NewProc("CreateNamedPipeW")
|
|
||||||
procCreateFileW = modkernel32.NewProc("CreateFileW")
|
|
||||||
procGetNamedPipeInfo = modkernel32.NewProc("GetNamedPipeInfo")
|
|
||||||
procGetNamedPipeHandleStateW = modkernel32.NewProc("GetNamedPipeHandleStateW")
|
|
||||||
procLocalAlloc = modkernel32.NewProc("LocalAlloc")
|
|
||||||
procNtCreateNamedPipeFile = modntdll.NewProc("NtCreateNamedPipeFile")
|
|
||||||
procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
|
|
||||||
procRtlDosPathNameToNtPathName_U = modntdll.NewProc("RtlDosPathNameToNtPathName_U")
|
|
||||||
procRtlDefaultNpAcl = modntdll.NewProc("RtlDefaultNpAcl")
|
|
||||||
procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
|
|
||||||
procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
|
procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
|
||||||
procConvertStringSecurityDescriptorToSecurityDescriptorW = modadvapi32.NewProc("ConvertStringSecurityDescriptorToSecurityDescriptorW")
|
procConvertStringSecurityDescriptorToSecurityDescriptorW = modadvapi32.NewProc("ConvertStringSecurityDescriptorToSecurityDescriptorW")
|
||||||
procConvertSecurityDescriptorToStringSecurityDescriptorW = modadvapi32.NewProc("ConvertSecurityDescriptorToStringSecurityDescriptorW")
|
|
||||||
procLocalFree = modkernel32.NewProc("LocalFree")
|
|
||||||
procGetSecurityDescriptorLength = modadvapi32.NewProc("GetSecurityDescriptorLength")
|
procGetSecurityDescriptorLength = modadvapi32.NewProc("GetSecurityDescriptorLength")
|
||||||
procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
|
|
||||||
procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle")
|
|
||||||
procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
|
|
||||||
procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
|
procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
|
||||||
procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
|
procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
|
||||||
procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
|
|
||||||
procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
|
|
||||||
procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
|
|
||||||
procLookupPrivilegeNameW = modadvapi32.NewProc("LookupPrivilegeNameW")
|
|
||||||
procLookupPrivilegeDisplayNameW = modadvapi32.NewProc("LookupPrivilegeDisplayNameW")
|
procLookupPrivilegeDisplayNameW = modadvapi32.NewProc("LookupPrivilegeDisplayNameW")
|
||||||
|
procLookupPrivilegeNameW = modadvapi32.NewProc("LookupPrivilegeNameW")
|
||||||
|
procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
|
||||||
|
procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
|
||||||
|
procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
|
||||||
procBackupRead = modkernel32.NewProc("BackupRead")
|
procBackupRead = modkernel32.NewProc("BackupRead")
|
||||||
procBackupWrite = modkernel32.NewProc("BackupWrite")
|
procBackupWrite = modkernel32.NewProc("BackupWrite")
|
||||||
|
procCancelIoEx = modkernel32.NewProc("CancelIoEx")
|
||||||
|
procConnectNamedPipe = modkernel32.NewProc("ConnectNamedPipe")
|
||||||
|
procCreateFileW = modkernel32.NewProc("CreateFileW")
|
||||||
|
procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
|
||||||
|
procCreateNamedPipeW = modkernel32.NewProc("CreateNamedPipeW")
|
||||||
|
procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
|
||||||
|
procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
|
||||||
|
procGetNamedPipeHandleStateW = modkernel32.NewProc("GetNamedPipeHandleStateW")
|
||||||
|
procGetNamedPipeInfo = modkernel32.NewProc("GetNamedPipeInfo")
|
||||||
|
procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
|
||||||
|
procLocalAlloc = modkernel32.NewProc("LocalAlloc")
|
||||||
|
procLocalFree = modkernel32.NewProc("LocalFree")
|
||||||
|
procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
|
||||||
|
procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle")
|
||||||
|
procNtCreateNamedPipeFile = modntdll.NewProc("NtCreateNamedPipeFile")
|
||||||
|
procRtlDefaultNpAcl = modntdll.NewProc("RtlDefaultNpAcl")
|
||||||
|
procRtlDosPathNameToNtPathName_U = modntdll.NewProc("RtlDosPathNameToNtPathName_U")
|
||||||
|
procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
|
||||||
|
procWSAGetOverlappedResult = modws2_32.NewProc("WSAGetOverlappedResult")
|
||||||
procbind = modws2_32.NewProc("bind")
|
procbind = modws2_32.NewProc("bind")
|
||||||
)
|
)
|
||||||
|
|
||||||
func cancelIoEx(file syscall.Handle, o *syscall.Overlapped) (err error) {
|
func adjustTokenPrivileges(token windows.Token, releaseAll bool, input *byte, outputSize uint32, output *byte, requiredSize *uint32) (success bool, err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(file), uintptr(unsafe.Pointer(o)), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func createIoCompletionPort(file syscall.Handle, port syscall.Handle, key uintptr, threadCount uint32) (newport syscall.Handle, err error) {
|
|
||||||
r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(file), uintptr(port), uintptr(key), uintptr(threadCount), 0, 0)
|
|
||||||
newport = syscall.Handle(r0)
|
|
||||||
if newport == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getQueuedCompletionStatus(port syscall.Handle, bytes *uint32, key *uintptr, o **ioOperation, timeout uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(port), uintptr(unsafe.Pointer(bytes)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(o)), uintptr(timeout), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func setFileCompletionNotificationModes(h syscall.Handle, flags uint8) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(h), uintptr(flags), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func wsaGetOverlappedResult(h syscall.Handle, o *syscall.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) {
|
|
||||||
var _p0 uint32
|
var _p0 uint32
|
||||||
if wait {
|
if releaseAll {
|
||||||
_p0 = 1
|
_p0 = 1
|
||||||
} else {
|
|
||||||
_p0 = 0
|
|
||||||
}
|
}
|
||||||
r1, _, e1 := syscall.Syscall6(procWSAGetOverlappedResult.Addr(), 5, uintptr(h), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(bytes)), uintptr(_p0), uintptr(unsafe.Pointer(flags)), 0)
|
r0, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(input)), uintptr(outputSize), uintptr(unsafe.Pointer(output)), uintptr(unsafe.Pointer(requiredSize)))
|
||||||
|
success = r0 != 0
|
||||||
|
if true {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertSecurityDescriptorToStringSecurityDescriptor(sd *byte, revision uint32, secInfo uint32, sddl **uint16, sddlSize *uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procConvertSecurityDescriptorToStringSecurityDescriptorW.Addr(), 5, uintptr(unsafe.Pointer(sd)), uintptr(revision), uintptr(secInfo), uintptr(unsafe.Pointer(sddl)), uintptr(unsafe.Pointer(sddlSize)), 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func connectNamedPipe(pipe syscall.Handle, o *syscall.Overlapped) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall(procConnectNamedPipe.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(o)), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func createNamedPipe(name string, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
|
|
||||||
var _p0 *uint16
|
|
||||||
_p0, err = syscall.UTF16PtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return _createNamedPipe(_p0, flags, pipeMode, maxInstances, outSize, inSize, defaultTimeout, sa)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _createNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
|
|
||||||
r0, _, e1 := syscall.Syscall9(procCreateNamedPipeW.Addr(), 8, uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(pipeMode), uintptr(maxInstances), uintptr(outSize), uintptr(inSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)), 0)
|
|
||||||
handle = syscall.Handle(r0)
|
|
||||||
if handle == syscall.InvalidHandle {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func createFile(name string, access uint32, mode uint32, sa *syscall.SecurityAttributes, createmode uint32, attrs uint32, templatefile syscall.Handle) (handle syscall.Handle, err error) {
|
|
||||||
var _p0 *uint16
|
|
||||||
_p0, err = syscall.UTF16PtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return _createFile(_p0, access, mode, sa, createmode, attrs, templatefile)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _createFile(name *uint16, access uint32, mode uint32, sa *syscall.SecurityAttributes, createmode uint32, attrs uint32, templatefile syscall.Handle) (handle syscall.Handle, err error) {
|
|
||||||
r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
|
|
||||||
handle = syscall.Handle(r0)
|
|
||||||
if handle == syscall.InvalidHandle {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getNamedPipeInfo(pipe syscall.Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procGetNamedPipeInfo.Addr(), 5, uintptr(pipe), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(outSize)), uintptr(unsafe.Pointer(inSize)), uintptr(unsafe.Pointer(maxInstances)), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getNamedPipeHandleState(pipe syscall.Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall9(procGetNamedPipeHandleStateW.Addr(), 7, uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(curInstances)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), uintptr(unsafe.Pointer(userName)), uintptr(maxUserNameSize), 0, 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func localAlloc(uFlags uint32, length uint32) (ptr uintptr) {
|
|
||||||
r0, _, _ := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(uFlags), uintptr(length), 0)
|
|
||||||
ptr = uintptr(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func ntCreateNamedPipeFile(pipe *syscall.Handle, access uint32, oa *objectAttributes, iosb *ioStatusBlock, share uint32, disposition uint32, options uint32, typ uint32, readMode uint32, completionMode uint32, maxInstances uint32, inboundQuota uint32, outputQuota uint32, timeout *int64) (status ntstatus) {
|
|
||||||
r0, _, _ := syscall.Syscall15(procNtCreateNamedPipeFile.Addr(), 14, uintptr(unsafe.Pointer(pipe)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(share), uintptr(disposition), uintptr(options), uintptr(typ), uintptr(readMode), uintptr(completionMode), uintptr(maxInstances), uintptr(inboundQuota), uintptr(outputQuota), uintptr(unsafe.Pointer(timeout)), 0)
|
|
||||||
status = ntstatus(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func rtlNtStatusToDosError(status ntstatus) (winerr error) {
|
|
||||||
r0, _, _ := syscall.Syscall(procRtlNtStatusToDosErrorNoTeb.Addr(), 1, uintptr(status), 0, 0)
|
|
||||||
if r0 != 0 {
|
|
||||||
winerr = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func rtlDosPathNameToNtPathName(name *uint16, ntName *unicodeString, filePart uintptr, reserved uintptr) (status ntstatus) {
|
|
||||||
r0, _, _ := syscall.Syscall6(procRtlDosPathNameToNtPathName_U.Addr(), 4, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(ntName)), uintptr(filePart), uintptr(reserved), 0, 0)
|
|
||||||
status = ntstatus(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func rtlDefaultNpAcl(dacl *uintptr) (status ntstatus) {
|
|
||||||
r0, _, _ := syscall.Syscall(procRtlDefaultNpAcl.Addr(), 1, uintptr(unsafe.Pointer(dacl)), 0, 0)
|
|
||||||
status = ntstatus(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupAccountName(systemName *uint16, accountName string, sid *byte, sidSize *uint32, refDomain *uint16, refDomainSize *uint32, sidNameUse *uint32) (err error) {
|
|
||||||
var _p0 *uint16
|
|
||||||
_p0, err = syscall.UTF16PtrFromString(accountName)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return _lookupAccountName(systemName, _p0, sid, sidSize, refDomain, refDomainSize, sidNameUse)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _lookupAccountName(systemName *uint16, accountName *uint16, sid *byte, sidSize *uint32, refDomain *uint16, refDomainSize *uint32, sidNameUse *uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidSize)), uintptr(unsafe.Pointer(refDomain)), uintptr(unsafe.Pointer(refDomainSize)), uintptr(unsafe.Pointer(sidNameUse)), 0, 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -281,11 +103,7 @@ func _lookupAccountName(systemName *uint16, accountName *uint16, sid *byte, sidS
|
||||||
func convertSidToStringSid(sid *byte, str **uint16) (err error) {
|
func convertSidToStringSid(sid *byte, str **uint16) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(str)), 0)
|
r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(str)), 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -302,126 +120,73 @@ func convertStringSecurityDescriptorToSecurityDescriptor(str string, revision ui
|
||||||
func _convertStringSecurityDescriptorToSecurityDescriptor(str *uint16, revision uint32, sd *uintptr, size *uint32) (err error) {
|
func _convertStringSecurityDescriptorToSecurityDescriptor(str *uint16, revision uint32, sd *uintptr, size *uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall6(procConvertStringSecurityDescriptorToSecurityDescriptorW.Addr(), 4, uintptr(unsafe.Pointer(str)), uintptr(revision), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(size)), 0, 0)
|
r1, _, e1 := syscall.Syscall6(procConvertStringSecurityDescriptorToSecurityDescriptorW.Addr(), 4, uintptr(unsafe.Pointer(str)), uintptr(revision), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(size)), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertSecurityDescriptorToStringSecurityDescriptor(sd *byte, revision uint32, secInfo uint32, sddl **uint16, sddlSize *uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procConvertSecurityDescriptorToStringSecurityDescriptorW.Addr(), 5, uintptr(unsafe.Pointer(sd)), uintptr(revision), uintptr(secInfo), uintptr(unsafe.Pointer(sddl)), uintptr(unsafe.Pointer(sddlSize)), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func localFree(mem uintptr) {
|
|
||||||
syscall.Syscall(procLocalFree.Addr(), 1, uintptr(mem), 0, 0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getSecurityDescriptorLength(sd uintptr) (len uint32) {
|
func getSecurityDescriptorLength(sd uintptr) (len uint32) {
|
||||||
r0, _, _ := syscall.Syscall(procGetSecurityDescriptorLength.Addr(), 1, uintptr(sd), 0, 0)
|
r0, _, _ := syscall.Syscall(procGetSecurityDescriptorLength.Addr(), 1, uintptr(sd), 0, 0)
|
||||||
len = uint32(r0)
|
len = uint32(r0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFileInformationByHandleEx(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(h), uintptr(class), uintptr(unsafe.Pointer(buffer)), uintptr(size), 0, 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func setFileInformationByHandle(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(h), uintptr(class), uintptr(unsafe.Pointer(buffer)), uintptr(size), 0, 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func adjustTokenPrivileges(token windows.Token, releaseAll bool, input *byte, outputSize uint32, output *byte, requiredSize *uint32) (success bool, err error) {
|
|
||||||
var _p0 uint32
|
|
||||||
if releaseAll {
|
|
||||||
_p0 = 1
|
|
||||||
} else {
|
|
||||||
_p0 = 0
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(input)), uintptr(outputSize), uintptr(unsafe.Pointer(output)), uintptr(unsafe.Pointer(requiredSize)))
|
|
||||||
success = r0 != 0
|
|
||||||
if true {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func impersonateSelf(level uint32) (err error) {
|
func impersonateSelf(level uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(level), 0, 0)
|
r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(level), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func revertToSelf() (err error) {
|
func lookupAccountName(systemName *uint16, accountName string, sid *byte, sidSize *uint32, refDomain *uint16, refDomainSize *uint32, sidNameUse *uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
|
var _p0 *uint16
|
||||||
|
_p0, err = syscall.UTF16PtrFromString(accountName)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _lookupAccountName(systemName, _p0, sid, sidSize, refDomain, refDomainSize, sidNameUse)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _lookupAccountName(systemName *uint16, accountName *uint16, sid *byte, sidSize *uint32, refDomain *uint16, refDomainSize *uint32, sidNameUse *uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidSize)), uintptr(unsafe.Pointer(refDomain)), uintptr(unsafe.Pointer(refDomainSize)), uintptr(unsafe.Pointer(sidNameUse)), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func openThreadToken(thread syscall.Handle, accessMask uint32, openAsSelf bool, token *windows.Token) (err error) {
|
func lookupPrivilegeDisplayName(systemName string, name *uint16, buffer *uint16, size *uint32, languageId *uint32) (err error) {
|
||||||
var _p0 uint32
|
var _p0 *uint16
|
||||||
if openAsSelf {
|
_p0, err = syscall.UTF16PtrFromString(systemName)
|
||||||
_p0 = 1
|
if err != nil {
|
||||||
} else {
|
return
|
||||||
_p0 = 0
|
|
||||||
}
|
}
|
||||||
r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(accessMask), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
|
return _lookupPrivilegeDisplayName(_p0, name, buffer, size, languageId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _lookupPrivilegeDisplayName(systemName *uint16, name *uint16, buffer *uint16, size *uint32, languageId *uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procLookupPrivilegeDisplayNameW.Addr(), 5, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(size)), uintptr(unsafe.Pointer(languageId)), 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentThread() (h syscall.Handle) {
|
func lookupPrivilegeName(systemName string, luid *uint64, buffer *uint16, size *uint32) (err error) {
|
||||||
r0, _, _ := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
|
var _p0 *uint16
|
||||||
h = syscall.Handle(r0)
|
_p0, err = syscall.UTF16PtrFromString(systemName)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _lookupPrivilegeName(_p0, luid, buffer, size)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _lookupPrivilegeName(systemName *uint16, luid *uint64, buffer *uint16, size *uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procLookupPrivilegeNameW.Addr(), 4, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(luid)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(size)), 0, 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,53 +207,27 @@ func lookupPrivilegeValue(systemName string, name string, luid *uint64) (err err
|
||||||
func _lookupPrivilegeValue(systemName *uint16, name *uint16, luid *uint64) (err error) {
|
func _lookupPrivilegeValue(systemName *uint16, name *uint16, luid *uint64) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
|
r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupPrivilegeName(systemName string, luid *uint64, buffer *uint16, size *uint32) (err error) {
|
func openThreadToken(thread syscall.Handle, accessMask uint32, openAsSelf bool, token *windows.Token) (err error) {
|
||||||
var _p0 *uint16
|
var _p0 uint32
|
||||||
_p0, err = syscall.UTF16PtrFromString(systemName)
|
if openAsSelf {
|
||||||
if err != nil {
|
_p0 = 1
|
||||||
return
|
|
||||||
}
|
}
|
||||||
return _lookupPrivilegeName(_p0, luid, buffer, size)
|
r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(accessMask), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
|
||||||
}
|
|
||||||
|
|
||||||
func _lookupPrivilegeName(systemName *uint16, luid *uint64, buffer *uint16, size *uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procLookupPrivilegeNameW.Addr(), 4, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(luid)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(size)), 0, 0)
|
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupPrivilegeDisplayName(systemName string, name *uint16, buffer *uint16, size *uint32, languageId *uint32) (err error) {
|
func revertToSelf() (err error) {
|
||||||
var _p0 *uint16
|
r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
|
||||||
_p0, err = syscall.UTF16PtrFromString(systemName)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return _lookupPrivilegeDisplayName(_p0, name, buffer, size, languageId)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _lookupPrivilegeDisplayName(systemName *uint16, name *uint16, buffer *uint16, size *uint32, languageId *uint32) (err error) {
|
|
||||||
r1, _, e1 := syscall.Syscall6(procLookupPrivilegeDisplayNameW.Addr(), 5, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(size)), uintptr(unsafe.Pointer(languageId)), 0)
|
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -501,22 +240,14 @@ func backupRead(h syscall.Handle, b []byte, bytesRead *uint32, abort bool, proce
|
||||||
var _p1 uint32
|
var _p1 uint32
|
||||||
if abort {
|
if abort {
|
||||||
_p1 = 1
|
_p1 = 1
|
||||||
} else {
|
|
||||||
_p1 = 0
|
|
||||||
}
|
}
|
||||||
var _p2 uint32
|
var _p2 uint32
|
||||||
if processSecurity {
|
if processSecurity {
|
||||||
_p2 = 1
|
_p2 = 1
|
||||||
} else {
|
|
||||||
_p2 = 0
|
|
||||||
}
|
}
|
||||||
r1, _, e1 := syscall.Syscall9(procBackupRead.Addr(), 7, uintptr(h), uintptr(unsafe.Pointer(_p0)), uintptr(len(b)), uintptr(unsafe.Pointer(bytesRead)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(context)), 0, 0)
|
r1, _, e1 := syscall.Syscall9(procBackupRead.Addr(), 7, uintptr(h), uintptr(unsafe.Pointer(_p0)), uintptr(len(b)), uintptr(unsafe.Pointer(bytesRead)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(context)), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -529,22 +260,178 @@ func backupWrite(h syscall.Handle, b []byte, bytesWritten *uint32, abort bool, p
|
||||||
var _p1 uint32
|
var _p1 uint32
|
||||||
if abort {
|
if abort {
|
||||||
_p1 = 1
|
_p1 = 1
|
||||||
} else {
|
|
||||||
_p1 = 0
|
|
||||||
}
|
}
|
||||||
var _p2 uint32
|
var _p2 uint32
|
||||||
if processSecurity {
|
if processSecurity {
|
||||||
_p2 = 1
|
_p2 = 1
|
||||||
} else {
|
|
||||||
_p2 = 0
|
|
||||||
}
|
}
|
||||||
r1, _, e1 := syscall.Syscall9(procBackupWrite.Addr(), 7, uintptr(h), uintptr(unsafe.Pointer(_p0)), uintptr(len(b)), uintptr(unsafe.Pointer(bytesWritten)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(context)), 0, 0)
|
r1, _, e1 := syscall.Syscall9(procBackupWrite.Addr(), 7, uintptr(h), uintptr(unsafe.Pointer(_p0)), uintptr(len(b)), uintptr(unsafe.Pointer(bytesWritten)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(context)), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
}
|
||||||
} else {
|
return
|
||||||
err = syscall.EINVAL
|
}
|
||||||
}
|
|
||||||
|
func cancelIoEx(file syscall.Handle, o *syscall.Overlapped) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(file), uintptr(unsafe.Pointer(o)), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func connectNamedPipe(pipe syscall.Handle, o *syscall.Overlapped) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall(procConnectNamedPipe.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(o)), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func createFile(name string, access uint32, mode uint32, sa *syscall.SecurityAttributes, createmode uint32, attrs uint32, templatefile syscall.Handle) (handle syscall.Handle, err error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, err = syscall.UTF16PtrFromString(name)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _createFile(_p0, access, mode, sa, createmode, attrs, templatefile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _createFile(name *uint16, access uint32, mode uint32, sa *syscall.SecurityAttributes, createmode uint32, attrs uint32, templatefile syscall.Handle) (handle syscall.Handle, err error) {
|
||||||
|
r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
|
||||||
|
handle = syscall.Handle(r0)
|
||||||
|
if handle == syscall.InvalidHandle {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func createIoCompletionPort(file syscall.Handle, port syscall.Handle, key uintptr, threadCount uint32) (newport syscall.Handle, err error) {
|
||||||
|
r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(file), uintptr(port), uintptr(key), uintptr(threadCount), 0, 0)
|
||||||
|
newport = syscall.Handle(r0)
|
||||||
|
if newport == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func createNamedPipe(name string, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, err = syscall.UTF16PtrFromString(name)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _createNamedPipe(_p0, flags, pipeMode, maxInstances, outSize, inSize, defaultTimeout, sa)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _createNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
|
||||||
|
r0, _, e1 := syscall.Syscall9(procCreateNamedPipeW.Addr(), 8, uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(pipeMode), uintptr(maxInstances), uintptr(outSize), uintptr(inSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)), 0)
|
||||||
|
handle = syscall.Handle(r0)
|
||||||
|
if handle == syscall.InvalidHandle {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCurrentThread() (h syscall.Handle) {
|
||||||
|
r0, _, _ := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
|
||||||
|
h = syscall.Handle(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFileInformationByHandleEx(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(h), uintptr(class), uintptr(unsafe.Pointer(buffer)), uintptr(size), 0, 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNamedPipeHandleState(pipe syscall.Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall9(procGetNamedPipeHandleStateW.Addr(), 7, uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(curInstances)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), uintptr(unsafe.Pointer(userName)), uintptr(maxUserNameSize), 0, 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNamedPipeInfo(pipe syscall.Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procGetNamedPipeInfo.Addr(), 5, uintptr(pipe), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(outSize)), uintptr(unsafe.Pointer(inSize)), uintptr(unsafe.Pointer(maxInstances)), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getQueuedCompletionStatus(port syscall.Handle, bytes *uint32, key *uintptr, o **ioOperation, timeout uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(port), uintptr(unsafe.Pointer(bytes)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(o)), uintptr(timeout), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func localAlloc(uFlags uint32, length uint32) (ptr uintptr) {
|
||||||
|
r0, _, _ := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(uFlags), uintptr(length), 0)
|
||||||
|
ptr = uintptr(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func localFree(mem uintptr) {
|
||||||
|
syscall.Syscall(procLocalFree.Addr(), 1, uintptr(mem), 0, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func setFileCompletionNotificationModes(h syscall.Handle, flags uint8) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(h), uintptr(flags), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func setFileInformationByHandle(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(h), uintptr(class), uintptr(unsafe.Pointer(buffer)), uintptr(size), 0, 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func ntCreateNamedPipeFile(pipe *syscall.Handle, access uint32, oa *objectAttributes, iosb *ioStatusBlock, share uint32, disposition uint32, options uint32, typ uint32, readMode uint32, completionMode uint32, maxInstances uint32, inboundQuota uint32, outputQuota uint32, timeout *int64) (status ntstatus) {
|
||||||
|
r0, _, _ := syscall.Syscall15(procNtCreateNamedPipeFile.Addr(), 14, uintptr(unsafe.Pointer(pipe)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(share), uintptr(disposition), uintptr(options), uintptr(typ), uintptr(readMode), uintptr(completionMode), uintptr(maxInstances), uintptr(inboundQuota), uintptr(outputQuota), uintptr(unsafe.Pointer(timeout)), 0)
|
||||||
|
status = ntstatus(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func rtlDefaultNpAcl(dacl *uintptr) (status ntstatus) {
|
||||||
|
r0, _, _ := syscall.Syscall(procRtlDefaultNpAcl.Addr(), 1, uintptr(unsafe.Pointer(dacl)), 0, 0)
|
||||||
|
status = ntstatus(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func rtlDosPathNameToNtPathName(name *uint16, ntName *unicodeString, filePart uintptr, reserved uintptr) (status ntstatus) {
|
||||||
|
r0, _, _ := syscall.Syscall6(procRtlDosPathNameToNtPathName_U.Addr(), 4, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(ntName)), uintptr(filePart), uintptr(reserved), 0, 0)
|
||||||
|
status = ntstatus(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func rtlNtStatusToDosError(status ntstatus) (winerr error) {
|
||||||
|
r0, _, _ := syscall.Syscall(procRtlNtStatusToDosErrorNoTeb.Addr(), 1, uintptr(status), 0, 0)
|
||||||
|
if r0 != 0 {
|
||||||
|
winerr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func wsaGetOverlappedResult(h syscall.Handle, o *syscall.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) {
|
||||||
|
var _p0 uint32
|
||||||
|
if wait {
|
||||||
|
_p0 = 1
|
||||||
|
}
|
||||||
|
r1, _, e1 := syscall.Syscall6(procWSAGetOverlappedResult.Addr(), 5, uintptr(h), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(bytes)), uintptr(_p0), uintptr(unsafe.Pointer(flags)), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -552,11 +439,7 @@ func backupWrite(h syscall.Handle, b []byte, bytesWritten *uint32, abort bool, p
|
||||||
func bind(s syscall.Handle, name unsafe.Pointer, namelen int32) (err error) {
|
func bind(s syscall.Handle, name unsafe.Pointer, namelen int32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
|
r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
|
||||||
if r1 == socketError {
|
if r1 == socketError {
|
||||||
if e1 != 0 {
|
err = errnoErr(e1)
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# hcsshim
|
# hcsshim
|
||||||
|
|
||||||
[![Build status](https://ci.appveyor.com/api/projects/status/nbcw28mnkqml0loa/branch/master?svg=true)](https://ci.appveyor.com/project/WindowsVirtualization/hcsshim/branch/master)
|
[![Build status](https://github.com/microsoft/hcsshim/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/microsoft/hcsshim/actions?query=branch%3Amaster)
|
||||||
|
|
||||||
This package contains the Golang interface for using the Windows [Host Compute Service](https://techcommunity.microsoft.com/t5/containers/introducing-the-host-compute-service-hcs/ba-p/382332) (HCS) to launch and manage [Windows Containers](https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/). It also contains other helpers and functions for managing Windows Containers such as the Golang interface for the Host Network Service (HNS).
|
This package contains the Golang interface for using the Windows [Host Compute Service](https://techcommunity.microsoft.com/t5/containers/introducing-the-host-compute-service-hcs/ba-p/382332) (HCS) to launch and manage [Windows Containers](https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/). It also contains other helpers and functions for managing Windows Containers such as the Golang interface for the Host Network Service (HNS).
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AttachLayerStorageFilter sets up the layer storage filter on a writable
|
||||||
|
// container layer.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory the writable layer is mounted. If the
|
||||||
|
// path does not end in a `\` the platform will append it automatically.
|
||||||
|
//
|
||||||
|
// `layerData` is the parent read-only layer data.
|
||||||
|
func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData LayerData) (err error) {
|
||||||
|
title := "hcsshim.AttachLayerStorageFilter"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("layerPath", layerPath),
|
||||||
|
)
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(layerData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hcsAttachLayerStorageFilter(layerPath, string(bytes))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to attach layer storage filter")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DestroyLayer deletes a container layer.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory containing the layer to export.
|
||||||
|
func DestroyLayer(ctx context.Context, layerPath string) (err error) {
|
||||||
|
title := "hcsshim.DestroyLayer"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(trace.StringAttribute("layerPath", layerPath))
|
||||||
|
|
||||||
|
err = hcsDestroyLayer(layerPath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to destroy layer")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DetachLayerStorageFilter detaches the layer storage filter on a writable container layer.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory containing the layer to export.
|
||||||
|
func DetachLayerStorageFilter(ctx context.Context, layerPath string) (err error) {
|
||||||
|
title := "hcsshim.DetachLayerStorageFilter"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(trace.StringAttribute("layerPath", layerPath))
|
||||||
|
|
||||||
|
err = hcsDetachLayerStorageFilter(layerPath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to detach layer storage filter")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ExportLayer exports a container layer.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory containing the layer to export.
|
||||||
|
//
|
||||||
|
// `exportFolderPath` is a pre-existing folder to export the layer to.
|
||||||
|
//
|
||||||
|
// `layerData` is the parent layer data.
|
||||||
|
//
|
||||||
|
// `options` are the export options applied to the exported layer.
|
||||||
|
func ExportLayer(ctx context.Context, layerPath, exportFolderPath string, layerData LayerData, options ExportLayerOptions) (err error) {
|
||||||
|
title := "hcsshim.ExportLayer"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("layerPath", layerPath),
|
||||||
|
trace.StringAttribute("exportFolderPath", exportFolderPath),
|
||||||
|
)
|
||||||
|
|
||||||
|
ldbytes, err := json.Marshal(layerData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
obytes, err := json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hcsExportLayer(layerPath, exportFolderPath, string(ldbytes), string(obytes))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to export layer")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FormatWritableLayerVhd formats a virtual disk for use as a writable container layer.
|
||||||
|
//
|
||||||
|
// If the VHD is not mounted it will be temporarily mounted.
|
||||||
|
func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err error) {
|
||||||
|
title := "hcsshim.FormatWritableLayerVhd"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
|
||||||
|
err = hcsFormatWritableLayerVhd(vhdHandle)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to format writable layer vhd")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,193 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/Microsoft/go-winio/pkg/security"
|
||||||
|
"github.com/Microsoft/go-winio/vhd"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
const defaultVHDXBlockSizeInMB = 1
|
||||||
|
|
||||||
|
// SetupContainerBaseLayer is a helper to setup a containers scratch. It
|
||||||
|
// will create and format the vhdx's inside and the size is configurable with the sizeInGB
|
||||||
|
// parameter.
|
||||||
|
//
|
||||||
|
// `layerPath` is the path to the base container layer on disk.
|
||||||
|
//
|
||||||
|
// `baseVhdPath` is the path to where the base vhdx for the base layer should be created.
|
||||||
|
//
|
||||||
|
// `diffVhdPath` is the path where the differencing disk for the base layer should be created.
|
||||||
|
//
|
||||||
|
// `sizeInGB` is the size in gigabytes to make the base vhdx.
|
||||||
|
func SetupContainerBaseLayer(ctx context.Context, layerPath, baseVhdPath, diffVhdPath string, sizeInGB uint64) (err error) {
|
||||||
|
var (
|
||||||
|
hivesPath = filepath.Join(layerPath, "Hives")
|
||||||
|
layoutPath = filepath.Join(layerPath, "Layout")
|
||||||
|
)
|
||||||
|
|
||||||
|
// We need to remove the hives directory and layout file as `SetupBaseOSLayer` fails if these files
|
||||||
|
// already exist. `SetupBaseOSLayer` will create these files internally. We also remove the base and
|
||||||
|
// differencing disks if they exist in case we're asking for a different size.
|
||||||
|
if _, err := os.Stat(hivesPath); err == nil {
|
||||||
|
if err := os.RemoveAll(hivesPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove prexisting hives directory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(layoutPath); err == nil {
|
||||||
|
if err := os.RemoveAll(layoutPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove prexisting layout file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(baseVhdPath); err == nil {
|
||||||
|
if err := os.RemoveAll(baseVhdPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove base vhdx path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(diffVhdPath); err == nil {
|
||||||
|
if err := os.RemoveAll(diffVhdPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove differencing vhdx")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createParams := &vhd.CreateVirtualDiskParameters{
|
||||||
|
Version: 2,
|
||||||
|
Version2: vhd.CreateVersion2{
|
||||||
|
MaximumSize: sizeInGB * 1024 * 1024 * 1024,
|
||||||
|
BlockSizeInBytes: defaultVHDXBlockSizeInMB * 1024 * 1024,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handle, err := vhd.CreateVirtualDisk(baseVhdPath, vhd.VirtualDiskAccessNone, vhd.CreateVirtualDiskFlagNone, createParams)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to create vhdx")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
_ = syscall.CloseHandle(handle)
|
||||||
|
os.RemoveAll(baseVhdPath)
|
||||||
|
os.RemoveAll(diffVhdPath)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err = FormatWritableLayerVhd(ctx, windows.Handle(handle)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Base vhd handle must be closed before calling SetupBaseLayer in case of Container layer
|
||||||
|
if err = syscall.CloseHandle(handle); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to close vhdx handle")
|
||||||
|
}
|
||||||
|
|
||||||
|
options := OsLayerOptions{
|
||||||
|
Type: OsLayerTypeContainer,
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupBaseOSLayer expects an empty vhd handle for a container layer and will
|
||||||
|
// error out otherwise.
|
||||||
|
if err = SetupBaseOSLayer(ctx, layerPath, 0, options); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Create the differencing disk that will be what's copied for the final rw layer
|
||||||
|
// for a container.
|
||||||
|
if err = vhd.CreateDiffVhd(diffVhdPath, baseVhdPath, defaultVHDXBlockSizeInMB); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to create differencing disk")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = security.GrantVmGroupAccess(baseVhdPath); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to grant vm group access to %s", baseVhdPath)
|
||||||
|
}
|
||||||
|
if err = security.GrantVmGroupAccess(diffVhdPath); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to grant vm group access to %s", diffVhdPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupUtilityVMBaseLayer is a helper to setup a UVMs scratch space. It will create and format
|
||||||
|
// the vhdx inside and the size is configurable by the sizeInGB parameter.
|
||||||
|
//
|
||||||
|
// `uvmPath` is the path to the UtilityVM filesystem.
|
||||||
|
//
|
||||||
|
// `baseVhdPath` is the path to where the base vhdx for the UVM should be created.
|
||||||
|
//
|
||||||
|
// `diffVhdPath` is the path where the differencing disk for the UVM should be created.
|
||||||
|
//
|
||||||
|
// `sizeInGB` specifies the size in gigabytes to make the base vhdx.
|
||||||
|
func SetupUtilityVMBaseLayer(ctx context.Context, uvmPath, baseVhdPath, diffVhdPath string, sizeInGB uint64) (err error) {
|
||||||
|
// Remove the base and differencing disks if they exist in case we're asking for a different size.
|
||||||
|
if _, err := os.Stat(baseVhdPath); err == nil {
|
||||||
|
if err := os.RemoveAll(baseVhdPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove base vhdx")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(diffVhdPath); err == nil {
|
||||||
|
if err := os.RemoveAll(diffVhdPath); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove differencing vhdx")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just create the vhdx for utilityVM layer, no need to format it.
|
||||||
|
createParams := &vhd.CreateVirtualDiskParameters{
|
||||||
|
Version: 2,
|
||||||
|
Version2: vhd.CreateVersion2{
|
||||||
|
MaximumSize: sizeInGB * 1024 * 1024 * 1024,
|
||||||
|
BlockSizeInBytes: defaultVHDXBlockSizeInMB * 1024 * 1024,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handle, err := vhd.CreateVirtualDisk(baseVhdPath, vhd.VirtualDiskAccessNone, vhd.CreateVirtualDiskFlagNone, createParams)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to create vhdx")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
_ = syscall.CloseHandle(handle)
|
||||||
|
os.RemoveAll(baseVhdPath)
|
||||||
|
os.RemoveAll(diffVhdPath)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// If it is a UtilityVM layer then the base vhdx must be attached when calling
|
||||||
|
// `SetupBaseOSLayer`
|
||||||
|
attachParams := &vhd.AttachVirtualDiskParameters{
|
||||||
|
Version: 2,
|
||||||
|
}
|
||||||
|
if err := vhd.AttachVirtualDisk(handle, vhd.AttachVirtualDiskFlagNone, attachParams); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to attach virtual disk")
|
||||||
|
}
|
||||||
|
|
||||||
|
options := OsLayerOptions{
|
||||||
|
Type: OsLayerTypeVM,
|
||||||
|
}
|
||||||
|
if err := SetupBaseOSLayer(ctx, uvmPath, windows.Handle(handle), options); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detach and close the handle after setting up the layer as we don't need the handle
|
||||||
|
// for anything else and we no longer need to be attached either.
|
||||||
|
if err = vhd.DetachVirtualDisk(handle); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to detach vhdx")
|
||||||
|
}
|
||||||
|
if err = syscall.CloseHandle(handle); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to close vhdx handle")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the differencing disk that will be what's copied for the final rw layer
|
||||||
|
// for a container.
|
||||||
|
if err = vhd.CreateDiffVhd(diffVhdPath, baseVhdPath, defaultVHDXBlockSizeInMB); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to create differencing disk")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := security.GrantVmGroupAccess(baseVhdPath); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to grant vm group access to %s", baseVhdPath)
|
||||||
|
}
|
||||||
|
if err := security.GrantVmGroupAccess(diffVhdPath); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to grant vm group access to %s", diffVhdPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ImportLayer imports a container layer.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory to import the layer to. If the directory
|
||||||
|
// does not exist it will be automatically created.
|
||||||
|
//
|
||||||
|
// `sourceFolderpath` is a pre-existing folder that contains the layer to
|
||||||
|
// import.
|
||||||
|
//
|
||||||
|
// `layerData` is the parent layer data.
|
||||||
|
func ImportLayer(ctx context.Context, layerPath, sourceFolderPath string, layerData LayerData) (err error) {
|
||||||
|
title := "hcsshim.ImportLayer"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("layerPath", layerPath),
|
||||||
|
trace.StringAttribute("sourceFolderPath", sourceFolderPath),
|
||||||
|
)
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(layerData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hcsImportLayer(layerPath, sourceFolderPath, string(bytes))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to import layer")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InitializeWritableLayer initializes a writable layer for a container.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory the layer is mounted. If the
|
||||||
|
// path does not end in a `\` the platform will append it automatically.
|
||||||
|
//
|
||||||
|
// `layerData` is the parent read-only layer data.
|
||||||
|
func InitializeWritableLayer(ctx context.Context, layerPath string, layerData LayerData) (err error) {
|
||||||
|
title := "hcsshim.InitializeWritableLayer"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("layerPath", layerPath),
|
||||||
|
)
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(layerData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Options are not used in the platform as of RS5
|
||||||
|
err = hcsInitializeWritableLayer(layerPath, string(bytes), "")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to intitialize container layer")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/interop"
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetLayerVhdMountPath returns the volume path for a virtual disk of a writable container layer.
|
||||||
|
func GetLayerVhdMountPath(ctx context.Context, vhdHandle windows.Handle) (path string, err error) {
|
||||||
|
title := "hcsshim.GetLayerVhdMountPath"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
|
||||||
|
var mountPath *uint16
|
||||||
|
err = hcsGetLayerVhdMountPath(vhdHandle, &mountPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "failed to get vhd mount path")
|
||||||
|
}
|
||||||
|
path = interop.ConvertAndFreeCoTaskMemString(mountPath)
|
||||||
|
return path, nil
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
|
"github.com/Microsoft/hcsshim/osversion"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetupBaseOSLayer sets up a layer that contains a base OS for a container.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory containing the layer.
|
||||||
|
//
|
||||||
|
// `vhdHandle` is an empty file handle of `options.Type == OsLayerTypeContainer`
|
||||||
|
// or else it is a file handle to the 'SystemTemplateBase.vhdx' if `options.Type
|
||||||
|
// == OsLayerTypeVm`.
|
||||||
|
//
|
||||||
|
// `options` are the options applied while processing the layer.
|
||||||
|
func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.Handle, options OsLayerOptions) (err error) {
|
||||||
|
title := "hcsshim.SetupBaseOSLayer"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("layerPath", layerPath),
|
||||||
|
)
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hcsSetupBaseOSLayer(layerPath, vhdHandle, string(bytes))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to setup base OS layer")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupBaseOSVolume sets up a volume that contains a base OS for a container.
|
||||||
|
//
|
||||||
|
// `layerPath` is a path to a directory containing the layer.
|
||||||
|
//
|
||||||
|
// `volumePath` is the path to the volume to be used for setup.
|
||||||
|
//
|
||||||
|
// `options` are the options applied while processing the layer.
|
||||||
|
func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, options OsLayerOptions) (err error) {
|
||||||
|
if osversion.Get().Build < 19645 {
|
||||||
|
return errors.New("SetupBaseOSVolume is not present on builds older than 19645")
|
||||||
|
}
|
||||||
|
title := "hcsshim.SetupBaseOSVolume"
|
||||||
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(
|
||||||
|
trace.StringAttribute("layerPath", layerPath),
|
||||||
|
trace.StringAttribute("volumePath", volumePath),
|
||||||
|
)
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hcsSetupBaseOSVolume(layerPath, volumePath, string(bytes))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to setup base OS layer")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
// Package computestorage is a wrapper around the HCS storage APIs. These are new storage APIs introduced
|
||||||
|
// separate from the original graphdriver calls intended to give more freedom around creating
|
||||||
|
// and managing container layers and scratch spaces.
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
hcsschema "github.com/Microsoft/hcsshim/internal/schema2"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate go run ../mksyscall_windows.go -output zsyscall_windows.go storage.go
|
||||||
|
|
||||||
|
//sys hcsImportLayer(layerPath string, sourceFolderPath string, layerData string) (hr error) = computestorage.HcsImportLayer?
|
||||||
|
//sys hcsExportLayer(layerPath string, exportFolderPath string, layerData string, options string) (hr error) = computestorage.HcsExportLayer?
|
||||||
|
//sys hcsDestroyLayer(layerPath string) (hr error) = computestorage.HcsDestoryLayer?
|
||||||
|
//sys hcsSetupBaseOSLayer(layerPath string, handle windows.Handle, options string) (hr error) = computestorage.HcsSetupBaseOSLayer?
|
||||||
|
//sys hcsInitializeWritableLayer(writableLayerPath string, layerData string, options string) (hr error) = computestorage.HcsInitializeWritableLayer?
|
||||||
|
//sys hcsAttachLayerStorageFilter(layerPath string, layerData string) (hr error) = computestorage.HcsAttachLayerStorageFilter?
|
||||||
|
//sys hcsDetachLayerStorageFilter(layerPath string) (hr error) = computestorage.HcsDetachLayerStorageFilter?
|
||||||
|
//sys hcsFormatWritableLayerVhd(handle windows.Handle) (hr error) = computestorage.HcsFormatWritableLayerVhd?
|
||||||
|
//sys hcsGetLayerVhdMountPath(vhdHandle windows.Handle, mountPath **uint16) (hr error) = computestorage.HcsGetLayerVhdMountPath?
|
||||||
|
//sys hcsSetupBaseOSVolume(layerPath string, volumePath string, options string) (hr error) = computestorage.HcsSetupBaseOSVolume?
|
||||||
|
|
||||||
|
// LayerData is the data used to describe parent layer information.
|
||||||
|
type LayerData struct {
|
||||||
|
SchemaVersion hcsschema.Version `json:"SchemaVersion,omitempty"`
|
||||||
|
Layers []hcsschema.Layer `json:"Layers,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExportLayerOptions are the set of options that are used with the `computestorage.HcsExportLayer` syscall.
|
||||||
|
type ExportLayerOptions struct {
|
||||||
|
IsWritableLayer bool `json:"IsWritableLayer,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OsLayerType is the type of layer being operated on.
|
||||||
|
type OsLayerType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// OsLayerTypeContainer is a container layer.
|
||||||
|
OsLayerTypeContainer OsLayerType = "Container"
|
||||||
|
// OsLayerTypeVM is a virtual machine layer.
|
||||||
|
OsLayerTypeVM OsLayerType = "Vm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OsLayerOptions are the set of options that are used with the `SetupBaseOSLayer` and
|
||||||
|
// `SetupBaseOSVolume` calls.
|
||||||
|
type OsLayerOptions struct {
|
||||||
|
Type OsLayerType `json:"Type,omitempty"`
|
||||||
|
DisableCiCacheOptimization bool `json:"DisableCiCacheOptimization,omitempty"`
|
||||||
|
SkipUpdateBcdForBoot bool `json:"SkipUpdateBcdForBoot,omitempty"`
|
||||||
|
}
|
319
vendor/github.com/Microsoft/hcsshim/computestorage/zsyscall_windows.go
generated
vendored
Normal file
319
vendor/github.com/Microsoft/hcsshim/computestorage/zsyscall_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,319 @@
|
||||||
|
// Code generated mksyscall_windows.exe DO NOT EDIT
|
||||||
|
|
||||||
|
package computestorage
|
||||||
|
|
||||||
|
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 (
|
||||||
|
modcomputestorage = windows.NewLazySystemDLL("computestorage.dll")
|
||||||
|
|
||||||
|
procHcsImportLayer = modcomputestorage.NewProc("HcsImportLayer")
|
||||||
|
procHcsExportLayer = modcomputestorage.NewProc("HcsExportLayer")
|
||||||
|
procHcsDestoryLayer = modcomputestorage.NewProc("HcsDestoryLayer")
|
||||||
|
procHcsSetupBaseOSLayer = modcomputestorage.NewProc("HcsSetupBaseOSLayer")
|
||||||
|
procHcsInitializeWritableLayer = modcomputestorage.NewProc("HcsInitializeWritableLayer")
|
||||||
|
procHcsAttachLayerStorageFilter = modcomputestorage.NewProc("HcsAttachLayerStorageFilter")
|
||||||
|
procHcsDetachLayerStorageFilter = modcomputestorage.NewProc("HcsDetachLayerStorageFilter")
|
||||||
|
procHcsFormatWritableLayerVhd = modcomputestorage.NewProc("HcsFormatWritableLayerVhd")
|
||||||
|
procHcsGetLayerVhdMountPath = modcomputestorage.NewProc("HcsGetLayerVhdMountPath")
|
||||||
|
procHcsSetupBaseOSVolume = modcomputestorage.NewProc("HcsSetupBaseOSVolume")
|
||||||
|
)
|
||||||
|
|
||||||
|
func hcsImportLayer(layerPath string, sourceFolderPath string, layerData string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p1 *uint16
|
||||||
|
_p1, hr = syscall.UTF16PtrFromString(sourceFolderPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p2 *uint16
|
||||||
|
_p2, hr = syscall.UTF16PtrFromString(layerData)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsImportLayer(_p0, _p1, _p2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsImportLayer(layerPath *uint16, sourceFolderPath *uint16, layerData *uint16) (hr error) {
|
||||||
|
if hr = procHcsImportLayer.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsImportLayer.Addr(), 3, uintptr(unsafe.Pointer(layerPath)), uintptr(unsafe.Pointer(sourceFolderPath)), uintptr(unsafe.Pointer(layerData)))
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsExportLayer(layerPath string, exportFolderPath string, layerData string, options string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p1 *uint16
|
||||||
|
_p1, hr = syscall.UTF16PtrFromString(exportFolderPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p2 *uint16
|
||||||
|
_p2, hr = syscall.UTF16PtrFromString(layerData)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p3 *uint16
|
||||||
|
_p3, hr = syscall.UTF16PtrFromString(options)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsExportLayer(_p0, _p1, _p2, _p3)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsExportLayer(layerPath *uint16, exportFolderPath *uint16, layerData *uint16, options *uint16) (hr error) {
|
||||||
|
if hr = procHcsExportLayer.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall6(procHcsExportLayer.Addr(), 4, uintptr(unsafe.Pointer(layerPath)), uintptr(unsafe.Pointer(exportFolderPath)), uintptr(unsafe.Pointer(layerData)), uintptr(unsafe.Pointer(options)), 0, 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsDestroyLayer(layerPath string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsDestroyLayer(_p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsDestroyLayer(layerPath *uint16) (hr error) {
|
||||||
|
if hr = procHcsDestoryLayer.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsDestoryLayer.Addr(), 1, uintptr(unsafe.Pointer(layerPath)), 0, 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsSetupBaseOSLayer(layerPath string, handle windows.Handle, options string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p1 *uint16
|
||||||
|
_p1, hr = syscall.UTF16PtrFromString(options)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsSetupBaseOSLayer(_p0, handle, _p1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsSetupBaseOSLayer(layerPath *uint16, handle windows.Handle, options *uint16) (hr error) {
|
||||||
|
if hr = procHcsSetupBaseOSLayer.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsSetupBaseOSLayer.Addr(), 3, uintptr(unsafe.Pointer(layerPath)), uintptr(handle), uintptr(unsafe.Pointer(options)))
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsInitializeWritableLayer(writableLayerPath string, layerData string, options string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(writableLayerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p1 *uint16
|
||||||
|
_p1, hr = syscall.UTF16PtrFromString(layerData)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p2 *uint16
|
||||||
|
_p2, hr = syscall.UTF16PtrFromString(options)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsInitializeWritableLayer(_p0, _p1, _p2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsInitializeWritableLayer(writableLayerPath *uint16, layerData *uint16, options *uint16) (hr error) {
|
||||||
|
if hr = procHcsInitializeWritableLayer.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsInitializeWritableLayer.Addr(), 3, uintptr(unsafe.Pointer(writableLayerPath)), uintptr(unsafe.Pointer(layerData)), uintptr(unsafe.Pointer(options)))
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsAttachLayerStorageFilter(layerPath string, layerData string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p1 *uint16
|
||||||
|
_p1, hr = syscall.UTF16PtrFromString(layerData)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsAttachLayerStorageFilter(_p0, _p1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsAttachLayerStorageFilter(layerPath *uint16, layerData *uint16) (hr error) {
|
||||||
|
if hr = procHcsAttachLayerStorageFilter.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsAttachLayerStorageFilter.Addr(), 2, uintptr(unsafe.Pointer(layerPath)), uintptr(unsafe.Pointer(layerData)), 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsDetachLayerStorageFilter(layerPath string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsDetachLayerStorageFilter(_p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsDetachLayerStorageFilter(layerPath *uint16) (hr error) {
|
||||||
|
if hr = procHcsDetachLayerStorageFilter.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsDetachLayerStorageFilter.Addr(), 1, uintptr(unsafe.Pointer(layerPath)), 0, 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsFormatWritableLayerVhd(handle windows.Handle) (hr error) {
|
||||||
|
if hr = procHcsFormatWritableLayerVhd.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsFormatWritableLayerVhd.Addr(), 1, uintptr(handle), 0, 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsGetLayerVhdMountPath(vhdHandle windows.Handle, mountPath **uint16) (hr error) {
|
||||||
|
if hr = procHcsGetLayerVhdMountPath.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsGetLayerVhdMountPath.Addr(), 2, uintptr(vhdHandle), uintptr(unsafe.Pointer(mountPath)), 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hcsSetupBaseOSVolume(layerPath string, volumePath string, options string) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(layerPath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p1 *uint16
|
||||||
|
_p1, hr = syscall.UTF16PtrFromString(volumePath)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var _p2 *uint16
|
||||||
|
_p2, hr = syscall.UTF16PtrFromString(options)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsSetupBaseOSVolume(_p0, _p1, _p2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsSetupBaseOSVolume(layerPath *uint16, volumePath *uint16, options *uint16) (hr error) {
|
||||||
|
if hr = procHcsSetupBaseOSVolume.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsSetupBaseOSVolume.Addr(), 3, uintptr(unsafe.Pointer(layerPath)), uintptr(unsafe.Pointer(volumePath)), uintptr(unsafe.Pointer(options)))
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -83,7 +83,6 @@ type NetworkNotFoundError = hns.NetworkNotFoundError
|
||||||
type ProcessError struct {
|
type ProcessError struct {
|
||||||
Process *process
|
Process *process
|
||||||
Operation string
|
Operation string
|
||||||
ExtraInfo string
|
|
||||||
Err error
|
Err error
|
||||||
Events []hcs.ErrorEvent
|
Events []hcs.ErrorEvent
|
||||||
}
|
}
|
||||||
|
@ -92,7 +91,6 @@ type ProcessError struct {
|
||||||
type ContainerError struct {
|
type ContainerError struct {
|
||||||
Container *container
|
Container *container
|
||||||
Operation string
|
Operation string
|
||||||
ExtraInfo string
|
|
||||||
Err error
|
Err error
|
||||||
Events []hcs.ErrorEvent
|
Events []hcs.ErrorEvent
|
||||||
}
|
}
|
||||||
|
@ -125,22 +123,9 @@ func (e *ContainerError) Error() string {
|
||||||
s += "\n" + ev.String()
|
s += "\n" + ev.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.ExtraInfo != "" {
|
|
||||||
s += " extra info: " + e.ExtraInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeContainerError(container *container, operation string, extraInfo string, err error) error {
|
|
||||||
// Don't double wrap errors
|
|
||||||
if _, ok := err.(*ContainerError); ok {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
containerError := &ContainerError{Container: container, Operation: operation, ExtraInfo: extraInfo, Err: err}
|
|
||||||
return containerError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *ProcessError) Error() string {
|
func (e *ProcessError) Error() string {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return "<nil>"
|
return "<nil>"
|
||||||
|
@ -171,15 +156,6 @@ func (e *ProcessError) Error() string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeProcessError(process *process, operation string, extraInfo string, err error) error {
|
|
||||||
// Don't double wrap errors
|
|
||||||
if _, ok := err.(*ProcessError); ok {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
processError := &ProcessError{Process: process, Operation: operation, ExtraInfo: extraInfo, Err: err}
|
|
||||||
return processError
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsNotExist checks if an error is caused by the Container or Process not existing.
|
// IsNotExist checks if an error is caused by the Container or Process not existing.
|
||||||
// Note: Currently, ErrElementNotFound can mean that a Process has either
|
// Note: Currently, ErrElementNotFound can mean that a Process has either
|
||||||
// already exited, or does not exist. Both IsAlreadyStopped and IsNotExist
|
// already exited, or does not exist. Both IsAlreadyStopped and IsNotExist
|
||||||
|
@ -230,6 +206,18 @@ func IsNotSupported(err error) bool {
|
||||||
return hcs.IsNotSupported(getInnerError(err))
|
return hcs.IsNotSupported(getInnerError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOperationInvalidState returns true when err is caused by
|
||||||
|
// `ErrVmcomputeOperationInvalidState`.
|
||||||
|
func IsOperationInvalidState(err error) bool {
|
||||||
|
return hcs.IsOperationInvalidState(getInnerError(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAccessIsDenied returns true when err is caused by
|
||||||
|
// `ErrVmcomputeOperationAccessIsDenied`.
|
||||||
|
func IsAccessIsDenied(err error) bool {
|
||||||
|
return hcs.IsAccessIsDenied(getInnerError(err))
|
||||||
|
}
|
||||||
|
|
||||||
func getInnerError(err error) error {
|
func getInnerError(err error) error {
|
||||||
switch pe := err.(type) {
|
switch pe := err.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
|
@ -244,7 +232,7 @@ func getInnerError(err error) error {
|
||||||
|
|
||||||
func convertSystemError(err error, c *container) error {
|
func convertSystemError(err error, c *container) error {
|
||||||
if serr, ok := err.(*hcs.SystemError); ok {
|
if serr, ok := err.(*hcs.SystemError); ok {
|
||||||
return &ContainerError{Container: c, Operation: serr.Op, ExtraInfo: serr.Extra, Err: serr.Err, Events: serr.Events}
|
return &ContainerError{Container: c, Operation: serr.Op, Err: serr.Err, Events: serr.Events}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,33 +3,20 @@ module github.com/Microsoft/hcsshim
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5
|
github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3
|
||||||
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f
|
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68
|
||||||
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1
|
github.com/containerd/console v1.0.1
|
||||||
github.com/containerd/containerd v1.3.2
|
github.com/containerd/containerd v1.5.0-beta.4
|
||||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
|
github.com/containerd/go-runc v0.0.0-20201020171139-16b287bc67d0
|
||||||
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 // indirect
|
github.com/containerd/ttrpc v1.0.2
|
||||||
github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3
|
github.com/containerd/typeurl v1.0.1
|
||||||
github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de
|
github.com/gogo/protobuf v1.3.2
|
||||||
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd
|
github.com/opencontainers/runtime-spec v1.0.3-0.20200929063507-e6143ca7d51d
|
||||||
github.com/gogo/protobuf v1.3.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/golang/protobuf v1.3.2 // indirect
|
github.com/sirupsen/logrus v1.7.0
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/urfave/cli v1.22.2
|
||||||
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2 // indirect
|
go.opencensus.io v0.22.3
|
||||||
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f // indirect
|
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
|
||||||
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700
|
golang.org/x/sys v0.0.0-20210324051608-47abb6519492
|
||||||
github.com/pkg/errors v0.8.1
|
google.golang.org/grpc v1.33.2
|
||||||
github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7 // indirect
|
|
||||||
github.com/sirupsen/logrus v1.4.2
|
|
||||||
github.com/stretchr/testify v1.4.0 // indirect
|
|
||||||
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5
|
|
||||||
go.opencensus.io v0.22.0
|
|
||||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3
|
|
||||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect
|
|
||||||
google.golang.org/grpc v1.23.1
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.2.8 // indirect
|
|
||||||
gotest.tools v2.2.0+incompatible // indirect
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -40,6 +40,9 @@ func HNSListEndpointRequest() ([]HNSEndpoint, error) {
|
||||||
// HotAttachEndpoint makes a HCS Call to attach the endpoint to the container
|
// HotAttachEndpoint makes a HCS Call to attach the endpoint to the container
|
||||||
func HotAttachEndpoint(containerID string, endpointID string) error {
|
func HotAttachEndpoint(containerID string, endpointID string) error {
|
||||||
endpoint, err := GetHNSEndpointByID(endpointID)
|
endpoint, err := GetHNSEndpointByID(endpointID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
isAttached, err := endpoint.IsAttached(containerID)
|
isAttached, err := endpoint.IsAttached(containerID)
|
||||||
if isAttached {
|
if isAttached {
|
||||||
return err
|
return err
|
||||||
|
@ -50,6 +53,9 @@ func HotAttachEndpoint(containerID string, endpointID string) error {
|
||||||
// HotDetachEndpoint makes a HCS Call to detach the endpoint from the container
|
// HotDetachEndpoint makes a HCS Call to detach the endpoint from the container
|
||||||
func HotDetachEndpoint(containerID string, endpointID string) error {
|
func HotDetachEndpoint(containerID string, endpointID string) error {
|
||||||
endpoint, err := GetHNSEndpointByID(endpointID)
|
endpoint, err := GetHNSEndpointByID(endpointID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
isAttached, err := endpoint.IsAttached(containerID)
|
isAttached, err := endpoint.IsAttached(containerID)
|
||||||
if !isAttached {
|
if !isAttached {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -80,4 +80,6 @@ type Container interface {
|
||||||
// container to be terminated by some error condition (including calling
|
// container to be terminated by some error condition (including calling
|
||||||
// Close).
|
// Close).
|
||||||
Wait() error
|
Wait() error
|
||||||
|
// Modify sends a request to modify container resources
|
||||||
|
Modify(ctx context.Context, config interface{}) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ func newSystemChannels() notificationChannels {
|
||||||
hcsNotificationSystemStartCompleted,
|
hcsNotificationSystemStartCompleted,
|
||||||
hcsNotificationSystemPauseCompleted,
|
hcsNotificationSystemPauseCompleted,
|
||||||
hcsNotificationSystemResumeCompleted,
|
hcsNotificationSystemResumeCompleted,
|
||||||
|
hcsNotificationSystemSaveCompleted,
|
||||||
} {
|
} {
|
||||||
channels[notif] = make(notificationChannel, 1)
|
channels[notif] = make(notificationChannel, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,6 @@ type SystemError struct {
|
||||||
ID string
|
ID string
|
||||||
Op string
|
Op string
|
||||||
Err error
|
Err error
|
||||||
Extra string
|
|
||||||
Events []ErrorEvent
|
Events []ErrorEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +181,6 @@ func (e *SystemError) Error() string {
|
||||||
for _, ev := range e.Events {
|
for _, ev := range e.Events {
|
||||||
s += "\n" + ev.String()
|
s += "\n" + ev.String()
|
||||||
}
|
}
|
||||||
if e.Extra != "" {
|
|
||||||
s += "\n(extra info: " + e.Extra + ")"
|
|
||||||
}
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +194,7 @@ func (e *SystemError) Timeout() bool {
|
||||||
return ok && err.Timeout()
|
return ok && err.Timeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeSystemError(system *System, op string, extra string, err error, events []ErrorEvent) error {
|
func makeSystemError(system *System, op string, err error, events []ErrorEvent) error {
|
||||||
// Don't double wrap errors
|
// Don't double wrap errors
|
||||||
if _, ok := err.(*SystemError); ok {
|
if _, ok := err.(*SystemError); ok {
|
||||||
return err
|
return err
|
||||||
|
@ -206,7 +202,6 @@ func makeSystemError(system *System, op string, extra string, err error, events
|
||||||
return &SystemError{
|
return &SystemError{
|
||||||
ID: system.ID(),
|
ID: system.ID(),
|
||||||
Op: op,
|
Op: op,
|
||||||
Extra: extra,
|
|
||||||
Err: err,
|
Err: err,
|
||||||
Events: events,
|
Events: events,
|
||||||
}
|
}
|
||||||
|
@ -312,6 +307,13 @@ func IsOperationInvalidState(err error) bool {
|
||||||
return err == ErrVmcomputeOperationInvalidState
|
return err == ErrVmcomputeOperationInvalidState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAccessIsDenied returns true when err is caused by
|
||||||
|
// `ErrVmcomputeOperationAccessIsDenied`.
|
||||||
|
func IsAccessIsDenied(err error) bool {
|
||||||
|
err = getInnerError(err)
|
||||||
|
return err == ErrVmcomputeOperationAccessIsDenied
|
||||||
|
}
|
||||||
|
|
||||||
func getInnerError(err error) error {
|
func getInnerError(err error) error {
|
||||||
switch pe := err.(type) {
|
switch pe := err.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
|
@ -325,12 +327,3 @@ func getInnerError(err error) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOperationLogResult(err error) (string, error) {
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return "Success", nil
|
|
||||||
default:
|
|
||||||
return "Error", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -64,11 +64,7 @@ type processStatus struct {
|
||||||
LastWaitResult int32
|
LastWaitResult int32
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const stdIn string = "StdIn"
|
||||||
stdIn string = "StdIn"
|
|
||||||
stdOut string = "StdOut"
|
|
||||||
stdErr string = "StdErr"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
modifyConsoleSize string = "ConsoleSize"
|
modifyConsoleSize string = "ConsoleSize"
|
||||||
|
@ -176,8 +172,10 @@ func (process *Process) waitBackground() {
|
||||||
trace.Int64Attribute("pid", int64(process.processID)))
|
trace.Int64Attribute("pid", int64(process.processID)))
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
exitCode = -1
|
exitCode = -1
|
||||||
|
propertiesJSON string
|
||||||
|
resultJSON string
|
||||||
)
|
)
|
||||||
|
|
||||||
err = waitForNotification(ctx, process.callbackNumber, hcsNotificationProcessExited, nil)
|
err = waitForNotification(ctx, process.callbackNumber, hcsNotificationProcessExited, nil)
|
||||||
|
@ -190,15 +188,15 @@ func (process *Process) waitBackground() {
|
||||||
|
|
||||||
// Make sure we didnt race with Close() here
|
// Make sure we didnt race with Close() here
|
||||||
if process.handle != 0 {
|
if process.handle != 0 {
|
||||||
propertiesJSON, resultJSON, err := vmcompute.HcsGetProcessProperties(ctx, process.handle)
|
propertiesJSON, resultJSON, err = vmcompute.HcsGetProcessProperties(ctx, process.handle)
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = makeProcessError(process, operation, err, events)
|
err = makeProcessError(process, operation, err, events) //nolint:ineffassign
|
||||||
} else {
|
} else {
|
||||||
properties := &processStatus{}
|
properties := &processStatus{}
|
||||||
err = json.Unmarshal([]byte(propertiesJSON), properties)
|
err = json.Unmarshal([]byte(propertiesJSON), properties)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = makeProcessError(process, operation, err, nil)
|
err = makeProcessError(process, operation, err, nil) //nolint:ineffassign
|
||||||
} else {
|
} else {
|
||||||
if properties.LastWaitResult != 0 {
|
if properties.LastWaitResult != 0 {
|
||||||
log.G(ctx).WithField("wait-result", properties.LastWaitResult).Warning("non-zero last wait result")
|
log.G(ctx).WithField("wait-result", properties.LastWaitResult).Warning("non-zero last wait result")
|
||||||
|
@ -468,7 +466,7 @@ func (process *Process) unregisterCallback(ctx context.Context) error {
|
||||||
delete(callbackMap, callbackNumber)
|
delete(callbackMap, callbackNumber)
|
||||||
callbackMapLock.Unlock()
|
callbackMapLock.Unlock()
|
||||||
|
|
||||||
handle = 0
|
handle = 0 //nolint:ineffassign
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package hcs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
hcsschema "github.com/Microsoft/hcsshim/internal/schema2"
|
||||||
|
"github.com/Microsoft/hcsshim/internal/vmcompute"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetServiceProperties returns properties of the host compute service.
|
||||||
|
func GetServiceProperties(ctx context.Context, q hcsschema.PropertyQuery) (*hcsschema.ServiceProperties, error) {
|
||||||
|
operation := "hcsshim::GetServiceProperties"
|
||||||
|
|
||||||
|
queryb, err := json.Marshal(q)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
propertiesJSON, resultJSON, err := vmcompute.HcsGetServiceProperties(ctx, string(queryb))
|
||||||
|
events := processHcsResult(ctx, resultJSON)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &HcsError{Op: operation, Err: err, Events: events}
|
||||||
|
}
|
||||||
|
|
||||||
|
if propertiesJSON == "" {
|
||||||
|
return nil, ErrUnexpectedValue
|
||||||
|
}
|
||||||
|
properties := &hcsschema.ServiceProperties{}
|
||||||
|
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return properties, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifyServiceSettings modifies settings of the host compute service.
|
||||||
|
func ModifyServiceSettings(ctx context.Context, settings hcsschema.ModificationRequest) error {
|
||||||
|
operation := "hcsshim::ModifyServiceSettings"
|
||||||
|
|
||||||
|
settingsJSON, err := json.Marshal(settings)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resultJSON, err := vmcompute.HcsModifyServiceSettings(ctx, string(settingsJSON))
|
||||||
|
events := processHcsResult(ctx, resultJSON)
|
||||||
|
if err != nil {
|
||||||
|
return &HcsError{Op: operation, Err: err, Events: events}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
package hcs
|
|
||||||
|
|
||||||
//go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go syscall.go
|
|
||||||
|
|
||||||
//sys hcsFormatWritableLayerVhd(handle uintptr) (hr error) = computestorage.HcsFormatWritableLayerVhd
|
|
|
@ -28,8 +28,7 @@ type System struct {
|
||||||
waitBlock chan struct{}
|
waitBlock chan struct{}
|
||||||
waitError error
|
waitError error
|
||||||
exitError error
|
exitError error
|
||||||
|
os, typ string
|
||||||
os, typ string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSystem(id string) *System {
|
func newSystem(id string) *System {
|
||||||
|
@ -74,8 +73,8 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in
|
||||||
if err = computeSystem.registerCallback(ctx); err != nil {
|
if err = computeSystem.registerCallback(ctx); err != nil {
|
||||||
// Terminate the compute system if it still exists. We're okay to
|
// Terminate the compute system if it still exists. We're okay to
|
||||||
// ignore a failure here.
|
// ignore a failure here.
|
||||||
computeSystem.Terminate(ctx)
|
_ = computeSystem.Terminate(ctx)
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +83,9 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in
|
||||||
if err == ErrTimeout {
|
if err == ErrTimeout {
|
||||||
// Terminate the compute system if it still exists. We're okay to
|
// Terminate the compute system if it still exists. We're okay to
|
||||||
// ignore a failure here.
|
// ignore a failure here.
|
||||||
computeSystem.Terminate(ctx)
|
_ = computeSystem.Terminate(ctx)
|
||||||
}
|
}
|
||||||
return nil, makeSystemError(computeSystem, operation, hcsDocument, err, events)
|
return nil, makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
go computeSystem.waitBackground()
|
go computeSystem.waitBackground()
|
||||||
if err = computeSystem.getCachedProperties(ctx); err != nil {
|
if err = computeSystem.getCachedProperties(ctx); err != nil {
|
||||||
|
@ -103,7 +102,7 @@ func OpenComputeSystem(ctx context.Context, id string) (*System, error) {
|
||||||
handle, resultJSON, err := vmcompute.HcsOpenComputeSystem(ctx, id)
|
handle, resultJSON, err := vmcompute.HcsOpenComputeSystem(ctx, id)
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, events)
|
return nil, makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
computeSystem.handle = handle
|
computeSystem.handle = handle
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -112,7 +111,7 @@ func OpenComputeSystem(ctx context.Context, id string) (*System, error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err = computeSystem.registerCallback(ctx); err != nil {
|
if err = computeSystem.registerCallback(ctx); err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
go computeSystem.waitBackground()
|
go computeSystem.waitBackground()
|
||||||
if err = computeSystem.getCachedProperties(ctx); err != nil {
|
if err = computeSystem.getCachedProperties(ctx); err != nil {
|
||||||
|
@ -188,13 +187,13 @@ func (computeSystem *System) Start(ctx context.Context) (err error) {
|
||||||
defer computeSystem.handleLock.RUnlock()
|
defer computeSystem.handleLock.RUnlock()
|
||||||
|
|
||||||
if computeSystem.handle == 0 {
|
if computeSystem.handle == 0 {
|
||||||
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
|
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "")
|
resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "")
|
||||||
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
|
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return makeSystemError(computeSystem, operation, "", err, events)
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -221,7 +220,7 @@ func (computeSystem *System) Shutdown(ctx context.Context) error {
|
||||||
switch err {
|
switch err {
|
||||||
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
|
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
|
||||||
default:
|
default:
|
||||||
return makeSystemError(computeSystem, operation, "", err, events)
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -242,7 +241,7 @@ func (computeSystem *System) Terminate(ctx context.Context) error {
|
||||||
switch err {
|
switch err {
|
||||||
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
|
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
|
||||||
default:
|
default:
|
||||||
return makeSystemError(computeSystem, operation, "", err, events)
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -264,10 +263,10 @@ func (computeSystem *System) waitBackground() {
|
||||||
log.G(ctx).Debug("system exited")
|
log.G(ctx).Debug("system exited")
|
||||||
case ErrVmcomputeUnexpectedExit:
|
case ErrVmcomputeUnexpectedExit:
|
||||||
log.G(ctx).Debug("unexpected system exit")
|
log.G(ctx).Debug("unexpected system exit")
|
||||||
computeSystem.exitError = makeSystemError(computeSystem, operation, "", err, nil)
|
computeSystem.exitError = makeSystemError(computeSystem, operation, err, nil)
|
||||||
err = nil
|
err = nil
|
||||||
default:
|
default:
|
||||||
err = makeSystemError(computeSystem, operation, "", err, nil)
|
err = makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
computeSystem.closedWaitOnce.Do(func() {
|
computeSystem.closedWaitOnce.Do(func() {
|
||||||
computeSystem.waitError = err
|
computeSystem.waitError = err
|
||||||
|
@ -305,13 +304,13 @@ func (computeSystem *System) Properties(ctx context.Context, types ...schema1.Pr
|
||||||
|
|
||||||
queryBytes, err := json.Marshal(schema1.PropertyQuery{PropertyTypes: types})
|
queryBytes, err := json.Marshal(schema1.PropertyQuery{PropertyTypes: types})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
|
propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, events)
|
return nil, makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
if propertiesJSON == "" {
|
if propertiesJSON == "" {
|
||||||
|
@ -319,7 +318,7 @@ func (computeSystem *System) Properties(ctx context.Context, types ...schema1.Pr
|
||||||
}
|
}
|
||||||
properties := &schema1.ContainerProperties{}
|
properties := &schema1.ContainerProperties{}
|
||||||
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
|
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties, nil
|
return properties, nil
|
||||||
|
@ -334,13 +333,13 @@ func (computeSystem *System) PropertiesV2(ctx context.Context, types ...hcsschem
|
||||||
|
|
||||||
queryBytes, err := json.Marshal(hcsschema.PropertyQuery{PropertyTypes: types})
|
queryBytes, err := json.Marshal(hcsschema.PropertyQuery{PropertyTypes: types})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
|
propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, events)
|
return nil, makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
if propertiesJSON == "" {
|
if propertiesJSON == "" {
|
||||||
|
@ -348,7 +347,7 @@ func (computeSystem *System) PropertiesV2(ctx context.Context, types ...hcsschem
|
||||||
}
|
}
|
||||||
properties := &hcsschema.Properties{}
|
properties := &hcsschema.Properties{}
|
||||||
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
|
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties, nil
|
return properties, nil
|
||||||
|
@ -369,13 +368,13 @@ func (computeSystem *System) Pause(ctx context.Context) (err error) {
|
||||||
defer computeSystem.handleLock.RUnlock()
|
defer computeSystem.handleLock.RUnlock()
|
||||||
|
|
||||||
if computeSystem.handle == 0 {
|
if computeSystem.handle == 0 {
|
||||||
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
|
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultJSON, err := vmcompute.HcsPauseComputeSystem(ctx, computeSystem.handle, "")
|
resultJSON, err := vmcompute.HcsPauseComputeSystem(ctx, computeSystem.handle, "")
|
||||||
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
|
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return makeSystemError(computeSystem, operation, "", err, events)
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -396,13 +395,45 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) {
|
||||||
defer computeSystem.handleLock.RUnlock()
|
defer computeSystem.handleLock.RUnlock()
|
||||||
|
|
||||||
if computeSystem.handle == 0 {
|
if computeSystem.handle == 0 {
|
||||||
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
|
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultJSON, err := vmcompute.HcsResumeComputeSystem(ctx, computeSystem.handle, "")
|
resultJSON, err := vmcompute.HcsResumeComputeSystem(ctx, computeSystem.handle, "")
|
||||||
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
|
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return makeSystemError(computeSystem, operation, "", err, events)
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the compute system
|
||||||
|
func (computeSystem *System) Save(ctx context.Context, options interface{}) (err error) {
|
||||||
|
operation := "hcsshim::System::Save"
|
||||||
|
|
||||||
|
// hcsSaveComputeSystemContext is an async peration. Start the outer span
|
||||||
|
// here to measure the full save time.
|
||||||
|
ctx, span := trace.StartSpan(ctx, operation)
|
||||||
|
defer span.End()
|
||||||
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
|
||||||
|
|
||||||
|
saveOptions, err := json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
computeSystem.handleLock.RLock()
|
||||||
|
defer computeSystem.handleLock.RUnlock()
|
||||||
|
|
||||||
|
if computeSystem.handle == 0 {
|
||||||
|
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := vmcompute.HcsSaveComputeSystem(ctx, computeSystem.handle, string(saveOptions))
|
||||||
|
events, err := processAsyncHcsResult(ctx, err, result, computeSystem.callbackNumber, hcsNotificationSystemSaveCompleted, &timeout.SystemSave)
|
||||||
|
if err != nil {
|
||||||
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -413,19 +444,19 @@ func (computeSystem *System) createProcess(ctx context.Context, operation string
|
||||||
defer computeSystem.handleLock.RUnlock()
|
defer computeSystem.handleLock.RUnlock()
|
||||||
|
|
||||||
if computeSystem.handle == 0 {
|
if computeSystem.handle == 0 {
|
||||||
return nil, nil, makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
|
return nil, nil, makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
configurationb, err := json.Marshal(c)
|
configurationb, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration := string(configurationb)
|
configuration := string(configurationb)
|
||||||
processInfo, processHandle, resultJSON, err := vmcompute.HcsCreateProcess(ctx, computeSystem.handle, configuration)
|
processInfo, processHandle, resultJSON, err := vmcompute.HcsCreateProcess(ctx, computeSystem.handle, configuration)
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, makeSystemError(computeSystem, operation, configuration, err, events)
|
return nil, nil, makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.G(ctx).WithField("pid", processInfo.ProcessId).Debug("created process pid")
|
log.G(ctx).WithField("pid", processInfo.ProcessId).Debug("created process pid")
|
||||||
|
@ -447,7 +478,7 @@ func (computeSystem *System) CreateProcess(ctx context.Context, c interface{}) (
|
||||||
|
|
||||||
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
|
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
process.stdin = pipes[0]
|
process.stdin = pipes[0]
|
||||||
process.stdout = pipes[1]
|
process.stdout = pipes[1]
|
||||||
|
@ -455,7 +486,7 @@ func (computeSystem *System) CreateProcess(ctx context.Context, c interface{}) (
|
||||||
process.hasCachedStdio = true
|
process.hasCachedStdio = true
|
||||||
|
|
||||||
if err = process.registerCallback(ctx); err != nil {
|
if err = process.registerCallback(ctx); err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
go process.waitBackground()
|
go process.waitBackground()
|
||||||
|
|
||||||
|
@ -470,18 +501,18 @@ func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process
|
||||||
operation := "hcsshim::System::OpenProcess"
|
operation := "hcsshim::System::OpenProcess"
|
||||||
|
|
||||||
if computeSystem.handle == 0 {
|
if computeSystem.handle == 0 {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
|
return nil, makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
processHandle, resultJSON, err := vmcompute.HcsOpenProcess(ctx, computeSystem.handle, uint32(pid))
|
processHandle, resultJSON, err := vmcompute.HcsOpenProcess(ctx, computeSystem.handle, uint32(pid))
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, events)
|
return nil, makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
process := newProcess(processHandle, pid, computeSystem)
|
process := newProcess(processHandle, pid, computeSystem)
|
||||||
if err = process.registerCallback(ctx); err != nil {
|
if err = process.registerCallback(ctx); err != nil {
|
||||||
return nil, makeSystemError(computeSystem, operation, "", err, nil)
|
return nil, makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
go process.waitBackground()
|
go process.waitBackground()
|
||||||
|
|
||||||
|
@ -505,12 +536,12 @@ func (computeSystem *System) Close() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = computeSystem.unregisterCallback(ctx); err != nil {
|
if err = computeSystem.unregisterCallback(ctx); err != nil {
|
||||||
return makeSystemError(computeSystem, operation, "", err, nil)
|
return makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = vmcompute.HcsCloseComputeSystem(ctx, computeSystem.handle)
|
err = vmcompute.HcsCloseComputeSystem(ctx, computeSystem.handle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return makeSystemError(computeSystem, operation, "", err, nil)
|
return makeSystemError(computeSystem, operation, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
computeSystem.handle = 0
|
computeSystem.handle = 0
|
||||||
|
@ -574,7 +605,7 @@ func (computeSystem *System) unregisterCallback(ctx context.Context) error {
|
||||||
delete(callbackMap, callbackNumber)
|
delete(callbackMap, callbackNumber)
|
||||||
callbackMapLock.Unlock()
|
callbackMapLock.Unlock()
|
||||||
|
|
||||||
handle = 0
|
handle = 0 //nolint:ineffassign
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -587,7 +618,7 @@ func (computeSystem *System) Modify(ctx context.Context, config interface{}) err
|
||||||
operation := "hcsshim::System::Modify"
|
operation := "hcsshim::System::Modify"
|
||||||
|
|
||||||
if computeSystem.handle == 0 {
|
if computeSystem.handle == 0 {
|
||||||
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
|
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBytes, err := json.Marshal(config)
|
requestBytes, err := json.Marshal(config)
|
||||||
|
@ -599,7 +630,7 @@ func (computeSystem *System) Modify(ctx context.Context, config interface{}) err
|
||||||
resultJSON, err := vmcompute.HcsModifyComputeSystem(ctx, computeSystem.handle, requestJSON)
|
resultJSON, err := vmcompute.HcsModifyComputeSystem(ctx, computeSystem.handle, requestJSON)
|
||||||
events := processHcsResult(ctx, resultJSON)
|
events := processHcsResult(ctx, resultJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return makeSystemError(computeSystem, operation, requestJSON, err, events)
|
return makeSystemError(computeSystem, operation, err, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/Microsoft/go-winio"
|
"github.com/Microsoft/go-winio"
|
||||||
diskutil "github.com/Microsoft/go-winio/vhd"
|
diskutil "github.com/Microsoft/go-winio/vhd"
|
||||||
|
"github.com/Microsoft/hcsshim/computestorage"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
@ -36,7 +37,7 @@ func makeOpenFiles(hs []syscall.Handle) (_ []io.ReadWriteCloser, err error) {
|
||||||
return fs, nil
|
return fs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a VHD formatted with NTFS of size `sizeGB` at the given `vhdPath`.
|
// CreateNTFSVHD creates a VHD formatted with NTFS of size `sizeGB` at the given `vhdPath`.
|
||||||
func CreateNTFSVHD(ctx context.Context, vhdPath string, sizeGB uint32) (err error) {
|
func CreateNTFSVHD(ctx context.Context, vhdPath string, sizeGB uint32) (err error) {
|
||||||
if err := diskutil.CreateVhdx(vhdPath, sizeGB, 1); err != nil {
|
if err := diskutil.CreateVhdx(vhdPath, sizeGB, 1); err != nil {
|
||||||
return errors.Wrap(err, "failed to create VHD")
|
return errors.Wrap(err, "failed to create VHD")
|
||||||
|
@ -53,7 +54,7 @@ func CreateNTFSVHD(ctx context.Context, vhdPath string, sizeGB uint32) (err erro
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := hcsFormatWritableLayerVhd(uintptr(vhd)); err != nil {
|
if err := computestorage.FormatWritableLayerVhd(ctx, windows.Handle(vhd)); err != nil {
|
||||||
return errors.Wrap(err, "failed to format VHD")
|
return errors.Wrap(err, "failed to format VHD")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,5 +65,4 @@ func waitForNotification(ctx context.Context, callbackNumber uintptr, expectedNo
|
||||||
case <-c:
|
case <-c:
|
||||||
return ErrTimeout
|
return ErrTimeout
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
// Code generated mksyscall_windows.exe DO NOT EDIT
|
|
||||||
|
|
||||||
package hcs
|
|
||||||
|
|
||||||
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 (
|
|
||||||
modcomputestorage = windows.NewLazySystemDLL("computestorage.dll")
|
|
||||||
|
|
||||||
procHcsFormatWritableLayerVhd = modcomputestorage.NewProc("HcsFormatWritableLayerVhd")
|
|
||||||
)
|
|
||||||
|
|
||||||
func hcsFormatWritableLayerVhd(handle uintptr) (hr error) {
|
|
||||||
r0, _, _ := syscall.Syscall(procHcsFormatWritableLayerVhd.Addr(), 1, uintptr(handle), 0, 0)
|
|
||||||
if int32(r0) < 0 {
|
|
||||||
if r0&0x1fff0000 == 0x00070000 {
|
|
||||||
r0 &= 0xffff
|
|
||||||
}
|
|
||||||
hr = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -17,12 +17,15 @@ type HNSEndpoint struct {
|
||||||
Policies []json.RawMessage `json:",omitempty"`
|
Policies []json.RawMessage `json:",omitempty"`
|
||||||
MacAddress string `json:",omitempty"`
|
MacAddress string `json:",omitempty"`
|
||||||
IPAddress net.IP `json:",omitempty"`
|
IPAddress net.IP `json:",omitempty"`
|
||||||
|
IPv6Address net.IP `json:",omitempty"`
|
||||||
DNSSuffix string `json:",omitempty"`
|
DNSSuffix string `json:",omitempty"`
|
||||||
DNSServerList string `json:",omitempty"`
|
DNSServerList string `json:",omitempty"`
|
||||||
GatewayAddress string `json:",omitempty"`
|
GatewayAddress string `json:",omitempty"`
|
||||||
|
GatewayAddressV6 string `json:",omitempty"`
|
||||||
EnableInternalDNS bool `json:",omitempty"`
|
EnableInternalDNS bool `json:",omitempty"`
|
||||||
DisableICC bool `json:",omitempty"`
|
DisableICC bool `json:",omitempty"`
|
||||||
PrefixLength uint8 `json:",omitempty"`
|
PrefixLength uint8 `json:",omitempty"`
|
||||||
|
IPv6PrefixLength uint8 `json:",omitempty"`
|
||||||
IsRemoteEndpoint bool `json:",omitempty"`
|
IsRemoteEndpoint bool `json:",omitempty"`
|
||||||
EnableLowMetric bool `json:",omitempty"`
|
EnableLowMetric bool `json:",omitempty"`
|
||||||
Namespace *Namespace `json:",omitempty"`
|
Namespace *Namespace `json:",omitempty"`
|
||||||
|
|
|
@ -39,12 +39,6 @@ type HNSNetwork struct {
|
||||||
AutomaticDNS bool `json:",omitempty"`
|
AutomaticDNS bool `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type hnsNetworkResponse struct {
|
|
||||||
Success bool
|
|
||||||
Error string
|
|
||||||
Output HNSNetwork
|
|
||||||
}
|
|
||||||
|
|
||||||
type hnsResponse struct {
|
type hnsResponse struct {
|
||||||
Success bool
|
Success bool
|
||||||
Error string
|
Error string
|
||||||
|
|
|
@ -27,9 +27,10 @@ type namespaceResourceRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Namespace struct {
|
type Namespace struct {
|
||||||
ID string
|
ID string
|
||||||
IsDefault bool `json:",omitempty"`
|
IsDefault bool `json:",omitempty"`
|
||||||
ResourceList []NamespaceResource `json:",omitempty"`
|
ResourceList []NamespaceResource `json:",omitempty"`
|
||||||
|
CompartmentId uint32 `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func issueNamespaceRequest(id *string, method, subpath string, request interface{}) (*Namespace, error) {
|
func issueNamespaceRequest(id *string, method, subpath string, request interface{}) (*Namespace, error) {
|
||||||
|
|
|
@ -11,72 +11,11 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/Microsoft/hcsshim/internal/longpath"
|
"github.com/Microsoft/hcsshim/internal/longpath"
|
||||||
|
"github.com/Microsoft/hcsshim/internal/winapi"
|
||||||
|
|
||||||
winio "github.com/Microsoft/go-winio"
|
winio "github.com/Microsoft/go-winio"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run $GOROOT\src\syscall\mksyscall_windows.go -output zsyscall_windows.go safeopen.go
|
|
||||||
|
|
||||||
//sys ntCreateFile(handle *uintptr, accessMask uint32, oa *objectAttributes, iosb *ioStatusBlock, allocationSize *uint64, fileAttributes uint32, shareAccess uint32, createDisposition uint32, createOptions uint32, eaBuffer *byte, eaLength uint32) (status uint32) = ntdll.NtCreateFile
|
|
||||||
//sys ntSetInformationFile(handle uintptr, iosb *ioStatusBlock, information uintptr, length uint32, class uint32) (status uint32) = ntdll.NtSetInformationFile
|
|
||||||
//sys rtlNtStatusToDosError(status uint32) (winerr error) = ntdll.RtlNtStatusToDosErrorNoTeb
|
|
||||||
//sys localAlloc(flags uint32, size int) (ptr uintptr) = kernel32.LocalAlloc
|
|
||||||
//sys localFree(ptr uintptr) = kernel32.LocalFree
|
|
||||||
|
|
||||||
type ioStatusBlock struct {
|
|
||||||
Status, Information uintptr
|
|
||||||
}
|
|
||||||
|
|
||||||
type objectAttributes struct {
|
|
||||||
Length uintptr
|
|
||||||
RootDirectory uintptr
|
|
||||||
ObjectName uintptr
|
|
||||||
Attributes uintptr
|
|
||||||
SecurityDescriptor uintptr
|
|
||||||
SecurityQoS uintptr
|
|
||||||
}
|
|
||||||
|
|
||||||
type unicodeString struct {
|
|
||||||
Length uint16
|
|
||||||
MaximumLength uint16
|
|
||||||
Buffer uintptr
|
|
||||||
}
|
|
||||||
|
|
||||||
type fileLinkInformation struct {
|
|
||||||
ReplaceIfExists bool
|
|
||||||
RootDirectory uintptr
|
|
||||||
FileNameLength uint32
|
|
||||||
FileName [1]uint16
|
|
||||||
}
|
|
||||||
|
|
||||||
type fileDispositionInformationEx struct {
|
|
||||||
Flags uintptr
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
_FileLinkInformation = 11
|
|
||||||
_FileDispositionInformationEx = 64
|
|
||||||
|
|
||||||
FILE_READ_ATTRIBUTES = 0x0080
|
|
||||||
FILE_WRITE_ATTRIBUTES = 0x0100
|
|
||||||
DELETE = 0x10000
|
|
||||||
|
|
||||||
FILE_OPEN = 1
|
|
||||||
FILE_CREATE = 2
|
|
||||||
|
|
||||||
FILE_DIRECTORY_FILE = 0x00000001
|
|
||||||
FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020
|
|
||||||
FILE_DELETE_ON_CLOSE = 0x00001000
|
|
||||||
FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000
|
|
||||||
FILE_OPEN_REPARSE_POINT = 0x00200000
|
|
||||||
|
|
||||||
FILE_DISPOSITION_DELETE = 0x00000001
|
|
||||||
|
|
||||||
_OBJ_DONT_REPARSE = 0x1000
|
|
||||||
|
|
||||||
_STATUS_REPARSE_POINT_ENCOUNTERED = 0xC000050B
|
|
||||||
)
|
|
||||||
|
|
||||||
func OpenRoot(path string) (*os.File, error) {
|
func OpenRoot(path string) (*os.File, error) {
|
||||||
longpath, err := longpath.LongAbs(path)
|
longpath, err := longpath.LongAbs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -85,16 +24,24 @@ func OpenRoot(path string) (*os.File, error) {
|
||||||
return winio.OpenForBackup(longpath, syscall.GENERIC_READ, syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, syscall.OPEN_EXISTING)
|
return winio.OpenForBackup(longpath, syscall.GENERIC_READ, syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, syscall.OPEN_EXISTING)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ntRelativePath(path string) ([]uint16, error) {
|
func cleanGoStringRelativePath(path string) (string, error) {
|
||||||
path = filepath.Clean(path)
|
path = filepath.Clean(path)
|
||||||
if strings.Contains(path, ":") {
|
if strings.Contains(path, ":") {
|
||||||
// Since alternate data streams must follow the file they
|
// Since alternate data streams must follow the file they
|
||||||
// are attached to, finding one here (out of order) is invalid.
|
// are attached to, finding one here (out of order) is invalid.
|
||||||
return nil, errors.New("path contains invalid character `:`")
|
return "", errors.New("path contains invalid character `:`")
|
||||||
}
|
}
|
||||||
fspath := filepath.FromSlash(path)
|
fspath := filepath.FromSlash(path)
|
||||||
if len(fspath) > 0 && fspath[0] == '\\' {
|
if len(fspath) > 0 && fspath[0] == '\\' {
|
||||||
return nil, errors.New("expected relative path")
|
return "", errors.New("expected relative path")
|
||||||
|
}
|
||||||
|
return fspath, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ntRelativePath(path string) ([]uint16, error) {
|
||||||
|
fspath, err := cleanGoStringRelativePath(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
path16 := utf16.Encode(([]rune)(fspath))
|
path16 := utf16.Encode(([]rune)(fspath))
|
||||||
|
@ -110,11 +57,11 @@ func ntRelativePath(path string) ([]uint16, error) {
|
||||||
func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
|
func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
|
||||||
var (
|
var (
|
||||||
h uintptr
|
h uintptr
|
||||||
iosb ioStatusBlock
|
iosb winapi.IOStatusBlock
|
||||||
oa objectAttributes
|
oa winapi.ObjectAttributes
|
||||||
)
|
)
|
||||||
|
|
||||||
path16, err := ntRelativePath(path)
|
cleanRelativePath, err := cleanGoStringRelativePath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -123,20 +70,16 @@ func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFl
|
||||||
return nil, errors.New("missing root directory")
|
return nil, errors.New("missing root directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
upathBuffer := localAlloc(0, int(unsafe.Sizeof(unicodeString{}))+len(path16)*2)
|
pathUnicode, err := winapi.NewUnicodeString(cleanRelativePath)
|
||||||
defer localFree(upathBuffer)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
upath := (*unicodeString)(unsafe.Pointer(upathBuffer))
|
}
|
||||||
upath.Length = uint16(len(path16) * 2)
|
|
||||||
upath.MaximumLength = upath.Length
|
|
||||||
upath.Buffer = upathBuffer + unsafe.Sizeof(*upath)
|
|
||||||
copy((*[32768]uint16)(unsafe.Pointer(upath.Buffer))[:], path16)
|
|
||||||
|
|
||||||
oa.Length = unsafe.Sizeof(oa)
|
oa.Length = unsafe.Sizeof(oa)
|
||||||
oa.ObjectName = upathBuffer
|
oa.ObjectName = pathUnicode
|
||||||
oa.RootDirectory = uintptr(root.Fd())
|
oa.RootDirectory = uintptr(root.Fd())
|
||||||
oa.Attributes = _OBJ_DONT_REPARSE
|
oa.Attributes = winapi.OBJ_DONT_REPARSE
|
||||||
status := ntCreateFile(
|
status := winapi.NtCreateFile(
|
||||||
&h,
|
&h,
|
||||||
accessMask|syscall.SYNCHRONIZE,
|
accessMask|syscall.SYNCHRONIZE,
|
||||||
&oa,
|
&oa,
|
||||||
|
@ -145,12 +88,12 @@ func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFl
|
||||||
0,
|
0,
|
||||||
shareFlags,
|
shareFlags,
|
||||||
createDisposition,
|
createDisposition,
|
||||||
FILE_OPEN_FOR_BACKUP_INTENT|FILE_SYNCHRONOUS_IO_NONALERT|flags,
|
winapi.FILE_OPEN_FOR_BACKUP_INTENT|winapi.FILE_SYNCHRONOUS_IO_NONALERT|flags,
|
||||||
nil,
|
nil,
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
if status != 0 {
|
if status != 0 {
|
||||||
return nil, rtlNtStatusToDosError(status)
|
return nil, winapi.RtlNtStatusToDosError(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath, err := longpath.LongAbs(filepath.Join(root.Name(), path))
|
fullPath, err := longpath.LongAbs(filepath.Join(root.Name(), path))
|
||||||
|
@ -182,7 +125,7 @@ func LinkRelative(oldname string, oldroot *os.File, newname string, newroot *os.
|
||||||
oldroot,
|
oldroot,
|
||||||
syscall.FILE_WRITE_ATTRIBUTES,
|
syscall.FILE_WRITE_ATTRIBUTES,
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
||||||
FILE_OPEN,
|
winapi.FILE_OPEN,
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -199,8 +142,8 @@ func LinkRelative(oldname string, oldroot *os.File, newname string, newroot *os.
|
||||||
newroot,
|
newroot,
|
||||||
syscall.GENERIC_READ,
|
syscall.GENERIC_READ,
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
||||||
FILE_OPEN,
|
winapi.FILE_OPEN,
|
||||||
FILE_DIRECTORY_FILE)
|
winapi.FILE_DIRECTORY_FILE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &os.LinkError{Op: "link", Old: oldf.Name(), New: filepath.Join(newroot.Name(), newname), Err: err}
|
return &os.LinkError{Op: "link", Old: oldf.Name(), New: filepath.Join(newroot.Name(), newname), Err: err}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +154,7 @@ func LinkRelative(oldname string, oldroot *os.File, newname string, newroot *os.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if (fi.FileAttributes & syscall.FILE_ATTRIBUTE_REPARSE_POINT) != 0 {
|
if (fi.FileAttributes & syscall.FILE_ATTRIBUTE_REPARSE_POINT) != 0 {
|
||||||
return &os.LinkError{Op: "link", Old: oldf.Name(), New: filepath.Join(newroot.Name(), newname), Err: rtlNtStatusToDosError(_STATUS_REPARSE_POINT_ENCOUNTERED)}
|
return &os.LinkError{Op: "link", Old: oldf.Name(), New: filepath.Join(newroot.Name(), newname), Err: winapi.RtlNtStatusToDosError(winapi.STATUS_REPARSE_POINT_ENCOUNTERED)}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -227,24 +170,25 @@ func LinkRelative(oldname string, oldroot *os.File, newname string, newroot *os.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
size := int(unsafe.Offsetof(fileLinkInformation{}.FileName)) + len(newbase16)*2
|
size := int(unsafe.Offsetof(winapi.FileLinkInformation{}.FileName)) + len(newbase16)*2
|
||||||
linkinfoBuffer := localAlloc(0, size)
|
linkinfoBuffer := winapi.LocalAlloc(0, size)
|
||||||
defer localFree(linkinfoBuffer)
|
defer winapi.LocalFree(linkinfoBuffer)
|
||||||
linkinfo := (*fileLinkInformation)(unsafe.Pointer(linkinfoBuffer))
|
|
||||||
|
linkinfo := (*winapi.FileLinkInformation)(unsafe.Pointer(linkinfoBuffer))
|
||||||
linkinfo.RootDirectory = parent.Fd()
|
linkinfo.RootDirectory = parent.Fd()
|
||||||
linkinfo.FileNameLength = uint32(len(newbase16) * 2)
|
linkinfo.FileNameLength = uint32(len(newbase16) * 2)
|
||||||
copy((*[32768]uint16)(unsafe.Pointer(&linkinfo.FileName[0]))[:], newbase16)
|
copy(winapi.Uint16BufferToSlice(&linkinfo.FileName[0], len(newbase16)), newbase16)
|
||||||
|
|
||||||
var iosb ioStatusBlock
|
var iosb winapi.IOStatusBlock
|
||||||
status := ntSetInformationFile(
|
status := winapi.NtSetInformationFile(
|
||||||
oldf.Fd(),
|
oldf.Fd(),
|
||||||
&iosb,
|
&iosb,
|
||||||
linkinfoBuffer,
|
linkinfoBuffer,
|
||||||
uint32(size),
|
uint32(size),
|
||||||
_FileLinkInformation,
|
winapi.FileLinkInformationClass,
|
||||||
)
|
)
|
||||||
if status != 0 {
|
if status != 0 {
|
||||||
return &os.LinkError{Op: "link", Old: oldf.Name(), New: filepath.Join(parent.Name(), newbase), Err: rtlNtStatusToDosError(status)}
|
return &os.LinkError{Op: "link", Old: oldf.Name(), New: filepath.Join(parent.Name(), newbase), Err: winapi.RtlNtStatusToDosError(status)}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -252,17 +196,17 @@ func LinkRelative(oldname string, oldroot *os.File, newname string, newroot *os.
|
||||||
|
|
||||||
// deleteOnClose marks a file to be deleted when the handle is closed.
|
// deleteOnClose marks a file to be deleted when the handle is closed.
|
||||||
func deleteOnClose(f *os.File) error {
|
func deleteOnClose(f *os.File) error {
|
||||||
disposition := fileDispositionInformationEx{Flags: FILE_DISPOSITION_DELETE}
|
disposition := winapi.FileDispositionInformationEx{Flags: winapi.FILE_DISPOSITION_DELETE}
|
||||||
var iosb ioStatusBlock
|
var iosb winapi.IOStatusBlock
|
||||||
status := ntSetInformationFile(
|
status := winapi.NtSetInformationFile(
|
||||||
f.Fd(),
|
f.Fd(),
|
||||||
&iosb,
|
&iosb,
|
||||||
uintptr(unsafe.Pointer(&disposition)),
|
uintptr(unsafe.Pointer(&disposition)),
|
||||||
uint32(unsafe.Sizeof(disposition)),
|
uint32(unsafe.Sizeof(disposition)),
|
||||||
_FileDispositionInformationEx,
|
winapi.FileDispositionInformationExClass,
|
||||||
)
|
)
|
||||||
if status != 0 {
|
if status != 0 {
|
||||||
return rtlNtStatusToDosError(status)
|
return winapi.RtlNtStatusToDosError(status)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -291,16 +235,16 @@ func RemoveRelative(path string, root *os.File) error {
|
||||||
f, err := openRelativeInternal(
|
f, err := openRelativeInternal(
|
||||||
path,
|
path,
|
||||||
root,
|
root,
|
||||||
FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|DELETE,
|
winapi.FILE_READ_ATTRIBUTES|winapi.FILE_WRITE_ATTRIBUTES|winapi.DELETE,
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
||||||
FILE_OPEN,
|
winapi.FILE_OPEN,
|
||||||
FILE_OPEN_REPARSE_POINT)
|
winapi.FILE_OPEN_REPARSE_POINT)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
err = deleteOnClose(f)
|
err = deleteOnClose(f)
|
||||||
if err == syscall.ERROR_ACCESS_DENIED {
|
if err == syscall.ERROR_ACCESS_DENIED {
|
||||||
// Maybe the file is marked readonly. Clear the bit and retry.
|
// Maybe the file is marked readonly. Clear the bit and retry.
|
||||||
clearReadOnly(f)
|
_ = clearReadOnly(f)
|
||||||
err = deleteOnClose(f)
|
err = deleteOnClose(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,8 +329,8 @@ func MkdirRelative(path string, root *os.File) error {
|
||||||
root,
|
root,
|
||||||
0,
|
0,
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
||||||
FILE_CREATE,
|
winapi.FILE_CREATE,
|
||||||
FILE_DIRECTORY_FILE)
|
winapi.FILE_DIRECTORY_FILE)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
} else {
|
} else {
|
||||||
|
@ -401,10 +345,10 @@ func LstatRelative(path string, root *os.File) (os.FileInfo, error) {
|
||||||
f, err := openRelativeInternal(
|
f, err := openRelativeInternal(
|
||||||
path,
|
path,
|
||||||
root,
|
root,
|
||||||
FILE_READ_ATTRIBUTES,
|
winapi.FILE_READ_ATTRIBUTES,
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
||||||
FILE_OPEN,
|
winapi.FILE_OPEN,
|
||||||
FILE_OPEN_REPARSE_POINT)
|
winapi.FILE_OPEN_REPARSE_POINT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &os.PathError{Op: "stat", Path: filepath.Join(root.Name(), path), Err: err}
|
return nil, &os.PathError{Op: "stat", Path: filepath.Join(root.Name(), path), Err: err}
|
||||||
}
|
}
|
||||||
|
@ -421,7 +365,7 @@ func EnsureNotReparsePointRelative(path string, root *os.File) error {
|
||||||
root,
|
root,
|
||||||
0,
|
0,
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
||||||
FILE_OPEN,
|
winapi.FILE_OPEN,
|
||||||
0)
|
0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
// Code generated by 'go generate'; DO NOT EDIT.
|
|
||||||
|
|
||||||
package safefile
|
|
||||||
|
|
||||||
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 (
|
|
||||||
modntdll = windows.NewLazySystemDLL("ntdll.dll")
|
|
||||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
|
||||||
|
|
||||||
procNtCreateFile = modntdll.NewProc("NtCreateFile")
|
|
||||||
procNtSetInformationFile = modntdll.NewProc("NtSetInformationFile")
|
|
||||||
procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
|
|
||||||
procLocalAlloc = modkernel32.NewProc("LocalAlloc")
|
|
||||||
procLocalFree = modkernel32.NewProc("LocalFree")
|
|
||||||
)
|
|
||||||
|
|
||||||
func ntCreateFile(handle *uintptr, accessMask uint32, oa *objectAttributes, iosb *ioStatusBlock, allocationSize *uint64, fileAttributes uint32, shareAccess uint32, createDisposition uint32, createOptions uint32, eaBuffer *byte, eaLength uint32) (status uint32) {
|
|
||||||
r0, _, _ := syscall.Syscall12(procNtCreateFile.Addr(), 11, uintptr(unsafe.Pointer(handle)), uintptr(accessMask), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(allocationSize)), uintptr(fileAttributes), uintptr(shareAccess), uintptr(createDisposition), uintptr(createOptions), uintptr(unsafe.Pointer(eaBuffer)), uintptr(eaLength), 0)
|
|
||||||
status = uint32(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func ntSetInformationFile(handle uintptr, iosb *ioStatusBlock, information uintptr, length uint32, class uint32) (status uint32) {
|
|
||||||
r0, _, _ := syscall.Syscall6(procNtSetInformationFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(information), uintptr(length), uintptr(class), 0)
|
|
||||||
status = uint32(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func rtlNtStatusToDosError(status uint32) (winerr error) {
|
|
||||||
r0, _, _ := syscall.Syscall(procRtlNtStatusToDosErrorNoTeb.Addr(), 1, uintptr(status), 0, 0)
|
|
||||||
if r0 != 0 {
|
|
||||||
winerr = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func localAlloc(flags uint32, size int) (ptr uintptr) {
|
|
||||||
r0, _, _ := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(flags), uintptr(size), 0)
|
|
||||||
ptr = uintptr(r0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func localFree(ptr uintptr) {
|
|
||||||
syscall.Syscall(procLocalFree.Addr(), 1, uintptr(ptr), 0, 0)
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -119,9 +119,9 @@ type PropertyType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PropertyTypeStatistics PropertyType = "Statistics" // V1 and V2
|
PropertyTypeStatistics PropertyType = "Statistics" // V1 and V2
|
||||||
PropertyTypeProcessList = "ProcessList" // V1 and V2
|
PropertyTypeProcessList PropertyType = "ProcessList" // V1 and V2
|
||||||
PropertyTypeMappedVirtualDisk = "MappedVirtualDisk" // Not supported in V2 schema call
|
PropertyTypeMappedVirtualDisk PropertyType = "MappedVirtualDisk" // Not supported in V2 schema call
|
||||||
PropertyTypeGuestConnection = "GuestConnection" // V1 and V2. Nil return from HCS before RS5
|
PropertyTypeGuestConnection PropertyType = "GuestConnection" // V1 and V2. Nil return from HCS before RS5
|
||||||
)
|
)
|
||||||
|
|
||||||
type PropertyQuery struct {
|
type PropertyQuery struct {
|
||||||
|
@ -218,6 +218,7 @@ type GuestDefinedCapabilities struct {
|
||||||
SignalProcessSupported bool `json:",omitempty"`
|
SignalProcessSupported bool `json:",omitempty"`
|
||||||
DumpStacksSupported bool `json:",omitempty"`
|
DumpStacksSupported bool `json:",omitempty"`
|
||||||
DeleteContainerStateSupported bool `json:",omitempty"`
|
DeleteContainerStateSupported bool `json:",omitempty"`
|
||||||
|
UpdateContainerSupported bool `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM
|
// GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM
|
||||||
|
|
16
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_add_instance_request.go
generated
vendored
Normal file
16
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_add_instance_request.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardAddInstanceRequest struct {
|
||||||
|
Id string `json:"Id,omitempty"`
|
||||||
|
CredentialSpec string `json:"CredentialSpec,omitempty"`
|
||||||
|
Transport string `json:"Transport,omitempty"`
|
||||||
|
}
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_hv_socket_service_config.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_hv_socket_service_config.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardHvSocketServiceConfig struct {
|
||||||
|
ServiceId string `json:"ServiceId,omitempty"`
|
||||||
|
ServiceConfig *HvSocketServiceConfig `json:"ServiceConfig,omitempty"`
|
||||||
|
}
|
16
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_instance.go
generated
vendored
Normal file
16
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_instance.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardInstance struct {
|
||||||
|
Id string `json:"Id,omitempty"`
|
||||||
|
CredentialGuard *ContainerCredentialGuardState `json:"CredentialGuard,omitempty"`
|
||||||
|
HvSocketConfig *ContainerCredentialGuardHvSocketServiceConfig `json:"HvSocketConfig,omitempty"`
|
||||||
|
}
|
17
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_modify_operation.go
generated
vendored
Normal file
17
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_modify_operation.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardModifyOperation string
|
||||||
|
|
||||||
|
const (
|
||||||
|
AddInstance ContainerCredentialGuardModifyOperation = "AddInstance"
|
||||||
|
RemoveInstance ContainerCredentialGuardModifyOperation = "RemoveInstance"
|
||||||
|
)
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_operation_request.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_operation_request.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardOperationRequest struct {
|
||||||
|
Operation ContainerCredentialGuardModifyOperation `json:"Operation,omitempty"`
|
||||||
|
OperationDetails interface{} `json:"OperationDetails,omitempty"`
|
||||||
|
}
|
14
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_remove_instance_request.go
generated
vendored
Normal file
14
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_remove_instance_request.go
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardRemoveInstanceRequest struct {
|
||||||
|
Id string `json:"Id,omitempty"`
|
||||||
|
}
|
14
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_system_info.go
generated
vendored
Normal file
14
vendor/github.com/Microsoft/hcsshim/internal/schema2/container_credential_guard_system_info.go
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ContainerCredentialGuardSystemInfo struct {
|
||||||
|
Instances []ContainerCredentialGuardInstance `json:"Instances,omitempty"`
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// CPU groups allow Hyper-V administrators to better manage and allocate the host's CPU resources across guest virtual machines
|
||||||
|
type CpuGroup struct {
|
||||||
|
Id string `json:"Id,omitempty"`
|
||||||
|
}
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_affinity.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_affinity.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type CpuGroupAffinity struct {
|
||||||
|
LogicalProcessorCount int32 `json:"LogicalProcessorCount,omitempty"`
|
||||||
|
LogicalProcessors []int32 `json:"LogicalProcessors,omitempty"`
|
||||||
|
}
|
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_config.go
generated
vendored
Normal file
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_config.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type CpuGroupConfig struct {
|
||||||
|
GroupId string `json:"GroupId,omitempty"`
|
||||||
|
Affinity *CpuGroupAffinity `json:"Affinity,omitempty"`
|
||||||
|
GroupProperties []CpuGroupProperty `json:"GroupProperties,omitempty"`
|
||||||
|
// Hypervisor CPU group IDs exposed to clients
|
||||||
|
HypervisorGroupId int32 `json:"HypervisorGroupId,omitempty"`
|
||||||
|
}
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_configurations.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_configurations.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// Structure used to return cpu groups for a Service property query
|
||||||
|
type CpuGroupConfigurations struct {
|
||||||
|
CpuGroups []CpuGroupConfig `json:"CpuGroups,omitempty"`
|
||||||
|
}
|
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_operations.go
generated
vendored
Normal file
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_operations.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type CPUGroupOperation string
|
||||||
|
|
||||||
|
const (
|
||||||
|
CreateGroup CPUGroupOperation = "CreateGroup"
|
||||||
|
DeleteGroup CPUGroupOperation = "DeleteGroup"
|
||||||
|
SetProperty CPUGroupOperation = "SetProperty"
|
||||||
|
)
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_property.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/cpu_group_property.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type CpuGroupProperty struct {
|
||||||
|
PropertyCode uint32 `json:"PropertyCode,omitempty"`
|
||||||
|
PropertyValue uint32 `json:"PropertyValue,omitempty"`
|
||||||
|
}
|
17
vendor/github.com/Microsoft/hcsshim/internal/schema2/create_group_operation.go
generated
vendored
Normal file
17
vendor/github.com/Microsoft/hcsshim/internal/schema2/create_group_operation.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// Create group operation settings
|
||||||
|
type CreateGroupOperation struct {
|
||||||
|
GroupId string `json:"GroupId,omitempty"`
|
||||||
|
LogicalProcessorCount uint32 `json:"LogicalProcessorCount,omitempty"`
|
||||||
|
LogicalProcessors []uint32 `json:"LogicalProcessors,omitempty"`
|
||||||
|
}
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/delete_group_operation.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/delete_group_operation.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// Delete group operation settings
|
||||||
|
type DeleteGroupOperation struct {
|
||||||
|
GroupId string `json:"GroupId,omitempty"`
|
||||||
|
}
|
|
@ -9,8 +9,19 @@
|
||||||
|
|
||||||
package hcsschema
|
package hcsschema
|
||||||
|
|
||||||
type Device struct {
|
type DeviceType string
|
||||||
|
|
||||||
// The interface class guid of the device to assign to container.
|
const (
|
||||||
|
ClassGUID DeviceType = "ClassGuid"
|
||||||
|
DeviceInstance DeviceType = "DeviceInstance"
|
||||||
|
GPUMirror DeviceType = "GpuMirror"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Device struct {
|
||||||
|
// The type of device to assign to the container.
|
||||||
|
Type DeviceType `json:"Type,omitempty"`
|
||||||
|
// The interface class guid of the device interfaces to assign to the container. Only used when Type is ClassGuid.
|
||||||
InterfaceClassGuid string `json:"InterfaceClassGuid,omitempty"`
|
InterfaceClassGuid string `json:"InterfaceClassGuid,omitempty"`
|
||||||
|
// The location path of the device to assign to the container. Only used when Type is DeviceInstance.
|
||||||
|
LocationPath string `json:"LocationPath,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
16
vendor/github.com/Microsoft/hcsshim/internal/schema2/host_processor_modify_request.go
generated
vendored
Normal file
16
vendor/github.com/Microsoft/hcsshim/internal/schema2/host_processor_modify_request.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// Structure used to request a service processor modification
|
||||||
|
type HostProcessorModificationRequest struct {
|
||||||
|
Operation CPUGroupOperation `json:"Operation,omitempty"`
|
||||||
|
OperationDetails interface{} `json:"OperationDetails,omitempty"`
|
||||||
|
}
|
17
vendor/github.com/Microsoft/hcsshim/internal/schema2/hv_socket_address.go
generated
vendored
Normal file
17
vendor/github.com/Microsoft/hcsshim/internal/schema2/hv_socket_address.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// This class defines address settings applied to a VM
|
||||||
|
// by the GCS every time a VM starts or restores.
|
||||||
|
type HvSocketAddress struct {
|
||||||
|
LocalAddress string `json:"LocalAddress,omitempty"`
|
||||||
|
ParentAddress string `json:"ParentAddress,omitempty"`
|
||||||
|
}
|
6
vendor/github.com/Microsoft/hcsshim/internal/schema2/hv_socket_service_config.go
generated
vendored
6
vendor/github.com/Microsoft/hcsshim/internal/schema2/hv_socket_service_config.go
generated
vendored
|
@ -19,4 +19,10 @@ type HvSocketServiceConfig struct {
|
||||||
|
|
||||||
// If true, HvSocket will process wildcard binds for this service/system combination. Wildcard binds are secured in the registry at SOFTWARE/Microsoft/Windows NT/CurrentVersion/Virtualization/HvSocket/WildcardDescriptors
|
// If true, HvSocket will process wildcard binds for this service/system combination. Wildcard binds are secured in the registry at SOFTWARE/Microsoft/Windows NT/CurrentVersion/Virtualization/HvSocket/WildcardDescriptors
|
||||||
AllowWildcardBinds bool `json:"AllowWildcardBinds,omitempty"`
|
AllowWildcardBinds bool `json:"AllowWildcardBinds,omitempty"`
|
||||||
|
|
||||||
|
// Disabled controls whether the HvSocket service is accepting connection requests.
|
||||||
|
// This set to true will make the service refuse all incoming connections as well as cancel
|
||||||
|
// any connections already established. The service itself will still be active however
|
||||||
|
// and can be re-enabled at a future time.
|
||||||
|
Disabled bool `json:"Disabled,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
42
vendor/github.com/Microsoft/hcsshim/internal/schema2/interrupt_moderation_mode.go
generated
vendored
Normal file
42
vendor/github.com/Microsoft/hcsshim/internal/schema2/interrupt_moderation_mode.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type InterruptModerationName string
|
||||||
|
|
||||||
|
// The valid interrupt moderation modes for I/O virtualization (IOV) offloading.
|
||||||
|
const (
|
||||||
|
DefaultName InterruptModerationName = "Default"
|
||||||
|
AdaptiveName InterruptModerationName = "Adaptive"
|
||||||
|
OffName InterruptModerationName = "Off"
|
||||||
|
LowName InterruptModerationName = "Low"
|
||||||
|
MediumName InterruptModerationName = "Medium"
|
||||||
|
HighName InterruptModerationName = "High"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InterruptModerationValue uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultValue InterruptModerationValue = iota
|
||||||
|
AdaptiveValue
|
||||||
|
OffValue
|
||||||
|
LowValue InterruptModerationValue = 100
|
||||||
|
MediumValue InterruptModerationValue = 200
|
||||||
|
HighValue InterruptModerationValue = 300
|
||||||
|
)
|
||||||
|
|
||||||
|
var InterruptModerationValueToName = map[InterruptModerationValue]InterruptModerationName{
|
||||||
|
DefaultValue: DefaultName,
|
||||||
|
AdaptiveValue: AdaptiveName,
|
||||||
|
OffValue: OffName,
|
||||||
|
LowValue: LowName,
|
||||||
|
MediumValue: MediumName,
|
||||||
|
HighValue: HighName,
|
||||||
|
}
|
22
vendor/github.com/Microsoft/hcsshim/internal/schema2/iov_settings.go
generated
vendored
Normal file
22
vendor/github.com/Microsoft/hcsshim/internal/schema2/iov_settings.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type IovSettings struct {
|
||||||
|
// The weight assigned to this port for I/O virtualization (IOV) offloading.
|
||||||
|
// Setting this to 0 disables IOV offloading.
|
||||||
|
OffloadWeight *uint32 `json:"OffloadWeight,omitempty"`
|
||||||
|
|
||||||
|
// The number of queue pairs requested for this port for I/O virtualization (IOV) offloading.
|
||||||
|
QueuePairsRequested *uint32 `json:"QueuePairsRequested,omitempty"`
|
||||||
|
|
||||||
|
// The interrupt moderation mode for I/O virtualization (IOV) offloading.
|
||||||
|
InterruptModeration *InterruptModerationName `json:"InterruptModeration,omitempty"`
|
||||||
|
}
|
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/logical_processor.go
generated
vendored
Normal file
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/logical_processor.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type LogicalProcessor struct {
|
||||||
|
LpIndex uint32 `json:"LpIndex,omitempty"`
|
||||||
|
NodeNumber uint8 `json:"NodeNumber,omitempty"`
|
||||||
|
PackageId uint32 `json:"PackageId,omitempty"`
|
||||||
|
CoreId uint32 `json:"CoreId,omitempty"`
|
||||||
|
RootVpIndex int32 `json:"RootVpIndex,omitempty"`
|
||||||
|
}
|
|
@ -10,5 +10,5 @@
|
||||||
package hcsschema
|
package hcsschema
|
||||||
|
|
||||||
type Memory struct {
|
type Memory struct {
|
||||||
SizeInMB int32 `json:"SizeInMB,omitempty"`
|
SizeInMB uint64 `json:"SizeInMB,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
package hcsschema
|
package hcsschema
|
||||||
|
|
||||||
type Memory2 struct {
|
type Memory2 struct {
|
||||||
SizeInMB int32 `json:"SizeInMB,omitempty"`
|
SizeInMB uint64 `json:"SizeInMB,omitempty"`
|
||||||
|
|
||||||
AllowOvercommit bool `json:"AllowOvercommit,omitempty"`
|
AllowOvercommit bool `json:"AllowOvercommit,omitempty"`
|
||||||
|
|
||||||
|
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/modification_request.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/modification_request.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ModificationRequest struct {
|
||||||
|
PropertyType PropertyType `json:"PropertyType,omitempty"`
|
||||||
|
Settings interface{} `json:"Settings,omitempty"`
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ package hcsschema
|
||||||
|
|
||||||
type NetworkAdapter struct {
|
type NetworkAdapter struct {
|
||||||
EndpointId string `json:"EndpointId,omitempty"`
|
EndpointId string `json:"EndpointId,omitempty"`
|
||||||
|
|
||||||
MacAddress string `json:"MacAddress,omitempty"`
|
MacAddress string `json:"MacAddress,omitempty"`
|
||||||
|
// The I/O virtualization (IOV) offloading configuration.
|
||||||
|
IovSettings *IovSettings `json:"IovSettings,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/processor_topology.go
generated
vendored
Normal file
15
vendor/github.com/Microsoft/hcsshim/internal/schema2/processor_topology.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
type ProcessorTopology struct {
|
||||||
|
LogicalProcessorCount uint32 `json:"LogicalProcessorCount,omitempty"`
|
||||||
|
LogicalProcessors []LogicalProcessor `json:"LogicalProcessors,omitempty"`
|
||||||
|
}
|
|
@ -18,6 +18,9 @@ const (
|
||||||
PTProcessList PropertyType = "ProcessList"
|
PTProcessList PropertyType = "ProcessList"
|
||||||
PTTerminateOnLastHandleClosed PropertyType = "TerminateOnLastHandleClosed"
|
PTTerminateOnLastHandleClosed PropertyType = "TerminateOnLastHandleClosed"
|
||||||
PTSharedMemoryRegion PropertyType = "SharedMemoryRegion"
|
PTSharedMemoryRegion PropertyType = "SharedMemoryRegion"
|
||||||
|
PTContainerCredentialGuard PropertyType = "ContainerCredentialGuard" // This field is not generated by swagger. This was added manually.
|
||||||
PTGuestConnection PropertyType = "GuestConnection"
|
PTGuestConnection PropertyType = "GuestConnection"
|
||||||
PTICHeartbeatStatus PropertyType = "ICHeartbeatStatus"
|
PTICHeartbeatStatus PropertyType = "ICHeartbeatStatus"
|
||||||
|
PTProcessorTopology PropertyType = "ProcessorTopology"
|
||||||
|
PTCPUGroup PropertyType = "CpuGroup"
|
||||||
)
|
)
|
||||||
|
|
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/service_properties.go
generated
vendored
Normal file
18
vendor/github.com/Microsoft/hcsshim/internal/schema2/service_properties.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type ServiceProperties struct {
|
||||||
|
// Changed Properties field to []json.RawMessage from []interface{} to avoid having to
|
||||||
|
// remarshal sp.Properties[n] and unmarshal into the type(s) we want.
|
||||||
|
Properties []json.RawMessage `json:"Properties,omitempty"`
|
||||||
|
}
|
22
vendor/github.com/Microsoft/hcsshim/internal/schema2/vm_processor_limits.go
generated
vendored
Normal file
22
vendor/github.com/Microsoft/hcsshim/internal/schema2/vm_processor_limits.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* HCS API
|
||||||
|
*
|
||||||
|
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
|
||||||
|
*
|
||||||
|
* API version: 2.4
|
||||||
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package hcsschema
|
||||||
|
|
||||||
|
// ProcessorLimits is used when modifying processor scheduling limits of a virtual machine.
|
||||||
|
type ProcessorLimits struct {
|
||||||
|
// Maximum amount of host CPU resources that the virtual machine can use.
|
||||||
|
Limit uint64 `json:"Limit,omitempty"`
|
||||||
|
// Value describing the relative priority of this virtual machine compared to other virtual machines.
|
||||||
|
Weight uint64 `json:"Weight,omitempty"`
|
||||||
|
// Minimum amount of host CPU resources that the virtual machine is guaranteed.
|
||||||
|
Reservation uint64 `json:"Reservation,omitempty"`
|
||||||
|
// Provides the target maximum CPU frequency, in MHz, for a virtual machine.
|
||||||
|
MaximumFrequencyMHz uint32 `json:"MaximumFrequencyMHz,omitempty"`
|
||||||
|
}
|
|
@ -29,6 +29,9 @@ var (
|
||||||
// SystemResume is the timeout for resuming a compute system
|
// SystemResume is the timeout for resuming a compute system
|
||||||
SystemResume time.Duration = defaultTimeout
|
SystemResume time.Duration = defaultTimeout
|
||||||
|
|
||||||
|
// SystemSave is the timeout for saving a compute system
|
||||||
|
SystemSave time.Duration = defaultTimeout
|
||||||
|
|
||||||
// SyscallWatcher is the timeout before warning of a potential stuck platform syscall.
|
// SyscallWatcher is the timeout before warning of a potential stuck platform syscall.
|
||||||
SyscallWatcher time.Duration = defaultTimeout
|
SyscallWatcher time.Duration = defaultTimeout
|
||||||
|
|
||||||
|
@ -51,6 +54,7 @@ func init() {
|
||||||
SystemStart = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSTART", SystemStart)
|
SystemStart = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSTART", SystemStart)
|
||||||
SystemPause = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMPAUSE", SystemPause)
|
SystemPause = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMPAUSE", SystemPause)
|
||||||
SystemResume = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMRESUME", SystemResume)
|
SystemResume = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMRESUME", SystemResume)
|
||||||
|
SystemSave = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSAVE", SystemSave)
|
||||||
SyscallWatcher = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSCALLWATCHER", SyscallWatcher)
|
SyscallWatcher = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSCALLWATCHER", SyscallWatcher)
|
||||||
Tar2VHD = durationFromEnvironment("HCSSHIM_TIMEOUT_TAR2VHD", Tar2VHD)
|
Tar2VHD = durationFromEnvironment("HCSSHIM_TIMEOUT_TAR2VHD", Tar2VHD)
|
||||||
ExternalCommandToStart = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDSTART", ExternalCommandToStart)
|
ExternalCommandToStart = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDSTART", ExternalCommandToStart)
|
||||||
|
|
|
@ -26,8 +26,10 @@ import (
|
||||||
//sys hcsResumeComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsResumeComputeSystem?
|
//sys hcsResumeComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsResumeComputeSystem?
|
||||||
//sys hcsGetComputeSystemProperties(computeSystem HcsSystem, propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetComputeSystemProperties?
|
//sys hcsGetComputeSystemProperties(computeSystem HcsSystem, propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetComputeSystemProperties?
|
||||||
//sys hcsModifyComputeSystem(computeSystem HcsSystem, configuration string, result **uint16) (hr error) = vmcompute.HcsModifyComputeSystem?
|
//sys hcsModifyComputeSystem(computeSystem HcsSystem, configuration string, result **uint16) (hr error) = vmcompute.HcsModifyComputeSystem?
|
||||||
|
//sys hcsModifyServiceSettings(settings string, result **uint16) (hr error) = vmcompute.HcsModifyServiceSettings?
|
||||||
//sys hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
|
//sys hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
|
||||||
//sys hcsUnregisterComputeSystemCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
|
//sys hcsUnregisterComputeSystemCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
|
||||||
|
//sys hcsSaveComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsSaveComputeSystem?
|
||||||
|
|
||||||
//sys hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsCreateProcess?
|
//sys hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsCreateProcess?
|
||||||
//sys hcsOpenProcess(computeSystem HcsSystem, pid uint32, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsOpenProcess?
|
//sys hcsOpenProcess(computeSystem HcsSystem, pid uint32, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsOpenProcess?
|
||||||
|
@ -60,7 +62,7 @@ type HcsCallback syscall.Handle
|
||||||
type HcsProcessInformation struct {
|
type HcsProcessInformation struct {
|
||||||
// ProcessId is the pid of the created process.
|
// ProcessId is the pid of the created process.
|
||||||
ProcessId uint32
|
ProcessId uint32
|
||||||
reserved uint32
|
reserved uint32 //nolint:structcheck
|
||||||
// StdInput is the handle associated with the stdin of the process.
|
// StdInput is the handle associated with the stdin of the process.
|
||||||
StdInput syscall.Handle
|
StdInput syscall.Handle
|
||||||
// StdOutput is the handle associated with the stdout of the process.
|
// StdOutput is the handle associated with the stdout of the process.
|
||||||
|
@ -337,6 +339,27 @@ func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, confi
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result string, hr error) {
|
||||||
|
ctx, span := trace.StartSpan(ctx, "HcsModifyServiceSettings")
|
||||||
|
defer span.End()
|
||||||
|
defer func() {
|
||||||
|
if result != "" {
|
||||||
|
span.AddAttributes(trace.StringAttribute("result", result))
|
||||||
|
}
|
||||||
|
oc.SetSpanStatus(span, hr)
|
||||||
|
}()
|
||||||
|
span.AddAttributes(trace.StringAttribute("settings", settings))
|
||||||
|
|
||||||
|
return result, execute(ctx, timeout.SyscallWatcher, func() error {
|
||||||
|
var resultp *uint16
|
||||||
|
err := hcsModifyServiceSettings(settings, &resultp)
|
||||||
|
if resultp != nil {
|
||||||
|
result = interop.ConvertAndFreeCoTaskMemString(resultp)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) {
|
func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) {
|
||||||
ctx, span := trace.StartSpan(ctx, "HcsRegisterComputeSystemCallback")
|
ctx, span := trace.StartSpan(ctx, "HcsRegisterComputeSystemCallback")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
@ -563,3 +586,25 @@ func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallba
|
||||||
return hcsUnregisterProcessCallback(callbackHandle)
|
return hcsUnregisterProcessCallback(callbackHandle)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HcsSaveComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
|
||||||
|
ctx, span := trace.StartSpan(ctx, "HcsSaveComputeSystem")
|
||||||
|
defer span.End()
|
||||||
|
defer func() {
|
||||||
|
if result != "" {
|
||||||
|
span.AddAttributes(trace.StringAttribute("result", result))
|
||||||
|
}
|
||||||
|
if hr != errVmcomputeOperationPending {
|
||||||
|
oc.SetSpanStatus(span, hr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return result, execute(ctx, timeout.SyscallWatcher, func() error {
|
||||||
|
var resultp *uint16
|
||||||
|
err := hcsSaveComputeSystem(computeSystem, options, &resultp)
|
||||||
|
if resultp != nil {
|
||||||
|
result = interop.ConvertAndFreeCoTaskMemString(resultp)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -50,8 +50,10 @@ var (
|
||||||
procHcsResumeComputeSystem = modvmcompute.NewProc("HcsResumeComputeSystem")
|
procHcsResumeComputeSystem = modvmcompute.NewProc("HcsResumeComputeSystem")
|
||||||
procHcsGetComputeSystemProperties = modvmcompute.NewProc("HcsGetComputeSystemProperties")
|
procHcsGetComputeSystemProperties = modvmcompute.NewProc("HcsGetComputeSystemProperties")
|
||||||
procHcsModifyComputeSystem = modvmcompute.NewProc("HcsModifyComputeSystem")
|
procHcsModifyComputeSystem = modvmcompute.NewProc("HcsModifyComputeSystem")
|
||||||
|
procHcsModifyServiceSettings = modvmcompute.NewProc("HcsModifyServiceSettings")
|
||||||
procHcsRegisterComputeSystemCallback = modvmcompute.NewProc("HcsRegisterComputeSystemCallback")
|
procHcsRegisterComputeSystemCallback = modvmcompute.NewProc("HcsRegisterComputeSystemCallback")
|
||||||
procHcsUnregisterComputeSystemCallback = modvmcompute.NewProc("HcsUnregisterComputeSystemCallback")
|
procHcsUnregisterComputeSystemCallback = modvmcompute.NewProc("HcsUnregisterComputeSystemCallback")
|
||||||
|
procHcsSaveComputeSystem = modvmcompute.NewProc("HcsSaveComputeSystem")
|
||||||
procHcsCreateProcess = modvmcompute.NewProc("HcsCreateProcess")
|
procHcsCreateProcess = modvmcompute.NewProc("HcsCreateProcess")
|
||||||
procHcsOpenProcess = modvmcompute.NewProc("HcsOpenProcess")
|
procHcsOpenProcess = modvmcompute.NewProc("HcsOpenProcess")
|
||||||
procHcsCloseProcess = modvmcompute.NewProc("HcsCloseProcess")
|
procHcsCloseProcess = modvmcompute.NewProc("HcsCloseProcess")
|
||||||
|
@ -314,6 +316,29 @@ func _hcsModifyComputeSystem(computeSystem HcsSystem, configuration *uint16, res
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hcsModifyServiceSettings(settings string, result **uint16) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsModifyServiceSettings(_p0, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsModifyServiceSettings(settings *uint16, result **uint16) (hr error) {
|
||||||
|
if hr = procHcsModifyServiceSettings.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsModifyServiceSettings.Addr(), 2, uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)), 0)
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) {
|
func hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) {
|
||||||
if hr = procHcsRegisterComputeSystemCallback.Find(); hr != nil {
|
if hr = procHcsRegisterComputeSystemCallback.Find(); hr != nil {
|
||||||
return
|
return
|
||||||
|
@ -342,6 +367,29 @@ func hcsUnregisterComputeSystemCallback(callbackHandle HcsCallback) (hr error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hcsSaveComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) {
|
||||||
|
var _p0 *uint16
|
||||||
|
_p0, hr = syscall.UTF16PtrFromString(options)
|
||||||
|
if hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return _hcsSaveComputeSystem(computeSystem, _p0, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _hcsSaveComputeSystem(computeSystem HcsSystem, options *uint16, result **uint16) (hr error) {
|
||||||
|
if hr = procHcsSaveComputeSystem.Find(); hr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r0, _, _ := syscall.Syscall(procHcsSaveComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
|
||||||
|
if int32(r0) < 0 {
|
||||||
|
if r0&0x1fff0000 == 0x00070000 {
|
||||||
|
r0 &= 0xffff
|
||||||
|
}
|
||||||
|
hr = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) {
|
func hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) {
|
||||||
var _p0 *uint16
|
var _p0 *uint16
|
||||||
_p0, hr = syscall.UTF16PtrFromString(processParameters)
|
_p0, hr = syscall.UTF16PtrFromString(processParameters)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// An activated layer must later be deactivated via DeactivateLayer.
|
// An activated layer must later be deactivated via DeactivateLayer.
|
||||||
func ActivateLayer(ctx context.Context, path string) (err error) {
|
func ActivateLayer(ctx context.Context, path string) (err error) {
|
||||||
title := "hcsshim::ActivateLayer"
|
title := "hcsshim::ActivateLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/Microsoft/hcsshim/internal/hcserror"
|
"github.com/Microsoft/hcsshim/internal/hcserror"
|
||||||
"github.com/Microsoft/hcsshim/internal/oc"
|
"github.com/Microsoft/hcsshim/internal/oc"
|
||||||
"github.com/Microsoft/hcsshim/internal/safefile"
|
"github.com/Microsoft/hcsshim/internal/safefile"
|
||||||
|
"github.com/Microsoft/hcsshim/internal/winapi"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ type dirInfo struct {
|
||||||
func reapplyDirectoryTimes(root *os.File, dis []dirInfo) error {
|
func reapplyDirectoryTimes(root *os.File, dis []dirInfo) error {
|
||||||
for i := range dis {
|
for i := range dis {
|
||||||
di := &dis[len(dis)-i-1] // reverse order: process child directories first
|
di := &dis[len(dis)-i-1] // reverse order: process child directories first
|
||||||
f, err := safefile.OpenRelative(di.path, root, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, safefile.FILE_OPEN, safefile.FILE_DIRECTORY_FILE)
|
f, err := safefile.OpenRelative(di.path, root, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, winapi.FILE_OPEN, winapi.FILE_DIRECTORY_FILE|syscall.FILE_FLAG_OPEN_REPARSE_POINT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -47,6 +48,7 @@ func reapplyDirectoryTimes(root *os.File, dis []dirInfo) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -92,14 +94,12 @@ func (w *baseLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) (err e
|
||||||
|
|
||||||
extraFlags := uint32(0)
|
extraFlags := uint32(0)
|
||||||
if fileInfo.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
|
if fileInfo.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
|
||||||
extraFlags |= safefile.FILE_DIRECTORY_FILE
|
extraFlags |= winapi.FILE_DIRECTORY_FILE
|
||||||
if fileInfo.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT == 0 {
|
w.dirInfo = append(w.dirInfo, dirInfo{name, *fileInfo})
|
||||||
w.dirInfo = append(w.dirInfo, dirInfo{name, *fileInfo})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mode := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE | winio.WRITE_DAC | winio.WRITE_OWNER | winio.ACCESS_SYSTEM_SECURITY)
|
mode := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE | winio.WRITE_DAC | winio.WRITE_OWNER | winio.ACCESS_SYSTEM_SECURITY)
|
||||||
f, err = safefile.OpenRelative(name, w.root, mode, syscall.FILE_SHARE_READ, safefile.FILE_CREATE, extraFlags)
|
f, err = safefile.OpenRelative(name, w.root, mode, syscall.FILE_SHARE_READ, winapi.FILE_CREATE, extraFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return hcserror.New(err, "Failed to safefile.OpenRelative", name)
|
return hcserror.New(err, "Failed to safefile.OpenRelative", name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// the parent layer provided.
|
// the parent layer provided.
|
||||||
func CreateLayer(ctx context.Context, path, parent string) (err error) {
|
func CreateLayer(ctx context.Context, path, parent string) (err error) {
|
||||||
title := "hcsshim::CreateLayer"
|
title := "hcsshim::CreateLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(
|
span.AddAttributes(
|
||||||
|
|
|
@ -10,9 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateScratchLayer creates and populates new read-write layer for use by a container.
|
// CreateScratchLayer creates and populates new read-write layer for use by a container.
|
||||||
// This requires both the id of the direct parent layer, as well as the full list
|
// This requires the full list of paths to all parent layers up to the base
|
||||||
// of paths to all parent layers up to the base (and including the direct parent
|
|
||||||
// whose id was provided).
|
|
||||||
func CreateScratchLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) {
|
func CreateScratchLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) {
|
||||||
title := "hcsshim::CreateScratchLayer"
|
title := "hcsshim::CreateScratchLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// DeactivateLayer will dismount a layer that was mounted via ActivateLayer.
|
// DeactivateLayer will dismount a layer that was mounted via ActivateLayer.
|
||||||
func DeactivateLayer(ctx context.Context, path string) (err error) {
|
func DeactivateLayer(ctx context.Context, path string) (err error) {
|
||||||
title := "hcsshim::DeactivateLayer"
|
title := "hcsshim::DeactivateLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// path, including that layer's containing folder, if any.
|
// path, including that layer's containing folder, if any.
|
||||||
func DestroyLayer(ctx context.Context, path string) (err error) {
|
func DestroyLayer(ctx context.Context, path string) (err error) {
|
||||||
title := "hcsshim::DestroyLayer"
|
title := "hcsshim::DestroyLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
|
@ -21,8 +21,7 @@ func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) {
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
||||||
var mountPathLength uintptr
|
var mountPathLength uintptr = 0
|
||||||
mountPathLength = 0
|
|
||||||
|
|
||||||
// Call the procedure itself.
|
// Call the procedure itself.
|
||||||
log.G(ctx).Debug("Calling proc (1)")
|
log.G(ctx).Debug("Calling proc (1)")
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// of registering them with the graphdriver, graph, and tagstore.
|
// of registering them with the graphdriver, graph, and tagstore.
|
||||||
func GetSharedBaseImages(ctx context.Context) (_ string, err error) {
|
func GetSharedBaseImages(ctx context.Context) (_ string, err error) {
|
||||||
title := "hcsshim::GetSharedBaseImages"
|
title := "hcsshim::GetSharedBaseImages"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// GrantVmAccess adds access to a file for a given VM
|
// GrantVmAccess adds access to a file for a given VM
|
||||||
func GrantVmAccess(ctx context.Context, vmid string, filepath string) (err error) {
|
func GrantVmAccess(ctx context.Context, vmid string, filepath string) (err error) {
|
||||||
title := "hcsshim::GrantVmAccess"
|
title := "hcsshim::GrantVmAccess"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(
|
span.AddAttributes(
|
||||||
|
|
|
@ -93,6 +93,19 @@ func (r *legacyLayerWriterWrapper) Close() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The reapplyDirectoryTimes must be called AFTER we are done with Tombstone
|
||||||
|
// deletion and hard link creation. This is because Tombstone deletion and hard link
|
||||||
|
// creation updates the directory last write timestamps so that will change the
|
||||||
|
// timestamps added by the `Add` call. Some container applications depend on the
|
||||||
|
// correctness of these timestamps and so we should change the timestamps back to
|
||||||
|
// the original value (i.e the value provided in the Add call) after this
|
||||||
|
// processing is done.
|
||||||
|
err = reapplyDirectoryTimes(r.destRoot, r.changedDi)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare the utility VM for use if one is present in the layer.
|
// Prepare the utility VM for use if one is present in the layer.
|
||||||
if r.HasUtilityVM {
|
if r.HasUtilityVM {
|
||||||
err := safefile.EnsureNotReparsePointRelative("UtilityVM", r.destRoot)
|
err := safefile.EnsureNotReparsePointRelative("UtilityVM", r.destRoot)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// to the system.
|
// to the system.
|
||||||
func LayerExists(ctx context.Context, path string) (_ bool, err error) {
|
func LayerExists(ctx context.Context, path string) (_ bool, err error) {
|
||||||
title := "hcsshim::LayerExists"
|
title := "hcsshim::LayerExists"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/Microsoft/go-winio"
|
"github.com/Microsoft/go-winio"
|
||||||
"github.com/Microsoft/hcsshim/internal/longpath"
|
"github.com/Microsoft/hcsshim/internal/longpath"
|
||||||
"github.com/Microsoft/hcsshim/internal/safefile"
|
"github.com/Microsoft/hcsshim/internal/safefile"
|
||||||
|
"github.com/Microsoft/hcsshim/internal/winapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errorIterationCanceled = errors.New("")
|
var errorIterationCanceled = errors.New("")
|
||||||
|
@ -341,7 +342,7 @@ type legacyLayerWriter struct {
|
||||||
backupWriter *winio.BackupFileWriter
|
backupWriter *winio.BackupFileWriter
|
||||||
Tombstones []string
|
Tombstones []string
|
||||||
HasUtilityVM bool
|
HasUtilityVM bool
|
||||||
uvmDi []dirInfo
|
changedDi []dirInfo
|
||||||
addedFiles map[string]bool
|
addedFiles map[string]bool
|
||||||
PendingLinks []pendingLink
|
PendingLinks []pendingLink
|
||||||
pendingDirs []pendingDir
|
pendingDirs []pendingDir
|
||||||
|
@ -389,7 +390,7 @@ func (w *legacyLayerWriter) CloseRoots() {
|
||||||
w.destRoot = nil
|
w.destRoot = nil
|
||||||
}
|
}
|
||||||
for i := range w.parentRoots {
|
for i := range w.parentRoots {
|
||||||
w.parentRoots[i].Close()
|
_ = w.parentRoots[i].Close()
|
||||||
}
|
}
|
||||||
w.parentRoots = nil
|
w.parentRoots = nil
|
||||||
}
|
}
|
||||||
|
@ -472,8 +473,8 @@ func copyFileWithMetadata(srcRoot, destRoot *os.File, subPath string, isDir bool
|
||||||
srcRoot,
|
srcRoot,
|
||||||
syscall.GENERIC_READ|winio.ACCESS_SYSTEM_SECURITY,
|
syscall.GENERIC_READ|winio.ACCESS_SYSTEM_SECURITY,
|
||||||
syscall.FILE_SHARE_READ,
|
syscall.FILE_SHARE_READ,
|
||||||
safefile.FILE_OPEN,
|
winapi.FILE_OPEN,
|
||||||
safefile.FILE_OPEN_REPARSE_POINT)
|
winapi.FILE_OPEN_REPARSE_POINT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -488,14 +489,14 @@ func copyFileWithMetadata(srcRoot, destRoot *os.File, subPath string, isDir bool
|
||||||
|
|
||||||
extraFlags := uint32(0)
|
extraFlags := uint32(0)
|
||||||
if isDir {
|
if isDir {
|
||||||
extraFlags |= safefile.FILE_DIRECTORY_FILE
|
extraFlags |= winapi.FILE_DIRECTORY_FILE
|
||||||
}
|
}
|
||||||
dest, err := safefile.OpenRelative(
|
dest, err := safefile.OpenRelative(
|
||||||
subPath,
|
subPath,
|
||||||
destRoot,
|
destRoot,
|
||||||
syscall.GENERIC_READ|syscall.GENERIC_WRITE|winio.WRITE_DAC|winio.WRITE_OWNER|winio.ACCESS_SYSTEM_SECURITY,
|
syscall.GENERIC_READ|syscall.GENERIC_WRITE|winio.WRITE_DAC|winio.WRITE_OWNER|winio.ACCESS_SYSTEM_SECURITY,
|
||||||
syscall.FILE_SHARE_READ,
|
syscall.FILE_SHARE_READ,
|
||||||
safefile.FILE_CREATE,
|
winapi.FILE_CREATE,
|
||||||
extraFlags)
|
extraFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -555,7 +556,7 @@ func cloneTree(srcRoot *os.File, destRoot *os.File, subPath string, mutatedFiles
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if isDir && !isReparsePoint {
|
if isDir {
|
||||||
di = append(di, dirInfo{path: relPath, fileInfo: *fi})
|
di = append(di, dirInfo{path: relPath, fileInfo: *fi})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -583,6 +584,10 @@ func (w *legacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) erro
|
||||||
return w.initUtilityVM()
|
return w.initUtilityVM()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileInfo.FileAttributes & syscall.FILE_ATTRIBUTE_DIRECTORY) != 0 {
|
||||||
|
w.changedDi = append(w.changedDi, dirInfo{path: name, fileInfo: *fileInfo})
|
||||||
|
}
|
||||||
|
|
||||||
name = filepath.Clean(name)
|
name = filepath.Clean(name)
|
||||||
if hasPathPrefix(name, utilityVMPath) {
|
if hasPathPrefix(name, utilityVMPath) {
|
||||||
if !w.HasUtilityVM {
|
if !w.HasUtilityVM {
|
||||||
|
@ -591,7 +596,7 @@ func (w *legacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) erro
|
||||||
if !hasPathPrefix(name, utilityVMFilesPath) && name != utilityVMFilesPath {
|
if !hasPathPrefix(name, utilityVMFilesPath) && name != utilityVMFilesPath {
|
||||||
return errors.New("invalid UtilityVM layer")
|
return errors.New("invalid UtilityVM layer")
|
||||||
}
|
}
|
||||||
createDisposition := uint32(safefile.FILE_OPEN)
|
createDisposition := uint32(winapi.FILE_OPEN)
|
||||||
if (fileInfo.FileAttributes & syscall.FILE_ATTRIBUTE_DIRECTORY) != 0 {
|
if (fileInfo.FileAttributes & syscall.FILE_ATTRIBUTE_DIRECTORY) != 0 {
|
||||||
st, err := safefile.LstatRelative(name, w.destRoot)
|
st, err := safefile.LstatRelative(name, w.destRoot)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
@ -612,16 +617,13 @@ func (w *legacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileInfo.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT == 0 {
|
|
||||||
w.uvmDi = append(w.uvmDi, dirInfo{path: name, fileInfo: *fileInfo})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Overwrite any existing hard link.
|
// Overwrite any existing hard link.
|
||||||
err := safefile.RemoveRelative(name, w.destRoot)
|
err := safefile.RemoveRelative(name, w.destRoot)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
createDisposition = safefile.FILE_CREATE
|
createDisposition = winapi.FILE_CREATE
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := safefile.OpenRelative(
|
f, err := safefile.OpenRelative(
|
||||||
|
@ -630,7 +632,7 @@ func (w *legacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) erro
|
||||||
syscall.GENERIC_READ|syscall.GENERIC_WRITE|winio.WRITE_DAC|winio.WRITE_OWNER|winio.ACCESS_SYSTEM_SECURITY,
|
syscall.GENERIC_READ|syscall.GENERIC_WRITE|winio.WRITE_DAC|winio.WRITE_OWNER|winio.ACCESS_SYSTEM_SECURITY,
|
||||||
syscall.FILE_SHARE_READ,
|
syscall.FILE_SHARE_READ,
|
||||||
createDisposition,
|
createDisposition,
|
||||||
safefile.FILE_OPEN_REPARSE_POINT,
|
winapi.FILE_OPEN_REPARSE_POINT,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -638,7 +640,7 @@ func (w *legacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) erro
|
||||||
defer func() {
|
defer func() {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
safefile.RemoveRelative(name, w.destRoot)
|
_ = safefile.RemoveRelative(name, w.destRoot)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -667,14 +669,14 @@ func (w *legacyLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) erro
|
||||||
w.currentIsDir = true
|
w.currentIsDir = true
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := safefile.OpenRelative(fname, w.root, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, safefile.FILE_CREATE, 0)
|
f, err := safefile.OpenRelative(fname, w.root, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, winapi.FILE_CREATE, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
safefile.RemoveRelative(fname, w.root)
|
_ = safefile.RemoveRelative(fname, w.root)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -805,11 +807,5 @@ func (w *legacyLayerWriter) Close() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.HasUtilityVM {
|
|
||||||
err := reapplyDirectoryTimes(w.destRoot, w.uvmDi)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// across all clients.
|
// across all clients.
|
||||||
func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) {
|
func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) {
|
||||||
title := "hcsshim::NameToGuid"
|
title := "hcsshim::NameToGuid"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("name", name))
|
span.AddAttributes(trace.StringAttribute("name", name))
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// The files should have been extracted to <path>\Files.
|
// The files should have been extracted to <path>\Files.
|
||||||
func ProcessBaseLayer(ctx context.Context, path string) (err error) {
|
func ProcessBaseLayer(ctx context.Context, path string) (err error) {
|
||||||
title := "hcsshim::ProcessBaseLayer"
|
title := "hcsshim::ProcessBaseLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
@ -28,7 +28,7 @@ func ProcessBaseLayer(ctx context.Context, path string) (err error) {
|
||||||
// The files should have been extracted to <path>\Files.
|
// The files should have been extracted to <path>\Files.
|
||||||
func ProcessUtilityVMImage(ctx context.Context, path string) (err error) {
|
func ProcessUtilityVMImage(ctx context.Context, path string) (err error) {
|
||||||
title := "hcsshim::ProcessUtilityVMImage"
|
title := "hcsshim::ProcessUtilityVMImage"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// the given id.
|
// the given id.
|
||||||
func UnprepareLayer(ctx context.Context, path string) (err error) {
|
func UnprepareLayer(ctx context.Context, path string) (err error) {
|
||||||
title := "hcsshim::UnprepareLayer"
|
title := "hcsshim::UnprepareLayer"
|
||||||
ctx, span := trace.StartSpan(ctx, title)
|
ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer func() { oc.SetSpanStatus(span, err) }()
|
defer func() { oc.SetSpanStatus(span, err) }()
|
||||||
span.AddAttributes(trace.StringAttribute("path", path))
|
span.AddAttributes(trace.StringAttribute("path", path))
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// Package wclayer provides bindings to HCS's legacy layer management API and
|
||||||
|
// provides a higher level interface around these calls for container layer
|
||||||
|
// management.
|
||||||
package wclayer
|
package wclayer
|
||||||
|
|
||||||
import "github.com/Microsoft/go-winio/pkg/guid"
|
import "github.com/Microsoft/go-winio/pkg/guid"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package winapi
|
||||||
|
|
||||||
|
import "github.com/Microsoft/go-winio/pkg/guid"
|
||||||
|
|
||||||
|
//sys CMGetDeviceIDListSize(pulLen *uint32, pszFilter *byte, uFlags uint32) (hr error) = cfgmgr32.CM_Get_Device_ID_List_SizeA
|
||||||
|
//sys CMGetDeviceIDList(pszFilter *byte, buffer *byte, bufferLen uint32, uFlags uint32) (hr error)= cfgmgr32.CM_Get_Device_ID_ListA
|
||||||
|
//sys CMLocateDevNode(pdnDevInst *uint32, pDeviceID string, uFlags uint32) (hr error) = cfgmgr32.CM_Locate_DevNodeW
|
||||||
|
//sys CMGetDevNodeProperty(dnDevInst uint32, propertyKey *DevPropKey, propertyType *uint32, propertyBuffer *uint16, propertyBufferSize *uint32, uFlags uint32) (hr error) = cfgmgr32.CM_Get_DevNode_PropertyW
|
||||||
|
|
||||||
|
type DevPropKey struct {
|
||||||
|
Fmtid guid.GUID
|
||||||
|
Pid uint32
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package winapi
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
//sys RtlNtStatusToDosError(status uint32) (winerr error) = ntdll.RtlNtStatusToDosError
|
||||||
|
|
||||||
|
const (
|
||||||
|
STATUS_REPARSE_POINT_ENCOUNTERED = 0xC000050B
|
||||||
|
ERROR_NO_MORE_ITEMS = 0x103
|
||||||
|
ERROR_MORE_DATA syscall.Errno = 234
|
||||||
|
)
|
||||||
|
|
||||||
|
func NTSuccess(status uint32) bool {
|
||||||
|
return status == 0
|
||||||
|
}
|
110
vendor/github.com/Microsoft/hcsshim/internal/winapi/filesystem.go
generated
vendored
Normal file
110
vendor/github.com/Microsoft/hcsshim/internal/winapi/filesystem.go
generated
vendored
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
package winapi
|
||||||
|
|
||||||
|
//sys NtCreateFile(handle *uintptr, accessMask uint32, oa *ObjectAttributes, iosb *IOStatusBlock, allocationSize *uint64, fileAttributes uint32, shareAccess uint32, createDisposition uint32, createOptions uint32, eaBuffer *byte, eaLength uint32) (status uint32) = ntdll.NtCreateFile
|
||||||
|
//sys NtSetInformationFile(handle uintptr, iosb *IOStatusBlock, information uintptr, length uint32, class uint32) (status uint32) = ntdll.NtSetInformationFile
|
||||||
|
|
||||||
|
//sys NtOpenDirectoryObject(handle *uintptr, accessMask uint32, oa *ObjectAttributes) (status uint32) = ntdll.NtOpenDirectoryObject
|
||||||
|
//sys NtQueryDirectoryObject(handle uintptr, buffer *byte, length uint32, singleEntry bool, restartScan bool, context *uint32, returnLength *uint32)(status uint32) = ntdll.NtQueryDirectoryObject
|
||||||
|
|
||||||
|
const (
|
||||||
|
FileLinkInformationClass = 11
|
||||||
|
FileDispositionInformationExClass = 64
|
||||||
|
|
||||||
|
FILE_READ_ATTRIBUTES = 0x0080
|
||||||
|
FILE_WRITE_ATTRIBUTES = 0x0100
|
||||||
|
DELETE = 0x10000
|
||||||
|
|
||||||
|
FILE_OPEN = 1
|
||||||
|
FILE_CREATE = 2
|
||||||
|
|
||||||
|
FILE_LIST_DIRECTORY = 0x00000001
|
||||||
|
FILE_DIRECTORY_FILE = 0x00000001
|
||||||
|
FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020
|
||||||
|
FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000
|
||||||
|
FILE_OPEN_REPARSE_POINT = 0x00200000
|
||||||
|
|
||||||
|
FILE_DISPOSITION_DELETE = 0x00000001
|
||||||
|
|
||||||
|
OBJ_DONT_REPARSE = 0x1000
|
||||||
|
|
||||||
|
STATUS_MORE_ENTRIES = 0x105
|
||||||
|
STATUS_NO_MORE_ENTRIES = 0x8000001a
|
||||||
|
)
|
||||||
|
|
||||||
|
// Select entries from FILE_INFO_BY_HANDLE_CLASS.
|
||||||
|
//
|
||||||
|
// C declaration:
|
||||||
|
// typedef enum _FILE_INFO_BY_HANDLE_CLASS {
|
||||||
|
// FileBasicInfo,
|
||||||
|
// FileStandardInfo,
|
||||||
|
// FileNameInfo,
|
||||||
|
// FileRenameInfo,
|
||||||
|
// FileDispositionInfo,
|
||||||
|
// FileAllocationInfo,
|
||||||
|
// FileEndOfFileInfo,
|
||||||
|
// FileStreamInfo,
|
||||||
|
// FileCompressionInfo,
|
||||||
|
// FileAttributeTagInfo,
|
||||||
|
// FileIdBothDirectoryInfo,
|
||||||
|
// FileIdBothDirectoryRestartInfo,
|
||||||
|
// FileIoPriorityHintInfo,
|
||||||
|
// FileRemoteProtocolInfo,
|
||||||
|
// FileFullDirectoryInfo,
|
||||||
|
// FileFullDirectoryRestartInfo,
|
||||||
|
// FileStorageInfo,
|
||||||
|
// FileAlignmentInfo,
|
||||||
|
// FileIdInfo,
|
||||||
|
// FileIdExtdDirectoryInfo,
|
||||||
|
// FileIdExtdDirectoryRestartInfo,
|
||||||
|
// FileDispositionInfoEx,
|
||||||
|
// FileRenameInfoEx,
|
||||||
|
// FileCaseSensitiveInfo,
|
||||||
|
// FileNormalizedNameInfo,
|
||||||
|
// MaximumFileInfoByHandleClass
|
||||||
|
// } FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS;
|
||||||
|
//
|
||||||
|
// Documentation: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ne-minwinbase-file_info_by_handle_class
|
||||||
|
const (
|
||||||
|
FileIdInfo = 18
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileDispositionInformationEx struct {
|
||||||
|
Flags uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type IOStatusBlock struct {
|
||||||
|
Status, Information uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type ObjectAttributes struct {
|
||||||
|
Length uintptr
|
||||||
|
RootDirectory uintptr
|
||||||
|
ObjectName *UnicodeString
|
||||||
|
Attributes uintptr
|
||||||
|
SecurityDescriptor uintptr
|
||||||
|
SecurityQoS uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type ObjectDirectoryInformation struct {
|
||||||
|
Name UnicodeString
|
||||||
|
TypeName UnicodeString
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileLinkInformation struct {
|
||||||
|
ReplaceIfExists bool
|
||||||
|
RootDirectory uintptr
|
||||||
|
FileNameLength uint32
|
||||||
|
FileName [1]uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// C declaration:
|
||||||
|
// typedef struct _FILE_ID_INFO {
|
||||||
|
// ULONGLONG VolumeSerialNumber;
|
||||||
|
// FILE_ID_128 FileId;
|
||||||
|
// } FILE_ID_INFO, *PFILE_ID_INFO;
|
||||||
|
//
|
||||||
|
// Documentation: https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_id_info
|
||||||
|
type FILE_ID_INFO struct {
|
||||||
|
VolumeSerialNumber uint64
|
||||||
|
FileID [16]byte
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package winapi
|
||||||
|
|
||||||
|
//sys GetQueuedCompletionStatus(cphandle windows.Handle, qty *uint32, key *uintptr, overlapped **windows.Overlapped, timeout uint32) (err error)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue