2 * Copyright (c) 2007 Vladimir Nadvornik <nadvornik@suse.cz>
3 * Copyright (c) 2007-2017 Dmitry V. Levin <ldv@altlinux.org>
4 * Copyright (c) 2015 Bart Van Assche <bart.vanassche@sandisk.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include DEF_MPERS_TYPE(struct_sg_io_hdr)
38 typedef struct sg_io_hdr struct_sg_io_hdr;
40 #endif /* HAVE_SCSI_SG_H */
44 #include "xlat/sg_io_info.h"
47 # include "xlat/sg_io_dxfer_direction.h"
48 # include "xlat/sg_io_flags.h"
51 print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
52 const unsigned int data_size, const unsigned int iovec_count)
55 tprint_iov_upto(tcp, iovec_count, addr, IOV_DECODE_STR,
58 printstr_ex(tcp, addr, data_size, QUOTE_FORCE_HEX);
63 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
65 struct_sg_io_hdr sg_io;
66 static const size_t skip_iid =
67 offsetof(struct_sg_io_hdr, dxfer_direction);
69 tprints("{interface_id='S', ");
70 if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
71 &sg_io.dxfer_direction)) {
73 return RVAL_DECODED | 1;
76 tprints("dxfer_direction=");
77 printxval(sg_io_dxfer_direction, sg_io.dxfer_direction,
79 tprintf(", cmd_len=%u, cmdp=", sg_io.cmd_len);
80 print_sg_io_buffer(tcp, ptr_to_kulong(sg_io.cmdp), sg_io.cmd_len, 0);
81 tprintf(", mx_sb_len=%d", sg_io.mx_sb_len);
82 tprintf(", iovec_count=%d", sg_io.iovec_count);
83 tprintf(", dxfer_len=%u", sg_io.dxfer_len);
84 tprintf(", timeout=%u", sg_io.timeout);
86 printflags(sg_io_flags, sg_io.flags, "SG_FLAG_???");
88 if (sg_io.dxfer_direction == SG_DXFER_TO_DEV ||
89 sg_io.dxfer_direction == SG_DXFER_TO_FROM_DEV) {
91 print_sg_io_buffer(tcp, ptr_to_kulong(sg_io.dxferp),
92 sg_io.dxfer_len, sg_io.iovec_count);
95 struct_sg_io_hdr *entering_sg_io = malloc(sizeof(*entering_sg_io));
97 memcpy(entering_sg_io, &sg_io, sizeof(sg_io));
98 entering_sg_io->interface_id = (unsigned char) 'S';
99 set_tcb_priv_data(tcp, entering_sg_io, free);
106 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
108 struct_sg_io_hdr *entering_sg_io = get_tcb_priv_data(tcp);
109 struct_sg_io_hdr sg_io;
111 if (umove(tcp, arg, &sg_io) < 0) {
112 /* print i/o fields fetched on entering syscall */
113 if (entering_sg_io->dxfer_direction == SG_DXFER_FROM_DEV) {
114 tprints(", dxferp=");
115 printaddr(ptr_to_kulong(entering_sg_io->dxferp));
118 printaddr(ptr_to_kulong(entering_sg_io->sbp));
119 return RVAL_DECODED | 1;
122 if (sg_io.interface_id != entering_sg_io->interface_id) {
123 tprintf(" => interface_id=%u", sg_io.interface_id);
124 return RVAL_DECODED | 1;
127 if (sg_io.dxfer_direction == SG_DXFER_FROM_DEV ||
128 sg_io.dxfer_direction == SG_DXFER_TO_FROM_DEV) {
129 uint32_t din_len = sg_io.dxfer_len;
131 if (sg_io.resid > 0 && (unsigned int) sg_io.resid <= din_len)
132 din_len -= sg_io.resid;
133 if (sg_io.dxfer_direction == SG_DXFER_FROM_DEV) {
134 tprints(", dxferp=");
135 } else if (din_len) {
136 tprints(" => dxferp=");
138 if (sg_io.dxfer_direction == SG_DXFER_FROM_DEV || din_len) {
139 print_sg_io_buffer(tcp, ptr_to_kulong(sg_io.dxferp),
140 din_len, sg_io.iovec_count);
143 tprintf(", status=%#x", sg_io.status);
144 tprintf(", masked_status=%#x", sg_io.masked_status);
145 tprintf(", msg_status=%#x", sg_io.msg_status);
146 tprintf(", sb_len_wr=%u, sbp=", sg_io.sb_len_wr);
147 print_sg_io_buffer(tcp, ptr_to_kulong(sg_io.sbp), sg_io.sb_len_wr, 0);
148 tprintf(", host_status=%#x", sg_io.host_status);
149 tprintf(", driver_status=%#x", sg_io.driver_status);
150 tprintf(", resid=%d", sg_io.resid);
151 tprintf(", duration=%u", sg_io.duration);
153 printflags(sg_io_info, sg_io.info, "SG_INFO_???");
155 return RVAL_DECODED | 1;
158 #else /* !HAVE_SCSI_SG_H */
161 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
163 tprints("{interface_id='S', ...}");
164 return RVAL_DECODED | 1;
168 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
175 MPERS_PRINTER_DECL(int, decode_sg_io_v3,
176 struct tcb *const tcp, const kernel_ulong_t arg)
178 return entering(tcp) ? decode_request(tcp, arg)
179 : decode_response(tcp, arg);