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
subsys: fs: Support file open flags to fs and POSIX API #26305
subsys: fs: Support file open flags to fs and POSIX API #26305
Conversation
e6bdb4e
to
b6565e4
Compare
POSIX is an API specification, so "adding to posix API" does not make sense, because then it's not posix anymore. I think we should instead fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should fix open() (by not unconditionally adding O_CREAT) and not introduce open2() at all.
/* NOTE: The Zephyr fs_open_ex flags allow opening existing files | ||
* with READ/WRITE access, as it happens in fs_open_ex above, but | ||
* the LittleFS assumes READ/WRITE access by default if no access | ||
* is selected which same as requesting READ ONLY and WRITE ONLY | ||
* access at the same time (bug?). | ||
* From Zephyr API point of view below tests should fail but they | ||
* will succeed, which is expected (?) behaviour of LittleFS; | ||
* that is why this test is left here commented out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding you right, you are saying that littlefs requires flags to be either LFS_O_RDONLY
, LFS_O_WRONLY
, or LFS_O_RDWR
, and passing a flag value of 0 is treated the same as LFS_O_RDWR
. If that's true, shouldn't it be the job of lfs_flags_from_zephyr
to never pass a flag value of 0 to lfs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lfs_flags_from_zephyr
is supposed to translate flags to obtain, from fs backend, specific behavior. I guess that the READONLY would be closest to expected.
I am not sure I can do that immediately because someone may be using current implementation the way it is. If it just gets changed then the code will stop working. Maybe there should be some Kconfig added that would enable compatibility with the original behavior for some time. |
b6565e4
to
81ac831
Compare
daea928
to
51317e4
Compare
51317e4
to
a785f8c
Compare
767d2e1
to
bc21a46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike FILE_SYSTEM_LEGACY_OPEN
. I suggest using some macro tricks like the ones described at https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros, which will let users continue to pass either 2 or 3 arguments to fs_open
, so that both existing code and new code can coexist and work correctly. For example, this test appears to do the trick:
#include <stdio.h>
#define FO_READ 0x01
#define FO_WRITE 0x02
#define FO_RDWR (FO_READ | FO_WRITE)
#define FO_CREATE 0x10
void real_fs_open(void *p, const char *path, int flags) {
printf("open(p=%p, path=\"%s\", flags=0x%02x)\n", p, path, flags);
}
void legacy_fs_open(void *p, const char *path) {
return real_fs_open(p, path, FO_CREATE | FO_RDWR);
}
/* With 0-2 arguments, fs_open(...) resolves to legacy_fs_open(...)
With 3 arguments, fs_open(...) resolves to real_fs_open(...)
More arguments are not handled.
*/
#define GET_ARG4(arg1, arg2, arg3, arg4, ...) arg4
#define OPEN_CHOOSE(...) GET_ARG4( \
__VA_ARGS__, real_fs_open, \
legacy_fs_open, legacy_fs_open, legacy_fs_open)
#define fs_open(...) OPEN_CHOOSE(__VA_ARGS__)(__VA_ARGS__)
/* Use example: */
main()
{
char p;
fs_open(&p, "/no-flags");
fs_open(&p, "/with-flags", FO_READ);
return 0;
}
Output:
$ gcc -Wall -pedantic -o test test.c
$ ./test
open(p=0x7fff85ee440f, path="/no-flags", flags=0x13)
open(p=0x7fff85ee440f, path="/with-flags", flags=0x01)
As for the POSIX side, I would just fix it and not support the old broken behavior at all. If it's still made configurable, I would strongly suggest making it default to the correct open() API; otherwise it doesn't make sense to call it POSIX at all, and I am certain that anyone attempting to port POSIX code to Zephyr would welcome the fix.
OK I can do that. I just hoped to deprecate the old function signature with time and leave the 3 parameter thing only.
I do not know how many users have been using this in the form it is. The "legacy" behavior is supposed to be deprecated after some time. The programmers should be given time to adjust code. If we will keep on breaking their applications without giving time to adjust to changes, they will be reluctant to update Zephyr within their projects. |
9d7ec7b
to
3650ef7
Compare
That sounds good. You could use the macro and mark the old signature with
I don't think it's a big deal either way, but I would still learn towards fixing it because:
So basically the only case where someone would get bitten by the change is if they were previously passing flags that didn't match the behavior they actually wanted -- ie. if they were passing "O_RDONLY" and then expecting to be able to write the file. I would suggest naming the configuration option
Unfortunately, because |
3650ef7
to
99931e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One style change, one spelling fix.
91137c5
to
ecfd342
Compare
ecfd342
to
656f46c
Compare
@pabigot Thanks! |
656f46c
to
26b0a93
Compare
This is no longer relevant because I has been decided to drop compatibility with two parameter ffs_open.
west.yml
Outdated
@@ -92,7 +92,7 @@ manifest: | |||
revision: d52aff5065ab5995f785877a834112461ff93526 | |||
path: bootloader/mcuboot | |||
- name: mcumgr | |||
revision: 898a5a7f5224be8345e58eca3b9a84389ed61d15 | |||
revision: pull/26/head |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use cfe5eb98a9493017448846fd1a44a9340bd0a22f
The fs_open has been extended with support for open flags. Currently supported flags are: FS_O_READ -- open for read FS_O_WRITE -- open for write FS_O_CREATE -- create file if it does not exist FS_O_APPEND -- move to the end of file before each write The FAT FS and LittleFS front-ends within the Zephyr has also been modified to utilize the flags. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Now fs_open supports open flags and the lvgl_fs code requires update. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Now fs_open supports open flags and the fuse requires update. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Common procedure, to use with fs back-ends, have been added for testing various fs_open flags combinations. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The addition of support for open flags, within fs_open, requires addition of new test cases to FAT FS back-end tests. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The addition of support for open flags, within fs_open, requires addition of new test cases. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit changes signature of open function from: int open(const char *name, int flags) to int open(const char *name, int flags, ...) Currently existing two argument invocations should not require any rework. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The fs_open flags has been changed to accept open flags, which requires changes to open(...) to support the new flags. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Add new tests that will utilize open mode flags with the open function. A few test functions which assumed O_CREAT behavior are updated to specify it explicitly. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Update release notes API change section with information on change to fs_open parameter list. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit updates mcumgr with latest snapshot from the upstream. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
26b0a93
to
87c63b0
Compare
{DNM] Due to required update to mcumgr, that is reviewed here: apache/mynewt-mcumgr#90
and requires update of https://github.com/zephyrproject-rtos/mcumgr
Anyone that is able to review apache/mynewt-mcumgr#90 please do so!
This series of commits adds support for file open flags (CREATE, APPEND, etc.) and fs_open_ex function to support them.
POSIX API was updated accordingly.
RFC Issue: #26833
Resolves: #16638
Requires changes to mcumgr: apache/mynewt-mcumgr#90Requires changes to mcumgr, for the regression to pass, brought by snapshot update: zephyrproject-rtos/mcumgr#26