• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2007
4  * Copyright (c) 2014 Fujitsu Ltd.
5  */
6 
7 #ifndef LAPI_FALLOCATE_H__
8 #define LAPI_FALLOCATE_H__
9 
10 #include <sys/types.h>
11 #include <endian.h>
12 #include "config.h"
13 #include "lapi/abisize.h"
14 #include "lapi/seek.h"
15 #include "lapi/syscalls.h"
16 
17 #ifndef FALLOC_FL_KEEP_SIZE
18 # define FALLOC_FL_KEEP_SIZE 0x01
19 #endif
20 
21 #ifndef FALLOC_FL_PUNCH_HOLE
22 # define FALLOC_FL_PUNCH_HOLE 0x02
23 #endif
24 
25 #ifndef FALLOC_FL_COLLAPSE_RANGE
26 # define FALLOC_FL_COLLAPSE_RANGE 0x08
27 #endif
28 
29 #ifndef FALLOC_FL_ZERO_RANGE
30 # define FALLOC_FL_ZERO_RANGE 0x10
31 #endif
32 
33 #ifndef FALLOC_FL_INSERT_RANGE
34 # define FALLOC_FL_INSERT_RANGE 0x20
35 #endif
36 
37 #if !defined(HAVE_FALLOCATE)
38 
39 # ifdef __TEST_H__
40 #  define TST_SYSCALL_WRAPPER ltp_syscall
41 # else
42 #  define TST_SYSCALL_WRAPPER tst_syscall
43 # endif /* __TEST_H__ */
44 
fallocate(int fd,int mode,loff_t offset,loff_t len)45 static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
46 {
47 	/* Deal with 32bit ABIs that have 64bit syscalls. */
48 # if LTP_USE_64_ABI
49 	return TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, offset, len);
50 # else
51 	return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode,
52 				 __LONG_LONG_PAIR((off_t) (offset >> 32),
53 						  (off_t) offset),
54 				 __LONG_LONG_PAIR((off_t) (len >> 32),
55 						  (off_t) len));
56 # endif
57 }
58 #endif
59 
60 #endif /* LAPI_FALLOCATE_H__ */
61