From 4667ee47a580566c18494f7a11dc3532277f4fc3 Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Tue, 6 Aug 2019 13:24:38 -0700 Subject: [PATCH] Update Microsoft/go-winio v0.4.14 Signed-off-by: Justin Terry (VM) --- vendor.conf | 2 +- .../Microsoft/go-winio/pkg/etw/provider.go | 27 +++++----- .../Microsoft/go-winio/pkg/fs/fs_windows.go | 7 ++- .../Microsoft/go-winio/pkg/guid/guid.go | 54 +++++++++++++++++-- .../github.com/Microsoft/go-winio/vhd/vhd.go | 10 ++-- 5 files changed, 79 insertions(+), 21 deletions(-) diff --git a/vendor.conf b/vendor.conf index 9b7c76908..edb2f4ea3 100644 --- a/vendor.conf +++ b/vendor.conf @@ -33,7 +33,7 @@ github.com/opencontainers/image-spec v1.0.1 golang.org/x/sync 42b317875d0fa942474b76e1b46a6060d720ae6e github.com/BurntSushi/toml v0.3.1 github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0 -github.com/Microsoft/go-winio 7cdfd71a950d40d0da2167ccb690b541f7ba98c0 +github.com/Microsoft/go-winio v0.4.14 github.com/Microsoft/hcsshim 8abdbb8205e4192c68b5f84c31197156f31be517 google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944 golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4 diff --git a/vendor/github.com/Microsoft/go-winio/pkg/etw/provider.go b/vendor/github.com/Microsoft/go-winio/pkg/etw/provider.go index 28db0d590..236960182 100644 --- a/vendor/github.com/Microsoft/go-winio/pkg/etw/provider.go +++ b/vendor/github.com/Microsoft/go-winio/pkg/etw/provider.go @@ -94,26 +94,27 @@ func providerCallbackAdapter(sourceID *guid.GUID, state uintptr, level uintptr, // uses the same algorithm as used by .NET's EventSource class, which is based // on RFC 4122. More information on the algorithm can be found here: // https://blogs.msdn.microsoft.com/dcook/2015/09/08/etw-provider-names-and-guids/ -// The algorithm is roughly: -// Hash = Sha1(namespace + arg.ToUpper().ToUtf16be()) -// Guid = Hash[0..15], with Hash[7] tweaked according to RFC 4122 +// +// The algorithm is roughly the RFC 4122 algorithm for a V5 UUID, but differs in +// the following ways: +// - The input name is first upper-cased, UTF16-encoded, and converted to +// big-endian. +// - No variant is set on the result UUID. +// - The result UUID is treated as being in little-endian format, rather than +// big-endian. func providerIDFromName(name string) guid.GUID { buffer := sha1.New() - - namespace := []byte{0x48, 0x2C, 0x2D, 0xB2, 0xC3, 0x90, 0x47, 0xC8, 0x87, 0xF8, 0x1A, 0x15, 0xBF, 0xC1, 0x30, 0xFB} - buffer.Write(namespace) - + namespace := guid.GUID{0x482C2DB2, 0xC390, 0x47C8, [8]byte{0x87, 0xF8, 0x1A, 0x15, 0xBF, 0xC1, 0x30, 0xFB}} + namespaceBytes := namespace.ToArray() + buffer.Write(namespaceBytes[:]) binary.Write(buffer, binary.BigEndian, utf16.Encode([]rune(strings.ToUpper(name)))) sum := buffer.Sum(nil) sum[7] = (sum[7] & 0xf) | 0x50 - return guid.GUID{ - Data1: binary.LittleEndian.Uint32(sum[0:4]), - Data2: binary.LittleEndian.Uint16(sum[4:6]), - Data3: binary.LittleEndian.Uint16(sum[6:8]), - Data4: [8]byte{sum[8], sum[9], sum[10], sum[11], sum[12], sum[13], sum[14], sum[15]}, - } + a := [16]byte{} + copy(a[:], sum) + return guid.FromWindowsArray(a) } // NewProvider creates and registers a new ETW provider. The provider ID is diff --git a/vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go b/vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go index 051cf5881..cf7de6d91 100644 --- a/vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go +++ b/vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go @@ -9,12 +9,17 @@ import ( "golang.org/x/sys/windows" ) +var ( + // ErrInvalidPath is returned when the location of a file path doesn't begin with a driver letter. + ErrInvalidPath = errors.New("the path provided to GetFileSystemType must start with a drive letter") +) + // GetFileSystemType obtains the type of a file system through GetVolumeInformation. // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx func GetFileSystemType(path string) (fsType string, hr error) { drive := filepath.VolumeName(path) if len(drive) != 2 { - return "", errors.New("getFileSystemType path must start with a drive letter") + return "", ErrInvalidPath } var ( diff --git a/vendor/github.com/Microsoft/go-winio/pkg/guid/guid.go b/vendor/github.com/Microsoft/go-winio/pkg/guid/guid.go index d0595f667..586406577 100644 --- a/vendor/github.com/Microsoft/go-winio/pkg/guid/guid.go +++ b/vendor/github.com/Microsoft/go-winio/pkg/guid/guid.go @@ -7,6 +7,7 @@ package guid import ( "crypto/rand" + "crypto/sha1" "encoding" "encoding/binary" "fmt" @@ -52,10 +53,34 @@ func NewV4() (GUID, error) { return GUID{}, err } - b[6] = (b[6] & 0x0f) | 0x40 // Version 4 (randomly generated) - b[8] = (b[8] & 0x3f) | 0x80 // RFC4122 variant + g := FromArray(b) + g.setVersion(4) // Version 4 means randomly generated. + g.setVariant(VariantRFC4122) - return FromArray(b), nil + return g, nil +} + +// NewV5 returns a new version 5 (generated from a string via SHA-1 hashing) +// GUID, as defined by RFC 4122. The RFC is unclear on the encoding of the name, +// and the sample code treats it as a series of bytes, so we do the same here. +// +// Some implementations, such as those found on Windows, treat the name as a +// big-endian UTF16 stream of bytes. If that is desired, the string can be +// encoded as such before being passed to this function. +func NewV5(namespace GUID, name []byte) (GUID, error) { + b := sha1.New() + namespaceBytes := namespace.ToArray() + b.Write(namespaceBytes[:]) + b.Write(name) + + a := [16]byte{} + copy(a[:], b.Sum(nil)) + + g := FromArray(a) + g.setVersion(5) // Version 5 means generated from a string. + g.setVariant(VariantRFC4122) + + return g, nil } func fromArray(b [16]byte, order binary.ByteOrder) GUID { @@ -150,6 +175,25 @@ func FromString(s string) (GUID, error) { return g, nil } +func (g *GUID) setVariant(v Variant) { + d := g.Data4[0] + switch v { + case VariantNCS: + d = (d & 0x7f) + case VariantRFC4122: + d = (d & 0x3f) | 0x80 + case VariantMicrosoft: + d = (d & 0x1f) | 0xc0 + case VariantFuture: + d = (d & 0x0f) | 0xe0 + case VariantUnknown: + fallthrough + default: + panic(fmt.Sprintf("invalid variant: %d", v)) + } + g.Data4[0] = d +} + // Variant returns the GUID variant, as defined in RFC 4122. func (g GUID) Variant() Variant { b := g.Data4[0] @@ -165,6 +209,10 @@ func (g GUID) Variant() Variant { return VariantUnknown } +func (g *GUID) setVersion(v Version) { + g.Data3 = (g.Data3 & 0x0fff) | (uint16(v) << 12) +} + // Version returns the GUID version, as defined in RFC 4122. func (g GUID) Version() Version { return Version((g.Data3 & 0xF000) >> 12) diff --git a/vendor/github.com/Microsoft/go-winio/vhd/vhd.go b/vendor/github.com/Microsoft/go-winio/vhd/vhd.go index 48fb1276d..229ac2556 100644 --- a/vendor/github.com/Microsoft/go-winio/vhd/vhd.go +++ b/vendor/github.com/Microsoft/go-winio/vhd/vhd.go @@ -117,9 +117,13 @@ func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error { return nil } -// DetachVhd detaches a VHD attached at the given path. +// DetachVhd detaches a mounted container layer vhd found at `path`. func DetachVhd(path string) error { - handle, err := OpenVirtualDisk(path, VirtualDiskAccessDetach, OpenVirtualDiskFlagNone) + handle, err := OpenVirtualDisk( + path, + VirtualDiskAccessNone, + OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator) + if err != nil { return err } @@ -127,7 +131,7 @@ func DetachVhd(path string) error { return detachVirtualDisk(handle, 0, 0) } -// OpenVirtuaDisk 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) { var ( defaultType virtualStorageType