From add48c7b8b2445cb4f45ec585d514bf7dfd139b1 Mon Sep 17 00:00:00 2001 From: WKJay <1931048074@qq.com> Date: Thu, 10 Aug 2023 16:24:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[DFS=5FV1]=E4=BF=AE=E5=A4=8D=20dfs=5Ffile?= =?UTF-8?q?=5Fstat=20=E4=B8=80=E4=B8=AA=20FATFS=20=E6=A0=B9=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=BC=9A=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/dfs_v1/src/dfs_file.c | 43 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/components/dfs/dfs_v1/src/dfs_file.c b/components/dfs/dfs_v1/src/dfs_file.c index 3a7e626f208..a1924e599fc 100644 --- a/components/dfs/dfs_v1/src/dfs_file.c +++ b/components/dfs/dfs_v1/src/dfs_file.c @@ -584,23 +584,44 @@ int dfs_file_stat(const char *path, struct stat *buf) return -ENOENT; } - if (fs->ops->stat == NULL) + if ((fullpath[0] == '/' && fullpath[1] == '\0') || + (dfs_subdir(fs->path, fullpath) == NULL)) { + /* it's the root directory */ + buf->st_dev = 0; + + buf->st_mode = S_IRUSR | S_IRGRP | S_IROTH | + S_IWUSR | S_IWGRP | S_IWOTH; + buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + + buf->st_size = 0; + buf->st_mtime = 0; + + /* release full path */ rt_free(fullpath); - LOG_E("the filesystem didn't implement this function"); - return -ENOSYS; - } - /* get the real file path and get file stat */ - if (fs->ops->flags & DFS_FS_FLAG_FULLPATH) - { - result = fs->ops->stat(fs, fullpath, buf); + return RT_EOK; } else { - const char *subdir = dfs_subdir(fs->path, fullpath); - subdir = subdir ? subdir : "/"; - result = fs->ops->stat(fs, subdir, buf); + if (fs->ops->stat == NULL) + { + rt_free(fullpath); + LOG_E("the filesystem didn't implement this function"); + + return -ENOSYS; + } + /* get the real file path and get file stat */ + if (fs->ops->flags & DFS_FS_FLAG_FULLPATH) + { + result = fs->ops->stat(fs, fullpath, buf); + } + else + { + const char *subdir = dfs_subdir(fs->path, fullpath); + subdir = subdir ? subdir : "/"; + result = fs->ops->stat(fs, subdir, buf); + } } rt_free(fullpath); From fb28d6f838bd892404476f1deab66d96d4dd6172 Mon Sep 17 00:00:00 2001 From: WKJay <1931048074@qq.com> Date: Fri, 18 Aug 2023 23:41:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=BF=98=E5=8E=9Fdfs=5Ffile.c,=E4=BF=AE?= =?UTF-8?q?=E6=94=B9ff.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/dfs_v1/filesystems/elmfat/ff.c | 2 +- components/dfs/dfs_v1/src/dfs_file.c | 43 +++++-------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/components/dfs/dfs_v1/filesystems/elmfat/ff.c b/components/dfs/dfs_v1/filesystems/elmfat/ff.c index 815c3d2b838..80e194d6e9a 100644 --- a/components/dfs/dfs_v1/filesystems/elmfat/ff.c +++ b/components/dfs/dfs_v1/filesystems/elmfat/ff.c @@ -4746,7 +4746,7 @@ FRESULT f_stat ( res = follow_path(&dj, path); /* Follow the file path */ if (res == FR_OK) { /* Follow completed */ if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */ - res = FR_INVALID_NAME; + fno->fattrib = AM_DIR; } else { /* Found an object */ if (fno) get_fileinfo(&dj, fno); } diff --git a/components/dfs/dfs_v1/src/dfs_file.c b/components/dfs/dfs_v1/src/dfs_file.c index a1924e599fc..3a7e626f208 100644 --- a/components/dfs/dfs_v1/src/dfs_file.c +++ b/components/dfs/dfs_v1/src/dfs_file.c @@ -584,44 +584,23 @@ int dfs_file_stat(const char *path, struct stat *buf) return -ENOENT; } - if ((fullpath[0] == '/' && fullpath[1] == '\0') || - (dfs_subdir(fs->path, fullpath) == NULL)) + if (fs->ops->stat == NULL) { - /* it's the root directory */ - buf->st_dev = 0; - - buf->st_mode = S_IRUSR | S_IRGRP | S_IROTH | - S_IWUSR | S_IWGRP | S_IWOTH; - buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; - - buf->st_size = 0; - buf->st_mtime = 0; - - /* release full path */ rt_free(fullpath); + LOG_E("the filesystem didn't implement this function"); - return RT_EOK; + return -ENOSYS; + } + /* get the real file path and get file stat */ + if (fs->ops->flags & DFS_FS_FLAG_FULLPATH) + { + result = fs->ops->stat(fs, fullpath, buf); } else { - if (fs->ops->stat == NULL) - { - rt_free(fullpath); - LOG_E("the filesystem didn't implement this function"); - - return -ENOSYS; - } - /* get the real file path and get file stat */ - if (fs->ops->flags & DFS_FS_FLAG_FULLPATH) - { - result = fs->ops->stat(fs, fullpath, buf); - } - else - { - const char *subdir = dfs_subdir(fs->path, fullpath); - subdir = subdir ? subdir : "/"; - result = fs->ops->stat(fs, subdir, buf); - } + const char *subdir = dfs_subdir(fs->path, fullpath); + subdir = subdir ? subdir : "/"; + result = fs->ops->stat(fs, subdir, buf); } rt_free(fullpath);