MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / __syscall_fallocate

Function __syscall_fallocate

system/lib/wasmfs/syscalls.cpp:1447–1487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1445}
1446
1447int __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
1489int __syscall_fcntl64(int fd, int cmd, ...) {
1490 auto fileTable = wasmFS.getFileTable().locked();

Callers

nothing calls this directly

Calls 7

getEntryMethod · 0.80
getModeMethod · 0.80
assertFunction · 0.50
lockedMethod · 0.45
getFileMethod · 0.45
getSizeMethod · 0.45
setSizeMethod · 0.45

Tested by

no test coverage detected