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