static void copy_file_task( void * pvParameters ) { FIL File; spiffs_DIR sf_dir; struct spiffs_dirent e; struct spiffs_dirent *pe = &e; s32_t err; void *temp = NULL; uint32_t remain; char *p_path_file = pvParameters; mn_screen_event_t fileLoad; choosedLinePosition = 0; choosedLine = 0; f_open(&File,p_path_file,FA_READ); spiffs_file *fd = &uspiffs[0].f; spiffs *fs = &uspiffs[0].gSPIFFS; SPIFFS_opendir(fs, "/", &sf_dir); do{ pe = SPIFFS_readdir(&sf_dir, pe); }while(strcmp((const char *)pe->name,"config.met") == 0); *fd = SPIFFS_open_by_dirent(fs, pe, SPIFFS_RDWR, 0); if(*fd >= SPIFFS_OK) { err = SPIFFS_fremove(fs, *fd); } *fd = SPIFFS_open(fs, p_path_file, SPIFFS_CREAT | SPIFFS_RDWR | SPIFFS_DIRECT, 0); temp = pvPortMalloc( FS_PAGE_SIZE ); while(!f_eof(&File)) { f_read(&File,temp,FS_PAGE_SIZE,(UINT *)&remain); err = SPIFFS_write(fs, *fd, (u8_t *)temp, remain); } vPortFree(temp); vPortFree(p_path_file); f_close(&File); SPIFFS_close(fs, *fd); fileLoad.event = FILE_LOAD_EVENT; xQueueSend( menu.qEvent, &fileLoad, 0 ); vTaskDelete( xHdlTaskFilecopy ); while(1) { } }
int main(int argc, char **argv) { FILE *fp; const char *filename = NULL; int i; int list = 0; const char *extDir = "."; for (i = 1; i < argc && argv[i][0] == '-'; i++) { if (strcmp(argv[i], "-d") == 0 && i + 1 < argc) { extDir = argv[i + 1]; i++; } else if (strcmp(argv[i], "-l") == 0) { list = 1; } else if (strcmp(argv[i], "-h") == 0) { show_usage(argv); } } if (argc - i < 1) { show_usage(argv); } filename = argv[i]; fp = fopen(filename, "r"); if (fp == NULL) { fprintf(stderr, "unable to open %s, err: %d\n", filename, errno); return 1; } fseek(fp, 0, SEEK_END); image_size = ftell(fp); fseek(fp, 0, SEEK_SET); image = (char *) malloc(image_size); if (fread(image, image_size, 1, fp) < 1) { fprintf(stderr, "cannot read %s, err: %d\n", filename, errno); return 1; } mem_spiffs_mount(); { spiffs_DIR d; struct spiffs_dirent de; SPIFFS_opendir(&fs, ".", &d); while (SPIFFS_readdir(&d, &de) != NULL) { if (list) { printf("%s\n", de.name); } else { char target[1024]; char *buf = NULL; FILE *out; spiffs_file in; sprintf(target, "%s/%s", extDir, de.name); fprintf(stderr, "extracting %s\n", de.name); out = fopen(target, "w"); if (out == NULL) { fprintf(stderr, "cannot write %s, err: %d\n", target, errno); return 1; } in = SPIFFS_open_by_dirent(&fs, &de, SPIFFS_RDONLY, 0); if (in < 0) { fprintf(stderr, "cannot open spiffs file %s, err: %d\n", de.name, SPIFFS_errno(&fs)); return 1; } buf = malloc(de.size); if (SPIFFS_read(&fs, in, buf, de.size) != de.size) { fprintf(stderr, "cannot read %s, err: %d\n", de.name, SPIFFS_errno(&fs)); return 1; } SPIFFS_close(&fs, in); fwrite(buf, de.size, 1, out); free(buf); fclose(out); } } SPIFFS_closedir(&d); } free(image); fclose(fp); return 0; }