// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // Component : FreeBSD direct device access. // // --[ Description ] ---------------------------------------------------------- // // Contains structures necessary for directly interfacing devices under // FreeBSD. // // --[ License ] -------------------------------------------------------------- // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see . // // ---------------------------------------------------------------------------- // Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System; using System.Runtime.InteropServices; namespace DiscImageChef.Devices.FreeBSD { struct ata_cmd { public CamAtaIoFlags flags; public byte command; public byte features; public byte lba_low; public byte lba_mid; public byte lba_high; public byte device; public byte lba_low_exp; public byte lba_mid_exp; public byte lba_high_exp; public byte features_exp; public byte sector_count; public byte sector_count_exp; public byte control; } struct ata_res { public CamAtaIoFlags flags; public byte status; public byte error; public byte lba_low; public byte lba_mid; public byte lba_high; public byte device; public byte lba_low_exp; public byte lba_mid_exp; public byte lba_high_exp; public byte sector_count; public byte sector_count_exp; } struct cam_pinfo { public uint priority; public uint generation; public int index; } struct camq_entry { /// /// LIST_ENTRY(ccb_hdr)=le->*le_next /// public IntPtr le_next; /// /// LIST_ENTRY(ccb_hdr)=le->**le_prev /// public IntPtr le_prev; /// /// SLIST_ENTRY(ccb_hdr)=sle->*sle_next /// public IntPtr sle_next; /// /// TAILQ_ENTRY(ccb_hdr)=tqe->*tqe_next /// public IntPtr tqe_next; /// /// TAILQ_ENTRY(ccb_hdr)=tqe->**tqe_prev /// public IntPtr tqe_prev; /// /// STAILQ_ENTRY(ccb_hdr)=stqe->*stqe_next /// public IntPtr stqe_next; } struct timeval { public long tv_sec; /// long public IntPtr tv_usec; } struct ccb_qos_area { public timeval etime; public UIntPtr sim_data; public UIntPtr periph_data; } struct ccb_hdr { public cam_pinfo pinfo; public camq_entry xpt_links; public camq_entry sim_links; public camq_entry periph_links; public uint retry_count; public IntPtr cbfcnp; public xpt_opcode func_code; public uint status; public IntPtr path; public uint path_id; public uint target_id; public ulong target_lun; public uint flags; public uint xflags; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public IntPtr[] periph_priv; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public IntPtr[] sim_priv; public ccb_qos_area qos; public uint timeout; public timeval softtimeout; } struct scsi_sense_data { public byte error_code; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 251)] public byte[] sense_buf; } /// /// SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO function codes. /// struct cdb_scsiio { public ccb_hdr ccb_h; /// Ptr for next CCB for action public IntPtr next_ccb; /// Ptr to mapping info public IntPtr req_map; /// Ptr to the data buf/SG list public IntPtr data_ptr; /// Data transfer length public uint dxfer_len; /// Autosense storage public scsi_sense_data sense_data; /// Number of bytes to autosense public byte sense_len; /// Number of bytes for the CDB public byte cdb_len; /// Number of SG list entries public short sglist_cnt; /// Returned SCSI status public byte scsi_status; /// Autosense resid length: 2's comp public sbyte sense_resid; /// Transfer residual length: 2's comp public int resid; /// Union for CDB bytes/pointer public IntPtr cdb_io; /// Pointer to the message buffer public IntPtr msg_ptr; /// Number of bytes for the Message public short msg_len; /// What to do for tag queueing. The tag action should be either the define below (to send a non-tagged transaction) or one of the defined scsi tag messages from scsi_message.h. public byte tag_action; /// tag id from initator (target mode) public uint tag_id; /// initiator id of who selected public uint init_id; } /// /// ATA I/O Request CCB used for the XPT_ATA_IO function code. /// struct ccb_ataio { public ccb_hdr ccb_h; /// Ptr for next CCB for action public IntPtr next_ccb; /// ATA command register set public ata_cmd cmd; /// ATA result register set public ata_res res; /// Ptr to the data buf/SG list public IntPtr data_ptr; /// Data transfer length public uint dxfer_len; /// Transfer residual length: 2's comp public int resid; /// What to do for tag queueing. The tag action should be either the define below (to send a non-tagged transaction) or one of the defined scsi tag messages from scsi_message.h. public byte tag_action; /// tag id from initator (target mode) public uint tag_id; /// initiator id of who selected public uint init_id; } struct nvme_command { private ushort opc_fuse_rsvd1; /// /// command identifier /// public ushort cid; /// /// namespace identifier /// public uint nsid; /// /// reserved /// public uint rsvd2; /// /// reserved /// public uint rsvd3; /// /// metadata pointer /// public ulong mptr; /// /// prp entry 1 /// public ulong prp1; /// /// prp entry 2 /// public ulong prp2; /// /// command-specific /// public uint cdw10; /// /// command-specific /// public uint cdw11; /// /// command-specific /// public uint cdw12; /// /// command-specific /// public uint cdw13; /// /// command-specific /// public uint cdw14; /// /// command-specific /// public uint cdw15; /// /// opcode /// public byte opc => (byte)((opc_fuse_rsvd1 & 0xFF00) >> 8); /// /// fused operation /// public byte fuse => (byte)((opc_fuse_rsvd1 & 0xC0) >> 6); /// /// reserved /// public byte rsvd1 => (byte)(opc_fuse_rsvd1 & 0x3F); } struct nvme_status { private ushort status; /// /// phase tag /// public byte p => (byte)((status & 0x8000) >> 15); /// /// status code /// public byte sc => (byte)((status & 0x7F80) >> 7); /// /// status code type /// public byte sct => (byte)((status & 0x70) >> 4); /// /// reserved /// public byte rsvd2 => (byte)((status & 0xC) >> 15); /// /// more /// public byte m => (byte)((status & 0x2) >> 1); /// /// do not retry /// public byte dnr => (byte)(status & 0x1); } struct nvme_completion { /// /// command-specific /// public uint cdw0; /// /// reserved /// public uint rsvd1; /// /// submission queue head pointer /// public ushort sqhd; /// /// submission queue identifier /// public ushort sqid; /// /// command identifier /// public ushort cid; public nvme_status status; } /// /// NVMe I/O Request CCB used for the XPT_NVME_IO and XPT_NVME_ADMIN function codes. /// struct ccb_nvmeio { public ccb_hdr ccb_h; /// Ptr for next CCB for action public IntPtr next_ccb; /// NVME command, per NVME standard public nvme_command cmd; /// NVME completion, per NVME standard public nvme_completion cpl; /// Ptr to the data buf/SG list public IntPtr data_ptr; /// Data transfer length public uint dxfer_len; /// Number of SG list entries public ushort sglist_cnt; /// padding for removed uint32_t public ushort unused; } }