Skip to content

Commit

Permalink
extmod/moduos: Move os.sync() into extmod/moduos.c.
Browse files Browse the repository at this point in the history
Avoiding code duplication.  To enable it, set MICROPY_PY_UOS_SYNC in the
port's mpconfigport.h.  It is operational only for FAT file system.  For
other filesystems it's a no-op.

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh authored and dpgeorge committed Jun 1, 2023
1 parent b85611d commit 5a991b4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions extmod/moduos.c
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5a991b4

Please sign in to comment.