2012-03-16 14:43:32 +04:00
/*
* Copyright ( c ) 2007 Vladimir Nadvornik < nadvornik @ suse . cz >
2017-01-07 22:01:27 +03:00
* Copyright ( c ) 2007 - 2017 Dmitry V . Levin < ldv @ altlinux . org >
2012-03-16 14:43:32 +04:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2007-06-30 15:37:09 +04:00
# include "defs.h"
2014-02-26 03:04:55 +04:00
# ifdef HAVE_SCSI_SG_H
# include <scsi / sg.h>
2017-01-08 03:01:03 +03:00
# endif
2007-06-30 15:37:09 +04:00
2017-01-09 05:40:08 +03:00
# include "xlat/scsi_sg_commands.h"
2017-01-09 19:01:08 +03:00
# include "xlat/sg_scsi_reset.h"
scsi: add bsg support
The Linux kernel supports two different versions of the SG_IO API,
namely v3 and v4. This patch adds support for version 4 of this API.
At least the sg3_utils package supports version 4 of this API. Version
4 of this API is used if /dev/bsg/H:C:I:L is used as device name.
This patch has been tested by inspecting the output of the following
commands:
modprobe scsi_debug dev_size_mb=16 delay=0
dev=$(lsscsi | sed -n '/ scsi_debug /s,^[^/]*,,p')
./strace -eioctl -s256 sg_inq $dev
echo 'Test XDWRITEREAD(10)'
bsg=/dev/bsg/$(lsscsi | sed -n '/ scsi_debug /s,^\[\([^]]\+\)\].*,\1,p')
dd if=/dev/zero bs=512 count=1 |
./strace -eioctl -s256 sg_raw -s 512 -r 1024 $bsg 53 00 00 00 00 01 00 00 01 00
* configure.ac (AC_CHECK_HEADERS): Add linux/bsg.h.
* xlat/bsg_protocol.in: New file.
* xlat/bsg_subprotocol.in: Likewise.
* scsi.c: Include them and <linux/bsg.h>.
(print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): New functions.
(print_sg_io_req, print_sg_io_res): Use them.
(scsi_ioctl): Update callers.
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-06 15:37:03 +03:00
2015-07-07 21:38:07 +03:00
static int
2017-01-08 03:01:03 +03:00
decode_sg_io ( struct tcb * const tcp , const uint32_t iid ,
const kernel_ulong_t arg )
scsi: add bsg support
The Linux kernel supports two different versions of the SG_IO API,
namely v3 and v4. This patch adds support for version 4 of this API.
At least the sg3_utils package supports version 4 of this API. Version
4 of this API is used if /dev/bsg/H:C:I:L is used as device name.
This patch has been tested by inspecting the output of the following
commands:
modprobe scsi_debug dev_size_mb=16 delay=0
dev=$(lsscsi | sed -n '/ scsi_debug /s,^[^/]*,,p')
./strace -eioctl -s256 sg_inq $dev
echo 'Test XDWRITEREAD(10)'
bsg=/dev/bsg/$(lsscsi | sed -n '/ scsi_debug /s,^\[\([^]]\+\)\].*,\1,p')
dd if=/dev/zero bs=512 count=1 |
./strace -eioctl -s256 sg_raw -s 512 -r 1024 $bsg 53 00 00 00 00 01 00 00 01 00
* configure.ac (AC_CHECK_HEADERS): Add linux/bsg.h.
* xlat/bsg_protocol.in: New file.
* xlat/bsg_subprotocol.in: Likewise.
* scsi.c: Include them and <linux/bsg.h>.
(print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): New functions.
(print_sg_io_req, print_sg_io_res): Use them.
(scsi_ioctl): Update callers.
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-06 15:37:03 +03:00
{
switch ( iid ) {
2017-01-08 03:01:03 +03:00
case ' S ' :
return decode_sg_io_v3 ( tcp , arg ) ;
case ' Q ' :
return decode_sg_io_v4 ( tcp , arg ) ;
default :
tprintf ( " [%u] " , iid ) ;
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
scsi: add bsg support
The Linux kernel supports two different versions of the SG_IO API,
namely v3 and v4. This patch adds support for version 4 of this API.
At least the sg3_utils package supports version 4 of this API. Version
4 of this API is used if /dev/bsg/H:C:I:L is used as device name.
This patch has been tested by inspecting the output of the following
commands:
modprobe scsi_debug dev_size_mb=16 delay=0
dev=$(lsscsi | sed -n '/ scsi_debug /s,^[^/]*,,p')
./strace -eioctl -s256 sg_inq $dev
echo 'Test XDWRITEREAD(10)'
bsg=/dev/bsg/$(lsscsi | sed -n '/ scsi_debug /s,^\[\([^]]\+\)\].*,\1,p')
dd if=/dev/zero bs=512 count=1 |
./strace -eioctl -s256 sg_raw -s 512 -r 1024 $bsg 53 00 00 00 00 01 00 00 01 00
* configure.ac (AC_CHECK_HEADERS): Add linux/bsg.h.
* xlat/bsg_protocol.in: New file.
* xlat/bsg_subprotocol.in: Likewise.
* scsi.c: Include them and <linux/bsg.h>.
(print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): New functions.
(print_sg_io_req, print_sg_io_res): Use them.
(scsi_ioctl): Update callers.
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-06 15:37:03 +03:00
}
}
2017-01-09 19:01:08 +03:00
# ifdef HAVE_SCSI_SG_H
static int
decode_sg_scsi_id ( struct tcb * const tcp , const kernel_ulong_t arg )
{
struct sg_scsi_id id ;
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
if ( ! umove_or_printaddr ( tcp , arg , & id ) ) {
tprintf ( " {host_no=%d "
" , channel=%d "
" , scsi_id=%#x "
" , lun=%d "
" , scsi_type=%#x "
" , h_cmd_per_lun=%hd "
" , d_queue_depth=%hd} " ,
id . host_no ,
id . channel ,
id . scsi_id ,
id . lun ,
id . scsi_type ,
id . h_cmd_per_lun ,
id . d_queue_depth ) ;
}
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2017-01-09 19:01:08 +03:00
}
# endif /* HAVE_SCSI_SG_H */
2007-06-30 15:37:09 +04:00
int
Change type of ioctl 3rd argument from long to kernel_ureg_t
* defs.h (DECL_IOCTL): Change arg type from long to kernel_ureg_t.
* dm.c (dm_known_ioctl, dm_ioctl): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* fs_x_ioctl.c (fs_x_ioctl): Likewise.
* ioctl.c (ioctl_decode): Likewise.
* loop.c (decode_loop_info, decode_loop_info64): Change addr type
from long to kernel_ureg_t.
(loop_ioctl): Change arg type from long to kernel_ureg_t.
* ptp.c (ptp_ioctl): Likewise.
* scsi.c (print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res, scsi_ioctl): Likewise.
* sock.c (print_ifreq, sock_ioctl): Likewise.
(decode_ifconf): Change addr type from long to kernel_ureg_t.
* term.c (decode_termios, decode_termio, decode_winsize, decode_ttysize,
decode_modem_flags): Likewise.
(term_ioctl): Change arg type from long to kernel_ureg_t.
* ubi.c (ubi_ioctl): Likewise.
* userfaultfd.c (uffdio_ioctl): Likewise.
2016-12-21 06:03:09 +03:00
scsi_ioctl ( struct tcb * const tcp , const unsigned int code ,
2016-12-26 13:26:03 +03:00
const kernel_ulong_t arg )
2007-06-30 15:37:09 +04:00
{
2017-01-09 16:53:27 +03:00
switch ( code ) {
case SG_IO :
if ( entering ( tcp ) ) {
uint32_t iid ;
2017-01-08 20:43:21 +03:00
2017-01-09 16:53:27 +03:00
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & iid ) ) {
break ;
} else {
return decode_sg_io ( tcp , iid , arg ) ;
}
2015-07-07 21:38:07 +03:00
} else {
2017-01-09 16:53:27 +03:00
uint32_t * piid = get_tcb_priv_data ( tcp ) ;
if ( piid )
decode_sg_io ( tcp , * piid , arg ) ;
tprints ( " } " ) ;
break ;
2015-07-07 21:38:07 +03:00
}
2017-01-09 19:01:08 +03:00
# ifdef HAVE_SCSI_SG_H
/* returns struct sg_scsi_id */
case SG_GET_SCSI_ID :
return decode_sg_scsi_id ( tcp , arg ) ;
/* returns struct sg_req_info */
case SG_GET_REQUEST_TABLE :
return decode_sg_req_info ( tcp , arg ) ;
# endif /* HAVE_SCSI_SG_H */
/* takes a value by pointer */
case SG_SCSI_RESET : {
unsigned int val ;
tprints ( " , " ) ;
if ( ! umove_or_printaddr ( tcp , arg , & val ) ) {
tprints ( " [ " ) ;
if ( val & SG_SCSI_RESET_NO_ESCALATE ) {
printxval ( sg_scsi_reset ,
SG_SCSI_RESET_NO_ESCALATE , 0 ) ;
tprints ( " | " ) ;
}
printxval ( sg_scsi_reset ,
val & ~ SG_SCSI_RESET_NO_ESCALATE ,
" SG_SCSI_RESET_??? " ) ;
tprints ( " ] " ) ;
}
break ;
}
/* takes a signed int by pointer */
case SG_NEXT_CMD_LEN :
case SG_SET_COMMAND_Q :
case SG_SET_DEBUG :
case SG_SET_FORCE_LOW_DMA :
case SG_SET_FORCE_PACK_ID :
case SG_SET_KEEP_ORPHAN :
case SG_SET_RESERVED_SIZE :
case SG_SET_TIMEOUT :
tprints ( " , " ) ;
printnum_int ( tcp , arg , " %d " ) ;
break ;
/* returns a signed int by pointer */
case SG_EMULATED_HOST :
case SG_GET_ACCESS_COUNT :
case SG_GET_COMMAND_Q :
case SG_GET_KEEP_ORPHAN :
case SG_GET_LOW_DMA :
case SG_GET_NUM_WAITING :
case SG_GET_PACK_ID :
case SG_GET_RESERVED_SIZE :
case SG_GET_SG_TABLESIZE :
case SG_GET_TRANSFORM :
case SG_GET_VERSION_NUM :
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printnum_int ( tcp , arg , " %d " ) ;
break ;
/* takes an integer by value */
case SG_SET_TRANSFORM :
tprintf ( " , %#x " , ( unsigned int ) arg ) ;
break ;
/* no arguments */
case SG_GET_TIMEOUT :
break ;
2017-01-09 16:53:27 +03:00
default :
return RVAL_DECODED ;
2007-06-30 15:37:09 +04:00
}
2017-01-09 16:53:27 +03:00
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2007-06-30 15:37:09 +04:00
}