Index: head/sys/cam/scsi/scsi_sa.h =================================================================== --- head/sys/cam/scsi/scsi_sa.h (revision 280229) +++ head/sys/cam/scsi/scsi_sa.h (revision 280230) @@ -1,1068 +1,1068 @@ /*- * Structure and function declarations for the * SCSI Sequential Access Peripheral driver for CAM. * * Copyright (c) 1999, 2000 Matthew Jacob * Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _SCSI_SCSI_SA_H #define _SCSI_SCSI_SA_H 1 #include struct scsi_read_block_limits { u_int8_t opcode; u_int8_t byte2; u_int8_t unused[3]; u_int8_t control; }; struct scsi_read_block_limits_data { u_int8_t gran; #define RBL_GRAN_MASK 0x1F #define RBL_GRAN(rblim) ((rblim)->gran & RBL_GRAN_MASK) u_int8_t maximum[3]; u_int8_t minimum[2]; }; struct scsi_sa_rw { u_int8_t opcode; u_int8_t sli_fixed; #define SAR_SLI 0x02 #define SARW_FIXED 0x01 u_int8_t length[3]; u_int8_t control; }; struct scsi_load_unload { u_int8_t opcode; u_int8_t immediate; #define SLU_IMMED 0x01 u_int8_t reserved[2]; u_int8_t eot_reten_load; #define SLU_EOT 0x04 #define SLU_RETEN 0x02 #define SLU_LOAD 0x01 u_int8_t control; }; struct scsi_rewind { u_int8_t opcode; u_int8_t immediate; #define SREW_IMMED 0x01 u_int8_t reserved[3]; u_int8_t control; }; typedef enum { SS_BLOCKS, SS_FILEMARKS, SS_SEQFILEMARKS, SS_EOD, SS_SETMARKS, SS_SEQSETMARKS } scsi_space_code; struct scsi_space { u_int8_t opcode; u_int8_t code; #define SREW_IMMED 0x01 u_int8_t count[3]; u_int8_t control; }; struct scsi_write_filemarks { u_int8_t opcode; u_int8_t byte2; #define SWFMRK_IMMED 0x01 #define SWFMRK_WSMK 0x02 u_int8_t num_marks[3]; u_int8_t control; }; /* * Reserve and release unit have the same exact cdb format, but different * opcodes. */ struct scsi_reserve_release_unit { u_int8_t opcode; u_int8_t lun_thirdparty; #define SRRU_LUN_MASK 0xE0 #define SRRU_3RD_PARTY 0x10 #define SRRU_3RD_SHAMT 1 #define SRRU_3RD_MASK 0xE u_int8_t reserved[3]; u_int8_t control; }; /* * Erase a tape */ struct scsi_erase { u_int8_t opcode; u_int8_t lun_imm_long; #define SE_LUN_MASK 0xE0 #define SE_LONG 0x1 #define SE_IMMED 0x2 u_int8_t reserved[3]; u_int8_t control; }; /* * Set tape capacity. */ struct scsi_set_capacity { u_int8_t opcode; u_int8_t byte1; #define SA_SSC_IMMED 0x01 u_int8_t reserved; u_int8_t cap_proportion[2]; u_int8_t control; }; /* * Format tape media. The CDB opcode is the same as the disk-specific * FORMAT UNIT command, but the fields are different inside the CDB. Thus * the reason for a separate definition here. */ struct scsi_format_medium { u_int8_t opcode; u_int8_t byte1; #define SFM_IMMED 0x01 #define SFM_VERIFY 0x02 u_int8_t byte2; #define SFM_FORMAT_DEFAULT 0x00 #define SFM_FORMAT_PARTITION 0x01 #define SFM_FORMAT_DEF_PART 0x02 #define SFM_FORMAT_MASK 0x0f u_int8_t length[2]; u_int8_t control; }; struct scsi_allow_overwrite { u_int8_t opcode; u_int8_t reserved1; u_int8_t allow_overwrite; #define SAO_ALLOW_OVERWRITE_DISABLED 0x00 #define SAO_ALLOW_OVERWRITE_CUR_POS 0x01 #define SAO_ALLOW_OVERWRITE_FORMAT 0x02 u_int8_t partition; u_int8_t logical_id[8]; u_int8_t reserved2[3]; u_int8_t control; }; /* * Dev specific mode page masks. */ #define SMH_SA_WP 0x80 #define SMH_SA_BUF_MODE_MASK 0x70 #define SMH_SA_BUF_MODE_NOBUF 0x00 #define SMH_SA_BUF_MODE_SIBUF 0x10 /* Single-Initiator buffering */ #define SMH_SA_BUF_MODE_MIBUF 0x20 /* Multi-Initiator buffering */ #define SMH_SA_SPEED_MASK 0x0F #define SMH_SA_SPEED_DEFAULT 0x00 /* * Sequential-access specific mode page numbers. */ #define SA_DEVICE_CONFIGURATION_PAGE 0x10 #define SA_MEDIUM_PARTITION_PAGE_1 0x11 #define SA_MEDIUM_PARTITION_PAGE_2 0x12 #define SA_MEDIUM_PARTITION_PAGE_3 0x13 #define SA_MEDIUM_PARTITION_PAGE_4 0x14 #define SA_DATA_COMPRESSION_PAGE 0x0f /* SCSI-3 */ /* * Mode page definitions. */ /* See SCSI-II spec 9.3.3.1 */ struct scsi_dev_conf_page { u_int8_t pagecode; /* 0x10 */ u_int8_t pagelength; /* 0x0e */ u_int8_t byte2; /* CAP, CAF, Active Format */ u_int8_t active_partition; u_int8_t wb_full_ratio; u_int8_t rb_empty_ratio; u_int8_t wrdelay_time[2]; u_int8_t byte8; #define SA_DBR 0x80 /* data buffer recovery */ #define SA_BIS 0x40 /* block identifiers supported */ #define SA_RSMK 0x20 /* report setmarks */ #define SA_AVC 0x10 /* automatic velocity control */ #define SA_SOCF_MASK 0x0c /* stop on consecutive formats */ #define SA_RBO 0x02 /* recover buffer order */ #define SA_REW 0x01 /* report early warning */ u_int8_t gap_size; u_int8_t byte10; /* from SCSI-3: SSC-4 Working draft (2/14) 8.3.3 */ #define SA_EOD_DEF_MASK 0xe0 /* EOD defined */ #define SA_EEG 0x10 /* Enable EOD Generation */ #define SA_SEW 0x08 /* Synchronize at Early Warning */ #define SA_SOFT_WP 0x04 /* Software Write Protect */ #define SA_BAML 0x02 /* Block Address Mode Lock */ #define SA_BAM 0x01 /* Block Address Mode */ u_int8_t ew_bufsize[3]; u_int8_t sel_comp_alg; #define SA_COMP_NONE 0x00 #define SA_COMP_DEFAULT 0x01 /* the following is 'reserved' in SCSI-2 but is defined in SSC-r22 */ u_int8_t extra_wp; #define SA_ASOC_WP 0x04 /* Associated Write Protect */ #define SA_PERS_WP 0x02 /* Persistent Write Protect */ #define SA_PERM_WP 0x01 /* Permanent Write Protect */ }; /* from SCSI-3: SSC-Rev10 (6/97) */ struct scsi_data_compression_page { u_int8_t page_code; /* 0x0f */ u_int8_t page_length; /* 0x0e */ u_int8_t dce_and_dcc; #define SA_DCP_DCE 0x80 /* Data compression enable */ #define SA_DCP_DCC 0x40 /* Data compression capable */ u_int8_t dde_and_red; #define SA_DCP_DDE 0x80 /* Data decompression enable */ #define SA_DCP_RED_MASK 0x60 /* Report Exception on Decomp. */ #define SA_DCP_RED_SHAMT 5 #define SA_DCP_RED_0 0x00 #define SA_DCP_RED_1 0x20 #define SA_DCP_RED_2 0x40 u_int8_t comp_algorithm[4]; u_int8_t decomp_algorithm[4]; u_int8_t reserved[4]; }; typedef union { struct { u_int8_t pagecode, pagelength; } hdr; struct scsi_dev_conf_page dconf; struct scsi_data_compression_page dcomp; } sa_comp_t; /* * Control Data Protection subpage. This is as defined in SSC3r03. */ struct scsi_control_data_prot_subpage { uint8_t page_code; #define SA_CTRL_DP_PAGE_CODE 0x0a uint8_t subpage_code; #define SA_CTRL_DP_SUBPAGE_CODE 0xf0 uint8_t length[2]; uint8_t prot_method; #define SA_CTRL_DP_NO_LBP 0x00 #define SA_CTRL_DP_REED_SOLOMON 0x01 #define SA_CTRL_DP_METHOD_MAX 0xff uint8_t pi_length; #define SA_CTRL_DP_PI_LENGTH_MASK 0x3f #define SA_CTRL_DP_RS_LENGTH 4 uint8_t prot_bits; #define SA_CTRL_DP_LBP_W 0x80 #define SA_CTRL_DP_LBP_R 0x40 #define SA_CTRL_DP_RBDP 0x20 uint8_t reserved[]; }; /* * This is the Read/Write Control mode page used on IBM Enterprise Tape * Drives. They are known as 3592, TS, or Jaguar drives. The SCSI inquiry * data will show a Product ID "03592XXX", where XXX is 'J1A', 'E05' (TS1120), * 'E06' (TS1130), 'E07' (TS1140) or 'E08' (TS1150). * * This page definition is current as of the 3592 SCSI Reference v6, * released on December 16th, 2014. */ struct scsi_tape_ibm_rw_control { uint8_t page_code; #define SA_IBM_RW_CTRL_PAGE_CODE 0x25 uint8_t page_length; uint8_t ignore_seq_checks; #define SA_IBM_RW_CTRL_LOC_IGNORE_SEQ 0x04 #define SA_IBM_RW_CTRL_SPC_BLK_IGNORE_SEQ 0x02 #define SA_IBM_RW_CTRL_SPC_FM_IGNORE_SEQ 0x01 uint8_t ignore_data_checks; #define SA_IBM_RW_CTRL_LOC_IGNORE_DATA 0x04 #define SA_IBM_RW_CTRL_SPC_BLK_IGNORE_DATA 0x02 #define SA_IBM_RW_CTRL_SPC_FM_IGNORE_DATA 0x01 uint8_t reserved1; uint8_t leop_method; #define SA_IBM_RW_CTRL_LEOP_DEFAULT 0x00 #define SA_IBM_RW_CTRL_LEOP_MAX_CAP 0x01 #define SA_IBM_RW_CTRL_LEOP_CONST_CAP 0x02 uint8_t leop_ew[2]; uint8_t byte8; #define SA_IBM_RW_CTRL_DISABLE_FASTSYNC 0x80 #define SA_IBM_RW_CTRL_DISABLE_SKIPSYNC 0x40 #define SA_IBM_RW_CTRL_DISABLE_CROSS_EOD 0x08 #define SA_IBM_RW_CTRL_DISABLE_CROSS_PERM_ERR 0x04 #define SA_IBM_RW_CTRL_REPORT_SEG_EW 0x02 #define SA_IBM_RW_CTRL_REPORT_HOUSEKEEPING_ERR 0x01 uint8_t default_write_dens_bop_0; uint8_t pending_write_dens_bop_0; uint8_t reserved2[21]; }; struct scsi_tape_read_position { u_int8_t opcode; /* READ_POSITION */ u_int8_t byte1; /* set LSB to read hardware block pos */ #define SA_RPOS_SHORT_FORM 0x00 #define SA_RPOS_SHORT_VENDOR 0x01 #define SA_RPOS_LONG_FORM 0x06 #define SA_RPOS_EXTENDED_FORM 0x08 u_int8_t reserved[5]; u_int8_t length[2]; u_int8_t control; }; struct scsi_tape_position_data { /* Short Form */ u_int8_t flags; #define SA_RPOS_BOP 0x80 /* Beginning of Partition */ #define SA_RPOS_EOP 0x40 /* End of Partition */ #define SA_RPOS_BCU 0x20 /* Block Count Unknown (SCSI3) */ #define SA_RPOS_BYCU 0x10 /* Byte Count Unknown (SCSI3) */ #define SA_RPOS_BPU 0x04 /* Block Position Unknown */ #define SA_RPOS_PERR 0x02 /* Position Error (SCSI3) */ #define SA_RPOS_BPEW 0x01 /* Beyond Programmable Early Warning */ #define SA_RPOS_UNCERTAIN SA_RPOS_BPU u_int8_t partition; u_int8_t reserved[2]; u_int8_t firstblk[4]; u_int8_t lastblk[4]; u_int8_t reserved2; u_int8_t nbufblk[3]; u_int8_t nbufbyte[4]; }; struct scsi_tape_position_long_data { u_int8_t flags; #define SA_RPOS_LONG_BOP 0x80 /* Beginning of Partition */ #define SA_RPOS_LONG_EOP 0x40 /* End of Partition */ #define SA_RPOS_LONG_MPU 0x08 /* Mark Position Unknown */ #define SA_RPOS_LONG_LONU 0x04 /* Logical Object Number Unknown */ #define SA_RPOS_LONG_BPEW 0x01 /* Beyond Programmable Early Warning */ u_int8_t reserved[3]; u_int8_t partition[4]; u_int8_t logical_object_num[8]; u_int8_t logical_file_num[8]; u_int8_t set_id[8]; }; struct scsi_tape_position_ext_data { u_int8_t flags; #define SA_RPOS_EXT_BOP 0x80 /* Beginning of Partition */ #define SA_RPOS_EXT_EOP 0x40 /* End of Partition */ #define SA_RPOS_EXT_LOCU 0x20 /* Logical Object Count Unknown */ #define SA_RPOS_EXT_BYCU 0x10 /* Byte Count Unknown */ #define SA_RPOS_EXT_LOLU 0x04 /* Logical Object Location Unknown */ #define SA_RPOS_EXT_PERR 0x02 /* Position Error */ #define SA_RPOS_EXT_BPEW 0x01 /* Beyond Programmable Early Warning */ u_int8_t partition; u_int8_t length[2]; u_int8_t reserved; u_int8_t num_objects[3]; u_int8_t first_object[8]; u_int8_t last_object[8]; u_int8_t bytes_in_buffer[8]; }; struct scsi_tape_locate { u_int8_t opcode; u_int8_t byte1; #define SA_SPOS_IMMED 0x01 #define SA_SPOS_CP 0x02 #define SA_SPOS_BT 0x04 u_int8_t reserved1; u_int8_t blkaddr[4]; #define SA_SPOS_MAX_BLK 0xffffffff u_int8_t reserved2; u_int8_t partition; u_int8_t control; }; struct scsi_locate_16 { u_int8_t opcode; u_int8_t byte1; #define SA_LC_IMMEDIATE 0x01 #define SA_LC_CP 0x02 #define SA_LC_DEST_TYPE_MASK 0x38 #define SA_LC_DEST_TYPE_SHIFT 3 #define SA_LC_DEST_OBJECT 0x00 #define SA_LC_DEST_FILE 0x01 #define SA_LC_DEST_SET 0x02 #define SA_LC_DEST_EOD 0x03 u_int8_t byte2; #define SA_LC_BAM_IMPLICIT 0x00 #define SA_LC_BAM_EXPLICIT 0x01 u_int8_t partition; u_int8_t logical_id[8]; u_int8_t reserved[3]; u_int8_t control; }; struct scsi_report_density_support { u_int8_t opcode; u_int8_t byte1; #define SRDS_MEDIA 0x01 #define SRDS_MEDIUM_TYPE 0x02 u_int8_t reserved[5]; u_int8_t length[2]; #define SRDS_MAX_LENGTH 0xffff u_int8_t control; }; struct scsi_density_hdr { u_int8_t length[2]; u_int8_t reserved[2]; u_int8_t descriptor[]; }; struct scsi_density_data { u_int8_t primary_density_code; u_int8_t secondary_density_code; u_int8_t byte2; #define SDD_DLV 0x01 #define SDD_DEFLT 0x20 #define SDD_DUP 0x40 #define SDD_WRTOK 0x80 u_int8_t length[2]; #define SDD_DEFAULT_LENGTH 52 u_int8_t bits_per_mm[3]; u_int8_t media_width[2]; u_int8_t tracks[2]; u_int8_t capacity[4]; u_int8_t assigning_org[8]; u_int8_t density_name[8]; u_int8_t description[20]; }; struct scsi_medium_type_data { u_int8_t medium_type; u_int8_t reserved1; u_int8_t length[2]; #define SMTD_DEFAULT_LENGTH 52 u_int8_t num_density_codes; - u_int8_t primary_density_codes[8]; + u_int8_t primary_density_codes[9]; u_int8_t media_width[2]; u_int8_t medium_length[2]; u_int8_t reserved2[2]; u_int8_t assigning_org[8]; u_int8_t medium_type_name[8]; u_int8_t description[20]; }; /* * Security Protocol Specific values for the Tape Data Encryption protocol * (0x20) used with SECURITY PROTOCOL IN. See below for values used with * SECURITY PROTOCOL OUT. Current as of SSC4r03. */ #define TDE_IN_SUPPORT_PAGE 0x0000 #define TDE_OUT_SUPPORT_PAGE 0x0001 #define TDE_DATA_ENC_CAP_PAGE 0x0010 #define TDE_SUPPORTED_KEY_FORMATS_PAGE 0x0011 #define TDE_DATA_ENC_MAN_CAP_PAGE 0x0012 #define TDE_DATA_ENC_STATUS_PAGE 0x0020 #define TDE_NEXT_BLOCK_ENC_STATUS_PAGE 0x0021 #define TDE_GET_ENC_MAN_ATTR_PAGE 0x0022 #define TDE_RANDOM_NUM_PAGE 0x0030 #define TDE_KEY_WRAP_PK_PAGE 0x0031 /* * Tape Data Encryption protocol pages used with SECURITY PROTOCOL IN and * SECURITY PROTOCOL OUT. */ /* * Tape Data Encryption In Support page (0x0000). */ struct tde_in_support_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t page_codes[]; }; /* * Tape Data Encryption Out Support page (0x0001). */ struct tde_out_support_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t page_codes[]; }; /* * Logical block encryption algorithm descriptor. This is reported in the * Data Encryption Capabilities page. */ struct tde_block_enc_alg_desc { uint8_t alg_index; uint8_t reserved1; uint8_t desc_length[2]; uint8_t byte4; #define TDE_BEA_AVFMV 0x80 #define TDE_BEA_SDK_C 0x40 #define TDE_BEA_MAC_C 0x20 #define TDE_BEA_DELB_C 0x10 #define TDE_BEA_DECRYPT_C_MASK 0x0c #define TDE_BEA_DECRYPT_C_EXT 0x0c #define TDE_BEA_DECRYPT_C_HARD 0x08 #define TDE_BEA_DECRYPT_C_SOFT 0x04 #define TDE_BEA_DECRYPT_C_NO_CAP 0x00 #define TDE_BEA_ENCRYPT_C_MASK 0x03 #define TDE_BEA_ENCRYPT_C_EXT 0x03 #define TDE_BEA_ENCRYPT_C_HARD 0x02 #define TDE_BEA_ENCRYPT_C_SOFT 0x01 #define TDE_BEA_ENCRYPT_C_NO_CAP 0x00 uint8_t byte5; #define TDE_BEA_AVFCLP_MASK 0xc0 #define TDE_BEA_AVFCLP_VALID 0x80 #define TDE_BEA_AVFCLP_NOT_VALID 0x40 #define TDE_BEA_AVFCLP_NOT_APP 0x00 #define TDE_BEA_NONCE_C_MASK 0x30 #define TDE_BEA_NONCE_C_SUPPORTED 0x30 #define TDE_BEA_NONCE_C_PROVIDED 0x20 #define TDE_BEA_NONCE_C_GENERATED 0x10 #define TDE_BEA_NONCE_C_NOT_REQUIRED 0x00 #define TDE_BEA_KADF_C 0x08 #define TDE_BEA_VCELB_C 0x04 #define TDE_BEA_UKADF 0x02 #define TDE_BEA_AKADF 0x01 uint8_t max_unauth_key_bytes[2]; uint8_t max_auth_key_bytes[2]; uint8_t lbe_key_size[2]; uint8_t byte12; #define TDE_BEA_DKAD_C_MASK 0xc0 #define TDE_BEA_DKAD_C_CAPABLE 0xc0 #define TDE_BEA_DKAD_C_NOT_ALLOWED 0x80 #define TDE_BEA_DKAD_C_REQUIRED 0x40 #define TDE_BEA_EEMC_C_MASK 0x30 #define TDE_BEA_EEMC_C_ALLOWED 0x20 #define TDE_BEA_EEMC_C_NOT_ALLOWED 0x10 #define TDE_BEA_EEMC_C_NOT_SPECIFIED 0x00 /* * Raw Decryption Mode Control Capabilities (RDMC_C) field. The * descriptions are too complex to represent as a simple name. */ #define TDE_BEA_RDMC_C_MASK 0x0e #define TDE_BEA_RDMC_C_MODE_7 0x0e #define TDE_BEA_RDMC_C_MODE_6 0x0c #define TDE_BEA_RDMC_C_MODE_5 0x0a #define TDE_BEA_RDMC_C_MODE_4 0x08 #define TDE_BEA_RDMC_C_MODE_1 0x02 #define TDE_BEA_EAREM 0x01 uint8_t byte13; #define TDE_BEA_MAX_EEDKS_MASK 0x0f uint8_t msdk_count[2]; uint8_t max_eedk_size[2]; uint8_t reserved2[2]; uint8_t security_algo_code[4]; }; /* * Data Encryption Capabilities page (0x0010). */ struct tde_data_enc_cap_page { uint8_t page_code[2]; uint8_t page_length; uint8_t byte4; #define DATA_ENC_CAP_EXTDECC_MASK 0x0c #define DATA_ENC_CAP_EXTDECC_NOT_REPORTED 0x00 #define DATA_ENC_CAP_EXTDECC_NOT_CAPABLE 0x04 #define DATA_ENC_CAP_EXTDECC_CAPABLE 0x08 #define DATA_ENC_CAP_CFG_P_MASK 0x03 #define DATA_ENC_CAP_CFG_P_NOT_REPORTED 0x00 #define DATA_ENC_CAP_CFG_P_ALLOWED 0x01 #define DATA_ENC_CAP_CFG_P_NOT_ALLOWED 0x02 uint8_t reserved[15]; struct tde_block_enc_alg_desc alg_descs[]; }; /* * Tape Data Encryption Supported Key Formats page (0x0011). */ struct tde_supported_key_formats_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t key_formats_list[]; }; /* * Tape Data Encryption Management Capabilities page (0x0012). */ struct tde_data_enc_man_cap_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t byte4; #define TDE_DEMC_LOCK_C 0x01 uint8_t byte5; #define TDE_DEMC_CKOD_C 0x04 #define TDE_DEMC_CKORP_C 0x02 #define TDE_DEMC_CKORL_C 0x01 uint8_t reserved1; uint8_t byte7; #define TDE_DEMC_AITN_C 0x04 #define TDE_DEMC_LOCAL_C 0x02 #define TDE_DEMC_PUBLIC_C 0x01 uint8_t reserved2[8]; }; /* * Tape Data Encryption Status Page (0x0020). */ struct tde_data_enc_status_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t scope; #define TDE_DES_IT_NEXUS_SCOPE_MASK 0xe0 #define TDE_DES_LBE_SCOPE_MASK 0x07 uint8_t encryption_mode; uint8_t decryption_mode; uint8_t algo_index; uint8_t key_instance_counter[4]; uint8_t byte12; #define TDE_DES_PARAM_CTRL_MASK 0x70 #define TDE_DES_PARAM_CTRL_MGMT 0x40 #define TDE_DES_PARAM_CTRL_CHANGER 0x30 #define TDE_DES_PARAM_CTRL_DRIVE 0x20 #define TDE_DES_PARAM_CTRL_EXT 0x10 #define TDE_DES_PARAM_CTRL_NOT_REPORTED 0x00 #define TDE_DES_VCELB 0x08 #define TDE_DES_CEEMS_MASK 0x06 #define TDE_DES_RDMD 0x01 uint8_t enc_params_kad_format; uint8_t asdk_count[2]; uint8_t reserved[8]; uint8_t key_assoc_data_desc[]; }; /* * Tape Data Encryption Next Block Encryption Status page (0x0021). */ struct tde_next_block_enc_status_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t logical_obj_number[8]; uint8_t status; #define TDE_NBES_COMP_STATUS_MASK 0xf0 #define TDE_NBES_COMP_INCAPABLE 0x00 #define TDE_NBES_COMP_NOT_YET 0x10 #define TDE_NBES_COMP_NOT_A_BLOCK 0x20 #define TDE_NBES_COMP_NOT_COMPRESSED 0x30 #define TDE_NBES_COMP_COMPRESSED 0x40 #define TDE_NBES_ENC_STATUS_MASK 0x0f #define TDE_NBES_ENC_INCAPABLE 0x00 #define TDE_NBES_ENC_NOT_YET 0x01 #define TDE_NBES_ENC_NOT_A_BLOCK 0x02 #define TDE_NBES_ENC_NOT_ENCRYPTED 0x03 #define TDE_NBES_ENC_ALG_NOT_SUPPORTED 0x04 #define TDE_NBES_ENC_SUPPORTED_ALG 0x05 #define TDE_NBES_ENC_NO_KEY 0x06 uint8_t algo_index; uint8_t byte14; #define TDE_NBES_EMES 0x02 #define TDE_NBES_RDMDS 0x01 uint8_t next_block_kad_format; uint8_t key_assoc_data_desc[]; }; /* * Tape Data Encryption Get Encryption Management Attributes page (0x0022). */ struct tde_get_enc_man_attr_page { uint8_t page_code[2]; uint8_t reserved[3]; uint8_t byte5; #define TDE_GEMA_CAOD 0x01 uint8_t page_length[2]; uint8_t enc_mgmt_attr_desc[]; }; /* * Tape Data Encryption Random Number page (0x0030). */ struct tde_random_num_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t random_number[32]; }; /* * Tape Data Encryption Device Server Key Wrapping Public Key page (0x0031). */ struct tde_key_wrap_pk_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t public_key_type[4]; uint8_t public_key_format[4]; uint8_t public_key_length[2]; uint8_t public_key[]; }; /* * Security Protocol Specific values for the Tape Data Encryption protocol * (0x20) used with SECURITY PROTOCOL OUT. See above for values used with * SECURITY PROTOCOL IN. Current as of SSCr03. */ #define TDE_SET_DATA_ENC_PAGE 0x0010 #define TDE_SA_ENCAP_PAGE 0x0011 #define TDE_SET_ENC_MGMT_ATTR_PAGE 0x0022 /* * Tape Data Encryption Set Data Encryption page (0x0010). */ struct tde_set_data_enc_page { uint8_t page_code[2]; uint8_t page_length[2]; uint8_t byte4; #define TDE_SDE_SCOPE_MASK 0xe0 #define TDE_SDE_SCOPE_ALL_IT_NEXUS 0x80 #define TDE_SDE_SCOPE_LOCAL 0x40 #define TDE_SDE_SCOPE_PUBLIC 0x00 #define TDE_SDE_LOCK 0x01 uint8_t byte5; #define TDE_SDE_CEEM_MASK 0xc0 #define TDE_SDE_CEEM_ENCRYPT 0xc0 #define TDE_SDE_CEEM_EXTERNAL 0x80 #define TDE_SDE_CEEM_NO_CHECK 0x40 #define TDE_SDE_RDMC_MASK 0x30 #define TDE_SDE_RDMC_DISABLED 0x30 #define TDE_SDE_RDMC_ENABLED 0x20 #define TDE_SDE_RDMC_DEFAULT 0x00 #define TDE_SDE_SDK 0x08 #define TDE_SDE_CKOD 0x04 #define TDE_SDE_CKORP 0x02 #define TDE_SDE_CKORL 0x01 uint8_t encryption_mode; #define TDE_SDE_ENC_MODE_DISABLE 0x00 #define TDE_SDE_ENC_MODE_EXTERNAL 0x01 #define TDE_SDE_ENC_MODE_ENCRYPT 0x02 uint8_t decryption_mode; #define TDE_SDE_DEC_MODE_DISABLE 0x00 #define TDE_SDE_DEC_MODE_RAW 0x01 #define TDE_SDE_DEC_MODE_DECRYPT 0x02 #define TDE_SDE_DEC_MODE_MIXED 0x03 uint8_t algo_index; uint8_t lbe_key_format; #define TDE_SDE_KEY_PLAINTEXT 0x00 #define TDE_SDE_KEY_VENDOR_SPEC 0x01 #define TDE_SDE_KEY_PUBLIC_WRAP 0x02 #define TDE_SDE_KEY_ESP_SCSI 0x03 uint8_t kad_format; #define TDE_SDE_KAD_ASCII 0x02 #define TDE_SDE_KAD_BINARY 0x01 #define TDE_SDE_KAD_UNSPECIFIED 0x00 uint8_t reserved[7]; uint8_t lbe_key_length[2]; uint8_t lbe_key[]; }; /* * Used for the Vendor Specific key format (0x01). */ struct tde_key_format_vendor { uint8_t t10_vendor_id[8]; uint8_t vendor_key[]; }; /* * Used for the public key wrapped format (0x02). */ struct tde_key_format_public_wrap { uint8_t parameter_set[2]; #define TDE_PARAM_SET_RSA2048 0x0000 #define TDE_PARAM_SET_ECC521 0x0010 uint8_t label_length[2]; uint8_t label[]; }; /* * Tape Data Encryption SA Encapsulation page (0x0011). */ struct tde_sa_encap_page { uint8_t page_code[2]; uint8_t data_desc[]; }; /* * Tape Data Encryption Set Encryption Management Attributes page (0x0022). */ struct tde_set_enc_mgmt_attr_page { uint8_t page_code[2]; uint8_t reserved[3]; uint8_t byte5; #define TDE_SEMA_CAOD 0x01 uint8_t page_length[2]; uint8_t attr_desc[]; }; /* * Tape Data Encryption descriptor format. * SSC4r03 Section 8.5.4.2.1 Table 197 */ struct tde_data_enc_desc { uint8_t key_desc_type; #define TDE_KEY_DESC_WK_KAD 0x04 #define TDE_KEY_DESC_M_KAD 0x03 #define TDE_KEY_DESC_NONCE_VALUE 0x02 #define TDE_KEY_DESC_A_KAD 0x01 #define TDE_KEY_DESC_U_KAD 0x00 uint8_t byte2; #define TDE_KEY_DESC_AUTH_MASK 0x07 #define TDE_KEY_DESC_AUTH_FAILED 0x04 #define TDE_KEY_DESC_AUTH_SUCCESS 0x03 #define TDE_KEY_DESC_AUTH_NO_ATTEMPT 0x02 #define TDE_KEY_DESC_AUTH_U_KAD 0x01 uint8_t key_desc_length[2]; uint8_t key_desc[]; }; /* * Wrapped Key descriptor format. * SSC4r03 Section 8.5.4.3.1 Table 200 */ struct tde_wrapped_key_desc { uint8_t wrapped_key_type; #define TDE_WRAP_KEY_DESC_LENGTH 0x04 #define TDE_WRAP_KEY_DESC_IDENT 0x03 #define TDE_WRAP_KEY_DESC_INFO 0x02 #define TDE_WRAP_KEY_DESC_ENTITY_ID 0x01 #define TDE_WRAP_KEY_DESC_DEVICE_ID 0x00 uint8_t reserved; uint8_t wrapped_desc_length[2]; uint8_t wrapped_desc[]; }; /* * Encryption management attributes descriptor format. * SSC4r03 Section 8.5.4.4.1 Table 202 */ struct tde_enc_mgmt_attr_desc { uint8_t enc_mgmt_attr_type[2]; #define TDE_EMAD_DESIRED_KEY_MGR_OP 0x0000 #define TDE_EMAD_LOG_BLOCK_ENC_KEY_CRIT 0x0001 #define TDE_EMAD_LOG_BLOCK_ENC_KEY_WRAP 0x0002 uint8_t reserved; uint8_t byte2; #define TDE_EMAD_CRIT 0x80 uint8_t attr_length[2]; uint8_t attributes[]; #define TDE_EMAD_DESIRED_KEY_CREATE 0x0001 #define TDE_EMAD_DESIRED_KEY_RESOLVE 0x0002 }; /* * Logical block encryption key selection criteria descriptor format. * SSC4r03 Section 8.5.4.4.3.1 Table 206 */ struct tde_lb_enc_key_sel_desc { uint8_t lbe_key_sel_crit_type[2]; /* * The CRIT bit is the top bit of the first byte of the type. */ #define TDE_LBE_KEY_SEL_CRIT 0x80 #define TDE_LBE_KEY_SEL_ALGO 0x0001 #define TDE_LBE_KEY_SEL_ID 0x0002 uint8_t lbe_key_sel_crit_length[2]; uint8_t lbe_key_sel_crit[]; }; /* * Logical block encryption key wrapping attribute descriptor format. * SSC4r03 Section 8.5.4.4.4.1 Table 209 */ struct tde_lb_enc_key_wrap_desc { uint8_t lbe_key_wrap_type[2]; /* * The CRIT bit is the top bit of the first byte of the type. */ #define TDE_LBE_KEY_WRAP_CRIT 0x80 #define TDE_LBE_KEY_WRAP_KEKS 0x0001 uint8_t lbe_key_wrap_length[2]; uint8_t lbe_key_wrap_attr[]; }; /* * Opcodes */ #define REWIND 0x01 #define FORMAT_MEDIUM 0x04 #define READ_BLOCK_LIMITS 0x05 #define SA_READ 0x08 #define SA_WRITE 0x0A #define SET_CAPACITY 0x0B #define WRITE_FILEMARKS 0x10 #define SPACE 0x11 #define RESERVE_UNIT 0x16 #define RELEASE_UNIT 0x17 #define ERASE 0x19 #define LOAD_UNLOAD 0x1B #define LOCATE 0x2B #define READ_POSITION 0x34 #define REPORT_DENSITY_SUPPORT 0x44 #define ALLOW_OVERWRITE 0x82 #define LOCATE_16 0x92 /* * Tape specific density codes- only enough of them here to recognize * some specific older units so we can choose 2FM@EOD or FIXED blocksize * quirks. */ #define SCSI_DENSITY_HALFINCH_800 0x01 #define SCSI_DENSITY_HALFINCH_1600 0x02 #define SCSI_DENSITY_HALFINCH_6250 0x03 #define SCSI_DENSITY_HALFINCH_6250C 0xC3 /* HP Compressed 6250 */ #define SCSI_DENSITY_QIC_11_4TRK 0x04 #define SCSI_DENSITY_QIC_11_9TRK 0x84 /* Vendor Unique Emulex */ #define SCSI_DENSITY_QIC_24 0x05 #define SCSI_DENSITY_HALFINCH_PE 0x06 #define SCSI_DENSITY_QIC_120 0x0f #define SCSI_DENSITY_QIC_150 0x10 #define SCSI_DENSITY_QIC_525_320 0x11 #define SCSI_DENSITY_QIC_1320 0x12 #define SCSI_DENSITY_QIC_2GB 0x22 #define SCSI_DENSITY_QIC_4GB 0x26 #define SCSI_DENSITY_QIC_3080 0x29 __BEGIN_DECLS void scsi_read_block_limits(struct ccb_scsiio *, u_int32_t, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t, struct scsi_read_block_limits_data *, u_int8_t , u_int32_t); void scsi_sa_read_write(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int readop, int sli, int fixed, u_int32_t length, u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, u_int32_t timeout); void scsi_rewind(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int immediate, u_int8_t sense_len, u_int32_t timeout); void scsi_space(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, scsi_space_code code, u_int32_t count, u_int8_t sense_len, u_int32_t timeout); void scsi_load_unload(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int immediate, int eot, int reten, int load, u_int8_t sense_len, u_int32_t timeout); void scsi_write_filemarks(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int immediate, int setmark, u_int32_t num_marks, u_int8_t sense_len, u_int32_t timeout); void scsi_reserve_release_unit(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int third_party, int third_party_id, u_int8_t sense_len, u_int32_t timeout, int reserve); void scsi_erase(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int immediate, int long_erase, u_int8_t sense_len, u_int32_t timeout); void scsi_data_comp_page(struct scsi_data_compression_page *page, u_int8_t dce, u_int8_t dde, u_int8_t red, u_int32_t comp_algorithm, u_int32_t decomp_algorithm); void scsi_read_position(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int hardsoft, struct scsi_tape_position_data *sbp, u_int8_t sense_len, u_int32_t timeout); void scsi_read_position_10(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int service_action, u_int8_t *data_ptr, u_int32_t length, u_int32_t sense_len, u_int32_t timeout); void scsi_set_position(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int hardsoft, u_int32_t blkno, u_int8_t sense_len, u_int32_t timeout); void scsi_locate_10(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int immed, int cp, int hard, int64_t partition, u_int32_t block_address, int sense_len, u_int32_t timeout); void scsi_locate_16(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int immed, int cp, u_int8_t dest_type, int bam, int64_t partition, u_int64_t logical_id, int sense_len, u_int32_t timeout); void scsi_report_density_support(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int media, int medium_type, u_int8_t *data_ptr, u_int32_t length, u_int32_t sense_len, u_int32_t timeout); void scsi_set_capacity(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int byte1, u_int32_t proportion, u_int32_t sense_len, u_int32_t timeout); void scsi_format_medium(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int byte1, int byte2, u_int8_t *data_ptr, u_int32_t length, u_int32_t sense_len, u_int32_t timeout); void scsi_allow_overwrite(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int allow_overwrite, int partition, u_int64_t logical_id, u_int32_t sense_len, u_int32_t timeout); __END_DECLS #endif /* _SCSI_SCSI_SA_H */ Index: head/usr.bin/mt/mt.c =================================================================== --- head/usr.bin/mt/mt.c (revision 280229) +++ head/usr.bin/mt/mt.c (revision 280230) @@ -1,1591 +1,1591 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /*- * Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * Authors: Ken Merry (Spectra Logic Corporation) */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1980, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)mt.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); /* * mt -- * magnetic tape manipulation program */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* the appropriate sections of are also #ifdef'd for FreeBSD */ /* c_flags */ #define NEED_2ARGS 0x01 #define ZERO_ALLOWED 0x02 #define IS_DENSITY 0x04 #define DISABLE_THIS 0x08 #define IS_COMP 0x10 #define USE_GETOPT 0x20 #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef MAX #define MAX(a, b) (a > b) ? a : b #endif typedef enum { MT_CMD_NONE = MTLOAD + 1, MT_CMD_PROTECT, MT_CMD_GETDENSITY } mt_commands; static const struct commands { const char *c_name; unsigned long c_code; int c_ronly; int c_flags; } com[] = { { "bsf", MTBSF, 1, 0 }, { "bsr", MTBSR, 1, 0 }, /* XXX FreeBSD considered "eof" dangerous, since it's being confused with "eom" (and is an alias for "weof" anyway) */ { "eof", MTWEOF, 0, DISABLE_THIS }, { "fsf", MTFSF, 1, 0 }, { "fsr", MTFSR, 1, 0 }, { "offline", MTOFFL, 1, 0 }, { "load", MTLOAD, 1, 0 }, { "rewind", MTREW, 1, 0 }, { "rewoffl", MTOFFL, 1, 0 }, { "ostatus", MTNOP, 1, 0 }, { "weof", MTWEOF, 0, ZERO_ALLOWED }, { "weofi", MTWEOFI, 0, ZERO_ALLOWED }, { "erase", MTERASE, 0, ZERO_ALLOWED}, { "blocksize", MTSETBSIZ, 0, NEED_2ARGS|ZERO_ALLOWED }, { "density", MTSETDNSTY, 0, NEED_2ARGS|ZERO_ALLOWED|IS_DENSITY }, { "eom", MTEOD, 1, 0 }, { "eod", MTEOD, 1, 0 }, { "smk", MTWSS, 0, 0 }, { "wss", MTWSS, 0, 0 }, { "fss", MTFSS, 1, 0 }, { "bss", MTBSS, 1, 0 }, { "comp", MTCOMP, 0, NEED_2ARGS|ZERO_ALLOWED|IS_COMP }, { "retension", MTRETENS, 1, 0 }, { "rdhpos", MTIOCRDHPOS, 0, 0 }, { "rdspos", MTIOCRDSPOS, 0, 0 }, { "sethpos", MTIOCHLOCATE, 0, NEED_2ARGS|ZERO_ALLOWED }, { "setspos", MTIOCSLOCATE, 0, NEED_2ARGS|ZERO_ALLOWED }, { "errstat", MTIOCERRSTAT, 0, 0 }, { "setmodel", MTIOCSETEOTMODEL, 0, NEED_2ARGS|ZERO_ALLOWED }, { "seteotmodel", MTIOCSETEOTMODEL, 0, NEED_2ARGS|ZERO_ALLOWED }, { "getmodel", MTIOCGETEOTMODEL, 0, 0 }, { "geteotmodel", MTIOCGETEOTMODEL, 0, 0 }, { "rblim", MTIOCRBLIM, 0, 0}, { "getdensity", MT_CMD_GETDENSITY, 0, USE_GETOPT}, { "status", MTIOCEXTGET, 0, USE_GETOPT }, { "locate", MTIOCEXTLOCATE, 0, USE_GETOPT }, { "param", MTIOCPARAMGET, 0, USE_GETOPT }, { "protect", MT_CMD_PROTECT, 0, USE_GETOPT }, { NULL, 0, 0, 0 } }; static const char *getblksiz(int); static void printreg(const char *, u_int, const char *); static void status(struct mtget *); static void usage(void); const char *get_driver_state_str(int dsreg); static void st_status (struct mtget *); static int mt_locate(int argc, char **argv, int mtfd, const char *tape); static int nstatus_print(int argc, char **argv, char *xml_str, struct mt_status_data *status_data); static int mt_xml_cmd(unsigned long cmd, int argc, char **argv, int mtfd, const char *tape); static int mt_print_density_entry(struct mt_status_entry *density_root, int indent); static int mt_print_density_report(struct mt_status_entry *report_root, int indent); static int mt_print_density(struct mt_status_entry *density_root, int indent); static int mt_getdensity(int argc, char **argv, char *xml_str, struct mt_status_data *status_data); static int mt_set_param(int mtfd, struct mt_status_data *status_data, char *param_name, char *param_value); static int mt_protect(int argc, char **argv, int mtfd, struct mt_status_data *status_data); static int mt_param(int argc, char **argv, int mtfd, char *xml_str, struct mt_status_data *status_data); static const char *denstostring (int d); static u_int32_t stringtocomp(const char *s); static const char *comptostring(u_int32_t comp); static void warn_eof(void); int main(int argc, char *argv[]) { const struct commands *comp; struct mtget mt_status; struct mtop mt_com; int ch, len, mtfd; const char *p, *tape; bzero(&mt_com, sizeof(mt_com)); if ((tape = getenv("TAPE")) == NULL) tape = DEFTAPE; while ((ch = getopt(argc, argv, "f:t:")) != -1) switch(ch) { case 'f': case 't': tape = optarg; break; case '?': usage(); break; default: break; } argc -= optind; argv += optind; if (argc < 1) usage(); len = strlen(p = *argv++); for (comp = com;; comp++) { if (comp->c_name == NULL) errx(1, "%s: unknown command", p); if (strncmp(p, comp->c_name, len) == 0) break; } if((comp->c_flags & NEED_2ARGS) && argc != 2) usage(); if(comp->c_flags & DISABLE_THIS) { warn_eof(); } if (comp->c_flags & USE_GETOPT) { argc--; optind = 0; } if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0) err(1, "%s", tape); if (comp->c_code != MTNOP) { mt_com.mt_op = comp->c_code; if (*argv) { if (!isdigit(**argv) && (comp->c_flags & IS_DENSITY)) { const char *dcanon; mt_com.mt_count = mt_density_num(*argv); if (mt_com.mt_count == 0) errx(1, "%s: unknown density", *argv); dcanon = denstostring(mt_com.mt_count); if (strcmp(dcanon, *argv) != 0) printf( "Using \"%s\" as an alias for %s\n", *argv, dcanon); p = ""; } else if (!isdigit(**argv) && (comp->c_flags & IS_COMP)) { mt_com.mt_count = stringtocomp(*argv); if ((u_int32_t)mt_com.mt_count == 0xf0f0f0f0) errx(1, "%s: unknown compression", *argv); p = ""; } else if ((comp->c_flags & USE_GETOPT) == 0) { char *q; /* allow for hex numbers; useful for density */ mt_com.mt_count = strtol(*argv, &q, 0); p = q; } if (((comp->c_flags & USE_GETOPT) == 0) && (((mt_com.mt_count <= ((comp->c_flags & ZERO_ALLOWED)? -1: 0)) && ((comp->c_flags & IS_COMP) == 0)) || *p)) errx(1, "%s: illegal count", *argv); } else mt_com.mt_count = 1; switch (comp->c_code) { case MTIOCERRSTAT: { unsigned int i; union mterrstat umn; struct scsi_tape_errors *s = &umn.scsi_errstat; if (ioctl(mtfd, comp->c_code, (caddr_t)&umn) < 0) err(2, "%s", tape); (void)printf("Last I/O Residual: %u\n", s->io_resid); (void)printf(" Last I/O Command:"); for (i = 0; i < sizeof (s->io_cdb); i++) (void)printf(" %02X", s->io_cdb[i]); (void)printf("\n"); (void)printf(" Last I/O Sense:\n\n\t"); for (i = 0; i < sizeof (s->io_sense); i++) { (void)printf(" %02X", s->io_sense[i]); if (((i + 1) & 0xf) == 0) { (void)printf("\n\t"); } } (void)printf("\n"); (void)printf("Last Control Residual: %u\n", s->ctl_resid); (void)printf(" Last Control Command:"); for (i = 0; i < sizeof (s->ctl_cdb); i++) (void)printf(" %02X", s->ctl_cdb[i]); (void)printf("\n"); (void)printf(" Last Control Sense:\n\n\t"); for (i = 0; i < sizeof (s->ctl_sense); i++) { (void)printf(" %02X", s->ctl_sense[i]); if (((i + 1) & 0xf) == 0) { (void)printf("\n\t"); } } (void)printf("\n\n"); exit(0); /* NOTREACHED */ } case MTIOCRDHPOS: case MTIOCRDSPOS: { u_int32_t block; if (ioctl(mtfd, comp->c_code, (caddr_t)&block) < 0) err(2, "%s", tape); (void)printf("%s: %s block location %u\n", tape, (comp->c_code == MTIOCRDHPOS)? "hardware" : "logical", block); exit(0); /* NOTREACHED */ } case MTIOCSLOCATE: case MTIOCHLOCATE: { u_int32_t block = (u_int32_t)mt_com.mt_count; if (ioctl(mtfd, comp->c_code, (caddr_t)&block) < 0) err(2, "%s", tape); exit(0); /* NOTREACHED */ } case MTIOCGETEOTMODEL: { u_int32_t om; if (ioctl(mtfd, MTIOCGETEOTMODEL, (caddr_t)&om) < 0) err(2, "%s", tape); (void)printf("%s: the model is %u filemar%s at EOT\n", tape, om, (om > 1)? "ks" : "k"); exit(0); /* NOTREACHED */ } case MTIOCSETEOTMODEL: { u_int32_t om, nm = (u_int32_t)mt_com.mt_count; if (ioctl(mtfd, MTIOCGETEOTMODEL, (caddr_t)&om) < 0) err(2, "%s", tape); if (ioctl(mtfd, comp->c_code, (caddr_t)&nm) < 0) err(2, "%s", tape); (void)printf("%s: old model was %u filemar%s at EOT\n", tape, om, (om > 1)? "ks" : "k"); (void)printf("%s: new model is %u filemar%s at EOT\n", tape, nm, (nm > 1)? "ks" : "k"); exit(0); /* NOTREACHED */ } case MTIOCRBLIM: { struct mtrblim rblim; bzero(&rblim, sizeof(rblim)); if (ioctl(mtfd, MTIOCRBLIM, (caddr_t)&rblim) < 0) err(2, "%s", tape); (void)printf("%s: min blocksize %u bytes, " "max blocksize %u bytes, granularity %u bytes\n", tape, rblim.min_block_length, rblim.max_block_length, rblim.granularity); exit(0); /* NOTREACHED */ } case MTIOCPARAMGET: case MTIOCEXTGET: case MT_CMD_PROTECT: case MT_CMD_GETDENSITY: { int retval = 0; retval = mt_xml_cmd(comp->c_code, argc, argv, mtfd, tape); exit(retval); } case MTIOCEXTLOCATE: { int retval = 0; retval = mt_locate(argc, argv, mtfd, tape); exit(retval); } default: break; } if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) err(1, "%s: %s", tape, comp->c_name); } else { if (ioctl(mtfd, MTIOCGET, &mt_status) < 0) err(1, NULL); status(&mt_status); } exit(0); /* NOTREACHED */ } static const struct tape_desc { short t_type; /* type of magtape device */ const char *t_name; /* printing name */ const char *t_dsbits; /* "drive status" register */ const char *t_erbits; /* "error" register */ } tapes[] = { { MT_ISAR, "SCSI tape drive", 0, 0 }, { 0, NULL, 0, 0 } }; /* * Interpret the status buffer returned */ static void status(struct mtget *bp) { const struct tape_desc *mt; for (mt = tapes;; mt++) { if (mt->t_type == 0) { (void)printf("%d: unknown tape drive type\n", bp->mt_type); return; } if (mt->t_type == bp->mt_type) break; } if(mt->t_type == MT_ISAR) st_status(bp); else { (void)printf("%s tape drive, residual=%d\n", mt->t_name, bp->mt_resid); printreg("ds", (unsigned short)bp->mt_dsreg, mt->t_dsbits); printreg("\ner", (unsigned short)bp->mt_erreg, mt->t_erbits); (void)putchar('\n'); } } /* * Print a register a la the %b format of the kernel's printf. */ static void printreg(const char *s, u_int v, const char *bits) { int i, any = 0; char c; if (bits && *bits == 8) printf("%s=%o", s, v); else printf("%s=%x", s, v); if (!bits) return; bits++; if (v && bits) { putchar('<'); while ((i = *bits++)) { if (v & (1 << (i-1))) { if (any) putchar(','); any = 1; for (; (c = *bits) > 32; bits++) putchar(c); } else for (; *bits > 32; bits++) ; } putchar('>'); } } static void usage(void) { (void)fprintf(stderr, "usage: mt [-f device] command [count]\n"); exit(1); } static const struct compression_types { u_int32_t comp_number; const char *name; } comp_types[] = { { 0x00, "none" }, { 0x00, "off" }, { 0x10, "IDRC" }, { 0x20, "DCLZ" }, { 0xffffffff, "enable" }, { 0xffffffff, "on" }, { 0xf0f0f0f0, NULL} }; static const char * denstostring(int d) { static char buf[20]; const char *name = mt_density_name(d); if (name == NULL) sprintf(buf, "0x%02x", d); else sprintf(buf, "0x%02x:%s", d, name); return buf; } static const char * getblksiz(int bs) { static char buf[25]; if (bs == 0) return "variable"; else { sprintf(buf, "%d bytes", bs); return buf; } } static const char * comptostring(u_int32_t comp) { static char buf[20]; const struct compression_types *ct; if (comp == MT_COMP_DISABLED) return "disabled"; else if (comp == MT_COMP_UNSUPP) return "unsupported"; for (ct = comp_types; ct->name; ct++) if (ct->comp_number == comp) break; if (ct->comp_number == 0xf0f0f0f0) { sprintf(buf, "0x%x", comp); return(buf); } else return(ct->name); } static u_int32_t stringtocomp(const char *s) { const struct compression_types *ct; size_t l = strlen(s); for (ct = comp_types; ct->name; ct++) if (strncasecmp(ct->name, s, l) == 0) break; return(ct->comp_number); } static struct driver_state { int dsreg; const char *desc; } driver_states[] = { { MTIO_DSREG_REST, "at rest" }, { MTIO_DSREG_RBSY, "Communicating with drive" }, { MTIO_DSREG_WR, "Writing" }, { MTIO_DSREG_FMK, "Writing Filemarks" }, { MTIO_DSREG_ZER, "Erasing" }, { MTIO_DSREG_RD, "Reading" }, { MTIO_DSREG_FWD, "Spacing Forward" }, { MTIO_DSREG_REV, "Spacing Reverse" }, { MTIO_DSREG_POS, "Hardware Positioning (direction unknown)" }, { MTIO_DSREG_REW, "Rewinding" }, { MTIO_DSREG_TEN, "Retensioning" }, { MTIO_DSREG_UNL, "Unloading" }, { MTIO_DSREG_LD, "Loading" }, }; const char * get_driver_state_str(int dsreg) { unsigned int i; for (i = 0; i < (sizeof(driver_states)/sizeof(driver_states[0])); i++) { if (driver_states[i].dsreg == dsreg) return (driver_states[i].desc); } return (NULL); } static void st_status(struct mtget *bp) { printf("Mode Density Blocksize bpi " "Compression\n" "Current: %-17s %-12s %-7d %s\n" "---------available modes---------\n" "0: %-17s %-12s %-7d %s\n" "1: %-17s %-12s %-7d %s\n" "2: %-17s %-12s %-7d %s\n" "3: %-17s %-12s %-7d %s\n", denstostring(bp->mt_density), getblksiz(bp->mt_blksiz), mt_density_bp(bp->mt_density, TRUE), comptostring(bp->mt_comp), denstostring(bp->mt_density0), getblksiz(bp->mt_blksiz0), mt_density_bp(bp->mt_density0, TRUE), comptostring(bp->mt_comp0), denstostring(bp->mt_density1), getblksiz(bp->mt_blksiz1), mt_density_bp(bp->mt_density1, TRUE), comptostring(bp->mt_comp1), denstostring(bp->mt_density2), getblksiz(bp->mt_blksiz2), mt_density_bp(bp->mt_density2, TRUE), comptostring(bp->mt_comp2), denstostring(bp->mt_density3), getblksiz(bp->mt_blksiz3), mt_density_bp(bp->mt_density3, TRUE), comptostring(bp->mt_comp3)); if (bp->mt_dsreg != MTIO_DSREG_NIL) { const char sfmt[] = "Current Driver State: %s.\n"; printf("---------------------------------\n"); const char *state_str; state_str = get_driver_state_str(bp->mt_dsreg); if (state_str == NULL) { char foo[32]; (void) sprintf(foo, "Unknown state 0x%x", bp->mt_dsreg); printf(sfmt, foo); } else { printf(sfmt, state_str); } } if (bp->mt_resid == 0 && bp->mt_fileno == (daddr_t) -1 && bp->mt_blkno == (daddr_t) -1) return; printf("---------------------------------\n"); printf("File Number: %d\tRecord Number: %d\tResidual Count %d\n", bp->mt_fileno, bp->mt_blkno, bp->mt_resid); } static int mt_locate(int argc, char **argv, int mtfd, const char *tape) { struct mtlocate mtl; uint64_t logical_id = 0; mt_locate_dest_type dest_type = MT_LOCATE_DEST_FILE; int eod = 0, explicit = 0, immediate = 0; int64_t partition = 0; int block_addr_set = 0, partition_set = 0, file_set = 0, set_set = 0; int c, retval; retval = 0; bzero(&mtl, sizeof(mtl)); while ((c = getopt(argc, argv, "b:eEf:ip:s:")) != -1) { switch (c) { case 'b': /* Block address */ logical_id = strtoull(optarg, NULL, 0); dest_type = MT_LOCATE_DEST_OBJECT; block_addr_set = 1; break; case 'e': /* end of data */ eod = 1; dest_type = MT_LOCATE_DEST_EOD; break; case 'E': /* * XXX KDM explicit address mode. Should we even * allow this, since the driver doesn't operate in * explicit address mode? */ explicit = 1; break; case 'f': /* file number */ logical_id = strtoull(optarg, NULL, 0); dest_type = MT_LOCATE_DEST_FILE; file_set = 1; break; case 'i': /* * Immediate address mode. XXX KDM do we want to * implement this? The other commands in the * tape driver will need to be able to handle this. */ immediate = 1; break; case 'p': /* * Change partition to the given partition. */ partition = strtol(optarg, NULL, 0); partition_set = 1; break; case 's': /* Go to the given set mark */ logical_id = strtoull(optarg, NULL, 0); dest_type = MT_LOCATE_DEST_SET; set_set = 1; break; default: break; } } /* * These options are mutually exclusive. The user may only specify * one. */ if ((block_addr_set + file_set + eod + set_set) != 1) errx(1, "You must specify only one of -b, -f, -e, or -s"); mtl.dest_type = dest_type; switch (dest_type) { case MT_LOCATE_DEST_OBJECT: case MT_LOCATE_DEST_FILE: case MT_LOCATE_DEST_SET: mtl.logical_id = logical_id; break; case MT_LOCATE_DEST_EOD: break; } if (immediate != 0) mtl.flags |= MT_LOCATE_FLAG_IMMED; if (partition_set != 0) { mtl.flags |= MT_LOCATE_FLAG_CHANGE_PART; mtl.partition = partition; } if (explicit != 0) mtl.block_address_mode = MT_LOCATE_BAM_EXPLICIT; else mtl.block_address_mode = MT_LOCATE_BAM_IMPLICIT; if (ioctl(mtfd, MTIOCEXTLOCATE, &mtl) == -1) err(1, "MTIOCEXTLOCATE ioctl failed on %s", tape); return (retval); } typedef enum { MT_PERIPH_NAME = 0, MT_UNIT_NUMBER = 1, MT_VENDOR = 2, MT_PRODUCT = 3, MT_REVISION = 4, MT_COMPRESSION_SUPPORTED = 5, MT_COMPRESSION_ENABLED = 6, MT_COMPRESSION_ALGORITHM = 7, MT_MEDIA_DENSITY = 8, MT_MEDIA_BLOCKSIZE = 9, MT_CALCULATED_FILENO = 10, MT_CALCULATED_REL_BLKNO = 11, MT_REPORTED_FILENO = 12, MT_REPORTED_BLKNO = 13, MT_PARTITION = 14, MT_BOP = 15, MT_EOP = 16, MT_BPEW = 17, MT_DSREG = 18, MT_RESID = 19, MT_FIXED_MODE = 20, MT_SERIAL_NUM = 21, MT_MAXIO = 22, MT_CPI_MAXIO = 23, MT_MAX_BLK = 24, MT_MIN_BLK = 25, MT_BLK_GRAN = 26, MT_MAX_EFF_IOSIZE = 27 } status_item_index; static struct mt_status_items { const char *name; struct mt_status_entry *entry; } req_status_items[] = { { "periph_name", NULL }, { "unit_number", NULL }, { "vendor", NULL }, { "product", NULL }, { "revision", NULL }, { "compression_supported", NULL }, { "compression_enabled", NULL }, { "compression_algorithm", NULL }, { "media_density", NULL }, { "media_blocksize", NULL }, { "calculated_fileno", NULL }, { "calculated_rel_blkno", NULL }, { "reported_fileno", NULL }, { "reported_blkno", NULL }, { "partition", NULL }, { "bop", NULL }, { "eop", NULL }, { "bpew", NULL }, { "dsreg", NULL }, { "residual", NULL }, { "fixed_mode", NULL }, { "serial_num", NULL }, { "maxio", NULL }, { "cpi_maxio", NULL }, { "max_blk", NULL }, { "min_blk", NULL }, { "blk_gran", NULL }, { "max_effective_iosize", NULL } }; int nstatus_print(int argc, char **argv, char *xml_str, struct mt_status_data *status_data) { unsigned int i; int64_t calculated_fileno, calculated_rel_blkno; int64_t rep_fileno, rep_blkno, partition, resid; char block_str[32]; const char *dens_str; int dsreg, bop, eop, bpew; int xml_dump = 0; size_t dens_len; unsigned int field_width; int verbose = 0; int c; while ((c = getopt(argc, argv, "xv")) != -1) { switch (c) { case 'x': xml_dump = 1; break; case 'v': verbose = 1; break; default: break; } } if (xml_dump != 0) { printf("%s", xml_str); return (0); } for (i = 0; i < (sizeof(req_status_items)/sizeof(req_status_items[0])); i++) { char *name; name = __DECONST(char *, req_status_items[i].name); req_status_items[i].entry = mt_status_entry_find(status_data, name); if (req_status_items[i].entry == NULL) { errx(1, "Cannot find status entry %s", req_status_items[i].name); } } printf("Drive: %s%ju: <%s %s %s> Serial Number: %s\n", req_status_items[MT_PERIPH_NAME].entry->value, (uintmax_t)req_status_items[MT_UNIT_NUMBER].entry->value_unsigned, req_status_items[MT_VENDOR].entry->value, req_status_items[MT_PRODUCT].entry->value, req_status_items[MT_REVISION].entry->value, (req_status_items[MT_SERIAL_NUM].entry->value) ? req_status_items[MT_SERIAL_NUM].entry->value : "none"); printf("---------------------------------\n"); /* * We check to see whether we're in fixed mode or not, and don't * just believe the blocksize. If the SILI bit is turned on, the * blocksize will be set to 4, even though we're doing variable * length (well, multiples of 4) blocks. */ if (req_status_items[MT_FIXED_MODE].entry->value_signed == 0) snprintf(block_str, sizeof(block_str), "variable"); else snprintf(block_str, sizeof(block_str), "%s", getblksiz(req_status_items[ MT_MEDIA_BLOCKSIZE].entry->value_unsigned)); dens_str = denstostring(req_status_items[ MT_MEDIA_DENSITY].entry->value_unsigned); if (dens_str == NULL) dens_len = 0; else dens_len = strlen(dens_str); field_width = MAX(dens_len, 17); printf("Mode %-*s Blocksize bpi Compression\n" "Current: %-*s %-12s %-7d ", field_width, "Density", field_width, dens_str, block_str, mt_density_bp(req_status_items[ MT_MEDIA_DENSITY].entry->value_unsigned, TRUE)); if (req_status_items[MT_COMPRESSION_SUPPORTED].entry->value_signed == 0) printf("unsupported\n"); else if (req_status_items[ MT_COMPRESSION_ENABLED].entry->value_signed == 0) printf("disabled\n"); else { printf("enabled (%s)\n", comptostring(req_status_items[ MT_COMPRESSION_ALGORITHM].entry->value_unsigned)); } dsreg = req_status_items[MT_DSREG].entry->value_signed; if (dsreg != MTIO_DSREG_NIL) { const char sfmt[] = "Current Driver State: %s.\n"; printf("---------------------------------\n"); const char *state_str; state_str = get_driver_state_str(dsreg); if (state_str == NULL) { char foo[32]; (void) sprintf(foo, "Unknown state 0x%x", dsreg); printf(sfmt, foo); } else { printf(sfmt, state_str); } } resid = req_status_items[MT_RESID].entry->value_signed; calculated_fileno = req_status_items[ MT_CALCULATED_FILENO].entry->value_signed; calculated_rel_blkno = req_status_items[ MT_CALCULATED_REL_BLKNO].entry->value_signed; rep_fileno = req_status_items[ MT_REPORTED_FILENO].entry->value_signed; rep_blkno = req_status_items[ MT_REPORTED_BLKNO].entry->value_signed; bop = req_status_items[MT_BOP].entry->value_signed; eop = req_status_items[MT_EOP].entry->value_signed; bpew = req_status_items[MT_BPEW].entry->value_signed; partition = req_status_items[MT_PARTITION].entry->value_signed; printf("---------------------------------\n"); printf("Partition: %3jd Calc File Number: %3jd " " Calc Record Number: %jd\n" "Residual: %3jd Reported File Number: %3jd " "Reported Record Number: %jd\n", partition, calculated_fileno, calculated_rel_blkno, resid, rep_fileno, rep_blkno); printf("Flags: "); if (bop > 0 || eop > 0 || bpew > 0) { int need_comma = 0; if (bop > 0) { printf("BOP"); need_comma = 1; } if (eop > 0) { if (need_comma != 0) printf(","); printf("EOP"); need_comma = 1; } if (bpew > 0) { if (need_comma != 0) printf(","); printf("BPEW"); need_comma = 1; } } else { printf("None"); } printf("\n"); if (verbose != 0) { printf("---------------------------------\n"); printf("Tape I/O parameters:\n"); for (i = MT_MAXIO; i <= MT_MAX_EFF_IOSIZE; i++) { printf(" %s (%s): %ju bytes\n", req_status_items[i].entry->desc, req_status_items[i].name, req_status_items[i].entry->value_unsigned); } } return (0); } int mt_xml_cmd(unsigned long cmd, int argc, char **argv, int mtfd, const char *tape) { struct mt_status_data status_data; #if 0 struct mt_status_entry *entry; #endif char *xml_str; int retval; unsigned long ioctl_cmd; switch (cmd) { case MT_CMD_PROTECT: case MTIOCPARAMGET: ioctl_cmd = MTIOCPARAMGET; break; default: ioctl_cmd = MTIOCEXTGET; break; } retval = mt_get_xml_str(mtfd, ioctl_cmd, &xml_str); if (retval != 0) err(1, "Couldn't get mt XML string"); retval = mt_get_status(xml_str, &status_data); if (retval != XML_STATUS_OK) { warn("Couldn't get mt status for %s", tape); goto bailout; } /* * This gets set if there are memory allocation or other errors in * our parsing of the XML. */ if (status_data.error != 0) { warnx("%s", status_data.error_str); retval = 1; goto bailout; } #if 0 STAILQ_FOREACH(entry, &status_data.entries, links) mt_status_tree_print(entry, 0, NULL); #endif switch (cmd) { case MTIOCEXTGET: retval = nstatus_print(argc, argv, xml_str, &status_data); break; case MTIOCPARAMGET: retval = mt_param(argc, argv, mtfd, xml_str, &status_data); break; case MT_CMD_PROTECT: retval = mt_protect(argc, argv, mtfd, &status_data); break; case MT_CMD_GETDENSITY: retval = mt_getdensity(argc, argv, xml_str, &status_data); break; } bailout: if (xml_str != NULL) free(xml_str); mt_status_free(&status_data); return (retval); } static int mt_set_param(int mtfd, struct mt_status_data *status_data, char *param_name, char *param_value) { struct mt_status_entry *entry; struct mtparamset param_set; entry = mt_status_entry_find(status_data, __DECONST(char *, "mtparamget")); if (entry == NULL) errx(1, "Cannot find parameter root node"); bzero(¶m_set, sizeof(param_set)); entry = mt_entry_find(entry, param_name); if (entry == NULL) errx(1, "Unknown parameter name \"%s\"", param_name); strlcpy(param_set.value_name, param_name, sizeof(param_set.value_name)); switch (entry->var_type) { case MT_TYPE_INT: param_set.value.value_signed = strtoll(param_value, NULL, 0); param_set.value_type = MT_PARAM_SET_SIGNED; param_set.value_len = entry->size; break; case MT_TYPE_UINT: param_set.value.value_unsigned = strtoull(param_value, NULL, 0); param_set.value_type = MT_PARAM_SET_UNSIGNED; param_set.value_len = entry->size; break; case MT_TYPE_STRING: { size_t param_len; param_len = strlen(param_value) + 1; if (param_len > sizeof(param_set.value.value_fixed_str)) { param_set.value_type = MT_PARAM_SET_VAR_STR; param_set.value.value_var_str = param_value; } else { param_set.value_type = MT_PARAM_SET_FIXED_STR; strlcpy(param_set.value.value_fixed_str, param_value, sizeof(param_set.value.value_fixed_str)); } param_set.value_len = param_len; break; } default: errx(1, "Unknown parameter type %d for %s", entry->var_type, param_name); break; } if (ioctl(mtfd, MTIOCPARAMSET, ¶m_set) == -1) err(1, "MTIOCPARAMSET"); if (param_set.status != MT_PARAM_STATUS_OK) errx(1, "Failed to set %s: %s", param_name, param_set.error_str); return (0); } typedef enum { MT_PP_LBP_R, MT_PP_LBP_W, MT_PP_RBDP, MT_PP_PI_LENGTH, MT_PP_PROT_METHOD } mt_protect_param; static struct mt_protect_info { const char *name; struct mt_status_entry *entry; uint32_t value; } mt_protect_list[] = { { "lbp_r", NULL, 0 }, { "lbp_w", NULL, 0 }, { "rbdp", NULL, 0 }, { "pi_length", NULL, 0 }, { "prot_method", NULL, 0 } }; #define MT_NUM_PROTECT_PARAMS (sizeof(mt_protect_list)/sizeof(mt_protect_list[0])) #define MT_PROT_NAME "protection" static int mt_protect(int argc, char **argv, int mtfd, struct mt_status_data *status_data) { int retval = 0; int do_enable = 0, do_disable = 0, do_list = 0; int rbdp_set = 0, lbp_w_set = 0, lbp_r_set = 0; int prot_method_set = 0, pi_length_set = 0; int verbose = 0; uint32_t rbdp = 0, lbp_w = 0, lbp_r = 0; uint32_t prot_method = 0, pi_length = 0; struct mt_status_entry *prot_entry, *supported_entry; struct mt_status_entry *entry; struct mtparamset params[MT_NUM_PROTECT_PARAMS]; struct mtsetlist param_list; unsigned int i; int c; while ((c = getopt(argc, argv, "b:delL:m:r:vw:")) != -1) { switch (c) { case 'b': rbdp_set = 1; rbdp = strtoul(optarg, NULL, 0); if ((rbdp != 0) && (rbdp != 1)) errx(1, "valid values for -b are 0 and 1"); break; case 'd': do_disable = 1; break; case 'e': do_enable = 1; break; case 'l': do_list = 1; break; case 'L': pi_length_set = 1; pi_length = strtoul(optarg, NULL, 0); if (pi_length > SA_CTRL_DP_PI_LENGTH_MASK) errx(1, "PI length %u > maximum %u", pi_length, SA_CTRL_DP_PI_LENGTH_MASK); break; case 'm': prot_method_set = 1; prot_method = strtoul(optarg, NULL, 0); if (prot_method > SA_CTRL_DP_METHOD_MAX) errx(1, "Method %u > maximum %u", prot_method, SA_CTRL_DP_METHOD_MAX); break; case 'r': lbp_r_set = 1; lbp_r = strtoul(optarg, NULL, 0); if ((lbp_r != 0) && (lbp_r != 1)) errx(1, "valid values for -r are 0 and 1"); break; case 'v': verbose = 1; break; case 'w': lbp_w_set = 1; lbp_w = strtoul(optarg, NULL, 0); if ((lbp_w != 0) && (lbp_r != 1)) errx(1, "valid values for -r are 0 and 1"); break; default: break; } } if ((rbdp_set + do_disable + do_enable + do_list + pi_length_set + prot_method_set + lbp_r_set + lbp_w_set) == 0) errx(1, "Need an argument for protect"); if ((do_disable + do_enable + do_list) != 1) errx(1, "You must specify only one of -e, -d or -l"); if (do_list != 0) { retval = mt_protect_print(status_data, verbose); goto bailout; } if (do_enable != 0) { /* * Enable protection, but allow the user to override * settings if he doesn't want everything turned on. */ if (rbdp_set == 0) rbdp = 1; if (lbp_w_set == 0) lbp_w = 1; if (lbp_r_set == 0) lbp_r = 1; /* * If the user doesn't override it, we default to enabling * Reed-Solomon checkums. */ if (prot_method_set == 0) prot_method = SA_CTRL_DP_REED_SOLOMON; if (pi_length_set == 0) pi_length = SA_CTRL_DP_RS_LENGTH; } else if (do_disable != 0) { /* * If the user wants to disable protection, we ignore any * other parameters he has set. Everything gets set to 0. */ rbdp = lbp_w = lbp_r = 0; prot_method = pi_length = 0; } prot_entry = mt_status_entry_find(status_data, __DECONST(char *, MT_PROT_NAME)); if (prot_entry == NULL) errx(1, "Unable to find protection information status"); supported_entry = mt_entry_find(prot_entry, __DECONST(char *, "protection_supported")); if (supported_entry == NULL) errx(1, "Unable to find protection support information"); if (((supported_entry->var_type == MT_TYPE_INT) && (supported_entry->value_signed == 0)) || ((supported_entry->var_type == MT_TYPE_UINT) && (supported_entry->value_unsigned == 0))) errx(1, "This device does not support protection information"); mt_protect_list[MT_PP_LBP_R].value = lbp_r; mt_protect_list[MT_PP_LBP_W].value = lbp_w; mt_protect_list[MT_PP_RBDP].value = rbdp; mt_protect_list[MT_PP_PI_LENGTH].value = pi_length; mt_protect_list[MT_PP_PROT_METHOD].value = prot_method; bzero(¶ms, sizeof(params)); bzero(¶m_list, sizeof(param_list)); /* * Go through the list and make sure that we have this parameter, * and that it is still an unsigned integer. If not, we've got a * problem. */ for (i = 0; i < MT_NUM_PROTECT_PARAMS; i++) { entry = mt_entry_find(prot_entry, __DECONST(char *, mt_protect_list[i].name)); if (entry == NULL) { errx(1, "Unable to find parameter %s", mt_protect_list[i].name); } mt_protect_list[i].entry = entry; if (entry->var_type != MT_TYPE_UINT) errx(1, "Parameter %s is type %d, not unsigned, " "cannot proceed", mt_protect_list[i].name, entry->var_type); snprintf(params[i].value_name, sizeof(params[i].value_name), "%s.%s", MT_PROT_NAME, mt_protect_list[i].name); /* XXX KDM unify types here */ params[i].value_type = MT_PARAM_SET_UNSIGNED; params[i].value_len = sizeof(mt_protect_list[i].value); params[i].value.value_unsigned = mt_protect_list[i].value; } param_list.num_params = MT_NUM_PROTECT_PARAMS; param_list.param_len = sizeof(params); param_list.params = params; if (ioctl(mtfd, MTIOCSETLIST, ¶m_list) == -1) err(1, "error issuing MTIOCSETLIST ioctl"); for (i = 0; i < MT_NUM_PROTECT_PARAMS; i++) { if (params[i].status != MT_PARAM_STATUS_OK) { warnx("%s", params[i].error_str); retval = 1; } } bailout: return (retval); } static int mt_param(int argc, char **argv, int mtfd, char *xml_str, struct mt_status_data *status_data) { int list = 0, do_set = 0, xml_dump = 0; char *param_name = NULL, *param_value = NULL; int retval = 0, quiet = 0; int c; while ((c = getopt(argc, argv, "lp:qs:x")) != -1) { switch (c) { case 'l': list = 1; break; case 'p': if (param_name != NULL) { warnx("Only one paramter name may be " "specified"); retval = 1; goto bailout; } param_name = strdup(optarg); break; case 'q': quiet = 1; break; case 's': if (param_value != NULL) { warnx("Only one paramter value may be " "specified"); retval = 1; goto bailout; } param_value = strdup(optarg); do_set = 1; break; case 'x': xml_dump = 1; break; default: break; } } if ((list + do_set + xml_dump) != 1) { warnx("You must specify only one of -s, -l or -x"); retval = 1; goto bailout; } if (xml_dump != 0) { printf("%s", xml_str); retval = 0; goto bailout; } if (do_set != 0) { if (param_name == NULL) errx(1, "You must specify -p with -s"); retval = mt_set_param(mtfd, status_data, param_name, param_value); } else if (list != 0) retval = mt_param_list(status_data, param_name, quiet); bailout: free(param_name); free(param_value); return (retval); } int mt_print_density_entry(struct mt_status_entry *density_root, int indent) { struct mt_status_entry *entry; int retval = 0; STAILQ_FOREACH(entry, &density_root->child_entries, links) { if (entry->var_type == MT_TYPE_NODE) { retval = mt_print_density_entry(entry, indent + 2); if (retval != 0) break; else continue; } if ((strcmp(entry->entry_name, "primary_density_code") == 0) - || (strcmp(entry->entry_name, "secondary_density_code") == 0)){ + || (strcmp(entry->entry_name, "secondary_density_code") == 0) + || (strcmp(entry->entry_name, "density_code") == 0)) { - /* XXX KDM this should really be unsigned */ printf("%*s%s (%s): %s\n", indent, "", entry->desc ? entry->desc : "", entry->entry_name, denstostring(entry->value_unsigned)); } else if (strcmp(entry->entry_name, "density_flags") == 0) { printf("%*sMedium Access: ", indent, ""); if (entry->value_unsigned & MT_DENS_WRITE_OK) { printf("Read and Write\n"); } else { printf("Read Only\n"); } printf("%*sDefault Density: %s\n", indent, "", (entry->value_unsigned & MT_DENS_DEFLT) ? "Yes" : "No"); printf("%*sDuplicate Density: %s\n", indent, "", (entry->value_unsigned & MT_DENS_DUP) ? "Yes" : "No"); } else if (strcmp(entry->entry_name, "media_width") == 0) { printf("%*s%s (%s): %.1f mm\n", indent, "", entry->desc ? entry->desc : "", entry->entry_name, (double)((double)entry->value_unsigned / 10)); } else if (strcmp(entry->entry_name, "medium_length") == 0) { printf("%*s%s (%s): %ju m\n", indent, "", entry->desc ? entry->desc : "", entry->entry_name, (uintmax_t)entry->value_unsigned); } else if (strcmp(entry->entry_name, "capacity") == 0) { printf("%*s%s (%s): %ju MB\n", indent, "", entry->desc ? entry->desc : "", entry->entry_name, (uintmax_t)entry->value_unsigned); } else { printf("%*s%s (%s): %s\n", indent, "", entry->desc ? entry->desc : "", entry->entry_name, entry->value); } } return (retval); } int mt_print_density_report(struct mt_status_entry *report_root, int indent) { struct mt_status_entry *mt_report, *media_report; struct mt_status_entry *entry; int retval = 0; mt_report = mt_entry_find(report_root, __DECONST(char *, MT_MEDIUM_TYPE_REPORT_NAME)); if (mt_report == NULL) return (1); media_report = mt_entry_find(report_root, __DECONST(char *, MT_MEDIA_REPORT_NAME)); if (media_report == NULL) return (1); if ((mt_report->value_signed == 0) && (media_report->value_signed == 0)) { printf("%*sThis tape drive supports the following " "media densities:\n", indent, ""); } else if ((mt_report->value_signed == 0) && (media_report->value_signed != 0)) { printf("%*sThe tape currently in this drive supports " "the following media densities:\n", indent, ""); } else if ((mt_report->value_signed != 0) && (media_report->value_signed == 0)) { printf("%*sThis tape drive supports the following " "media types:\n", indent, ""); } else { printf("%*sThis tape currently in this drive supports " "the following media types:\n", indent, ""); } STAILQ_FOREACH(entry, &report_root->child_entries, links) { struct mt_status_nv *nv; if (strcmp(entry->entry_name, MT_DENSITY_ENTRY_NAME) != 0) continue; STAILQ_FOREACH(nv, &entry->nv_list, links) { if (strcmp(nv->name, "num") != 0) continue; break; } indent += 2; printf("%*sDensity Entry", indent, ""); if (nv != NULL) printf(" %s", nv->value); printf(":\n"); retval = mt_print_density_entry(entry, indent + 2); indent -= 2; } return (retval); } int mt_print_density(struct mt_status_entry *density_root, int indent) { struct mt_status_entry *entry; int retval = 0; /* * We should have this entry for every tape drive. This particular * value is reported via the mode page block header, not the * SCSI REPORT DENSITY SUPPORT command. */ entry = mt_entry_find(density_root, __DECONST(char *, MT_MEDIA_DENSITY_NAME)); if (entry == NULL) errx(1, "Unable to find node %s", MT_MEDIA_DENSITY_NAME); printf("%*sCurrent density: %s\n", indent, "", denstostring(entry->value_unsigned)); /* * It isn't an error if we don't have any density reports. Tape * drives that don't support the REPORT DENSITY SUPPORT command * won't have any; they will only have the current density entry * above. */ STAILQ_FOREACH(entry, &density_root->child_entries, links) { if (strcmp(entry->entry_name, MT_DENSITY_REPORT_NAME) != 0) continue; retval = mt_print_density_report(entry, indent); } return (retval); } int mt_getdensity(int argc, char **argv, char *xml_str, struct mt_status_data *status_data) { int retval = 0; int verbose = 0, xml_dump = 0; struct mt_status_entry *density_root = NULL; int c; while ((c = getopt(argc, argv, "vx")) != -1) { switch (c) { case 'v': verbose = 1; break; case 'x': xml_dump = 1; break; } } if (xml_dump != 0) { printf("%s", xml_str); return (0); } density_root = mt_status_entry_find(status_data, __DECONST(char *, MT_DENSITY_ROOT_NAME)); if (density_root == NULL) errx(1, "Cannot find density root node %s", MT_DENSITY_ROOT_NAME); retval = mt_print_density(density_root, 0); return (retval); } static void warn_eof(void) { fprintf(stderr, "The \"eof\" command has been disabled.\n" "Use \"weof\" if you really want to write end-of-file marks,\n" "or \"eom\" if you rather want to skip to the end of " "recorded medium.\n"); exit(1); }