From a9fc1e0e5d3e5eb8a34c568a8d147320a9afebe1 Mon Sep 17 00:00:00 2001 From: Far Date: Thu, 24 Jun 2021 14:31:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Liteos-a=E5=88=9B=E5=BB=BA=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=9C=A8Ubuntu=E4=B8=AD=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linux的文件夹需要包含"."和".."才会被视为一个有效的目录 通过在新建的文件夹中创建"."和".."目录项修复这个BUG Close #I3XMY6 Signed-off-by: Far --- fs/fat/os_adapt/fatfs.c | 66 ++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index dc5070a9..0530dddd 100644 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -251,11 +251,13 @@ static enum VnodeType fatfstype_2_vnodetype(BYTE type) { } } -static FRESULT init_cluster(DIR *dp_new, FATFS *fs, int type, const char *target, DWORD *clust) +#define DIR_SIZE 32 +static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, const char *target, DWORD *clust) { FRESULT result; BYTE *dir = NULL; QWORD sect; + DWORD pclust; UINT n; /* Allocate a new cluster */ @@ -285,23 +287,51 @@ static FRESULT init_cluster(DIR *dp_new, FATFS *fs, int type, const char *target if (type == AM_LNK && target) { /* Write target to symlink */ strcpy_s((char *)dir, SS(fs), target); - } - for (n = fs->csize; n > 0; n--) { -#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION - fs->winsect = sect++; - fs->wflag = 1; -#else - PARENTFS(fs)->winsect = sect++; - PARENTFS(fs)->wflag = 1; -#endif - result = sync_window(fs); - if (result != FR_OK) { - remove_chain(&(dp_new->obj), *clust, 0); - return result; + } else { + /* Write the dir cluster */ + mem_set(dir, 0, SS(fs)); + mem_set(dir + DIR_Name, ' ', 11); /* Create "." entry */ + dir[DIR_Name] = '.'; + dir[DIR_Attr] = AM_DIR; + st_clust(fs, dir, *clust); + mem_cpy(dir + DIR_SIZE, dir, DIR_SIZE); /* Create ".." entry */ + dir[DIR_SIZE + 1] = '.'; /* Add extra "." */ + pclust = pdfp->fno.sclst; + if (fs->fs_type == FS_FAT32 && pclust == fs->dirbase) { + pclust = 0; } - if (type == AM_LNK) { - /* No need to clean the rest sectors of the cluster for symlink */ - break; + st_clust(fs, dir + DIR_SIZE, pclust); + } + +#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION + fs->winsect = sect++; + fs->wflag = 1; +#else + PARENTFS(fs)->winsect = sect++; + PARENTFS(fs)->wflag = 1; +#endif + result = sync_window(fs); + if (result != FR_OK) { + remove_chain(&(dp_new->obj), *clust, 0); + return result; + } + + /* Rest of directory cluster should set to be zero */ + if (type == AM_DIR) { + mem_set(dir, 0, SS(fs)); + for (n = fs->csize - 1; n > 0; n--) { +#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION + fs->winsect = sect++; + fs->wflag = 1; +#else + PARENTFS(fs)->winsect = sect++; + PARENTFS(fs)->wflag = 1; +#endif + result = sync_window(fs); + if (result != FR_OK) { + remove_chain(&(dp_new->obj), *clust, 0); + return result; + } } } @@ -366,7 +396,7 @@ static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, st } if (type == AM_DIR || type == AM_LNK) { - result = init_cluster(dp_new, fs, type, target, &clust); + result = init_cluster(dfp, dp_new, fs, type, target, &clust); if (result != FR_OK) { goto ERROR_UNLOCK; }