| 301 | } |
| 302 | |
| 303 | __wasi_errno_t __wasi_fd_sync(__wasi_fd_t fd) { |
| 304 | auto openFile = wasmFS.getFileTable().locked().getEntry(fd); |
| 305 | if (!openFile) { |
| 306 | return __WASI_ERRNO_BADF; |
| 307 | } |
| 308 | |
| 309 | // Nothing to flush for anything but a data file, but also not an error either |
| 310 | // way. TODO: in the future we may want syncing of directories. |
| 311 | auto dataFile = openFile->locked().getFile()->dynCast<DataFile>(); |
| 312 | if (dataFile) { |
| 313 | auto ret = dataFile->locked().flush(); |
| 314 | assert(ret <= 0); |
| 315 | // Translate to WASI standard of positive return codes. |
| 316 | return -ret; |
| 317 | } |
| 318 | |
| 319 | return __WASI_ERRNO_SUCCESS; |
| 320 | } |
| 321 | |
| 322 | int __syscall_fdatasync(int fd) { |
| 323 | // TODO: Optimize this to avoid unnecessarily flushing unnecessary metadata. |