-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[nodefs] Return real values for statvfs via __syscall_statfs64 #22631
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
Changes from 9 commits
0896af7
5770db8
a18edbe
c3c0c5f
d2e8f4c
5adafc1
d96e461
e7569a8
46de52e
d96eb8a
a9d68cd
df511ea
7601bd8
3a5a167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -672,6 +672,31 @@ FS.staticInit(); | |
| } | ||
| return parent.node_ops.mknod(parent, name, mode, dev); | ||
| }, | ||
| statfs(path) { | ||
|
|
||
| // NOTE: None of the defaults here are true. We're just returning safe and | ||
| // sane values. | ||
| var ffree = FS.nextInode - 1; // Free inodes can not be larger than total inodes | ||
| var defaults = { | ||
| bsize: 4096, | ||
| frsize: 4096, | ||
| blocks: 1e6, | ||
| bfree: 5e5, | ||
| bavail: 5e5, | ||
| files: FS.nextInode, | ||
| ffree, | ||
| fsid: 42, | ||
| flags: 2, | ||
| namelen: 255, | ||
| }; | ||
|
|
||
| var parent = FS.lookupPath(path, {follow: true}).node; | ||
| if (typeof parent.node_ops?.statfs !== 'function') { | ||
| return defaults; | ||
| } | ||
|
|
||
| return { ...defaults, ...parent.node_ops.statfs(parent.mount.opts.root) }; | ||
|
||
| }, | ||
| // helpers to create specific types of nodes | ||
| create(path, mode) { | ||
| mode = mode !== undefined ? mode : 438 /* 0666 */; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include <assert.h> | ||
| #include <stdio.h> | ||
| #include <sys/statvfs.h> | ||
| #include <emscripten.h> | ||
|
|
||
| void test_statfs(const char *path) { | ||
| printf("Testing statfs for path: %s\n", path); | ||
| struct statvfs st; | ||
| int result = statvfs(path, &st); | ||
|
|
||
| assert(result == 0 && "statvfs should succeed"); | ||
|
|
||
|
|
||
|
|
||
jeroenpf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Basic sanity checks | ||
| assert(st.f_bsize > 0 && "Block size should be positive"); | ||
| assert(st.f_blocks > 0 && "Total blocks should be positive"); | ||
| assert(st.f_bfree <= st.f_blocks && "Free blocks should not exceed total blocks"); | ||
| assert(st.f_bavail <= st.f_bfree && "Available blocks should not exceed free blocks"); | ||
| assert(st.f_files > 0 && "Total inodes should be positive"); | ||
| assert(st.f_ffree <= st.f_files && "Free inodes should not exceed total inodes"); | ||
| } | ||
|
|
||
| int main() { | ||
| // Test the root filesystem (which should be MEMFS by default) | ||
| test_statfs("/"); | ||
jeroenpf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Mount NODEFS and test it | ||
| EM_ASM( | ||
| FS.mkdir('/working'); | ||
| FS.mount(NODEFS, { root: '.' }, '/working'); | ||
| ); | ||
jeroenpf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| test_statfs("/working"); | ||
|
|
||
| puts("success"); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.