From d6a24afd71067102ca5e2ac9c2c81ddfae5ba140 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 28 Jun 2017 14:46:49 -0700 Subject: Change vfs mount ordering such that the root is always last in the linked list. Its also the only one statically allocated and made available over USB. --- py/runtime.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'py/runtime.c') diff --git a/py/runtime.c b/py/runtime.c index 504c17c15..1eb6da433 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -117,18 +117,22 @@ void mp_init(void) { #if MICROPY_VFS #if MICROPY_FATFS_NUM_PERSISTENT > 0 + // We preserve the last MICROPY_FATFS_NUM_PERSISTENT mounts because newer + // mounts are put at the front of the list. mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); - if (vfs != NULL) { - MP_STATE_VM(vfs_cur) = vfs; + // Count how many mounts we have. + uint8_t count = 0; + while (vfs != NULL) { + vfs = vfs->next; + count++; } - // Skip forward until the vfs->next pointer is the first vfs that shouldn't - // persist. - uint8_t i = 1; - while (vfs != NULL && i < MICROPY_FATFS_NUM_PERSISTENT) { + // Find the vfs MICROPY_FATFS_NUM_PERSISTENT mounts from the end. + vfs = MP_STATE_VM(vfs_mount_table); + for (uint8_t j = 0; j < count - MICROPY_FATFS_NUM_PERSISTENT; j++) { vfs = vfs->next; - i++; } - vfs->next = NULL; + MP_STATE_VM(vfs_mount_table) = vfs; + MP_STATE_VM(vfs_cur) = vfs; #else // initialise the VFS sub-system MP_STATE_VM(vfs_cur) = NULL; -- cgit v1.2.3