Commit 9ffa3822 authored by Timo Teräs's avatar Timo Teräs

io: use posix_fallocate to allocate disk space

ftruncate does not allocate it, and subsequent access to mmaped
file will result in SIGBUS. this fixes to properly report disk
full errors.
parent 0e87d08d
......@@ -144,9 +144,14 @@ size_t apk_istream_splice(void *stream, int fd, size_t size,
bufsz = size;
if (size > 128 * 1024) {
if (size != APK_SPLICE_ALL && ftruncate(fd, size) == 0)
mmapbase = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (size != APK_SPLICE_ALL) {
r = posix_fallocate(fd, 0, size);
if (r == 0)
mmapbase = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
else if (r != ENOSYS)
return -r;
}
if (bufsz > 2*1024*1024)
bufsz = 2*1024*1024;
buf = mmapbase;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment