-/* Work register for fs command */
-struct stat_dat_s {
- DWORD AccSize;
- WORD AccFiles, AccDirs;
- FILINFO Finfo;
-};
-
-static
-FRESULT scan_files (
- char *path, /* Pointer to the working buffer with start path */
- struct stat_dat_s *statp
-)
-{
- DIR dirs;
- FRESULT res;
- int i;
- char *fn;
-
- res = f_opendir(&dirs, path);
- swirl();
- if (res == FR_OK) {
- i = strlen(path);
- while (((res = f_readdir(&dirs, &statp->Finfo)) == FR_OK) &&
- statp->Finfo.fname[0]) {
- if (FF_FS_RPATH && statp->Finfo.fname[0] == '.')
- continue;
- fn = statp->Finfo.fname;
- if (statp->Finfo.fattrib & AM_DIR) {
- statp->AccDirs++;
- path[i] = '/';
- strcpy(path+i+1, fn);
- res = scan_files(path, statp);
- path[i] = '\0';
- if (res != FR_OK)
- break;
- } else {
- //printf_P(PSTR("%s/%s\n"), path, fn);
- statp->AccFiles++;
- statp->AccSize += statp->Finfo.fsize;
- }
- if (check_abort()) {
- res = 255;
- break;
- }
- }
- }
-
- return res;
-}
-
-
-/*
- * fatstat path - Show logical drive status
- *
- */
-command_ret_t do_stat(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
-{
- FATFS *fs;
- DWORD nfreeclst;
- FRESULT res;
- char *path;
- struct stat_dat_s statp;
-
- (void) cmdtp; (void) flag; (void) argc;
-
- path = (char *) malloc(BUFFER_SIZE);
- if (path == NULL) {
- printf_P(PSTR("fatstat: Out of Memory!\n"));
- free(path);
- return CMD_RET_FAILURE;
- }
-
- res = f_getfree(argv[1], &nfreeclst, &fs);
- if (!res) {
- printf_P(PSTR(
- "FAT type: %u\n"
- "Bytes/Cluster: %lu\n"
- "Number of FATs: %u\n"
- "Root DIR entries: %u\n"
- "Sectors/FAT: %lu\n"
- "Number of clusters: %lu\n"
- "FAT start (lba): %lu\n"
- "DIR start (lba,cluster): %lu\n"
- "Data start (lba): %lu\n"),
- fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats,
- fs->n_rootdir, fs->fsize, fs->n_fatent - 2,
- fs->fatbase, fs->dirbase, fs->database);
-
-#if _USE_LABEL
- TCHAR label[12];
- DWORD serial;
- res = f_getlabel(argv[1], label, &serial);
- if (!res) {
- printf_P(PSTR(
- "Volume name: %s\n"
- "Volume S/N: %04X-%04X\n"),
- label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF));
- }
-#endif
- if (!res) {
- my_puts_P(PSTR("\nCounting... "));
- statp.AccSize = statp.AccFiles = statp.AccDirs = 0;
- strcpy(path, argv[1]);
-
- res = scan_files(path, &statp);
- }
- if (!res) {
- printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n"
- "%lu KB total disk space.\n%lu KB available.\n"),
- statp.AccFiles, statp.AccSize, statp.AccDirs,
- (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2)
- );
- }
- }
-
- free(path);
- if (res) {
- put_rc(res);
- return CMD_RET_FAILURE;
- }
- return CMD_RET_SUCCESS;
-}
-