1 /* vdfmt.h 1.5 87/11/23 */ 2 3 /* 4 * VERSAbus disk controller (vd) disk formatter. 5 */ 6 #include <setjmp.h> 7 #include "tahoe/mtpr.h" 8 #include "param.h" 9 #include "buf.h" 10 #include "disklabel.h" 11 #include "inode.h" 12 #include "fs.h" 13 #include "tahoevba/vbaparam.h" 14 #include "tahoevba/vdreg.h" 15 16 #include "tahoe/cp.h" 17 extern struct cpdcb_i cpin; /* found in prf.c */ 18 19 /* 20 * Poll console and return 1 if input is present. 21 */ 22 #define input() \ 23 (uncache(&cpin.cp_hdr.cp_unit), (cpin.cp_hdr.cp_unit&CPDONE)) 24 25 /* 26 * Configuration parameters 27 */ 28 #define MAXCTLR 8 /* Maximum # of controllers */ 29 #define MAXDRIVE 16 /* Max drives per controller */ 30 31 #define NUMMAP 1 /* # Cyls in bad sector map */ 32 #define NUMMNT 1 /* # cyls for diagnostics */ 33 #define NUMREL 3 /* # Cyls in relocation area */ 34 #define NUMSYS (NUMREL+NUMMNT+NUMMAP) /* Total cyls used by system */ 35 36 #define MAXTRKS 24 37 #define MAXSECS_PER_TRK 72 /* at 512 bytes/sector */ 38 #define MAXERR 1000 39 #define MAXTRKSIZ ((512/sizeof(long)) * MAXSECS_PER_TRK) 40 #define bytes_trk (lab->d_nsectors * lab->d_secsize) 41 42 #define HARD_ERROR \ 43 (DCBS_NRDY|DCBS_IVA|DCBS_NEM|DCBS_DPE|DCBS_OAB|DCBS_WPT|DCBS_SKI|DCBS_OCYL) 44 #define DATA_ERROR \ 45 (DCBS_HCE|DCBS_UDE|DCBS_DCE|DCBS_DSE|DCBS_DSL|DCBS_TOP|DCBS_TOM|DCBS_CCD|\ 46 DCBS_HARD|DCBS_SOFT) 47 #define HEADER_ERROR (DCBS_HCRC|DCBS_HCE) 48 #define NRM (short)0 49 #define BAD (short)VDUF 50 #define WPT (short)(NRM | VDWPT) 51 #define RELOC_SECTOR (short)(VDALT) 52 #define ALT_SECTOR (short)(VDALT) 53 54 typedef enum { false, true } boolean; 55 typedef enum { u_false, u_true, u_unknown } uncertain; 56 57 /* 58 * Free bad block allocation bit map 59 */ 60 typedef struct { 61 long free_error; 62 enum { ALLOCATED, NOTALLOCATED } free_status; 63 } fmt_free; 64 65 typedef enum { SINGLE_SECTOR, FULL_TRACK } rel_type; /* relocation type */ 66 67 /* 68 * Error table format 69 */ 70 typedef struct { 71 dskadr err_adr; 72 long err_stat; 73 } fmt_err; 74 75 /* utilities */ 76 int blkcopy(); 77 int blkzero(); 78 int to_sector(); 79 int to_track(); 80 int data_ok(); 81 boolean blkcmp(); 82 boolean get_yes_no(); 83 boolean is_in_map(); 84 boolean is_formatted(); 85 boolean read_bad_sector_map(); 86 dskadr *from_sector(); 87 dskadr *from_track(); 88 dskadr *from_unix(); 89 dskadr is_relocated(); 90 dskadr *new_location(); 91 92 /* 93 * Operation table 94 */ 95 typedef struct { 96 int (*routine)(); 97 char *op_name; 98 char *op_action; 99 } op_tbl; 100 101 #define NUMOPS 7 102 op_tbl operations[NUMOPS]; 103 104 /* 105 * Operation bit mask values (must match order in operations table) 106 */ 107 #define FORMAT_OP 0x01 /* Format operation bit */ 108 #define VERIFY_OP 0x02 /* Verify operation bit */ 109 #define RELOCATE_OP 0x04 /* Relocate operation bit */ 110 #define INFO_OP 0x08 /* Info operation bit */ 111 #define CORRECT_OP 0x10 /* Correct operation bit */ 112 #define PROFILE_OP 0x20 /* Profile operation bit */ 113 #define EXERCISE_OP 0x40 /* Exercise operation bit */ 114 115 extern int format(), verify(), relocate(), info(); 116 extern int correct(), profile(), exercise(); 117 118 119 /* 120 * Operation table type and definitions 121 */ 122 typedef struct { 123 int op; 124 int numpat; 125 } op_spec; 126 op_spec ops_to_do[MAXCTLR][MAXDRIVE]; 127 128 /* 129 * Contains all the current parameters 130 */ 131 typedef enum { 132 formatted, 133 half_formatted, 134 unformatted, 135 unknown 136 } drv_stat; 137 typedef enum { 138 fmt, 139 vfy, 140 rel, 141 cor, 142 inf, 143 cmd, 144 exec, 145 prof, 146 setup 147 } state; 148 typedef enum { 149 sub_chk, 150 sub_rcvr, 151 sub_stat, 152 sub_rel, 153 sub_vfy, 154 sub_fmt, 155 sub_sk 156 } substate; 157 158 /* 159 * Different environments for setjumps 160 */ 161 jmp_buf reset_environ; /* Use when reset is issued */ 162 jmp_buf quit_environ; /* Use when you want to quit what your doing */ 163 jmp_buf abort_environ; /* Use when nothing can be done to recover */ 164 165 /* 166 * Flaw map definitions and storage 167 */ 168 typedef struct { 169 short bs_cyl; /* Cylinder position of flaw */ 170 short bs_trk; /* Track position of flaw */ 171 long bs_offset; /* (byte) Position of flaw on track */ 172 long bs_length; /* Length (in bits) of flaw */ 173 dskadr bs_alt; /* Addr of alt sector (all 0 if none) */ 174 enum { flaw_map, scanning, operator } bs_how; /* How it was found */ 175 } bs_entry ; 176 177 struct { 178 int controller; 179 int drive; 180 state state; 181 substate substate; 182 int error; 183 dskadr daddr; 184 } cur; 185 186 /* 187 * Controller specific information 188 */ 189 typedef struct { 190 uncertain alive; 191 struct vddevice *addr; 192 char *name; 193 int type; 194 fmt_err (*decode_pos)(); 195 bs_entry (*code_pos)(); 196 } ctlr_info; 197 198 ctlr_info c_info[MAXCTLR]; 199 ctlr_info *C_INFO; 200 201 /* 202 * Drive specific information 203 */ 204 typedef struct { 205 uncertain alive; 206 int id; 207 struct disklabel label; 208 drv_stat condition; 209 } drive_info; 210 #define d_traksize d_drivedata[1] 211 #define d_pat d_drivedata[2] 212 213 drive_info d_info[MAXCTLR][MAXDRIVE]; 214 drive_info *D_INFO; 215 struct disklabel *lab; 216 217 struct disklabel vdproto[]; 218 int ndrives; 219 int smddrives; 220 221 typedef struct { 222 unsigned int bs_id; /* Pack id */ 223 unsigned int bs_count; /* number of known bad sectors */ 224 unsigned int bs_max; /* Maximum allowable bad sectors */ 225 bs_entry list[1]; 226 } bs_map; 227 228 #define MAX_FLAWS (((MAXTRKSIZ*sizeof(long))-sizeof(bs_map))/sizeof(bs_entry)) 229 230 long bs_map_space[MAXTRKSIZ]; 231 bs_map *bad_map; 232 233 boolean kill_processes; 234 int num_controllers; 235 extern int vdtimeout; 236 237 /* 238 * Pattern buffers and the sort 239 */ 240 fmt_free free_tbl[NUMREL*MAXTRKS][MAXSECS_PER_TRK]; 241 struct mdcb mdcb; /* Master device control block */ 242 struct dcb dcb; /* Device control blocks */ 243 244 long pattern_0[MAXTRKSIZ], pattern_1[MAXTRKSIZ]; 245 long pattern_2[MAXTRKSIZ], pattern_3[MAXTRKSIZ]; 246 long pattern_4[MAXTRKSIZ], pattern_5[MAXTRKSIZ]; 247 long pattern_6[MAXTRKSIZ], pattern_7[MAXTRKSIZ]; 248 long pattern_8[MAXTRKSIZ], pattern_9[MAXTRKSIZ]; 249 long pattern_10[MAXTRKSIZ], pattern_11[MAXTRKSIZ]; 250 long pattern_12[MAXTRKSIZ], pattern_13[MAXTRKSIZ]; 251 long pattern_14[MAXTRKSIZ], pattern_15[MAXTRKSIZ]; 252 253 long *pattern_address[16]; /* pointers to pattern_* */ 254 255 /* 256 * Double buffer for scanning existing 257 * file systems and general scratch 258 */ 259 long scratch[MAXTRKSIZ]; 260 long save[MAXTRKSIZ]; 261 262 /* XXX */ 263 /* 264 * Flaw map stuff 265 */ 266 typedef struct { 267 long flaw_sync; 268 short flaw_cyl; 269 char flaw_trk; 270 char flaw_sec; 271 struct { 272 short flaw_offset; 273 short flaw_length; 274 } flaw_pos[4]; 275 char flaw_status; 276 char flaw_junk[1024]; /* Fill up 518 byte block */ 277 } flaw; 278 279 typedef struct { 280 long smde_sync; 281 unsigned adr_cyl : 12; 282 unsigned adr_trk : 8; 283 unsigned adr_sec : 8; 284 unsigned sec_flgs : 4; 285 unsigned alt_cyl : 12; 286 unsigned alt_trk : 8; 287 unsigned alt_sec : 8; 288 char smde_junk[1024]; 289 } smde_hdr; 290 291 /* for MAXTOR */ 292 293 typedef struct { 294 unsigned long esdi_flaw_sync; 295 unsigned short esdi_flaw_cyl; 296 unsigned char esdi_flaw_trk; 297 unsigned char esdi_flaw_sec; 298 unsigned char esdi_flags; 299 unsigned char esdi_ecc_1[2]; 300 unsigned char esdi_pad_1[2]; 301 unsigned char esdi_plo_sync[26]; 302 } esdi_flaw_header; 303 304 typedef struct { 305 unsigned long esdi_data_sync; 306 unsigned char esdi_month; 307 unsigned char esdi_day; 308 unsigned char esdi_year; 309 unsigned char esdi_head; 310 unsigned char esdi_pad_2[2]; 311 unsigned char esdi_flaws[50][5]; /* see esdi_flaw_entry */ 312 unsigned char esdi_ecc_2[2]; 313 unsigned char esdi_pad_3[2]; 314 char esdi_flaw_junk[1024]; /* Fill up block */ 315 } esdi_flaw_data; 316 317 318 319 typedef struct { 320 esdi_flaw_header esdi_header; 321 esdi_flaw_data esdi_data; 322 } esdi_flaw; 323 324 325 326 /* 327 ** since each flaw entry is 5 bytes and this forces alignment problems we 328 ** define a structure here so that the entries can be BCOPYed into a 329 ** reasonable work area before access. 330 */ 331 332 typedef struct { 333 unsigned short esdi_flaw_cyl; 334 unsigned short esdi_flaw_offset; 335 unsigned char esdi_flaw_length; 336 } esdi_flaw_entry; 337 338 #define CDCSYNC 0x1919 339 #define SMDSYNC 0x0019 340 #define SMDESYNC 0x0009 341 #define SMDE1SYNC 0x000d 342 #define ESDISYNC 0x00fe 343 #define ESDI1SYNC 0x00fe /* 0x00f8 */ 344 345 /* XXX */ 346 347 /* 348 * Flaw testing patterns. 349 */ 350 struct flawpat { 351 u_int fp_pat[16]; 352 }; 353