xref: /third_party/ltp/include/lapi/fallocate.h (revision f08c3bdf)
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
39static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
40{
41	/* Deal with 32bit ABIs that have 64bit syscalls. */
42# if LTP_USE_64_ABI
43	return tst_syscall(__NR_fallocate, fd, mode, offset, len);
44# else
45	return (long)tst_syscall(__NR_fallocate, fd, mode,
46				 __LONG_LONG_PAIR((off_t) (offset >> 32),
47						  (off_t) offset),
48				 __LONG_LONG_PAIR((off_t) (len >> 32),
49						  (off_t) len));
50# endif
51}
52#endif
53
54#endif /* LAPI_FALLOCATE_H__ */
55