[WIP][fs] Setup streams of minimal libc to use fdtable for more unified manner. #79397
+152
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a WIP PR, the description will be updated at a later point of time.
To implement file io functions like fopen, fwrite in minimal libc, fs support is needed. To have this support fdtable will be leveraged, as this facilitates the conversion between posix fd and standard files.
For starters, define the standard streams (stdio, stdout) as an fd_entry which has the virtual methods for read and write. This follows the same approach as POSIX DEVICE IO. The std streams will be installed during hook install step which zephyr os calls during application bootstrap. If the file support is not needed then the streams can fall back to integers (We can consider using fd_entry for them as well and have the fd numbers as an object - but it probably uses unnecessary space in code hence opted for simple integers).
Split the vmethods for each streams as each of them will perform different operations.
How can this be used for fopen, fwrite etc? Similar vmethods will be written on top of fs apis.
This PR just aims at showing the concept and get reviewers opinion on this approach, unit tests and proper flags will be defined in a followup revision.
Tested locally using
./scripts/twister -i -T tests/posix -T tests/lib/c_lib -p qemu_x86_64 -p qemu_riscv64
and validated functionality using a simple app that prints hello world.