Win32 API 日本語リファレンス
ホームStorage.IscsiDisc › ISCSI_DEVICE_ON_SESSIONW

ISCSI_DEVICE_ON_SESSIONW

構造体
サイズx64: 2040 バイト / x86: 2040 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
InitiatorNameWCHAR512+0+0デバイスが属するイニシエータ名を保持する固定長WCHAR配列。
TargetNameWCHAR448+512+512デバイスが属するターゲット名を保持する固定長WCHAR配列。
ScsiAddressSCSI_ADDRESS8+960+960デバイスのSCSIアドレス(ポート/パス/ターゲット/LUN)を表すSCSI_ADDRESS。
DeviceInterfaceTypeGUID16+968+968デバイスインターフェイスクラスを示すGUID。
DeviceInterfaceNameWCHAR520+984+984デバイスインターフェイスのシンボリックリンク名を保持する固定長WCHAR配列。
LegacyNameWCHAR520+1504+1504従来形式のデバイス名(\\.\PhysicalDriveN等)を保持する固定長WCHAR配列。
StorageDeviceNumberSTORAGE_DEVICE_NUMBER12+2024+2024ストレージデバイス番号(種別/番号/パーティション)を表すSTORAGE_DEVICE_NUMBER。
DeviceInstanceDWORD4+2036+2036デバイスインスタンスを識別する番号。

各言語での定義

#include <windows.h>

// SCSI_ADDRESS  (x64 8 / x86 8 バイト)
typedef struct SCSI_ADDRESS {
    DWORD Length;
    BYTE PortNumber;
    BYTE PathId;
    BYTE TargetId;
    BYTE Lun;
} SCSI_ADDRESS;

// STORAGE_DEVICE_NUMBER  (x64 12 / x86 12 バイト)
typedef struct STORAGE_DEVICE_NUMBER {
    DWORD DeviceType;
    DWORD DeviceNumber;
    DWORD PartitionNumber;
} STORAGE_DEVICE_NUMBER;

// ISCSI_DEVICE_ON_SESSIONW  (x64 2040 / x86 2040 バイト)
typedef struct ISCSI_DEVICE_ON_SESSIONW {
    WCHAR InitiatorName[256];
    WCHAR TargetName[224];
    SCSI_ADDRESS ScsiAddress;
    GUID DeviceInterfaceType;
    WCHAR DeviceInterfaceName[260];
    WCHAR LegacyName[260];
    STORAGE_DEVICE_NUMBER StorageDeviceNumber;
    DWORD DeviceInstance;
} ISCSI_DEVICE_ON_SESSIONW;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SCSI_ADDRESS
{
    public uint Length;
    public byte PortNumber;
    public byte PathId;
    public byte TargetId;
    public byte Lun;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct STORAGE_DEVICE_NUMBER
{
    public uint DeviceType;
    public uint DeviceNumber;
    public uint PartitionNumber;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ISCSI_DEVICE_ON_SESSIONW
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string InitiatorName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 224)] public string TargetName;
    public SCSI_ADDRESS ScsiAddress;
    public Guid DeviceInterfaceType;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string DeviceInterfaceName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string LegacyName;
    public STORAGE_DEVICE_NUMBER StorageDeviceNumber;
    public uint DeviceInstance;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SCSI_ADDRESS
    Public Length As UInteger
    Public PortNumber As Byte
    Public PathId As Byte
    Public TargetId As Byte
    Public Lun As Byte
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure STORAGE_DEVICE_NUMBER
    Public DeviceType As UInteger
    Public DeviceNumber As UInteger
    Public PartitionNumber As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ISCSI_DEVICE_ON_SESSIONW
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public InitiatorName As String
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=224)> Public TargetName As String
    Public ScsiAddress As SCSI_ADDRESS
    Public DeviceInterfaceType As Guid
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> Public DeviceInterfaceName As String
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> Public LegacyName As String
    Public StorageDeviceNumber As STORAGE_DEVICE_NUMBER
    Public DeviceInstance As UInteger
End Structure
import ctypes
from ctypes import wintypes

