| 1195 | } |
| 1196 | |
| 1197 | bool allocFileSpace(int fd, off_t offset, FB_SIZE_T length, CheckStatusWrapper* statusVector) |
| 1198 | { |
| 1199 | #if defined(HAVE_LINUX_FALLOC_H) && defined(HAVE_FALLOCATE) |
| 1200 | if (fallocate(fd, 0, offset, length) == 0) |
| 1201 | return true; |
| 1202 | |
| 1203 | if (errno != EOPNOTSUPP && errno != ENOSYS) |
| 1204 | { |
| 1205 | reportError("fallocate", statusVector); |
| 1206 | return false; |
| 1207 | } |
| 1208 | // fallocate is not supported by this kernel or file system |
| 1209 | // take the long way around |
| 1210 | #endif |
| 1211 | static const FB_SIZE_T buf128KSize = 131072; |
| 1212 | HalfStaticArray<UCHAR, BUFFER_LARGE> buf; |
| 1213 | const FB_SIZE_T bufSize = length < buf128KSize ? length : buf128KSize; |
| 1214 | |
| 1215 | memset(buf.getBuffer(bufSize), 0, bufSize); |
| 1216 | os_utils::lseek(fd, LSEEK_OFFSET_CAST offset, SEEK_SET); |
| 1217 | |
| 1218 | while (length) |
| 1219 | { |
| 1220 | const FB_SIZE_T cnt = length < bufSize ? length : bufSize; |
| 1221 | if (write(fd, buf.begin(), cnt) != (ssize_t) cnt) |
| 1222 | { |
| 1223 | reportError("write", statusVector); |
| 1224 | return false; |
| 1225 | } |
| 1226 | length -= cnt; |
| 1227 | } |
| 1228 | |
| 1229 | if (fsync(fd)) |
| 1230 | { |
| 1231 | reportError("fsync", statusVector); |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | return true; |
| 1236 | } |
| 1237 | |
| 1238 | |
| 1239 | void SharedMemoryBase::internalUnmap() |
no test coverage detected