Create fallocate.h to encapsulate fallocate(2)
Signed-off-by: Zeng Linggang <[email protected]>
---
testcases/kernel/syscalls/fallocate/fallocate.h | 44 +++++++++++++++++++++++
testcases/kernel/syscalls/fallocate/fallocate01.c | 23 +-----------
testcases/kernel/syscalls/fallocate/fallocate02.c | 19 +---------
testcases/kernel/syscalls/fallocate/fallocate03.c | 19 +---------
4 files changed, 47 insertions(+), 58 deletions(-)
create mode 100644 testcases/kernel/syscalls/fallocate/fallocate.h
diff --git a/testcases/kernel/syscalls/fallocate/fallocate.h
b/testcases/kernel/syscalls/fallocate/fallocate.h
new file mode 100644
index 0000000..69b4fda
--- /dev/null
+++ b/testcases/kernel/syscalls/fallocate/fallocate.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef FALLOCATE_H
+#define FALLOCATE_H
+
+#include <sys/types.h>
+#include <endian.h>
+#include "linux_syscall_numbers.h"
+
+static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+ /* Deal with 32bit ABIs that have 64bit syscalls. */
+#if (defined(__mips__) && _MIPS_SIM == _ABIN32) || \
+ (defined(__x86_64__) && defined(__ILP32__)) || \
+ __WORDSIZE == 64
+ return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
+#else
+ return (long)ltp_syscall(__NR_fallocate, fd, mode,
+ __LONG_LONG_PAIR((off_t) (offset >> 32),
+ (off_t) offset),
+ __LONG_LONG_PAIR((off_t) (len >> 32),
+ (off_t) len));
+#endif
+}
+
+#endif /* FALLOCATE_H */
diff --git a/testcases/kernel/syscalls/fallocate/fallocate01.c
b/testcases/kernel/syscalls/fallocate/fallocate01.c
index 0240687..eec39fa 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate01.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate01.c
@@ -100,12 +100,10 @@
#include "test.h"
#include "usctest.h"
-#include "linux_syscall_numbers.h"
+#include "fallocate.h"
#define BLOCKS_WRITTEN 12
-/* Local Function */
-static inline long fallocate();
void get_blocksize(int);
void populate_files(int fd);
void runtest(int, int, loff_t);
@@ -183,16 +181,10 @@ void get_blocksize(int fd)
void populate_files(int fd)
{
char buf[buf_size + 1];
- char *fname;
int index;
int blocks;
int data;
- if (fd == fd_mode1)
- fname = fname_mode1;
- else
- fname = fname_mode2;
-
for (blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) {
for (index = 0; index < buf_size; index++)
buf[index] = 'A' + (index % 26);
@@ -239,19 +231,6 @@ int main(int ac, char **av)
tst_exit();
}
-static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
-{
-#if __WORDSIZE == 32
- return (long)ltp_syscall(__NR_fallocate, fd, mode,
- __LONG_LONG_PAIR((off_t) (offset >> 32),
- (off_t) offset),
- __LONG_LONG_PAIR((off_t) (len >> 32),
- (off_t) len));
-#else
- return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
-#endif
-}
-
/*****************************************************************************
* Calls the system call, with appropriate parameters and writes data
******************************************************************************/
diff --git a/testcases/kernel/syscalls/fallocate/fallocate02.c
b/testcases/kernel/syscalls/fallocate/fallocate02.c
index 37f0635..e5e482c 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate02.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate02.c
@@ -96,7 +96,7 @@
#include "test.h"
#include "usctest.h"
-#include "linux_syscall_numbers.h"
+#include "fallocate.h"
#define BLOCKS_WRITTEN 12
@@ -108,7 +108,6 @@
#define OFFSET 12
-static inline long fallocate();
void populate_file();
void create_fifo();
void create_pipe();
@@ -225,22 +224,6 @@ void populate_file()
}
/*****************************************************************************
- * Wraper function to call fallocate system call
-
******************************************************************************/
-static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
-{
-#if __WORDSIZE == 32
- return (long)ltp_syscall(__NR_fallocate, fd, mode,
- __LONG_LONG_PAIR((off_t) (offset >> 32),
- (off_t) offset),
- __LONG_LONG_PAIR((off_t) (len >> 32),
- (off_t) len));
-#else
- return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
-#endif
-}
-
-/*****************************************************************************
* Main function that calls the system call with the appropriate parameters
******************************************************************************/
/* ac: number of command line parameters */
diff --git a/testcases/kernel/syscalls/fallocate/fallocate03.c
b/testcases/kernel/syscalls/fallocate/fallocate03.c
index 973b2d7..a42dcad 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate03.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate03.c
@@ -95,7 +95,7 @@
#include "test.h"
#include "usctest.h"
-#include "linux_syscall_numbers.h"
+#include "fallocate.h"
#define BLOCKS_WRITTEN 12
#define HOLE_SIZE_IN_BLOCKS 12
@@ -103,7 +103,6 @@
#define FALLOC_FL_KEEP_SIZE 1 //Need to be removed once the glibce support is
provided
#define TRUE 0
-static inline long fallocate();
void get_blocksize(int);
void populate_file();
void file_seek(off_t);
@@ -219,22 +218,6 @@ void populate_file()
}
/*****************************************************************************
- * Wraper function to call fallocate system call
-
******************************************************************************/
-static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
-{
-#if __WORDSIZE == 32
- return (long)ltp_syscall(__NR_fallocate, fd, mode,
- __LONG_LONG_PAIR((off_t) (offset >> 32),
- (off_t) offset),
- __LONG_LONG_PAIR((off_t) (len >> 32),
- (off_t) len));
-#else
- return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
-#endif
-}
-
-/*****************************************************************************
* Main function that calls the system call with the appropriate parameters
******************************************************************************/
/* ac: number of command line parameters */
--
1.8.2.1
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list