/** * @brief file_scan处理非递归过程, * 删除旧的playlist(用于存储歌曲路径,用于文件定位)和lcdlist(用于存储歌曲列表,用于显示) * @param path:初始扫描路径 * @retval none */ static void file_scan(char* path) { fres = f_unlink("0:mp3player/playlist.txt");//删除旧的playlist fres = f_unlink("0:mp3player/lcdlist.txt"); //删除旧的playlist fres = scan_files(path); //递归扫描歌曲文件 }
FRESULT scan_files (char* path) { FILINFO fno; DIR dir; int i; char *fn; #if _USE_LFN static char lfn[_MAX_LFN * (_DF1S ? 2 : 1) + 1]; fno.lfname = lfn; fno.lfsize = sizeof(lfn); #endif res = f_opendir(&dir, path); if (res == FR_OK) { i = strlen(path); for (;;) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; if (fno.fname[0] == '.') continue; #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (fno.fattrib & AM_DIR) { sprintf(&path[i], "/%s", fn); res = scan_files(path); if (res != FR_OK) break; path[i] = 0; } else { printf("\r\n%s/%s", path, fn); } } } return res; }
FRESULT scan_files ( char* path /* Start node to be scanned (***also used as work area***) */ ) { FRESULT res; DIR dir; UINT i; static FILINFO fno; res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fattrib & AM_DIR) { /* It is a directory */ sprintf(&path[i = strlen(path)], "/%s", fno.fname); res = scan_files(path); /* Enter the directory */ if (res != FR_OK) break; path[i] = 0; } else { /* It is a file. */ send_uart(path); send_uart("/"); send_uart(fno.fname); send_uart("\n"); //printf("%s/%s\n", path, fno.fname); } } f_closedir(&dir); } return res; }
static FRESULT scan_files(BaseChannel *chp, char *path) { FRESULT res; FILINFO fno; DIR dir; int i; char *fn; res = f_opendir(&dir, path); if (res == FR_OK) { i = strlen(path); for (;;) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; if (fno.fname[0] == '.') continue; fn = fno.fname; if (fno.fattrib & AM_DIR) { path[i++] = '/'; strcpy(&path[i], fn); res = scan_files(chp, path); if (res != FR_OK) break; path[i] = 0; } else { chprintf(chp, "%s/%s\r\n", path, fn); } } } return res; }
/* * Executed as event handler at 500mS intervals. */ static void TimerHandler(eventid_t id) { (void)id; if (!palReadPad(IOPORT1, PA_BUTTON1)) { if (fs_ready) { FRESULT err; uint32_t clusters; FATFS *fsp; err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { chprintf((BaseSequentialStream *)&SD1, "FS: f_getfree() failed\r\n"); return; } chprintf((BaseSequentialStream *)&SD1, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)MMC_FS.csize, clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); fbuff[0] = 0; scan_files((BaseSequentialStream *)&SD1, (char *)fbuff); } } else if (!palReadPad(IOPORT1, PA_BUTTON2)) { static WORKING_AREA(waTestThread, 256); Thread *tp = chThdCreateStatic(waTestThread, sizeof(waTestThread), NORMALPRIO, TestThread, &SD1); chThdWait(tp); buzzPlay(500, MS2ST(100)); } }
static FRESULT scan_files(BaseSequentialStream *chp, char *path) { static FILINFO fno; FRESULT res; DIR dir; size_t i; char *fn; res = f_opendir(&dir, path); if (res == FR_OK) { i = strlen(path); while (((res = f_readdir(&dir, &fno)) == FR_OK) && fno.fname[0]) { if (FF_FS_RPATH && fno.fname[0] == '.') continue; fn = fno.fname; if (fno.fattrib & AM_DIR) { *(path + i) = '/'; strcpy(path + i + 1, fn); res = scan_files(chp, path); *(path + i) = '\0'; if (res != FR_OK) break; } else { chprintf(chp, "%s/%s\r\n", path, fn); } } } return res; }
static FRESULT scan_files ( char* path /* Pointer to the path name working buffer */ ) { DIR dirs; FRESULT res; BYTE i; char* fn; if ((res = f_opendir(&dirs, path)) == FR_OK) { i = strlen(path); while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { if (_FS_RPATH && Finfo.fname[0] == '.') continue; #if _USE_LFN fn = *Finfo.lfname ? Finfo.lfname : Finfo.fname; #else fn = Finfo.fname; #endif if (Finfo.fattrib & AM_DIR) { AccDirs++; *(path+i) = '/'; strcpy(path+i+1, fn); res = scan_files(path); *(path+i) = '\0'; if (res != FR_OK) break; } else { /*xprintf("%s/%s\n", path, fn);*/ AccFiles++; AccSize += Finfo.fsize; } } } return res; }
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { FRESULT err; uint32_t fre_clust; FATFS *fsp; (void)argv; if (argc > 0) { chprintf(chp, "Usage: tree\r\n"); return; } if (!fs_ready) { chprintf(chp, "File System not mounted\r\n"); return; } err = f_getfree("/", &fre_clust, &fsp); if (err != FR_OK) { chprintf(chp, "FS: f_getfree() failed\r\n"); return; } chprintf(chp, "FS: %lu free clusters with %lu sectors (%lu bytes) per cluster\r\n", fre_clust, (uint32_t)fsp->csize, (uint32_t)fsp->csize * 512); fbuff[0] = 0; scan_files(chp, (char *)fbuff); }
static FRESULT scan_files(char* path) { FRESULT res; FILINFO fno; DIR dir; int i; char *fn; res = f_opendir(&dir, path); if (res == FR_OK) { i = strlen(path); for (;;) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; fn = fno.fname; if (*fn == '.') continue; if (fno.fattrib & AM_DIR) { TRACE_MSG(&path[i], "/%s", fn); res = scan_files(path); if (res != FR_OK) break; path[i] = 0; } else { DEBUG_MSG("%s/%s", path, fn); } } } return res; }
void scan_files(char* path) { FRESULT res; FILINFO fno; DIR dir; int i; /* Open the directory */ res = f_opendir(&dir, path); if (res != FR_OK) return; i = strlen(path); do { /* Read a directory item */ res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; /* Ignore dot entry */ if (fno.fname[0] == '.') continue; /* Recursively scan subdirectories */ path[i] = '/'; strcpy(&path[i+1], fno.fname); if (fno.fattrib & AM_DIR) scan_files(path); else printf("%s\n", path); path[i] = 0; } while (1); }
void scan_root(void){ if (artist_list != NULL) {rprintf("already scanned.\n");return;} char long_pathname[40] = "0:/MUSIC"; rprintf("scanning 0:/MUSIC\n"); scan_files(long_pathname); rprintf("found artists: "); num_of_artists = 0; unsigned int num_of_tracks = 0; Artist * list_cpy = artist_list; while(list_cpy != NULL) { num_of_artists++; list_cpy->tracks = bubblesort(list_cpy->tracks); unsigned int arts_trks = 0; for (Track *tmp=list_cpy->tracks; tmp->next != NULL; tmp=tmp->next) { arts_trks++; } //counts how many tracks this artist has rprintf("%s [%i], ",list_cpy->name, arts_trks ); num_of_tracks += arts_trks; //add artist total to the overall total. list_cpy = list_cpy->next; } rprintf("\nnumber of: artists=%i, tracks=%i \n",num_of_artists,num_of_tracks); }
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) { FRESULT err; uint32_t clusters; FATFS *fsp; (void)argv; if (argc > 0) { chprintf(chp, "Usage: tree\r\n"); return; } if (!fs_ready) { chprintf(chp, "File System not mounted\r\n"); return; } err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { chprintf(chp, "FS: f_getfree() failed\r\n"); return; } chprintf(chp, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)MMC_FS.csize, clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE); fbuff[0] = 0; scan_files(chp, (char *)fbuff); }
FRESULT scan_files (char* path) { FRESULT res; FILINFO fno; DIR dir; char bufpath[12]; res = pf_opendir(&dir, path); if (res == FR_OK) { for (;;) { res = pf_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) break; if (fno.fattrib & AM_DIR) { psprintf(bufpath, "/%s", fno.fname); res = scan_files(bufpath); if (res != FR_OK) break; } else { #ifdef SERIAL_PRINT serial_printf("%s/", path); serial_printf("%s\r\n", fno.fname); #endif #ifdef CDC_PRINT CDCprintf("%s/", path); CDCprintf("%s\r\n", fno.fname); #endif } } } return res; }
static FRESULT scan_files (char* path) { DWORD acc_size; /* Work register for fs command */ WORD acc_files, acc_dirs; FILINFO finfo; DIR dirs; FRESULT res; BYTE i; if ((res = f_opendir(&dirs, path)) == FR_OK) { i = strlen(path); while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) { if (finfo.fattrib & AM_DIR) { acc_dirs++; *(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]); res = scan_files(path); *(path+i) = '\0'; if (res != FR_OK) break; } else { acc_files++; acc_size += finfo.fsize; } } } return res; }
FRESULT scan_files(char* path) { DIR dirs; FRESULT res; int i; char *fn; if ((res = f_opendir(&dirs, path)) == FR_OK) { i = strlen(path); //CDCprintln("scan path: %s", path); while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { if (_FS_RPATH && Finfo.fname[0] == '.') continue; #if _USE_LFN fn = *Finfo.lfname ? Finfo.lfname : Finfo.fname; #else fn = Finfo.fname; #endif if (Finfo.fattrib & AM_DIR) { AccDirs++; //CDCprintln("next path: %s", fn); /* FIXME: doubles code size! char * s = malloc(snprintf(NULL, 0, "%s/%s", path, fn) + 1); sprintf(s, "%s/%s", path, fn); */ res = scan_files(s); /* FIXME: seg fault path[i] = '/'; CDCprintln("#1: %s", path); mem_cpy(&path[i + 1], fn); CDCprintln("#2: %s", path); res = scan_files(path); path[i] = 0; CDCprintln("#3: %s", path); */ if (res != FR_OK) break; } else { #if 0 CDCprintln("%s/%s\n", path, fn); #endif AccFiles++; AccSize += Finfo.fsize; } } } return res; }
FRESULT play_wav(void) { FATFS fs; FRESULT rslt; volatile uint8_t dmy = 0xff; /* SS = PC0 = Out,hi */ /* SCK = PC1 = Out,lo */ /* MISO = PC2 = In, hi-z */ /* MOSI = PC3 = Out,hi */ PORTC.DIRSET = PIN0_bm; PORTC.OUTSET = PIN0_bm; PORTC.DIRSET = PIN1_bm | PIN3_bm; PORTC.OUTCLR = PIN1_bm; PORTC.OUTSET = PIN3_bm; PORTC.DIRCLR = PIN2_bm; /* Setup USART C0 as MSPI mode */ USARTC0.CTRLC = USART_CMODE_MSPI_gc; /* SPI Mode 0, MSB first */ USARTC0.CTRLB = USART_TXEN_bm | USART_RXEN_bm; USARTC0.BAUDCTRLA = 63; /* Setup DMA for USART SPI */ EDMA.CTRL = EDMA_ENABLE_bm | EDMA_CHMODE_STD02_gc | EDMA_DBUFMODE_DISABLE_gc | EDMA_PRIMODE_CH0123_gc; /* DMA Chennel0 -> Transfer from USARTC0.Data to buffer */ EDMA.CH0.ADDRCTRL = EDMA_CH_RELOAD_NONE_gc | EDMA_CH_DIR_FIXED_gc; EDMA.CH0.ADDR = (uint16_t)(&USARTC0.DATA); EDMA.CH0.DESTADDRCTRL = EDMA_CH_RELOAD_NONE_gc | EDMA_CH_DIR_INC_gc; EDMA.CH0.TRIGSRC = EDMA_CH_TRIGSRC_USARTC0_RXC_gc; /* DMA Chennel2 -> Transfer dummy 0xff to USARTC0.Data */ EDMA.CH2.ADDRCTRL = EDMA_CH_RELOAD_NONE_gc | EDMA_CH_DIR_FIXED_gc; EDMA.CH2.ADDR = (uint16_t)(&dmy); EDMA.CH2.DESTADDRCTRL = EDMA_CH_RELOAD_NONE_gc | EDMA_CH_DIR_FIXED_gc; EDMA.CH2.DESTADDR = (uint16_t)(&USARTC0.DATA); EDMA.CH2.TRIGSRC = EDMA_CH_TRIGSRC_USARTC0_DRE_gc; f_mount(&fs, "", 0); rslt = scan_files(); EDMA.CH0.CTRLA = 0; EDMA.CH2.CTRLA = 0; EDMA.CTRL = 0; USARTC0.CTRLB = 0; PORTC.OUTSET = PIN0_bm; return rslt; }
static void cmd_listfiles(BaseSequentialStream *chp, int argc, char *argv[]) { (void)argv; if (argc > 0) return; if(fs_ready) { chprintf(chp, "Listing files on the SD card ...\r\n"); scan_files(chp, rootpath); } }
void main() { FATFS fs; FIL file; InitMCU(); //VS_SinTest(0x74); VS_Init(); if(disk_initialize(0)) ConsoleWrite("Disk Initialization FAILED. :(\n"); else ConsoleWrite("Disk Initialization Complete.\n"); if(f_mount(0,&fs)) ConsoleWrite("Mount FieSystem Failed\n"); else ConsoleWrite("Mount FileSystem Success!\n"); ConsoleWrite("Scaning Music Files...\n\n"); if(scan_files("/",&(Player.TotalSongNum))) ConsoleWrite("Scan Files Failed\n"); else{ ConsoleWrite("\nScan Files Accomplished.\ntotal files: "); ConsolePutUInt (Player.TotalSongNum); ConsoleWrite ("\n\n");} if(scan_files_open (&file,"/",1)) // Start node to be scanned and opened ConsoleWrite("Open File Error\n"); //Playing mp3/track001.mp3 ... will apear in function Player.currFile = &file; Player.SongNum = 1; Player.Status = PS_PLAYING; Player.Mode = SM_SONG; Player.Volume = 170; Player.Bass = 7; Player.Treble = 0; VS_SetBassTreble(Player.Bass,Player.Treble); BufCnt = 0; // GenerateEvent(EV_BUFEMPTY); //Main loop while(1) { //Get system event Player.Event = GetEvent(); //Handle Events HandleEvent(); } }
int main(int argc, char **argv) { progname = argv[0]; buf_init(module, INIT_MODS, 1, struct _module, "modules"); buf_init(dep, INIT_MODS, 1, int, "dependencies"); stack_size = STACK_SIZE; get_options(argc, argv); if (nfiles == 0 && !dump) panic("no input files"); if (stdlib && libdir == NULL) panic("no libdir specified"); if (rtlibdir == NULL) rtlibdir = libdir; make_prim("INTERP"); make_prim("DLTRAP"); #define bind(x) def_global(find_symbol(#x), ABS, x, X_SYM) bind(GC_BASE); bind(GC_REPEAT); bind(GC_BLOCK); bind(GC_MAP); bind(GC_FLEX); bind(GC_END); bind(E_CAST); bind(E_ASSIGN); bind(E_CASE); bind(E_WITH); bind(E_ASSERT); bind(E_RETURN); bind(E_BOUND); bind(E_NULL); bind(E_DIV); bind(E_FDIV); bind(E_STACK); bind(E_GLOB); /* First pass -- check for dependencies */ scan_files(); /* Compute needed modules */ buf_grow(module); module[nmodules].m_dep = ndeps; trace_imports(); if (status != 0) return status; /* Second pass -- link the modules that are needed */ if (!dump) { init_linker(outname, interp); load_needed(); gen_main(); if (rtlibdir != NULL) save_string("LIBDIR", rtlibdir); end_linking(); } if (dump || custom) { printf("/* Primitive table -- generated by oblink */\n\n"); printf("#include \"obx.h\"\n\n"); dump_prims(stdout); } return status; }
void main(void) { char tmpbuf[128]; int f; tmpbuf[0] = '1'; tmpbuf[1] = ':'; tmpbuf[2] = 0; f = open(tmpbuf, O_RDONLY); if (f > 0) close(f); scan_files(tmpbuf); }
static FRESULT scan_files(char *path) { FRESULT res; FILINFO fno; DIR dir; int32_t i; char *pc_fn; #if _USE_LFN char c_lfn[_MAX_LFN + 1]; fno.lfname = c_lfn; fno.lfsize = sizeof(c_lfn); #endif /* Open the directory */ res = f_opendir(&dir, path); if (res == FR_OK) { i = strlen(path); for (;;) { res = f_readdir(&dir, &fno); if (res != FR_OK || fno.fname[0] == 0) { break; } #if _USE_LFN pc_fn = *fno.lfname ? fno.lfname : fno.fname; #else pc_fn = fno.fname; #endif if (*pc_fn == '.') { continue; } /* Check if it is a directory type */ if (fno.fattrib & AM_DIR) { sprintf(&path[i], "/%s", pc_fn); res = scan_files(path); if (res != FR_OK) { break; } path[i] = 0; } else { printf("%s/%s\n\r", path, pc_fn); } } } return res; }
/* 扫描磁盘BMP文件 */ static FRESULT scan_files(char* path) { FRESULT res; FILINFO fno; DIR dir; char *fn; /* This function is assuming non-Unicode cfg. */ #if _USE_LFN static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ fno.lfname = lfn; fno.lfsize = sizeof lfn; #endif char full_path[64]; res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.') continue; /* Ignore dot entry */ #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (fno.fattrib & AM_DIR) { /* It is a directory */ //printf("%s <DIR>\r\n", fn); res = scan_files(fn); if (res != FR_OK) break; } else { /* It is a file. */ //printf("File:%s\r\n", fn); if(!strncmp((const char *)(uint32_t)fn + strlen(fn)-3 , "BMP", 3)) { sprintf(full_path, "%s/%s", path, fn); printf("openning file:%s/%s...\r\n", path, fn); _DrawBMPFile(full_path); DelayMs(500); } } } f_closedir(&dir); } return res; }
FRESULT scan_files( char *path ) { FRESULT res; FILINFO fno; DIR dir; int i; char *fn; #if _USE_LFN fno.lfname = 0; fno.lfsize = 0; #endif res = f_opendir( &dir, path ); if( res == FR_OK ) { i = strlen( path ); while( true ) { res = f_readdir( &dir, &fno ); if( res != FR_OK || fno.fname[ 0 ] == 0 ) break; if( fno.fname[ 0 ] == '.' ) continue; fn = fno.fname; if( fno.fattrib & AM_DIR ) { path[ i++ ] = '/'; strcpy( &path[ i ], fn ); res = scan_files( path ); if( res != FR_OK ) break; path[ --i ] = 0; } else { CLI_PRINT( 1, "%s/%s\r\n", path, fn ); } } } return res; }
/** * @brief Fill_FileList处理非递归过程,然后调用递归函数scan_files扫描目录 * * @param path:初始扫描路径 * @retval none */ void Fill_FileList(char* path,char* record_file,WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode,int *p) { char p_path[BROWSER_FILE_NAME_LEN]={0}; //目录名 指针 char file_name[BROWSER_FILE_NAME_LEN]={0}; //用于存储的目录文件名, result = f_unlink(record_file);//删除旧的filelist // TBD 增加自建目录 result = f_open (&listfile, record_file, FA_READ|FA_WRITE|FA_CREATE_ALWAYS ); //打开创建索引文件 if(result != FR_OK) return ; strcpy(p_path,path); //复制目录名到指针 result = scan_files(p_path,file_name,&listfile,hTree,hNode,p); //递归扫描文件 f_close (&listfile); //关闭索引文件 }
void scan_dir( char *path, void (*get_file_props) (char*path,void *cb), void *cb ) { dent_t *d; char *s; int p, root = m_create(10, sizeof(dent_t)); scan_files( root, path, get_file_props, cb ); m_foreach(root,p,d) { if( d->subdir ) { asprintf(&s, "%s/%s", path, d->name ); scan_dir( s,get_file_props,cb ); free(s); } if( d->name ) free(d->name); } m_free(root); }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ int main(void) { USART_Configuration(); MSD_SPI_Configuration(); if( _card_insert() == 0 ) { printf("-- SD card detected OK \r\n"); } else { printf("-- Please connect a SD card \r\n"); while( _card_insert() != 0 ); printf("-- SD card connection detected \r\n"); Delay(0xffffff); } f_mount(0,&fs); res = f_open( &fsrc , "0:/Demo.TXT" , FA_CREATE_NEW | FA_WRITE); if ( res == FR_OK ) { /* Write buffer to file */ res = f_write(&fsrc, textFileBuffer, sizeof(textFileBuffer), &br); printf("Demo.TXT successfully created \r\n"); /*close file */ f_close(&fsrc); } else if ( res == FR_EXIST ) { printf("Demo.TXT created in the disk \r\n"); } scan_files(path); SD_TotalSize(); /* Infinite loop */ while (1){ } }
int main(int argc, char *argv[]) { if ( argc < 2 ) { g_print("buildheaderfile.exe - missing argument"); return 0; } GTimer * yimer = g_timer_new(); if (argc >= 3) { title_replace = argv[3]; //g_print("title_replace = \"%s\"\n", title_replace); if (argc >= 4) { descript_replace = argv[4]; //g_print("descript_replace = \"%s\"\n", descript_replace); } if (argc >= 5) { icon_replace = argv[5]; //g_print("icon_replace = \"%s\"\n", icon_replace); } } GString * content = NULL; gchar * output_file = g_strdup( argv[2] ); content = scan_files( argv[1] ); if ( content ) { g_print("Writing %d header to %s. Time Taken: %f\n", header_count, output_file, g_timer_elapsed(yimer, NULL) ); g_file_set_contents( output_file, content->str, -1, NULL); } g_free( output_file ); g_string_free( content, TRUE ); return 0; }
/******************************************************************************* * @函数名称 scan_files * @函数说明 搜索文件目录下所有文件 * @输入参数 path: 根目录 * @输出参数 无 * @返回参数 FRESULT * @注意事项 无 *****************************************************************************/ FRESULT scan_files (char* path ) /* Start node to be scanned (also used as work area) */ { FRESULT res; FILINFO fno; DIR dir; int i; char *fn; /* This function is assuming non-Unicode cfg. */ #if _USE_LFN static char lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = sizeof(lfn); #endif res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { i = strlen(path); for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.') continue; /* Ignore dot entry */ #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (fno.fattrib & AM_DIR) { /* It is a directory */ sprintf(&path[i], "/%s", fn); printf("scan file - %s\n\r",path); res = scan_files(path); if (res != FR_OK) break; path[i] = 0; } else { /* It is a file. */ printf("scan file - %s/%s\n\r", path, fn); } } }else{ printf("scan files error : %d\n\r",res); } return res; }
FRESULT TM_FATFS_Search(char* Folder, char* tmp_buffer, uint16_t tmp_buffer_size, TM_FATFS_Search_t* FindStructure) { uint8_t malloc_used = 0; FRESULT res; /* Reset values first */ FindStructure->FilesCount = 0; FindStructure->FoldersCount = 0; /* Check for buffer */ if (tmp_buffer == NULL) { /* Try to allocate memory */ tmp_buffer = (char *) LIB_ALLOC_FUNC(tmp_buffer_size); /* Check for success */ if (tmp_buffer == NULL) { return FR_NOT_ENOUGH_CORE; } } /* Check if there is a lot of memory allocated */ if (strlen(Folder) < tmp_buffer_size) { /* Reset TMP buffer */ tmp_buffer[0] = 0; /* Format path first */ strcpy(tmp_buffer, Folder); /* Call search function */ res = scan_files(tmp_buffer, tmp_buffer_size, FindStructure); } else { /* Not enough memory */ res = FR_NOT_ENOUGH_CORE; } /* Check for malloc */ if (malloc_used) { LIB_FREE_FUNC(tmp_buffer); } /* Return result */ return res; }
void ReadDirectoryListing(void) { FATFS *fsp; uint32_t clusters; FRESULT err; err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { report_fatfs_error(err,0); return; } /* chprintf(chp, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)SDC_FS.csize, clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); */ ((char*)fbuff)[0] = 'A'; ((char*)fbuff)[1] = 'x'; ((char*)fbuff)[2] = 'o'; ((char*)fbuff)[3] = 'd'; fbuff[1] = clusters; fbuff[2] = fsp->csize; fbuff[3] = MMCSD_BLOCK_SIZE; chSequentialStreamWrite((BaseSequentialStream * )&BDU1, (const unsigned char* )(&fbuff[0]), 16); chThdSleepMilliseconds(10); fbuff[0] = '/'; fbuff[1] = 0; scan_files((char *)&fbuff[0]); char *msg = &((char*)fbuff)[64]; msg[0] = 'A'; msg[1] = 'x'; msg[2] = 'o'; msg[3] = 'f'; *(int32_t *)(&msg[4]) = 0; *(int32_t *)(&msg[8]) = 0; msg[12] = '/'; msg[13] = 0; chSequentialStreamWrite((BaseSequentialStream * )&BDU1, (const unsigned char* )msg, 14); }