From a9ea9725d418815652e142e7f074d8cd810a0579 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Mon, 4 May 2020 20:30:51 +0200 Subject: [PATCH] Speed up copy & formats --- source/libs/fatfs/ff.c | 5 +- source/tegraexplorer/common/types.h | 2 +- source/tegraexplorer/emmc/emmcdumppart.c | 2 +- source/tegraexplorer/emmc/emmcrestorepart.c | 4 +- source/tegraexplorer/fs/fsactions.c | 55 +++++++++++++-------- source/tegraexplorer/utils/tools.c | 19 +++++-- 6 files changed, 57 insertions(+), 30 deletions(-) diff --git a/source/libs/fatfs/ff.c b/source/libs/fatfs/ff.c index 4c1b77f..f1d251c 100644 --- a/source/libs/fatfs/ff.c +++ b/source/libs/fatfs/ff.c @@ -5629,7 +5629,8 @@ FRESULT f_forward ( } #endif /* FF_USE_FORWARD */ - +#pragma GCC push_options +#pragma GCC optimize ("Os") #if FF_USE_MKFS && !FF_FS_READONLY /*-----------------------------------------------------------------------*/ @@ -6094,7 +6095,7 @@ FRESULT f_mkfs ( LEAVE_MKFS(FR_OK); } - +#pragma GCC pop_options #if FF_MULTI_PARTITION /*-----------------------------------------------------------------------*/ diff --git a/source/tegraexplorer/common/types.h b/source/tegraexplorer/common/types.h index 199a33c..7eff426 100644 --- a/source/tegraexplorer/common/types.h +++ b/source/tegraexplorer/common/types.h @@ -23,7 +23,7 @@ #define COPY_MODE_PRINT 0x1 #define COPY_MODE_CANCEL 0x2 -#define BUFSIZE 32768 +#define BUFSIZE 65536 //32768 #define OPERATIONCOPY 0x2 #define OPERATIONMOVE 0x4 diff --git a/source/tegraexplorer/emmc/emmcdumppart.c b/source/tegraexplorer/emmc/emmcdumppart.c index e7f2069..4569d8d 100644 --- a/source/tegraexplorer/emmc/emmcdumppart.c +++ b/source/tegraexplorer/emmc/emmcdumppart.c @@ -45,7 +45,7 @@ int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){ f_lseek(&fp, 0); while (totalSectors > 0){ - num = MIN(totalSectors, 64); + num = MIN(totalSectors, 128); if (!emummc_storage_read(mmcstorage, lba_curr, num, buf)){ gfx_errDisplay("dump_emmc_part", ERR_EMMC_READ_FAILED, 3); return -1; diff --git a/source/tegraexplorer/emmc/emmcrestorepart.c b/source/tegraexplorer/emmc/emmcrestorepart.c index d0197f8..d904377 100644 --- a/source/tegraexplorer/emmc/emmcrestorepart.c +++ b/source/tegraexplorer/emmc/emmcrestorepart.c @@ -32,7 +32,7 @@ int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){ gfx_printf("Initializing\r"); - buf = calloc(16384, sizeof(u8)); + buf = calloc(BUFSIZE, sizeof(u8)); if (!buf){ gfx_errDisplay("restore_emmc_part", ERR_MEM_ALLOC_FAILED, 1); @@ -78,7 +78,7 @@ int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){ } while (totalSectors > 0){ - num = MIN(totalSectors, 32); + num = MIN(totalSectors, 128); if ((res = f_read(&fp, buf, num * NX_EMMC_BLOCKSIZE, NULL))){ gfx_errDisplay("restore_emmc_part", res, 5); diff --git a/source/tegraexplorer/fs/fsactions.c b/source/tegraexplorer/fs/fsactions.c index 7a07b08..eff6458 100644 --- a/source/tegraexplorer/fs/fsactions.c +++ b/source/tegraexplorer/fs/fsactions.c @@ -8,15 +8,16 @@ #include "../utils/utils.h" #include "../../mem/heap.h" #include "../../hid/hid.h" +#include "../../utils/btn.h" #include "fsutils.h" int fsact_copy(const char *locin, const char *locout, u8 options){ FIL in, out; FILINFO in_info; - u64 sizeoffile, sizecopied = 0, totalsize; + u64 sizeRemaining, toCopy; UINT temp1, temp2; - u8 *buff; - unsigned int x, y, i = 0; + u8 *buff, toPrint = options & COPY_MODE_PRINT, toCancel = options & COPY_MODE_CANCEL; + u32 x, y, i = 11; int res; gfx_con_getpos(&x, &y); @@ -41,17 +42,26 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ return 1; } - buff = malloc (BUFSIZE); - sizeoffile = f_size(&in); - totalsize = sizeoffile; + if (toPrint){ + SWAPCOLOR(COLOR_GREEN); + gfx_printf("[ ]"); + x += 16; + gfx_con_setpos(x, y); + } - while (sizeoffile > 0){ - if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))){ + buff = malloc (BUFSIZE); + sizeRemaining = f_size(&in); + const u64 totalsize = sizeRemaining; + + while (sizeRemaining > 0){ + toCopy = MIN(sizeRemaining, BUFSIZE); + + if ((res = f_read(&in, buff, toCopy, &temp1))){ gfx_errDisplay("copy", res, 5); return 1; } - if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))){ + if ((res = f_write(&out, buff, toCopy, &temp2))){ gfx_errDisplay("copy", res, 6); return 1; } @@ -61,23 +71,28 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ return 1; } - sizeoffile -= temp1; - sizecopied += temp1; + sizeRemaining -= toCopy; - if (options & COPY_MODE_PRINT && 10 > i++){ - gfx_printf("%k[%d%%]%k", COLOR_GREEN, ((sizecopied * 100) / totalsize) ,COLOR_WHITE); + if (toPrint && (i > 16 || !sizeRemaining)){ + gfx_printf("%3d%%", (u32)(((totalsize - sizeRemaining) * 100) / totalsize)); gfx_con_setpos(x, y); - - i = 0; + } - if (options & COPY_MODE_CANCEL) - if (hidRead()->buttons & (KEY_VOLP | KEY_VOLM)){ - f_unlink(locout); - break; - } + if (toCancel && i > 16){ + if (btn_read() & (BTN_VOL_DOWN | BTN_VOL_UP)){ + f_unlink(locout); + break; + } + } + + if (options){ + if (i++ > 16) + i = 0; } } + RESETCOLOR; + f_close(&in); f_close(&out); free(buff); diff --git a/source/tegraexplorer/utils/tools.c b/source/tegraexplorer/utils/tools.c index 93f846e..646069c 100644 --- a/source/tegraexplorer/utils/tools.c +++ b/source/tegraexplorer/utils/tools.c @@ -185,9 +185,9 @@ int format(int mode){ gfx_clearscreen(); int res; bool fatalerror = false; - DWORD plist[] = {666, 61145088}; + DWORD plist[] = {666, 61145088, 0, 0}; u32 timer, totalsectors, alignedsectors, extrasectors; - BYTE work[FF_MAX_SS]; + u8 *work; DWORD clustsize = 32768; BYTE formatoptions = 0; formatoptions |= (FM_FAT32); @@ -198,6 +198,15 @@ int format(int mode){ timer = get_tmr_s(); totalsectors = sd_storage.csd.capacity; + gfx_printf("Initializing...\n"); + + work = calloc(BUFSIZE, sizeof(BYTE)); + + if (work == NULL){ + gfx_errDisplay("format", ERR_MEM_ALLOC_FAILED, 0); + return 0; + } + if (mode == FORMAT_EMUMMC){ if (totalsectors < 83886080){ gfx_printf("%kYou seem to be running this on a <=32GB SD\nNot enough free space for emummc!", COLOR_RED); @@ -219,7 +228,7 @@ int format(int mode){ if (!fatalerror){ gfx_printf("\nPartitioning SD...\n"); - res = f_fdisk(0, plist, &work); + res = f_fdisk(0, plist, work); if (res){ gfx_printf("%kf_fdisk returned %d!\n", COLOR_RED, res); @@ -231,7 +240,7 @@ int format(int mode){ if (!fatalerror){ gfx_printf("\n\nFormatting Partition1...\n"); - res = f_mkfs("0:", formatoptions, clustsize, &work, sizeof work); + res = f_mkfs("0:", formatoptions, clustsize, work, BUFSIZE * sizeof(BYTE)); if (res){ gfx_printf("%kf_mkfs returned %d!\n", COLOR_RED, res); @@ -241,6 +250,8 @@ int format(int mode){ gfx_printf("Smells like a formatted SD\n\n"); } + free(work); + sd_unmount(); if (!fatalerror){