MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / allocFileSpace

Function allocFileSpace

src/common/isc_sync.cpp:1197–1236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1195}
1196
1197bool 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
1239void SharedMemoryBase::internalUnmap()

Callers 2

isc_sync.cppFile · 0.85
remapFileMethod · 0.85

Calls 3

reportErrorFunction · 0.85
getBufferMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected