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 <dpiliaiev@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36821>
This commit is contained in:
committed by
Marge Bot
parent
d93813c7a0
commit
ff9ba2cef0
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user