I want to preallocate storage with the system call fcntl. Here is my code to do so:
fstore_t store = {F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, length, 0};
int ret = fcntl(fd, F_PREALLOCATE, &store);
if (ret == -1) {
store.fst_flags = F_ALLOCATEALL;
ret = fcntl(fd, F_PREALLOCATE, &store);
}
The variable ret is not -1 after executing that code. When I get the file size by calling fstat on the same file handle, I get stat.st_size = 0. But the value store.fst_bytesalloc equals the value of length.
What do I have to do? When I call
ftruncate(fd, length);
do I get a file with a hole or is it a 'real' file without holes? The second one is my goal.