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

FS/littlefs: it is possible to write to already deleted file #32990

Closed
nvlsianpu opened this issue Mar 5, 2021 · 8 comments
Closed

FS/littlefs: it is possible to write to already deleted file #32990

nvlsianpu opened this issue Mar 5, 2021 · 8 comments

Comments

@nvlsianpu
Copy link
Collaborator

nvlsianpu commented Mar 5, 2021

Describe the bug
It is possible to write to file which was removed if it had been opened before removal.

To Reproduce
fs_open(&f, "lfs1/fname", FS_O_CREATE | FS_O_WRITE);
fs_write(&f, data, length);
fs_unlink("lfs1/fname");
fs_write(&f, data, length); /* will succedd */

Expected behavior
shouldn't be possible to write to a unlinked file

Alternative Expected behavior
the file which is opened can't be unlinked.

Impact
Thread which writes to the file might be not aware that another thread deleted the file. This cause data lost.

@nvlsianpu nvlsianpu added bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug area: File System labels Mar 5, 2021
@nvlsianpu
Copy link
Collaborator Author

@pabigot I encountered this issue while testing FS log backend.

@pabigot
Copy link
Collaborator

pabigot commented Mar 5, 2021

I think that behavior is correct: unlinking simply removes the directory entry, it won't invalidate the file.

That idiom has long been used on Unix systems to create a temporary file to hold data so the space is reclaimed when the last open descriptor closes.

@pabigot pabigot added question and removed bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug labels Mar 5, 2021
@pabigot
Copy link
Collaborator

pabigot commented Mar 5, 2021

IOW, I don't think this is a bug, unless the FS API explicitly requires a failure when writing to an open file where the underlying storage has been deleted. And if that's so, it may not be something that can be fixed.

@nvlsianpu
Copy link
Collaborator Author

cc @de-nordic

@nvlsianpu
Copy link
Collaborator Author

Maybe expected behavior should be that the file which is opened can't be unlinked.

@de-nordic
Copy link
Collaborator

@nvlsianpu , @pabigot

This is VFS design compromise that is deficiency when parallel access to file system is exercised.
It has never been specified what should happen when opened file is deleted, and the issue also does exists with read operations, or files opened as read-only.
I do not thin that this has been predicted to be happening as probably the original idea has been that the developer is the only one to have control on files, their existence and their access time-line, which means that the developer is responsible for not removing files he is working on.

Maybe expected behavior should be that the file which is opened can't be unlinked.

This will require rework of VFS, because the VFS does not hold registry of all opened files, as the user is responsible for providing structures for file system information, so it is not aware of files that are currently opened or being accessed.
The LittleFS back-end in VFS is responsible for allocating and providing to LittleFS driver, file information structures which means that information for each opened file is stored separately and not within the LittleFS back-end.

@github-actions
Copy link

github-actions bot commented May 8, 2021

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label May 8, 2021
@de-nordic de-nordic removed the Stale label May 10, 2021
@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants