Eric Sandeen wrote:
Now that we have ext4 as the new default filesystem, it'd be nice
if we
can get more applications to take advantage of some of the features.
One big feature that has already been brought up on the list[1] is file
preallocation, which allows an application to pre-allocate blocks it
knows that it will eventually write into, thereby making sure it won't
run out of space, and also generally getting a more efficient/contiguous
file layout.
[snip]
fallocate(2):
long fallocate(int fd, int mode, loff_t offset, loff_t len);
This is directly wired to the syscall, so only succeeds on filesystems
that support it. It also takes a FALLOC_FL_KEEP_SIZE mode argument,
which allows one to allocate blocks without updating the file size if
desired (blocks can then be allocated past EOF). This call is only
wired up in very recent glibc, but it is available in F11.
I tried using fallocate() on glibc-2.9.90-22.
The man-pages are out of date and say the glibc interface is not available,
but from inspecting the headers I came up with the test prog below.
However I get a link error if I uncomment #define _FILE_OFFSET_BITS 64.
What am I missing?
cheers,
Pádraig.
//#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <fcntl.h>
#include <linux/falloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <inttypes.h>
int main (int argc, char** argv)
{
char* endptr;
off_t len = strtoll(argv[1], &endptr, 10);
fprintf(stderr, "setting to %jd\n", (intmax_t)len);
int ret = fallocate(1, 0, 0, len);
fprintf(stderr, "ret=%d (%s)\n", ret, strerror(ret));
}