-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Introduction
- Each node in Jffs2 has multiple versions.
- Unlinking an inode is accomplished by setting the
inoof the correspondingdirentnodes to zero. - When mounting, we do a linear scan if the nodes on the jffs filesystem.
- We associate a list of version of a dirent with (parent inode, filename of the dirent).
- When we encounter a dirent version with
ino=0, we remove all versions of that dirent and consider the file lost & found.
Potential problem
I have been unable to find a guarantee that the nodes are ordered by version on disk, especially after a garbage collection cycle or wear leveling operations.
Consider the following layout on disk, where the latest version comes first
entry1 (dirent version=2 ino=0) # Unlink
entry2 (dirent version=1 ino=3) # Hardlink
Here, we first delete all versions of the dirent (there are none), but then erroneously recreate the mapping when we scan entry2.
The recreation is invalid because the version of the node (1) is older than the most recent one (2).
Reproduction
I have not been able to reproduce it because it is yet unclear how to force the ordering of nodes.
This report is solely based on code inspection.
Possible solution
Instead of deleting all dirents, keep the entry with ino=0 and prune later on.
***Uknown* ****: Can there be new versions of a dirent after an unlink operation?