Skip to content

os: add zephyr virtual filesystem (zvfs) api #72894

@cfriedt

Description

@cfriedt

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 and int 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 be typedefed as typedef struct zvfs_entry FILE
  • fdtable[] could server as a LUT mapping int to FILE *
  • Zephyr needs to define a struct zvfs_mode, which could be typedefed to mode_t
  • struct fd_entry requires a struct zvfs_mode to 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 * or int file descriptor operations (i.e. duplicate all functions, macros enabled with POSIX_DEVICE_IO, POSIX_FILE_SYSTEM, POSIX_NETWORKING, POSIX_MAPPED_FILES, POSIX_FD_MGMT) but prefix them with zvfs_.
  • all of the other functionality will need to be "squeezed in" to struct fd_op_vtable. However, keep in mind, that Zephyr overloads ioctl() to achieve a lot of optional POSIX file descriptor functionality. E.g. lseek() -> ZFD_IOCTL_FSYNC.
  • refer to e.g. /usr/include/linux/sockios.h in 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()).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions