xref: /illumos-gate/usr/src/cmd/fs.d/pcfs/fsck/inject.c (revision 6dde88b51419b99fe0aab8e56184c693945826b8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*
28  * fsck_pcfs -- inject.c
29  *	Debugging routine that will insert random errors into the reads,
30  *	so that you'll actually end up with some bad clusters.
31  */
32 
33 #include <stdio.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 
37 extern ssize_t _read(int fildes, void *buf, size_t nbyte);
38 
39 ssize_t
40 read(int fildes, void *buf, size_t nbyte)
41 {
42 	static int count = 0;
43 
44 	if ((count++ >= 263 && count <= 267) ||
45 	    (count >= 381 && count <= 385) ||
46 	    (count >= 1014 && count <= 1019) ||
47 	    (count >= 1119 && count <= 1123) ||
48 	    (count >= 1888 && count <= 1892)) {
49 		errno = EIO;
50 		return (-1);
51 	}
52 	return (_read(fildes, buf, nbyte));
53 }
54