From ee70efcd097330109b7406c3f2a312544bf260c9 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sun, 11 Dec 2022 12:43:24 +0800 Subject: [PATCH] fc_fallocate fail back to ftruncate under Linux --- src/common_define.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/common_define.h b/src/common_define.h index 81892db..5e92ed0 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -485,7 +485,18 @@ static inline int fc_compare_int64(const int64_t n1, const int64_t n2) } #ifdef OS_LINUX -#define fc_fallocate(fd, size) fallocate(fd, 0, 0, size) +static inline int fc_fallocate(int fd, const int64_t size) +{ + if (fallocate(fd, 0, 0, size) < 0) { + if (errno == EOPNOTSUPP) { + return ftruncate(fd, size); + } + return -1; + } + + return 0; +} + #else #define fc_fallocate(fd, size) ftruncate(fd, size) #define posix_fadvise(fd, offset, len, advice) 0