fallocate02.c revision fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716
16a360ef49a83c623784ce97e32f7c07b170ef364David Gross/******************************************************************************
26a360ef49a83c623784ce97e32f7c07b170ef364David Gross *			 fallocate02.c
36a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	Mon Dec 24 2007
46a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	Copyright (c) International Business Machines  Corp., 2007
56a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	Emali : sharyathi@in.ibm.com
66a360ef49a83c623784ce97e32f7c07b170ef364David Gross ******************************************************************************/
76a360ef49a83c623784ce97e32f7c07b170ef364David Gross
86a360ef49a83c623784ce97e32f7c07b170ef364David Gross/***************************************************************************
96a360ef49a83c623784ce97e32f7c07b170ef364David Gross * This program is free software;  you can redistribute it and/or modify
106a360ef49a83c623784ce97e32f7c07b170ef364David Gross * it under the terms of the GNU General Public License as published by
116a360ef49a83c623784ce97e32f7c07b170ef364David Gross * the Free Software Foundation; either version 2 of the License, or
126a360ef49a83c623784ce97e32f7c07b170ef364David Gross * (at your option) any later version.
136a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
146a360ef49a83c623784ce97e32f7c07b170ef364David Gross * This program is distributed in the hope that it will be useful,
156a360ef49a83c623784ce97e32f7c07b170ef364David Gross * but WITHOUT ANY WARRANTY; without even the implied warranty of
166a360ef49a83c623784ce97e32f7c07b170ef364David Gross * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
176a360ef49a83c623784ce97e32f7c07b170ef364David Gross * GNU Library General Public License for more details.
186a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
196a360ef49a83c623784ce97e32f7c07b170ef364David Gross * You should have received a copy of the GNU General Public License
206a360ef49a83c623784ce97e32f7c07b170ef364David Gross * along with this program; if not, write to the Free Software
216a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
226a360ef49a83c623784ce97e32f7c07b170ef364David Gross***************************************************************************/
236a360ef49a83c623784ce97e32f7c07b170ef364David Gross
246a360ef49a83c623784ce97e32f7c07b170ef364David Gross/*****************************************************************************
256a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
266a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	OS Test - International Business Machines Corp. 2007.
276a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
286a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	TEST IDENTIFIER	: fallocate02
296a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
306a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	EXECUTED BY		: anyone
316a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
326a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	TEST TITLE		: Checks for Errors from fallocate()
336a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
346a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	TEST CASE TOTAL	: 7
356a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
366a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	CPU ARCHITECTURES	: PPC,X86, X86_64
376a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
386a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	AUTHOR			: Sharyathi Nagesh
396a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
406a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	CO-PILOT			:
416a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
426a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	DATE STARTED		: 24/12/2007
436a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
446a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	TEST CASES
456a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	(Tests fallocate() for different test cases as reported in map page)
466a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
476a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	INPUT SPECIFICATIONS
486a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		No input needs to be specified
496a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		  fallocate() in-puts are specified through test_data
506a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
516a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	OUTPUT SPECIFICATIONS
526a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		fallocate Error message matches with the expected error message.
536a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
546a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	ENVIRONMENTAL NEEDS
556a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Test Needs to be executed on file system supporting ext4
566a360ef49a83c623784ce97e32f7c07b170ef364David Gross *   LTP {TMP} Needs to be set to such a folder
576a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
586a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	SPECIAL PROCEDURAL REQUIREMENTS
596a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		None
606a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
616a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	DETAILED DESCRIPTION
626a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		This is a test case for fallocate() system call.
636a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		This test suite tests various error messages from fallocate
646a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		If the error message received matches with the expected
656a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		test is considered passed else test fails
666a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Provided TEST_DEFAULT to switch b/w modes
676a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
686a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Total 7 Test Cases :-
696a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Various error messages from the man page
706a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
716a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	Setup:
726a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Setup files on which fallocate is to be called
736a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
746a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	Test:
756a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Loop if the proper options are given.
766a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Execute system call
776a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Check return code.
786a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		If error obtained matches with the expected error
796a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		PASS the test, otherwise TEST FAILS
806a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Provided TEST_DEFAULT to switch b/w modes
816a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
826a360ef49a83c623784ce97e32f7c07b170ef364David Gross *	Cleanup:
836a360ef49a83c623784ce97e32f7c07b170ef364David Gross *		Cleanup the temporary folder
846a360ef49a83c623784ce97e32f7c07b170ef364David Gross *
856a360ef49a83c623784ce97e32f7c07b170ef364David Gross*************************************************************************/
866a360ef49a83c623784ce97e32f7c07b170ef364David Gross
876a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <stdio.h>
886a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <stdlib.h>
896a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <endian.h>
906a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <errno.h>
916a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <sys/stat.h>
926a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <sys/types.h>
936a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <fcntl.h>
946a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <inttypes.h>
956a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include <sys/utsname.h>
966a360ef49a83c623784ce97e32f7c07b170ef364David Gross
976a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include "test.h"
986a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include "usctest.h"
996a360ef49a83c623784ce97e32f7c07b170ef364David Gross#include "linux_syscall_numbers.h"
1006a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1016a360ef49a83c623784ce97e32f7c07b170ef364David Gross#define BLOCKS_WRITTEN 12
1026a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1036a360ef49a83c623784ce97e32f7c07b170ef364David Gross#ifdef TEST_DEFAULT
1046a360ef49a83c623784ce97e32f7c07b170ef364David Gross#define DEFAULT_TEST_MODE 0	//DEFAULT MODE
1056a360ef49a83c623784ce97e32f7c07b170ef364David Gross#else
1066a360ef49a83c623784ce97e32f7c07b170ef364David Gross#define DEFAULT_TEST_MODE 1	//FALLOC_FL_KEEP_SIZE MODE
1076a360ef49a83c623784ce97e32f7c07b170ef364David Gross#endif
1086a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1096a360ef49a83c623784ce97e32f7c07b170ef364David Gross#define OFFSET 12
1106a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1116a360ef49a83c623784ce97e32f7c07b170ef364David Grossstatic inline long fallocate();
1126a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid populate_file();
1136a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid create_fifo();
1146a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid create_pipe();
1156a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid get_blocksize(int fd);
1166a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1176a360ef49a83c623784ce97e32f7c07b170ef364David Grosschar *TCID = "fallocate02";
1186a360ef49a83c623784ce97e32f7c07b170ef364David Grosschar fnamew[255];
1196a360ef49a83c623784ce97e32f7c07b170ef364David Grosschar fnamer[255];
1206a360ef49a83c623784ce97e32f7c07b170ef364David Grossint fdw;
1216a360ef49a83c623784ce97e32f7c07b170ef364David Grossint fdr;
1226a360ef49a83c623784ce97e32f7c07b170ef364David Grossenum { RFILE, WFILE, PIPE, FIFO };
1236a360ef49a83c623784ce97e32f7c07b170ef364David Grossstruct test_data_t {
1246a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int file;
1256a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int mode;
1266a360ef49a83c623784ce97e32f7c07b170ef364David Gross	loff_t offset;
1276a360ef49a83c623784ce97e32f7c07b170ef364David Gross	loff_t len;
1286a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int error;
1296a360ef49a83c623784ce97e32f7c07b170ef364David Gross} test_data[] = {
1306a360ef49a83c623784ce97e32f7c07b170ef364David Gross	{
1316a360ef49a83c623784ce97e32f7c07b170ef364David Gross	RFILE, DEFAULT_TEST_MODE, 0, 1, EBADF}, {
1326a360ef49a83c623784ce97e32f7c07b170ef364David Gross	WFILE, DEFAULT_TEST_MODE, -1, 1, EINVAL}, {
1336a360ef49a83c623784ce97e32f7c07b170ef364David Gross	WFILE, DEFAULT_TEST_MODE, 1, -1, EINVAL}, {
1346a360ef49a83c623784ce97e32f7c07b170ef364David Gross	WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, 0, EINVAL}, {
1356a360ef49a83c623784ce97e32f7c07b170ef364David Gross	WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, -1, EINVAL}, {
1366a360ef49a83c623784ce97e32f7c07b170ef364David Gross	WFILE, DEFAULT_TEST_MODE, -(BLOCKS_WRITTEN + OFFSET), 1, EINVAL}, {
1376a360ef49a83c623784ce97e32f7c07b170ef364David Gross	WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN - OFFSET, 1, 0}
1386a360ef49a83c623784ce97e32f7c07b170ef364David Gross};
1396a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1406a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1416a360ef49a83c623784ce97e32f7c07b170ef364David Grossint TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
1426a360ef49a83c623784ce97e32f7c07b170ef364David Grossint block_size;
1436a360ef49a83c623784ce97e32f7c07b170ef364David Grossint buf_size;
1446a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1456a360ef49a83c623784ce97e32f7c07b170ef364David Gross/******************************************************************************
1466a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Performs all one time clean up for this test on successful
1476a360ef49a83c623784ce97e32f7c07b170ef364David Gross * completion,  premature exit or  failure. Closes all temporary
1486a360ef49a83c623784ce97e32f7c07b170ef364David Gross * files, removes all temporary directories exits the test with
1496a360ef49a83c623784ce97e32f7c07b170ef364David Gross * appropriate return code by calling tst_exit() function.
1506a360ef49a83c623784ce97e32f7c07b170ef364David Gross******************************************************************************/
1516a360ef49a83c623784ce97e32f7c07b170ef364David Grossextern void cleanup()
1526a360ef49a83c623784ce97e32f7c07b170ef364David Gross{
1536a360ef49a83c623784ce97e32f7c07b170ef364David Gross	/* Close all open file descriptors. */
1546a360ef49a83c623784ce97e32f7c07b170ef364David Gross	if (close(fdw) == -1)
1556a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_resm(TWARN | TERRNO, "close(%s) failed", fnamew);
1566a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1576a360ef49a83c623784ce97e32f7c07b170ef364David Gross	if (close(fdr) == -1)
1586a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_resm(TWARN | TERRNO, "close(%s) failed", fnamer);
1596a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1606a360ef49a83c623784ce97e32f7c07b170ef364David Gross	tst_rmdir();
1616a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1626a360ef49a83c623784ce97e32f7c07b170ef364David Gross}
1636a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1646a360ef49a83c623784ce97e32f7c07b170ef364David Gross/*****************************************************************************
1656a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Performs all one time setup for this test. This function is
1666a360ef49a83c623784ce97e32f7c07b170ef364David Gross * used to create temporary dirs and temporary files
1676a360ef49a83c623784ce97e32f7c07b170ef364David Gross * that may be used in the course of this test
1686a360ef49a83c623784ce97e32f7c07b170ef364David Gross ******************************************************************************/
1696a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid setup()
1706a360ef49a83c623784ce97e32f7c07b170ef364David Gross{
1716a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1726a360ef49a83c623784ce97e32f7c07b170ef364David Gross	tst_sig(FORK, DEF_HANDLER, cleanup);
1736a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1746a360ef49a83c623784ce97e32f7c07b170ef364David Gross	TEST_PAUSE;
1756a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1766a360ef49a83c623784ce97e32f7c07b170ef364David Gross	tst_tmpdir();
1776a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1786a360ef49a83c623784ce97e32f7c07b170ef364David Gross	sprintf(fnamer, "tfile_read_%d", getpid());
1796a360ef49a83c623784ce97e32f7c07b170ef364David Gross	sprintf(fnamew, "tfile_write_%d", getpid());
1806a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1816a360ef49a83c623784ce97e32f7c07b170ef364David Gross	fdr = open(fnamer, O_RDONLY | O_CREAT, S_IRUSR);
1826a360ef49a83c623784ce97e32f7c07b170ef364David Gross	if (fdr == -1)
1836a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_brkm(TBROK | TERRNO, cleanup,
1846a360ef49a83c623784ce97e32f7c07b170ef364David Gross			 "open(%s, O_RDONLY|O_CREAT, S_IRUSR) failed", fnamer);
1856a360ef49a83c623784ce97e32f7c07b170ef364David Gross	fdw = open(fnamew, O_RDWR | O_CREAT, S_IRWXU);
1866a360ef49a83c623784ce97e32f7c07b170ef364David Gross	if (fdw == -1)
1876a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_brkm(TBROK | TERRNO, cleanup,
1886a360ef49a83c623784ce97e32f7c07b170ef364David Gross			 "open(%s, O_RDWR|O_CREAT, S_IRWXU) failed", fnamew);
1896a360ef49a83c623784ce97e32f7c07b170ef364David Gross	get_blocksize(fdr);
1906a360ef49a83c623784ce97e32f7c07b170ef364David Gross	populate_file();
1916a360ef49a83c623784ce97e32f7c07b170ef364David Gross}
1926a360ef49a83c623784ce97e32f7c07b170ef364David Gross
1936a360ef49a83c623784ce97e32f7c07b170ef364David Gross/*****************************************************************************
1946a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Gets the block size for the file system
1956a360ef49a83c623784ce97e32f7c07b170ef364David Gross ******************************************************************************/
1966a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid get_blocksize(int fd)
1976a360ef49a83c623784ce97e32f7c07b170ef364David Gross{
1986a360ef49a83c623784ce97e32f7c07b170ef364David Gross	struct stat file_stat;
1996a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2006a360ef49a83c623784ce97e32f7c07b170ef364David Gross	if (fstat(fd, &file_stat) < 0)
2016a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_resm(TFAIL | TERRNO,
2026a360ef49a83c623784ce97e32f7c07b170ef364David Gross			 "fstat failed while getting block_size");
2036a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2046a360ef49a83c623784ce97e32f7c07b170ef364David Gross	block_size = (int)file_stat.st_blksize;
2056a360ef49a83c623784ce97e32f7c07b170ef364David Gross	buf_size = block_size;
2066a360ef49a83c623784ce97e32f7c07b170ef364David Gross}
2076a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2086a360ef49a83c623784ce97e32f7c07b170ef364David Gross/*****************************************************************************
2096a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Writes data into the file
2106a360ef49a83c623784ce97e32f7c07b170ef364David Gross ******************************************************************************/
2116a360ef49a83c623784ce97e32f7c07b170ef364David Grossvoid populate_file()
2126a360ef49a83c623784ce97e32f7c07b170ef364David Gross{
2136a360ef49a83c623784ce97e32f7c07b170ef364David Gross	char buf[buf_size + 1];
2146a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int index;
2156a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int blocks;
2166a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int data;
2176a360ef49a83c623784ce97e32f7c07b170ef364David Gross	for (blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) {
2186a360ef49a83c623784ce97e32f7c07b170ef364David Gross		for (index = 0; index < buf_size; index++)
2196a360ef49a83c623784ce97e32f7c07b170ef364David Gross			buf[index] = 'A' + (index % 26);
2206a360ef49a83c623784ce97e32f7c07b170ef364David Gross		buf[buf_size] = '\0';
2216a360ef49a83c623784ce97e32f7c07b170ef364David Gross		if ((data = write(fdw, buf, buf_size)) < 0)
2226a360ef49a83c623784ce97e32f7c07b170ef364David Gross			tst_brkm(TBROK | TERRNO, cleanup,
2236a360ef49a83c623784ce97e32f7c07b170ef364David Gross				 "Unable to write to %s", fnamew);
2246a360ef49a83c623784ce97e32f7c07b170ef364David Gross	}
2256a360ef49a83c623784ce97e32f7c07b170ef364David Gross}
2266a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2276a360ef49a83c623784ce97e32f7c07b170ef364David Gross/*****************************************************************************
2286a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Wraper function to call fallocate system call
2296a360ef49a83c623784ce97e32f7c07b170ef364David Gross ******************************************************************************/
2306a360ef49a83c623784ce97e32f7c07b170ef364David Grossstatic inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
2316a360ef49a83c623784ce97e32f7c07b170ef364David Gross{
2326a360ef49a83c623784ce97e32f7c07b170ef364David Gross#if __WORDSIZE == 32
2336a360ef49a83c623784ce97e32f7c07b170ef364David Gross	return (long)ltp_syscall(__NR_fallocate, fd, mode,
2346a360ef49a83c623784ce97e32f7c07b170ef364David Gross			     __LONG_LONG_PAIR((off_t) (offset >> 32),
2356a360ef49a83c623784ce97e32f7c07b170ef364David Gross					      (off_t) offset),
2366a360ef49a83c623784ce97e32f7c07b170ef364David Gross			     __LONG_LONG_PAIR((off_t) (len >> 32),
2376a360ef49a83c623784ce97e32f7c07b170ef364David Gross					      (off_t) len));
2386a360ef49a83c623784ce97e32f7c07b170ef364David Gross#else
2396a360ef49a83c623784ce97e32f7c07b170ef364David Gross	return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
2406a360ef49a83c623784ce97e32f7c07b170ef364David Gross#endif
2416a360ef49a83c623784ce97e32f7c07b170ef364David Gross}
2426a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2436a360ef49a83c623784ce97e32f7c07b170ef364David Gross/*****************************************************************************
2446a360ef49a83c623784ce97e32f7c07b170ef364David Gross * Main function that calls the system call with the  appropriate parameters
2456a360ef49a83c623784ce97e32f7c07b170ef364David Gross ******************************************************************************/
2466a360ef49a83c623784ce97e32f7c07b170ef364David Gross/* ac: number of command line parameters */
2476a360ef49a83c623784ce97e32f7c07b170ef364David Gross/* av: pointer to the array of the command line parameters */
2486a360ef49a83c623784ce97e32f7c07b170ef364David Grossint main(int ac, char **av)
2496a360ef49a83c623784ce97e32f7c07b170ef364David Gross{
2506a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2516a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int test_index = 0;
2526a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int lc;
2536a360ef49a83c623784ce97e32f7c07b170ef364David Gross	int fd;
2546a360ef49a83c623784ce97e32f7c07b170ef364David Gross	char fname[255], *msg;
2556a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2566a360ef49a83c623784ce97e32f7c07b170ef364David Gross	/***************************************************************
2576a360ef49a83c623784ce97e32f7c07b170ef364David Gross	     * parse standard options
2586a360ef49a83c623784ce97e32f7c07b170ef364David Gross     	***************************************************************/
2596a360ef49a83c623784ce97e32f7c07b170ef364David Gross	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
2606a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
2616a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2626a360ef49a83c623784ce97e32f7c07b170ef364David Gross	/* perform global test setup, call setup() function. */
2636a360ef49a83c623784ce97e32f7c07b170ef364David Gross	setup();
2646a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2656a360ef49a83c623784ce97e32f7c07b170ef364David Gross	for (lc = 0; TEST_LOOPING(lc); lc++) {
2666a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2676a360ef49a83c623784ce97e32f7c07b170ef364David Gross		tst_count = 0;
2686a360ef49a83c623784ce97e32f7c07b170ef364David Gross		for (test_index = 0; test_index < TST_TOTAL; test_index++) {
2696a360ef49a83c623784ce97e32f7c07b170ef364David Gross			switch (test_data[test_index].file) {
2706a360ef49a83c623784ce97e32f7c07b170ef364David Gross			case RFILE:
2716a360ef49a83c623784ce97e32f7c07b170ef364David Gross				fd = fdr;
2726a360ef49a83c623784ce97e32f7c07b170ef364David Gross				strcpy(fname, fnamer);
2736a360ef49a83c623784ce97e32f7c07b170ef364David Gross				break;
2746a360ef49a83c623784ce97e32f7c07b170ef364David Gross			case WFILE:
2756a360ef49a83c623784ce97e32f7c07b170ef364David Gross				fd = fdw;
2766a360ef49a83c623784ce97e32f7c07b170ef364David Gross				strcpy(fname, fnamew);
2776a360ef49a83c623784ce97e32f7c07b170ef364David Gross				break;
2786a360ef49a83c623784ce97e32f7c07b170ef364David Gross			default:
2796a360ef49a83c623784ce97e32f7c07b170ef364David Gross				tst_brkm(TCONF, cleanup,
2806a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 "invalid test setting");
2816a360ef49a83c623784ce97e32f7c07b170ef364David Gross				tst_exit();
2826a360ef49a83c623784ce97e32f7c07b170ef364David Gross			}
2836a360ef49a83c623784ce97e32f7c07b170ef364David Gross
2846a360ef49a83c623784ce97e32f7c07b170ef364David Gross			TEST(fallocate
2856a360ef49a83c623784ce97e32f7c07b170ef364David Gross			     (fd, test_data[test_index].mode,
2866a360ef49a83c623784ce97e32f7c07b170ef364David Gross			      test_data[test_index].offset * block_size,
2876a360ef49a83c623784ce97e32f7c07b170ef364David Gross			      test_data[test_index].len * block_size));
2886a360ef49a83c623784ce97e32f7c07b170ef364David Gross			/* check return code */
2896a360ef49a83c623784ce97e32f7c07b170ef364David Gross			if (TEST_ERRNO != test_data[test_index].error) {
2906a360ef49a83c623784ce97e32f7c07b170ef364David Gross				if (TEST_ERRNO == EOPNOTSUPP
2916a360ef49a83c623784ce97e32f7c07b170ef364David Gross				    || TEST_ERRNO == ENOSYS) {
2926a360ef49a83c623784ce97e32f7c07b170ef364David Gross					tst_brkm(TCONF, cleanup,
2936a360ef49a83c623784ce97e32f7c07b170ef364David Gross						 "fallocate system call is not implemented");
2946a360ef49a83c623784ce97e32f7c07b170ef364David Gross				}
2956a360ef49a83c623784ce97e32f7c07b170ef364David Gross				TEST_ERROR_LOG(TEST_ERRNO);
2966a360ef49a83c623784ce97e32f7c07b170ef364David Gross				tst_resm(TFAIL | TTERRNO,
2976a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 "fallocate(%s:%d, %d, %" PRId64 ", %"
2986a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 PRId64 ") failed, expected errno:%d",
2996a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 fname, fd, test_data[test_index].mode,
3006a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 test_data[test_index].offset *
3016a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 block_size,
3026a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 test_data[test_index].len * block_size,
3036a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 test_data[test_index].error);
3046a360ef49a83c623784ce97e32f7c07b170ef364David Gross			} else {
3056a360ef49a83c623784ce97e32f7c07b170ef364David Gross				/* No Verification test, yet... */
3066a360ef49a83c623784ce97e32f7c07b170ef364David Gross				tst_resm(TPASS,
3076a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 "fallocate(%s:%d, %d, %" PRId64 ", %"
3086a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 PRId64 ") returned %d", fname, fd,
3096a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 test_data[test_index].mode,
3106a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 test_data[test_index].offset *
3116a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 block_size,
3126a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 test_data[test_index].len * block_size,
3136a360ef49a83c623784ce97e32f7c07b170ef364David Gross					 TEST_ERRNO);
3146a360ef49a83c623784ce97e32f7c07b170ef364David Gross			}
3156a360ef49a83c623784ce97e32f7c07b170ef364David Gross		}
3166a360ef49a83c623784ce97e32f7c07b170ef364David Gross	}
3176a360ef49a83c623784ce97e32f7c07b170ef364David Gross	cleanup();
3186a360ef49a83c623784ce97e32f7c07b170ef364David Gross	tst_exit();
3196a360ef49a83c623784ce97e32f7c07b170ef364David Gross}
3206a360ef49a83c623784ce97e32f7c07b170ef364David Gross