xref: /titanic_52/usr/src/cmd/format/defect.h (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
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 1991-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DEFECT_H
28 #define	_DEFECT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * This file contains definitions related to the defect list.
38  */
39 
40 extern	struct defect_list work_list;
41 extern	struct dkbad badmap;
42 
43 /*
44  * This is the structure of the header of a defect list.  It is always
45  * the first sector on a track containing a defect list.
46  */
47 struct defectHeader {
48 	uint_t	magicno;
49 	int	count;
50 	int	cksum;
51 	int	save[125];
52 };
53 
54 /*
55  * This is the structure of a defect.  Defects are stored on the disk
56  * as an array of these structures following the defect header.
57  */
58 struct defect_entry {
59 	short	cyl;
60 	short	head;
61 	short	sect;
62 	short	nbits;
63 	int	bfi;
64 };
65 
66 /*
67  * This is the internal representation of a defect list.  We store
68  * the header statically, but dynamically allocate space for the
69  * actual defects, since their number may vary.  The flags field is
70  * used to keep track of whether the list has been modified.
71  */
72 struct defect_list {
73 	struct	defectHeader header;
74 	struct	defect_entry *list;
75 	int	flags;
76 };
77 
78 /*
79  * This defines the number of copies of the defect list kept on the disk.
80  * They are stored 1/track, starting at track 0 of the second alternate cyl.
81  */
82 #define	LISTCOUNT	2
83 
84 /*
85  * This defines the size (in sectors) of the defect array given the number
86  * of defects in the array.  It must be rounded to a sector boundary since
87  * that is the atomic disk size.  We make a zero length list use up a
88  * sector because it is convenient to have malloc'd space in every
89  * non-null list.
90  */
91 #define	LISTSIZE(x)	((x) ? ((x) * sizeof (struct defect_entry) + \
92 			SECSIZE - 1) / SECSIZE : 1)
93 
94 /*
95  * These defines are the flags for the defect list.
96  */
97 #define	LIST_DIRTY	0x01	/* List needs to be synced */
98 #define	LIST_RELOAD	0x02	/* Reload list after formatting (SCSI) */
99 #define	LIST_PGLIST	0x04	/* embedded SCSI - both manufacturer's (P) */
100 				/* and grown (G) list */
101 
102 /*
103  * Miscellaneous defines.
104  */
105 #define	DEFECT_MAGIC	0x89898989	/* magic no for defect lists */
106 #define	NO_CHECKSUM	0x1		/* magic no for no checksum in */
107 					/* defect list */
108 #define	UNKNOWN		(-1)		/* value used in defect fields */
109 #define	DEF_PRINTHEADER	" num     cyl     hd     bfi     len     sec     blk\n"
110 
111 /*
112  * This defines the number of copies of the bad block table kept on the
113  * disk.  They are stored in the first 5 even sectors on the last track
114  * of the disk.  Note: this also defines the number of backup labels,
115  * which are kept in the first 5 odd sectors of the appropriate
116  * track.
117  */
118 #define	BAD_LISTCNT	5
119 
120 
121 /*
122  * Prototypes for ANSI C compilers
123  */
124 void	read_list(struct defect_list *list);
125 int	makebfi(struct defect_list *list, struct defect_entry *def);
126 void	calc_bfi(struct defect_list *list, struct defect_entry *def,
127 		struct defect_entry *end, int skew);
128 int	makelsect(struct defect_list *list);
129 int	checkdefsum(struct defect_list *list, int mode);
130 void	pr_defect(struct defect_entry *def, int num);
131 int	sort_defect(struct defect_entry *def, struct defect_list *list);
132 void	write_deflist(struct defect_list *list);
133 void	add_ldef(diskaddr_t blkno, struct defect_list *list);
134 void	add_def(struct defect_entry *def, struct defect_list *list,
135 		int index);
136 void	kill_deflist(struct defect_list *list);
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif	/* _DEFECT_H */
143