Open cfriedt opened 4 months ago
A fair bit of this has been done without public API already.
I'm fine not making a public API for this until post LTSv3, as it could take some time to smooth out and properly document.
Updated to reflect that the the posix device_io and fd_mgmt features were reverted.
This puts LTSv3 in a kind of dilapidated state from the POSIX & libc perspective.
Is your enhancement proposal related to a problem? Please describe.
As part of the POSIX Roadmap for LTSv3, we should implement a common abstraction for
FILE *
andint
file descriptors that can be used throughout Zephyr applications.Describe the solution you'd like
The abstraction serves to support
FILE *
operations)FILE *
operations andint
operations on files, devices, sockets, etc)and should call into existing Zephyr subsystems such as Networking and Filesystem, which are part of Zephyr.
Other APIs such as POSIX, and C should call into ZVFS and not the opposite in order to eliminate API-level dependency cycles and to provide a more fully-featured and standard-conformant API.
Describe alternatives you've considered
Additional context
There are a number of other issues currently assigned to the C Library highlighting missing C89 functions. Many of these should be a part of the Common C Library, as they are OS-dependent and mostly libc-independent.
https://github.com/zephyrproject-rtos/zephyr/issues?q=is%3Aopen+is%3Aissue+label%3A%22area%3A+C+Library%22+%22libc%3A+implement%22+
Details to be worked-out:
struct fd_entry
could betypedef
ed astypedef struct zvfs_entry FILE
fdtable[]
could server as a LUT mappingint
toFILE *
struct zvfs_mode
, which could betypedef
ed tomode_t
struct fd_entry
requires astruct zvfs_mode
to differentiate between block, char special files, links, directories, sockets, pipes, etcZVFS_
mode prefixFILE *
orint
file descriptor operations (i.e. duplicate all functions, macros enabled withPOSIX_DEVICE_IO
,POSIX_FILE_SYSTEM
,POSIX_NETWORKING
,POSIX_MAPPED_FILES
,POSIX_FD_MGMT
) but prefix them withzvfs_
.struct fd_op_vtable
. However, keep in mind, that Zephyr overloadsioctl()
to achieve a lot of optional POSIX file descriptor functionality. E.g.lseek()
->ZFD_IOCTL_FSYNC
./usr/include/linux/sockios.h
in Linuxstruct zvfs_fdset
->fdset
,struct zsock_poll
->struct zvfs_poll
,FD_ISSET()
->ZVFS_FD_ISSET()
).