On Sun, 2007-11-18 at 18:10 -0700, Rob Bosch wrote:
> Matt, I have absolutely no programming skills for developing my own
> program! I'd be happy to compile and test a program however.
Attached is the C++ source for a simple program "allocate" to allocate a
file. Call the program like "./allocate thefile 77000000000".
> Are you going to put the fix for the preallocate patch in the 3.0 next
> pre-release or release?
That's Wayne's job.
I notice that the Linux kernel 2.6.23 has gained a system call
"fallocate" that preallocates at the filesystem level like Cygwin's
implementation of posix_fallocate; thus, preallocation may become (at
least slightly) helpful on Linux. Unfortunately, neither ext2 nor
reiserfs supports this call yet, at least in the kernel on my computer;
I hope support will be added soon.
My computer's glibc seems to implement posix_fallocate to first attempt
fallocate and force allocation the slow/dumb way if that fails.
However, rsync probably wants to allocate if it can be done the fast way
and otherwise not bother. To achieve this, rsync should call fallocate
if available, otherwise posix_fallocate if on Cygwin, otherwise nothing
at all; or if Cygwin adds fallocate as a synonym for its (good)
posix_fallocate, rsync can just call fallocate if available.
Matt
#define _FILE_OFFSET_BITS 64
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <iostream>
using namespace std;
int main(int argc, const char *const *const argv) {
const char *progName = (argc == 0) ? "allocate" : argv[0];
if (argc != 3) {
cout << progName << ": Usage: `" << progName << " <file> <new size>'" << endl;
return 4;
}
const char *path = argv[1];
const char *lengthStr = argv[2];
const char *endPtr = lengthStr; // in case
errno = 0;
long long llength = strtoll(lengthStr, (char **)(&endPtr), 0);
off_t length = off_t(llength);
if (!(errno == 0 && *endPtr == '\0' && llength == (long long)(length))) {
cout << progName << ": There was a problem converting `" << lengthStr << "' to a file size." << endl;
return 3;
}
int fd = open(path, O_WRONLY | O_CREAT, 0666);
if (fd == -1) {
perror(progName);
return 1;
}
int retCode = posix_fallocate(fd, 0, length);
close(fd);
if (retCode == -1) {
perror(progName);
return 1;
}
return 0;
}
--
To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html