From 4b1fddec8a81ccc963b1a8a053f74409a315b003 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Fri, 30 Apr 2021 13:38:55 +0900 Subject: [PATCH] drivers/mtd/smart.c: Recover the missing link of directory entry When creating the next chain of directory entries, (1) add the position of next entry to the current sector, and then (2) update the sector of next entry. If the power is turned off between (1) and (2), the next entry will not be found, and the chain of directory entries will break. It causes the SmartFS file system corruption, and we will not be able to add files. To avoid this issue, in checking the filesystem by smart_fsck_directory, if the sector of next entry does not exist, update the sector of directory entry to invalidate the field of next entry. --- drivers/mtd/smart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 52b7bf32b8..1171d6b39a 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -5894,6 +5894,10 @@ static int smart_fsck_directory(FAR struct smart_struct_s *dev, ferr("Invalidate next log sector %d\n", nextsector); *(uint16_t *)chain->nextsector = 0xffff; + + /* Set flag to relocate later */ + + relocate = 1; } }