internal

package
v0.0.0-...-4e4ffe9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const AllInititatorPorts uint32 = math.MaxUint32

AllInititatorPorts maps to the `ISCSI_ALL_INITIATOR_PORTS` C++ constant. see the "InitiatorPortNumber" section of https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/nf-iscsidsc-addiscsisendtargetportalw

View Source
const DefaultPortalPortNumber uint16 = 3260

DefaultPortalPortNumber is the default port on which target portals are expected to be listening on if no other port is explicitly provided.

View Source
const LoginOptionsVersion uint32 = 0

LoginOptionsVersion maps to the `ISCSI_LOGIN_OPTIONS_VERSION` C++ constant. see the "Version" section of https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_login_options

View Source
const MaxHbaNameLen = 256

MaxHbaNameLen maps to the `MAX_ISCSI_HBANAME_LEN` C++ constant.

View Source
const MaxIscsiNameLen = 223

MaxIscsiNameLen maps to the `MAX_ISCSI_NAME_LEN` C++ constant.

View Source
const MaxIscsiPortalAddressLen = 256

MaxIscsiPortalAddressLen maps to the `MAX_ISCSI_PORTAL_ADDRESS_LEN` C++ constant.

View Source
const MaxIscsiPortalNameLen = 256

MaxIscsiPortalNameLen maps to the `MAX_ISCSI_PORTAL_NAME_LEN` C++ constant.

View Source
const MaxPath = 260

MaxPath maps to the `MAX_PATH` C++ constant.

Variables

View Source
var (

	// ConnectionInfoSize is the size, in bytes, of the internal `ConnectionInfo` type.
	ConnectionInfoSize = unsafe.Sizeof(emptyConnectionInfo)
)
View Source
var (

	// DeviceSize is the size, in bytes, of the internal `Device` type.
	DeviceSize = unsafe.Sizeof(emptyDevice)
)
View Source
var (

	// InitialAPIBufferSize is the size of the buffer used for the 1st call to APIs that need one.
	// It should big enough to ensure we won't need to make another call with a bigger buffer in most situations.
	// Having it as a var and not a constant allows overriding it during tests.
	// Note that on some versions of Windows, if this is too big, some API calls might result in ERROR_NOACCESS
	// errors (...?)
	InitialAPIBufferSize uintptr = 100000
)
View Source
var (

	// PortalInfoSize is the size, in bytes, of the internal `PortalInfo` type.
	PortalInfoSize = unsafe.Sizeof(emptyPrivatePortalInfo)
)
View Source
var (

	// SessionInfoSize is the size, in bytes, of the internal `SessionInfo` type.
	SessionInfoSize = unsafe.Sizeof(emptySessionInfo)
)

Functions

func BoolToByte

func BoolToByte(b bool) byte

BoolToByte converts a boolean to a C++ byte.

func CallWinAPI

func CallWinAPI(proc *windows.LazyProc, args ...uintptr) (uintptr, error)

CallWinAPI makes a call to Windows' API.

func CheckAndConvertKey

func CheckAndConvertKey(key *string) (keyPtr *byte, keySize uint32, err error)

CheckAndConvertKey converts the user-facing key argument, common to several procs, into internal types compatible with Windows' API.

func ConvertInitiatorArgs

func ConvertInitiatorArgs(initiatorInstance *string, initiatorPortNumber *uint32) (*uint16, uint32, error)

ConvertInitiatorArgs converts user-facing initiator arguments to internal types compatible with Windows' API.

func ConvertInitiatorPortNumber

func ConvertInitiatorPortNumber(initiatorPortNumber *uint32) uint32

ConvertInitiatorPortNumber converts the user-facing initiatorPortNumber to an internal type compatible with Windows' API.

func ExtractStringFromBuffer

func ExtractStringFromBuffer(buffer []byte, bufferPointer, stringPointer, stringSize uintptr) (string, error)

ExtractStringFromBuffer extracts a regular string (PCHAR) with known length from a buffer returned by the Windows API.

func ExtractWideStringFromBuffer

func ExtractWideStringFromBuffer(buffer []byte, bufferPointer, stringPointer uintptr) (string, uintptr, error)

ExtractWideStringFromBuffer extracts a null-terminated wide string from a buffer returned by the Windows API.

func GetDllProc

func GetDllProc(name string) *windows.LazyProc

GetDllProc returns a handle to a proc from the system's iscsidsc.dll.

func HandleBufferedWinAPICall

func HandleBufferedWinAPICall(f func(s, c, b uintptr) (uintptr, error), procName string, typeSize uintptr) (buffer []byte, bufferPointer uintptr, count int32, err error)

HandleBufferedWinAPICall is a helper for Windows API calls listing objects, that always follow the same pattern: the caller has to allocate a buffer, and the proc fills that buffer, returning an object count and a byte count. typeSize is the size, in bytes, of the type the API calls expect the buffer to be (eg 1 for CHAR, 2 for WCHAR, etc...)

func IterateOverAllSubsets

func IterateOverAllSubsets(n uint, f func(subset []uint))

IterateOverAllSubsets will call f with all the 2^n - 1 (unordered) subsets of {0,1,2,...,n}.

func StringToUTF16ByteBuffer

func StringToUTF16ByteBuffer(s string) []byte

StringToUTF16ByteBuffer converts a string to UTF16 characters, then casts that to a null-terminated byte slice.

