2015-11-19 21:13:53 +03:00
/*
* Copyright ( c ) 1991 , 1992 Paul Kranenburg < pk @ cs . few . eur . nl >
* Copyright ( c ) 1993 Branko Lankester < branko @ hacktic . nl >
* Copyright ( c ) 1993 , 1994 , 1995 , 1996 Rick Sladkey < jrs @ world . std . com >
* Copyright ( c ) 1996 - 1999 Wichert Akkerman < wichert @ cistron . nl >
* Copyright ( c ) 2005 - 2015 Dmitry V . Levin < ldv @ altlinux . org >
* 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 .
*/
2014-09-12 02:40:37 +04:00
# include "defs.h"
2015-11-19 21:13:53 +03:00
# include DEF_MPERS_TYPE(kernel_dirent)
2015-11-27 04:51:22 +03:00
# include "kernel_types.h"
2015-11-19 21:13:53 +03:00
# include MPERS_DEFS
# define D_NAME_LEN_MAX 256
2014-09-12 02:40:37 +04:00
static void
print_old_dirent ( struct tcb * tcp , long addr )
{
2015-11-19 21:13:53 +03:00
kernel_dirent d ;
2014-09-12 02:40:37 +04:00
2015-07-20 18:42:22 +03:00
if ( umove_or_printaddr ( tcp , addr , & d ) )
2014-09-12 02:40:37 +04:00
return ;
2015-12-16 03:07:16 +03:00
tprintf ( " {d_ino=%llu, d_off=%llu, d_reclen=%u, d_name= " ,
2015-11-27 04:51:22 +03:00
( unsigned long long ) d . d_ino ,
( unsigned long long ) d . d_off , d . d_reclen ) ;
2015-01-25 03:04:20 +03:00
if ( d . d_reclen > D_NAME_LEN_MAX )
d . d_reclen = D_NAME_LEN_MAX ;
2015-11-19 21:13:53 +03:00
printpathn ( tcp , addr + offsetof ( kernel_dirent , d_name ) , d . d_reclen ) ;
2015-01-25 03:04:20 +03:00
tprints ( " } " ) ;
2014-09-12 02:40:37 +04:00
}
2015-04-07 04:36:50 +03:00
SYS_FUNC ( readdir )
2014-09-12 02:40:37 +04:00
{
if ( entering ( tcp ) ) {
printfd ( tcp , tcp - > u_arg [ 0 ] ) ;
tprints ( " , " ) ;
} else {
2015-07-20 18:42:22 +03:00
if ( tcp - > u_rval = = 0 )
printaddr ( tcp - > u_arg [ 1 ] ) ;
2014-09-12 02:40:37 +04:00
else
print_old_dirent ( tcp , tcp - > u_arg [ 1 ] ) ;
/* Not much point in printing this out, it is always 1. */
if ( tcp - > u_arg [ 2 ] ! = 1 )
tprintf ( " , %lu " , tcp - > u_arg [ 2 ] ) ;
}
return 0 ;
}
2015-04-07 04:36:50 +03:00
SYS_FUNC ( getdents )
2014-09-12 02:40:37 +04:00
{
unsigned int i , len , dents = 0 ;
2016-05-17 00:35:07 +03:00
unsigned char * buf ;
2014-09-12 02:40:37 +04:00
if ( entering ( tcp ) ) {
printfd ( tcp , tcp - > u_arg [ 0 ] ) ;
tprints ( " , " ) ;
return 0 ;
}
2016-04-27 01:38:10 +03:00
const unsigned int count = tcp - > u_arg [ 2 ] ;
2014-09-12 02:40:37 +04:00
if ( syserror ( tcp ) | | ! verbose ( tcp ) ) {
2015-07-20 18:42:22 +03:00
printaddr ( tcp - > u_arg [ 1 ] ) ;
2016-04-27 01:38:10 +03:00
tprintf ( " , %u " , count ) ;
2014-09-12 02:40:37 +04:00
return 0 ;
}
/* Beware of insanely large or too small values in tcp->u_rval */
if ( tcp - > u_rval > 1024 * 1024 )
len = 1024 * 1024 ;
2015-11-19 21:13:53 +03:00
else if ( tcp - > u_rval < ( int ) sizeof ( kernel_dirent ) )
2014-09-12 02:40:37 +04:00
len = 0 ;
else
len = tcp - > u_rval ;
if ( len ) {
2015-07-20 18:42:22 +03:00
buf = malloc ( len ) ;
if ( ! buf | | umoven ( tcp , tcp - > u_arg [ 1 ] , len , buf ) < 0 ) {
printaddr ( tcp - > u_arg [ 1 ] ) ;
2016-04-27 01:38:10 +03:00
tprintf ( " , %u " , count ) ;
2014-09-12 02:40:37 +04:00
free ( buf ) ;
return 0 ;
}
} else {
buf = NULL ;
}
if ( ! abbrev ( tcp ) )
2015-11-19 13:44:30 +03:00
tprints ( " [ " ) ;
2015-11-19 21:13:53 +03:00
for ( i = 0 ; len & & i < = len - sizeof ( kernel_dirent ) ; ) {
kernel_dirent * d = ( kernel_dirent * ) & buf [ i ] ;
2014-09-12 02:40:37 +04:00
if ( ! abbrev ( tcp ) ) {
2015-11-19 21:13:53 +03:00
int oob = d - > d_reclen < sizeof ( kernel_dirent ) | |
2014-09-12 02:40:37 +04:00
i + d - > d_reclen - 1 > = len ;
int d_name_len = oob ? len - i : d - > d_reclen ;
2015-11-19 21:13:53 +03:00
d_name_len - = offsetof ( kernel_dirent , d_name ) + 1 ;
2015-01-25 03:04:20 +03:00
if ( d_name_len > D_NAME_LEN_MAX )
d_name_len = D_NAME_LEN_MAX ;
2015-12-16 03:07:16 +03:00
tprintf ( " %s{d_ino=%llu, d_off=%llu, d_reclen=%u "
2015-11-27 04:51:22 +03:00
" , d_name= " , i ? " , " : " " ,
( unsigned long long ) d - > d_ino ,
( unsigned long long ) d - > d_off , d - > d_reclen ) ;
2015-01-25 03:04:20 +03:00
if ( print_quoted_string ( d - > d_name , d_name_len ,
QUOTE_0_TERMINATED ) > 0 ) {
tprints ( " ... " ) ;
}
2014-09-12 02:40:37 +04:00
2015-01-25 03:04:20 +03:00
tprints ( " , d_type= " ) ;
2014-09-12 02:40:37 +04:00
if ( oob )
tprints ( " ? " ) ;
else
2015-11-19 21:13:53 +03:00
printxval ( dirent_types , buf [ i + d - > d_reclen - 1 ] , " DT_??? " ) ;
2014-09-12 02:40:37 +04:00
tprints ( " } " ) ;
}
dents + + ;
2015-11-19 21:13:53 +03:00
if ( d - > d_reclen < sizeof ( kernel_dirent ) ) {
2015-11-27 04:51:22 +03:00
tprints ( " /* d_reclen < sizeof(struct dirent) */ " ) ;
2014-09-12 02:40:37 +04:00
break ;
}
i + = d - > d_reclen ;
}
if ( ! abbrev ( tcp ) )
2015-11-19 13:44:30 +03:00
tprints ( " ] " ) ;
2014-09-12 02:40:37 +04:00
else
tprintf ( " /* %u entries */ " , dents ) ;
2016-04-27 01:38:10 +03:00
tprintf ( " , %u " , count ) ;
2014-09-12 02:40:37 +04:00
free ( buf ) ;
return 0 ;
}