//! @brief This function displays the free space of each drive present //! void ushell_cmd_free_space( void ) { uint8_t u8_tmp; Fs_index sav_index = nav_getindex(); // Save current position for( u8_tmp=0; u8_tmp<nav_drive_nb(); u8_tmp++ ) { nav_drive_set( u8_tmp ); // Select drive if( !nav_partition_mount() ) // Mount drive continue; // Display drive letter name (a, b...) printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) ); if( g_s_arg[0][0]=='l' ) // Choose command option { // Long and exact function printf("Free space: %llu Bytes / %llu Bytes\n\r", (uint64_t)(nav_partition_freespace() << FS_SHIFT_B_TO_SECTOR), (uint64_t)(nav_partition_space() << FS_SHIFT_B_TO_SECTOR)); } else { // Otherwise use fast command printf("Free space: %u %%\n\r", nav_partition_freespace_percent() ); } } nav_gotoindex(&sav_index); // Restore position }
//! @brief This function display all drives present //! void ushell_cmd_nb_drive( void ) { uint8_t u8_tmp; printf("Memory interface available:\r\n"); for( u8_tmp=0; u8_tmp<nav_drive_nb(); u8_tmp++ ) { // Display drive letter name (a, b...) printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) ); } }
//! @brief This function displays the disk space of current drive //! void ushell_cmd_space( void ) { uint32_t u32_space; // Display drive letter name (a, b...) fputs( mem_name(nav_drive_get()), stdout); putchar(' '); putchar( nav_drive_get()+'a'); // Otherwise use fast command u32_space = nav_partition_space(); if( 1024 >(u32_space % (2*1024)) ) { u32_space = u32_space/(2*1024); }else{ u32_space = (u32_space/(2*1024))+1; } printf(": space: %luMB \n\r", u32_space ); }
bool custom_allocator::recover_alloc_info(void * page,unsigned int page_size) { MEM_BLOCK * block = (MEM_BLOCK *)page; char * end = (char *)page + page_size; while((char*)block<end) { if ( block->is_valid()==false ) return false; switch ( block->_state ) { case EMPTY_BLOCK: _free_blocks.insert(block); break; case ALLOCATED_BLOCK: { if ( block->_name_len>0 ) { // 保存名字内存映射表 std::string mem_name((char *)block + block->_size - block->_name_len,block->_name_len); mem_name += '\0'; _alloc_blocks[mem_name] = block+1; }else { // 没有名字时用地址做名字 char mem_name[256]; sprintf(mem_name,"0x%x",block); _alloc_blocks[mem_name] = block+1; } break; } default: return false; } block = (MEM_BLOCK *)((char *)block + block->_size); } return true; }
//! @brief This function manages the ls command //! //! @param b_more enable the '|more' management when true otherwise no '|more' management //! void ushell_cmd_ls( bool b_more ) { uint8_t str_char[MAX_FILE_PATH_LENGTH]; uint16_t u16_i,u16_nb_file,u16_nb_dir,last_i; uint8_t ext_filter=false; //** Print drive name printf("%c: volume is %s\r\n", 'a'+nav_drive_get(), mem_name(nav_drive_get()) ); printf("Drive uses "); switch (nav_partition_type()) { case FS_TYPE_FAT_12: printf("FAT12\n\r"); break; case FS_TYPE_FAT_16: printf("FAT16\n\r"); break; case FS_TYPE_FAT_32: printf("FAT32\n\r"); break; default: printf("an unknown partition type\r\n"); return; } //** Print directory name if( !nav_dir_name( (FS_STRING)str_char, MAX_FILE_PATH_LENGTH ) ) return; printf("Dir name is %s\n\r",str_char); //** Check extension filter in extra parameters if(g_s_arg[0][0]!=0) { if(g_s_arg[0][0] == '*' && g_s_arg[0][1]=='.') { ext_filter=true; for(u16_i=2; u16_i<USHELL_SIZE_CMD_LINE; u16_i++) { g_s_arg[0][u16_i-2]=g_s_arg[0][u16_i]; } } } //** Print files list printf(" Size Name\n\r"); // Init loop at the beginning of directory nav_filelist_reset(); u16_nb_file=0; u16_nb_dir=0; last_i=0; // For each file in list while( nav_filelist_set(0,FS_FIND_NEXT) ) { if(!ext_filter) { // No extension filter if( nav_file_isdir() ) { printf("Dir "); u16_nb_dir++; // count the number of directory }else{ printf(" "); } } else { // If extension filter then ignore directories if(nav_file_isdir()) continue; // Check extension if(!nav_file_checkext((FS_STRING)g_s_arg[0])) continue; } u16_nb_file++; // count the total of files (directories and files) // Check 'more' step if( b_more && ((u16_nb_file%USHELL_NB_LINE)==0) && (u16_nb_file!=0) && (last_i != u16_nb_file) ) { last_i=u16_nb_file; if( !ushell_more_wait() ) return; // Exit LS command } // Display file nav_file_name((FS_STRING)str_char, MAX_FILE_PATH_LENGTH, FS_NAME_GET, true); printf("%10lu %s\n\r", nav_file_lgt(), str_char); } // Display total number printf(" %4i Files\r\n", u16_nb_file-u16_nb_dir ); printf(" %4i Dir\r\n", u16_nb_dir ); }