Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartfs: add partial support for FIOC_FILEPATH ioctl #13584

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

michallenc
Copy link
Contributor

Summary

The FIOC_FILEPATH ioctl call is required if smartfs is to be used together with inotify monitoring system. This partially implements the call support to smartfs file system.

The call currently does not work correctly if subdirectories are in the file's path. For example /dir/file will be returned correctly, but /dir/subdir/file will exclude the subdir part and return only /dir/file. The full support is complicated due to the SmartFS design.

The correct procedure would be to take the inode's path obtained by inode_getpath and let SmartFS recursively get the full path from the file. However, SmartFS entries do not keep the information about their parents and it is not possible to obtain the full path by going backwards. The file system currently takes the advantage of knowing the full path during the node creation/remove/rename/etc and does the forward search with node by node string comparison.

This possible solution would require the introduction of parent field in the entry structure and going backwards to obtain the full path. This would mean the modification of SmartFS structures including the ones stored in the NOR flash, most likely causing the incompatibility with previous versions.

Impact

SmartFS now at least partially work with inotify for calls that do not have direct knowledge of the full file path.

@github-actions github-actions bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Sep 23, 2024
@michallenc
Copy link
Contributor Author

I am not 100 % forcing this to be merged. It provides SmartFS with least partial support for inotify but does not handle correctly subdirectories and there is no way how to detect it at runtime and return error if subdirectory is present. On the other hand, there are both compile time and runtime warning describing this issue, so the user gets the memo.

I would generally prefer to merge this, but I understand if it is rejected. I currently don't have time to dive into SmartFS properly and rewrite it to provide the full support, but maybe it will inspire someone to finish this.

@xiaoxiang781216
Copy link
Contributor

one simple method is that smartfs_open cache the path into smartfs_ofile_s.

@michallenc
Copy link
Contributor Author

one simple method is that smartfs_open cache the path into smartfs_ofile_s.

Yes, but can we afford it for smaller microcontrollers with less memory? The maximum path length is 4 KBs if I remember correctly, although yes, the entire length won't be used in 99 % cases. But I suppose that's why most of the file systems do not store the entire path and iterate backwards to get it.

@xiaoxiang781216
Copy link
Contributor

one simple method is that smartfs_open cache the path into smartfs_ofile_s.

Yes, but can we afford it for smaller microcontrollers with less memory?

But if smartfs can't restore the full path from the leaf node like littlefs, the full path has to be record in open callback.

The maximum path length is 4 KBs if I remember correctly, although yes, the entire length won't be used in 99 % cases. But I suppose that's why most of the file systems do not store the entire path and iterate backwards to get it.

But in most case, the path is less than 128bytes.

@michallenc
Copy link
Contributor Author

michallenc commented Sep 25, 2024

Ok, then we can simplify this quite a lot. Updated to store the path during smartfs_open and free it during smartfs_close.

@michallenc michallenc force-pushed the smartfs_ioctl branch 2 times, most recently from 0a6aee4 to ede98e3 Compare September 25, 2024 12:39
fs/smartfs/smartfs.h Outdated Show resolved Hide resolved
fs/smartfs/smartfs_smart.c Outdated Show resolved Hide resolved
fs/smartfs/smartfs_smart.c Outdated Show resolved Hide resolved
fs/smartfs/smartfs_smart.c Outdated Show resolved Hide resolved
fs/smartfs/smartfs_smart.c Outdated Show resolved Hide resolved
The FIOC_FILEPATH ioctl call is required if smartfs is to be used
together with inotify monitoring system. This implements the
call support to smartfs file system. The path to the file has to
be stored in smartfs_ofile_s structure during file open (and is freed
during close) as smartfs currently is not able to obtain the path
knowing only the file node. The full path is concatenated with the file
name and creates the full path needed for inotify to detect whether
the file is on the watchlist.

Signed-off-by: Michal Lenc <[email protected]>
@xiaoxiang781216 xiaoxiang781216 merged commit 8639b1c into apache:master Sep 27, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: File System File System issues Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants