From 13de8fe6efa9b9095345b89bf1062c4fee55903f Mon Sep 17 00:00:00 2001 From: Far Date: Mon, 28 Jun 2021 15:54:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=81=A2=E5=A4=8D=E4=BA=86FATFS?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8D=B7=E6=A0=87=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Liteos_a FATFS需要提供格式化时设置卷标的功能,该功能在当前系统中缺失。 为了适配VFS层重构的逻辑,重新封装部分函数。 Close #I3Y5G8 Signed-off-by: Far --- source/ff.c | 29 ++++++++++++++++++----------- source/ff.h | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/source/ff.c b/source/ff.c index 3878984..46536d2 100644 --- a/source/ff.c +++ b/source/ff.c @@ -5095,13 +5095,10 @@ FRESULT f_getlabel ( /* Set Volume Label */ /*-----------------------------------------------------------------------*/ -FRESULT f_setlabel ( - const TCHAR* label /* Volume label to set with heading logical drive number */ -) +FRESULT set_volumn_label(FATFS *fs, const TCHAR *label) { FRESULT res; DIR dj; - FATFS *fs; BYTE dirvn[22]; UINT di; WCHAR wc; @@ -5109,13 +5106,7 @@ FRESULT f_setlabel ( #if FF_USE_LFN DWORD dc; #endif - - /* Get logical drive */ - res = find_volume(&label, &fs, FA_WRITE); - if (res != FR_OK) LEAVE_FF(fs, res); - - - /* On the FAT/FAT32 volume */ + /* On the FAT/FAT32 volume */ mem_set(dirvn, ' ', 11); di = 0; while ((UINT)*label >= ' ') { /* Create volume label */ @@ -5171,6 +5162,22 @@ FRESULT f_setlabel ( } } + return res; +} + +FRESULT f_setlabel ( + const TCHAR* label /* Volume label to set with heading logical drive number */ +) +{ + FRESULT res; + FATFS *fs; + + /* Get logical drive */ + res = find_volume(&label, &fs, FA_WRITE); + if (res != FR_OK) LEAVE_FF(fs, res); + + res = set_volumn_label(fs, label); + LEAVE_FF(fs, res); } diff --git a/source/ff.h b/source/ff.h index c3bbc8f..ab1b802 100644 --- a/source/ff.h +++ b/source/ff.h @@ -484,6 +484,7 @@ FRESULT remove_chain (FFOBJID* obj, DWORD clst, DWORD pclst); void mem_set (void* dst, int val, UINT cnt); void mem_cpy (void* dst, const void* src, UINT cnt); int fatfs_get_vol (FATFS *fat); +FRESULT set_volumn_label(FATFS *fs, const TCHAR *label); #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) #define f_error(fp) ((fp)->err) -- GitLab