1 /* vdfmt.h 1.4 87/06/01 */ 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 "inode.h" 11 #include "fs.h" 12 #include "tahoevba/vbaparam.h" 13 #include "tahoevba/vdreg.h" 14 15 #include "tahoe/cp.h" 16 extern struct cpdcb_i cpin; /* found in prf.c */ 17 18 /* 19 * Poll console and return 1 if input is present. 20 */ 21 #define input() \ 22 (uncache(&cpin.cp_hdr.cp_unit), (cpin.cp_hdr.cp_unit&CPDONE)) 23 24 /* 25 * Configuration parameters 26 */ 27 #define MAXCTLR 8 /* Maximum # of controllers */ 28 #define MAXDRIVE 16 /* Max drives per controller */ 29 30 #define NUMMAP 1 /* # Cyls in bad sector map */ 31 #define NUMMNT 1 /* # cyls for diagnostics */ 32 #define NUMREL 3 /* # Cyls in relocation area */ 33 #define NUMSYS (NUMREL+NUMMNT+NUMMAP) /* Total cyls used by system */ 34 35 #define MAXTRKS 24 36 #define MAXSECS_PER_TRK 64 37 #define MAXERR 1000 38 #define SECSIZ 512 39 #define TRKSIZ ((SECSIZ/sizeof(long)) * MAXSECS_PER_TRK) 40 #define bytes_trk (CURRENT->vc_nsec * SECSIZ) 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 int (*cylinder_skew)(); 197 int (*track_skew)(); 198 } ctlr_info; 199 200 #define C_INFO c_info[cur.controller] 201 ctlr_info c_info[MAXCTLR]; 202 203 /* 204 * Drive specific information 205 */ 206 typedef struct { 207 uncertain alive; 208 int id; 209 struct vdconfig *info; 210 int trk_size; 211 int num_slip; 212 int track_skew; 213 drv_stat condition; 214 } drive_info; 215 216 #define D_INFO d_info[cur.controller][cur.drive] 217 #define CURRENT D_INFO.info 218 drive_info d_info[MAXCTLR][MAXDRIVE]; 219 220 typedef struct { 221 unsigned int bs_id; /* Pack id */ 222 unsigned int bs_count; /* number of known bad sectors */ 223 unsigned int bs_max; /* Maximum allowable bad sectors */ 224 bs_entry list[1]; 225 } bs_map; 226 227 #define MAX_FLAWS (((TRKSIZ*sizeof(long))-sizeof(bs_map))/sizeof(bs_entry)) 228 229 long bs_map_space[TRKSIZ]; 230 bs_map *bad_map; 231 232 boolean kill_processes; 233 int num_controllers; 234 extern int vdtimeout; 235 236 /* 237 * Pattern buffers and the sort 238 */ 239 fmt_free free_tbl[NUMREL*MAXTRKS][MAXSECS_PER_TRK]; 240 struct mdcb mdcb; /* Master device control block */ 241 struct dcb dcb; /* Device control blocks */ 242 243 long pattern_0[TRKSIZ], pattern_1[TRKSIZ]; 244 long pattern_2[TRKSIZ], pattern_3[TRKSIZ]; 245 long pattern_4[TRKSIZ], pattern_5[TRKSIZ]; 246 long pattern_6[TRKSIZ], pattern_7[TRKSIZ]; 247 long pattern_8[TRKSIZ], pattern_9[TRKSIZ]; 248 long pattern_10[TRKSIZ], pattern_11[TRKSIZ]; 249 long pattern_12[TRKSIZ], pattern_13[TRKSIZ]; 250 long pattern_14[TRKSIZ], pattern_15[TRKSIZ]; 251 252 long *pattern_address[16]; /* pointers to pattern_* */ 253 254 /* 255 * Double buffer for scanning existing 256 * file systems and general scratch 257 */ 258 long scratch[TRKSIZ]; 259 long save[TRKSIZ]; 260 261 /* XXX */ 262 /* 263 * Flaw map stuff 264 */ 265 typedef struct { 266 long flaw_sync; 267 short flaw_cyl; 268 char flaw_trk; 269 char flaw_sec; 270 struct { 271 short flaw_offset; 272 short flaw_length; 273 } flaw_pos[4]; 274 char flaw_status; 275 char flaw_junk[1024]; /* Fill up 518 byte block */ 276 } flaw; 277 278 typedef struct { 279 long smde_sync; 280 unsigned adr_cyl : 12; 281 unsigned adr_trk : 8; 282 unsigned adr_sec : 8; 283 unsigned sec_flgs : 4; 284 unsigned alt_cyl : 12; 285 unsigned alt_trk : 8; 286 unsigned alt_sec : 8; 287 char smde_junk[1024]; 288 } smde_hdr; 289 290 #define CDCSYNC 0x1919 291 #define SMDSYNC 0x0019 292 #define SMDESYNC 0x0009 293 #define SMDE1SYNC 0x000d 294 295 /* XXX */ 296 297 /* 298 * Disk drive geometry definition. 299 */ 300 struct geometry { 301 u_short g_nsec; /* sectors/track */ 302 u_short g_ntrak; /* tracks/cylinder */ 303 u_int g_ncyl; /* cylinders/drive */ 304 }; 305 306 /* 307 * Flaw testing patterns. 308 */ 309 struct flawpat { 310 u_int fp_pat[16]; 311 }; 312 313 /* 314 * Disk drive configuration information. 315 */ 316 struct vdconfig { 317 char *vc_name; /* drive name for selection */ 318 struct geometry vc_geometry; /* disk geometry */ 319 #define vc_nsec vc_geometry.g_nsec 320 #define vc_ntrak vc_geometry.g_ntrak 321 #define vc_ncyl vc_geometry.g_ncyl 322 int vc_nslip; /* # of slip sectors */ 323 int vc_rpm; /* revolutions/minute */ 324 int vc_traksize; /* bits/track for flaw map interp */ 325 struct flawpat *vc_pat; /* flaw testing patterns */ 326 char *vc_type; /* informative description */ 327 }; 328 struct vdconfig vdconfig[]; 329 int ndrives; 330 int smddrives; 331