1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) International Business Machines  Corp., 2008
4 */
5
6#ifndef LAPI_SYNC_FILE_RANGE_H__
7#define LAPI_SYNC_FILE_RANGE_H__
8
9#include <sys/types.h>
10#include "config.h"
11#include "lapi/syscalls.h"
12#include "lapi/abisize.h"
13
14#if !defined(HAVE_SYNC_FILE_RANGE)
15
16/*****************************************************************************
17 * Wraper function to call sync_file_range system call
18 ******************************************************************************/
19static inline long sync_file_range(int fd, off64_t offset, off64_t nbytes,
20				   unsigned int flags)
21{
22#if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__))
23# ifdef TST_ABI32
24#  if __BYTE_ORDER == __BIG_ENDIAN
25	return tst_syscall(__NR_sync_file_range2, fd, flags,
26		(int)(offset >> 32), (int)offset, (int)(nbytes >> 32),
27		(int)nbytes);
28#  elif __BYTE_ORDER == __LITTLE_ENDIAN
29	return tst_syscall(__NR_sync_file_range2, fd, flags, (int)offset,
30		       (int)(offset >> 32), nbytes, (int)(nbytes >> 32));
31#  endif
32# else
33	return tst_syscall(__NR_sync_file_range2, fd, flags, offset, nbytes);
34# endif
35#elif (defined(__s390__) || defined(__s390x__)) && defined(TST_ABI32)
36	return tst_syscall(__NR_sync_file_range, fd, (int)(offset >> 32),
37		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
38#elif defined(__mips__) && defined(TST_ABI32)
39# if __BYTE_ORDER == __BIG_ENDIAN
40	return tst_syscall(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
41		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
42# elif __BYTE_ORDER == __LITTLE_ENDIAN
43	return tst_syscall(__NR_sync_file_range, fd, 0, (int)offset,
44		(int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags);
45# endif
46#else
47	return tst_syscall(__NR_sync_file_range, fd, offset, nbytes, flags);
48#endif
49}
50#endif
51
52#endif /* LAPI_SYNC_FILE_RANGE_H__ */
53