Skip to content

Commit 6ef65e7

Browse files
committed
extmod/vfs_fat: Add fat_vfs_import_stat(), reusable import stat routine.
Moved from stmhal.
1 parent eaa96a7 commit 6ef65e7

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

extmod/vfs_fat_misc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "lib/fatfs/diskio.h"
3535
#include "extmod/vfs_fat_file.h"
3636
#include "fsusermount.h"
37+
#include "py/lexer.h"
3738

3839
#if _USE_LFN
3940
STATIC char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */
@@ -94,4 +95,21 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) {
9495
return dir_list;
9596
}
9697

98+
mp_import_stat_t fat_vfs_import_stat(const char *path) {
99+
FILINFO fno;
100+
#if _USE_LFN
101+
fno.lfname = NULL;
102+
fno.lfsize = 0;
103+
#endif
104+
FRESULT res = f_stat(path, &fno);
105+
if (res == FR_OK) {
106+
if ((fno.fattrib & AM_DIR) != 0) {
107+
return MP_IMPORT_STAT_DIR;
108+
} else {
109+
return MP_IMPORT_STAT_FILE;
110+
}
111+
}
112+
return MP_IMPORT_STAT_NO_EXIST;
113+
}
114+
97115
#endif // MICROPY_VFS_FAT

stmhal/import.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,8 @@
2929
#include "py/lexer.h"
3030
#include "lib/fatfs/ff.h"
3131

32+
mp_import_stat_t fat_vfs_import_stat(const char *path);
33+
3234
mp_import_stat_t mp_import_stat(const char *path) {
33-
FILINFO fno;
34-
#if _USE_LFN
35-
fno.lfname = NULL;
36-
fno.lfsize = 0;
37-
#endif
38-
FRESULT res = f_stat(path, &fno);
39-
if (res == FR_OK) {
40-
if ((fno.fattrib & AM_DIR) != 0) {
41-
return MP_IMPORT_STAT_DIR;
42-
} else {
43-
return MP_IMPORT_STAT_FILE;
44-
}
45-
}
46-
return MP_IMPORT_STAT_NO_EXIST;
35+
return fat_vfs_import_stat(path);
4736
}

0 commit comments

Comments
 (0)