Update Microsoft/go-winio v0.4.14
Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
		
							
								
								
									
										27
									
								
								vendor/github.com/Microsoft/go-winio/pkg/etw/provider.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										27
									
								
								vendor/github.com/Microsoft/go-winio/pkg/etw/provider.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -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 (
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								vendor/github.com/Microsoft/go-winio/pkg/guid/guid.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										54
									
								
								vendor/github.com/Microsoft/go-winio/pkg/guid/guid.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -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)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								vendor/github.com/Microsoft/go-winio/vhd/vhd.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								vendor/github.com/Microsoft/go-winio/vhd/vhd.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user