-
Couldn't load subscription status.
- Fork 8.1k
Description
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 * and int file descriptors that can be used throughout Zephyr applications.
Describe the solution you'd like
The abstraction serves to support
- ISO C (
FILE *operations) - POSIX (
FILE *operations andintoperations 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
- posix: standardize kconfig options #73047
- posix: device_io: implement fdopen(), fileno(), pread(), pselect(), pwrite() #73978
- posix: add support for mmap, memlock, shared memory, and mprotect #73799
- posix: fd_mgmt: implement dup(), dup2(), fseeko(), and ftello() #74096
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.
Details to be worked-out:
struct fd_entrycould betypedefed astypedef struct zvfs_entry FILEfdtable[]could server as a LUT mappinginttoFILE *- Zephyr needs to define a
struct zvfs_mode, which could betypedefed tomode_t struct fd_entryrequires astruct zvfs_modeto differentiate between block, char special files, links, directories, sockets, pipes, etc- All of those identifiers should also have a unique
ZVFS_mode prefix - we need to account for most
FILE *orintfile 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_. - all of the other functionality will need to be "squeezed in" to
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. - refer to e.g.
/usr/include/linux/sockios.hin Linux - Functionality may need to move down the stack (into the Zephyr kernel or middleware layers) from net, fs, posix. Do this very sparingly.
- for polll, select, etc, we will want to rename the zsock equivalent sets and structures (
struct zvfs_fdset->fdset,struct zsock_poll->struct zvfs_poll,FD_ISSET()->ZVFS_FD_ISSET()).