robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 1 | /* IBM Corporation */ |
| 2 | /* 01/03/2003 Port to LTP avenkat@us.ibm.com */ |
| 3 | /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ |
| 4 | |
| 5 | /* |
| 6 | * Copyright (c) International Business Machines Corp., 2003 |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 16 | * the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * Mmap a sparse file and then fiddle with the hole in the middle. |
| 25 | * Then check the file contents. |
| 26 | * |
| 27 | * Usage: mmapstress07 filename holesize e_pageskip sparseoff |
| 28 | * EXAMPLE: mmapstress07 myfile 4096 1 4096 |
| 29 | */ |
| 30 | #include <stdio.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/mman.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <unistd.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <signal.h> |
| 37 | #include <errno.h> |
| 38 | #include <sys/wait.h> |
| 39 | #include "test.h" |
| 40 | #include "usctest.h" |
| 41 | #define FAILED 0 |
| 42 | #define PASSED 1 |
| 43 | |
| 44 | static char *tmpname; |
| 45 | |
| 46 | #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", \ |
| 47 | argv[0], errno) |
| 48 | |
| 49 | #define CLEANERROR(M) (void)close(rofd); \ |
| 50 | (void)close(rwfd); \ |
| 51 | (void)unlink(tmpname); \ |
| 52 | ERROR(M) |
| 53 | |
| 54 | #define CATCH_SIG(SIG) \ |
| 55 | if (sigaction(SIG, &sa, 0) == -1) { \ |
| 56 | ERROR("couldn't catch signal " #SIG); \ |
| 57 | exit(1); \ |
| 58 | } |
| 59 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | extern time_t time(time_t *); |
| 61 | extern char *ctime(const time_t *); |
| 62 | extern void exit(int); |
| 63 | static int checkchars(int fd, char val, int n); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 64 | |
| 65 | char *TCID = "mmapstress07"; |
| 66 | |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 67 | int local_flag = PASSED; |
| 68 | int block_number; |
| 69 | FILE *temp; |
| 70 | int TST_TOTAL = 1; |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 71 | |
| 72 | int anyfail(); |
| 73 | void ok_exit(); |
| 74 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 75 | /*ARGSUSED*/ static |
| 76 | void cleanup(int sig) |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 77 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 78 | /* |
| 79 | * Don't check error codes - we could be signaled before the file is |
| 80 | * created. |
| 81 | */ |
| 82 | (void)unlink(tmpname); |
| 83 | exit(1); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 86 | int main(int argc, char **argv) |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 87 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 88 | size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE); |
| 89 | caddr_t mapaddr; |
| 90 | time_t t; |
| 91 | int rofd, rwfd, i; |
| 92 | struct sigaction sa; |
| 93 | int e_pageskip; |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 94 | #ifdef LARGE_FILE |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | off64_t holesize; |
| 96 | off64_t sparseoff; |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 97 | #else /* LARGE_FILE */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 98 | off_t holesize; |
| 99 | off_t sparseoff; |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 100 | #endif /* LARGE_FILE */ |
| 101 | |
| 102 | (void)time(&t); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | // (void)printf("%s: Started %s", argv[0], ctime(&t)); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 104 | /* Test fsync & mmap over a hole in a sparse file & extend fragment */ |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 105 | if (argc < 2 || argc > 5) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 106 | fprintf(stderr, |
| 107 | "Usage: mmapstress07 filename holesize e_pageskip sparseoff\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 108 | /***** ** LTP Port 02/01/03 ** **** */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 109 | fprintf(stderr, |
| 110 | "\t*holesize should be a multiple of pagesize\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 111 | fprintf(stderr, "\t*e_pageskip should be 1 always \n"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | fprintf(stderr, |
| 113 | "\t*sparseoff should be a multiple of pagesize\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 114 | fprintf(stderr, "Example: mmapstress07 myfile 4096 1 8192\n"); |
| 115 | /***** ** ****** ***** ***** ** 02/01/03 */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 116 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 117 | } |
| 118 | tst_tmpdir(); |
| 119 | tmpname = argv[1]; |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 120 | |
| 121 | if (argc >= 3) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 122 | #ifdef LARGE_FILE |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 123 | holesize = atoll(argv[2]); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 124 | #else /* LARGE_FILE */ |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 125 | holesize = atoi(argv[2]); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 126 | #endif /* LARGE_FILE */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | } else |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 128 | holesize = pagesize; |
| 129 | |
| 130 | if (argc >= 4) |
| 131 | e_pageskip = atoi(argv[3]); |
| 132 | else |
| 133 | e_pageskip = 1; |
| 134 | |
| 135 | if (argc >= 5) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 136 | #ifdef LARGE_FILE |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 137 | sparseoff = atoll(argv[4]); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 138 | #else /* LARGE_FILE */ |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 139 | sparseoff = atoi(argv[4]); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 140 | #endif /* LARGE_FILE */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 141 | } else |
| 142 | sparseoff = pagesize * 2; |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 143 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | sa.sa_handler = cleanup; |
| 145 | sa.sa_flags = 0; |
| 146 | if (sigemptyset(&sa.sa_mask)) { |
| 147 | ERROR("sigemptyset failed"); |
| 148 | return 1; |
| 149 | } |
| 150 | CATCH_SIG(SIGINT); |
| 151 | CATCH_SIG(SIGQUIT); |
| 152 | CATCH_SIG(SIGTERM); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 153 | #ifdef LARGE_FILE |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 154 | if ((rofd = open64(tmpname, O_RDONLY | O_CREAT, 0777)) == -1) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 155 | #else /* LARGE_FILE */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 156 | if ((rofd = open(tmpname, O_RDONLY | O_CREAT, 0777)) == -1) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 157 | #endif /* LARGE_FILE */ |
| 158 | ERROR("couldn't reopen rofd for reading"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 159 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 160 | } |
| 161 | #ifdef LARGE_FILE |
| 162 | if ((rwfd = open64(tmpname, O_RDWR)) == -1) { |
| 163 | #else /* LARGE_FILE */ |
| 164 | if ((rwfd = open(tmpname, O_RDWR)) == -1) { |
| 165 | #endif /* LARGE_FILE */ |
| 166 | CLEANERROR("couldn't reopen rwfd for read/write"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 167 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 168 | } |
| 169 | #ifdef LARGE_FILE |
| 170 | if (lseek64(rwfd, sparseoff, SEEK_SET) < 0) { |
| 171 | #else /* LARGE_FILE */ |
| 172 | if (lseek(rwfd, sparseoff, SEEK_SET) < 0) { |
| 173 | #endif /* LARGE_FILE */ |
| 174 | perror("lseek"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 175 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 176 | } |
| 177 | /* fill file with junk. */ |
| 178 | i = 0; |
| 179 | while (i < pagesize && write(rwfd, "a", 1) == 1) |
| 180 | i++; |
| 181 | if (i != pagesize) { |
| 182 | CLEANERROR("couldn't fill first part of file with junk"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 183 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 184 | } |
| 185 | #ifdef LARGE_FILE |
| 186 | if (lseek64(rwfd, holesize, SEEK_CUR) == -1) { |
| 187 | #else /* LARGE_FILE */ |
| 188 | if (lseek(rwfd, holesize, SEEK_CUR) == -1) { |
| 189 | #endif /* LARGE_FILE */ |
| 190 | CLEANERROR("couldn't create hole in file"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 191 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 192 | } |
| 193 | /* create fragment */ |
| 194 | i = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 195 | while (i < (pagesize >> 1) && write(rwfd, "b", 1) == 1) |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 196 | i++; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 197 | if (i != (pagesize >> 1)) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 198 | CLEANERROR("couldn't fill second part of file with junk"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 199 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 200 | } |
| 201 | /* At this point fd contains 1 page of a's, holesize bytes skipped, |
| 202 | * 1/2 page of b's. |
| 203 | */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 204 | |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 205 | #ifdef LARGE_FILE |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 206 | if ((mapaddr = mmap64((caddr_t) 0, pagesize * 2 + holesize, PROT_READ, |
| 207 | MAP_SHARED | MAP_FILE, rofd, |
| 208 | sparseoff)) == (caddr_t) - 1) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 209 | #else /* LARGE_FILE */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 210 | if ((mapaddr = mmap((caddr_t) 0, pagesize * 2 + holesize, PROT_READ, |
| 211 | MAP_SHARED | MAP_FILE, rofd, |
| 212 | sparseoff)) == (caddr_t) - 1) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 213 | #endif /* LARGE_FILE */ |
| 214 | CLEANERROR("mmap tmp file failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 215 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 216 | } |
subrata_modak | ab5bcc3 | 2008-12-12 10:40:15 +0000 | [diff] [blame] | 217 | /* fill out remainder of page + one more page to extend mmapped flag */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 218 | while (i < 2 * pagesize && write(rwfd, "c", 1) == 1) |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 219 | i++; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 220 | if (i != 2 * pagesize) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 221 | CLEANERROR("couldn't fill second part of file with junk"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 222 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 223 | } |
| 224 | /* fiddle with mmapped hole */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 225 | if (*(mapaddr + pagesize + (holesize >> 1)) != 0) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 226 | CLEANERROR("hole not filled with 0's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 227 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 228 | } |
| 229 | #ifdef LARGE_FILE |
| 230 | if (lseek64(rwfd, sparseoff + e_pageskip * pagesize, SEEK_SET) == -1) { |
| 231 | #else /* LARGE_FILE */ |
| 232 | if (lseek(rwfd, sparseoff + e_pageskip * pagesize, SEEK_SET) == -1) { |
| 233 | #endif /* LARGE_FILE */ |
| 234 | CLEANERROR("couldn't lseek back to put e's in hole"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 235 | anyfail(); /*LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 236 | } |
| 237 | i = 0; |
| 238 | while (i < pagesize && write(rwfd, "e", 1) == 1) |
| 239 | i++; |
| 240 | if (i != pagesize) { |
| 241 | CLEANERROR("couldn't part of hole with e's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 242 | anyfail(); /*LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 243 | } |
| 244 | if (fsync(rwfd) == -1) { |
| 245 | CLEANERROR("fsync failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 246 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 247 | } |
| 248 | #ifdef LARGE_FILE |
| 249 | if (lseek64(rofd, sparseoff, SEEK_SET) == -1) { |
| 250 | #else /* LARGE_FILE */ |
| 251 | if (lseek(rofd, sparseoff, SEEK_SET) == -1) { |
| 252 | #endif /* LARGE_FILE */ |
| 253 | CLEANERROR("couldn't lseek to begining to verify contents"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 254 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 255 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 256 | if (munmap(mapaddr, holesize + 2 * pagesize) == -1) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 257 | CLEANERROR("munmap of tmp file failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 258 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 259 | } |
| 260 | /* check file's contents */ |
| 261 | if (checkchars(rofd, 'a', pagesize)) { |
| 262 | CLEANERROR("first page not filled with a's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 263 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 264 | } |
| 265 | if (checkchars(rofd, '\0', (e_pageskip - 1) * pagesize)) { |
| 266 | CLEANERROR("e_skip not filled with 0's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 267 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 268 | } |
| 269 | if (checkchars(rofd, 'e', pagesize)) { |
| 270 | CLEANERROR("part after first 0's not filled with e's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 271 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 272 | } |
| 273 | if (checkchars(rofd, '\0', holesize - e_pageskip * pagesize)) { |
| 274 | CLEANERROR("second hole section not filled with 0's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 275 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 276 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 277 | if (checkchars(rofd, 'b', (pagesize >> 1))) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 278 | CLEANERROR("next to last half page not filled with b's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 279 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 280 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 281 | if (checkchars(rofd, 'c', pagesize + (pagesize >> 1))) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 282 | CLEANERROR("extended fragment not filled with c's"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 283 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 284 | } |
| 285 | if (close(rofd) == -1) { |
| 286 | CLEANERROR("second close of rofd failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 287 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 288 | } |
| 289 | if (unlink(tmpname) == -1) { |
| 290 | CLEANERROR("unlink failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 291 | anyfail(); /* LTP Port */ |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 292 | } |
| 293 | (void)time(&t); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 294 | // (void)printf("%s: Finished %s", argv[0], ctime(&t)); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 295 | ok_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 296 | tst_exit(); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* checkchars |
| 300 | * verrify that the next n characters of file fd are of value val. |
| 301 | * 0 = success; -1 = failure |
| 302 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 303 | static int checkchars(int fd, char val, int n) |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 304 | { |
| 305 | int i; |
| 306 | char buf; |
| 307 | |
| 308 | for (i = 0; i < n && read(fd, &buf, 1) == 1; i++) |
| 309 | if (buf != val) |
| 310 | return -1; |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | /***** ** LTP Port ** *****/ |
| 315 | int anyfail() |
| 316 | { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame^] | 317 | tst_brkm(TFAIL, tst_rmdir, "Test failed\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 318 | } |
| 319 | |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 320 | void ok_exit() |
| 321 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 322 | tst_resm(TPASS, "Test passed\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 323 | tst_rmdir(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 324 | tst_exit(); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 327 | /***** ** ****** ** *****/ |