Skip to content

Commit 06c8084

Browse files
committed
fatfs: use cluster size for st_blksize in stat
1 parent e28b6b4 commit 06c8084

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Version 7.1.0
44
- Added DITTO to duplicate code/data in Spin2 assembly
55
- Many internal changes to support DITTO and future assembly work
66
- Updated -gbrk debug code (thanks Ada)
7+
- Use cluster size for stat() st_blksize on FAT32
78

89
Version 7.0.5
910
- Fixed internal handle usage to avoid conflicts with BASIC hard-coded handles

include/filesys/fatfs/fatfs.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int v_stat(const char *name, struct stat *buf)
224224
int r;
225225
FILINFO finfo;
226226
unsigned mode;
227+
unsigned clustersize = 4096;
227228
#ifdef _DEBUG_FATFS
228229
__builtin_printf("v_stat(%s)\n", name);
229230
#endif
@@ -234,6 +235,7 @@ int v_stat(const char *name, struct stat *buf)
234235
r = 0;
235236
} else {
236237
r = f_stat(name, &finfo);
238+
clustersize = finfo.fclust;
237239
}
238240
if (r != 0) {
239241
return _set_dos_error(r);
@@ -248,8 +250,8 @@ int v_stat(const char *name, struct stat *buf)
248250
buf->st_mode = mode;
249251
buf->st_nlink = 1;
250252
buf->st_size = finfo.fsize;
251-
buf->st_blksize = 512;
252-
buf->st_blocks = (finfo.fsize + 511) / 512;
253+
buf->st_blksize = clustersize;
254+
buf->st_blocks = (finfo.fsize + clustersize - 1) / clustersize;
253255
buf->st_atime = buf->st_mtime = buf->st_ctime = unixtime(finfo.fdate, finfo.ftime);
254256
#ifdef _DEBUG_FATFS
255257
__builtin_printf("v_stat returning %d mode=0x%x\n", r, buf->st_mode);

include/filesys/fatfs/ff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,6 +4754,7 @@ FRESULT f_stat (
47544754
FREE_NAMBUF();
47554755
}
47564756

4757+
if (fno) fno->fclust = (DWORD)dj.obj.fs->csize * SS(dj.obj.fs);
47574758
LEAVE_FF(dj.obj.fs, res);
47584759
}
47594760

include/filesys/fatfs/ff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ typedef struct {
249249
WORD fdate; /* Modified date */
250250
WORD ftime; /* Modified time */
251251
BYTE fattrib; /* File attribute */
252+
DWORD fclust; /* File cluster size in bytes */
252253
#if FF_USE_LFN
253254
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
254255
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */

0 commit comments

Comments
 (0)