Win32 API 日本語リファレンス
ホームSystem.Ioctl › STORAGE_PROTOCOL_COMMAND

STORAGE_PROTOCOL_COMMAND

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

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

フィールド

フィールドサイズx64x86説明
VersionDWORD4+0+0この構造体のバージョン番号。
LengthDWORD4+4+4この構造体のバイト単位のサイズ。
ProtocolTypeSTORAGE_PROTOCOL_TYPE4+8+8NVMeやATAなどのプロトコル種別を示す列挙値。
FlagsDWORD4+12+12コマンド動作を制御するフラグのビットマスク。
ReturnStatusDWORD4+16+16コマンドの戻りステータスコード。
ErrorCodeDWORD4+20+20デバイスから返されたエラーコード。
CommandLengthDWORD4+24+24Commandフィールドのバイト長。
ErrorInfoLengthDWORD4+28+28エラー情報領域のバイト長。
DataToDeviceTransferLengthDWORD4+32+32デバイスへ転送するデータのバイト長。
DataFromDeviceTransferLengthDWORD4+36+36デバイスから受信するデータのバイト長。
TimeOutValueDWORD4+40+40コマンドのタイムアウト時間。秒単位。
ErrorInfoOffsetDWORD4+44+44構造体先頭からエラー情報領域までのオフセット。
DataToDeviceBufferOffsetDWORD4+48+48デバイスへの送信データバッファへのオフセット。
DataFromDeviceBufferOffsetDWORD4+52+52デバイスからの受信データバッファへのオフセット。
CommandSpecificDWORD4+56+56コマンド固有の情報を格納する。
Reserved0DWORD4+60+60予約領域。ゼロを設定する。
FixedProtocolReturnDataDWORD4+64+64プロトコル固有の固定返却データ領域。
FixedProtocolReturnData2DWORD4+68+68プロトコル固有の追加の固定返却データ領域。
Reserved1DWORD8+72+72予約領域。ゼロを設定する。
CommandBYTE1+80+80送信するプロトコルコマンドのバイト列。可変長配列。

各言語での定義

#include <windows.h>

