2011-01-15 23:15:31 +03:00
/*
* Copyright ( c ) 2009 , 2010 Jeff Mahoney < jeffm @ suse . com >
2016-05-26 13:43:51 +03:00
* Copyright ( c ) 2011 - 2016 Dmitry V . Levin < ldv @ altlinux . org >
2018-04-05 04:40:00 +03:00
* Copyright ( c ) 2011 - 2018 The strace developers .
2011-01-15 23:15:31 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : LGPL - 2.1 - or - later
2011-01-15 23:15:31 +03:00
*/
# include "defs.h"
2016-05-26 13:43:51 +03:00
# include DEF_MPERS_TYPE(struct_blk_user_trace_setup)
# include DEF_MPERS_TYPE(struct_blkpg_ioctl_arg)
# include DEF_MPERS_TYPE(struct_blkpg_partition)
2016-11-13 19:00:27 +03:00
# include <linux/ioctl.h>
2011-01-15 23:15:31 +03:00
# include <linux/fs.h>
2016-11-13 19:00:27 +03:00
typedef struct {
int op ;
int flags ;
int datalen ;
void * data ;
} struct_blkpg_ioctl_arg ;
# define BLKPG_DEVNAMELTH 64
# define BLKPG_VOLNAMELTH 64
typedef struct {
2016-12-19 18:59:47 +03:00
int64_t start ; /* starting offset in bytes */
int64_t length ; /* length in bytes */
2016-11-13 19:00:27 +03:00
int pno ; /* partition number */
char devname [ BLKPG_DEVNAMELTH ] ; /* partition name, like sda5 or c0d1p2,
to be used in kernel messages */
char volname [ BLKPG_VOLNAMELTH ] ; /* volume label */
} struct_blkpg_partition ;
2011-01-15 23:15:31 +03:00
# define BLKTRACE_BDEV_SIZE 32
2016-05-26 13:43:51 +03:00
typedef struct blk_user_trace_setup {
2011-01-15 23:15:31 +03:00
char name [ BLKTRACE_BDEV_SIZE ] ; /* output */
uint16_t act_mask ; /* input */
uint32_t buf_size ; /* input */
uint32_t buf_nr ; /* input */
uint64_t start_lba ;
uint64_t end_lba ;
uint32_t pid ;
2016-05-26 13:43:51 +03:00
} struct_blk_user_trace_setup ;
block: move fallback definitions for ioctl commands to xlat
* xlat/block_ioctl_cmds.in: New file.
* block.c: Include "xlat/block_ioctl_cmds.h" in XLAT_MACROS_ONLY mode.
(BLKPG, BLKTRACESETUP, BLKTRACESTART, BLKTRACESTOP, BLKTRACETEARDOWN,
BLKDISCARD, BLKIOMIN, BLKIOOPT, BLKALIGNOFF, BLKPBSZGET,
BLKDISCARDZEROES, BLKSECDISCARD, BLKROTATIONAL, BLKZEROOUT): Remove
fallback definitions as those are porvided by block_ioctl_cmds xlat now.
2018-08-25 23:02:35 +03:00
/* Provide fall-back definitions for BLK* ioctls */
# define XLAT_MACROS_ONLY
# include "xlat / block_ioctl_cmds.h"
# undef XLAT_MACROS_ONLY
2016-05-26 13:43:51 +03:00
# include MPERS_DEFS
2017-07-11 03:20:54 +03:00
# include "print_fields.h"
2014-04-26 03:30:54 +04:00
# include "xlat/blkpg_ops.h"
2011-01-15 23:15:31 +03:00
static void
2016-05-26 13:43:51 +03:00
print_blkpg_req ( struct tcb * tcp , const struct_blkpg_ioctl_arg * blkpg )
2011-01-15 23:15:31 +03:00
{
2016-05-26 13:43:51 +03:00
struct_blkpg_partition p ;
2011-01-15 23:15:31 +03:00
2017-07-13 15:38:51 +03:00
PRINT_FIELD_XVAL ( " { " , * blkpg , op , blkpg_ops , " BLKPG_??? " ) ;
PRINT_FIELD_D ( " , " , * blkpg , flags ) ;
PRINT_FIELD_D ( " , " , * blkpg , datalen ) ;
2011-01-15 23:15:31 +03:00
2017-07-13 15:38:51 +03:00
tprints ( " , data= " ) ;
2016-12-26 04:37:21 +03:00
if ( ! umove_or_printaddr ( tcp , ptr_to_kulong ( blkpg - > data ) , & p ) ) {
2017-07-13 15:38:51 +03:00
PRINT_FIELD_D ( " { " , p , start ) ;
PRINT_FIELD_D ( " , " , p , length ) ;
PRINT_FIELD_D ( " , " , p , pno ) ;
2017-07-11 03:20:54 +03:00
PRINT_FIELD_CSTRING ( " , " , p , devname ) ;
PRINT_FIELD_CSTRING ( " , " , p , volname ) ;
2015-07-05 15:15:03 +03:00
tprints ( " } " ) ;
2015-01-25 04:04:01 +03:00
}
2015-07-05 15:15:03 +03:00
tprints ( " } " ) ;
2011-01-15 23:15:31 +03:00
}
2016-12-21 06:03:09 +03:00
MPERS_PRINTER_DECL ( int , block_ioctl , struct tcb * const tcp ,
2016-12-26 13:26:03 +03:00
const unsigned int code , const kernel_ulong_t arg )
2011-01-15 23:15:31 +03:00
{
switch ( code ) {
2011-01-17 02:07:51 +03:00
/* take arg as a value, not as a pointer */
2011-01-15 23:15:31 +03:00
case BLKRASET :
case BLKFRASET :
2016-12-26 13:16:35 +03:00
tprintf ( " , % " PRI_klu , arg ) ;
2011-01-15 23:15:31 +03:00
break ;
2015-07-05 15:15:03 +03:00
/* return an unsigned short */
2011-01-15 23:15:31 +03:00
case BLKSECTGET :
2015-07-05 15:15:03 +03:00
case BLKROTATIONAL :
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printnum_short ( tcp , arg , " %hu " ) ;
2011-01-15 23:15:31 +03:00
break ;
2011-01-17 02:07:51 +03:00
/* return a signed int */
2011-01-15 23:15:31 +03:00
case BLKROGET :
case BLKBSZGET :
case BLKSSZGET :
case BLKALIGNOFF :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
2018-03-07 02:52:08 +03:00
ATTRIBUTE_FALLTHROUGH ;
2016-05-26 15:36:56 +03:00
/* take a signed int */
case BLKROSET :
case BLKBSZSET :
2015-07-05 15:15:03 +03:00
tprints ( " , " ) ;
printnum_int ( tcp , arg , " %d " ) ;
2011-01-15 23:15:31 +03:00
break ;
2011-01-17 02:07:51 +03:00
/* return an unsigned int */
2011-01-15 23:15:31 +03:00
case BLKPBSZGET :
case BLKIOMIN :
case BLKIOOPT :
case BLKDISCARDZEROES :
2018-12-17 16:45:05 +03:00
case BLKGETZONESZ :
case BLKGETNRZONES :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printnum_int ( tcp , arg , " %u " ) ;
2011-01-15 23:15:31 +03:00
break ;
2011-01-17 02:07:51 +03:00
/* return a signed long */
2011-01-15 23:15:31 +03:00
case BLKRAGET :
case BLKFRAGET :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
Fix printing tracee's long integers
Replace ambiguous printnum_long that used to fetch native long integers
from tracee's memory with printnum_ptr, printnum_slong, and printnum_ulong
that fetch tracee's pointer, signed long, and unsigned long integers.
* defs.h (printnum_long, printpair_long): Remove prototypes.
(printnum_int64, printpair_int64): Remove macros, declare functions
unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New prototype.
(printnum_ptr, printnum_slong, printnum_ulong): New macros.
* aio.c (sys_io_setup): Use printnum_ulong.
* block.c (block_ioctl): Use printnum_slong and printnum_ulong.
* get_robust_list.c (sys_get_robust_list): Use printnum_ptr
and printnum_ulong.
* io.c (print_off_t): Remove.
(sys_sendfile): Use printnum_ulong.
* ipc.c (sys_semctl): Use printnum_ptr.
* prctl.c (sys_prctl): Likewise.
* process.c (sys_ptrace): Likewise.
* rtc.c (rtc_ioctl): Use printnum_ulong.
* util.c (printnum_long, printpair_long): Remove.
(printnum_int64, printpair_int64): Define unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New function.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Elvira Khabirova <lineprinter0@gmail.com>
2015-08-18 17:58:27 +03:00
printnum_slong ( tcp , arg ) ;
2011-01-15 23:15:31 +03:00
break ;
2011-01-17 02:07:51 +03:00
/* returns an unsigned long */
2011-01-15 23:15:31 +03:00
case BLKGETSIZE :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
Fix printing tracee's long integers
Replace ambiguous printnum_long that used to fetch native long integers
from tracee's memory with printnum_ptr, printnum_slong, and printnum_ulong
that fetch tracee's pointer, signed long, and unsigned long integers.
* defs.h (printnum_long, printpair_long): Remove prototypes.
(printnum_int64, printpair_int64): Remove macros, declare functions
unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New prototype.
(printnum_ptr, printnum_slong, printnum_ulong): New macros.
* aio.c (sys_io_setup): Use printnum_ulong.
* block.c (block_ioctl): Use printnum_slong and printnum_ulong.
* get_robust_list.c (sys_get_robust_list): Use printnum_ptr
and printnum_ulong.
* io.c (print_off_t): Remove.
(sys_sendfile): Use printnum_ulong.
* ipc.c (sys_semctl): Use printnum_ptr.
* prctl.c (sys_prctl): Likewise.
* process.c (sys_ptrace): Likewise.
* rtc.c (rtc_ioctl): Use printnum_ulong.
* util.c (printnum_long, printpair_long): Remove.
(printnum_int64, printpair_int64): Define unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New function.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Elvira Khabirova <lineprinter0@gmail.com>
2015-08-18 17:58:27 +03:00
printnum_ulong ( tcp , arg ) ;
2011-01-15 23:15:31 +03:00
break ;
2015-07-05 15:15:03 +03:00
/* returns an uint64_t */
2011-01-15 23:15:31 +03:00
case BLKGETSIZE64 :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printnum_int64 ( tcp , arg , " % " PRIu64 ) ;
2011-01-15 23:15:31 +03:00
break ;
2015-07-05 15:15:03 +03:00
/* takes a pair of uint64_t */
2011-01-15 23:15:31 +03:00
case BLKDISCARD :
case BLKSECDISCARD :
2015-07-05 15:15:03 +03:00
case BLKZEROOUT :
tprints ( " , " ) ;
2016-05-26 15:33:21 +03:00
printpair_int64 ( tcp , arg , " % " PRIu64 ) ;
2011-01-15 23:15:31 +03:00
break ;
2015-07-05 15:15:03 +03:00
/* More complex types */
case BLKPG : {
2016-05-26 13:43:51 +03:00
struct_blkpg_ioctl_arg blkpg ;
2015-07-05 15:15:03 +03:00
tprints ( " , " ) ;
if ( ! umove_or_printaddr ( tcp , arg , & blkpg ) )
print_blkpg_req ( tcp , & blkpg ) ;
2011-01-15 23:15:31 +03:00
break ;
2015-07-05 15:15:03 +03:00
}
2011-01-17 02:07:51 +03:00
2011-01-15 23:15:31 +03:00
case BLKTRACESETUP :
if ( entering ( tcp ) ) {
2016-05-26 13:43:51 +03:00
struct_blk_user_trace_setup buts ;
2015-07-05 15:15:03 +03:00
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & buts ) )
break ;
2017-07-13 15:38:51 +03:00
PRINT_FIELD_U ( " { " , buts , act_mask ) ;
PRINT_FIELD_U ( " , " , buts , buf_size ) ;
PRINT_FIELD_U ( " , " , buts , buf_nr ) ;
PRINT_FIELD_U ( " , " , buts , start_lba ) ;
PRINT_FIELD_U ( " , " , buts , end_lba ) ;
PRINT_FIELD_U ( " , " , buts , pid ) ;
2017-08-27 01:18:27 +03:00
return 0 ;
2015-07-05 15:15:03 +03:00
} else {
2016-05-26 13:43:51 +03:00
struct_blk_user_trace_setup buts ;
2015-07-05 15:15:03 +03:00
2017-07-11 03:20:54 +03:00
if ( ! syserror ( tcp ) & & ! umove ( tcp , arg , & buts ) )
PRINT_FIELD_CSTRING ( " , " , buts , name ) ;
2015-07-05 15:15:03 +03:00
tprints ( " } " ) ;
break ;
2011-01-15 23:15:31 +03:00
}
2011-01-17 02:07:51 +03:00
2015-07-05 15:15:03 +03:00
/* No arguments */
case BLKRRPART :
case BLKFLSBUF :
2011-01-15 23:15:31 +03:00
case BLKTRACESTART :
case BLKTRACESTOP :
case BLKTRACETEARDOWN :
break ;
2015-07-05 15:15:03 +03:00
default :
return RVAL_DECODED ;
}
2011-01-15 23:15:31 +03:00
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2011-01-15 23:15:31 +03:00
}