xref: /aosp_15_r20/external/sg3_utils/include/sg_cmds_extra.h (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1*44704f69SBart Van Assche #ifndef SG_CMDS_EXTRA_H
2*44704f69SBart Van Assche #define SG_CMDS_EXTRA_H
3*44704f69SBart Van Assche 
4*44704f69SBart Van Assche /*
5*44704f69SBart Van Assche  * Copyright (c) 2004-2018 Douglas Gilbert.
6*44704f69SBart Van Assche  * All rights reserved.
7*44704f69SBart Van Assche  * Use of this source code is governed by a BSD-style
8*44704f69SBart Van Assche  * license that can be found in the BSD_LICENSE file.
9*44704f69SBart Van Assche  *
10*44704f69SBart Van Assche  * SPDX-License-Identifier: BSD-2-Clause
11*44704f69SBart Van Assche  */
12*44704f69SBart Van Assche 
13*44704f69SBart Van Assche #include <stdint.h>
14*44704f69SBart Van Assche 
15*44704f69SBart Van Assche #ifdef __cplusplus
16*44704f69SBart Van Assche extern "C" {
17*44704f69SBart Van Assche #endif
18*44704f69SBart Van Assche 
19*44704f69SBart Van Assche /* Note: all functions that have an 'int timeout_secs' argument will use
20*44704f69SBart Van Assche  * that value if it is > 0. Otherwise they will set an internal default
21*44704f69SBart Van Assche  * which is currently 60 seconds. This timeout is typically applied in the
22*44704f69SBart Van Assche  * SCSI stack above the initiator. If it goes off then the SCSI command is
23*44704f69SBart Van Assche  * aborted and there can be other unwelcome side effects. Note that some
24*44704f69SBart Van Assche  * commands (e.g. FORMAT UNIT and the Third Party copy commands) can take
25*44704f69SBart Van Assche  * a lot longer than the default timeout. */
26*44704f69SBart Van Assche 
27*44704f69SBart Van Assche /* Functions with the "_pt" suffix ^^^ take a pointer to an object (derived
28*44704f69SBart Van Assche  * from) sg_pt_base rather than an open file descriptor as their first
29*44704f69SBart Van Assche  * argument. That object is assumed to be constructed and have a device file
30*44704f69SBart Van Assche  * descriptor * associated with it. Caller is responsible for lifetime of
31*44704f69SBart Van Assche  * ptp.
32*44704f69SBart Van Assche  *    ^^^ apart from sg_ll_ata_pt() as 'pass-through' is part of its name. */
33*44704f69SBart Van Assche 
34*44704f69SBart Van Assche struct sg_pt_base;
35*44704f69SBart Van Assche 
36*44704f69SBart Van Assche 
37*44704f69SBart Van Assche /* Invokes a ATA PASS-THROUGH (12, 16 or 32) SCSI command (SAT). This is
38*44704f69SBart Van Assche  * selected by the cdb_len argument that can take values of 12, 16 or 32
39*44704f69SBart Van Assche  * only (else -1 is returned). The byte at offset 0 (and bytes 0 to 9
40*44704f69SBart Van Assche  * inclusive for ATA PT(32)) pointed to be cdbp are ignored and apart from
41*44704f69SBart Van Assche  * the control byte, the rest is copied into an internal cdb which is then
42*44704f69SBart Van Assche  * sent to the device. The control byte is byte 11 for ATA PT(12), byte 15
43*44704f69SBart Van Assche  * for ATA PT(16) and byte 1 for ATA PT(32). If timeout_secs <= 0 then the
44*44704f69SBart Van Assche  * timeout is set to 60 seconds. For data in or out transfers set dinp or
45*44704f69SBart Van Assche  * doutp, and dlen to the number of bytes to transfer. If dlen is zero then
46*44704f69SBart Van Assche  * no data transfer is assumed. If sense buffer obtained then it is written
47*44704f69SBart Van Assche  * to sensep, else sensep[0] is set to 0x0. If ATA return descriptor is
48*44704f69SBart Van Assche  * obtained then written to ata_return_dp, else ata_return_dp[0] is set to
49*44704f69SBart Van Assche  * 0x0. Either sensep or ata_return_dp (or both) may be NULL pointers.
50*44704f69SBart Van Assche  * Returns SCSI status value (>= 0) or -1 if other error. Users are
51*44704f69SBart Van Assche  * expected to check the sense buffer themselves. If available the data in
52*44704f69SBart Van Assche  * resid is written to residp. Note in SAT-2 and later, fixed format sense
53*44704f69SBart Van Assche  * data may be placed in *sensep in which case sensep[0]==0x70, prior to
54*44704f69SBart Van Assche  * SAT-2 descriptor sense format was required (i.e. sensep[0]==0x72).
55*44704f69SBart Van Assche  */
56*44704f69SBart Van Assche int sg_ll_ata_pt(int sg_fd, const uint8_t * cdbp, int cdb_len,
57*44704f69SBart Van Assche                  int timeout_secs,  void * dinp, void * doutp, int dlen,
58*44704f69SBart Van Assche                  uint8_t * sensep, int max_sense_len, uint8_t * ata_return_dp,
59*44704f69SBart Van Assche                  int max_ata_return_len, int * residp, int verbose);
60*44704f69SBart Van Assche 
61*44704f69SBart Van Assche /* Invokes a FORMAT UNIT (SBC-3) command. Return of 0 -> success,
62*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Format unit not supported,
63*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
64*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
65*44704f69SBart Van Assche  * -1 -> other failure. Note that sg_ll_format_unit2() and
66*44704f69SBart Van Assche  * sg_ll_format_unit_v2() are the same, both add the ffmt argument. */
67*44704f69SBart Van Assche int sg_ll_format_unit(int sg_fd, int fmtpinfo, bool longlist, bool fmtdata,
68*44704f69SBart Van Assche                       bool cmplist, int dlist_format, int timeout_secs,
69*44704f69SBart Van Assche                       void * paramp, int param_len, bool noisy, int verbose);
70*44704f69SBart Van Assche int sg_ll_format_unit2(int sg_fd, int fmtpinfo, bool longlist, bool fmtdata,
71*44704f69SBart Van Assche                        bool cmplist, int dlist_format, int ffmt,
72*44704f69SBart Van Assche                        int timeout_secs, void * paramp, int param_len,
73*44704f69SBart Van Assche                        bool noisy, int verbose);
74*44704f69SBart Van Assche int sg_ll_format_unit_v2(int sg_fd, int fmtpinfo, bool longlist, bool fmtdata,
75*44704f69SBart Van Assche                          bool cmplist, int dlist_format, int ffmt,
76*44704f69SBart Van Assche                          int timeout_secs, void * paramp, int param_len,
77*44704f69SBart Van Assche                          bool noisy, int verbose);
78*44704f69SBart Van Assche 
79*44704f69SBart Van Assche /* Invokes a SCSI GET LBA STATUS(16) or GET LBA STATUS(32) command (SBC).
80*44704f69SBart Van Assche  * Returns 0 -> success,
81*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> GET LBA STATUS(16 or 32) not supported,
82*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
83*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure.
84*44704f69SBart Van Assche  * sg_ll_get_lba_status() calls the 16 byte variant with rt=0 . */
85*44704f69SBart Van Assche int sg_ll_get_lba_status(int sg_fd, uint64_t start_llba, void * resp,
86*44704f69SBart Van Assche                          int alloc_len, bool noisy, int verbose);
87*44704f69SBart Van Assche int sg_ll_get_lba_status16(int sg_fd, uint64_t start_llba, uint8_t rt,
88*44704f69SBart Van Assche                            void * resp, int alloc_len, bool noisy,
89*44704f69SBart Van Assche                            int verbose);
90*44704f69SBart Van Assche int sg_ll_get_lba_status32(int sg_fd, uint64_t start_llba, uint32_t scan_len,
91*44704f69SBart Van Assche                            uint32_t element_id, uint8_t rt,
92*44704f69SBart Van Assche                            void * resp, int alloc_len, bool noisy,
93*44704f69SBart Van Assche                            int verbose);
94*44704f69SBart Van Assche 
95*44704f69SBart Van Assche /* Invokes a SCSI PERSISTENT RESERVE IN command (SPC). Returns 0
96*44704f69SBart Van Assche  * when successful, SG_LIB_CAT_INVALID_OP if command not supported,
97*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported,
98*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */
99*44704f69SBart Van Assche int sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, void * resp,
100*44704f69SBart Van Assche                                 int mx_resp_len, bool noisy, int verbose);
101*44704f69SBart Van Assche 
102*44704f69SBart Van Assche /* Invokes a SCSI PERSISTENT RESERVE OUT command (SPC). Returns 0
103*44704f69SBart Van Assche  * when successful, SG_LIB_CAT_INVALID_OP if command not supported,
104*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported,
105*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */
106*44704f69SBart Van Assche int sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope,
107*44704f69SBart Van Assche                                  unsigned int rq_type, void * paramp,
108*44704f69SBart Van Assche                                  int param_len, bool noisy, int verbose);
109*44704f69SBart Van Assche 
110*44704f69SBart Van Assche /* Invokes a SCSI READ BLOCK LIMITS command. Return of 0 -> success,
111*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> READ BLOCK LIMITS not supported,
112*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
113*44704f69SBart Van Assche  * SG_LIB_NOT_READY (shouldn't happen), -1 -> other failure */
114*44704f69SBart Van Assche int sg_ll_read_block_limits(int sg_fd, void * resp, int mx_resp_len,
115*44704f69SBart Van Assche                             bool noisy, int verbose);
116*44704f69SBart Van Assche int sg_ll_read_block_limits_v2(int sg_fd, bool mloi, void * resp,
117*44704f69SBart Van Assche                                int mx_resp_len, int * residp, bool noisy,
118*44704f69SBart Van Assche                                int verbose);
119*44704f69SBart Van Assche 
120*44704f69SBart Van Assche /* Invokes a SCSI READ BUFFER command (SPC). Return of 0 ->
121*44704f69SBart Van Assche  * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
122*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
123*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
124*44704f69SBart Van Assche  * -1 -> other failure */
125*44704f69SBart Van Assche int sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
126*44704f69SBart Van Assche                       void * resp, int mx_resp_len, bool noisy, int verbose);
127*44704f69SBart Van Assche 
128*44704f69SBart Van Assche /* Invokes a SCSI READ DEFECT DATA (10) command (SBC). Return of 0 ->
129*44704f69SBart Van Assche  * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
130*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
131*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
132*44704f69SBart Van Assche  * -1 -> other failure */
133*44704f69SBart Van Assche int sg_ll_read_defect10(int sg_fd, bool req_plist, bool req_glist,
134*44704f69SBart Van Assche                         int dl_format, void * resp, int mx_resp_len,
135*44704f69SBart Van Assche                         bool noisy, int verbose);
136*44704f69SBart Van Assche 
137*44704f69SBart Van Assche /* Invokes a SCSI READ LONG (10) command (SBC). Note that 'xfer_len'
138*44704f69SBart Van Assche  * is in bytes. Returns 0 -> success,
139*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> READ LONG(10) not supported,
140*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
141*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
142*44704f69SBart Van Assche  * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION,
143*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
144*44704f69SBart Van Assche  * -1 -> other failure */
145*44704f69SBart Van Assche int sg_ll_read_long10(int sg_fd, bool pblock, bool correct, unsigned int lba,
146*44704f69SBart Van Assche                       void * resp, int xfer_len, int * offsetp, bool noisy,
147*44704f69SBart Van Assche                       int verbose);
148*44704f69SBart Van Assche 
149*44704f69SBart Van Assche /* Invokes a SCSI READ LONG (16) command (SBC). Note that 'xfer_len'
150*44704f69SBart Van Assche  * is in bytes. Returns 0 -> success,
151*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> READ LONG(16) not supported,
152*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
153*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
154*44704f69SBart Van Assche  * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION,
155*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
156*44704f69SBart Van Assche  *  -1 -> other failure */
157*44704f69SBart Van Assche int sg_ll_read_long16(int sg_fd, bool pblock, bool correct, uint64_t llba,
158*44704f69SBart Van Assche                       void * resp, int xfer_len, int * offsetp, bool noisy,
159*44704f69SBart Van Assche                       int verbose);
160*44704f69SBart Van Assche 
161*44704f69SBart Van Assche /* Invokes a SCSI READ MEDIA SERIAL NUMBER command. Return of 0 -> success,
162*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Read media serial number not supported,
163*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
164*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
165*44704f69SBart Van Assche  * -1 -> other failure */
166*44704f69SBart Van Assche int sg_ll_read_media_serial_num(int sg_fd, void * resp, int mx_resp_len,
167*44704f69SBart Van Assche                                 bool noisy, int verbose);
168*44704f69SBart Van Assche 
169*44704f69SBart Van Assche /* Invokes a SCSI REASSIGN BLOCKS command.  Return of 0 -> success,
170*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_UNIT_ATTENTION,
171*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
172*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
173*44704f69SBart Van Assche int sg_ll_reassign_blocks(int sg_fd, bool longlba, bool longlist,
174*44704f69SBart Van Assche                           void * paramp, int param_len, bool noisy,
175*44704f69SBart Van Assche                           int verbose);
176*44704f69SBart Van Assche 
177*44704f69SBart Van Assche /* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success,
178*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Receive diagnostic results not supported,
179*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
180*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
181*44704f69SBart Van Assche  * -1 -> other failure */
182*44704f69SBart Van Assche int sg_ll_receive_diag(int sg_fd, bool pcv, int pg_code, void * resp,
183*44704f69SBart Van Assche                        int mx_resp_len, bool noisy, int verbose);
184*44704f69SBart Van Assche 
185*44704f69SBart Van Assche /* Same as sg_ll_receive_diag() but with added timeout_secs and residp
186*44704f69SBart Van Assche  * arguments. Adds the ability to set the command abort timeout
187*44704f69SBart Van Assche  * and the ability to report the residual count. If timeout_secs is zero
188*44704f69SBart Van Assche  * or less the default command abort timeout (60 seconds) is used.
189*44704f69SBart Van Assche  * If residp is non-NULL then the residual value is written where residp
190*44704f69SBart Van Assche  * points. A residual value of 0 implies mx_resp_len bytes have be written
191*44704f69SBart Van Assche  * where resp points. If the residual value equals mx_resp_len then no
192*44704f69SBart Van Assche  * bytes have been written. */
193*44704f69SBart Van Assche int sg_ll_receive_diag_v2(int sg_fd, bool pcv, int pg_code, void * resp,
194*44704f69SBart Van Assche                           int mx_resp_len, int timeout_secs, int * residp,
195*44704f69SBart Van Assche                           bool noisy, int verbose);
196*44704f69SBart Van Assche 
197*44704f69SBart Van Assche int sg_ll_receive_diag_pt(struct sg_pt_base * ptp, bool pcv, int pg_code,
198*44704f69SBart Van Assche                           void * resp, int mx_resp_len, int timeout_secs,
199*44704f69SBart Van Assche                           int * residp, bool noisy, int verbose);
200*44704f69SBart Van Assche 
201*44704f69SBart Van Assche /* Invokes a SCSI REPORT IDENTIFYING INFORMATION command. This command was
202*44704f69SBart Van Assche  * called REPORT DEVICE IDENTIFIER prior to spc4r07. Return of 0 -> success,
203*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Report identifying information not supported,
204*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
205*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
206*44704f69SBart Van Assche  * -1 -> other failure */
207*44704f69SBart Van Assche int sg_ll_report_id_info(int sg_fd, int itype, void * resp, int max_resp_len,
208*44704f69SBart Van Assche                          bool noisy, int verbose);
209*44704f69SBart Van Assche 
210*44704f69SBart Van Assche /* Invokes a SCSI REPORT TARGET PORT GROUPS command. Return of 0 -> success,
211*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported,
212*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
213*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
214*44704f69SBart Van Assche int sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len,
215*44704f69SBart Van Assche                              bool noisy, int verbose);
216*44704f69SBart Van Assche int sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len,
217*44704f69SBart Van Assche                               bool extended, bool noisy, int verbose);
218*44704f69SBart Van Assche 
219*44704f69SBart Van Assche /* Invokes a SCSI SET TARGET PORT GROUPS command. Return of 0 -> success,
220*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported,
221*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
222*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
223*44704f69SBart Van Assche int sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, bool noisy,
224*44704f69SBart Van Assche                           int verbose);
225*44704f69SBart Van Assche 
226*44704f69SBart Van Assche /* Invokes a SCSI REPORT REFERRALS command. Return of 0 -> success,
227*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Report Referrals not supported,
228*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
229*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
230*44704f69SBart Van Assche int sg_ll_report_referrals(int sg_fd, uint64_t start_llba, bool one_seg,
231*44704f69SBart Van Assche                            void * resp, int mx_resp_len, bool noisy,
232*44704f69SBart Van Assche                            int verbose);
233*44704f69SBart Van Assche 
234*44704f69SBart Van Assche /* Invokes a SCSI SEND DIAGNOSTIC command. Foreground, extended self tests can
235*44704f69SBart Van Assche  * take a long time, if so set long_duration flag in which case the timeout
236*44704f69SBart Van Assche  * is set to 7200 seconds; if the value of long_duration is > 7200 then that
237*44704f69SBart Van Assche  * value is taken as the timeout value in seconds. Return of 0 -> success,
238*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Send diagnostic not supported,
239*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
240*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
241*44704f69SBart Van Assche  * -1 -> other failure */
242*44704f69SBart Van Assche int sg_ll_send_diag(int sg_fd, int st_code, bool pf_bit, bool st_bit,
243*44704f69SBart Van Assche                     bool devofl_bit, bool unitofl_bit, int long_duration,
244*44704f69SBart Van Assche                     void * paramp, int param_len, bool noisy, int verbose);
245*44704f69SBart Van Assche 
246*44704f69SBart Van Assche int sg_ll_send_diag_pt(struct sg_pt_base * ptp, int st_code, bool pf_bit,
247*44704f69SBart Van Assche                        bool st_bit, bool devofl_bit, bool unitofl_bit,
248*44704f69SBart Van Assche                        int long_duration, void * paramp, int param_len,
249*44704f69SBart Van Assche                        bool noisy, int verbose);
250*44704f69SBart Van Assche 
251*44704f69SBart Van Assche /* Invokes a SCSI SET IDENTIFYING INFORMATION command. This command was
252*44704f69SBart Van Assche  * called SET DEVICE IDENTIFIER prior to spc4r07. Return of 0 -> success,
253*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Set identifying information not supported,
254*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
255*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
256*44704f69SBart Van Assche  * -1 -> other failure */
257*44704f69SBart Van Assche int sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len,
258*44704f69SBart Van Assche                       bool noisy, int verbose);
259*44704f69SBart Van Assche 
260*44704f69SBart Van Assche /* Invokes a SCSI UNMAP (SBC-3) command. Return of 0 -> success,
261*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> command not supported,
262*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
263*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
264*44704f69SBart Van Assche int sg_ll_unmap(int sg_fd, int group_num, int timeout_secs, void * paramp,
265*44704f69SBart Van Assche                 int param_len, bool noisy, int verbose);
266*44704f69SBart Van Assche /* Invokes a SCSI UNMAP (SBC-3) command. Version 2 adds anchor field
267*44704f69SBart Van Assche  * (sbc3r22). Otherwise same as sg_ll_unmap() . */
268*44704f69SBart Van Assche int sg_ll_unmap_v2(int sg_fd, bool anchor, int group_num, int timeout_secs,
269*44704f69SBart Van Assche                    void * paramp, int param_len, bool noisy, int verbose);
270*44704f69SBart Van Assche 
271*44704f69SBart Van Assche /* Invokes a SCSI VERIFY (10) command (SBC and MMC).
272*44704f69SBart Van Assche  * Note that 'veri_len' is in blocks while 'data_out_len' is in bytes.
273*44704f69SBart Van Assche  * Returns of 0 -> success,
274*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Verify(10) not supported,
275*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
276*44704f69SBart Van Assche  * SG_LIB_CAT_MEDIUM_HARD -> medium or hardware error, no valid info,
277*44704f69SBart Van Assche  * SG_LIB_CAT_MEDIUM_HARD_WITH_INFO -> as previous, with valid info,
278*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
279*44704f69SBart Van Assche  * SG_LIB_CAT_MISCOMPARE, -1 -> other failure */
280*44704f69SBart Van Assche int sg_ll_verify10(int sg_fd, int vrprotect, bool dpo, int bytechk,
281*44704f69SBart Van Assche                    unsigned int lba, int veri_len, void * data_out,
282*44704f69SBart Van Assche                    int data_out_len, unsigned int * infop, bool noisy,
283*44704f69SBart Van Assche                    int verbose);
284*44704f69SBart Van Assche 
285*44704f69SBart Van Assche /* Invokes a SCSI VERIFY (16) command (SBC).
286*44704f69SBart Van Assche  * Note that 'veri_len' is in blocks while 'data_out_len' is in bytes.
287*44704f69SBart Van Assche  * Returns of 0 -> success,
288*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Verify(16) not supported,
289*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
290*44704f69SBart Van Assche  * SG_LIB_CAT_MEDIUM_HARD -> medium or hardware error, no valid info,
291*44704f69SBart Van Assche  * SG_LIB_CAT_MEDIUM_HARD_WITH_INFO -> as previous, with valid info,
292*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
293*44704f69SBart Van Assche  * SG_LIB_CAT_MISCOMPARE, -1 -> other failure */
294*44704f69SBart Van Assche int sg_ll_verify16(int sg_fd, int vrprotect, bool dpo, int bytechk,
295*44704f69SBart Van Assche                    uint64_t llba, int veri_len, int group_num,
296*44704f69SBart Van Assche                    void * data_out, int data_out_len, uint64_t * infop,
297*44704f69SBart Van Assche                    bool noisy, int verbose);
298*44704f69SBart Van Assche 
299*44704f69SBart Van Assche /* Invokes a SCSI WRITE BUFFER command (SPC). Return of 0 ->
300*44704f69SBart Van Assche  * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
301*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
302*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
303*44704f69SBart Van Assche  * -1 -> other failure */
304*44704f69SBart Van Assche int sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
305*44704f69SBart Van Assche                        void * paramp, int param_len, bool noisy, int verbose);
306*44704f69SBart Van Assche 
307*44704f69SBart Van Assche /* Invokes a SCSI WRITE BUFFER command (SPC). Return of 0 ->
308*44704f69SBart Van Assche  * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
309*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
310*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
311*44704f69SBart Van Assche  * -1 -> other failure. Adds mode specific field (spc4r32) and timeout
312*44704f69SBart Van Assche  *  to command abort to override default of 60 seconds. If timeout_secs is
313*44704f69SBart Van Assche  *  0 or less then the default timeout is used instead. */
314*44704f69SBart Van Assche int
315*44704f69SBart Van Assche sg_ll_write_buffer_v2(int sg_fd, int mode, int m_specific, int buffer_id,
316*44704f69SBart Van Assche                       uint32_t buffer_offset, void * paramp,
317*44704f69SBart Van Assche                       uint32_t param_len, int timeout_secs, bool noisy,
318*44704f69SBart Van Assche                       int verbose);
319*44704f69SBart Van Assche 
320*44704f69SBart Van Assche /* Invokes a SCSI WRITE LONG (10) command (SBC). Note that 'xfer_len'
321*44704f69SBart Van Assche  * is in bytes. Returns 0 -> success,
322*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> WRITE LONG(10) not supported,
323*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
324*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
325*44704f69SBart Van Assche  * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION,
326*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
327*44704f69SBart Van Assche  * -1 -> other failure */
328*44704f69SBart Van Assche int sg_ll_write_long10(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock,
329*44704f69SBart Van Assche                        unsigned int lba, void * data_out, int xfer_len,
330*44704f69SBart Van Assche                        int * offsetp, bool noisy, int verbose);
331*44704f69SBart Van Assche 
332*44704f69SBart Van Assche /* Invokes a SCSI WRITE LONG (16) command (SBC). Note that 'xfer_len'
333*44704f69SBart Van Assche  * is in bytes. Returns 0 -> success,
334*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> WRITE LONG(16) not supported,
335*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
336*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
337*44704f69SBart Van Assche  * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION,
338*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
339*44704f69SBart Van Assche  * -1 -> other failure */
340*44704f69SBart Van Assche int sg_ll_write_long16(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock,
341*44704f69SBart Van Assche                        uint64_t llba, void * data_out, int xfer_len,
342*44704f69SBart Van Assche                        int * offsetp, bool noisy, int verbose);
343*44704f69SBart Van Assche 
344*44704f69SBart Van Assche /* Invokes a SPC-3 SCSI RECEIVE COPY RESULTS command. In SPC-4 this function
345*44704f69SBart Van Assche  * supports all service action variants of the THIRD-PARTY COPY IN opcode.
346*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Receive copy results not supported,
347*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
348*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
349*44704f69SBart Van Assche  * -1 -> other failure */
350*44704f69SBart Van Assche int sg_ll_receive_copy_results(int sg_fd, int sa, int list_id, void * resp,
351*44704f69SBart Van Assche                                int mx_resp_len, bool noisy, int verbose);
352*44704f69SBart Van Assche 
353*44704f69SBart Van Assche /* Invokes a SCSI EXTENDED COPY(LID1) command. For EXTENDED COPY(LID4)
354*44704f69SBart Van Assche  * including POPULATE TOKEN and WRITE USING TOKEN use
355*44704f69SBart Van Assche  * sg_ll_3party_copy_out().  Return of 0 -> success,
356*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Extended copy not supported,
357*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
358*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
359*44704f69SBart Van Assche  * -1 -> other failure */
360*44704f69SBart Van Assche int sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, bool noisy,
361*44704f69SBart Van Assche                         int verbose);
362*44704f69SBart Van Assche 
363*44704f69SBart Van Assche /* Handles various service actions associated with opcode 0x83 which is
364*44704f69SBart Van Assche  * called THIRD PARTY COPY OUT. These include the EXTENDED COPY(LID4),
365*44704f69SBart Van Assche  * POPULATE TOKEN and WRITE USING TOKEN commands. Return of 0 -> success,
366*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> opcode 0x83 not supported,
367*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
368*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
369*44704f69SBart Van Assche  * -1 -> other failure */
370*44704f69SBart Van Assche int sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id,
371*44704f69SBart Van Assche                           int group_num, int timeout_secs, void * paramp,
372*44704f69SBart Van Assche                           int param_len, bool noisy, int verbose);
373*44704f69SBart Van Assche 
374*44704f69SBart Van Assche /* Invokes a SCSI PRE-FETCH(10), PRE-FETCH(16) or SEEK(10) command (SBC).
375*44704f69SBart Van Assche  * Returns 0 -> success, 25 (SG_LIB_CAT_CONDITION_MET), various SG_LIB_CAT_*
376*44704f69SBart Van Assche  * positive values or -1 -> other errors. Note that CONDITION MET status
377*44704f69SBart Van Assche  * is returned when immed=true and num_blocks can fit in device's cache,
378*44704f69SBart Van Assche  * somewaht strangely, GOOD status (return 0) is returned if num_blocks
379*44704f69SBart Van Assche  * cannot fit in device's cache. If do_seek10==true then does a SEEK(10)
380*44704f69SBart Van Assche  * command with given lba, if that LBA is < 2**32 . Unclear what SEEK(10)
381*44704f69SBart Van Assche  * does, assume it is like PRE-FETCH. If timeout_secs is 0 (or less) then
382*44704f69SBart Van Assche  * use DEF_PT_TIMEOUT (60 seconds) as command timeout. */
383*44704f69SBart Van Assche int sg_ll_pre_fetch_x(int sg_fd, bool do_seek10, bool cdb16, bool immed,
384*44704f69SBart Van Assche                       uint64_t lba, uint32_t num_blocks, int group_num,
385*44704f69SBart Van Assche                       int timeout_secs, bool noisy, int verbose);
386*44704f69SBart Van Assche 
387*44704f69SBart Van Assche #ifdef __cplusplus
388*44704f69SBart Van Assche }
389*44704f69SBart Van Assche #endif
390*44704f69SBart Van Assche 
391*44704f69SBart Van Assche #endif
392