From ff9ba2cef0d97fdf5aa44680c874924b3bd663e4 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Mon, 17 Feb 2025 17:26:40 +0100 Subject: [PATCH] util/disk_cache: Fallback to ftruncate if posix_fallocate not supported The posix_fallocate itself may be present and callable but filesystem may not support it. Happens at least on Android. Signed-off-by: Danylo Piliaiev Part-of: --- src/util/disk_cache_os.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index 6d2b43f1db9..c2a90bd9fcc 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -1126,8 +1126,15 @@ disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache) /* posix_fallocate() ensures disk space is allocated otherwise it * fails if there is not enough space on the disk. */ - if (posix_fallocate(fd, 0, size) != 0) - goto path_fail; + int ret = posix_fallocate(fd, 0, size); + if (ret != 0) { + if (ret == EOPNOTSUPP) { + if (ftruncate(fd, size) == -1) + goto path_fail; + } else { + goto path_fail; + } + } #else /* ftruncate() allocates disk space lazily. If the disk is full * and it is unable to allocate disk space when accessed via