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