| 1445 | } |
| 1446 | |
| 1447 | int __syscall_fallocate(int fd, int mode, off_t offset, off_t len) { |
| 1448 | assert(mode == 0); // TODO, but other modes were never supported in the old FS |
| 1449 | |
| 1450 | auto fileTable = wasmFS.getFileTable().locked(); |
| 1451 | auto openFile = fileTable.getEntry(fd); |
| 1452 | if (!openFile) { |
| 1453 | return -EBADF; |
| 1454 | } |
| 1455 | |
| 1456 | auto dataFile = openFile->locked().getFile()->dynCast<DataFile>(); |
| 1457 | // TODO: support for symlinks. |
| 1458 | if (!dataFile) { |
| 1459 | return -ENODEV; |
| 1460 | } |
| 1461 | |
| 1462 | auto locked = dataFile->locked(); |
| 1463 | if (!(locked.getMode() & WASMFS_PERM_WRITE)) { |
| 1464 | return -EBADF; |
| 1465 | } |
| 1466 | |
| 1467 | if (offset < 0 || len <= 0) { |
| 1468 | return -EINVAL; |
| 1469 | } |
| 1470 | |
| 1471 | // TODO: We could only fill zeros for regions that were completely unused |
| 1472 | // before, which for a backend with sparse data storage could make a |
| 1473 | // difference. For that we'd need a new backend API. |
| 1474 | auto newNeededSize = offset + len; |
| 1475 | off_t size = locked.getSize(); |
| 1476 | if (size < 0) { |
| 1477 | return size; |
| 1478 | } |
| 1479 | if (newNeededSize > size) { |
| 1480 | if (auto err = locked.setSize(newNeededSize)) { |
| 1481 | assert(err < 0); |
| 1482 | return err; |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | int __syscall_fcntl64(int fd, int cmd, ...) { |
| 1490 | auto fileTable = wasmFS.getFileTable().locked(); |