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