2 * Check decoding of ioctl SG_IO v4 commands.
4 * Copyright (c) 2017-2018 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifdef HAVE_LINUX_BSG_H
14 # include <inttypes.h>
16 # include <sys/ioctl.h>
18 # include <linux/bsg.h>
20 # include "xlat/scsi_sg_commands.h"
26 printf("ioctl(-1, SG_IO, NULL) = -1 EBADF (%m)\n");
28 TAIL_ALLOC_OBJECT_CONST_PTR(struct sg_io_v4, sg_io);
29 fill_memory(sg_io, sizeof(*sg_io));
31 const void *const efault = sg_io + 1;
32 ioctl(-1, SG_IO, efault);
33 printf("ioctl(-1, SG_IO, %p) = -1 EBADF (%m)\n", efault);
35 ioctl(-1, SG_IO, sg_io);
36 printf("ioctl(-1, SG_IO, [%u]) = -1 EBADF (%m)\n", sg_io->guard);
38 TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, pguard);
39 *pguard = (unsigned char) 'Q';
40 ioctl(-1, SG_IO, pguard);
41 printf("ioctl(-1, SG_IO, {guard='Q', %p}) = -1 EBADF (%m)\n", pguard + 1);
43 sg_io->guard = (unsigned char) 'Q';
45 sg_io->subprotocol = 1;
48 sg_io->request = (kernel_ulong_t) 0xfacefeedfffffff1ULL;
49 sg_io->response = (kernel_ulong_t) 0xfacefeedfffffff2ULL;
50 sg_io->dout_xferp = (kernel_ulong_t) 0xfacefeedfffffff3ULL;
51 sg_io->din_xferp = (kernel_ulong_t) 0xfacefeedfffffff4ULL;
52 ioctl(-1, SG_IO, sg_io);
53 printf("ioctl(-1, SG_IO, {guard='Q'"
54 ", protocol=BSG_PROTOCOL_SCSI"
55 ", subprotocol=BSG_SUB_PROTOCOL_SCSI_TMF"
58 ", request_tag=%#" PRI__x64
60 ", request_priority=%u"
62 ", max_response_len=%u"
63 ", dout_iovec_count=%u"
65 ", din_iovec_count=%u"
69 ", flags=BSG_FLAG_Q_AT_TAIL|BSG_FLAG_Q_AT_HEAD|0xffffffcf"
70 ", usr_ptr=%#" PRI__x64
75 ", transport_status=%#x"
78 ", info=SG_INFO_CHECK|SG_INFO_DIRECT_IO|SG_INFO_MIXED_IO|0xfffffff8"
83 ", generated_tag=%#" PRI__x64 "}) = -1 EBADF (%m)\n",
85 (unsigned long long) (kernel_ulong_t) sg_io->request,
88 sg_io->request_priority,
90 sg_io->max_response_len,
91 sg_io->dout_iovec_count,
93 sg_io->din_iovec_count,
95 (unsigned long long) (kernel_ulong_t) sg_io->dout_xferp,
99 (unsigned long long) (kernel_ulong_t) sg_io->response,
100 (unsigned long long) (kernel_ulong_t) sg_io->din_xferp,
101 sg_io->driver_status,
102 sg_io->transport_status,
103 sg_io->device_status,
109 sg_io->generated_tag);
111 const struct iovec iov[] = {
113 .iov_base = (void *) efault - 2,
116 .iov_base = (void *) efault - 3,
120 const struct iovec *const t_iov = tail_memdup(iov, sizeof(iov));
121 sg_io->dout_iovec_count = ARRAY_SIZE(iov);
122 sg_io->dout_xfer_len = iov[0].iov_len + iov[1].iov_len - 1;
123 sg_io->dout_xferp = (unsigned long) t_iov;
125 sg_io->din_iovec_count = 0;
126 sg_io->din_xfer_len = 5;
127 sg_io->din_resid = 1;
128 sg_io->din_xferp = (unsigned long) efault -
129 (sg_io->dout_xfer_len - sg_io->din_resid);
131 sg_io->request_len = 3;
132 sg_io->request = (unsigned long) efault - sg_io->request_len;
133 sg_io->response_len = 2;
134 sg_io->response = (unsigned long) efault - sg_io->response_len;
139 ioctl(-1, SG_IO, sg_io);
140 printf("ioctl(-1, SG_IO, {guard='Q'"
141 ", protocol=BSG_PROTOCOL_SCSI"
142 ", subprotocol=BSG_SUB_PROTOCOL_SCSI_TMF"
144 ", request=\"\\x%x\\x%x\\x%x\""
145 ", request_tag=%#" PRI__x64
147 ", request_priority=%u"
149 ", max_response_len=%u"
150 ", dout_iovec_count=%u"
152 ", din_iovec_count=%u"
154 ", dout_xferp=[{iov_base=\"\\%o\\%o\", iov_len=%u}"
155 ", {iov_base=\"\\%o\\%o\\%o\", iov_len=%u}]"
156 ", timeout=%u, flags=BSG_FLAG_Q_AT_HEAD"
157 ", usr_ptr=%#" PRI__x64
159 ", response=\"\\x%x\\x%x\""
160 ", din_xferp=\"\\x%x\\x%x\\x%x\\x%x\""
161 ", driver_status=%#x"
162 ", transport_status=%#x"
163 ", device_status=%#x"
165 ", info=SG_INFO_CHECK"
170 ", generated_tag=%#" PRI__x64 "}) = -1 EBADF (%m)\n",
172 *(unsigned char *) ((unsigned long) sg_io->request + 0),
173 *(unsigned char *) ((unsigned long) sg_io->request + 1),
174 *(unsigned char *) ((unsigned long) sg_io->request + 2),
177 sg_io->request_priority,
178 sg_io->request_extra,
179 sg_io->max_response_len,
180 sg_io->dout_iovec_count,
181 sg_io->dout_xfer_len,
182 sg_io->din_iovec_count,
184 *(unsigned char *) (iov[0].iov_base + 0),
185 *(unsigned char *) (iov[0].iov_base + 1),
186 (unsigned int) iov[0].iov_len,
187 *(unsigned char *) (iov[1].iov_base + 0),
188 *(unsigned char *) (iov[1].iov_base + 1),
189 *(unsigned char *) (iov[1].iov_base + 2),
190 (unsigned int) iov[1].iov_len,
194 *(unsigned char *) ((unsigned long) sg_io->response + 0),
195 *(unsigned char *) ((unsigned long) sg_io->response + 1),
196 *(unsigned char *) ((unsigned long) sg_io->din_xferp + 0),
197 *(unsigned char *) ((unsigned long) sg_io->din_xferp + 1),
198 *(unsigned char *) ((unsigned long) sg_io->din_xferp + 2),
199 *(unsigned char *) ((unsigned long) sg_io->din_xferp + 3),
200 sg_io->driver_status,
201 sg_io->transport_status,
202 sg_io->device_status,
208 sg_io->generated_tag);
210 puts("+++ exited with 0 +++");
216 SKIP_MAIN_UNDEFINED("HAVE_LINUX_BSG_H")