13 syscallError(
isDirectory() ? Error::IsADirectory : Error::OperationNotSupported);
17 SYSCALL_ERROR(InvalidArgument);
21 if (offset > maximum || length > maximum - offset || length > ~
size_t(0) - offset) {
22 SYSCALL_ERROR(FileTooLarge);
27 if (m_pFilesystem && m_pFilesystem->
isReadOnly()) {
28 SYSCALL_ERROR(ReadOnlyFilesystem);
31 if (cacheState().executableMappings) {
32 SYSCALL_ERROR(TextFileBusy);
35 const size_t oldSize = getSize();
36 const size_t end = offset + length;
37 const size_t newSize = keepSize || end < oldSize ? oldSize : end;
42 if (newSize > oldSize) {
43 if (!resizeFile(newSize))
47 const size_t within = oldSize % pageSize;
49 const size_t pageOffset = oldSize - within;
50 const uintptr_t page = cacheState().fill.
lookup(pageOffset);
53 newSize - oldSize < pageSize - within ? newSize - oldSize : pageSize - within;
54 ByteSet(
reinterpret_cast<void*
>(page + within), 0, amount);
56 cacheState().fill.
release(pageOffset);
62 attributes.modified = attributes.changed = Time::getTime();
63 updateAttributes(attributes, ModifyTime | ChangeTime);