From eb0df6b12c42c342c35b46bb14bdc5c37854ae9b Mon Sep 17 00:00:00 2001 From: xqyjlj Date: Sat, 25 Mar 2023 07:34:00 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(components/dfs/filesystems/elm?= =?UTF-8?q?fat/dfs=5Felm.c):=20add=20st=5Fblocks=20su=E2=80=A6=20(#7091)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/filesystems/elmfat/dfs_elm.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index f32ab53285..7e35dac79a 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -29,6 +29,13 @@ #include #include +#undef SS +#if FF_MAX_SS == FF_MIN_SS +#define SS(fs) ((UINT)FF_MAX_SS) /* Fixed sector size */ +#else +#define SS(fs) ((fs)->ssize) /* Variable sector size */ +#endif + static rt_device_t disk[FF_VOLUMES] = {0}; static int elm_result_to_dfs(FRESULT result) @@ -751,9 +758,12 @@ int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *n int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { + FATFS *f; FILINFO file_info; FRESULT result; + f = (FATFS *)fs->data; + #if FF_VOLUMES > 1 int vol; char *drivers_fn; @@ -793,7 +803,16 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) st->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); st->st_size = file_info.fsize; - + st->st_blksize = f->csize * SS(f); + if (file_info.fattrib & AM_ARC) + { + st->st_blocks = file_info.fsize ? ((file_info.fsize - 1) / SS(f) / f->csize + 1) : 0; + st->st_blocks *= (st->st_blksize / 512); // man say st_blocks is number of 512B blocks allocated + } + else + { + st->st_blocks = f->csize; + } /* get st_mtime. */ { struct tm tm_file; -- GitLab