summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-06-28 14:46:49 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-06-28 14:46:49 -0700
commitd6a24afd71067102ca5e2ac9c2c81ddfae5ba140 (patch)
tree130de908bfeec1c0a2719a7c4dc8f73ff2be30ae
parent5ddbf26b62af230004219ec021c9e8ecd8abec26 (diff)
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.
-rw-r--r--atmel-samd/access_vfs.c8
-rw-r--r--py/runtime.c20
-rw-r--r--shared-module/storage/__init__.c12
3 files changed, 18 insertions, 22 deletions
diff --git a/atmel-samd/access_vfs.c b/atmel-samd/access_vfs.c
index 5dc47a7a1..0eb11b84e 100644
--- a/atmel-samd/access_vfs.c
+++ b/atmel-samd/access_vfs.c
@@ -42,15 +42,13 @@
#define VFS_INDEX 0
+// The root FS is always at the end of the list.
static fs_user_mount_t* get_vfs(int index) {
mp_vfs_mount_t* current_mount = MP_STATE_VM(vfs_mount_table);
- for (uint8_t i = 0; current_mount != NULL; i++) {
- if (i == VFS_INDEX) {
- return (fs_user_mount_t *) current_mount->obj;
- }
+ while (current_mount->next != NULL) {
current_mount = current_mount->next;
}
- return NULL;
+ return current_mount->obj;
}
//! This function tests memory state, and starts memory initialization
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;
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c
index 582b91a5b..97a049bac 100644
--- a/shared-module/storage/__init__.c
+++ b/shared-module/storage/__init__.c
@@ -78,16 +78,10 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
}
}
- // insert the vfs into the mount table
+ // Insert the vfs into the mount table by pushing it onto the front of the
+ // mount table.
mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table);
- while (*vfsp != NULL) {
- if ((*vfsp)->len == 1) {
- // make sure anything mounted at the root stays at the end of the list
- vfs->next = *vfsp;
- break;
- }
- vfsp = &(*vfsp)->next;
- }
+ vfs->next = *vfsp;
*vfsp = vfs;
}