1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1991-2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_DEFECT_H
28*0Sstevel@tonic-gate #define	_DEFECT_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * This file contains definitions related to the defect list.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate extern	struct defect_list work_list;
41*0Sstevel@tonic-gate extern	struct dkbad badmap;
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  * This is the structure of the header of a defect list.  It is always
45*0Sstevel@tonic-gate  * the first sector on a track containing a defect list.
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate struct defectHeader {
48*0Sstevel@tonic-gate 	uint_t	magicno;
49*0Sstevel@tonic-gate 	int	count;
50*0Sstevel@tonic-gate 	int	cksum;
51*0Sstevel@tonic-gate 	int	save[125];
52*0Sstevel@tonic-gate };
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate  * This is the structure of a defect.  Defects are stored on the disk
56*0Sstevel@tonic-gate  * as an array of these structures following the defect header.
57*0Sstevel@tonic-gate  */
58*0Sstevel@tonic-gate struct defect_entry {
59*0Sstevel@tonic-gate 	short	cyl;
60*0Sstevel@tonic-gate 	short	head;
61*0Sstevel@tonic-gate 	short	sect;
62*0Sstevel@tonic-gate 	short	nbits;
63*0Sstevel@tonic-gate 	int	bfi;
64*0Sstevel@tonic-gate };
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate /*
67*0Sstevel@tonic-gate  * This is the internal representation of a defect list.  We store
68*0Sstevel@tonic-gate  * the header statically, but dynamically allocate space for the
69*0Sstevel@tonic-gate  * actual defects, since their number may vary.  The flags field is
70*0Sstevel@tonic-gate  * used to keep track of whether the list has been modified.
71*0Sstevel@tonic-gate  */
72*0Sstevel@tonic-gate struct defect_list {
73*0Sstevel@tonic-gate 	struct	defectHeader header;
74*0Sstevel@tonic-gate 	struct	defect_entry *list;
75*0Sstevel@tonic-gate 	int	flags;
76*0Sstevel@tonic-gate };
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate /*
79*0Sstevel@tonic-gate  * This defines the number of copies of the defect list kept on the disk.
80*0Sstevel@tonic-gate  * They are stored 1/track, starting at track 0 of the second alternate cyl.
81*0Sstevel@tonic-gate  */
82*0Sstevel@tonic-gate #define	LISTCOUNT	2
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate /*
85*0Sstevel@tonic-gate  * This defines the size (in sectors) of the defect array given the number
86*0Sstevel@tonic-gate  * of defects in the array.  It must be rounded to a sector boundary since
87*0Sstevel@tonic-gate  * that is the atomic disk size.  We make a zero length list use up a
88*0Sstevel@tonic-gate  * sector because it is convenient to have malloc'd space in every
89*0Sstevel@tonic-gate  * non-null list.
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate #define	LISTSIZE(x)	((x) ? ((x) * sizeof (struct defect_entry) + \
92*0Sstevel@tonic-gate 			SECSIZE - 1) / SECSIZE : 1)
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate /*
95*0Sstevel@tonic-gate  * These defines are the flags for the defect list.
96*0Sstevel@tonic-gate  */
97*0Sstevel@tonic-gate #define	LIST_DIRTY	0x01	/* List needs to be synced */
98*0Sstevel@tonic-gate #define	LIST_RELOAD	0x02	/* Reload list after formatting (SCSI) */
99*0Sstevel@tonic-gate #define	LIST_PGLIST	0x04	/* embedded SCSI - both manufacturer's (P) */
100*0Sstevel@tonic-gate 				/* and grown (G) list */
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate /*
103*0Sstevel@tonic-gate  * Miscellaneous defines.
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate #define	DEFECT_MAGIC	0x89898989	/* magic no for defect lists */
106*0Sstevel@tonic-gate #define	NO_CHECKSUM	0x1		/* magic no for no checksum in */
107*0Sstevel@tonic-gate 					/* defect list */
108*0Sstevel@tonic-gate #define	UNKNOWN		(-1)		/* value used in defect fields */
109*0Sstevel@tonic-gate #define	DEF_PRINTHEADER	" num     cyl     hd     bfi     len     sec     blk\n"
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /*
112*0Sstevel@tonic-gate  * This defines the number of copies of the bad block table kept on the
113*0Sstevel@tonic-gate  * disk.  They are stored in the first 5 even sectors on the last track
114*0Sstevel@tonic-gate  * of the disk.  Note: this also defines the number of backup labels,
115*0Sstevel@tonic-gate  * which are kept in the first 5 odd sectors of the appropriate
116*0Sstevel@tonic-gate  * track.
117*0Sstevel@tonic-gate  */
118*0Sstevel@tonic-gate #define	BAD_LISTCNT	5
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate /*
122*0Sstevel@tonic-gate  * Prototypes for ANSI C compilers
123*0Sstevel@tonic-gate  */
124*0Sstevel@tonic-gate void	read_list(struct defect_list *list);
125*0Sstevel@tonic-gate int	makebfi(struct defect_list *list, struct defect_entry *def);
126*0Sstevel@tonic-gate void	calc_bfi(struct defect_list *list, struct defect_entry *def,
127*0Sstevel@tonic-gate 		struct defect_entry *end, int skew);
128*0Sstevel@tonic-gate int	makelsect(struct defect_list *list);
129*0Sstevel@tonic-gate int	checkdefsum(struct defect_list *list, int mode);
130*0Sstevel@tonic-gate void	pr_defect(struct defect_entry *def, int num);
131*0Sstevel@tonic-gate int	sort_defect(struct defect_entry *def, struct defect_list *list);
132*0Sstevel@tonic-gate void	write_deflist(struct defect_list *list);
133*0Sstevel@tonic-gate void	add_ldef(diskaddr_t blkno, struct defect_list *list);
134*0Sstevel@tonic-gate void	add_def(struct defect_entry *def, struct defect_list *list,
135*0Sstevel@tonic-gate 		int index);
136*0Sstevel@tonic-gate void	kill_deflist(struct defect_list *list);
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #ifdef	__cplusplus
139*0Sstevel@tonic-gate }
140*0Sstevel@tonic-gate #endif
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate #endif	/* _DEFECT_H */
143