Commit 16fa2c6
authored
[NODEFS] hardlinks, utimensat nofollow, and fadvise/fallocate seek errors (emscripten-core#27305)
Adds a handful of filesystem fixes to the legacy (non-WASMFS) JS
filesystem, mostly around the NODEFS/NODERAWFS host backends where these
operations previously either errored unconditionally or asserted.
* `linkat(2)`: the weak stub always returned `EMLINK`, so hardlinks were
impossible even on host-backed filesystems. A new `FS.link` core op
looks up the target and delegates to a backend `link` node op when one
exists, still returning `EMLINK` for backends without one. Only
NODERAWFS provides it (via `fs.linkSync`). NODEFS deliberately does
**not**: unlike NODERAWFS it confines the guest to a mount root, and a
real host hardlink can't be guaranteed to stay within that root (host
symlinks in intermediate path components are resolved by the OS and
would escape it, with no portable atomic way to check), so NODEFS
reports `EMLINK` like MEMFS. `AT_SYMLINK_FOLLOW` is honored.
* `utimensat(2)`: previously asserted `!flags`, so `AT_SYMLINK_NOFOLLOW`
aborted under assertions. `FS.utime` gains a `dontFollow` argument
threaded through `doSetAttr`. Both NODERAWFS and NODEFS use
`fs.lutimesSync` for the nofollow case so a symlink's *own* timestamps
are set without the host resolving the link — which also avoids escaping
the NODEFS mount root that `fs.utimesSync` (follows symlinks) would
allow.
* `posix_fadvise`/`posix_fallocate`: return `ESPIPE` on a non-seekable
fd (pipe/socket) to match Linux, rather than silently succeeding or
truncating. `__syscall_fadvise64` moves from a weak C stub into the JS
syscall layer so it can inspect the stream.
* NODERAWFS `fstat`: virtual streams (pipes, sockets) have no backing
host fd, so defer to their own `getattr` instead of calling
`fs.fstatSync` on an undefined nfd.
Tests in `test/fs` cover these across MEMFS/NODEFS/NODERAWFS
(`test_fs_link`, `test_fs_utimensat_nofollow`,
`test_fs_fadvise_fallocate`). Codesize expectations are updated for the
new `FS.link`/`FS_link` symbol.
_Made with AI assistance under my review_1 parent 93ff3a9 commit 16fa2c6
17 files changed
Lines changed: 294 additions & 50 deletions
File tree
- src/lib
- system/lib
- libc
- wasmfs
- test
- codesize
- fs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
858 | 877 | | |
859 | 878 | | |
860 | 879 | | |
| |||
1119 | 1138 | | |
1120 | 1139 | | |
1121 | 1140 | | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1127 | 1144 | | |
1128 | | - | |
| 1145 | + | |
| 1146 | + | |
1129 | 1147 | | |
1130 | 1148 | | |
1131 | 1149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
| |||
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
102 | 116 | | |
103 | 117 | | |
104 | 118 | | |
| |||
152 | 166 | | |
153 | 167 | | |
154 | 168 | | |
155 | | - | |
| 169 | + | |
156 | 170 | | |
157 | 171 | | |
158 | 172 | | |
159 | 173 | | |
160 | | - | |
| 174 | + | |
161 | 175 | | |
162 | 176 | | |
163 | 177 | | |
164 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
165 | 183 | | |
166 | 184 | | |
167 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| |||
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
| 262 | + | |
261 | 263 | | |
262 | 264 | | |
263 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
961 | 961 | | |
962 | 962 | | |
963 | 963 | | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
964 | 972 | | |
965 | 973 | | |
966 | 974 | | |
| |||
1009 | 1017 | | |
1010 | 1018 | | |
1011 | 1019 | | |
| 1020 | + | |
1012 | 1021 | | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | 1022 | | |
1017 | 1023 | | |
1018 | 1024 | | |
| |||
1042 | 1048 | | |
1043 | 1049 | | |
1044 | 1050 | | |
1045 | | - | |
| 1051 | + | |
1046 | 1052 | | |
1047 | 1053 | | |
1048 | 1054 | | |
| |||
1055 | 1061 | | |
1056 | 1062 | | |
1057 | 1063 | | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1058 | 1069 | | |
1059 | 1070 | | |
1060 | 1071 | | |
| |||
1064 | 1075 | | |
1065 | 1076 | | |
1066 | 1077 | | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
1067 | 1087 | | |
1068 | 1088 | | |
1069 | 1089 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 99 | | |
104 | 100 | | |
105 | 101 | | |
| |||
170 | 166 | | |
171 | 167 | | |
172 | 168 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 169 | | |
179 | 170 | | |
180 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1855 | 1855 | | |
1856 | 1856 | | |
1857 | 1857 | | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
1858 | 1867 | | |
1859 | 1868 | | |
1860 | 1869 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2053 | 2053 | | |
2054 | 2054 | | |
2055 | 2055 | | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
2056 | 2077 | | |
2057 | 2078 | | |
2058 | 2079 | | |
| |||
2310 | 2331 | | |
2311 | 2332 | | |
2312 | 2333 | | |
2313 | | - | |
| 2334 | + | |
2314 | 2335 | | |
2315 | | - | |
| 2336 | + | |
2316 | 2337 | | |
2317 | | - | |
2318 | | - | |
2319 | | - | |
| 2338 | + | |
2320 | 2339 | | |
2321 | | - | |
| 2340 | + | |
| 2341 | + | |
2322 | 2342 | | |
2323 | 2343 | | |
2324 | 2344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| 229 | + | |
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
| |||
243 | 244 | | |
244 | 245 | | |
245 | 246 | | |
| 247 | + | |
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
| |||
1751 | 1753 | | |
1752 | 1754 | | |
1753 | 1755 | | |
| 1756 | + | |
1754 | 1757 | | |
1755 | 1758 | | |
1756 | 1759 | | |
| |||
1768 | 1771 | | |
1769 | 1772 | | |
1770 | 1773 | | |
| 1774 | + | |
1771 | 1775 | | |
1772 | 1776 | | |
1773 | 1777 | | |
| |||
2205 | 2209 | | |
2206 | 2210 | | |
2207 | 2211 | | |
2208 | | - | |
2209 | 2212 | | |
2210 | 2213 | | |
2211 | 2214 | | |
| |||
2219 | 2222 | | |
2220 | 2223 | | |
2221 | 2224 | | |
2222 | | - | |
2223 | 2225 | | |
2224 | 2226 | | |
2225 | 2227 | | |
| |||
4090 | 4092 | | |
4091 | 4093 | | |
4092 | 4094 | | |
4093 | | - | |
4094 | 4095 | | |
4095 | 4096 | | |
4096 | 4097 | | |
4097 | 4098 | | |
4098 | 4099 | | |
4099 | 4100 | | |
4100 | | - | |
4101 | 4101 | | |
4102 | 4102 | | |
4103 | 4103 | | |
| |||
4926 | 4926 | | |
4927 | 4927 | | |
4928 | 4928 | | |
| 4929 | + | |
4929 | 4930 | | |
4930 | 4931 | | |
4931 | 4932 | | |
| |||
0 commit comments