Skip to content

[FS] Make fstatfs actually work #23381

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

Merged
merged 4 commits into from
Jan 13, 2025
Merged

Conversation

hoodmane
Copy link
Collaborator

@hoodmane hoodmane commented Jan 13, 2025

Prior to this change, fstatfs calls statfs64 with the char* path pointer argument set to zero. Generally byte zero of the memory seems to be null, so when statfs64 converts this char* to a JS string it gets the empty string. Then it calls FS.statfs with the empty string as an argument. FS.statfs calls lookupPath with an empty string argument which returns a null node, so fstatfs returns the default values for when there is no statfs handler in the files system.

This fixes the problem and adds testing for statfs/fstatfs on nodefs and rawfs. We have to add separate FS.statfsNode and FS.statfsStream handlers because in some cases stream.node is null and in some cases stream.path is useless (like for stdout). Also, in noderawfs we need to give paths for the standard streams because there is unfortunately no fs.fstatfsSync so we can only access information from the host via a path. This means the noderawfs test won't be portable to windows.

Prior to this change, `fstatfs` calls `statfs64` with the `char*` path
pointer argument set to zero. Generally byte zero of the memory seems
to be null, so when `statfs64` converts this `char*` to a JS string it
gets the empty string. Then it calls `FS.statfs` with the empty string
as an argument. `FS.statfs` calls `lookupPath` with an empty string
argument which returns a `null` node, so `fstatfs` returns the default
values for when there is no statfs handler in the files system.

This fixes the problem and adds testing for statfs/fstatfs on nodefs and
rawfs. We have to add separate `FS.statfsNode` and `FS.statfsStream` handlers
because in some cases `stream.node` is null and in some cases `stream.path
is useless (like for stdout). Also, in noderawfs we need to give paths for
the standard streams because there is unfortunately no `fs.fstatfsSync` so
we can only access information from the host via a path. This means the
noderawfs  test won't be portable to windows.
@hoodmane hoodmane merged commit 07e4fb2 into emscripten-core:main Jan 13, 2025
29 checks passed
@hoodmane hoodmane deleted the working-fstatfs branch January 13, 2025 20:21
bgrgicak added a commit to WordPress/wordpress-playground that referenced this pull request May 7, 2025
## Motivation for the change, related issues

[Emscripten merged a fix for
`statfs`](emscripten-core/emscripten#23381) in
`4.0.1`, so this PR updates Emscripten to allow us to run `statfs` in
PHP functions like `disk_total_space`.

## Implementation details

This PR updates the version of Emscripten to `4.0.5`, rebuilds all
PHP-wasm libraries, and recompiles PHP-wasm.

While rebuilding PHP-wasm libraries there was a bug in the `libcurl`
build script because it expected `libopenssl` to be located in
`libopenssl/asyncify/dist`, but in reality `libopenssl` was located in
`libopenssl/asyncify/dist/1.1.0h` (similarly for JSPI).
We have two versions of `libopenssl` because it [was requires for PHP
7.0](#2038).
This PR drops `libopenssl 1.1.0h` support because [Playground doesn't
support PHP 7.0
anymore.](Automattic/wordpress-playground-private#74)

## Testing Instructions (or ideally a Blueprint)

- CI
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.

2 participants