scsi.c: enhance SG_IO ioctl parser

Fix SG_IO ioctl output in case of failed umove

* scsi.c: Include <linux/ioctl.h> instead of <sys/ioctl.h>.
Update for RVAL_DECODED.
(print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): Do not print address in case of failed umove.
(scsi_ioctl): Use printaddr.
This commit is contained in:
Дмитрий Левин 2015-07-07 21:38:07 +03:00
parent 317d19e8e9
commit 3d0e1f331f

108
scsi.c
View File

@ -30,7 +30,7 @@
#ifdef HAVE_SCSI_SG_H #ifdef HAVE_SCSI_SG_H
# include <sys/ioctl.h> # include <linux/ioctl.h>
# include <scsi/sg.h> # include <scsi/sg.h>
# include "xlat/sg_io_dxfer_direction.h" # include "xlat/sg_io_dxfer_direction.h"
@ -67,17 +67,16 @@ out:
tprints("]"); tprints("]");
} }
static void static int
print_sg_io_v3_req(struct tcb *tcp, long arg) print_sg_io_v3_req(struct tcb *tcp, const long arg)
{ {
struct sg_io_hdr sg_io; struct sg_io_hdr sg_io;
if (umove(tcp, arg, &sg_io) < 0) { if (umove(tcp, arg, &sg_io) < 0) {
tprintf(", %#lx", arg); tprints("???}");
return; return RVAL_DECODED | 1;
} }
tprints(", ");
printxval(sg_io_dxfer_direction, sg_io.dxfer_direction, printxval(sg_io_dxfer_direction, sg_io.dxfer_direction,
"SG_DXFER_???"); "SG_DXFER_???");
tprintf(", cmd[%u]=", sg_io.cmd_len); tprintf(", cmd[%u]=", sg_io.cmd_len);
@ -99,15 +98,16 @@ print_sg_io_v3_req(struct tcb *tcp, long arg)
print_sg_io_buffer(tcp, (unsigned long) sg_io.dxferp, print_sg_io_buffer(tcp, (unsigned long) sg_io.dxferp,
sg_io.dxfer_len); sg_io.dxfer_len);
} }
return 1;
} }
static void static void
print_sg_io_v3_res(struct tcb *tcp, long arg) print_sg_io_v3_res(struct tcb *tcp, const long arg)
{ {
struct sg_io_hdr sg_io; struct sg_io_hdr sg_io;
if (umove(tcp, arg, &sg_io) < 0) { if (umove(tcp, arg, &sg_io) < 0) {
tprintf(", %#lx", arg); tprints(", ???");
return; return;
} }
@ -139,17 +139,16 @@ print_sg_io_v3_res(struct tcb *tcp, long arg)
#ifdef HAVE_LINUX_BSG_H #ifdef HAVE_LINUX_BSG_H
static void static int
print_sg_io_v4_req(struct tcb *tcp, long arg) print_sg_io_v4_req(struct tcb *tcp, const long arg)
{ {
struct sg_io_v4 sg_io; struct sg_io_v4 sg_io;
if (umove(tcp, arg, &sg_io) < 0) { if (umove(tcp, arg, &sg_io) < 0) {
tprintf(", %#lx", arg); tprints("???}");
return; return RVAL_DECODED | 1;
} }
tprints(", ");
printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???"); printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
tprints(", "); tprints(", ");
printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???"); printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
@ -175,16 +174,17 @@ print_sg_io_v4_req(struct tcb *tcp, long arg)
1, sg_io.dout_xfer_len); 1, sg_io.dout_xfer_len);
else else
print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len); print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
return 1;
} }
static void static void
print_sg_io_v4_res(struct tcb *tcp, long arg) print_sg_io_v4_res(struct tcb *tcp, const long arg)
{ {
struct sg_io_v4 sg_io; struct sg_io_v4 sg_io;
uint32_t din_len; uint32_t din_len;
if (umove(tcp, arg, &sg_io) < 0) { if (umove(tcp, arg, &sg_io) < 0) {
tprintf(", %#lx", arg); tprints(", ???");
return; return;
} }
@ -214,78 +214,76 @@ print_sg_io_v4_res(struct tcb *tcp, long arg)
#else /* !HAVE_LINUX_BSG_H */ #else /* !HAVE_LINUX_BSG_H */
static void static int
print_sg_io_v4_req(struct tcb *tcp, long arg) print_sg_io_v4_req(struct tcb *tcp, const long arg)
{ {
tprintf(", %#lx", arg); tprints("...}");
return RVAL_DECODED | 1;
} }
static void static void
print_sg_io_v4_res(struct tcb *tcp, long arg) print_sg_io_v4_res(struct tcb *tcp, const long arg)
{ {
} }
#endif #endif
static void static int
print_sg_io_req(struct tcb *tcp, uint32_t iid, long arg) print_sg_io_req(struct tcb *tcp, uint32_t iid, const long arg)
{ {
tprintf("{'%c'", iid); tprintf("{'%c', ", iid);
switch (iid) { switch (iid) {
case 'S': case 'S':
print_sg_io_v3_req(tcp, arg); return print_sg_io_v3_req(tcp, arg);
break;
case 'Q': case 'Q':
print_sg_io_v4_req(tcp, arg); return print_sg_io_v4_req(tcp, arg);
break;
default: default:
tprints(", ..."); tprints("...}");
return RVAL_DECODED | 1;
} }
} }
static void static void
print_sg_io_res(struct tcb *tcp, uint32_t iid, long arg) print_sg_io_res(struct tcb *tcp, uint32_t iid, const long arg)
{ {
if (!syserror(tcp)) { switch (iid) {
switch (iid) { case 'S':
case 'S': print_sg_io_v3_res(tcp, arg);
print_sg_io_v3_res(tcp, arg); break;
break; case 'Q':
case 'Q': print_sg_io_v4_res(tcp, arg);
print_sg_io_v4_res(tcp, arg); break;
break;
}
} }
tprintf("}");
} }
int int
scsi_ioctl(struct tcb *tcp, const unsigned int code, long arg) scsi_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
{ {
uint32_t iid; uint32_t iid;
switch (code) { if (SG_IO != code)
case SG_IO: return RVAL_DECODED;
if (entering(tcp)) {
tprints(", "); if (entering(tcp)) {
if (umove(tcp, arg, &iid) < 0) tprints(", ");
tprintf("%#lx", arg); if (!arg || umove(tcp, arg, &iid) < 0) {
else printaddr(arg);
print_sg_io_req(tcp, iid, arg); return RVAL_DECODED | 1;
} else { } else {
if (umove(tcp, arg, &iid) >= 0) return print_sg_io_req(tcp, iid, arg);
}
} else {
if (!syserror(tcp)) {
if (umove(tcp, arg, &iid) < 0)
tprints(", ???");
else
print_sg_io_res(tcp, iid, arg); print_sg_io_res(tcp, iid, arg);
} }
break; tprintf("}");
default: return RVAL_DECODED | 1;
if (entering(tcp))
tprintf(", %#lx", arg);
break;
} }
return 1;
} }
#endif /* HAVE_SCSI_SG_H */ #endif /* HAVE_SCSI_SG_H */