aboutsummaryrefslogtreecommitdiff
path: root/extmod/vfs.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-03-11 14:24:26 +1100
committerDamien George <damien.p.george@gmail.com>2020-03-11 14:24:26 +1100
commited848553b408e14746f0ce96c8b20517bfdede35 (patch)
tree910e0f26564a011b32c301ae792c138b6cffb92b /extmod/vfs.c
parent554c01fc256640b9e88578b9d0310b53a8786fef (diff)
extmod/vfs: Factor out vfs mount-and-chdir helper from stm32.
Diffstat (limited to 'extmod/vfs.c')
-rw-r--r--extmod/vfs.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/extmod/vfs.c b/extmod/vfs.c
index d8bc02c6f..79a8e8509 100644
--- a/extmod/vfs.c
+++ b/extmod/vfs.c
@@ -524,4 +524,25 @@ mp_obj_t mp_vfs_statvfs(mp_obj_t path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_statvfs_obj, mp_vfs_statvfs);
+// This is a C-level helper function for ports to use if needed.
+int mp_vfs_mount_and_chdir_protected(mp_obj_t bdev, mp_obj_t mount_point) {
+ nlr_buf_t nlr;
+ mp_int_t ret = -MP_EIO;
+ if (nlr_push(&nlr) == 0) {
+ mp_obj_t args[] = { bdev, mount_point };
+ mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map);
+ mp_vfs_chdir(mount_point);
+ ret = 0; // success
+ nlr_pop();
+ } else {
+ mp_obj_base_t *exc = nlr.ret_val;
+ if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_OSError))) {
+ mp_obj_t v = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(exc));
+ mp_obj_get_int_maybe(v, &ret); // get errno value
+ ret = -ret;
+ }
+ }
+ return ret;
+}
+
#endif // MICROPY_VFS