📄 fs_shell.c
字号:
else if ( !strncmp( "dump", token[ 0 ], 4) )
{
if ( n == 1 )
storage_dump_info( 0, 1024 );
else if ( n == 2 )
storage_dump_info( atol( token[ 1 ] ), 0 );
else if ( n == 3 )
storage_dump_info( atol( token[ 1 ] ), atol( token[ 2 ] ) );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "cs", token[ 0 ], 2) )
{
if ( n == 2 )
fsts_cs( token[ 1 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "fat", token[ 0 ], 3) )
{
if ( n == 2 )
fsts_fat( token[ 1 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "format", token[ 0 ], 6) )
{
if ( n == 1 )
fsts_format();
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "test", token[ 0 ], 4) )
{
if ( n == 1 )
fsts_test();
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "1mb", token[ 0 ], 3) )
{
if ( n == 1 )
fsts_make1mb_local( "test1mb.bin" );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "unmount", token[ 0 ], 7) )
{
if ( storage_remount( False ) )
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nCan not unmount\r\n" );
}
else if ( !strncmp( "mount", token[ 0 ], 5) )
{
if ( storage_mount() )
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nCan not mount\r\n" );
}
else if ( !strncmp( "read1", token[ 0 ], 5) )
{
if ( n == 2 )
fsts_test1( token[ 1 ], token[ 1 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments (%u)", n );
}
else
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nunknown command " );
mprintf( FSTS_NORM, CONTINUE, ": type [e] (for exit) and [return] to quit from FSTS.\r\n" );
}
}
mprintf( FSTS_NORM, CONTINUE, "\r\n" );
// Update screen info
ui_status_monitor();
// Poll the event (for topology change event)
portctl_isr_flag_routine_dspatch();
}
if ( is_in_execution )
is_in_execution = False;
}
static unsigned char split_command_string( char **token, char *string )
{
unsigned short i;
char c;
char *s;
unsigned short n = 0;
s = string;
while ( (s - string) < MAX_PATH_STRING_LENGTH )
{
while ( isspace( *s++ ) )
;
s--;
if ( !(*s) )
return ( n );
*(token + n) = s;
n++;
if ( n == MAX_COMMAND_TOKENS )
return ( n );
while ( !isspace( c = *s++ ) )
if ( !c )
return ( n );
*(s - 1) = 0;
}
return ( n );
}
static void fsts_ls( char *path )
{
directory_entry *dp;
unsigned short entries;
unsigned short valid;
unsigned short i;
unsigned short available_cluster;
unsigned short total_cluster;
unsigned short cluster_size;
unsigned char first_char;
entries = 512;
if ( NULL == (dp = (directory_entry *)malloc( sizeof( directory_entry ) * entries )) )
{
mprintf( FSTS_NORM, CONTINUE, "error : malloc @ ls command\r\n" );
return;
}
if ( fs_ls( path, dp, entries ) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nno directory \"%s\"\r\n", path );
free( dp );
return;
}
mprintf( FSTS_NORM, CONTINUE, "\r\nList of directory\r\n" );
mprintf( FSTS_NORM, CONTINUE, " attr file name date time size cluster\r\n" );
valid = 0;
for ( i = 0; i < entries; i++ )
{
first_char = *((unsigned char *)(dp + i));
if ( !first_char )
break;
if ( (first_char == 0xE5) || ((dp + i)->attributes & 0x8) )
continue;
show_file_entry( dp + i );
valid++;
if ( !((valid + 1) % 8) )
{
mprintf( FSTS_LIGHTRED, CONTINUE, " Press key to continue. Key [esc] to break.\r" );
if ( (ui_key_wait() & 0xFF) == 0x1B )
{
mprintf( FSTS_LIGHTRED, CONTINUE, " \r" );
free( dp );
return;
}
}
}
#if 1
mprintf( FSTS_NORM, CONTINUE, " valid %u / total %u entries in this directory\r\n", valid, i );
mprintf( FSTS_RED, CONTINUE, " Calculating free space.\r" );
fs_df( &available_cluster, &total_cluster, &cluster_size );
mprintf( FSTS_NORM, CONTINUE, " %6.2lf%%", ((double)(total_cluster - available_cluster) / (double)total_cluster) * 100.00 );
mprintf( FSTS_NORM, CONTINUE, " of disk space used. %luK bytes free\r\n", ((unsigned long)available_cluster) * ((unsigned long)cluster_size) >> 10 );
#endif //DEBUG
free( dp );
}
static void format_file_name_for_screen( char *str, char *filename, char *suffix )
{
unsigned char i;
for ( i = 0; i < 8; i++ )
*str++ = tolower( *filename++ );
*str++ = '.';
for ( i = 0; i < 3; i++ )
*str++ = tolower( *suffix++ );
*str = 0;
}
static unsigned char show_file_entry( directory_entry *entry_ptr )
{
char filename[ 13 ];
static char *month_name[] = { "???", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
static char attrib_char[] = { 'r', 'h', 's', 'v', 'd', 'a' };
unsigned char color;
char i;
#if 0
if ( !(*((unsigned char *)entry_ptr)) )
return ( 1 );
if ( *((unsigned char *)entry_ptr) == 0xE5 ) // deleted entry
return ( 0 );
if ( entry_ptr->attributes & 0x08 ) // This means volume label. But how can I handle this?
return ( 0 );
#endif
format_file_name_for_screen( filename, entry_ptr->filename, entry_ptr->suffix );
if ( entry_ptr->attributes & 0x10 )
color = FSTS_YELLOW;
else if ( entry_ptr->attributes & 0x06 )
color = FSTS_NORM;
else
color = FSTS_WHITE;
mprintf( color, CONTINUE, " ", entry_ptr->attributes );
for ( i = 5; i >= 0; --i )
{
if ( (entry_ptr->attributes >> i) & 0x1 )
mprintf( color, CONTINUE, "%c", attrib_char[ i ] );
else
mprintf( color, CONTINUE, "-" );
}
mprintf( color, CONTINUE, " ", entry_ptr->attributes );
mprintf( color, CONTINUE,
"%s %04d-%s-%02d %02d:%02d:%02d %10ld 0x%04X\r\n",
filename,
((entry_ptr->date) >> 9) + 1980,
month_name[ ( (entry_ptr->date) >> 5) & 0x000F ],
((entry_ptr->date) >> 0) & 0x001F,
((entry_ptr->time) >> 11),
((entry_ptr->time) >> 5) & 0x003F,
((entry_ptr->time) << 1) & 0x001F,
entry_ptr->size,
entry_ptr->cluster
);
return ( 0 );
}
static void fsts_cd( char *path )
{
if ( fs_cd( path ) )
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ndirectory could not be found\r\n" );
}
static void fsts_rm( char **path, unsigned short n, unsigned char recursive )
{
unsigned char err;
unsigned short i;
if ( n == 1 )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
return;
}
for ( i = 1; i < n; i++ )
{
if ( 0 != (err = fs_rm( *(path + i), recursive )) )
{
switch ( err )
{
case FS_RM_DIRECTORY_ACCESS_ERR :
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nrm error : FS_RM_DIRECTORY_ACCESS_ERR" );
break;
case FS_RM_SUB_DIRECTORY_EXIST :
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nrm error : FS_RM_SUB_DIRECTORY_EXIST" );
break;
default :
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nrm error : FS_RM_NOT_DIRECTORY_EMPTY" );
break;
}
}
}
}
static void fsts_mv( char *from, char *to )
{
if ( fs_mv( from, to ) )
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nfile could not be moved\r\n" );
}
/*
void fsts_clean( char **path, unsigned short n )
{
unsigned short i;
for ( i = 1; i < n; i++ )
if ( fs_rm( *(path + i) ) )
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nfile could not be found. file name : %s\r\n", *(path + i) );
}
*/
static void fsts_mkdir( char **path, unsigned short n )
{
unsigned short i;
for ( i = 1; i < n; i++ )
if ( fs_mkdir( *(path + i) ) )
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nfile could not be found. file name : %s\r\n", *(path + i) );
}
static void fsts_df( void )
{
unsigned short available_cluster;
unsigned long available;
unsigned short total_cluster;
unsigned long total;
unsigned short cluster_size;
fs_df( &available_cluster, &total_cluster, &cluster_size );
available = ((unsigned long)available_cluster * (unsigned long)cluster_size) >> 10L;
total = ((unsigned long)total_cluster * (unsigned long)cluster_size) >> 10L;
mprintf( FSTS_NORM, CONTINUE, "\r\n total(KB) used(KB) available(KB) capacity\r\n", total, total-available, available, cluster_size );
mprintf( FSTS_NORM, CONTINUE, " %9lu %9lu %9lu %5.1lf%%\r\n", total, total - available, available, ((double)(total - available) / (double)total) * 100.00, cluster_size );
}
unsigned short debug_error = 0;
unsigned char check_file_content( char *orig, char *copied );
static void fsts_test( void )
{
unsigned short i;
unsigned short prev_error;
for ( i = 0; i < 100; i++ )
{
mprintf( WHITE, CONTINUE, " ====== TEST === TEST === TEST ====== ROUND:%u (0-99))\r",i );
prev_error = debug_error;
// fsts_format();
fsts_put( "gymno1.zip", "gymno1.zip" );
fsts_get( "gymno1.zip", "got.zip" );
mprintf( WHITE, CONTINUE, "\r\nput-get done\r\n", prev_error, debug_error );
if ( prev_error != debug_error )
{
mprintf( WHITE, CONTINUE, "error happened while put\r\n" );
break;
}
if ( check_file_content( "gymno1.zip", "got.zip" ) )
break;
storage_show_cclog_result();
}
if ( i == 100 )
mprintf( (WHITE << 4), CONTINUE, "\r\nTEST completed with no problem\r\n" );
else
mprintf( (LIGHTRED << 4), CONTINUE, "\r\nTEST aborted with error (%u)\r\n", i );
storage_show_cclog_result();
}
unsigned char check_file_content( char *orig, char *copied )
{
FILE *fo;
FILE *fc;
unsigned char bo[ 10240 ];
unsigned char bc[ 10240 ];
unsigned short orig_sz;
unsigned long proc_sz = 0;
unsigned short i;
if ( NULL == (fo = fopen( orig, "rb" )) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -