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 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20
21 #ifndef FALLOCATE_H
22 #define FALLOCATE_H
23
24 #include <sys/types.h>
25 #include <endian.h>
26 #include "config.h"
27 #include "lapi/abisize.h"
28 #include "linux_syscall_numbers.h"
29
30 #ifndef SEEK_HOLE
31 #define SEEK_HOLE 4
32 #endif
33
34 #ifndef FALLOC_FL_KEEP_SIZE
35 #define FALLOC_FL_KEEP_SIZE 0x01
36 #endif
37
38 #ifndef FALLOC_FL_PUNCH_HOLE
39 #define FALLOC_FL_PUNCH_HOLE 0x02
40 #endif
41
42 #ifndef FALLOC_FL_COLLAPSE_RANGE
43 #define FALLOC_FL_COLLAPSE_RANGE 0x08
44 #endif
45
46 #ifndef FALLOC_FL_ZERO_RANGE
47 #define FALLOC_FL_ZERO_RANGE 0x10
48 #endif
49
50 #if !defined(HAVE_FALLOCATE)
fallocate(int fd,int mode,loff_t offset,loff_t len)51 static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
52 {
53 /* Deal with 32bit ABIs that have 64bit syscalls. */
54 # if LTP_USE_64_ABI
55 return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
56 # else
57 return (long)ltp_syscall(__NR_fallocate, fd, mode,
58 __LONG_LONG_PAIR((off_t) (offset >> 32),
59 (off_t) offset),
60 __LONG_LONG_PAIR((off_t) (len >> 32),
61 (off_t) len));
62 # endif
63 }
64 #endif
65
66 #endif /* FALLOCATE_H */
67