You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Total and free size of filesystem reported in sites doesn't match actual values #341
The total and free size of filesystem reported in sites doesn't match the ones from the machine. This can lead to issues in plugins that rely on these values.
Steps to reproduce
Open the app.
Create/start a site.
Edit the wp-config-php file of the site and add the following code at the bottom:
I explored the Playground code and noticed that the free and total values are fixed values. Let me briefly explain the references I found while debugging this:
The calculation isf_bsize * f_bavail, which values represent Optimal transfer block size and Free blocks available to unprivileged user (documentation).
As you can see, the values are fixed so as outlined in the issue, they don't reflect the actual total and free size of the file system. Here are the results:
Total available size: 4096 * 1^6 = 4.096.000.000 (4GB).
Total free size: 4096 * 5^5 = 2.048.000.000 (2GB).
As a next step, we'd need to explore if this is set by Playground when compiling PHP source. Or if on the other hand, this is set by Emscripten.
UPDATE: As shared in #341 (comment), the values are set by Emscripten here.
With the various types of available VFS's it could be complicated to give a meaningful output of statfs which is probably why they settled on a stub with, as they call it, sane values.
@adamziel Do you have any ideas of how we can proceed with this? I'm happy to have a deeper look but I'm out of my depth here so some pointers would be very welcome :-)
// None of the constants here are true. We're just returning safe and
// sane values.
It sounds like this could be solved with an Emscripten PR that delegates the statfs call to the FS object which in turn delegates it to the underlying FS backend like NODEFS and falls back to the hardcoded constants if that backend doesn't support the statfs call. Opening an Emscripten issue first would be useful to validate the approach with the team.
Reacted by Wojtek Naruniec, Carlos Garcia and Jeroen P
Activity
fluiddot commentedon Jul 4, 2024
I explored the Playground code and noticed that the free and total values are fixed values. Let me briefly explain the references I found while debugging this:
Free space
disk_free_spacecalculates the value using the filesystem functionstatfs:f_bsize * f_bavail, which values representOptimal transfer block sizeandFree blocks available to unprivileged user(documentation).Total space
disk_total_spacecalculates the value using the filesystem functionstatfs:f_bsize * f_blocks, which values representOptimal transfer block sizeandTotal data blocks in filesystem(documentation).Filesystem values
NODEFS.statfsfunction which returns value is represented with the classstatfs.4096 * 1^6 = 4.096.000.000(4GB).4096 * 5^5 = 2.048.000.000(2GB).As a next step, we'd need to explore if this is set by Playground when compiling PHP source. Or if on the other hand, this is set by Emscripten.UPDATE: As shared in #341 (comment), the values are set by Emscripten here.
wojtekn commentedon Jul 8, 2024
CC @adamziel
jeroenpf commentedon Aug 22, 2024
@fluiddot I went a bit deeper and it looks like these values are set in emscripten:
https://github.com/emscripten-core/emscripten/blob/7f8a05dd4e37cbd7ffde6d624f91fd545f7b52e3/src/library_syscall.js#L804
https://github.com/emscripten-core/emscripten/blob/7f8a05dd4e37cbd7ffde6d624f91fd545f7b52e3/system/lib/wasmfs/syscalls.cpp#L1530
With the various types of available VFS's it could be complicated to give a meaningful output of statfs which is probably why they settled on a stub with, as they call it, sane values.
@adamziel Do you have any ideas of how we can proceed with this? I'm happy to have a deeper look but I'm out of my depth here so some pointers would be very welcome :-)
adamziel commentedon Sep 11, 2024
It seems like it's reporting the heap size, not the disk size. The 2GB comes up on this Emscripten doc page but not directly tied with this problem.
The original commit introducing these constants in Emscripten says:
It sounds like this could be solved with an Emscripten PR that delegates the
statfscall to the FS object which in turn delegates it to the underlying FS backend likeNODEFSand falls back to the hardcoded constants if that backend doesn't support thestatfscall. Opening an Emscripten issue first would be useful to validate the approach with the team.13 remaining items
bgrgicak commentedon Feb 17, 2025
We update Emscripten in Playground.
To resolve this issue, Studio will need to update Playground from our self-hosted packages.
Also, the Playground still doesn't support browser cookies, so if Studio want's to update Playground, it will need to apply the cookie patch.
bgrgicak commentedon Mar 3, 2025
The Emscripten update didn't fix this issue. Related thread #959 (comment)
bgrgicak commentedon Mar 25, 2025
@wojtekn is there a specific example that we could use to test our fix?
wojtekn commentedon Mar 25, 2025
@bgrgicak I don't know any specific example other than steps shown in the issue description.