fix: Liteos-a创建的文件夹在Ubuntu中不可见

Linux的文件夹需要包含"."和".."才会被视为一个有效的目录
通过在新建的文件夹中创建"."和".."目录项修复这个BUG

Close #I3XMY6

Signed-off-by: Far <yesiyuan2@huawei.com>
This commit is contained in:
Far 2021-06-24 14:31:20 +08:00
parent 8a3d188240
commit a9fc1e0e5d
1 changed files with 48 additions and 18 deletions

View File

@ -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;
}