10000 Change vfs mount ordering such that the root is always last in the · ladyada/circuitpython@d6a24af · GitHub
[go: up one dir, main page]

Skip to content

Commit d6a24af

Browse files
committed
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.
1 parent 5ddbf26 commit d6a24af

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

atmel-samd/access_vfs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@
4242

4343
#define VFS_INDEX 0
4444

45+
// The root FS is always at the end of the list.
4546
static fs_user_mount_t* get_vfs(int index) {
4647
mp_vfs_mount_t* current_mount = MP_STATE_VM(vfs_mount_table);
47-
for (uint8_t i = 0; current_mount != NULL; i++) {
48-
if (i == VFS_INDEX) {
49-
return (fs_user_mount_t *) current_mount->obj;
50-
}
48+
while (current_mount->next != NULL) {
5149
current_mount = current_mount->next;
5250
}
53-
return NULL;
51+
return current_mount->obj;
5452
}
5553

5654
//! This function tests memory state, and starts memory initialization

py/runtime.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,22 @@ void mp_init(void) {
117117

118118
#if MICROPY_VFS
119119
#if MICROPY_FATFS_NUM_PERSISTENT > 0
120+
// We preserve the last MICROPY_FATFS_NUM_PERSISTENT mounts because newer
121+
// mounts are put at the front of the list.
120122
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
121-
if (vfs != NULL) {
122-
MP_STATE_VM(vfs_cur) = vfs;
123+
// Count how many mounts we have.
124+
uint8_t count = 0;
125+
while (vfs != NULL) {
126+
vfs = vfs->next;
127+
count++;
123128
}
124-
// Skip forward until the vfs->next pointer is the first vfs that shouldn't
125-
// persist.
126-
uint8_t i = 1;
127-
while (vfs != NULL && i < MICROPY_FATFS_NUM_PERSISTENT) {
129+
// Find the vfs MICROPY_FATFS_NUM_PERSISTENT mounts from the end.
130+
vfs = MP_STATE_VM(vfs_mount_table);
131+
for (uint8_t j = 0; j < count - MICROPY_FATFS_NUM_PERSISTENT; j++) {
128132
vfs = vfs->next;
129-
i++;
130133
}
131-
vfs->next = NULL;
134+
MP_STATE_VM(vfs_mount_table) = vfs;
135+
MP_STATE_VM(vfs_cur) = vfs;
132136
#else
133137
// initialise the VFS sub-system
134138
MP_STATE_VM(vfs_cur) = NULL;

shared-module/storage/__init__.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,10 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
7878
}
7979
}
8080

81-
// insert the vfs into the mount table
81+
// Insert the vfs into the mount table by pushing it onto the front of the
82+
// mount table.
8283
mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table);
83-
while (*vfsp != NULL) {
84-
if ((*vfsp)->len == 1) {
85-
// make sure anything mounted at the root stays at the end of the list
86-
vfs->next = *vfsp;
87-
break;
88-
}
89-
vfsp = &(*vfsp)->next;
90-
}
84+
vfs->next = *vfsp;
9185
*vfsp = vfs;
9286
}
9387

0 commit comments

Comments
 (0)
0