xref: /illumos-gate/usr/src/cmd/format/defect.h (revision 65908c77)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * Common Development and Distribution License (the "License").
6*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_DEFECT_H
277c478bd9Sstevel@tonic-gate #define	_DEFECT_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * This file contains definitions related to the defect list.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate extern	struct defect_list work_list;
387c478bd9Sstevel@tonic-gate extern	struct dkbad badmap;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * This is the structure of the header of a defect list.  It is always
427c478bd9Sstevel@tonic-gate  * the first sector on a track containing a defect list.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate struct defectHeader {
457c478bd9Sstevel@tonic-gate 	uint_t	magicno;
467c478bd9Sstevel@tonic-gate 	int	count;
477c478bd9Sstevel@tonic-gate 	int	cksum;
487c478bd9Sstevel@tonic-gate 	int	save[125];
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * This is the structure of a defect.  Defects are stored on the disk
537c478bd9Sstevel@tonic-gate  * as an array of these structures following the defect header.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate struct defect_entry {
567c478bd9Sstevel@tonic-gate 	short	cyl;
577c478bd9Sstevel@tonic-gate 	short	head;
587c478bd9Sstevel@tonic-gate 	short	sect;
597c478bd9Sstevel@tonic-gate 	short	nbits;
607c478bd9Sstevel@tonic-gate 	int	bfi;
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * This is the internal representation of a defect list.  We store
657c478bd9Sstevel@tonic-gate  * the header statically, but dynamically allocate space for the
667c478bd9Sstevel@tonic-gate  * actual defects, since their number may vary.  The flags field is
677c478bd9Sstevel@tonic-gate  * used to keep track of whether the list has been modified.
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate struct defect_list {
707c478bd9Sstevel@tonic-gate 	struct	defectHeader header;
717c478bd9Sstevel@tonic-gate 	struct	defect_entry *list;
727c478bd9Sstevel@tonic-gate 	int	flags;
737c478bd9Sstevel@tonic-gate };
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * This defines the number of copies of the defect list kept on the disk.
777c478bd9Sstevel@tonic-gate  * They are stored 1/track, starting at track 0 of the second alternate cyl.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate #define	LISTCOUNT	2
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * These defines are the flags for the defect list.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #define	LIST_DIRTY	0x01	/* List needs to be synced */
857c478bd9Sstevel@tonic-gate #define	LIST_RELOAD	0x02	/* Reload list after formatting (SCSI) */
867c478bd9Sstevel@tonic-gate #define	LIST_PGLIST	0x04	/* embedded SCSI - both manufacturer's (P) */
877c478bd9Sstevel@tonic-gate 				/* and grown (G) list */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * Miscellaneous defines.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	DEFECT_MAGIC	0x89898989	/* magic no for defect lists */
937c478bd9Sstevel@tonic-gate #define	NO_CHECKSUM	0x1		/* magic no for no checksum in */
947c478bd9Sstevel@tonic-gate 					/* defect list */
957c478bd9Sstevel@tonic-gate #define	UNKNOWN		(-1)		/* value used in defect fields */
967c478bd9Sstevel@tonic-gate #define	DEF_PRINTHEADER	" num     cyl     hd     bfi     len     sec     blk\n"
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * This defines the number of copies of the bad block table kept on the
1007c478bd9Sstevel@tonic-gate  * disk.  They are stored in the first 5 even sectors on the last track
1017c478bd9Sstevel@tonic-gate  * of the disk.  Note: this also defines the number of backup labels,
1027c478bd9Sstevel@tonic-gate  * which are kept in the first 5 odd sectors of the appropriate
1037c478bd9Sstevel@tonic-gate  * track.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate #define	BAD_LISTCNT	5
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * Prototypes for ANSI C compilers
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate void	read_list(struct defect_list *list);
1127c478bd9Sstevel@tonic-gate int	makebfi(struct defect_list *list, struct defect_entry *def);
1137c478bd9Sstevel@tonic-gate void	calc_bfi(struct defect_list *list, struct defect_entry *def,
1147c478bd9Sstevel@tonic-gate 		struct defect_entry *end, int skew);
1157c478bd9Sstevel@tonic-gate int	makelsect(struct defect_list *list);
1167c478bd9Sstevel@tonic-gate int	checkdefsum(struct defect_list *list, int mode);
1177c478bd9Sstevel@tonic-gate void	pr_defect(struct defect_entry *def, int num);
1187c478bd9Sstevel@tonic-gate int	sort_defect(struct defect_entry *def, struct defect_list *list);
1197c478bd9Sstevel@tonic-gate void	write_deflist(struct defect_list *list);
1207c478bd9Sstevel@tonic-gate void	add_ldef(diskaddr_t blkno, struct defect_list *list);
1217c478bd9Sstevel@tonic-gate void	add_def(struct defect_entry *def, struct defect_list *list,
1227c478bd9Sstevel@tonic-gate 		int index);
1237c478bd9Sstevel@tonic-gate void	kill_deflist(struct defect_list *list);
1247c478bd9Sstevel@tonic-gate 
125*65908c77Syu, larry liu - Sun Microsystems - Beijing China /*
126*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * This defines the size (in sectors) of the defect array given the number
127*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * of defects in the array.  It must be rounded to a sector boundary since
128*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * that is the atomic disk size.  We make a zero length list use up a
129*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * sector because it is convenient to have malloc'd space in every
130*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * non-null list.
131*65908c77Syu, larry liu - Sun Microsystems - Beijing China  */
132*65908c77Syu, larry liu - Sun Microsystems - Beijing China int	deflist_size(int secsz, int sz);
133*65908c77Syu, larry liu - Sun Microsystems - Beijing China 
1347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #endif	/* _DEFECT_H */
139