class SCSI_ADDRESS(ctypes.Structure):
    _fields_ = [
        ("Length", wintypes.DWORD),
        ("PortNumber", ctypes.c_ubyte),
        ("PathId", ctypes.c_ubyte),
        ("TargetId", ctypes.c_ubyte),
        ("Lun", ctypes.c_ubyte),
    ]

class STORAGE_DEVICE_NUMBER(ctypes.Structure):
    _fields_ = [
        ("DeviceType", wintypes.DWORD),
        ("DeviceNumber", wintypes.DWORD),
        ("PartitionNumber", wintypes.DWORD),
    ]

class ISCSI_DEVICE_ON_SESSIONW(ctypes.Structure):
    _fields_ = [
        ("InitiatorName", ctypes.c_wchar * 256),
        ("TargetName", ctypes.c_wchar * 224),
        ("ScsiAddress", SCSI_ADDRESS),
        ("DeviceInterfaceType", GUID),
        ("DeviceInterfaceName", ctypes.c_wchar * 260),
        ("LegacyName", ctypes.c_wchar * 260),
        ("StorageDeviceNumber", STORAGE_DEVICE_NUMBER),
        ("DeviceInstance", wintypes.DWORD),
    ]
#[repr(C)]
pub struct SCSI_ADDRESS {
    pub Length: u32,
    pub PortNumber: u8,
    pub PathId: u8,
    pub TargetId: u8,
    pub Lun: u8,
}

#[repr(C)]
pub struct STORAGE_DEVICE_NUMBER {
    pub DeviceType: u32,
    pub DeviceNumber: u32,
    pub PartitionNumber: u32,
}

#[repr(C)]
pub struct ISCSI_DEVICE_ON_SESSIONW {
    pub InitiatorName: [u16; 256],
    pub TargetName: [u16; 224],
    pub ScsiAddress: SCSI_ADDRESS,
    pub DeviceInterfaceType: GUID,
    pub DeviceInterfaceName: [u16; 260],
    pub LegacyName: [u16; 260],
    pub StorageDeviceNumber: STORAGE_DEVICE_NUMBER,
    pub DeviceInstance: u32,
}
import "golang.org/x/sys/windows"

type SCSI_ADDRESS struct {
	Length uint32
	PortNumber byte
	PathId byte
	TargetId byte
	Lun byte
}

type STORAGE_DEVICE_NUMBER struct {
	DeviceType uint32
	DeviceNumber uint32
	PartitionNumber uint32
}

type ISCSI_DEVICE_ON_SESSIONW struct {
	InitiatorName [256]uint16
	TargetName [224]uint16
	ScsiAddress SCSI_ADDRESS
	DeviceInterfaceType windows.GUID
	DeviceInterfaceName [260]uint16
	LegacyName [260]uint16
	StorageDeviceNumber STORAGE_DEVICE_NUMBER
	DeviceInstance uint32
}
type
  SCSI_ADDRESS = record
    Length: DWORD;
    PortNumber: Byte;
    PathId: Byte;
    TargetId: Byte;
    Lun: Byte;
  end;

  STORAGE_DEVICE_NUMBER = record
    DeviceType: DWORD;
    DeviceNumber: DWORD;
    PartitionNumber: DWORD;
  end;

  ISCSI_DEVICE_ON_SESSIONW = record
    InitiatorName: array[0..255] of WideChar;
    TargetName: array[0..223] of WideChar;
    ScsiAddress: SCSI_ADDRESS;
    DeviceInterfaceType: TGUID;
    DeviceInterfaceName: array[0..259] of WideChar;
    LegacyName: array[0..259] of WideChar;
    StorageDeviceNumber: STORAGE_DEVICE_NUMBER;
    DeviceInstance: DWORD;
  end;
const SCSI_ADDRESS = extern struct {
    Length: u32,
    PortNumber: u8,
    PathId: u8,
    TargetId: u8,
    Lun: u8,
};

const STORAGE_DEVICE_NUMBER = extern struct {
    DeviceType: u32,
    DeviceNumber: u32,
    PartitionNumber: u32,
};

