2015-11-23 00:29:32 +03:00
/*
* Copyright ( c ) 2015 Dmitry V . Levin < ldv @ altlinux . org >
2018-12-25 02:46:43 +03:00
* Copyright ( c ) 2015 - 2018 The strace developers .
2015-11-23 00:29:32 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : LGPL - 2.1 - or - later
2015-11-23 00:29:32 +03:00
*/
# include "defs.h"
2016-10-21 00:48:50 +03:00
# include "xlat/name_to_handle_at_flags.h"
2015-11-23 00:29:32 +03:00
# ifndef MAX_HANDLE_SZ
# define MAX_HANDLE_SZ 128
# endif
typedef struct {
unsigned int handle_bytes ;
int handle_type ;
} file_handle_header ;
SYS_FUNC ( name_to_handle_at )
{
file_handle_header h ;
2016-12-26 13:26:03 +03:00
const kernel_ulong_t addr = tcp - > u_arg [ 2 ] ;
2015-11-23 00:29:32 +03:00
if ( entering ( tcp ) ) {
/* dirfd */
print_dirfd ( tcp , tcp - > u_arg [ 0 ] ) ;
/* pathname */
printpath ( tcp , tcp - > u_arg [ 1 ] ) ;
tprints ( " , " ) ;
/* handle */
if ( umove_or_printaddr ( tcp , addr , & h ) ) {
tprints ( " , " ) ;
/* mount_id */
printaddr ( tcp - > u_arg [ 3 ] ) ;
tprints ( " , " ) ;
/* flags */
2016-10-21 00:48:50 +03:00
printflags ( name_to_handle_at_flags , tcp - > u_arg [ 4 ] ,
" AT_??? " ) ;
2015-11-23 00:29:32 +03:00
return RVAL_DECODED ;
}
tprintf ( " {handle_bytes=%u " , h . handle_bytes ) ;
2016-07-15 19:08:19 +03:00
set_tcb_priv_ulong ( tcp , h . handle_bytes ) ;
2015-11-23 00:29:32 +03:00
return 0 ;
} else {
2016-07-15 19:08:19 +03:00
unsigned int i = get_tcb_priv_ulong ( tcp ) ;
2015-11-23 00:29:32 +03:00
if ( ( ! syserror ( tcp ) | | EOVERFLOW = = tcp - > u_error )
& & ! umove ( tcp , addr , & h ) ) {
unsigned char f_handle [ MAX_HANDLE_SZ ] ;
if ( i ! = h . handle_bytes )
tprintf ( " => %u " , h . handle_bytes ) ;
if ( ! syserror ( tcp ) ) {
tprintf ( " , handle_type=%d " , h . handle_type ) ;
if ( h . handle_bytes > MAX_HANDLE_SZ )
h . handle_bytes = MAX_HANDLE_SZ ;
if ( ! umoven ( tcp , addr + sizeof ( h ) , h . handle_bytes ,
f_handle ) ) {
tprints ( " , f_handle=0x " ) ;
for ( i = 0 ; i < h . handle_bytes ; + + i )
tprintf ( " %02x " , f_handle [ i ] ) ;
}
}
}
tprints ( " }, " ) ;
/* mount_id */
printnum_int ( tcp , tcp - > u_arg [ 3 ] , " %d " ) ;
tprints ( " , " ) ;
/* flags */
2016-10-21 00:48:50 +03:00
printflags ( name_to_handle_at_flags , tcp - > u_arg [ 4 ] , " AT_??? " ) ;
2015-11-23 00:29:32 +03:00
}
return 0 ;
}
SYS_FUNC ( open_by_handle_at )
{
file_handle_header h ;
2016-12-26 13:26:03 +03:00
const kernel_ulong_t addr = tcp - > u_arg [ 1 ] ;
2015-11-23 00:29:32 +03:00
/* mount_fd */
printfd ( tcp , tcp - > u_arg [ 0 ] ) ;
tprints ( " , " ) ;
/* handle */
if ( ! umove_or_printaddr ( tcp , addr , & h ) ) {
unsigned char f_handle [ MAX_HANDLE_SZ ] ;
tprintf ( " {handle_bytes=%u, handle_type=%d " ,
h . handle_bytes , h . handle_type ) ;
if ( h . handle_bytes > MAX_HANDLE_SZ )
h . handle_bytes = MAX_HANDLE_SZ ;
if ( ! umoven ( tcp , addr + sizeof ( h ) , h . handle_bytes , & f_handle ) ) {
unsigned int i ;
tprints ( " , f_handle=0x " ) ;
for ( i = 0 ; i < h . handle_bytes ; + + i )
tprintf ( " %02x " , f_handle [ i ] ) ;
}
tprints ( " } " ) ;
}
tprints ( " , " ) ;
/* flags */
tprint_open_modes ( tcp - > u_arg [ 2 ] ) ;
return RVAL_DECODED ;
}