// 'ls' and 'dir' handler static void shell_ls( char* args ) { const DM_DEVICE *pdev; unsigned dev, i; DM_DIR *d; struct dm_dirent *ent; u32 total; // Iterate through all devices, looking for the ones that can do "opendir" for( dev = 0; dev < dm_get_num_devices(); dev ++ ) { pdev = dm_get_device_at( dev ); if( pdev->p_opendir_r == NULL || pdev->p_readdir_r == NULL || pdev->p_closedir_r == NULL ) continue; d = dm_opendir( pdev->name ); if( d ) { total = 0; printf( "\n%s", pdev->name ); while( ( ent = dm_readdir( d ) ) != NULL ) { printf( "\n%s", ent->fname ); for( i = strlen( ent->fname ); i <= DM_MAX_FNAME_LENGTH; i++ ) printf( " " ); printf( "%u bytes", ( unsigned )ent->fsize ); total = total + ent->fsize; } printf( "\n\nTotal on %s: %u bytes\n", pdev->name, ( unsigned )total ); dm_closedir( d ); } } printf( "\n" ); }
// Lua: res = fs_mounted( fs ) static int elua_fs_mounted( lua_State *L ) { const char *pname = luaL_checkstring( L, 1 ); DM_DIR *pdir; int res = 0; if( ( pdir = dm_opendir( pname ) ) != NULL ) { dm_closedir( pdir ); res = 1; } lua_pushboolean( L, res ); return 1; }