Skip to content

Conversation

@fkokosinski
Copy link
Member

This PR:

  • moves all operations on single files into ZVFS and makes the POSIX subsystem call into ZVFS to perform them
  • simplifies cooperation between different file access APIs (current & future)
  • makes preparation for the file descriptor table becoming optional

It was necessary to define a struct zvfs_stat to avoid a dependency cycle. Functions used internally for file i/o operations are publicised since they won't require any changes between various subsystems. This allows ZVFS to actually fulfill its purpose of facilitating cooperation of different file APIs.

The file descriptor table is used in every area that expects to work on files through descriptor indices. It can only be operated on through functions whose names indicate a relationship with ZVFS (zvfs_*fd*). The integer file descriptor mechanism shouldn't be separate from ZVFS.

lib/os/fdtable.c Outdated
#include <zephyr/fs/fs.h>

struct stat;
K_MEM_SLAB_DEFINE(file_desc_slab, sizeof(struct fs_file_t), CONFIG_ZVFS_OPEN_MAX, 4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that after the commit 1cfdf7c, you need to use ZVFS_OPEN_SIZE define instead of CONFIG_ZVFS_OPEN_MAX (as the latter is set to 0 in typical use cases).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks!

@fkokosinski fkokosinski force-pushed the 84656-rework_zvfs branch 5 times, most recently from 8c36f05 to 5e6c7fa Compare November 6, 2025 15:14
Jakub Klimczak added 3 commits November 7, 2025 01:12
This commit moves all operations on single files into ZVFS and makes the
POSIX subsystem call into ZVFS to perform them. It was necessary to define
a `struct zvfs_stat` to avoid a dependency cycle. Functions used
internally for file i/o operations are publicised since they won't require
any changes between various subsystems. This allows ZVFS to actually
fulfill its purpose of facilitating cooperation of different file APIs.

Signed-off-by: Jakub Klimczak <jklimczak@internships.antmicro.com>
The file descriptor table is used in every area that expects to work on
files through descriptor indices. It can only be operated on through
functions whose names indicate a relationship with ZVFS (`zvfs_*fd*`).
The integer file descriptor mechanism shouldn't be separate from ZVFS.
This will make cooperation between different file access APIs much
simpler. This commit also makes preparations for the fdtable becoming
optional.

Signed-off-by: Jakub Klimczak <jklimczak@internships.antmicro.com>
This removes a function that created a new mutex and conditional variable
and used memcpy() to compare them with ones in a given fdtable entry.
Since those struct members are initialized statically, this test doesn't
serve much of a purpose anymore. Moreover, padding bytes inside structs
are technically not required to be zero, so these memcpy() calls caused
SonarQube to complain.

Signed-off-by: Jakub Klimczak <jklimczak@internships.antmicro.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 7, 2025

@fkokosinski fkokosinski marked this pull request as ready for review November 7, 2025 00:45
@zephyrbot zephyrbot added area: POSIX POSIX API Library area: Networking area: Sockets Networking sockets area: Tests Issues related to a particular existing or missing test area: Samples Samples area: Base OS Base OS Library (lib/os) area: HTTP HTTP client/server support area: Wi-Fi Wi-Fi labels Nov 7, 2025
Copy link
Contributor

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again why are we investing into this?
I do not see any reason for ZVFS and POSIX to coexist in one system.
Has anyone noticed that this is basically requiring something like 4-5 stack frames from POSIX to FS to even work? Who does it make POSIX work for? Who is the ZVFS for?

@fkokosinski
Copy link
Member Author

@de-nordic -

Thanks a lot for taking a look at this PR.

Once again why are we investing into this?

The POSIX subsystem has its users (including us) - so I suppose it's natural that those users will try to contribute patches/fixes they're using downstream that they found useful.

This PR is an attempt at addressing the comments we've received in the previous PR. We'd be happy to address any further technical comments you might have.

I do not see any reason for ZVFS and POSIX to coexist in one system.

As you've noticed in the linked PR, ZVFS claims to be a central library, and "is designed to be used by all Zephyr subsystems that need to work with files."

I'm not sure why the POSIX layer wouldn't fit into that description?

Has anyone noticed that this is basically requiring something like 4-5 stack frames from POSIX to FS to even work? Who does it make POSIX work for?

The POSIX layer is completely optional - it's up to the user whether they want to allocate the device's resources on it or not.

Plus, there are features in Zephyr that are not targeted towards the more resource-constrained devices, such as SMP. Zephyr is very useful and works well on beefy RISC-V or Armv8-A machines. There are also features that straight up wouldn't work on a physical device, like VIRTIO, but are useful nevertheless.

Who is the ZVFS for?

At least according to the documentation, it's meant to be central, so for everyone.

Let me reiterate that we're committed to making these changes of as little impact to the average user as possible, meaning - if there's a change introduced by this PR that can be made optional, we'd be more than happy making it disabled by default.

Comment on lines +127 to +131
/**
* @brief Read from a file.
*
* See IEEE 1003.1
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that ZVFS is already POSIX.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is selectable by ZVFS_DEFAULT_FILE_VMETHODS, which is n-selected by default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, it is already POSIX, does not matter how many Kconfigs are there needed to select this.

@nashif nashif merged commit 3c42773 into zephyrproject-rtos:main Nov 18, 2025
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Base OS Base OS Library (lib/os) area: HTTP HTTP client/server support area: Networking area: POSIX POSIX API Library area: Samples Samples area: Sockets Networking sockets area: Tests Issues related to a particular existing or missing test area: Wi-Fi Wi-Fi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants