From 9515d53dccc9a6458bfbaf8e15143928f05cb660 Mon Sep 17 00:00:00 2001 From: Far Date: Mon, 28 Jun 2021 15:04:44 +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需要提供格式化时设置卷标的功能,该功能在当前系统中缺失。 现在恢复该功能,使用方法与原来一致。即使用set_label设置卷标文本后,调用format对设备格式化。 Close #I3Y5G8 Signed-off-by: Far --- fs/fat/os_adapt/fatfs.c | 52 +++++++++++++++++++++++++++++++++++++---- fs/fat/os_adapt/fatfs.h | 2 ++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index fa431c93..06c33d57 100644 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -1776,6 +1776,45 @@ static int fatfs_set_part_info(los_part *part) return 0; } +static FRESULT fatfs_setlabel(los_part *part) +{ + QWORD start_sector = 0; + BYTE fmt = 0; + FATFS fs; + FRESULT result; + +#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION + fs.vir_flag = FS_PARENT; + fs.parent_fs = &fs; + fs.vir_amount = DISK_ERROR; + fs.vir_avail = FS_VIRDISABLE; +#endif + if (disk_ioctl(fs.pdrv, GET_SECTOR_SIZE, &(fs.ssize)) != RES_OK) { + return -EIO; + } + fs.win = (BYTE *)ff_memalloc(fs.ssize); + if (fs.win == NULL) { + return -ENOMEM; + } + + result = find_fat_partition(&fs, part, &fmt, &start_sector); + if (result != FR_OK) { + free(fs.win); + return -fatfs_2_vfs(result); + } + + result = init_fatobj(&fs, fmt, start_sector); + if (result != FR_OK) { + free(fs.win); + return -fatfs_2_vfs(result); + } + + result = set_volumn_label(&fs, FatLabel); + free(fs.win); + + return result; +} + int fatfs_mkfs (struct Vnode *device, int sectors, int option) { BYTE *work_buff = NULL; @@ -1811,19 +1850,22 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option) return -fatfs_2_vfs(result); } + result = fatfs_setlabel(part); + if (result == FR_OK) { #ifdef LOSCFG_FS_FAT_CACHE - ret = OsSdSync(part->disk_id); - if (ret != 0) { - return -EIO; - } + ret = OsSdSync(part->disk_id); + if (ret != 0) { + return -EIO; + } #endif + } ret = fatfs_set_part_info(part); if (ret != 0) { return -EIO; } - return 0; + return -fatfs_2_vfs(result); } int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp) diff --git a/fs/fat/os_adapt/fatfs.h b/fs/fat/os_adapt/fatfs.h index a9d280e5..734cf948 100644 --- a/fs/fat/os_adapt/fatfs.h +++ b/fs/fat/os_adapt/fatfs.h @@ -113,6 +113,8 @@ extern "C" { #define FMT_ANY 0x07 #define FMT_ERASE 0x08 +extern char FatLabel[LABEL_LEN]; + int fatfs_2_vfs(int result); int fatfs_lookup(struct Vnode *parent, const char *name, int len, struct Vnode **vpp); int fatfs_create(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp); -- GitLab