subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 2 | * fallocate01.c |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 3 | * Mon Dec 24 2007 |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 4 | * Copyright (c) International Business Machines Corp., 2007 |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 5 | * Emali : sharyathi@in.ibm.com |
| 6 | ******************************************************************************/ |
| 7 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 8 | /*************************************************************************** |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Library General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | ***************************************************************************/ |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 23 | |
| 24 | /***************************************************************************** |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 25 | * |
| 26 | * OS Test - International Business Machines Corp. 2007. |
| 27 | * |
| 28 | * TEST IDENTIFIER : fallocate01 |
| 29 | * |
| 30 | * EXECUTED BY : anyone |
| 31 | * |
| 32 | * TEST TITLE : Basic test for fallocate() |
| 33 | * |
| 34 | * TEST CASE TOTAL : 2 |
| 35 | * |
| 36 | * CPU ARCHITECTURES : PPC,X86, X86_64 |
| 37 | * |
| 38 | * AUTHOR : Sharyathi Nagesh |
| 39 | * |
| 40 | * CO-PILOT : |
| 41 | * |
| 42 | * DATE STARTED : 24/12/2007 |
| 43 | * |
| 44 | * TEST CASES |
| 45 | * (Working of fallocate under 2 modes) |
| 46 | * 1) DEFAULT 2)FALLOC_FL_KEEP_SIZE |
| 47 | * |
| 48 | * INPUT SPECIFICATIONS |
| 49 | * No input needs to be specified |
| 50 | * fallocate() in puts are generated randomly |
| 51 | * |
| 52 | * OUTPUT SPECIFICATIONS |
| 53 | * Output describing whether test cases passed or failed. |
| 54 | * |
| 55 | * ENVIRONMENTAL NEEDS |
| 56 | * Test Needs to be executed on file system supporting ext4 |
| 57 | * LTP {TMP} Needs to be set to such a folder |
| 58 | * |
| 59 | * SPECIAL PROCEDURAL REQUIREMENTS |
| 60 | * None |
| 61 | * |
| 62 | * DETAILED DESCRIPTION |
| 63 | * This is a test case for fallocate() system call. |
| 64 | * This test suite tests basic working of fallocate under different modes |
| 65 | * It trys to fallocate memory blocks and write into that block |
| 66 | * |
| 67 | * Total 2 Test Cases :- |
| 68 | * (1) Test Case for DEFAULT MODE |
| 69 | * (2) Test Case for FALLOC_FL_KEEP_SIZE |
| 70 | * |
| 71 | * Setup: |
| 72 | * Setup file on which fallocate is to be called |
| 73 | * Set up 2 files for each mode |
| 74 | * |
| 75 | * Test: |
| 76 | * Loop if the proper options are given. |
| 77 | * Execute system call |
| 78 | * Check return code, if system call did fail |
| 79 | * lseek to some random location with in allocate block |
| 80 | * write data into the locattion Report if any error encountered |
| 81 | * PASS the test otherwise |
| 82 | * |
| 83 | * Cleanup: |
| 84 | * Cleanup the temporary folder |
| 85 | * |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 86 | *************************************************************************/ |
| 87 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 88 | #include <stdio.h> |
| 89 | #include <stdlib.h> |
Garrett Cooper | 187f251 | 2010-12-19 18:07:59 -0800 | [diff] [blame] | 90 | #include <endian.h> |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 91 | #include <errno.h> |
| 92 | #include <sys/stat.h> |
| 93 | #include <sys/types.h> |
| 94 | #include <fcntl.h> |
| 95 | #include <sys/syscall.h> |
| 96 | #include <unistd.h> |
| 97 | #include <error.h> |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 98 | #include <inttypes.h> |
subrata_modak | df18bd0 | 2008-02-19 09:32:47 +0000 | [diff] [blame] | 99 | #include <sys/utsname.h> |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 100 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 101 | #include "test.h" |
| 102 | #include "usctest.h" |
Zeng Linggang | 7148254 | 2014-01-22 13:55:17 +0800 | [diff] [blame^] | 103 | #include "fallocate.h" |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 104 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 105 | #define BLOCKS_WRITTEN 12 |
| 106 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 107 | void get_blocksize(int); |
| 108 | void populate_files(int fd); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | void runtest(int, int, loff_t); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 110 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 111 | char *TCID = "fallocate01"; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 112 | char fname_mode1[255], fname_mode2[255]; /* Files used for testing */ |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 113 | int fd_mode1, fd_mode2; |
Garrett Cooper | 8dca422 | 2010-12-18 03:57:35 -0800 | [diff] [blame] | 114 | int TST_TOTAL = 2; |
| 115 | loff_t block_size; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 116 | int buf_size; |
| 117 | |
| 118 | /****************************************************************************** |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | * Performs all one time clean up for this test on successful |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 120 | * completion, premature exit or failure. Closes all temporary |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | * files, removes all temporary directories exits the test with |
| 122 | * appropriate return code by calling tst_exit() function. |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 123 | ******************************************************************************/ |
Garrett Cooper | 8dca422 | 2010-12-18 03:57:35 -0800 | [diff] [blame] | 124 | void cleanup() |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 125 | { |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 126 | |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 127 | if (close(fd_mode1) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 128 | tst_resm(TWARN | TERRNO, "close(%s) failed", fname_mode1); |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 129 | if (close(fd_mode2) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 130 | tst_resm(TWARN | TERRNO, "close(%s) failed", fname_mode2); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 131 | tst_rmdir(); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 132 | } |
| 133 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 134 | /***************************************************************************** |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 135 | * Performs all one time setup for this test. This function is |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 136 | * used to create temporary dirs and temporary files |
| 137 | * that may be used in the course of this test |
| 138 | ******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | void setup() |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 140 | { |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 141 | /* Create temporary directories */ |
| 142 | TEST_PAUSE; |
| 143 | |
| 144 | tst_tmpdir(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 145 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 146 | sprintf(fname_mode1, "tfile_mode1_%d", getpid()); |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 147 | fd_mode1 = open(fname_mode1, O_RDWR | O_CREAT, 0700); |
| 148 | if (fd_mode1 == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_RDWR) failed", |
| 150 | fname_mode1); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 151 | get_blocksize(fd_mode1); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 152 | populate_files(fd_mode1); |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 153 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | sprintf(fname_mode2, "tfile_mode2_%d", getpid()); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 155 | fd_mode2 = open(fname_mode2, O_RDWR | O_CREAT, 0700); |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 156 | if (fd_mode2 == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 157 | tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_RDWR) failed", |
| 158 | fname_mode2); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 159 | populate_files(fd_mode2); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /***************************************************************************** |
| 163 | * Gets the block size for the file system |
| 164 | ******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | void get_blocksize(int fd) |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 166 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 167 | struct stat file_stat; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 168 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 169 | if (fstat(fd, &file_stat) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 170 | tst_resm(TFAIL | TERRNO, |
| 171 | "fstat failed while getting block_size"); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 172 | |
Garrett Cooper | 8dca422 | 2010-12-18 03:57:35 -0800 | [diff] [blame] | 173 | block_size = file_stat.st_blksize; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 174 | buf_size = block_size; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 175 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 176 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 177 | /***************************************************************************** |
| 178 | * Writes data into the file |
| 179 | ******************************************************************************/ |
| 180 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 181 | void populate_files(int fd) |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 182 | { |
| 183 | char buf[buf_size + 1]; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 184 | int index; |
| 185 | int blocks; |
| 186 | int data; |
| 187 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 188 | for (blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) { |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 189 | for (index = 0; index < buf_size; index++) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | buf[index] = 'A' + (index % 26); |
| 191 | buf[buf_size] = '\0'; |
Garrett Cooper | 8dca422 | 2010-12-18 03:57:35 -0800 | [diff] [blame] | 192 | if ((data = write(fd, buf, buf_size)) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 193 | tst_brkm(TBROK | TERRNO, cleanup, "write failed"); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 197 | int main(int ac, char **av) |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 198 | { |
| 199 | int fd; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 200 | enum { DEFAULT, FALLOC_FL_KEEP_SIZE } mode; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 201 | loff_t expected_size; |
| 202 | int lc; |
| 203 | char *msg; |
| 204 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 205 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 206 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 207 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 208 | setup(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 209 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 210 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 211 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 212 | tst_count = 0; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 213 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 214 | for (mode = DEFAULT; mode <= FALLOC_FL_KEEP_SIZE; mode++) { |
| 215 | switch (mode) { |
| 216 | case DEFAULT: |
| 217 | fd = fd_mode1; |
| 218 | expected_size = |
| 219 | BLOCKS_WRITTEN * block_size + block_size; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 220 | break; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 221 | case FALLOC_FL_KEEP_SIZE: |
| 222 | fd = fd_mode2; |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 223 | expected_size = BLOCKS_WRITTEN * block_size; |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 224 | break; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 225 | } |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 226 | runtest(mode, fd, expected_size); |
| 227 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 228 | } |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 229 | |
| 230 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 231 | tst_exit(); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 232 | } |
| 233 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 234 | /***************************************************************************** |
| 235 | * Calls the system call, with appropriate parameters and writes data |
| 236 | ******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 237 | void runtest(int mode, int fd, loff_t expected_size) |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 238 | { |
| 239 | loff_t offset; |
| 240 | loff_t len = block_size; |
| 241 | loff_t write_offset, lseek_offset; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 242 | offset = lseek(fd, 0, SEEK_END); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 243 | struct stat file_stat; |
| 244 | errno = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 245 | |
| 246 | TEST(fallocate(fd, mode, offset, len)); |
| 247 | /* check return code */ |
| 248 | if (TEST_RETURN != 0) { |
vapier | 6dd41a3 | 2009-11-04 16:31:05 +0000 | [diff] [blame] | 249 | if (TEST_ERRNO == EOPNOTSUPP || TEST_ERRNO == ENOSYS) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 250 | tst_brkm(TCONF, cleanup, |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 251 | "fallocate system call is not implemented"); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 252 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 253 | TEST_ERROR_LOG(TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 254 | tst_resm(TFAIL | TTERRNO, |
| 255 | "fallocate(%d, %d, %" PRId64 ", %" PRId64 ") failed", |
vapier | 4a5373f | 2009-08-28 12:40:49 +0000 | [diff] [blame] | 256 | fd, mode, offset, len); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 257 | return; |
| 258 | } else { |
| 259 | if (STD_FUNCTIONAL_TEST) { |
| 260 | /* No Verification test, yet... */ |
| 261 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 262 | "fallocate(%d, %d, %" PRId64 ", %" PRId64 |
| 263 | ") returned %ld", fd, mode, offset, len, |
| 264 | TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 265 | } |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 266 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 267 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 268 | if (fstat(fd, &file_stat) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 269 | tst_resm(TFAIL | TERRNO, "fstat failed after fallocate()"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 270 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 271 | if (file_stat.st_size != expected_size) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 272 | tst_resm(TFAIL | TTERRNO, |
| 273 | "fstat test fails on fallocate (%d, %d, %" PRId64 ", %" |
| 274 | PRId64 ") Failed on mode", fd, mode, offset, len); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 275 | |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 276 | write_offset = random() % len; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 277 | lseek_offset = lseek(fd, write_offset, SEEK_CUR); |
| 278 | if (lseek_offset != offset + write_offset) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 279 | tst_resm(TFAIL | TTERRNO, |
| 280 | "lseek fails in fallocate(%d, %d, %" PRId64 ", %" |
| 281 | PRId64 ") failed on mode", fd, mode, offset, len); |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 284 | //Write a character to file at random location |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 285 | TEST(write(fd, "A", 1)); |
| 286 | /* check return code */ |
| 287 | if (TEST_RETURN == -1) { |
| 288 | TEST_ERROR_LOG(TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 289 | tst_resm(TFAIL | TTERRNO, |
| 290 | "write fails in fallocate(%d, %d, %" PRId64 ", %" |
| 291 | PRId64 ") failed", fd, mode, offset, len); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 292 | } else { |
| 293 | if (STD_FUNCTIONAL_TEST) { |
| 294 | /* No Verification test, yet... */ |
| 295 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 296 | "write operation on fallocated(%d, %d, %" |
| 297 | PRId64 ", %" PRId64 ") returned %ld", fd, mode, |
| 298 | offset, len, TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 299 | } |
subrata_modak | 122c603 | 2008-01-08 11:01:11 +0000 | [diff] [blame] | 300 | } |
Garrett Cooper | 187f251 | 2010-12-19 18:07:59 -0800 | [diff] [blame] | 301 | } |