2006-03-25 14:07:25 +03:00
/*
2007-07-11 02:57:28 +04:00
* net / 9 p / fcprint . c
2006-03-25 14:07:25 +03:00
*
* Print 9 P call .
*
* Copyright ( C ) 2005 by Latchesar Ionkov < lucho @ ionkov . net >
*
* This program is free software ; you can redistribute it and / or modify
2006-03-25 14:07:28 +03:00
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation .
2006-03-25 14:07:25 +03:00
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to :
* Free Software Foundation
* 51 Franklin Street , Fifth Floor
* Boston , MA 02111 - 1301 USA
*
*/
# include <linux/module.h>
# include <linux/errno.h>
# include <linux/fs.h>
# include <linux/idr.h>
2007-07-11 02:57:28 +04:00
# include <net/9p/9p.h>
2006-03-25 14:07:25 +03:00
2007-07-11 02:57:28 +04:00
# ifdef CONFIG_NET_9P_DEBUG
2006-03-25 14:07:25 +03:00
static int
2007-07-11 02:57:28 +04:00
p9_printqid ( char * buf , int buflen , struct p9_qid * q )
2006-03-25 14:07:25 +03:00
{
int n ;
char b [ 10 ] ;
n = 0 ;
2007-07-11 02:57:28 +04:00
if ( q - > type & P9_QTDIR )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' d ' ;
2007-07-11 02:57:28 +04:00
if ( q - > type & P9_QTAPPEND )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' a ' ;
2007-07-11 02:57:28 +04:00
if ( q - > type & P9_QTAUTH )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' A ' ;
2007-07-11 02:57:28 +04:00
if ( q - > type & P9_QTEXCL )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' l ' ;
2007-07-11 02:57:28 +04:00
if ( q - > type & P9_QTTMP )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' t ' ;
2007-07-11 02:57:28 +04:00
if ( q - > type & P9_QTSYMLINK )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' L ' ;
b [ n ] = ' \0 ' ;
2007-07-11 02:57:28 +04:00
return scnprintf ( buf , buflen , " (%.16llx %x %s) " ,
( long long int ) q - > path , q - > version , b ) ;
2006-03-25 14:07:25 +03:00
}
static int
2007-07-11 02:57:28 +04:00
p9_printperm ( char * buf , int buflen , int perm )
2006-03-25 14:07:25 +03:00
{
int n ;
char b [ 15 ] ;
n = 0 ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMDIR )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' d ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMAPPEND )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' a ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMAUTH )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' A ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMEXCL )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' l ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMTMP )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' t ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMDEVICE )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' D ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMSOCKET )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' S ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMNAMEDPIPE )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' P ' ;
2007-07-11 02:57:28 +04:00
if ( perm & P9_DMSYMLINK )
2006-03-25 14:07:25 +03:00
b [ n + + ] = ' L ' ;
b [ n ] = ' \0 ' ;
return scnprintf ( buf , buflen , " %s%03o " , b , perm & 077 ) ;
}
static int
2007-07-11 02:57:28 +04:00
p9_printstat ( char * buf , int buflen , struct p9_stat * st , int extended )
2006-03-25 14:07:25 +03:00
{
int n ;
n = scnprintf ( buf , buflen , " '%.*s' '%.*s' " , st - > name . len ,
st - > name . str , st - > uid . len , st - > uid . str ) ;
if ( extended )
n + = scnprintf ( buf + n , buflen - n , " (%d) " , st - > n_uid ) ;
n + = scnprintf ( buf + n , buflen - n , " '%.*s' " , st - > gid . len , st - > gid . str ) ;
if ( extended )
n + = scnprintf ( buf + n , buflen - n , " (%d) " , st - > n_gid ) ;
n + = scnprintf ( buf + n , buflen - n , " '%.*s' " , st - > muid . len , st - > muid . str ) ;
if ( extended )
n + = scnprintf ( buf + n , buflen - n , " (%d) " , st - > n_muid ) ;
n + = scnprintf ( buf + n , buflen - n , " q " ) ;
2007-07-11 02:57:28 +04:00
n + = p9_printqid ( buf + n , buflen - n , & st - > qid ) ;
2006-03-25 14:07:25 +03:00
n + = scnprintf ( buf + n , buflen - n , " m " ) ;
2007-07-11 02:57:28 +04:00
n + = p9_printperm ( buf + n , buflen - n , st - > mode ) ;
2006-03-25 14:07:25 +03:00
n + = scnprintf ( buf + n , buflen - n , " at %d mt %d l %lld " ,
st - > atime , st - > mtime , ( long long int ) st - > length ) ;
if ( extended )
n + = scnprintf ( buf + n , buflen - n , " ext '%.*s' " ,
st - > extension . len , st - > extension . str ) ;
return n ;
}
static int
2007-07-11 02:57:28 +04:00
p9_dumpdata ( char * buf , int buflen , u8 * data , int datalen )
2006-03-25 14:07:25 +03:00
{
int i , n ;
i = n = 0 ;
while ( i < datalen ) {
n + = scnprintf ( buf + n , buflen - n , " %02x " , data [ i ] ) ;
if ( i % 4 = = 3 )
n + = scnprintf ( buf + n , buflen - n , " " ) ;
if ( i % 32 = = 31 )
n + = scnprintf ( buf + n , buflen - n , " \n " ) ;
i + + ;
}
n + = scnprintf ( buf + n , buflen - n , " \n " ) ;
return n ;
}
static int
2007-07-11 02:57:28 +04:00
p9_printdata ( char * buf , int buflen , u8 * data , int datalen )
2006-03-25 14:07:25 +03:00
{
2007-07-11 02:57:28 +04:00
return p9_dumpdata ( buf , buflen , data , datalen < 16 ? datalen : 16 ) ;
2006-03-25 14:07:25 +03:00
}
int
2007-07-11 02:57:28 +04:00
p9_printfcall ( char * buf , int buflen , struct p9_fcall * fc , int extended )
2006-03-25 14:07:25 +03:00
{
int i , ret , type , tag ;
if ( ! fc )
return scnprintf ( buf , buflen , " <NULL> " ) ;
type = fc - > id ;
tag = fc - > tag ;
ret = 0 ;
switch ( type ) {
2007-07-11 02:57:28 +04:00
case P9_TVERSION :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
2007-07-11 02:57:28 +04:00
" Tversion tag %u msize %u version '%.*s' " , tag ,
fc - > params . tversion . msize ,
fc - > params . tversion . version . len ,
fc - > params . tversion . version . str ) ;
2006-03-25 14:07:25 +03:00
break ;
2007-07-11 02:57:28 +04:00
case P9_RVERSION :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
2007-07-11 02:57:28 +04:00
" Rversion tag %u msize %u version '%.*s' " , tag ,
fc - > params . rversion . msize ,
fc - > params . rversion . version . len ,
fc - > params . rversion . version . str ) ;
2006-03-25 14:07:25 +03:00
break ;
2007-07-11 02:57:28 +04:00
case P9_TAUTH :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Tauth tag %u afid %d uname '%.*s' aname '%.*s' " , tag ,
fc - > params . tauth . afid , fc - > params . tauth . uname . len ,
fc - > params . tauth . uname . str , fc - > params . tauth . aname . len ,
fc - > params . tauth . aname . str ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RAUTH :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rauth tag %u qid " , tag ) ;
2007-07-11 02:57:28 +04:00
p9_printqid ( buf + ret , buflen - ret , & fc - > params . rauth . qid ) ;
2006-03-25 14:07:25 +03:00
break ;
2007-07-11 02:57:28 +04:00
case P9_TATTACH :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
2007-07-11 02:57:28 +04:00
" Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s' " , tag ,
fc - > params . tattach . fid , fc - > params . tattach . afid ,
fc - > params . tattach . uname . len , fc - > params . tattach . uname . str ,
fc - > params . tattach . aname . len , fc - > params . tattach . aname . str ) ;
2006-03-25 14:07:25 +03:00
break ;
2007-07-11 02:57:28 +04:00
case P9_RATTACH :
ret + = scnprintf ( buf + ret , buflen - ret , " Rattach tag %u qid " ,
tag ) ;
p9_printqid ( buf + ret , buflen - ret , & fc - > params . rattach . qid ) ;
2006-03-25 14:07:25 +03:00
break ;
2007-07-11 02:57:28 +04:00
case P9_RERROR :
ret + = scnprintf ( buf + ret , buflen - ret ,
" Rerror tag %u ename '%.*s' " , tag ,
fc - > params . rerror . error . len ,
fc - > params . rerror . error . str ) ;
2006-03-25 14:07:25 +03:00
if ( extended )
ret + = scnprintf ( buf + ret , buflen - ret , " ecode %d \n " ,
fc - > params . rerror . errno ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TFLUSH :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Tflush tag %u oldtag %u " ,
tag , fc - > params . tflush . oldtag ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RFLUSH :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rflush tag %u " , tag ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TWALK :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Twalk tag %u fid %d newfid %d nwname %d " , tag ,
fc - > params . twalk . fid , fc - > params . twalk . newfid ,
fc - > params . twalk . nwname ) ;
2007-07-11 02:57:28 +04:00
for ( i = 0 ; i < fc - > params . twalk . nwname ; i + + )
ret + = scnprintf ( buf + ret , buflen - ret , " '%.*s' " ,
2006-03-25 14:07:25 +03:00
fc - > params . twalk . wnames [ i ] . len ,
fc - > params . twalk . wnames [ i ] . str ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RWALK :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rwalk tag %u nwqid %d " ,
tag , fc - > params . rwalk . nwqid ) ;
2007-07-11 02:57:28 +04:00
for ( i = 0 ; i < fc - > params . rwalk . nwqid ; i + + )
ret + = p9_printqid ( buf + ret , buflen - ret ,
2006-03-25 14:07:25 +03:00
& fc - > params . rwalk . wqids [ i ] ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TOPEN :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Topen tag %u fid %d mode %d " , tag ,
fc - > params . topen . fid , fc - > params . topen . mode ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_ROPEN :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Ropen tag %u " , tag ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printqid ( buf + ret , buflen - ret , & fc - > params . ropen . qid ) ;
ret + = scnprintf ( buf + ret , buflen - ret , " iounit %d " ,
2006-03-25 14:07:25 +03:00
fc - > params . ropen . iounit ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TCREATE :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Tcreate tag %u fid %d name '%.*s' perm " , tag ,
fc - > params . tcreate . fid , fc - > params . tcreate . name . len ,
fc - > params . tcreate . name . str ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printperm ( buf + ret , buflen - ret ,
fc - > params . tcreate . perm ) ;
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " mode %d " ,
fc - > params . tcreate . mode ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RCREATE :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rcreate tag %u " , tag ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printqid ( buf + ret , buflen - ret ,
& fc - > params . rcreate . qid ) ;
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " iounit %d " ,
fc - > params . rcreate . iounit ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TREAD :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Tread tag %u fid %d offset %lld count %u " , tag ,
fc - > params . tread . fid ,
( long long int ) fc - > params . tread . offset ,
fc - > params . tread . count ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RREAD :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Rread tag %u count %u data " , tag ,
fc - > params . rread . count ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printdata ( buf + ret , buflen - ret , fc - > params . rread . data ,
2006-03-25 14:07:25 +03:00
fc - > params . rread . count ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TWRITE :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret ,
" Twrite tag %u fid %d offset %lld count %u data " ,
tag , fc - > params . twrite . fid ,
( long long int ) fc - > params . twrite . offset ,
fc - > params . twrite . count ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printdata ( buf + ret , buflen - ret , fc - > params . twrite . data ,
2006-03-25 14:07:25 +03:00
fc - > params . twrite . count ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RWRITE :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rwrite tag %u count %u " ,
tag , fc - > params . rwrite . count ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TCLUNK :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Tclunk tag %u fid %d " ,
tag , fc - > params . tclunk . fid ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RCLUNK :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rclunk tag %u " , tag ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TREMOVE :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Tremove tag %u fid %d " ,
tag , fc - > params . tremove . fid ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RREMOVE :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rremove tag %u " , tag ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TSTAT :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Tstat tag %u fid %d " ,
tag , fc - > params . tstat . fid ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_RSTAT :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rstat tag %u " , tag ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printstat ( buf + ret , buflen - ret , & fc - > params . rstat . stat ,
2006-03-25 14:07:25 +03:00
extended ) ;
break ;
2007-07-11 02:57:28 +04:00
case P9_TWSTAT :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Twstat tag %u fid %d " ,
tag , fc - > params . twstat . fid ) ;
2007-07-11 02:57:28 +04:00
ret + = p9_printstat ( buf + ret , buflen - ret ,
& fc - > params . twstat . stat , extended ) ;
2006-03-25 14:07:25 +03:00
break ;
2007-07-11 02:57:28 +04:00
case P9_RWSTAT :
2006-03-25 14:07:25 +03:00
ret + = scnprintf ( buf + ret , buflen - ret , " Rwstat tag %u " , tag ) ;
break ;
default :
ret + = scnprintf ( buf + ret , buflen - ret , " unknown type %d " , type ) ;
break ;
}
return ret ;
}
2007-07-11 02:57:28 +04:00
# else
int
p9_printfcall ( char * buf , int buflen , struct p9_fcall * fc , int extended )
{
return 0 ;
}
# endif /* CONFIG_NET_9P_DEBUG */
2008-02-07 04:25:01 +03:00
EXPORT_SYMBOL ( p9_printfcall ) ;