From: Subrata <sub...@us...> - 2009-03-23 14:46:46
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/fallocate In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14647/ltp/testcases/kernel/syscalls/fallocate Modified Files: fallocate01.c fallocate02.c fallocate03.c Log Message: Coding Syle Cleanups. Signed-Off-By: <mic...@pe...>. Index: fallocate02.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/fallocate/fallocate02.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** fallocate02.c 20 Mar 2009 09:28:11 -0000 1.8 --- fallocate02.c 23 Mar 2009 13:35:40 -0000 1.9 *************** *** 1,89 **** - /****************************************************************************** ! * fallocate02.c * Mon Dec 24 2007 ! * Copyright (c) International Business Machines Corp., 2007 * Emali : sha...@in... ******************************************************************************/ - /*************************************************************************** ! * 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. ! ***************************************************************************/ ! /***************************************************************************** ! * ! * OS Test - International Business Machines Corp. 2007. ! * ! * TEST IDENTIFIER : fallocate02 ! * ! * EXECUTED BY : anyone ! * ! * TEST TITLE : Checks for Errors from fallocate() ! * ! * TEST CASE TOTAL : 7 ! * ! * CPU ARCHITECTURES : PPC,X86, X86_64 ! * ! * AUTHOR : Sharyathi Nagesh ! * ! * CO-PILOT : ! * ! * DATE STARTED : 24/12/2007 ! * ! * TEST CASES ! * (Tests fallocate() for different test cases as reported in map page) ! * ! * INPUT SPECIFICATIONS ! * No input needs to be specified ! * fallocate() in-puts are specified through test_data ! * ! * OUTPUT SPECIFICATIONS ! * fallocate Error message matches with the expected error message. ! * ! * ENVIRONMENTAL NEEDS ! * Test Needs to be executed on file system supporting ext4 ! * LTP {TMP} Needs to be set to such a folder ! * ! * SPECIAL PROCEDURAL REQUIREMENTS ! * None ! * ! * DETAILED DESCRIPTION ! * This is a test case for fallocate() system call. ! * This test suite tests various error messages from fallocate ! * If the error message received matches with the expected ! * test is considered passed else test fails ! * Provided TEST_DEFAULT to switch b/w modes ! * ! * Total 7 Test Cases :- ! * Various error messages from the man page ! * ! * Setup: ! * Setup files on which fallocate is to be called ! * ! * Test: ! * Loop if the proper options are given. ! * Execute system call ! * Check return code. ! * If error obtained matches with the expected error ! * PASS the test, otherwise TEST FAILS ! * Provided TEST_DEFAULT to switch b/w modes ! * ! * Cleanup: ! * Cleanup the temporary folder ! * *************************************************************************/ --- 1,86 ---- /****************************************************************************** ! * fallocate02.c * Mon Dec 24 2007 ! * Copyright (c) International Business Machines Corp., 2007 * Emali : sha...@in... ******************************************************************************/ /*************************************************************************** ! * 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. ! ***************************************************************************/ /***************************************************************************** ! * ! * OS Test - International Business Machines Corp. 2007. ! * ! * TEST IDENTIFIER : fallocate02 ! * ! * EXECUTED BY : anyone ! * ! * TEST TITLE : Checks for Errors from fallocate() ! * ! * TEST CASE TOTAL : 7 ! * ! * CPU ARCHITECTURES : PPC,X86, X86_64 ! * ! * AUTHOR : Sharyathi Nagesh ! * ! * CO-PILOT : ! * ! * DATE STARTED : 24/12/2007 ! * ! * TEST CASES ! * (Tests fallocate() for different test cases as reported in map page) ! * ! * INPUT SPECIFICATIONS ! * No input needs to be specified ! * fallocate() in-puts are specified through test_data ! * ! * OUTPUT SPECIFICATIONS ! * fallocate Error message matches with the expected error message. ! * ! * ENVIRONMENTAL NEEDS ! * Test Needs to be executed on file system supporting ext4 ! * LTP {TMP} Needs to be set to such a folder ! * ! * SPECIAL PROCEDURAL REQUIREMENTS ! * None ! * ! * DETAILED DESCRIPTION ! * This is a test case for fallocate() system call. ! * This test suite tests various error messages from fallocate ! * If the error message received matches with the expected ! * test is considered passed else test fails ! * Provided TEST_DEFAULT to switch b/w modes ! * ! * Total 7 Test Cases :- ! * Various error messages from the man page ! * ! * Setup: ! * Setup files on which fallocate is to be called ! * ! * Test: ! * Loop if the proper options are given. ! * Execute system call ! * Check return code. ! * If error obtained matches with the expected error ! * PASS the test, otherwise TEST FAILS ! * Provided TEST_DEFAULT to switch b/w modes ! * ! * Cleanup: ! * Cleanup the temporary folder ! * *************************************************************************/ *************** *** 105,118 **** #ifdef TEST_DEFAULT ! #define DEFAULT_TEST_MODE 0 //DEFAULT MODE #else ! #define DEFAULT_TEST_MODE 1 //FALLOC_FL_KEEP_SIZE MODE #endif #ifndef __NR_fallocate ! # define __NR_fallocate -1 //DUMMY VALUE ! int arch_support = 0; #else ! int arch_support = 1; #endif --- 102,115 ---- #ifdef TEST_DEFAULT ! #define DEFAULT_TEST_MODE 0 //DEFAULT MODE #else ! #define DEFAULT_TEST_MODE 1 //FALLOC_FL_KEEP_SIZE MODE #endif #ifndef __NR_fallocate ! # define __NR_fallocate -1 //DUMMY VALUE ! int arch_support = 0; #else ! int arch_support = 1; #endif *************** *** 127,140 **** /* Extern Global Variables */ ! extern int Tst_count; /* counter for tst_xxx routines. */ /* Global Variables */ ! char *TCID = "fallocate02"; /* test program identifier. */ ! char fnamew[255]; /* Files used for testing */ ! char fnamer[255]; /* Files used for testing */ int fdw; int fdr; ! enum {RFILE,WFILE,PIPE,FIFO}; ! struct test_data_t ! { int file; int mode; --- 124,136 ---- /* Extern Global Variables */ ! extern int Tst_count; /* counter for tst_xxx routines */ /* Global Variables */ ! char *TCID = "fallocate02"; /* test program identifier */ ! char fnamew[255]; /* Files used for testing */ ! char fnamer[255]; /* Files used for testing */ int fdw; int fdr; ! enum { RFILE, WFILE, PIPE, FIFO }; ! struct test_data_t { int file; int mode; *************** *** 143,159 **** int error; } test_data[] = { ! {RFILE, DEFAULT_TEST_MODE, 0, 1, EBADF}, ! {WFILE, DEFAULT_TEST_MODE, -1, 1, EINVAL}, ! {WFILE, DEFAULT_TEST_MODE, 1, -1, EINVAL}, ! {WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, 0, EINVAL}, ! {WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, -1, EINVAL}, ! {WFILE, DEFAULT_TEST_MODE,-( BLOCKS_WRITTEN + OFFSET ), 1 , EINVAL}, ! {WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN - OFFSET, 1 , 0} }; ! int TST_TOTAL = sizeof(test_data)/sizeof(test_data[0]); /* total number of tests in this file. */ int block_size; int buf_size; - /****************************************************************************** * Performs all one time clean up for this test on successful --- 139,156 ---- int error; } test_data[] = { ! { ! RFILE, DEFAULT_TEST_MODE, 0, 1, EBADF}, { ! WFILE, DEFAULT_TEST_MODE, -1, 1, EINVAL}, { ! WFILE, DEFAULT_TEST_MODE, 1, -1, EINVAL}, { ! WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, 0, EINVAL}, { ! WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, -1, EINVAL}, { ! WFILE, DEFAULT_TEST_MODE, -(BLOCKS_WRITTEN + OFFSET), 1, EINVAL}, { ! WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN - OFFSET, 1, 0} }; ! /* total number of tests in this file */ ! int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); int block_size; int buf_size; /****************************************************************************** * Performs all one time clean up for this test on successful *************** *** 162,183 **** * appropriate return code by calling tst_exit() function. ******************************************************************************/ ! extern void ! cleanup() { /* Close all open file descriptors. */ ! if(close(fdw) == -1) ! { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", ! fnamew, errno, strerror(errno)); } ! if(close(fdr) == -1) ! { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", ! fnamer, errno, strerror(errno)); } ! /* Remove tmp dir and all files in it */ ! tst_rmdir(); /* Exit with appropriate return code. */ --- 159,177 ---- * appropriate return code by calling tst_exit() function. ******************************************************************************/ ! extern void cleanup() { /* Close all open file descriptors. */ ! if (close(fdw) == -1) { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fnamew, ! errno, strerror(errno)); } ! if (close(fdr) == -1) { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fnamer, ! errno, strerror(errno)); } ! /* Remove tmp dir and all files in it */ ! tst_rmdir(); /* Exit with appropriate return code. */ *************** *** 191,217 **** * that may be used in the course of this test ******************************************************************************/ ! void ! setup() { ! /* capture signals */ ! tst_sig(FORK, DEF_HANDLER, cleanup); ! /* Pause if that option was specified */ ! TEST_PAUSE; ! /* make a temp directory and cd to it */ ! tst_tmpdir(); ! sprintf(fnamer,"tfile_read_%d",getpid()); ! sprintf(fnamew,"tfile_write_%d",getpid()); ! if ((fdr = open(fnamer,O_RDONLY|O_CREAT,S_IRUSR)) == -1) { ! tst_brkm(TBROK, cleanup, "open(%s,O_RDONLY|O_CREAT,S_IRUSR) Failed, errno=%d : %s", ! fnamer, errno, strerror(errno)); ! } ! if ((fdw = open(fnamew,O_RDWR|O_CREAT,S_IRWXU)) == -1) { ! tst_brkm(TBROK, cleanup, "open(%s,O_RDWR|O_CREAT,S_IRWXU) Failed, errno=%d : %s", ! fnamew, errno, strerror(errno)); ! } get_blocksize(fdr); populate_file(); --- 185,212 ---- * that may be used in the course of this test ******************************************************************************/ ! void setup() { ! /* capture signals */ ! tst_sig(FORK, DEF_HANDLER, cleanup); ! /* Pause if that option was specified */ ! TEST_PAUSE; ! /* make a temp directory and cd to it */ ! tst_tmpdir(); ! sprintf(fnamer, "tfile_read_%d", getpid()); ! sprintf(fnamew, "tfile_write_%d", getpid()); ! if ((fdr = open(fnamer, O_RDONLY | O_CREAT, S_IRUSR)) == -1) { ! tst_brkm(TBROK, cleanup, ! "open(%s,O_RDONLY|O_CREAT,S_IRUSR) Failed, errno=%d : %s", ! fnamer, errno, strerror(errno)); ! } ! if ((fdw = open(fnamew, O_RDWR | O_CREAT, S_IRWXU)) == -1) { ! tst_brkm(TBROK, cleanup, ! "open(%s,O_RDWR|O_CREAT,S_IRWXU) Failed, errno=%d : %s", ! fnamew, errno, strerror(errno)); ! } get_blocksize(fdr); populate_file(); *************** *** 221,234 **** * Gets the block size for the file system ******************************************************************************/ ! void ! get_blocksize(int fd) { ! struct stat file_stat; ! if( fstat(fd, &file_stat) < 0 ) ! tst_resm(TFAIL, "fstat failed while getting block_size errno=%d : %s", ! TEST_ERRNO, strerror(TEST_ERRNO)); ! block_size = (int) file_stat.st_blksize; buf_size = block_size; } --- 216,229 ---- * Gets the block size for the file system ******************************************************************************/ ! void get_blocksize(int fd) { ! struct stat file_stat; ! if (fstat(fd, &file_stat) < 0) ! tst_resm(TFAIL, ! "fstat failed while getting block_size errno=%d : %s", ! TEST_ERRNO, strerror(TEST_ERRNO)); ! block_size = (int)file_stat.st_blksize; buf_size = block_size; } *************** *** 237,261 **** * Writes data into the file ******************************************************************************/ ! void ! populate_file() { ! char buf[buf_size + 1]; ! int index; ! int blocks; ! int data; ! for (blocks = 0; blocks < BLOCKS_WRITTEN ; blocks++) ! { ! for (index = 0; index < buf_size; index++) ! buf[index] = 'A' + (index % 26); ! buf[buf_size]='\0'; ! if (( data = write(fdw, buf, buf_size)) < 0 ) ! { ! tst_brkm(TBROK, cleanup, "Unable to write to %s. Error: %d, %s", \ ! fnamew,errno, strerror(errno)); ! } ! } } - /***************************************************************************** * Wraper function to call fallocate system call --- 232,253 ---- * Writes data into the file ******************************************************************************/ ! void populate_file() { ! char buf[buf_size + 1]; ! int index; ! int blocks; ! int data; ! for (blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) { ! for (index = 0; index < buf_size; index++) ! buf[index] = 'A' + (index % 26); ! buf[buf_size] = '\0'; ! if ((data = write(fdw, buf, buf_size)) < 0) { ! tst_brkm(TBROK, cleanup, ! "Unable to write to %s. Error: %d, %s", fnamew, ! errno, strerror(errno)); ! } ! } } /***************************************************************************** * Wraper function to call fallocate system call *************** *** 263,288 **** static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) { ! #if __WORDSIZE == 32 ! struct utsname buf; ! if ( uname(&buf) == 0 ){ ! if(!strcmp(buf.machine,"ppc64") || !strcmp(buf.machine,"x86_64")) ! return syscall(__NR_fallocate, fd, mode, (int)(offset>>32), (int)offset ,(int)(len>>32), (int)len); ! } ! else{ ! perror("uname:"); ! return -1; ! } ! #endif ! return syscall(__NR_fallocate, fd, mode, ! offset,len); } - /***************************************************************************** * Main function that calls the system call with the appropriate parameters ******************************************************************************/ ! int ! main(int ac, /* number of command line parameters */ ! char **av) /* pointer to the array of the command line parameters. */ { --- 255,280 ---- static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) { ! #if __WORDSIZE == 32 ! struct utsname buf; ! if (uname(&buf) == 0) { ! if (!strcmp(buf.machine, "ppc64") ! || !strcmp(buf.machine, "x86_64")) ! return syscall(__NR_fallocate, fd, mode, ! (int)(offset >> 32), (int)offset, ! (int)(len >> 32), (int)len); ! } else { ! perror("uname:"); ! return -1; ! } ! #endif ! return syscall(__NR_fallocate, fd, mode, offset, len); } /***************************************************************************** * Main function that calls the system call with the appropriate parameters ******************************************************************************/ ! /* ac: number of command line parameters */ ! /* av: pointer to the array of the command line parameters */ ! int main(int ac, char **av) { *************** *** 292,299 **** char fname[255], *msg; ! /*************************************************************** * parse standard options ***************************************************************/ ! if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); --- 284,291 ---- char fname[255], *msg; ! /*************************************************************** * parse standard options ***************************************************************/ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); *************** *** 301,306 **** * either of x86, x86_64 or ppc architecture */ ! if ( !arch_support || (tst_kvercmp(2,6,23) < 0)) { ! tst_resm(TCONF," System doesn't support execution of the test"); exit(0); } --- 293,299 ---- * either of x86, x86_64 or ppc architecture */ ! if (!arch_support || (tst_kvercmp(2, 6, 23) < 0)) { ! tst_resm(TCONF, ! " System doesn't support execution of the test"); exit(0); } *************** *** 309,345 **** setup(); ! for (lc=0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count=0; ! for(test_index = 0 ; test_index < TST_TOTAL; test_index ++) ! { ! switch(test_data[test_index].file){ ! case RFILE: fd = fdr; ! strcpy(fname,fnamer); break; ! case WFILE: fd = fdw; ! strcpy(fname,fnamew); break; } ! ! TEST(fallocate( fd, test_data[test_index].mode, ! test_data[test_index].offset * block_size, test_data[test_index].len * block_size)); ! /* check return code */ ! if ( TEST_ERRNO != test_data[test_index].error ) { ! if ( TEST_ERRNO == EOPNOTSUPP ) { ! tst_brkm( TCONF, cleanup, " fallocate system call" \ ! " is not implemented"); } - TEST_ERROR_LOG(TEST_ERRNO); - tst_resm(TFAIL, "fallocate(%s:%d, %d, %lld, %lld) Failed, expected errno:%d \ - instead errno=%d : %s", fname, fd,test_data[test_index].mode, - test_data[test_index].offset * block_size, test_data[test_index].len * block_size, - test_data[test_index].error, TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - /* No Verification test, yet... */ - tst_resm(TPASS, "fallocate(%s:%d, %d, %lld, %lld) returned %d ", - fname, fd,test_data[test_index].mode, test_data[test_index].offset * block_size, - test_data[test_index].len * block_size, TEST_ERRNO); - } } } --- 302,349 ---- setup(); ! for (lc = 0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count = 0; ! for (test_index = 0; test_index < TST_TOTAL; test_index++) { ! switch (test_data[test_index].file) { ! case RFILE: ! fd = fdr; ! strcpy(fname, fnamer); break; ! case WFILE: ! fd = fdw; ! strcpy(fname, fnamew); break; } ! ! TEST(fallocate ! (fd, test_data[test_index].mode, ! test_data[test_index].offset * block_size, ! test_data[test_index].len * block_size)); ! /* check return code */ ! if (TEST_ERRNO != test_data[test_index].error) { ! if (TEST_ERRNO == EOPNOTSUPP) { ! tst_brkm(TCONF, cleanup, ! " fallocate system call" ! " is not implemented"); ! } ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, "fallocate(%s:%d, %d, %lld, %lld) Failed, \ ! expected errno:%d instead errno=%d : %s", ! fname, fd, test_data[test_index].mode, ! test_data[test_index].offset * block_size, ! test_data[test_index].len * block_size, ! test_data[test_index].error, TEST_ERRNO, ! strerror(TEST_ERRNO)); ! } else { ! /* No Verification test, yet... */ ! tst_resm(TPASS, ! "fallocate(%s:%d, %d, %lld, %lld) returned %d ", ! fname, fd, test_data[test_index].mode, ! test_data[test_index].offset * ! block_size, ! test_data[test_index].len * block_size, ! TEST_ERRNO); } } } *************** *** 347,349 **** return 0; } - --- 351,352 ---- Index: fallocate03.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/fallocate/fallocate03.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** fallocate03.c 20 Mar 2009 09:28:11 -0000 1.8 --- fallocate03.c 23 Mar 2009 13:35:40 -0000 1.9 *************** *** 1,86 **** - /****************************************************************************** ! * fallocate03.c * Mon Dec 24 2007 ! * Copyright (c) International Business Machines Corp., 2007 * Emali : sha...@in... ******************************************************************************/ - /*************************************************************************** ! * 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. ! ***************************************************************************/ /***************************************************************************** ! * ! * OS Test - International Business Machines Corp. 2007. ! * ! * TEST IDENTIFIER : fallocate03 ! * ! * EXECUTED BY : anyone ! * ! * TEST TITLE : fallocate ! * ! * TEST CASE TOTAL : 8 ! * ! * CPU ARCHITECTURES : PPC,X86, X86_64 ! * ! * AUTHOR : Sharyathi Nagesh ! * ! * CO-PILOT : ! * ! * DATE STARTED : 24/12/2007 ! * ! * TEST CASES ! * (Working of fallocate on a sparse file) ! * ! * ! * INPUT SPECIFICATIONS ! * No input needs to be specified ! * fallocate() in-puts are specified through test_data ! * ! * OUTPUT SPECIFICATIONS ! * Output describing whether test cases passed or failed. ! * ! * ENVIRONMENTAL NEEDS ! * Test Needs to be executed on file system supporting ext4 ! * LTP {TMP} Needs to be set to such a folder ! * ! * SPECIAL PROCEDURAL REQUIREMENTS ! * None ! * ! * DETAILED DESCRIPTION ! * This is a test case for fallocate() system call. ! * This test suite tests working of fallocate on sparse file ! * fallocate is tested for different offsets ! * ! * Total 8 Test Cases :- ! * Different offsets with in a sparse file is tested ! * ! * Setup: ! * Setup file on which fallocate is to be called ! * Set up a file with hole, created through lseek ! * ! * Test: ! * Loop if the proper options are given ! * Execute system call ! * Check return code, if system call failed ! * TEST fails, PASS the test otherwise ! * ! * Cleanup: ! * Cleanup the temporary folder ! * *************************************************************************/ --- 1,84 ---- /****************************************************************************** ! * fallocate03.c * Mon Dec 24 2007 ! * Copyright (c) International Business Machines Corp., 2007 * Emali : sha...@in... ******************************************************************************/ /*************************************************************************** ! * 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. ! ***************************************************************************/ /***************************************************************************** ! * ! * OS Test - International Business Machines Corp. 2007. ! * ! * TEST IDENTIFIER : fallocate03 ! * ! * EXECUTED BY : anyone ! * ! * TEST TITLE : fallocate ! * ! * TEST CASE TOTAL : 8 ! * ! * CPU ARCHITECTURES : PPC,X86, X86_64 ! * ! * AUTHOR : Sharyathi Nagesh ! * ! * CO-PILOT : ! * ! * DATE STARTED : 24/12/2007 ! * ! * TEST CASES ! * (Working of fallocate on a sparse file) ! * ! * ! * INPUT SPECIFICATIONS ! * No input needs to be specified ! * fallocate() in-puts are specified through test_data ! * ! * OUTPUT SPECIFICATIONS ! * Output describing whether test cases passed or failed. ! * ! * ENVIRONMENTAL NEEDS ! * Test Needs to be executed on file system supporting ext4 ! * LTP {TMP} Needs to be set to such a folder ! * ! * SPECIAL PROCEDURAL REQUIREMENTS ! * None ! * ! * DETAILED DESCRIPTION ! * This is a test case for fallocate() system call. ! * This test suite tests working of fallocate on sparse file ! * fallocate is tested for different offsets ! * ! * Total 8 Test Cases :- ! * Different offsets with in a sparse file is tested ! * ! * Setup: ! * Setup file on which fallocate is to be called ! * Set up a file with hole, created through lseek ! * ! * Test: ! * Loop if the proper options are given ! * Execute system call ! * Check return code, if system call failed ! * TEST fails, PASS the test otherwise ! * ! * Cleanup: ! * Cleanup the temporary folder ! * *************************************************************************/ *************** *** 90,94 **** #include <errno.h> #include <sys/stat.h> ! #include <sys/types.h> //Can be done with out #include <fcntl.h> #include <unistd.h> --- 88,92 ---- #include <errno.h> #include <sys/stat.h> ! #include <sys/types.h> //Can be done with out #include <fcntl.h> #include <unistd.h> *************** *** 103,114 **** #define HOLE_SIZE_IN_BLOCKS 12 #define DEFAULT_MODE 0 ! #define FALLOC_FL_KEEP_SIZE 1 //Need to be removed once the glibce support is provided #define TRUE 0 #ifndef __NR_fallocate ! # define __NR_fallocate -1 //DUMMY VALUE ! int arch_support = 0; #else ! int arch_support = 1; #endif --- 101,112 ---- #define HOLE_SIZE_IN_BLOCKS 12 #define DEFAULT_MODE 0 ! #define FALLOC_FL_KEEP_SIZE 1 //Need to be removed once the glibce support is provided #define TRUE 0 #ifndef __NR_fallocate ! # define __NR_fallocate -1 //DUMMY VALUE ! int arch_support = 0; #else ! int arch_support = 1; #endif *************** *** 120,146 **** /* Extern Global Variables */ ! extern int Tst_count; /* counter for tst_xxx routines. */ /* Global Variables */ ! char *TCID = "fallocate03"; /* test program identifier. */ char fname[255]; int fd; ! struct test_data_t ! { int mode; loff_t offset; loff_t len; int error; ! }test_data[] = { ! {DEFAULT_MODE, 2, 1, TRUE}, ! {DEFAULT_MODE, BLOCKS_WRITTEN, 1, TRUE}, ! {DEFAULT_MODE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS/2 -1 , 1, TRUE}, ! {DEFAULT_MODE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS + 1 , 1, TRUE}, ! {FALLOC_FL_KEEP_SIZE,2, 1, TRUE}, ! {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN , 1, TRUE}, ! {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS/2 + 1 , 1, TRUE}, ! {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS + 2 , 1, TRUE} }; ! int TST_TOTAL = sizeof(test_data)/sizeof(test_data[0]); /* total number of tests in this file. */ int block_size; int buf_size; --- 118,144 ---- /* Extern Global Variables */ ! extern int Tst_count; /* counter for tst_xxx routines */ /* Global Variables */ ! char *TCID = "fallocate03"; /* test program identifier */ char fname[255]; int fd; ! struct test_data_t { int mode; loff_t offset; loff_t len; int error; ! } test_data[] = { ! { ! DEFAULT_MODE, 2, 1, TRUE}, { ! DEFAULT_MODE, BLOCKS_WRITTEN, 1, TRUE}, { ! DEFAULT_MODE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS / 2 - 1, 1, TRUE}, { ! DEFAULT_MODE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS + 1, 1, TRUE}, { ! FALLOC_FL_KEEP_SIZE, 2, 1, TRUE}, { ! FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN, 1, TRUE}, { ! FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS / 2 + 1, 1, TRUE}, { ! FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS + 2, 1, TRUE} }; ! int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); /* total number of tests in this file. */ int block_size; int buf_size; *************** *** 152,167 **** * appropriate return code by calling tst_exit() function. ******************************************************************************/ ! extern void ! cleanup() { /* Close all open file descriptors. */ ! if(close(fd) == -1) ! { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", ! fname, errno, strerror(errno)); } ! /* Remove tmp dir and all files in it */ ! tst_rmdir(); /* Exit with appropriate return code. */ --- 150,163 ---- * appropriate return code by calling tst_exit() function. ******************************************************************************/ ! extern void cleanup() { /* Close all open file descriptors. */ ! if (close(fd) == -1) { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, ! strerror(errno)); } ! /* Remove tmp dir and all files in it */ ! tst_rmdir(); /* Exit with appropriate return code. */ *************** *** 169,173 **** } - /***************************************************************************** * Performs all one time setup for this test. This function is --- 165,168 ---- *************** *** 176,183 **** ******************************************************************************/ ! void ! setup() { - /* Create temporary directories */ TEST_PAUSE; --- 171,176 ---- ******************************************************************************/ ! void setup() { /* Create temporary directories */ TEST_PAUSE; *************** *** 185,199 **** tst_tmpdir(); ! sprintf(fname,"tfile_sparse_%d",getpid()); ! if ((fd = open(fname, O_RDWR|O_CREAT, 0700)) == -1 ) ! { ! tst_brkm(TBROK, cleanup, "Unable to open %s for read/write. Error:%d, %s\n", \ ! fname, errno, strerror(errno)); } get_blocksize(fd); populate_file(); ! file_seek(BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS); //create holes populate_file(); ! file_seek(0); //Rewind } --- 178,192 ---- tst_tmpdir(); ! sprintf(fname, "tfile_sparse_%d", getpid()); ! if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { ! tst_brkm(TBROK, cleanup, ! "Unable to open %s for read/write. Error:%d, %s\n", ! fname, errno, strerror(errno)); } get_blocksize(fd); populate_file(); ! file_seek(BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS); /* create holes */ populate_file(); ! file_seek(0); /* Rewind */ } *************** *** 201,215 **** * Gets the block size for the file system ******************************************************************************/ ! void ! get_blocksize(int fd) { ! struct stat file_stat; ! if( fstat(fd, &file_stat) < 0 ) ! tst_resm(TFAIL, "fstat failed while getting block_size errno=%d : %s", ! TEST_ERRNO, strerror(TEST_ERRNO)); ! block_size = (int) file_stat.st_blksize; ! buf_size = block_size; } --- 194,208 ---- * Gets the block size for the file system ******************************************************************************/ ! void get_blocksize(int fd) { ! struct stat file_stat; ! if (fstat(fd, &file_stat) < 0) ! tst_resm(TFAIL, ! "fstat failed while getting block_size errno=%d : %s", ! TEST_ERRNO, strerror(TEST_ERRNO)); ! block_size = (int)file_stat.st_blksize; ! buf_size = block_size; } *************** *** 217,233 **** * Create a Hole in the file ******************************************************************************/ ! void ! file_seek(off_t offset) { offset *= block_size; ! lseek(fd,offset,SEEK_SET); } - /***************************************************************************** * Writes data into the file ******************************************************************************/ ! void ! populate_file() { char buf[buf_size + 1]; --- 210,223 ---- * Create a Hole in the file ******************************************************************************/ ! void file_seek(off_t offset) { offset *= block_size; ! lseek(fd, offset, SEEK_SET); } /***************************************************************************** * Writes data into the file ******************************************************************************/ ! void populate_file() { char buf[buf_size + 1]; *************** *** 235,253 **** int blocks; int data; ! for (blocks = 0; blocks < BLOCKS_WRITTEN ; blocks++) ! { for (index = 0; index < buf_size; index++) ! buf[index] = 'A' + (index % 26); ! buf[buf_size]='\0'; ! if (( data = write(fd, buf, buf_size)) < 0 ) ! { ! tst_brkm(TBROK, cleanup, "Unable to write to %s. Error: %d, %s", \ ! fname,errno, strerror(errno)); } } } - - /***************************************************************************** * Wraper function to call fallocate system call --- 225,240 ---- int blocks; int data; ! for (blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) { for (index = 0; index < buf_size; index++) ! buf[index] = 'A' + (index % 26); ! buf[buf_size] = '\0'; ! if ((data = write(fd, buf, buf_size)) < 0) { ! tst_brkm(TBROK, cleanup, ! "Unable to write to %s. Error: %d, %s", fname, ! errno, strerror(errno)); } } } /***************************************************************************** * Wraper function to call fallocate system call *************** *** 255,271 **** static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) { ! #if __WORDSIZE == 32 ! struct utsname buf; ! if ( uname(&buf) == 0 ){ ! if(!strcmp(buf.machine,"ppc64") || !strcmp(buf.machine,"x86_64")) ! return syscall(__NR_fallocate, fd, mode, (int)(offset>>32), (int)offset ,(int)(len>>32), (int)len); ! } ! else{ ! perror("uname:"); ! return -1; ! } ! #endif ! return syscall(__NR_fallocate, fd, mode, ! offset,len); } --- 242,259 ---- static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) { ! #if __WORDSIZE == 32 ! struct utsname buf; ! if (uname(&buf) == 0) { ! if (!strcmp(buf.machine, "ppc64") ! || !strcmp(buf.machine, "x86_64")) ! return syscall(__NR_fallocate, fd, mode, ! (int)(offset >> 32), (int)offset, ! (int)(len >> 32), (int)len); ! } else { ! perror("uname:"); ! return -1; ! } ! #endif ! return syscall(__NR_fallocate, fd, mode, offset, len); } *************** *** 273,279 **** * Main function that calls the system call with the appropriate parameters ******************************************************************************/ ! int ! main(int ac, /* number of command line parameters */ ! char **av) /* pointer to the array of the command line parameters. */ { int test_index = 0; --- 261,267 ---- * Main function that calls the system call with the appropriate parameters ******************************************************************************/ ! /* ac: number of command line parameters */ ! /* av: pointer to the array of the command line parameters */ ! int main(int ac, char **av) { int test_index = 0; *************** *** 281,288 **** char *msg; ! /*************************************************************** ! * parse standard options ! ***************************************************************/ ! if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); --- 269,276 ---- char *msg; ! /*************************************************************** ! * parse standard options ! ***************************************************************/ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); *************** *** 290,327 **** * either of x86, x86_64 or ppc architecture */ ! if ( !arch_support || (tst_kvercmp(2,6,23) < 0)) { ! tst_resm(TCONF," System doesn't support execution of the test"); exit(0); } ! /* perform global test setup, call setup() function. */ setup(); ! for (lc=0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count=0; ! for(test_index = 0 ; test_index < TST_TOTAL; test_index ++) ! { ! TEST(fallocate(fd, test_data[test_index].mode, ! test_data[test_index].offset * block_size, test_data[test_index].len * block_size)); ! /* check return code */ ! if ( TEST_RETURN != test_data[test_index].error ) { ! if ( TEST_ERRNO == EOPNOTSUPP ) { ! tst_resm( TCONF, " fallocate system call" \ ! " is not implemented"); ! cleanup(); /* calls tst_exit */ } ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, "fallocate(%s, %d, %lld, %lld) Failed, errno=%d : %s", ! fname,test_data[test_index].mode, test_data[test_index].offset * block_size, ! test_data[test_index].len * block_size, TEST_ERRNO, strerror(TEST_ERRNO)); ! } else { ! if ( STD_FUNCTIONAL_TEST ) { ! /* No Verification test, yet... */ ! tst_resm(TPASS, "fallocate(%s, %d, %lld, %lld) returned %d ", ! fname,test_data[test_index].mode, test_data[test_index].offset * block_size, ! test_data[test_index].len * block_size, TEST_RETURN); } ! } } } --- 278,327 ---- * either of x86, x86_64 or ppc architecture */ ! if (!arch_support || (tst_kvercmp(2, 6, 23) < 0)) { ! tst_resm(TCONF, " System doesn't support execution of the test"); exit(0); } ! /* perform global test setup, call setup() function */ setup(); ! for (lc = 0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping */ ! Tst_count = 0; ! for (test_index = 0; test_index < TST_TOTAL; test_index++) { ! TEST(fallocate ! (fd, test_data[test_index].mode, ! test_data[test_index].offset * block_size, ! test_data[test_index].len * block_size)); ! /* check return code */ ! if (TEST_RETURN != test_data[test_index].error) { ! if (TEST_ERRNO == EOPNOTSUPP) { ! tst_resm(TCONF, ! " fallocate system call" ! " is not implemented"); ! cleanup(); /* calls tst_exit */ } ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, ! "fallocate(%s, %d, %lld, %lld) Failed, errno=%d : %s", ! fname, test_data[test_index].mode, ! test_data[test_index].offset * ! block_size, ! test_data[test_index].len * block_size, ! TEST_ERRNO, strerror(TEST_ERRNO)); ! } else { ! if (STD_FUNCTIONAL_TEST) { ! /* No Verification test, yet... */ ! tst_resm(TPASS, ! "fallocate(%s, %d, %lld, %lld) returned %d ", ! fname, ! test_data[test_index].mode, ! test_data[test_index].offset * ! block_size, ! test_data[test_index].len * ! block_size, TEST_RETURN); ! } ! } } } Index: fallocate01.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/fallocate/fallocate01.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** fallocate01.c 20 Mar 2009 09:28:11 -0000 1.7 --- fallocate01.c 23 Mar 2009 13:35:40 -0000 1.8 *************** *** 1,90 **** - /****************************************************************************** ! * fallocate01.c * Mon Dec 24 2007 ! * Copyright (c) International Business Machines Corp., 2007 * Emali : sha...@in... ******************************************************************************/ - /*************************************************************************** ! * 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. ! ***************************************************************************/ ! /***************************************************************************** ! * ! * OS Test - International Business Machines Corp. 2007. ! * ! * TEST IDENTIFIER : fallocate01 ! * ! * EXECUTED BY : anyone ! * ! * TEST TITLE : Basic test for fallocate() ! * ! * TEST CASE TOTAL : 2 ! * ! * CPU ARCHITECTURES : PPC,X86, X86_64 ! * ! * AUTHOR : Sharyathi Nagesh ! * ! * CO-PILOT : ! * ! * DATE STARTED : 24/12/2007 ! * ! * TEST CASES ! * (Working of fallocate under 2 modes) ! * 1) DEFAULT 2)FALLOC_FL_KEEP_SIZE ! * ! * INPUT SPECIFICATIONS ! * No input needs to be specified ! * fallocate() in puts are generated randomly ! * ! * OUTPUT SPECIFICATIONS ! * Output describing whether test cases passed or failed. ! * ! * ENVIRONMENTAL NEEDS ! * Test Needs to be executed on file system supporting ext4 ! * LTP {TMP} Needs to be set to such a folder ! * ! * SPECIAL PROCEDURAL REQUIREMENTS ! * None ! * ! * DETAILED DESCRIPTION ! * This is a test case for fallocate() system call. ! * This test suite tests basic working of fallocate under different modes ! * It trys to fallocate memory blocks and write into that block ! * ! * Total 2 Test Cases :- ! * (1) Test Case for DEFAULT MODE ! * (2) Test Case for FALLOC_FL_KEEP_SIZE ! * ! * Setup: ! * Setup file on which fallocate is to be called ! * Set up 2 files for each mode ! * ! * Test: ! * Loop if the proper options are given. ! * Execute system call ! * Check return code, if system call did fail ! * lseek to some random location with in allocate block ! * write data into the locattion Report if any error encountered ! * PASS the test otherwise ! * ! * Cleanup: ! * Cleanup the temporary folder ! * *************************************************************************/ --- 1,87 ---- /****************************************************************************** ! * fallocate01.c * Mon Dec 24 2007 ! * Copyright (c) International Business Machines Corp., 2007 * Emali : sha...@in... ******************************************************************************/ /*************************************************************************** ! * 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. ! ***************************************************************************/ /***************************************************************************** ! * ! * OS Test - International Business Machines Corp. 2007. ! * ! * TEST IDENTIFIER : fallocate01 ! * ! * EXECUTED BY : anyone ! * ! * TEST TITLE : Basic test for fallocate() ! * ! * TEST CASE TOTAL : 2 ! * ! * CPU ARCHITECTURES : PPC,X86, X86_64 ! * ! * AUTHOR : Sharyathi Nagesh ! * ! * CO-PILOT : ! * ! * DATE STARTED : 24/12/2007 ! * ! * TEST CASES ! * (Working of fallocate under 2 modes) ! * 1) DEFAULT 2)FALLOC_FL_KEEP_SIZE ! * ! * INPUT SPECIFICATIONS ! * No input needs to be specified ! * fallocate() in puts are generated randomly ! * ! * OUTPUT SPECIFICATIONS ! * Output describing whether test cases passed or failed. ! * ! * ENVIRONMENTAL NEEDS ! * Test Needs to be executed on file system supporting ext4 ! * LTP {TMP} Needs to be set to such a folder ! * ! * SPECIAL PROCEDURAL REQUIREMENTS ! * None ! * ! * DETAILED DESCRIPTION ! * This is a test case for fallocate() system call. ! * This test suite tests basic working of fallocate under different modes ! * It trys to fallocate memory blocks and write into that block ! * ! * Total 2 Test Cases :- ! * (1) Test Case for DEFAULT MODE ! * (2) Test Case for FALLOC_FL_KEEP_SIZE ! * ! * Setup: ! * Setup file on which fallocate is to be called ! * Set up 2 files for each mode ! * ! * Test: ! * Loop if the proper options are given. ! * Execute system call ! * Check return code, if system call did fail ! * lseek to some random location with in allocate block ! * write data into the locattion Report if any error encountered ! * PASS the test otherwise ! * ! * Cleanup: ! * Cleanup the temporary folder ! * *************************************************************************/ *************** *** 106,157 **** #include "linux_syscall_numbers.h" - #define BLOCKS_WRITTEN 12 #ifndef __NR_fallocate ! # define __NR_fallocate -1 //Dummy Value ! int arch_support = 0; //Architecure is not supported #else ! int arch_support = 1; //Architecture is supported #endif - /* Local Function */ static inline long fallocate(); void get_blocksize(int); void populate_files(int fd); ! void runtest(int,int,loff_t); /* Extern Global Variables */ ! extern int Tst_count; /* counter for tst_xxx routines. */ /* Global Variables */ ! char *TCID = "fallocate01"; /* test program identifier. */ ! char fname_mode1[255], fname_mode2[255]; /* Files used for testing */ int fd_mode1, fd_mode2; ! int TST_TOTAL ; int block_size; int buf_size; /****************************************************************************** ! * Performs all one time clean up for this test on successful * completion, premature exit or failure. Closes all temporary ! * files, removes all temporary directories exits the test with ! * appropriate return code by calling tst_exit() function. ******************************************************************************/ ! extern void ! cleanup() { /* Close all open file descriptors. */ ! if(close(fd_mode1) == -1) ! { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", ! fname_mode1, errno, strerror(errno)); } ! if(close(fd_mode2) == -1) ! { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", ! fname_mode2, errno, strerror(errno)); } //remove tem directory and all the files in it --- 103,149 ---- #include "linux_syscall_numbers.h" #define BLOCKS_WRITTEN 12 #ifndef __NR_fallocate ! # define __NR_fallocate -1 //Dummy Value ! int arch_support = 0; /* Architecure is not supported */ #else ! int arch_support = 1; /* Architecture is supported */ #endif /* Local Function */ static inline long fallocate(); void get_blocksize(int); void populate_files(int fd); ! void runtest(int, int, loff_t); /* Extern Global Variables */ ! extern int Tst_count; /* counter for tst_xxx routines */ /* Global Variables */ ! char *TCID = "fallocate01"; /* test program identifier */ ! char fname_mode1[255], fname_mode2[255]; /* Files used for testing */ int fd_mode1, fd_mode2; ! int TST_TOTAL; int block_size; int buf_size; /****************************************************************************** ! * Performs all one time clean up for this test on successful * completion, premature exit or failure. Closes all temporary ! * files, removes all temporary directories exits the test with ! * appropriate return code by calling tst_exit() function. ******************************************************************************/ ! extern void cleanup() { /* Close all open file descriptors. */ ! if (close(fd_mode1) == -1) { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname_mode1, ! errno, strerror(errno)); } ! if (close(fd_mode2) == -1) { ! tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname_mode2, ! errno, strerror(errno)); } //remove tem directory and all the files in it *************** *** 161,165 **** } - /***************************************************************************** * Performs all one time setup for this test. This function is --- 153,156 ---- *************** *** 167,174 **** * that may be used in the course of this test ******************************************************************************/ ! void ! setup() { - /* Create temporary directories */ TEST_PAUSE; --- 158,163 ---- * that may be used in the course of this test ******************************************************************************/ ! void setup() { /* Create temporary directories */ TEST_PAUSE; *************** *** 176,184 **** tst_tmpdir(); ! sprintf(fname_mode1,"tfile_mode1_%d",getpid()); ! if ((fd_mode1 = open(fname_mode1, O_RDWR|O_CREAT, 0700)) == -1 ) ! { ! tst_brkm(TBROK, cleanup, "Unable to open %s for read/write. Error:%d, %s\n", \ ! fname_mode1, errno, strerror(errno)); } --- 165,173 ---- tst_tmpdir(); ! sprintf(fname_mode1, "tfile_mode1_%d", getpid()); ! if ((fd_mode1 = open(fname_mode1, O_RDWR | O_CREAT, 0700)) == -1) { ! tst_brkm(TBROK, cleanup, ! "Unable to open %s for read/write. Error:%d, %s\n", ! fname_mode1, errno, strerror(errno)); } *************** *** 186,197 **** populate_files(fd_mode1); ! sprintf(fname_mode2,"tfile_mode2_%d",getpid()); ! if ((fd_mode2 = open(fname_mode2, O_RDWR|O_CREAT, 0700)) == -1 ) ! { ! tst_brkm(TBROK, cleanup, "Unable to open %s for read/write. Error:%d, %s\n", \ ! fname_mode2, errno, strerror(errno)); } populate_files(fd_mode2); - } --- 175,185 ---- populate_files(fd_mode1); ! sprintf(fname_mode2, "tfile_mode2_%d", getpid()); ! if ((fd_mode2 = open(fname_mode2, O_RDWR | O_CREAT, 0700)) == -1) { ! tst_brkm(TBROK, cleanup, ! "Unable to open %s for read/write. Error:%d, %s\n", ! fname_mode2, errno, strerror(errno)); } populate_files(fd_mode2); } *************** *** 199,220 **** * Gets the block size for the file system ******************************************************************************/ ! void ! get_blocksize(int fd) { ! struct stat file_stat; ! if( fstat(fd, &file_stat) < 0 ) ! tst_resm(TFAIL, "fstat failed while getting block_size errno=%d : %s", ! TEST_ERRNO, strerror(TEST_ERRNO)); ! block_size = (int) file_stat.st_blksize; ! buf_size = block_size; } /***************************************************************************** * Writes data into the file ******************************************************************************/ ! void ! populate_files(int fd) { char buf[buf_size + 1]; --- 187,208 ---- * Gets the block size for the file system ******************************************************************************/ ! void get_blocksize(int fd) { ! struct stat file_stat; ! if (fstat(fd, &file_stat) < 0) ! tst_resm(TFAIL, ! "fstat failed while getting block_size errno=%d : %s", ! TEST_ERRNO, strerror(TEST_ERRNO)); ! block_size = (int)file_stat.st_blksize; ! buf_size = block_size; } + /***************************************************************************** * Writes data into the file ******************************************************************************/ ! void populate_files(int fd) { char buf[buf_size + 1]; *************** *** 224,252 **** 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); ! buf[buf_size]='\0'; ! if (( data = write(fd, buf, buf_size)) < 0 ) ! { ! tst_brkm(TBROK, cleanup, "Unable to write to %s. Error: %d, %s", \ ! fname,errno, strerror(errno)); } } } ! ! int ! main(int ac, /* number of command line parameters */ ! char **av) /* pointer to the array of the command line parameters. */ { int fd; ! enum {DEFAULT, FALLOC_FL_KEEP_SIZE} mode; loff_t expected_size; int lc; --- 212,238 ---- 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); ! buf[buf_size] = '\0'; ! if ((data = write(fd, buf, buf_size)) < 0) { ! tst_brkm(TBROK, cleanup, ! "Unable to write to %s. Error: %d, %s", fname, ! errno, strerror(errno)); } } } ! /* ac: number of command line parameters */ ! /* av: pointer to the array of the command line parameters */ ! int main(int ac, char **av) { int fd; ! enum { DEFAULT, FALLOC_FL_KEEP_SIZE } mode; loff_t expected_size; int lc; *************** *** 255,294 **** TST_TOTAL = 2; ! ! /*************************************************************** ! * parse standard options ! ***************************************************************/ ! if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); - /* This test needs kernel version > 2.6.23 and * either of x86, x86_64 or ppc architecture */ ! if ( !arch_support || (tst_kvercmp(2,6,23) < 0)) { ! tst_resm(TCONF," System doesn't support execution of the test"); exit(0); } - /* perform global test setup, call setup() function. */ setup(); ! for (lc=0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count=0; ! ! for ( mode = DEFAULT; mode <= FALLOC_FL_KEEP_SIZE; mode++) ! { ! switch(mode){ ! case DEFAULT: fd = fd_mode1; ! expected_size = BLOCKS_WRITTEN * block_size + block_size; break; ! case FALLOC_FL_KEEP_SIZE: fd = fd_mode2; expected_size = BLOCKS_WRITTEN * block_size; break; ! } runtest(mode, fd, expected_size); } --- 241,279 ---- TST_TOTAL = 2; ! /*************************************************************** ! * parse standard options ! ***************************************************************/ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /* This test needs kernel version > 2.6.23 and * either of x86, x86_64 or ppc architecture */ ! if (!arch_support || (tst_kvercmp(2, 6, 23) < 0)) { ! tst_resm(TCONF, ! " System doesn't support execution of the test"); exit(0); } /* perform global test setup, call setup() function. */ setup(); + for (lc = 0; TEST_LOOPING(lc); lc++) { + /* reset Tst_count in case we are looping. */ + Tst_count = 0; ! for (mode = DEFAULT; mode <= FALLOC_FL_KEEP_SIZE; mode++) { ! switch (mode) { ! case DEFAULT: ! fd = fd_mode1; ! expected_size = ! BLOCKS_WRITTEN * block_size + block_size; break; ! case FALLOC_FL_KEEP_SIZE: ! fd = fd_mode2; expected_size = BLOCKS_WRITTEN * block_size; break; ! } runtest(mode, fd, expected_size); } *************** *** 299,303 **** } - /***************************************************************************** * Wraper function to call fallocate system call --- 284,287 ---- *************** *** 305,321 **** static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) { ! #if __WORDSIZE == 32 ! struct utsname buf; ! if ( uname(&buf) == 0 ){ ! if(!strcmp(buf.machine,"ppc64") || !strcmp(buf.machine,"x86_64")) ! return syscall(__NR_fallocate, fd, mode, (int)(offset>>32), (int)offset ,(int)(len>>32), (int)len); ! } ! else{ ! perror("uname:"); ! return -1; ! } ! #endif ! return syscall(__NR_fal... [truncated message content] |