summaryrefslogtreecommitdiff
path: root/stmhal/moduos.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-02-10 16:32:57 +0000
committerDamien George <damien.p.george@gmail.com>2016-02-10 23:40:10 +0000
commitb33a7705966a743c5e4c0c3c3bb83e6d97b5e84d (patch)
tree2c62a5389a7f0189119b5fcbbb9b30f0ff5b9db5 /stmhal/moduos.c
parent34023eb673d5356bb4eb6fc635d6d48eefb35135 (diff)
extmod/fsusermount: Support mounting of multiple block devices.
This patch adds support to fsusermount for multiple block devices (instead of just one). The maximum allowed is fixed at compile time by the size of the fs_user_mount array accessed via MP_STATE_PORT, which in turn is set by MICROPY_FATFS_VOLUMES. With this patch, stmhal (which is still tightly coupled to fsusermount) is also modified to support mounting multiple devices And the flash and SD card are now just two block devices that are mounted at start up if they exist (and they have special native code to make them more efficient).
Diffstat (limited to 'stmhal/moduos.c')
-rw-r--r--stmhal/moduos.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/stmhal/moduos.c b/stmhal/moduos.c
index cb2a73c11..293fbabaf 100644
--- a/stmhal/moduos.c
+++ b/stmhal/moduos.c
@@ -58,15 +58,6 @@
static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */
#endif
-STATIC bool sd_in_root(void) {
-#if MICROPY_HW_HAS_SDCARD
- // TODO this is not the correct logic to check for /sd
- return sdcard_is_present();
-#else
- return false;
-#endif
-}
-
STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename,
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
@@ -144,12 +135,11 @@ STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) {
// "hack" to list root directory
if (path[0] == '/' && path[1] == '\0') {
mp_obj_t dir_list = mp_obj_new_list(0, NULL);
- mp_obj_list_append(dir_list, MP_OBJ_NEW_QSTR(MP_QSTR_flash));
- if (sd_in_root()) {
- mp_obj_list_append(dir_list, MP_OBJ_NEW_QSTR(MP_QSTR_sd));
- }
- if (MP_STATE_PORT(fs_user_mount) != NULL) {
- mp_obj_list_append(dir_list, mp_obj_new_str(MP_STATE_PORT(fs_user_mount)->str + 1, MP_STATE_PORT(fs_user_mount)->len - 1, false));
+ for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
+ fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
+ if (vfs != NULL) {
+ mp_obj_list_append(dir_list, mp_obj_new_str(vfs->str + 1, vfs->len - 1, false));
+ }
}
return dir_list;
}
@@ -298,21 +288,32 @@ STATIC mp_obj_t os_stat(mp_obj_t path_in) {
#endif
FRESULT res;
- if (path_equal(path, "/") || path_equal(path, "/flash") || path_equal(path, "/sd")) {
- // stat built-in directory
- if (path[1] == 's' && !sd_in_root()) {
- // no /sd directory
- res = FR_NO_PATH;
- goto error;
- }
+ if (path_equal(path, "/")) {
+ // stat root directory
fno.fsize = 0;
fno.fdate = 0;
fno.ftime = 0;
fno.fattrib = AM_DIR;
} else {
- res = f_stat(path, &fno);
+ res = FR_NO_PATH;
+ for (size_t i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount)); ++i) {
+ fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
+ if (vfs != NULL && path_equal(path, vfs->str)) {
+ // stat mounted device directory
+ fno.fsize = 0;
+ fno.fdate = 0;
+ fno.ftime = 0;
+ fno.fattrib = AM_DIR;
+ res = FR_OK;
+ }
+ }
+ if (res == FR_NO_PATH) {
+ // stat normal file
+ res = f_stat(path, &fno);
+ }
if (res != FR_OK) {
- goto error;
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
+ MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
}
}
@@ -343,9 +344,6 @@ STATIC mp_obj_t os_stat(mp_obj_t path_in) {
t->items[9] = MP_OBJ_NEW_SMALL_INT(seconds); // st_ctime
return t;
-
-error:
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat);