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