Documentation ¶
Index ¶
- Constants
- Variables
- func BoolToByte(b bool) byte
- func CallWinAPI(proc *windows.LazyProc, args ...uintptr) (uintptr, error)
- func CheckAndConvertKey(key *string) (keyPtr *byte, keySize uint32, err error)
- func ConvertInitiatorArgs(initiatorInstance *string, initiatorPortNumber *uint32) (*uint16, uint32, error)
- func ConvertInitiatorPortNumber(initiatorPortNumber *uint32) uint32
- func ExtractStringFromBuffer(buffer []byte, bufferPointer, stringPointer, stringSize uintptr) (string, error)
- func ExtractWideStringFromBuffer(buffer []byte, bufferPointer, stringPointer uintptr) (string, uintptr, error)
- func GetDllProc(name string) *windows.LazyProc
- func HandleBufferedWinAPICall(f func(s, c, b uintptr) (uintptr, error), procName string, typeSize uintptr) (buffer []byte, bufferPointer uintptr, count int32, err error)
- func IterateOverAllSubsets(n uint, f func(subset []uint))
- func StringToUTF16ByteBuffer(s string) []byte
- type ConnectionInfo
- type Device
- type GUID
- type InformationSpecified
- type LoginOptions
- type Portal
- type PortalInfo
- type ScsiAddress
- type SessionInfo
Constants ¶
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
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.
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
const MaxHbaNameLen = 256
MaxHbaNameLen maps to the `MAX_ISCSI_HBANAME_LEN` C++ constant.
const MaxIscsiNameLen = 223
MaxIscsiNameLen maps to the `MAX_ISCSI_NAME_LEN` C++ constant.
const MaxIscsiPortalAddressLen = 256
MaxIscsiPortalAddressLen maps to the `MAX_ISCSI_PORTAL_ADDRESS_LEN` C++ constant.
const MaxIscsiPortalNameLen = 256
MaxIscsiPortalNameLen maps to the `MAX_ISCSI_PORTAL_NAME_LEN` C++ constant.
const MaxPath = 260
MaxPath maps to the `MAX_PATH` C++ constant.
Variables ¶
var ( // ConnectionInfoSize is the size, in bytes, of the internal `ConnectionInfo` type. ConnectionInfoSize = unsafe.Sizeof(emptyConnectionInfo) )
var ( // DeviceSize is the size, in bytes, of the internal `Device` type. DeviceSize = unsafe.Sizeof(emptyDevice) )
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 )
var ( // PortalInfoSize is the size, in bytes, of the internal `PortalInfo` type. PortalInfoSize = unsafe.Sizeof(emptyPrivatePortalInfo) )
var ( // SessionInfoSize is the size, in bytes, of the internal `SessionInfo` type. SessionInfoSize = unsafe.Sizeof(emptySessionInfo) )
Functions ¶
func CallWinAPI ¶
CallWinAPI makes a call to Windows' API.
func CheckAndConvertKey ¶
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 ¶
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 ¶
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 ¶
IterateOverAllSubsets will call f with all the 2^n - 1 (unordered) subsets of {0,1,2,...,n}.
func StringToUTF16ByteBuffer ¶
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 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
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 ¶
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