void scan_root(char *dir, char* dirFullPath, int* depth, int maxDepth) // 定义目录扫描函数 { DIR *dp; // 定义子目录流指针 struct dirent *entry; // 定义dirent结构指针保存后续目录 struct stat statbuf; // 定义statbuf结构保存文件属性 char* path = NULL; int currentDepth; (*depth)++; if (*depth == maxDepth) { return; } currentDepth = *depth; if((dp = opendir(dir)) == NULL) // 打开目录,获取子目录流指针,判断操作是否成功 { puts("can't open dir."); return; } chdir (dir); // 切换到当前目录 while((entry = readdir(dp)) != NULL) // 获取下一级目录信息,如果未否则循环 { path = createFullName(dirFullPath, entry->d_name); lstat(entry->d_name, &statbuf); // 获取下一级成员属性 if(S_IFDIR & statbuf.st_mode) // 判断下一级成员是否是目录 { if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0) continue; // printf("%s\n", path); // 输出目录名称 scan_root(entry->d_name, path, depth, maxDepth); // 递归调用自身,扫描下一级目录的内容 *depth = currentDepth; } else if (S_IFREG & statbuf.st_mode) { //判断下一级成员是否是一般文件 //printf("%s\n", path); // 输出文件名称 char* copy = malloc((strlen(path) + 1) * sizeof(char)); strcpy(copy, path); pqueue_put(&pqb, (void *) copy); } //fprintf(stdout, "%s\n", path); // free(path); } chdir(".."); // 回到上级目录 closedir(dp); // 关闭子目录流 }
NTSTATUS WINAPI VfatChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback) { #if 0 BOOLEAN verify; BOOLEAN salvage_files; #endif //ULONG free_clusters; //DOS_FS fs; /* Store callback pointer */ ChkdskCallback = Callback; FsCheckMemQueue = NULL; /* Set parameters */ FsCheckFlags = 0; if (Verbose) FsCheckFlags |= FSCHECK_VERBOSE; FsCheckTotalFiles = 0; #if 0 verify = TRUE; salvage_files = TRUE; /* Open filesystem */ fs_open(DriveRoot,FixErrors); if (CheckOnlyIfDirty && !fs_isdirty()) { /* No need to check FS */ return fs_close(FALSE); } read_boot(&fs); if (verify) VfatPrint("Starting check/repair pass.\n"); while (read_fat(&fs), scan_root(&fs)) qfree(&FsCheckMemQueue); if (ScanDrive) fix_bad(&fs); if (salvage_files) reclaim_file(&fs); else reclaim_free(&fs); free_clusters = update_free(&fs); file_unused(); qfree(&FsCheckMemQueue); if (verify) { VfatPrint("Starting verification pass.\n"); read_fat(&fs); scan_root(&fs); reclaim_free(&fs); qfree(&FsCheckMemQueue); } if (fs_changed()) { if (FixErrors) { if (FsCheckFlags & FSCHECK_INTERACTIVE) FixErrors = get_key("yn","Perform changes ? (y/n)") == 'y'; else VfatPrint("Performing changes.\n"); } else { VfatPrint("Leaving file system unchanged.\n"); } } VfatPrint("%wZ: %u files, %lu/%lu clusters\n", DriveRoot, FsCheckTotalFiles, fs.clusters - free_clusters, fs.clusters ); if (FixErrors) { /* Dismount the volume */ fs_dismount(); /* Unlock the volume */ fs_lock(FALSE); } /* Close the volume */ return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; #else return STATUS_SUCCESS; #endif }
int main(int argc, char **argv) { DOS_FS fs; int salvage_files, verify, c; uint32_t free_clusters = 0; memset(&fs, 0, sizeof(fs)); salvage_files = verify = 0; rw = interactive = 1; check_atari(); while ((c = getopt(argc, argv, "Aac:d:bflnprtu:vVwy")) != -1) switch (c) { case 'A': /* toggle Atari format */ atari_format = !atari_format; break; case 'a': case 'p': case 'y': rw = 1; interactive = 0; salvage_files = 1; break; case 'b': rw = 0; interactive = 0; boot_only = 1; break; case 'c': set_dos_codepage(atoi(optarg)); break; case 'd': file_add(optarg, fdt_drop); break; case 'f': salvage_files = 1; break; case 'l': list = 1; break; case 'n': rw = 0; interactive = 0; break; case 'r': rw = 1; interactive = 1; break; case 't': test = 1; break; case 'u': file_add(optarg, fdt_undelete); break; case 'v': verbose = 1; break; case 'V': verify = 1; break; case 'w': write_immed = 1; break; default: usage(argv[0]); } set_dos_codepage(-1); /* set default codepage if none was given in command line */ if ((test || write_immed) && !rw) { fprintf(stderr, "-t and -w can not be used in read only mode\n"); exit(2); } if (optind != argc - 1) usage(argv[0]); printf("fsck.fat " VERSION " (" VERSION_DATE ")\n"); fs_open(argv[optind], rw); read_boot(&fs); if (boot_only) goto exit; if (verify) printf("Starting check/repair pass.\n"); while (read_fat(&fs), scan_root(&fs)) qfree(&mem_queue); if (test) fix_bad(&fs); if (salvage_files) reclaim_file(&fs); else reclaim_free(&fs); free_clusters = update_free(&fs); file_unused(); qfree(&mem_queue); if (verify) { n_files = 0; printf("Starting verification pass.\n"); read_fat(&fs); scan_root(&fs); reclaim_free(&fs); qfree(&mem_queue); } exit: if (fs_changed()) { if (rw) { if (interactive) rw = get_key("yn", "Perform changes ? (y/n)") == 'y'; else printf("Performing changes.\n"); } else printf("Leaving filesystem unchanged.\n"); } if (!boot_only) printf("%s: %u files, %lu/%lu clusters\n", argv[optind], n_files, (unsigned long)fs.clusters - free_clusters, (unsigned long)fs.clusters); return fs_close(rw) ? 1 : 0; }
void mp3_task(void *pvParameters) { OSHANDLES *osHandles = (OSHANDLES*)pvParameters; // Cast the void pointer to pointer of OSHANDLES player_status.has_song = 0; player_status.playing = 0; vTaskDelay(100); scan_root(); //scan/populate database of artist & their albums. //artist_list->tracks = bubblesort(artist_list->tracks); for(;;) { Track * playlist; player_status.playlist_pos = 0; unsigned char cntl = RESUME; if (xQueueReceive(osHandles->queue.playback_playlist, &playlist,999999999)) { player_status.playlist_pos = 0; while (1) { //playlist loop Track * this_song = get_track_number(player_status.playlist_pos, playlist); if (this_song == NULL) {rprintf("get_track_number returned null."); break;} //past end of the playlist. rprintf("item(%i) track(%s) path(%s)",player_status.playlist_pos,this_song->name,this_song->filename); /* ---- check file's extention. ---- */ char* got_ext = strrchr(this_song->filename,'.'); //get position of last '.' if ((got_ext == NULL) || (0 != strncmp(got_ext, ".MP3", 4)) ){ rprintf("file not .mp3\n"); break; // filename didn't have a .mp3 extention. } /* ---- open the file. ---- */ FIL file; FRESULT rstat = f_open(&file, this_song->filename, (FA_READ | FA_OPEN_EXISTING)); if (rstat != FR_OK) { rprintf("open error #%i (0x%02X).\n",rstat,rstat); f_close(&file); break; } /* ---- file opened successfully ---- */ player_status.has_song = 1; player_status.playing = 1; //player_status.legnth = Finfo.fsize; player_status.position = 0; while (1){ /* ---- check about the control queue ---- */ if (xQueueReceive(osHandles->queue.mp3_control, &cntl,0)){ if ((cntl == PAUSE) || (cntl == PLAY_PAUSE)) { player_status.playing = 0; if (xQueueReceive(osHandles->queue.mp3_control, &cntl,1000*60*5)) {} else {cntl = STOP; break;} //stop if past timeout (5 mins) } if ((cntl == NEXT_T)||(cntl == PREV_T)||(cntl == STOP)) break; //breaks the playing loop.. } if (cntl == SEEK_F_8X) { f_lseek(&file, file.fptr + 4096*8); player_status.position += 8; } if (cntl == SEEK_R_8X) { f_lseek(&file, file.fptr - 4096*8); player_status.position -= 8; } player_status.position += 1; /* ---- read a chunk of data to the buffer ---- */ player_status.playing = 1; char buff[4096]; unsigned int bytesRead = 0; unsigned int start_ms = xTaskGetTickCount(); f_read(&file, buff, sizeof(buff), &bytesRead); player_status.read_speed = bytesRead/(xTaskGetTickCount()-start_ms); /* ---- send chunked data to the mp3 decoder ---- */ int i = 0; while( i < bytesRead) { if (MP3_DATAREQ_IS_HIGH) { if (xSemaphoreTake( osHandles->lock.SPI, 100)){ IOSET1 = (1<<29); //MP3-decoder CS => active high rxTxByteSSPSPI(buff[i++]); IOCLR1 = (1<<29); //MP3-decoder CS xSemaphoreGive( osHandles->lock.SPI ); } } } if(sizeof(buff) > bytesRead){ // Last Chunk in file break; // Break outer loop, song ended } } f_close(&file); player_status.has_song = 0; player_status.playing = 0; //done playing the current playlist position, increment and continue. if (cntl == STOP) break; //breaks the playlist loop.. else if (cntl == PREV_T) { //previous / skip to beginning of track. if ((player_status.position < 50) && (player_status.playlist_pos > 0)){ player_status.playlist_pos--; } } else if (cntl == NEXT_T) {player_status.playlist_pos++;} else {player_status.playlist_pos++;cntl = RESUME;} } //playlist loop } //xQueueReceive } //endless for loop. don't break; this. }
int main(int argc,char **argv) { DOS_FS fs; int rw,salvage_files,verify,c; unsigned n_files_check=0, n_files_verify=0; unsigned long free_clusters; rw = salvage_files = verify = 0; interactive = 1; check_atari(); while ((c = getopt(argc,argv,"Aad:flnprtu:vVwy")) != EOF) switch (c) { case 'A': /* toggle Atari format */ atari_format = !atari_format; break; case 'a': case 'p': case 'y': rw = 1; interactive = 0; salvage_files = 1; break; case 'd': file_add(optarg,fdt_drop); break; case 'f': salvage_files = 1; break; case 'l': list = 1; break; case 'n': rw = 0; interactive = 0; break; case 'r': rw = 1; interactive = 1; break; case 't': test = 1; break; case 'u': file_add(optarg,fdt_undelete); break; case 'v': verbose = 1; printf("dosfsck " VERSION " (" VERSION_DATE ")\n"); break; case 'V': verify = 1; break; case 'w': write_immed = 1; break; default: usage(argv[0]); } if ((test || write_immed) && !rw) { fprintf(stderr,"-t and -w require -a or -r\n"); exit(2); } if (optind != argc-1) usage(argv[0]); printf( "dosfsck " VERSION ", " VERSION_DATE ", FAT32, LFN\n" ); fs_open(argv[optind],rw); read_boot(&fs); if (verify) printf("Starting check/repair pass.\n"); while (read_fat(&fs), scan_root(&fs)) qfree(&mem_queue); if (test) fix_bad(&fs); if (salvage_files) reclaim_file(&fs); else reclaim_free(&fs); free_clusters = update_free(&fs); file_unused(); qfree(&mem_queue); n_files_check = n_files; if (verify) { n_files = 0; printf("Starting verification pass.\n"); read_fat(&fs); scan_root(&fs); reclaim_free(&fs); qfree(&mem_queue); n_files_verify = n_files; } if (fs_changed()) { if (rw) { if (interactive) rw = get_key("yn","Perform changes ? (y/n)") == 'y'; else printf("Performing changes.\n"); } else printf("Leaving file system unchanged.\n"); } printf( "%s: %u files, %lu/%lu clusters\n", argv[optind], n_files, fs.clusters - free_clusters, fs.clusters ); return fs_close(rw) ? 1 : 0; }
doachkpt() { extern int errno; FILE *fp; char tmpcheckfile[256]; /* nowhere to checkpoint cache... */ if (cache_file == NULL) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(to where?)\n"); #endif return; } #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt()\n"); #endif (void) sprintf(tmpcheckfile, "%s.chk", cache_file); if ((fp = fopen(tmpcheckfile, "w")) == NULL) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(can't open %s for write)\n", tmpcheckfile); #endif return; } (void) gettime(&tt); fprintf(fp, "; Dumped at %s", ctime(&tt.tv_sec)); fflush(fp); if (ferror(fp)) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(write to checkpoint file failed)\n"); #endif return; } if (fcachetab != NULL) { int n; if ((n = scan_root(hashtab)) < MINROOTS) { syslog(LOG_ERR, "%d root hints... (too low)", n); fprintf(fp, "; ---- Root hint cache dump ----\n"); (void) db_dump(fcachetab, fp, DB_Z_CACHE, ""); } } if (hashtab != NULL) { fprintf(fp, "; ---- Cache dump ----\n"); if (db_dump(hashtab, fp, DB_Z_CACHE, "") == NODBFILE) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(checkpoint failed)\n"); #endif (void) fclose(fp); return; } } (void) fsync(fileno(fp)); if (fclose(fp) == EOF) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(close failed)\n"); #endif return; } if (rename(tmpcheckfile, cache_file)) { #ifdef DEBUG if (debug >= 3) fprintf(ddt,"doachkpt(install %s to %s failed, %d)\n", tmpcheckfile,cache_file, errno); #endif } }
int main(int argc, char *argv[]) { int i, j; struct rlimit rlb; char *arg; pthread_t tid; pthread_attr_t pab; int yu_tmp_len; int depth = 0; argv0 = argv[0]; //setlocale(LC_CTYPE, ""); getrlimit(RLIMIT_NOFILE, &rlb); rlb.rlim_cur = rlb.rlim_max; setrlimit(RLIMIT_NOFILE, &rlb); signal(SIGPIPE, SIG_IGN); nworkers = 2; pthread_mutex_init(&print_lock, NULL); pthread_mutex_init(&aworker_lock, NULL); pthread_mutex_init(&matches_lock, NULL); pthread_cond_init(&aworker_cv, NULL); for (i = 1; i < argc && argv[i][0] == '-'; i++) for (j = 1; j > 0 && argv[i][j]; ++j) switch (argv[i][j]) { case '-': ++i; goto EndOptions; case 'V': print_version(stdout); break; case 'd': ++debug; break; case 'i': ignore_case = 1; break; case 'v': ++verbose; break; case 'h': usage(stdout); exit(0); case 'l': ++line_f; break; case 'L': if (argv[i][2]) arg = argv[i]+2; else arg = argv[++i]; if (!arg || sscanf(arg, "%u", &maxlen) != 1){ fprintf(stderr, "%s: Invalid length specification: %s\n", argv[0], arg ? arg : "<null>"); exit(1); } j = -2; break; case 'n': if (argv[i][2]) arg = argv[i]+2; else arg = argv[++i]; if (!arg || sscanf(arg, "%u", &nworkers) != 1){ fprintf(stderr,"%s: Invalid workers specification: %s\n", argv[0], arg ? arg : "<null>"); exit(1); } j = -2; break; default: fprintf(stderr, "%s: unknown command line switch: -%c\n", argv[0], argv[i][j]); exit(1); } EndOptions: yu_tmp_len = strlen(argv[i]) + 1; rstr = (unsigned char*) malloc( yu_tmp_len * sizeof(unsigned char)); strcpy(rstr, argv[i]); //, yu_tmp_len); i++; rlen = deslash(rstr); if (bm_init(&bmb, rstr, rlen, ignore_case) < 0) { fprintf(stderr, "%s: Failed search string setup: %s\n", argv[0], rstr); exit(1); } max_depth = rlb.rlim_max - nworkers - 16; if (debug) fprintf(stderr, "max_depth = %d, nworkers = %d\n", max_depth, nworkers); pqueue_init(&pqb, nworkers + 8); pthread_attr_init(&pab); pthread_attr_setscope(&pab, PTHREAD_SCOPE_SYSTEM); aworkers = nworkers; for (j = 0; j < nworkers; ++j) if (pthread_create(&tid, &pab, worker, NULL) != 0) { fprintf(stderr, "%s: pthread_create: failed to create worker thread\n", argv[0]); exit(1); } //while (i < argc && do_ftw(argv[i++]) == 0) //; for (; i < argc; i++) { scan_root(argv[i], argv[i], &depth, max_depth); } pqueue_close(&pqb); if (debug) fprintf(stderr, "Waiting for workers to finish...\n"); pthread_mutex_lock(&aworker_lock); while (aworkers > 0) pthread_cond_wait(&aworker_cv, &aworker_lock); pthread_mutex_unlock(&aworker_lock); if (debug) fprintf(stderr, "n_files = %d, n_matches = %d, n_workers = %d, n_Mbytes = %d\n", n_files, n_matches, nworkers, (int) (n_bytes / 1000000)); //pthread_exit(0); return n_matches; }