1 /* 2 * Copyright (c) International Business Machines Corp., 2007 3 * Copyright (c) 2014 Fujitsu Ltd. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Library General Public License for more details. 14 * 15 */ 16 17 #ifndef FALLOCATE_H 18 #define FALLOCATE_H 19 20 #include <sys/types.h> 21 #include <endian.h> 22 #include "config.h" 23 #include "lapi/abisize.h" 24 #include "lapi/seek.h" 25 #include "lapi/syscalls.h" 26 27 #ifndef FALLOC_FL_KEEP_SIZE 28 # define FALLOC_FL_KEEP_SIZE 0x01 29 #endif 30 31 #ifndef FALLOC_FL_PUNCH_HOLE 32 # define FALLOC_FL_PUNCH_HOLE 0x02 33 #endif 34 35 #ifndef FALLOC_FL_COLLAPSE_RANGE 36 # define FALLOC_FL_COLLAPSE_RANGE 0x08 37 #endif 38 39 #ifndef FALLOC_FL_ZERO_RANGE 40 # define FALLOC_FL_ZERO_RANGE 0x10 41 #endif 42 43 #ifndef FALLOC_FL_INSERT_RANGE 44 # define FALLOC_FL_INSERT_RANGE 0x20 45 #endif 46 47 #if !defined(HAVE_FALLOCATE) 48 49 # ifdef __TEST_H__ 50 # define TST_SYSCALL_WRAPPER ltp_syscall 51 # else 52 # define TST_SYSCALL_WRAPPER tst_syscall 53 # endif /* __TEST_H__ */ 54 55 static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) 56 { 57 /* Deal with 32bit ABIs that have 64bit syscalls. */ 58 # if LTP_USE_64_ABI 59 return TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, offset, len); 60 # else 61 return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, 62 __LONG_LONG_PAIR((off_t) (offset >> 32), 63 (off_t) offset), 64 __LONG_LONG_PAIR((off_t) (len >> 32), 65 (off_t) len)); 66 # endif 67 } 68 #endif 69 70 #endif /* FALLOCATE_H */ 71