1/* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License as 4 * published by the Free Software Foundation; either version 2 of 5 * the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15 * MA 02111-1307 USA 16 */ 17#ifndef SG_CMDS_EXTRA_H 18#define SG_CMDS_EXTRA_H 19 20/* 21 * Copyright (c) 2004-2006 Douglas Gilbert. 22 * All rights reserved. 23 * 24 * Redistribution and use in source and binary forms, with or without 25 * modification, are permitted provided that the following conditions 26 * are met: 27 * 1. Redistributions of source code must retain the above copyright 28 * notice, this list of conditions and the following disclaimer. 29 * 2. Redistributions in binary form must reproduce the above copyright 30 * notice, this list of conditions and the following disclaimer in the 31 * documentation and/or other materials provided with the distribution. 32 * 3. The name of the author may not be used to endorse or promote products 33 * derived from this software without specific prior written permission. 34 * 35 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 38 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 45 * SUCH DAMAGE. 46 * 47 */ 48 49#ifdef __cplusplus 50extern "C" { 51#endif 52 53 54/* Invokes a ATA PASS-THROUGH (12 or 16) SCSI command (SAT). If cdb_len 55 * is 12 then a ATA PASS-THROUGH (12) command is called. If cdb_len is 16 56 * then a ATA PASS-THROUGH (16) command is called. If cdb_len is any other 57 * value -1 is returned. After copying from cdbp to an internal buffer, 58 * the first byte (i.e. offset 0) is set to 0xa1 if cdb_len is 12; or is 59 * set to 0x85 if cdb_len is 16. The last byte (offset 11 or offset 15) is 60 * set to 0x0 in the internal buffer. If timeout_secs <= 0 then the timeout 61 * is set to 60 seconds. For data in or out transfers set dinp or doutp, 62 * and dlen to the number of bytes to transfer. If dlen is zero then no data 63 * transfer is assumed. If sense buffer obtained then it is written to 64 * sensep, else sensep[0] is set to 0x0. If ATA return descriptor is obtained 65 * then written to ata_return_dp, else ata_return_dp[0] is set to 0x0. Either 66 * sensep or ata_return_dp (or both) may be NULL pointers. Returns SCSI 67 * status value (>= 0) or -1 if other error. Users are expected to check the 68 * sense buffer themselves. If available the data in resid is written to 69 * residp. 70 */ 71extern int sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len, 72 int timeout_secs, void * dinp, void * doutp, 73 int dlen, unsigned char * sensep, 74 int max_sense_len, unsigned char * ata_return_dp, 75 int max_ata_return_len, int * residp, int verbose); 76 77/* Invokes a FORMAT UNIT (SBC-3) command. Return of 0 -> success, 78 * SG_LIB_CAT_INVALID_OP -> Format unit not supported, 79 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 80 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 81 * -1 -> other failure */ 82extern int sg_ll_format_unit(int sg_fd, int fmtpinfo, int rto_req, 83 int longlist, int fmtdata, int cmplist, 84 int dlist_format, int timeout_secs, 85 void * paramp, int param_len, int noisy, 86 int verbose); 87 88/* Invokes a SCSI GET CONFIGURATION command (MMC-3,4,5). 89 * Returns 0 when successful, SG_LIB_CAT_INVALID_OP if command not 90 * supported, SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported, 91 * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */ 92extern int sg_ll_get_config(int sg_fd, int rt, int starting, void * resp, 93 int mx_resp_len, int noisy, int verbose); 94 95/* Invokes a SCSI PERSISTENT RESERVE IN command (SPC). Returns 0 96 * when successful, SG_LIB_CAT_INVALID_OP if command not supported, 97 * SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported, 98 * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */ 99extern int sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, 100 void * resp, int mx_resp_len, 101 int noisy, int verbose); 102 103/* Invokes a SCSI PERSISTENT RESERVE OUT command (SPC). Returns 0 104 * when successful, SG_LIB_CAT_INVALID_OP if command not supported, 105 * SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported, 106 * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */ 107extern int sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, 108 int rq_scope, unsigned int rq_type, 109 void * paramp, int param_len, 110 int noisy, int verbose); 111 112/* Invokes a SCSI READ BUFFER command (SPC). Return of 0 -> 113 * success, SG_LIB_CAT_INVALID_OP -> invalid opcode, 114 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 115 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 116 * -1 -> other failure */ 117extern int sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, 118 int buffer_offset, void * resp, 119 int mx_resp_len, int noisy, int verbose); 120 121/* Invokes a SCSI READ DEFECT DATA (10) command (SBC). Return of 0 -> 122 * success, SG_LIB_CAT_INVALID_OP -> invalid opcode, 123 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 124 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 125 * -1 -> other failure */ 126extern int sg_ll_read_defect10(int sg_fd, int req_plist, int req_glist, 127 int dl_format, void * resp, int mx_resp_len, 128 int noisy, int verbose); 129 130/* Invokes a SCSI READ LONG (10) command (SBC). Note that 'xfer_len' 131 * is in bytes. Returns 0 -> success, 132 * SG_LIB_CAT_INVALID_OP -> READ LONG(10) not supported, 133 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, 134 * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info 135 * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION, 136 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 137 * -1 -> other failure */ 138extern int sg_ll_read_long10(int sg_fd, int pblock, int correct, 139 unsigned long lba, void * resp, int xfer_len, 140 int * offsetp, int noisy, int verbose); 141 142/* Invokes a SCSI READ LONG (16) command (SBC). Note that 'xfer_len' 143 * is in bytes. Returns 0 -> success, 144 * SG_LIB_CAT_INVALID_OP -> READ LONG(16) not supported, 145 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, 146 * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info 147 * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION, 148 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 149 * -1 -> other failure */ 150extern int sg_ll_read_long16(int sg_fd, int pblock, int correct, 151 unsigned long long llba, void * resp, 152 int xfer_len, int * offsetp, int noisy, 153 int verbose); 154 155/* Invokes a SCSI READ MEDIA SERIAL NUMBER command. Return of 0 -> success, 156 * SG_LIB_CAT_INVALID_OP -> Read media serial number not supported, 157 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 158 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 159 * -1 -> other failure */ 160extern int sg_ll_read_media_serial_num(int sg_fd, void * resp, 161 int mx_resp_len, int noisy, 162 int verbose); 163 164/* Invokes a SCSI REASSIGN BLOCKS command. Return of 0 -> success, 165 * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_UNIT_ATTENTION, 166 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND, 167 * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */ 168extern int sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, 169 void * paramp, int param_len, int noisy, 170 int verbose); 171 172/* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success, 173 * SG_LIB_CAT_INVALID_OP -> Receive diagnostic results not supported, 174 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 175 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 176 * -1 -> other failure */ 177extern int sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp, 178 int mx_resp_len, int noisy, int verbose); 179 180/* Invokes a SCSI REPORT IDENTIFYING INFORMATION command. This command was 181 * called REPORT DEVICE IDENTIFIER prior to spc4r07. Return of 0 -> success, 182 * SG_LIB_CAT_INVALID_OP -> Report identifying information not supported, 183 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 184 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 185 * -1 -> other failure */ 186extern int sg_ll_report_id_info(int sg_fd, int itype, void * resp, 187 int max_resp_len, int noisy, int verbose); 188 189/* Invokes a SCSI REPORT TARGET PORT GROUPS command. Return of 0 -> success, 190 * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported, 191 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND, 192 * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */ 193extern int sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, 194 int mx_resp_len, int noisy, int verbose); 195 196/* Invokes a SCSI SET TARGET PORT GROUPS command. Return of 0 -> success, 197 * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported, 198 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND, 199 * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */ 200extern int sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, 201 int param_len, int noisy, int verbose); 202 203/* Invokes a SCSI SEND DIAGNOSTIC command. Foreground, extended self tests can 204 * take a long time, if so set long_duration flag. Return of 0 -> success, 205 * SG_LIB_CAT_INVALID_OP -> Send diagnostic not supported, 206 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 207 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 208 * -1 -> other failure */ 209extern int sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, 210 int devofl_bit, int unitofl_bit, int long_duration, 211 void * paramp, int param_len, int noisy, 212 int verbose); 213 214/* Invokes a SCSI SET IDENTIFYING INFORMATION command. This command was 215 * called SET DEVICE IDENTIFIER prior to spc4r07. Return of 0 -> success, 216 * SG_LIB_CAT_INVALID_OP -> Set identifying information not supported, 217 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 218 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 219 * -1 -> other failure */ 220extern int sg_ll_set_id_info(int sg_fd, int itype, void * paramp, 221 int param_len, int noisy, int verbose); 222 223/* Invokes a SCSI VERIFY (10) command (SBC and MMC). 224 * Note that 'veri_len' is in blocks while 'data_out_len' is in bytes. 225 * Returns of 0 -> success, 226 * SG_LIB_CAT_INVALID_OP -> Verify(10) not supported, 227 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 228 * SG_LIB_CAT_MEDIUM_HARD -> medium or hardware error, no valid info, 229 * SG_LIB_CAT_MEDIUM_HARD_WITH_INFO -> as previous, with valid info, 230 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 231 * -1 -> other failure */ 232extern int sg_ll_verify10(int sg_fd, int dpo, int bytechk, unsigned long lba, 233 int veri_len, void * data_out, int data_out_len, 234 unsigned long * infop, int noisy, int verbose); 235 236/* Invokes a SCSI WRITE BUFFER command (SPC). Return of 0 -> 237 * success, SG_LIB_CAT_INVALID_OP -> invalid opcode, 238 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION, 239 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 240 * -1 -> other failure */ 241extern int sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, 242 int buffer_offset, void * paramp, 243 int param_len, int noisy, int verbose); 244 245/* Invokes a SCSI WRITE LONG (10) command (SBC). Note that 'xfer_len' 246 * is in bytes. Returns 0 -> success, 247 * SG_LIB_CAT_INVALID_OP -> WRITE LONG(10) not supported, 248 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, 249 * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info 250 * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION, 251 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 252 * -1 -> other failure */ 253extern int sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock, 254 unsigned long lba, void * data_out, 255 int xfer_len, int * offsetp, int noisy, 256 int verbose); 257 258/* Invokes a SCSI WRITE LONG (16) command (SBC). Note that 'xfer_len' 259 * is in bytes. Returns 0 -> success, 260 * SG_LIB_CAT_INVALID_OP -> WRITE LONG(16) not supported, 261 * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, 262 * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info 263 * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION, 264 * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, 265 * -1 -> other failure */ 266extern int sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock, 267 unsigned long long llba, void * data_out, 268 int xfer_len, int * offsetp, int noisy, 269 int verbose); 270 271#ifdef __cplusplus 272} 273#endif 274 275#endif 276