// STORAGE_PROTOCOL_COMMAND  (x64 84 / x86 84 バイト)
typedef struct STORAGE_PROTOCOL_COMMAND {
    DWORD Version;
    DWORD Length;
    STORAGE_PROTOCOL_TYPE ProtocolType;
    DWORD Flags;
    DWORD ReturnStatus;
    DWORD ErrorCode;
    DWORD CommandLength;
    DWORD ErrorInfoLength;
    DWORD DataToDeviceTransferLength;
    DWORD DataFromDeviceTransferLength;
    DWORD TimeOutValue;
    DWORD ErrorInfoOffset;
    DWORD DataToDeviceBufferOffset;
    DWORD DataFromDeviceBufferOffset;
    DWORD CommandSpecific;
    DWORD Reserved0;
    DWORD FixedProtocolReturnData;
    DWORD FixedProtocolReturnData2;
    DWORD Reserved1[2];
    BYTE Command[1];
} STORAGE_PROTOCOL_COMMAND;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct STORAGE_PROTOCOL_COMMAND
{
    public uint Version;
    public uint Length;
    public int ProtocolType;
    public uint Flags;
    public uint ReturnStatus;
    public uint ErrorCode;
    public uint CommandLength;
    public uint ErrorInfoLength;
    public uint DataToDeviceTransferLength;
    public uint DataFromDeviceTransferLength;
    public uint TimeOutValue;
    public uint ErrorInfoOffset;
    public uint DataToDeviceBufferOffset;
    public uint DataFromDeviceBufferOffset;
    public uint CommandSpecific;
    public uint Reserved0;
    public uint FixedProtocolReturnData;
    public uint FixedProtocolReturnData2;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public uint[] Reserved1;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Command;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure STORAGE_PROTOCOL_COMMAND
    Public Version As UInteger
    Public Length As UInteger
    Public ProtocolType As Integer
    Public Flags As UInteger
    Public ReturnStatus As UInteger
    Public ErrorCode As UInteger
    Public CommandLength As UInteger
    Public ErrorInfoLength As UInteger
    Public DataToDeviceTransferLength As UInteger
    Public DataFromDeviceTransferLength As UInteger
    Public TimeOutValue As UInteger
    Public ErrorInfoOffset As UInteger
    Public DataToDeviceBufferOffset As UInteger
    Public DataFromDeviceBufferOffset As UInteger
    Public CommandSpecific As UInteger
    Public Reserved0 As UInteger
    Public FixedProtocolReturnData As UInteger
    Public FixedProtocolReturnData2 As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public Reserved1() As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public Command() As Byte
End Structure
import ctypes
from ctypes import wintypes

class STORAGE_PROTOCOL_COMMAND(ctypes.Structure):
    _fields_ = [
        ("Version", wintypes.DWORD),
        ("Length", wintypes.DWORD),
        ("ProtocolType", ctypes.c_int),
        ("Flags", wintypes.DWORD),
        ("ReturnStatus", wintypes.DWORD),
        ("ErrorCode", wintypes.DWORD),
        ("CommandLength", wintypes.DWORD),
        ("ErrorInfoLength", wintypes.DWORD),
        ("DataToDeviceTransferLength", wintypes.DWORD),
        ("DataFromDeviceTransferLength", wintypes.DWORD),
        ("TimeOutValue", wintypes.DWORD),
        ("ErrorInfoOffset", wintypes.DWORD),
        ("DataToDeviceBufferOffset", wintypes.DWORD),
        ("DataFromDeviceBufferOffset", wintypes.DWORD),
        ("CommandSpecific", wintypes.DWORD),
        ("Reserved0", wintypes.DWORD),
        ("FixedProtocolReturnData", wintypes.DWORD),
        ("FixedProtocolReturnData2", wintypes.DWORD),
        ("Reserved1", wintypes.DWORD * 2),
        ("Command", ctypes.c_ubyte * 1),
    ]
#[repr(C)]
pub struct STORAGE_PROTOCOL_COMMAND {
    pub Version: u32,
    pub Length: u32,
    pub ProtocolType: i32,
    pub Flags: u32,
    pub ReturnStatus: u32,
    pub ErrorCode: u32,
    pub CommandLength: u32,
    pub ErrorInfoLength: u32,
    pub DataToDeviceTransferLength: u32,
    pub DataFromDeviceTransferLength: u32,
    pub TimeOutValue: u32,
    pub ErrorInfoOffset: u32,
    pub DataToDeviceBufferOffset: u32,
    pub DataFromDeviceBufferOffset: u32,
    pub CommandSpecific: u32,
    pub Reserved0: u32,
    pub FixedProtocolReturnData: u32,
    pub FixedProtocolReturnData2: u32,
    pub Reserved1: [u32; 2],
    pub Command: [u8; 1],
}
import "golang.org/x/sys/windows"

type STORAGE_PROTOCOL_COMMAND struct {
	Version uint32
	Length uint32
	ProtocolType int32
	Flags uint32
	ReturnStatus uint32
	ErrorCode uint32
	CommandLength uint32
	ErrorInfoLength uint32
	DataToDeviceTransferLength uint32
	DataFromDeviceTransferLength uint32
	TimeOutValue uint32
	ErrorInfoOffset uint32
	DataToDeviceBufferOffset uint32
	DataFromDeviceBufferOffset uint32
	CommandSpecific uint32
	Reserved0 uint32
	FixedProtocolReturnData uint32
	FixedProtocolReturnData2 uint32
	Reserved1 [2]uint32
	Command [1]byte
}
type
  STORAGE_PROTOCOL_COMMAND = record
    Version: DWORD;
    Length: DWORD;
    ProtocolType: Integer;
    Flags: DWORD;
    ReturnStatus: DWORD;
    ErrorCode: DWORD;
    CommandLength: DWORD;
    ErrorInfoLength: DWORD;
    DataToDeviceTransferLength: DWORD;
    DataFromDeviceTransferLength: DWORD;
    TimeOutValue: DWORD;
    ErrorInfoOffset: DWORD;
    DataToDeviceBufferOffset: DWORD;
    DataFromDeviceBufferOffset: DWORD;
    CommandSpecific: DWORD;
    Reserved0: DWORD;
    FixedProtocolReturnData: DWORD;
    FixedProtocolReturnData2: DWORD;
    Reserved1: array[0..1] of DWORD;
    Command: array[0..0] of Byte;
  end;
const STORAGE_PROTOCOL_COMMAND = extern struct {
    Version: u32,
    Length: u32,
    ProtocolType: i32,
    Flags: u32,
    ReturnStatus: u32,
    ErrorCode: u32,
    CommandLength: u32,
    ErrorInfoLength: u32,
    DataToDeviceTransferLength: u32,
    DataFromDeviceTransferLength: u32,
    TimeOutValue: u32,
    ErrorInfoOffset: u32,
    DataToDeviceBufferOffset: u32,
    DataFromDeviceBufferOffset: u32,
    CommandSpecific: u32,
    Reserved0: u32,
    FixedProtocolReturnData: u32,
    FixedProtocolReturnData2: u32,
    Reserved1: [2]u32,
    Command: [1]u8,
};
type
  STORAGE_PROTOCOL_COMMAND {.bycopy.} = object
    Version: uint32
    Length: uint32
    ProtocolType: int32
    Flags: uint32
    ReturnStatus: uint32
    ErrorCode: uint32
    CommandLength: uint32
    ErrorInfoLength: uint32
    DataToDeviceTransferLength: uint32
    DataFromDeviceTransferLength: uint32
    TimeOutValue: uint32
    ErrorInfoOffset: uint32
    DataToDeviceBufferOffset: uint32
    DataFromDeviceBufferOffset: uint32
    CommandSpecific: uint32
    Reserved0: uint32
    FixedProtocolReturnData: uint32
    FixedProtocolReturnData2: uint32
    Reserved1: array[2, uint32]
    Command: array[1, uint8]
struct STORAGE_PROTOCOL_COMMAND
{
    uint Version;
    uint Length;
    int ProtocolType;
    uint Flags;
    uint ReturnStatus;
    uint ErrorCode;
    uint CommandLength;
    uint ErrorInfoLength;
    uint DataToDeviceTransferLength;
    uint DataFromDeviceTransferLength;
    uint TimeOutValue;
    uint ErrorInfoOffset;
    uint DataToDeviceBufferOffset;
    uint DataFromDeviceBufferOffset;
    uint CommandSpecific;
    uint Reserved0;
    uint FixedProtocolReturnData;
    uint FixedProtocolReturnData2;
    uint[2] Reserved1;
    ubyte[1] Command;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; STORAGE_PROTOCOL_COMMAND サイズ: 84 バイト(x64)
dim st, 21    ; 4byte整数×21(構造体サイズ 84 / 4 切り上げ)
; Version : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Length : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; ProtocolType : STORAGE_PROTOCOL_TYPE (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; Flags : DWORD (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; ReturnStatus : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; ErrorCode : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; CommandLength : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; ErrorInfoLength : DWORD (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; DataToDeviceTransferLength : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; DataFromDeviceTransferLength : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; TimeOutValue : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; ErrorInfoOffset : DWORD (+44, 4byte)  st.11 = 値  /  値 = st.11   (lpoke/lpeek も可)
; DataToDeviceBufferOffset : DWORD (+48, 4byte)  st.12 = 値  /  値 = st.12   (lpoke/lpeek も可)
; DataFromDeviceBufferOffset : DWORD (+52, 4byte)  st.13 = 値  /  値 = st.13   (lpoke/lpeek も可)
; CommandSpecific : DWORD (+56, 4byte)  st.14 = 値  /  値 = st.14   (lpoke/lpeek も可)
; Reserved0 : DWORD (+60, 4byte)  st.15 = 値  /  値 = st.15   (lpoke/lpeek も可)
; FixedProtocolReturnData : DWORD (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; FixedProtocolReturnData2 : DWORD (+68, 4byte)  st.17 = 値  /  値 = st.17   (lpoke/lpeek も可)
; Reserved1 : DWORD (+72, 8byte)  varptr(st)+72 を基点に操作(8byte:入れ子/配列)
; Command : BYTE (+80, 1byte)  varptr(st)+80 を基点に操作(1byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global STORAGE_PROTOCOL_COMMAND
    #field int Version
    #field int Length
    #field int ProtocolType
    #field int Flags
    #field int ReturnStatus
    #field int ErrorCode
    #field int CommandLength
    #field int ErrorInfoLength
    #field int DataToDeviceTransferLength
    #field int DataFromDeviceTransferLength
    #field int TimeOutValue
    #field int ErrorInfoOffset
    #field int DataToDeviceBufferOffset
    #field int DataFromDeviceBufferOffset
    #field int CommandSpecific
    #field int Reserved0
    #field int FixedProtocolReturnData
    #field int FixedProtocolReturnData2
    #field int Reserved1 2
    #field byte Command 1
#endstruct

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