13 if (!tryAcquireFilesystemOperation(operation)) {
17 syscallError(
isDirectory() ? Error::IsADirectory : Error::OperationNotSupported);
21 SYSCALL_ERROR(InvalidArgument);
25 if (offset > maximum || length > maximum - offset || length > ~
size_t(0) - offset) {
26 SYSCALL_ERROR(FileTooLarge);
31 if (m_pFilesystem && m_pFilesystem->
isReadOnly()) {
32 SYSCALL_ERROR(ReadOnlyFilesystem);
35 if (cacheState().executableMappings) {
36 SYSCALL_ERROR(TextFileBusy);
39 const size_t oldSize = getSize();
40 const size_t end = offset + length;
41 const size_t newSize = keepSize || end < oldSize ? oldSize : end;
46 if (newSize > oldSize) {
47 if (!resizeFile(newSize))
51 const size_t within = oldSize % pageSize;
53 const size_t pageOffset = oldSize - within;
54 const uintptr_t page = cacheState().fill.
lookup(pageOffset);
57 newSize - oldSize < pageSize - within ? newSize - oldSize : pageSize - within;
58 ByteSet(
reinterpret_cast<void*
>(page + within), 0, amount);
60 cacheState().fill.
release(pageOffset);
66 attributes.modified = attributes.changed = Time::getTime();
67 updateAttributes(attributes, ModifyTime | ChangeTime);