xref: /aosp_15_r20/external/sg3_utils/include/sg_cmds_basic.h (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1*44704f69SBart Van Assche #ifndef SG_CMDS_BASIC_H
2*44704f69SBart Van Assche #define SG_CMDS_BASIC_H
3*44704f69SBart Van Assche 
4*44704f69SBart Van Assche /*
5*44704f69SBart Van Assche  * Copyright (c) 2004-2020 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 /*
14*44704f69SBart Van Assche  * Error, warning and verbose output is sent to the file pointed to by
15*44704f69SBart Van Assche  * sg_warnings_strm which is declared in sg_lib.h and can be set with
16*44704f69SBart Van Assche  * the sg_set_warnings_strm() function. If not given sg_warnings_strm
17*44704f69SBart Van Assche  * defaults to stderr.
18*44704f69SBart Van Assche  * If 'noisy' is false and 'verbose' is zero then following functions should
19*44704f69SBart Van Assche  * not output anything to sg_warnings_strm. If 'noisy' is true and 'verbose'
20*44704f69SBart Van Assche  * is zero then Unit Attention, Recovered, Medium and Hardware errors (sense
21*44704f69SBart Van Assche  * keys) send output to sg_warnings_strm. Increasing values of 'verbose'
22*44704f69SBart Van Assche  * send increasing amounts of (debug) output to sg_warnings_strm.
23*44704f69SBart Van Assche  */
24*44704f69SBart Van Assche 
25*44704f69SBart Van Assche #include <stdint.h>
26*44704f69SBart Van Assche #include <stdbool.h>
27*44704f69SBart Van Assche 
28*44704f69SBart Van Assche #ifdef __cplusplus
29*44704f69SBart Van Assche extern "C" {
30*44704f69SBart Van Assche #endif
31*44704f69SBart Van Assche 
32*44704f69SBart Van Assche /* Functions with the "_pt" suffix take a pointer to an object (derived from)
33*44704f69SBart Van Assche  * sg_pt_base rather than an open file descriptor as their first argument.
34*44704f69SBart Van Assche  * That object is assumed to be constructed and have a device file descriptor
35*44704f69SBart Van Assche  * associated with it. clear_scsi_pt_obj() is called at the start of each
36*44704f69SBart Van Assche  * "_pt" function. Caller is responsible for lifetime of ptp.
37*44704f69SBart Van Assche  * If the sense buffer is accessed outside the "_pt" function then the caller
38*44704f69SBart Van Assche  * must invoke set_scsi_pt_sense() _prior_ to the "_pt" function. Otherwise
39*44704f69SBart Van Assche  * a sense buffer local to "_pt" function is used.
40*44704f69SBart Van Assche  * Usually the cdb pointer will be NULL going into the "_pt" functions but
41*44704f69SBart Van Assche  * could be given by the caller in which case it will used rather than a
42*44704f69SBart Van Assche  * locally generated one. */
43*44704f69SBart Van Assche 
44*44704f69SBart Van Assche struct sg_pt_base;
45*44704f69SBart Van Assche 
46*44704f69SBart Van Assche 
47*44704f69SBart Van Assche /* Invokes a SCSI INQUIRY command and yields the response
48*44704f69SBart Van Assche  * Returns 0 when successful, SG_LIB_CAT_INVALID_OP -> not supported,
49*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
50*44704f69SBart Van Assche  * SG_LIB_CAT_ABORTED_COMMAND, a negated errno or -1 -> other errors */
51*44704f69SBart Van Assche int sg_ll_inquiry(int sg_fd, bool cmddt, bool evpd, int pg_op, void * resp,
52*44704f69SBart Van Assche                   int mx_resp_len, bool noisy, int verbose);
53*44704f69SBart Van Assche 
54*44704f69SBart Van Assche /* Invokes a SCSI INQUIRY command and yields the response. Returns 0 when
55*44704f69SBart Van Assche  * successful, various SG_LIB_CAT_* positive values, negated error or -1
56*44704f69SBart Van Assche  * for other errors. The CMDDT field is obsolete in the INQUIRY cdb (since
57*44704f69SBart Van Assche  * spc3r16 in 2003) so * an argument to set it has been removed (use the
58*44704f69SBart Van Assche  * REPORT SUPPORTED OPERATION CODES command instead). Adds the ability to
59*44704f69SBart Van Assche  * set the command abort timeout and the ability to report the residual
60*44704f69SBart Van Assche  * count. If timeout_secs is zero or less the default command abort timeout
61*44704f69SBart Van Assche  * (60 seconds) is used. If residp is non-NULL then the residual value is
62*44704f69SBart Van Assche  * written where residp points. A residual value of 0 implies mx_resp_len
63*44704f69SBart Van Assche  * bytes have be written where resp points. If the residual value equals
64*44704f69SBart Van Assche  * mx_resp_len then no bytes have been written. */
65*44704f69SBart Van Assche int sg_ll_inquiry_v2(int sg_fd, bool evpd, int pg_op, void * resp,
66*44704f69SBart Van Assche                      int mx_resp_len, int timeout_secs, int * residp,
67*44704f69SBart Van Assche                      bool noisy, int verbose);
68*44704f69SBart Van Assche 
69*44704f69SBart Van Assche /* Similar to sg_ll_inquiry_v2(). See note above about "_pt" suffix. */
70*44704f69SBart Van Assche int sg_ll_inquiry_pt(struct sg_pt_base * ptp, bool evpd, int pg_op,
71*44704f69SBart Van Assche                      void * resp, int mx_resp_len, int timeout_secs,
72*44704f69SBart Van Assche                      int * residp, bool noisy, int verbose);
73*44704f69SBart Van Assche 
74*44704f69SBart Van Assche /* Invokes a SCSI LOG SELECT command. Return of 0 -> success,
75*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Log Select not supported,
76*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
77*44704f69SBart Van Assche  * SG_LIB_CAT_ABORTED_COMMAND, * SG_LIB_CAT_NOT_READY -> device not ready,
78*44704f69SBart Van Assche  * -1 -> other failure */
79*44704f69SBart Van Assche int sg_ll_log_select(int sg_fd, bool pcr, bool sp, int pc, int pg_code,
80*44704f69SBart Van Assche                      int subpg_code, uint8_t * paramp, int param_len,
81*44704f69SBart Van Assche                      bool noisy, int verbose);
82*44704f69SBart Van Assche 
83*44704f69SBart Van Assche /* Invokes a SCSI LOG SENSE command. Return of 0 -> success,
84*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Log Sense not supported,
85*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
86*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
87*44704f69SBart Van Assche  * -1 -> other failure */
88*44704f69SBart Van Assche int sg_ll_log_sense(int sg_fd, bool ppc, bool sp, int pc, int pg_code,
89*44704f69SBart Van Assche                     int subpg_code, int paramp, uint8_t * resp,
90*44704f69SBart Van Assche                     int mx_resp_len, bool noisy, int verbose);
91*44704f69SBart Van Assche 
92*44704f69SBart Van Assche /* Same as sg_ll_log_sense() apart from timeout_secs and residp. See
93*44704f69SBart Van Assche  * sg_ll_inquiry_v2() for their description */
94*44704f69SBart Van Assche int sg_ll_log_sense_v2(int sg_fd, bool ppc, bool sp, int pc, int pg_code,
95*44704f69SBart Van Assche                        int subpg_code, int paramp, uint8_t * resp,
96*44704f69SBart Van Assche                        int mx_resp_len, int timeout_secs, int * residp,
97*44704f69SBart Van Assche                        bool noisy, int verbose);
98*44704f69SBart Van Assche 
99*44704f69SBart Van Assche /* Invokes a SCSI MODE SELECT (6) command.  Return of 0 -> success,
100*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
101*44704f69SBart Van Assche  * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
102*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND,
103*44704f69SBart Van Assche  * -1 -> other failure */
104*44704f69SBart Van Assche int sg_ll_mode_select6(int sg_fd, bool pf, bool sp, void * paramp,
105*44704f69SBart Van Assche                         int param_len, bool noisy, int verbose);
106*44704f69SBart Van Assche /* v2 adds RTD (revert to defaults) bit, added in spc5r11 */
107*44704f69SBart Van Assche int sg_ll_mode_select6_v2(int sg_fd, bool pf, bool rtd, bool sp,
108*44704f69SBart Van Assche                           void * paramp, int param_len, bool noisy,
109*44704f69SBart Van Assche                           int verbose);
110*44704f69SBart Van Assche 
111*44704f69SBart Van Assche /* Invokes a SCSI MODE SELECT (10) command.  Return of 0 -> success,
112*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
113*44704f69SBart Van Assche  * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
114*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND,
115*44704f69SBart Van Assche  * -1 -> other failure */
116*44704f69SBart Van Assche int sg_ll_mode_select10(int sg_fd, bool pf, bool sp, void * paramp,
117*44704f69SBart Van Assche                         int param_len, bool noisy, int verbose);
118*44704f69SBart Van Assche /* v2 adds RTD (revert to defaults) bit, added in spc5r11 */
119*44704f69SBart Van Assche int sg_ll_mode_select10_v2(int sg_fd, bool pf, bool rtd, bool sp,
120*44704f69SBart Van Assche                            void * paramp, int param_len, bool noisy,
121*44704f69SBart Van Assche                            int verbose);
122*44704f69SBart Van Assche 
123*44704f69SBart Van Assche /* Invokes a SCSI MODE SENSE (6) command. Return of 0 -> success,
124*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
125*44704f69SBart Van Assche  * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
126*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND,
127*44704f69SBart Van Assche  * -1 -> other failure */
128*44704f69SBart Van Assche int sg_ll_mode_sense6(int sg_fd, bool dbd, int pc, int pg_code,
129*44704f69SBart Van Assche                       int sub_pg_code, void * resp, int mx_resp_len,
130*44704f69SBart Van Assche                       bool noisy, int verbose);
131*44704f69SBart Van Assche 
132*44704f69SBart Van Assche /* Invokes a SCSI MODE SENSE (10) command. Return of 0 -> success,
133*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
134*44704f69SBart Van Assche  * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
135*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND,
136*44704f69SBart Van Assche  * -1 -> other failure */
137*44704f69SBart Van Assche int sg_ll_mode_sense10(int sg_fd, bool llbaa, bool dbd, int pc, int pg_code,
138*44704f69SBart Van Assche                        int sub_pg_code, void * resp, int mx_resp_len,
139*44704f69SBart Van Assche                        bool noisy, int verbose);
140*44704f69SBart Van Assche 
141*44704f69SBart Van Assche /* Same as sg_ll_mode_sense10() apart from timeout_secs and residp. See
142*44704f69SBart Van Assche  * sg_ll_inquiry_v2() for their description */
143*44704f69SBart Van Assche int sg_ll_mode_sense10_v2(int sg_fd, bool llbaa, bool dbd, int pc,
144*44704f69SBart Van Assche                           int pg_code, int sub_pg_code, void * resp,
145*44704f69SBart Van Assche                           int mx_resp_len, int timeout_secs, int * residp,
146*44704f69SBart Van Assche                           bool noisy, int verbose);
147*44704f69SBart Van Assche 
148*44704f69SBart Van Assche /* Invokes a SCSI PREVENT ALLOW MEDIUM REMOVAL command (SPC-3)
149*44704f69SBart Van Assche  * prevent==0 allows removal, prevent==1 prevents removal ...
150*44704f69SBart Van Assche  * Return of 0 -> success,
151*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> command not supported
152*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
153*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
154*44704f69SBart Van Assche  * -1 -> other failure */
155*44704f69SBart Van Assche int sg_ll_prevent_allow(int sg_fd, int prevent, bool noisy, int verbose);
156*44704f69SBart Van Assche 
157*44704f69SBart Van Assche /* Invokes a SCSI READ CAPACITY (10) command. Return of 0 -> success,
158*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_UNIT_ATTENTION
159*44704f69SBart Van Assche  * -> perhaps media changed, SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
160*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
161*44704f69SBart Van Assche  * -1 -> other failure */
162*44704f69SBart Van Assche int sg_ll_readcap_10(int sg_fd, bool pmi, unsigned int lba, void * resp,
163*44704f69SBart Van Assche                      int mx_resp_len, bool noisy, int verbose);
164*44704f69SBart Van Assche 
165*44704f69SBart Van Assche /* Invokes a SCSI READ CAPACITY (16) command. Returns 0 -> success,
166*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION -> media changed??, SG_LIB_CAT_INVALID_OP
167*44704f69SBart Van Assche  *  -> cdb not supported, SG_LIB_CAT_IlLEGAL_REQ -> bad field in cdb
168*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
169*44704f69SBart Van Assche  * -1 -> other failure */
170*44704f69SBart Van Assche int sg_ll_readcap_16(int sg_fd, bool pmi, uint64_t llba, void * resp,
171*44704f69SBart Van Assche                      int mx_resp_len, bool noisy, int verbose);
172*44704f69SBart Van Assche 
173*44704f69SBart Van Assche /* Invokes a SCSI REPORT LUNS command. Return of 0 -> success,
174*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Report Luns not supported,
175*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
176*44704f69SBart Van Assche  * SG_LIB_NOT_READY (shouldn't happen), -1 -> other failure */
177*44704f69SBart Van Assche int sg_ll_report_luns(int sg_fd, int select_report, void * resp,
178*44704f69SBart Van Assche                       int mx_resp_len, bool noisy, int verbose);
179*44704f69SBart Van Assche 
180*44704f69SBart Van Assche /* Similar to sg_ll_report_luns(). See note above about "_pt" suffix. */
181*44704f69SBart Van Assche int sg_ll_report_luns_pt(struct sg_pt_base * ptp, int select_report,
182*44704f69SBart Van Assche                          void * resp, int mx_resp_len, bool noisy,
183*44704f69SBart Van Assche                          int verbose);
184*44704f69SBart Van Assche 
185*44704f69SBart Van Assche /* Invokes a SCSI REQUEST SENSE command. Return of 0 -> success,
186*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Request Sense not supported??,
187*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
188*44704f69SBart Van Assche  * -1 -> other failure */
189*44704f69SBart Van Assche int sg_ll_request_sense(int sg_fd, bool desc, void * resp, int mx_resp_len,
190*44704f69SBart Van Assche                         bool noisy, int verbose);
191*44704f69SBart Van Assche 
192*44704f69SBart Van Assche /* Similar to sg_ll_request_sense(). See note above about "_pt" suffix. */
193*44704f69SBart Van Assche int sg_ll_request_sense_pt(struct sg_pt_base * ptp, bool desc, void * resp,
194*44704f69SBart Van Assche                            int mx_resp_len, bool noisy, int verbose);
195*44704f69SBart Van Assche 
196*44704f69SBart Van Assche /* Invokes a SCSI START STOP UNIT command (SBC + MMC).
197*44704f69SBart Van Assche  * Return of 0 -> success,
198*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> Start stop unit not supported,
199*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
200*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
201*44704f69SBart Van Assche  * -1 -> other failure
202*44704f69SBart Van Assche  * SBC-3 and MMC partially overlap on the power_condition_modifier(sbc) and
203*44704f69SBart Van Assche  * format_layer_number(mmc) fields. They also overlap on the noflush(sbc)
204*44704f69SBart Van Assche  * and fl(mmc) one bit field. This is the cause of the awkardly named
205*44704f69SBart Van Assche  * pc_mod__fl_num and noflush__fl arguments to this function.  */
206*44704f69SBart Van Assche int sg_ll_start_stop_unit(int sg_fd, bool immed, int pc_mod__fl_num,
207*44704f69SBart Van Assche                           int power_cond, bool noflush__fl, bool loej,
208*44704f69SBart Van Assche                           bool start, bool noisy, int verbose);
209*44704f69SBart Van Assche 
210*44704f69SBart Van Assche /* Similar to sg_ll_start_stop_unit(). See note above about "_pt" suffix. */
211*44704f69SBart Van Assche int sg_ll_start_stop_unit_pt(struct sg_pt_base * ptp, bool immed,
212*44704f69SBart Van Assche                              int pc_mod__fl_num, int power_cond,
213*44704f69SBart Van Assche                              bool noflush__fl, bool loej, bool start,
214*44704f69SBart Van Assche                              bool noisy, int verbose);
215*44704f69SBart Van Assche 
216*44704f69SBart Van Assche /* Invokes a SCSI SYNCHRONIZE CACHE (10) command. Return of 0 -> success,
217*44704f69SBart Van Assche  * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND,
218*44704f69SBart Van Assche  * SG_LIB_CAT_INVALID_OP -> cdb not supported,
219*44704f69SBart Van Assche  * SG_LIB_CAT_IlLEGAL_REQ -> bad field in cdb
220*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
221*44704f69SBart Van Assche int sg_ll_sync_cache_10(int sg_fd, bool sync_nv, bool immed, int group,
222*44704f69SBart Van Assche                         unsigned int lba, unsigned int count, bool noisy,
223*44704f69SBart Van Assche                         int verbose);
224*44704f69SBart Van Assche 
225*44704f69SBart Van Assche /* Invokes a SCSI TEST UNIT READY command.
226*44704f69SBart Van Assche  * 'pack_id' is just for diagnostics, safe to set to 0.
227*44704f69SBart Van Assche  * Return of 0 -> success, SG_LIB_CAT_UNIT_ATTENTION,
228*44704f69SBart Van Assche  * SG_LIB_CAT_NOT_READY -> device not ready,
229*44704f69SBart Van Assche  * SG_LIB_CAT_ABORTED_COMMAND, -1 -> other failure */
230*44704f69SBart Van Assche int sg_ll_test_unit_ready(int sg_fd, int pack_id, bool noisy, int verbose);
231*44704f69SBart Van Assche 
232*44704f69SBart Van Assche /* Similar to sg_ll_test_unit_ready(). See note above about "_pt" suffix. */
233*44704f69SBart Van Assche int sg_ll_test_unit_ready_pt(struct sg_pt_base * ptp, int pack_id,
234*44704f69SBart Van Assche                              bool noisy, int verbose);
235*44704f69SBart Van Assche 
236*44704f69SBart Van Assche /* Invokes a SCSI TEST UNIT READY command.
237*44704f69SBart Van Assche  * 'pack_id' is just for diagnostics, safe to set to 0.
238*44704f69SBart Van Assche  * Looks for progress indicator if 'progress' non-NULL;
239*44704f69SBart Van Assche  * if found writes value [0..65535] else write -1.
240*44704f69SBart Van Assche  * Return of 0 -> success, SG_LIB_CAT_UNIT_ATTENTION,
241*44704f69SBart Van Assche  * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_NOT_READY ->
242*44704f69SBart Van Assche  * device not ready, -1 -> other failure */
243*44704f69SBart Van Assche int sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
244*44704f69SBart Van Assche                                    bool noisy, int verbose);
245*44704f69SBart Van Assche 
246*44704f69SBart Van Assche /* Similar to sg_ll_test_unit_ready_progress(). See note above about "_pt"
247*44704f69SBart Van Assche  * suffix. */
248*44704f69SBart Van Assche int sg_ll_test_unit_ready_progress_pt(struct sg_pt_base * ptp, int pack_id,
249*44704f69SBart Van Assche                                      int * progress, bool noisy, int verbose);
250*44704f69SBart Van Assche 
251*44704f69SBart Van Assche 
252*44704f69SBart Van Assche struct sg_simple_inquiry_resp {
253*44704f69SBart Van Assche     uint8_t peripheral_qualifier;
254*44704f69SBart Van Assche     uint8_t peripheral_type;
255*44704f69SBart Van Assche     uint8_t byte_1;             /* was 'rmb' prior to version 1.39 */
256*44704f69SBart Van Assche                                 /* now rmb == !!(0x80 & byte_1) */
257*44704f69SBart Van Assche     uint8_t version;            /* as per recent drafts: whole of byte 2 */
258*44704f69SBart Van Assche     uint8_t byte_3;
259*44704f69SBart Van Assche     uint8_t byte_5;
260*44704f69SBart Van Assche     uint8_t byte_6;
261*44704f69SBart Van Assche     uint8_t byte_7;
262*44704f69SBart Van Assche     char vendor[9];             /* T10 field is 8 bytes, NUL char appended */
263*44704f69SBart Van Assche     char product[17];
264*44704f69SBart Van Assche     char revision[5];
265*44704f69SBart Van Assche };
266*44704f69SBart Van Assche 
267*44704f69SBart Van Assche /* Yields most of first 36 bytes of a standard INQUIRY (evpd==0) response.
268*44704f69SBart Van Assche  * Returns 0 when successful, SG_LIB_CAT_INVALID_OP -> not supported,
269*44704f69SBart Van Assche  * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
270*44704f69SBart Van Assche  * a negated errno or -1 -> other errors */
271*44704f69SBart Van Assche int sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
272*44704f69SBart Van Assche                       bool noisy, int verbose);
273*44704f69SBart Van Assche 
274*44704f69SBart Van Assche /* Similar to sg_simple_inquiry(). See note above about "_pt" suffix. */
275*44704f69SBart Van Assche int sg_simple_inquiry_pt(struct sg_pt_base * ptvp,
276*44704f69SBart Van Assche                          struct sg_simple_inquiry_resp * inq_data, bool noisy,
277*44704f69SBart Van Assche                          int verbose);
278*44704f69SBart Van Assche 
279*44704f69SBart Van Assche /* MODE SENSE commands yield a response that has header then zero or more
280*44704f69SBart Van Assche  * block descriptors followed by mode pages. In most cases users are
281*44704f69SBart Van Assche  * interested in the first mode page. This function returns the (byte)
282*44704f69SBart Van Assche  * offset of the start of the first mode page. Set mode_sense_6 to true for
283*44704f69SBart Van Assche  * MODE SENSE (6) and false for MODE SENSE (10). Returns >= 0 is successful
284*44704f69SBart Van Assche  * or -1 if failure. If there is a failure a message is written to err_buff
285*44704f69SBart Van Assche  * if it is non-NULL and err_buff_len > 0. */
286*44704f69SBart Van Assche int sg_mode_page_offset(const uint8_t * resp, int resp_len,
287*44704f69SBart Van Assche                         bool mode_sense_6, char * err_buff, int err_buff_len);
288*44704f69SBart Van Assche 
289*44704f69SBart Van Assche /* MODE SENSE commands yield a response that has header then zero or more
290*44704f69SBart Van Assche  * block descriptors followed by mode pages. This functions returns the
291*44704f69SBart Van Assche  * length (in bytes) of those three components. Note that the return value
292*44704f69SBart Van Assche  * can exceed resp_len in which case the MODE SENSE command should be
293*44704f69SBart Van Assche  * re-issued with a larger response buffer. If bd_lenp is non-NULL and if
294*44704f69SBart Van Assche  * successful the block descriptor length (in bytes) is written to *bd_lenp.
295*44704f69SBart Van Assche  * Set mode_sense_6 to true for MODE SENSE (6) and false for MODE SENSE (10)
296*44704f69SBart Van Assche  * responses. Returns -1 if there is an error (e.g. response too short). */
297*44704f69SBart Van Assche int sg_msense_calc_length(const uint8_t * resp, int resp_len,
298*44704f69SBart Van Assche                           bool mode_sense_6, int * bd_lenp);
299*44704f69SBart Van Assche 
300*44704f69SBart Van Assche /* Fetches current, changeable, default and/or saveable modes pages as
301*44704f69SBart Van Assche  * indicated by pcontrol_arr for given pg_code and sub_pg_code. If
302*44704f69SBart Van Assche  * mode6 is true then use MODE SENSE (6) else use MODE SENSE (10). If
303*44704f69SBart Van Assche  * flexible true and mode data length seems wrong then try and
304*44704f69SBart Van Assche  * fix (compensating hack for bad device or driver). pcontrol_arr
305*44704f69SBart Van Assche  * should have 4 elements for output of current, changeable, default
306*44704f69SBart Van Assche  * and saved values respectively. Each element should be NULL or
307*44704f69SBart Van Assche  * at least mx_mpage_len bytes long.
308*44704f69SBart Van Assche  * Return of 0 -> overall 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,
311*44704f69SBart Van Assche  * SG_LIB_CAT_MALFORMED -> bad response, -1 -> other failure.
312*44704f69SBart Van Assche  * If success_mask pointer is not NULL then first zeros it. Then set bits
313*44704f69SBart Van Assche  * 0, 1, 2 and/or 3 if the current, changeable, default and saved values
314*44704f69SBart Van Assche  * respectively have been fetched. If error on current page
315*44704f69SBart Van Assche  * then stops and returns that error; otherwise continues if an error is
316*44704f69SBart Van Assche  * detected but returns the first error encountered.  */
317*44704f69SBart Van Assche int sg_get_mode_page_controls(int sg_fd, bool mode6, int pg_code,
318*44704f69SBart Van Assche                               int sub_pg_code, bool dbd, bool flexible,
319*44704f69SBart Van Assche                               int mx_mpage_len, int * success_mask,
320*44704f69SBart Van Assche                               void * pcontrol_arr[], int * reported_lenp,
321*44704f69SBart Van Assche                               int verbose);
322*44704f69SBart Van Assche 
323*44704f69SBart Van Assche /* Returns file descriptor >= 0 if successful. If error in Unix returns
324*44704f69SBart Van Assche    negated errno. Implementation calls scsi_pt_open_device(). */
325*44704f69SBart Van Assche int sg_cmds_open_device(const char * device_name, bool read_only, int verbose);
326*44704f69SBart Van Assche 
327*44704f69SBart Van Assche /* Returns file descriptor >= 0 if successful. If error in Unix returns
328*44704f69SBart Van Assche    negated errno. Implementation calls scsi_pt_open_flags(). */
329*44704f69SBart Van Assche int sg_cmds_open_flags(const char * device_name, int flags, int verbose);
330*44704f69SBart Van Assche 
331*44704f69SBart Van Assche /* Returns 0 if successful. If error in Unix returns negated errno.
332*44704f69SBart Van Assche    Implementation calls scsi_pt_close_device(). */
333*44704f69SBart Van Assche int sg_cmds_close_device(int device_fd);
334*44704f69SBart Van Assche 
335*44704f69SBart Van Assche const char * sg_cmds_version();
336*44704f69SBart Van Assche 
337*44704f69SBart Van Assche #define SG_NO_DATA_IN 0
338*44704f69SBart Van Assche 
339*44704f69SBart Van Assche 
340*44704f69SBart Van Assche /* This is a helper function used by sg_cmds_* implementations after the
341*44704f69SBart Van Assche  * call to the pass-through. pt_res is returned from do_scsi_pt(). If valid
342*44704f69SBart Van Assche  * sense data is found it is decoded and output to sg_warnings_strm (def:
343*44704f69SBart Van Assche  * stderr); depending on the 'noisy' and 'verbose' settings. Returns -2 for
344*44704f69SBart Van Assche  * sense data (may not be fatal), -1 for failed, 0, or a positive number. If
345*44704f69SBart Van Assche  * 'mx_di_len > 0' then asks pass-through for resid and returns
346*44704f69SBart Van Assche  * (mx_di_len - resid); otherwise returns 0. So for data-in it should return
347*44704f69SBart Van Assche  * the actual number of bytes received. For data-out (to device) or no data
348*44704f69SBart Van Assche  * call with 'mx_di_len' set to 0 or less. If -2 returned then sense category
349*44704f69SBart Van Assche  * output via 'o_sense_cat' pointer (if not NULL). Note that several sense
350*44704f69SBart Van Assche  * categories also have data in bytes received; -2 is still returned. */
351*44704f69SBart Van Assche int sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin,
352*44704f69SBart Van Assche                          int pt_res, bool noisy, int verbose,
353*44704f69SBart Van Assche                          int * o_sense_cat);
354*44704f69SBart Van Assche 
355*44704f69SBart Van Assche /* NVMe devices use a different command set. This function will return true
356*44704f69SBart Van Assche  * if the device associated with 'pvtp' is a NVME device, else it will
357*44704f69SBart Van Assche  * return false (e.g. for SCSI devices). */
358*44704f69SBart Van Assche bool sg_cmds_is_nvme(const struct sg_pt_base * ptvp);
359*44704f69SBart Van Assche 
360*44704f69SBart Van Assche #ifdef __cplusplus
361*44704f69SBart Van Assche }
362*44704f69SBart Van Assche #endif
363*44704f69SBart Van Assche 
364*44704f69SBart Van Assche #endif
365