summaryrefslogtreecommitdiff
path: root/tests/extmod/vfs_lfs.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-07-29 01:01:48 +1000
committerDamien George <damien@micropython.org>2020-08-25 17:35:19 +1000
commit2acc087880de39d7e17abc9344b8d2faba3478dd (patch)
treee7a8e21a14bad32ef1b78b351c8d754962e18d1c /tests/extmod/vfs_lfs.py
parentee50a6effebf315c38d4a129dc9f65ee722eb5b6 (diff)
extmod/vfs_lfs: Add mtime support to littlefs files.
This commit adds support for modification time of files on littlefs v2 filesystems, using file attributes. For some background see issue #6114. Features/properties of this implementation: - Only supported on littlefs2 (not littlefs1). - Uses littlefs2's general file attributes to store the timestamp. - The timestamp is 64-bits and stores nanoseconds since 1970/1/1 (if the range to the year 2554 is not enough then additional bits can be added to this timestamp by adding another file attribute). - mtime is enabled by default but can be disabled in the constructor, eg: uos.mount(uos.VfsLfs2(bdev, mtime=False), '/flash') - It's fully backwards compatible, existing littlefs2 filesystems will work without reformatting and timestamps will be added transparently to existing files (once they are opened for writing). - Files without timestamps will open correctly, and stat will just return 0 for their timestamp. - mtime can be disabled or enabled each mount time and timestamps will only be updated if mtime is enabled (otherwise they will be untouched). Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/extmod/vfs_lfs.py')
-rw-r--r--tests/extmod/vfs_lfs.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/extmod/vfs_lfs.py b/tests/extmod/vfs_lfs.py
index 609d9f949..8e56400df 100644
--- a/tests/extmod/vfs_lfs.py
+++ b/tests/extmod/vfs_lfs.py
@@ -35,6 +35,11 @@ class RAMBlockDevice:
return 0
+def print_stat(st, print_size=True):
+ # don't print times (just check that they have the correct type)
+ print(st[:6], st[6] if print_size else -1, type(st[7]), type(st[8]), type(st[9]))
+
+
def test(bdev, vfs_class):
print("test", vfs_class)
@@ -69,10 +74,10 @@ def test(bdev, vfs_class):
vfs.mkdir("testdir")
# stat a file
- print(vfs.stat("test"))
+ print_stat(vfs.stat("test"))
# stat a dir (size seems to vary on LFS2 so don't print that)
- print(vfs.stat("testdir")[:6])
+ print_stat(vfs.stat("testdir"), False)
# read
with vfs.open("test", "r") as f:
@@ -112,8 +117,8 @@ def test(bdev, vfs_class):
# create file in directory to make sure paths are relative
vfs.open("test2", "w").close()
- print(vfs.stat("test2"))
- print(vfs.stat("/testdir/test2"))
+ print_stat(vfs.stat("test2"))
+ print_stat(vfs.stat("/testdir/test2"))
vfs.remove("test2")
# chdir back to root and remove testdir