summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extmod/moduos.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/extmod/moduos.c b/extmod/moduos.c
index 87a611148..a245ae728 100644
--- a/extmod/moduos.c
+++ b/extmod/moduos.c
@@ -34,6 +34,10 @@
#if MICROPY_VFS_FAT
#include "extmod/vfs_fat.h"
+#if MICROPY_PY_UOS_SYNC
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
+#endif
#endif
#if MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2
@@ -58,6 +62,21 @@
#define MICROPY_BUILD_TYPE_PAREN
#endif
+#if MICROPY_PY_UOS_SYNC
+// sync()
+// Sync all filesystems.
+STATIC mp_obj_t mp_uos_sync(void) {
+ #if MICROPY_VFS_FAT
+ for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) {
+ // this assumes that vfs->obj is fs_user_mount_t with block device functions
+ disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL);
+ }
+ #endif
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync);
+#endif
+
#if MICROPY_PY_UOS_UNAME
#if MICROPY_PY_UOS_UNAME_RELEASE_DYNAMIC