Types

type ConnectionInfo

type ConnectionInfo struct {
	ConnectionID     iscsidsc.ConnectionID
	InitiatorAddress uintptr
	TargetAddress    uintptr
	InitiatorSocket  uint16
	TargetSocket     uint16
	CID              [2]byte
}

ConnectionInfo maps to the `ISCSI_CONNECTION_INFOW` C++ struct. see https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_connection_infow

type Device

type Device struct {
	InitiatorName       [MaxHbaNameLen]uint16
	TargetName          [MaxIscsiNameLen + 1]uint16
	ScsiAddress         ScsiAddress
	DeviceInterfaceType GUID
	DeviceInterfaceName [MaxPath]uint16
	LegacyName          [MaxPath]uint16
	StorageDeviceNumber iscsidsc.StorageDeviceNumber
	DeviceInstance      uint32
}

Device maps to the `ISCSI_DEVICE_ON_SESSIONW` C++ struct. see https://docs.microsoft.com/en-us/windows/win32/api/iscsidsc/ns-iscsidsc-iscsi_device_on_sessionw

type GUID

type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

GUID maps to the `GUID` C++ struct

type InformationSpecified

type InformationSpecified uint32

InformationSpecified are used in `LoginOptions`. see the "InformationSpecified" section of https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_login_options

const (
	InformationSpecifiedHeaderDigest       InformationSpecified = 0x00000001
	InformationSpecifiedDataDigest         InformationSpecified = 0x00000002
	InformationSpecifiedMaximumConnections InformationSpecified = 0x00000004
	InformationSpecifiedDefaultTime2Wait   InformationSpecified = 0x00000008
	InformationSpecifiedDefaultTime2Retain InformationSpecified = 0x00000010
	InformationSpecifiedUsername           InformationSpecified = 0x00000020
	InformationSpecifiedPassword           InformationSpecified = 0x00000040
	InformationSpecifiedAuthType           InformationSpecified = 0x00000080
)

The flags for the various pieces of information that can be specified in login options.

type LoginOptions

type LoginOptions struct {
	Version              uint32
	InformationSpecified InformationSpecified
	LoginFlags           iscsidsc.LoginFlags
	AuthType             iscsidsc.AuthType
	HeaderDigest         iscsidsc.DigestType
	DataDigest           iscsidsc.DigestType
	MaximumConnections   uint32
	DefaultTime2Wait     uint32
	DefaultTime2Retain   uint32
	UsernameLength       uint32
	PasswordLength       uint32
	Username             uintptr
	Password             uintptr
}

LoginOptions maps to the `ISCSI_LOGIN_OPTIONS` C++ struct. see https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_login_options

func CheckAndConvertLoginOptions

func CheckAndConvertLoginOptions(optsIn *iscsidsc.LoginOptions) (opts *LoginOptions, userNamePtr, passwordPtr *byte, err error)

CheckAndConvertLoginOptions translates the user-facing `LoginOptions` struct into the internal `LoginOptions` struct that the syscalls expect. Note that this latter struct contains two `uintptr`s that map to `PUCHAR`s on the C++ side, which means they need to be converted to unsafe pointers in a safe way; we achieve that by taking advantage of converting them to unsafe pointers as part of a function call's argument lists. See https://golang.org/pkg/unsafe/#Pointer (point 4) for more info.

type Portal

type Portal struct {
	SymbolicName [MaxIscsiPortalNameLen]uint16
	Address      [MaxIscsiPortalAddressLen]uint16
	Socket       uint16
}

Portal maps to the `ISCSI_TARGET_PORTALW` C++ struct. We need a separate struct from the public-facing Portal struct for the same reason we outlined above for loginOptions/LoginOptions. see https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_target_portalw

func CheckAndConvertPortal

func CheckAndConvertPortal(ptlIn *iscsidsc.Portal) (*Portal, error)

CheckAndConvertPortal translates the user-facing `Portal` struct into the internal `Portal` struct that the syscalls expect.

type PortalInfo

type PortalInfo struct {
	InitiatorName       [MaxHbaNameLen]uint16
	InitiatorPortNumber uint32
	SymbolicName        [MaxIscsiPortalNameLen]uint16
	Address             [MaxIscsiPortalAddressLen]uint16
	Socket              uint16
	SecurityFlags       iscsidsc.SecurityFlags
	LoginOptions        LoginOptions
}

PortalInfo maps to the `ISCSI_TARGET_PORTAL_INFO_EXW` C++ struct. see https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_target_portal_info_exw

type ScsiAddress

type ScsiAddress struct {
	Length     uint32
	PortNumber uint8
	PathID     uint8
	TargetID   uint8
	Lun        uint8
}

ScsiAddress maps to the `SCSI_ADDRESS` C++ struct. see https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddscsi/ns-ntddscsi-_scsi_address

type SessionInfo

type SessionInfo struct {
	SessionID       iscsidsc.SessionID
	InitiatorName   uintptr
	TargetNodeName  uintptr
	TargetName      uintptr
	ISID            [6]byte
	TSID            [2]byte
	ConnectionCount uint32
	Connections     uintptr
}

SessionInfo maps to the `ISCSI_SESSION_INFOW` C++ struct. see https://docs.microsoft.com/en-us/windows/desktop/api/iscsidsc/ns-iscsidsc-iscsi_session_infow

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL