2 * Copyright (c) 2015 Bart Van Assche <bart.vanassche@sandisk.com>
3 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifdef HAVE_LINUX_BSG_H
33 # include <linux/bsg.h>
34 # include "xlat/bsg_protocol.h"
35 # include "xlat/bsg_subprotocol.h"
36 # include "xlat/bsg_flags.h"
39 print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
40 const unsigned int data_size, const unsigned int iovec_count)
43 tprint_iov_upto(tcp, iovec_count, addr, IOV_DECODE_STR,
46 printstr_ex(tcp, addr, data_size, QUOTE_FORCE_HEX);
51 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
53 struct sg_io_v4 sg_io;
54 static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
56 tprints("{guard='Q', ");
57 if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
60 return RVAL_DECODED | 1;
64 printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
65 tprints(", subprotocol=");
66 printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
67 tprintf(", request_len=%u, request=", sg_io.request_len);
68 print_sg_io_buffer(tcp, sg_io.request, sg_io.request_len, 0);
69 tprintf(", request_tag=%#" PRI__x64, sg_io.request_tag);
70 tprintf(", request_attr=%u", sg_io.request_attr);
71 tprintf(", request_priority=%u", sg_io.request_priority);
72 tprintf(", request_extra=%u", sg_io.request_extra);
73 tprintf(", max_response_len=%u", sg_io.max_response_len);
75 tprintf(", dout_iovec_count=%u", sg_io.dout_iovec_count);
76 tprintf(", dout_xfer_len=%u", sg_io.dout_xfer_len);
77 tprintf(", din_iovec_count=%u", sg_io.din_iovec_count);
78 tprintf(", din_xfer_len=%u", sg_io.din_xfer_len);
79 tprints(", dout_xferp=");
80 print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len,
81 sg_io.dout_iovec_count);
83 tprintf(", timeout=%u", sg_io.timeout);
85 printflags(bsg_flags, sg_io.flags, "BSG_FLAG_???");
86 tprintf(", usr_ptr=%#" PRI__x64, sg_io.usr_ptr);
88 struct sg_io_v4 *entering_sg_io = malloc(sizeof(*entering_sg_io));
90 memcpy(entering_sg_io, &sg_io, sizeof(sg_io));
91 entering_sg_io->guard = (unsigned char) 'Q';
92 set_tcb_priv_data(tcp, entering_sg_io, free);
99 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
101 struct sg_io_v4 *entering_sg_io = get_tcb_priv_data(tcp);
102 struct sg_io_v4 sg_io;
105 if (umove(tcp, arg, &sg_io) < 0) {
106 /* print i/o fields fetched on entering syscall */
107 tprints(", response=");
108 printaddr(entering_sg_io->response);
109 tprints(", din_xferp=");
110 printaddr(entering_sg_io->din_xferp);
111 return RVAL_DECODED | 1;
114 if (sg_io.guard != entering_sg_io->guard) {
115 tprintf(" => guard=%u", sg_io.guard);
116 return RVAL_DECODED | 1;
119 tprintf(", response_len=%u, response=", sg_io.response_len);
120 print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len, 0);
121 din_len = sg_io.din_xfer_len;
122 if (sg_io.din_resid > 0 && (unsigned int) sg_io.din_resid <= din_len)
123 din_len -= sg_io.din_resid;
124 tprints(", din_xferp=");
125 print_sg_io_buffer(tcp, sg_io.din_xferp, din_len,
126 sg_io.din_iovec_count);
127 tprintf(", driver_status=%#x", sg_io.driver_status);
128 tprintf(", transport_status=%#x", sg_io.transport_status);
129 tprintf(", device_status=%#x", sg_io.device_status);
130 tprintf(", retry_delay=%u", sg_io.retry_delay);
132 printflags(sg_io_info, sg_io.info, "SG_INFO_???");
133 tprintf(", duration=%u", sg_io.duration);
134 tprintf(", response_len=%u", sg_io.response_len);
135 tprintf(", din_resid=%d", sg_io.din_resid);
136 tprintf(", dout_resid=%d", sg_io.dout_resid);
137 tprintf(", generated_tag=%#" PRI__x64, sg_io.generated_tag);
139 return RVAL_DECODED | 1;
142 #else /* !HAVE_LINUX_BSG_H */
145 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
147 tprints("{guard='Q', ...}");
148 return RVAL_DECODED | 1;
152 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
160 decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
162 return entering(tcp) ? decode_request(tcp, arg)
163 : decode_response(tcp, arg);