const ISCSI_DEVICE_ON_SESSIONW = extern struct {
    InitiatorName: [256]u16,
    TargetName: [224]u16,
    ScsiAddress: SCSI_ADDRESS,
    DeviceInterfaceType: GUID,
    DeviceInterfaceName: [260]u16,
    LegacyName: [260]u16,
    StorageDeviceNumber: STORAGE_DEVICE_NUMBER,
    DeviceInstance: u32,
};
type
  SCSI_ADDRESS {.bycopy.} = object
    Length: uint32
    PortNumber: uint8
    PathId: uint8
    TargetId: uint8
    Lun: uint8

  STORAGE_DEVICE_NUMBER {.bycopy.} = object
    DeviceType: uint32
    DeviceNumber: uint32
    PartitionNumber: uint32

  ISCSI_DEVICE_ON_SESSIONW {.bycopy.} = object
    InitiatorName: array[256, uint16]
    TargetName: array[224, uint16]
    ScsiAddress: SCSI_ADDRESS
    DeviceInterfaceType: GUID
    DeviceInterfaceName: array[260, uint16]
    LegacyName: array[260, uint16]
    StorageDeviceNumber: STORAGE_DEVICE_NUMBER
    DeviceInstance: uint32
struct SCSI_ADDRESS
{
    uint Length;
    ubyte PortNumber;
    ubyte PathId;
    ubyte TargetId;
    ubyte Lun;
}

struct STORAGE_DEVICE_NUMBER
{
    uint DeviceType;
    uint DeviceNumber;
    uint PartitionNumber;
}

struct ISCSI_DEVICE_ON_SESSIONW
{
    wchar[256] InitiatorName;
    wchar[224] TargetName;
    SCSI_ADDRESS ScsiAddress;
    GUID DeviceInterfaceType;
    wchar[260] DeviceInterfaceName;
    wchar[260] LegacyName;
    STORAGE_DEVICE_NUMBER StorageDeviceNumber;
    uint DeviceInstance;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; ISCSI_DEVICE_ON_SESSIONW サイズ: 2040 バイト(x64)
dim st, 510    ; 4byte整数×510(構造体サイズ 2040 / 4 切り上げ)
; InitiatorName : WCHAR (+0, 512byte)  varptr(st)+0 を基点に操作(512byte:入れ子/配列)
; TargetName : WCHAR (+512, 448byte)  varptr(st)+512 を基点に操作(448byte:入れ子/配列)
; ScsiAddress : SCSI_ADDRESS (+960, 8byte)  varptr(st)+960 を基点に操作(8byte:入れ子/配列)
; DeviceInterfaceType : GUID (+968, 16byte)  varptr(st)+968 を基点に操作(16byte:入れ子/配列)
; DeviceInterfaceName : WCHAR (+984, 520byte)  varptr(st)+984 を基点に操作(520byte:入れ子/配列)
; LegacyName : WCHAR (+1504, 520byte)  varptr(st)+1504 を基点に操作(520byte:入れ子/配列)
; StorageDeviceNumber : STORAGE_DEVICE_NUMBER (+2024, 12byte)  varptr(st)+2024 を基点に操作(12byte:入れ子/配列)
; DeviceInstance : DWORD (+2036, 4byte)  st.509 = 値  /  値 = st.509   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global SCSI_ADDRESS
    #field int Length
    #field byte PortNumber
    #field byte PathId
    #field byte TargetId
    #field byte Lun
#endstruct

#defstruct global GUID, pack=1
    #field int Data1
    #field short Data2
    #field short Data3
    #field byte Data4 8
#endstruct

#defstruct global STORAGE_DEVICE_NUMBER
    #field int DeviceType
    #field int DeviceNumber
    #field int PartitionNumber
#endstruct

#defstruct global ISCSI_DEVICE_ON_SESSIONW
    #field wchar InitiatorName 256
    #field wchar TargetName 224
    #field SCSI_ADDRESS ScsiAddress
    #field GUID DeviceInterfaceType
    #field wchar DeviceInterfaceName 260
    #field wchar LegacyName 260
    #field STORAGE_DEVICE_NUMBER StorageDeviceNumber
    #field int DeviceInstance
#endstruct

stdim st, ISCSI_DEVICE_ON_SESSIONW        ; NSTRUCT 変数を確保
st->DeviceInstance = 100
mes "DeviceInstance=" + st->DeviceInstance