10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*9889SLarry.Liu@Sun.COM * Common Development and Distribution License (the "License"). 6*9889SLarry.Liu@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9889SLarry.Liu@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _DEFECT_H 270Sstevel@tonic-gate #define _DEFECT_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * This file contains definitions related to the defect list. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate extern struct defect_list work_list; 380Sstevel@tonic-gate extern struct dkbad badmap; 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * This is the structure of the header of a defect list. It is always 420Sstevel@tonic-gate * the first sector on a track containing a defect list. 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate struct defectHeader { 450Sstevel@tonic-gate uint_t magicno; 460Sstevel@tonic-gate int count; 470Sstevel@tonic-gate int cksum; 480Sstevel@tonic-gate int save[125]; 490Sstevel@tonic-gate }; 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * This is the structure of a defect. Defects are stored on the disk 530Sstevel@tonic-gate * as an array of these structures following the defect header. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate struct defect_entry { 560Sstevel@tonic-gate short cyl; 570Sstevel@tonic-gate short head; 580Sstevel@tonic-gate short sect; 590Sstevel@tonic-gate short nbits; 600Sstevel@tonic-gate int bfi; 610Sstevel@tonic-gate }; 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * This is the internal representation of a defect list. We store 650Sstevel@tonic-gate * the header statically, but dynamically allocate space for the 660Sstevel@tonic-gate * actual defects, since their number may vary. The flags field is 670Sstevel@tonic-gate * used to keep track of whether the list has been modified. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate struct defect_list { 700Sstevel@tonic-gate struct defectHeader header; 710Sstevel@tonic-gate struct defect_entry *list; 720Sstevel@tonic-gate int flags; 730Sstevel@tonic-gate }; 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * This defines the number of copies of the defect list kept on the disk. 770Sstevel@tonic-gate * They are stored 1/track, starting at track 0 of the second alternate cyl. 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate #define LISTCOUNT 2 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 820Sstevel@tonic-gate * These defines are the flags for the defect list. 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate #define LIST_DIRTY 0x01 /* List needs to be synced */ 850Sstevel@tonic-gate #define LIST_RELOAD 0x02 /* Reload list after formatting (SCSI) */ 860Sstevel@tonic-gate #define LIST_PGLIST 0x04 /* embedded SCSI - both manufacturer's (P) */ 870Sstevel@tonic-gate /* and grown (G) list */ 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * Miscellaneous defines. 910Sstevel@tonic-gate */ 920Sstevel@tonic-gate #define DEFECT_MAGIC 0x89898989 /* magic no for defect lists */ 930Sstevel@tonic-gate #define NO_CHECKSUM 0x1 /* magic no for no checksum in */ 940Sstevel@tonic-gate /* defect list */ 950Sstevel@tonic-gate #define UNKNOWN (-1) /* value used in defect fields */ 960Sstevel@tonic-gate #define DEF_PRINTHEADER " num cyl hd bfi len sec blk\n" 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * This defines the number of copies of the bad block table kept on the 1000Sstevel@tonic-gate * disk. They are stored in the first 5 even sectors on the last track 1010Sstevel@tonic-gate * of the disk. Note: this also defines the number of backup labels, 1020Sstevel@tonic-gate * which are kept in the first 5 odd sectors of the appropriate 1030Sstevel@tonic-gate * track. 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate #define BAD_LISTCNT 5 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * Prototypes for ANSI C compilers 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate void read_list(struct defect_list *list); 1120Sstevel@tonic-gate int makebfi(struct defect_list *list, struct defect_entry *def); 1130Sstevel@tonic-gate void calc_bfi(struct defect_list *list, struct defect_entry *def, 1140Sstevel@tonic-gate struct defect_entry *end, int skew); 1150Sstevel@tonic-gate int makelsect(struct defect_list *list); 1160Sstevel@tonic-gate int checkdefsum(struct defect_list *list, int mode); 1170Sstevel@tonic-gate void pr_defect(struct defect_entry *def, int num); 1180Sstevel@tonic-gate int sort_defect(struct defect_entry *def, struct defect_list *list); 1190Sstevel@tonic-gate void write_deflist(struct defect_list *list); 1200Sstevel@tonic-gate void add_ldef(diskaddr_t blkno, struct defect_list *list); 1210Sstevel@tonic-gate void add_def(struct defect_entry *def, struct defect_list *list, 1220Sstevel@tonic-gate int index); 1230Sstevel@tonic-gate void kill_deflist(struct defect_list *list); 1240Sstevel@tonic-gate 125*9889SLarry.Liu@Sun.COM /* 126*9889SLarry.Liu@Sun.COM * This defines the size (in sectors) of the defect array given the number 127*9889SLarry.Liu@Sun.COM * of defects in the array. It must be rounded to a sector boundary since 128*9889SLarry.Liu@Sun.COM * that is the atomic disk size. We make a zero length list use up a 129*9889SLarry.Liu@Sun.COM * sector because it is convenient to have malloc'd space in every 130*9889SLarry.Liu@Sun.COM * non-null list. 131*9889SLarry.Liu@Sun.COM */ 132*9889SLarry.Liu@Sun.COM int deflist_size(int secsz, int sz); 133*9889SLarry.Liu@Sun.COM 1340Sstevel@tonic-gate #ifdef __cplusplus 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate #endif 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate #endif /* _DEFECT_H */ 139