diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-02-28 17:17:24 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-02-28 17:17:24 +0200 |
commit | cd6d189f48ccb02761ee286e1254c764ee732d7f (patch) | |
tree | 851f2f65ee10270722ffc4f245c64074e46338c0 /stmhal/moduos.c | |
parent | 8a180845711d881d31876a43259092eaf03268f7 (diff) |
extmod/vfs_fat: Move listdir() method from stmhal for reuse.
Diffstat (limited to 'stmhal/moduos.c')
-rw-r--r-- | stmhal/moduos.c | 56 |
1 files changed, 1 insertions, 55 deletions
diff --git a/stmhal/moduos.c b/stmhal/moduos.c index 75cb8986d..310b8d44f 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -54,10 +54,6 @@ /// On boot up, the current directory is `/flash` if no SD card is inserted, /// otherwise it is `/sd`. -#if _USE_LFN -static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ -#endif - STATIC const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine @@ -144,57 +140,7 @@ STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) { return dir_list; } - FRESULT res; - FILINFO fno; - DIR dir; -#if _USE_LFN - fno.lfname = lfn; - fno.lfsize = sizeof lfn; -#endif - - res = f_opendir(&dir, path); /* Open the directory */ - if (res != FR_OK) { - // TODO should be mp_type_FileNotFoundError - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "No such file or directory: '%s'", path)); - } - - mp_obj_t dir_list = mp_obj_new_list(0, NULL); - - for (;;) { - res = f_readdir(&dir, &fno); /* Read a directory item */ - if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ - if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */ - if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */ - -#if _USE_LFN - char *fn = *fno.lfname ? fno.lfname : fno.fname; -#else - char *fn = fno.fname; -#endif - - /* - if (fno.fattrib & AM_DIR) { - // dir - } else { - // file - } - */ - - // make a string object for this entry - mp_obj_t entry_o; - if (is_str_type) { - entry_o = mp_obj_new_str(fn, strlen(fn), false); - } else { - entry_o = mp_obj_new_bytes((const byte*)fn, strlen(fn)); - } - - // add the entry to the list - mp_obj_list_append(dir_list, entry_o); - } - - f_closedir(&dir); - - return dir_list; + return fat_vfs_listdir(path, is_str_type); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_listdir_obj, 0, 1, os_listdir); |