2011-01-15 20:15:31 +00:00
/*
* Copyright ( c ) 2009 , 2010 Jeff Mahoney < jeffm @ suse . com >
2016-05-26 10:43:51 +00:00
* Copyright ( c ) 2011 - 2016 Dmitry V . Levin < ldv @ altlinux . org >
2017-09-05 10:01:01 +02:00
* Copyright ( c ) 2011 - 2017 The strace developers .
2011-01-15 20:15:31 +00: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 .
*/
# include "defs.h"
2016-05-26 10:43:51 +00: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 20:15:31 +00: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 15:59:47 +00: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 20:15:31 +00:00
# define BLKTRACE_BDEV_SIZE 32
2016-05-26 10:43:51 +00:00
typedef struct blk_user_trace_setup {
2011-01-15 20:15:31 +00: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 10:43:51 +00:00
} struct_blk_user_trace_setup ;
# include MPERS_DEFS
2017-07-11 00:20:54 +00:00
# include "print_fields.h"
2016-11-13 19:00:27 +03:00
# ifndef BLKPG
2017-06-17 22:23:09 +00:00
# define BLKPG _IO(0x12, 105)
2016-11-13 19:00:27 +03:00
# endif
2016-05-26 10:43:51 +00:00
/*
* ioctl numbers < = 114 are present in Linux 2.4 . The following ones have been
* added since then and headers containing them may not be available on every
* system .
*/
2011-01-15 20:15:31 +00:00
# ifndef BLKTRACESETUP
2016-05-26 10:43:51 +00:00
# define BLKTRACESETUP _IOWR(0x12, 115, struct_blk_user_trace_setup)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKTRACESTART
2017-06-17 22:23:09 +00:00
# define BLKTRACESTART _IO(0x12, 116)
2011-01-15 20:15:31 +00:00
# endif
2011-04-07 19:58:10 +00:00
# ifndef BLKTRACESTOP
2017-06-17 22:23:09 +00:00
# define BLKTRACESTOP _IO(0x12, 117)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKTRACETEARDOWN
2017-06-17 22:23:09 +00:00
# define BLKTRACETEARDOWN _IO(0x12, 118)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKDISCARD
2017-06-17 22:23:09 +00:00
# define BLKDISCARD _IO(0x12, 119)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKIOMIN
2017-06-17 22:23:09 +00:00
# define BLKIOMIN _IO(0x12, 120)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKIOOPT
2017-06-17 22:23:09 +00:00
# define BLKIOOPT _IO(0x12, 121)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKALIGNOFF
2017-06-17 22:23:09 +00:00
# define BLKALIGNOFF _IO(0x12, 122)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKPBSZGET
2017-06-17 22:23:09 +00:00
# define BLKPBSZGET _IO(0x12, 123)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKDISCARDZEROES
2017-06-17 22:23:09 +00:00
# define BLKDISCARDZEROES _IO(0x12, 124)
2011-01-15 20:15:31 +00:00
# endif
# ifndef BLKSECDISCARD
2017-06-17 22:23:09 +00:00
# define BLKSECDISCARD _IO(0x12, 125)
2015-07-05 15:15:03 +03:00
# endif
# ifndef BLKROTATIONAL
2017-06-17 22:23:09 +00:00
# define BLKROTATIONAL _IO(0x12, 126)
2015-07-05 15:15:03 +03:00
# endif
# ifndef BLKZEROOUT
2017-06-17 22:23:09 +00:00
# define BLKZEROOUT _IO(0x12, 127)
2011-01-15 20:15:31 +00:00
# endif
2014-04-25 23:30:54 +00:00
# include "xlat/blkpg_ops.h"
2011-01-15 20:15:31 +00:00
static void
2016-05-26 10:43:51 +00:00
print_blkpg_req ( struct tcb * tcp , const struct_blkpg_ioctl_arg * blkpg )
2011-01-15 20:15:31 +00:00
{
2016-05-26 10:43:51 +00:00
struct_blkpg_partition p ;
2011-01-15 20:15:31 +00:00
2017-07-13 12:38:51 +00:00
PRINT_FIELD_XVAL ( " { " , * blkpg , op , blkpg_ops , " BLKPG_??? " ) ;
PRINT_FIELD_D ( " , " , * blkpg , flags ) ;
PRINT_FIELD_D ( " , " , * blkpg , datalen ) ;
2011-01-15 20:15:31 +00:00
2017-07-13 12:38:51 +00:00
tprints ( " , data= " ) ;
2016-12-26 01:37:21 +00:00
if ( ! umove_or_printaddr ( tcp , ptr_to_kulong ( blkpg - > data ) , & p ) ) {
2017-07-13 12:38:51 +00:00
PRINT_FIELD_D ( " { " , p , start ) ;
PRINT_FIELD_D ( " , " , p , length ) ;
PRINT_FIELD_D ( " , " , p , pno ) ;
2017-07-11 00:20:54 +00:00
PRINT_FIELD_CSTRING ( " , " , p , devname ) ;
PRINT_FIELD_CSTRING ( " , " , p , volname ) ;
2015-07-05 15:15:03 +03:00
tprints ( " } " ) ;
2015-01-25 01:04:01 +00:00
}
2015-07-05 15:15:03 +03:00
tprints ( " } " ) ;
2011-01-15 20:15:31 +00:00
}
2016-12-21 03:03:09 +00:00
MPERS_PRINTER_DECL ( int , block_ioctl , struct tcb * const tcp ,
2016-12-26 10:26:03 +00:00
const unsigned int code , const kernel_ulong_t arg )
2011-01-15 20:15:31 +00:00
{
switch ( code ) {
2011-01-16 23:07:51 +00:00
/* take arg as a value, not as a pointer */
2011-01-15 20:15:31 +00:00
case BLKRASET :
case BLKFRASET :
2016-12-26 10:16:35 +00:00
tprintf ( " , % " PRI_klu , arg ) ;
2011-01-15 20:15:31 +00:00
break ;
2015-07-05 15:15:03 +03:00
/* return an unsigned short */
2011-01-15 20:15:31 +00: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 20:15:31 +00:00
break ;
2011-01-16 23:07:51 +00:00
/* return a signed int */
2011-01-15 20:15:31 +00:00
case BLKROGET :
case BLKBSZGET :
case BLKSSZGET :
case BLKALIGNOFF :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
2016-05-26 12:36:56 +00:00
/* fall through */
/* 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 20:15:31 +00:00
break ;
2011-01-16 23:07:51 +00:00
/* return an unsigned int */
2011-01-15 20:15:31 +00:00
case BLKPBSZGET :
case BLKIOMIN :
case BLKIOOPT :
case BLKDISCARDZEROES :
2015-07-05 15:15:03 +03:00
if ( entering ( tcp ) )
return 0 ;
tprints ( " , " ) ;
printnum_int ( tcp , arg , " %u " ) ;
2011-01-15 20:15:31 +00:00
break ;
2011-01-16 23:07:51 +00:00
/* return a signed long */
2011-01-15 20:15:31 +00: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 14:58:27 +00:00
printnum_slong ( tcp , arg ) ;
2011-01-15 20:15:31 +00:00
break ;
2011-01-16 23:07:51 +00:00
/* returns an unsigned long */
2011-01-15 20:15:31 +00: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 14:58:27 +00:00
printnum_ulong ( tcp , arg ) ;
2011-01-15 20:15:31 +00:00
break ;
2011-08-16 21:36:16 +00:00
# ifdef HAVE_BLKGETSIZE64
2015-07-05 15:15:03 +03:00
/* returns an uint64_t */
2011-01-15 20:15:31 +00: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 20:15:31 +00:00
break ;
2011-08-15 11:36:09 +02:00
# endif
2011-01-15 20:15:31 +00:00
2015-07-05 15:15:03 +03:00
/* takes a pair of uint64_t */
2011-01-15 20:15:31 +00:00
case BLKDISCARD :
case BLKSECDISCARD :
2015-07-05 15:15:03 +03:00
case BLKZEROOUT :
tprints ( " , " ) ;
2016-05-26 12:33:21 +00:00
printpair_int64 ( tcp , arg , " % " PRIu64 ) ;
2011-01-15 20:15:31 +00:00
break ;
2015-07-05 15:15:03 +03:00
/* More complex types */
case BLKPG : {
2016-05-26 10:43:51 +00: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 20:15:31 +00:00
break ;
2015-07-05 15:15:03 +03:00
}
2011-01-16 23:07:51 +00:00
2011-01-15 20:15:31 +00:00
case BLKTRACESETUP :
if ( entering ( tcp ) ) {
2016-05-26 10:43:51 +00: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 12:38:51 +00: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 00:18:27 +02:00
return 0 ;
2015-07-05 15:15:03 +03:00
} else {
2016-05-26 10:43:51 +00:00
struct_blk_user_trace_setup buts ;
2015-07-05 15:15:03 +03:00
2017-07-11 00:20:54 +00: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 20:15:31 +00:00
}
2011-01-16 23:07:51 +00:00
2015-07-05 15:15:03 +03:00
/* No arguments */
case BLKRRPART :
case BLKFLSBUF :
2011-01-15 20:15:31 +00:00
case BLKTRACESTART :
case BLKTRACESTOP :
case BLKTRACETEARDOWN :
break ;
2015-07-05 15:15:03 +03:00
default :
return RVAL_DECODED ;
}
2011-01-15 20:15:31 +00:00
2017-08-28 00:39:15 +00:00
return RVAL_IOCTL_DECODED ;
2011-01-15 20:15:31 +00:00
}