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

posix: implement FILE_LOCKING, SYSTEM_DATABASE, SYSTEM_DATABASE_R #83368

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

@cfriedt cfriedt requested a review from ycsin December 24, 2024 17:59
@cfriedt cfriedt force-pushed the create-posix-system-database-option-group branch 13 times, most recently from b69c332 to 0126d05 Compare December 26, 2024 16:18
@cfriedt
Copy link
Member Author

cfriedt commented Dec 26, 2024

checkpatch false positives 🙄

int dirfd(DIR *dirp);
DIR *fdopendir(int fd);
 SPACING: need consistent spacing around '*' (ctx:WxV)
File:include/zephyr/posix/dirent.h
Line:22
 SPACING: need consistent spacing around '*' (ctx:WxV)
File:include/zephyr/posix/dirent.h
Line:24

@cfriedt cfriedt force-pushed the create-posix-system-database-option-group branch 15 times, most recently from cca3776 to fdbfb54 Compare January 1, 2025 12:46
@cfriedt cfriedt force-pushed the create-posix-system-database-option-group branch 12 times, most recently from 4e17db6 to fb1cb22 Compare January 8, 2025 02:18
@cfriedt cfriedt force-pushed the create-posix-system-database-option-group branch from fb1cb22 to 6b79e37 Compare January 10, 2025 03:34
Newlib currently relies on calling stat() indirectly via
_fstat_r() when performing certain stdio file operations
(e.g. reading a file).

However, that results in errno being set to 95 (EOPNOTSUPP)
in unexpected places, which causes non-determinism and
unpredictability, and it is inconsistent with both picolibc
and the minimal libc.

Normally, it would be a great opportunity to implement
zvfs_stat() via fs_stat(). However, the current implementation
of fs_stat() is not particularly useful to call from
zvfs_stat() since fs_state() relies on an absolute path passed
as the first parameter and it is currently _difficult_ to get
that from an integer file descriptor.

In the ideal world, it would be possible to extrapolate the
absolute path of a filename from a fs_file_t oobject or
some other filesystem subsystem API.

Since it is not practical to modify Newlib to change the way it
performs standard C I/O, simply add a no-op operations for the
fs subsystem vtable.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Previously, there was an implicit assumption that Zephyr's
internal struct fd_entry * was synonymous with FILE * from
the C library.

This is generally not the case and aliasing these two
distinct types was preventing a fair bit of functionality
from Just Working - namely stdio function calls like
fgets() and fopen(). The problem can be seen directly
when trying to use a function like zvfs_fdopen().

Instead of aliasing the two types, require that all Zephyr
C libraries provide a z_libc_file_alloc() function that
allocates and populates the required fields of a FILE
object.

Zephyr currently only provides the integer file descriptor
to the C library for initializing FILE objects.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Provide an implementation for the POSIX_SYSTEM_DATABASE_R
Option Group.

This group is required for all conforming implementations and is
therefore required for PSE51, PSE52, PSE53, PSE54, and all other
possible subprofiles.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a teststuite to exercise the POSIX_SYSTEM_DATABASE_R
Option Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Mark the POSIX_SYSTEM_DATABASE_R Option Group as supported.

This Option Group is required for all conformant implementations
as part of the _POSIX_THREAD_SAFE_FUNCTIONS Option.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Provide an implementation for the POSIX_SYSTEM_DATABASE Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a testsuite for the POSIX_SYSTEM_DATABASE Option Group

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Mark the POSIX_SYSTEM_DATABASE Option Group as supported.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Provide an implementation of the POSIX_FILE_LOCKING Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a testsuite for the POSIX_FILE_LOCKING Option Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Mark POSIX_FILE_LOCKING as supported. This Option Group is part
of the _POSIX_THREAD_SAFE_FUNCTIONS Option and is mandatory for
all conforming implementations.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The functions associated with the _POSIX_THREAD_SAFE_FUNCTIONS
Option are members of other POSIX Option Groups. Specifically,
POSIX_C_LANG_SUPPORT_R, POSIX_FILE_LOCKING, POSIX_FILE_SYSTEM_R,
and POSIX_SYSTEM_DATABASE_R.

Moreover, _POSIX_THREAD_SAFE_FUNCTIONS is required to be
available with any conforming implementation.

Therefore, it does not make sense to have a Kconfig option to
turn it off or on; it should be enabled or disabled based on
whether the required POSIX Option Groups are active.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Mark the _POSIX_THREAD_SAFE_FUNCTIONS Option as supported.

This Option is required mandatory for any conformant
implementation and is comprised of functions belonging to the
following Option Groups:

- POSIX_C_LANG_SUPPORT_R
- POSIX_FILE_LOCKING
- POSIX_FILE_SYSTEM_R
- POSIX_SYSTEM_DATABASE_R

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant