summaryrefslogtreecommitdiff
path: root/extmod/vfs_lfsx_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/vfs_lfsx_file.c')
-rw-r--r--extmod/vfs_lfsx_file.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/extmod/vfs_lfsx_file.c b/extmod/vfs_lfsx_file.c
index f74b41837..bc1a37b90 100644
--- a/extmod/vfs_lfsx_file.c
+++ b/extmod/vfs_lfsx_file.c
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2019 Damien P. George
+ * Copyright (c) 2019-2020 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -101,6 +101,17 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod
#endif
o->cfg.buffer = &o->file_buffer[0];
+ #if LFS_BUILD_VERSION == 2
+ if (self->enable_mtime) {
+ lfs_get_mtime(&o->mtime[0]);
+ o->attrs[0].type = LFS_ATTR_MTIME;
+ o->attrs[0].buffer = &o->mtime[0];
+ o->attrs[0].size = sizeof(o->mtime);
+ o->cfg.attrs = &o->attrs[0];
+ o->cfg.attr_count = MP_ARRAY_SIZE(o->attrs);
+ }
+ #endif
+
const char *path = MP_VFS_LFSx(make_path)(self, path_in);
int ret = LFSx_API(file_opencfg)(&self->lfs, &o->file, path, flags, &o->cfg);
if (ret < 0) {
@@ -131,6 +142,11 @@ STATIC mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t s
STATIC mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in);
MP_VFS_LFSx(check_open)(self);
+ #if LFS_BUILD_VERSION == 2
+ if (self->vfs->enable_mtime) {
+ lfs_get_mtime(&self->mtime[0]);
+ }
+ #endif
LFSx_API(ssize_t) sz = LFSx_API(file_write)(&self->vfs->lfs, &self->file, buf, size);
if (sz < 0) {
*errcode = -sz;