1 /* vdfmt.h 1.3 86/12/19 */ 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 (DRVNRDY|INVDADR|DNEMEM|PARERR|OPABRT|WPTERR|DSEEKERR|NOTCYLERR) 44 #define DATA_ERROR \ 45 (CTLRERR|UCDATERR|DCOMPERR|DSERLY|DSLATE|TOPLUS|TOMNUS|CPDCRT|HRDERR|SFTERR) 46 #define HEADER_ERROR (HCRCERR | HCMPERR) 47 #define NRM (short)0 48 #define BAD (short)VDUF 49 #define WPT (short)(NRM | VDWPT) 50 #define RELOC_SECTOR (short)(VDALT) 51 #define ALT_SECTOR (short)(VDALT) 52 53 typedef enum { false, true } boolean; 54 typedef enum { u_false, u_true, u_unknown } uncertain; 55 56 /* 57 * Free bad block allocation bit map 58 */ 59 typedef struct { 60 long free_error; 61 enum { ALLOCATED, NOTALLOCATED } free_status; 62 } fmt_free; 63 64 typedef enum { SINGLE_SECTOR, FULL_TRACK } rel_type; /* relocation type */ 65 66 /* 67 * Error table format 68 */ 69 typedef struct { 70 dskadr err_adr; 71 long err_stat; 72 } fmt_err; 73 74 /* utilities */ 75 int blkcopy(); 76 int blkzero(); 77 int to_sector(); 78 int to_track(); 79 int data_ok(); 80 boolean blkcmp(); 81 boolean get_yes_no(); 82 boolean is_in_map(); 83 boolean is_formatted(); 84 boolean read_bad_sector_map(); 85 dskadr *from_sector(); 86 dskadr *from_track(); 87 dskadr *from_unix(); 88 dskadr is_relocated(); 89 dskadr *new_location(); 90 91 /* 92 * Operation table 93 */ 94 typedef struct { 95 int (*routine)(); 96 char *op_name; 97 char *op_action; 98 } op_tbl; 99 100 #define NUMOPS 7 101 op_tbl operations[NUMOPS]; 102 103 /* 104 * Operation bit mask values (must match order in operations table) 105 */ 106 #define FORMAT_OP 0x01 /* Format operation bit */ 107 #define VERIFY_OP 0x02 /* Verify operation bit */ 108 #define RELOCATE_OP 0x04 /* Relocate operation bit */ 109 #define INFO_OP 0x08 /* Info operation bit */ 110 #define CORRECT_OP 0x10 /* Correct operation bit */ 111 #define PROFILE_OP 0x20 /* Profile operation bit */ 112 #define EXERCISE_OP 0x40 /* Exercise operation bit */ 113 114 extern int format(), verify(), relocate(), info(); 115 extern int correct(), profile(), exercise(); 116 117 118 /* 119 * Operation table type and definitions 120 */ 121 typedef struct { 122 int op; 123 int numpat; 124 } op_spec; 125 op_spec ops_to_do[MAXCTLR][MAXDRIVE]; 126 127 /* 128 * Contains all the current parameters 129 */ 130 typedef enum { 131 formatted, 132 half_formatted, 133 unformatted, 134 unknown 135 } drv_stat; 136 typedef enum { 137 fmt, 138 vfy, 139 rel, 140 cor, 141 inf, 142 cmd, 143 exec, 144 prof, 145 setup 146 } state; 147 typedef enum { 148 sub_chk, 149 sub_rcvr, 150 sub_stat, 151 sub_rel, 152 sub_vfy, 153 sub_fmt, 154 sub_sk 155 } substate; 156 157 /* 158 * Different environments for setjumps 159 */ 160 jmp_buf reset_environ; /* Use when reset is issued */ 161 jmp_buf quit_environ; /* Use when you want to quit what your doing */ 162 jmp_buf abort_environ; /* Use when nothing can be done to recover */ 163 164 /* 165 * Flaw map definitions and storage 166 */ 167 typedef struct { 168 short bs_cyl; /* Cylinder position of flaw */ 169 short bs_trk; /* Track position of flaw */ 170 long bs_offset; /* (byte) Position of flaw on track */ 171 long bs_length; /* Length (in bits) of flaw */ 172 dskadr bs_alt; /* Addr of alt sector (all 0 if none) */ 173 enum { flaw_map, scanning, operator } bs_how; /* How it was found */ 174 } bs_entry ; 175 176 struct { 177 int controller; 178 int drive; 179 state state; 180 substate substate; 181 int error; 182 dskadr daddr; 183 } cur; 184 185 /* 186 * Controller specific information 187 */ 188 typedef struct { 189 uncertain alive; 190 cdr *addr; 191 char *name; 192 int type; 193 fmt_err (*decode_pos)(); 194 bs_entry (*code_pos)(); 195 int (*cylinder_skew)(); 196 int (*track_skew)(); 197 } ctlr_info; 198 199 #define C_INFO c_info[cur.controller] 200 ctlr_info c_info[MAXCTLR]; 201 202 /* 203 * Drive specific information 204 */ 205 typedef struct { 206 uncertain alive; 207 int id; 208 struct vdconfig *info; 209 int trk_size; 210 int num_slip; 211 int track_skew; 212 drv_stat condition; 213 } drive_info; 214 215 #define D_INFO d_info[cur.controller][cur.drive] 216 #define CURRENT D_INFO.info 217 drive_info d_info[MAXCTLR][MAXDRIVE]; 218 219 typedef struct { 220 unsigned int bs_id; /* Pack id */ 221 unsigned int bs_count; /* number of known bad sectors */ 222 unsigned int bs_max; /* Maximum allowable bad sectors */ 223 bs_entry list[1]; 224 } bs_map; 225 226 #define MAX_FLAWS (((TRKSIZ*sizeof(long))-sizeof(bs_map))/sizeof(bs_entry)) 227 228 long bs_map_space[TRKSIZ]; 229 bs_map *bad_map; 230 231 boolean kill_processes; 232 int num_controllers; 233 extern int vdtimeout; 234 235 /* 236 * Pattern buffers and the sort 237 */ 238 fmt_free free_tbl[NUMREL*MAXTRKS][MAXSECS_PER_TRK]; 239 fmt_mdcb mdcb; /* Master device control block */ 240 fmt_dcb dcb; /* Device control blocks */ 241 242 long pattern_0[TRKSIZ], pattern_1[TRKSIZ]; 243 long pattern_2[TRKSIZ], pattern_3[TRKSIZ]; 244 long pattern_4[TRKSIZ], pattern_5[TRKSIZ]; 245 long pattern_6[TRKSIZ], pattern_7[TRKSIZ]; 246 long pattern_8[TRKSIZ], pattern_9[TRKSIZ]; 247 long pattern_10[TRKSIZ], pattern_11[TRKSIZ]; 248 long pattern_12[TRKSIZ], pattern_13[TRKSIZ]; 249 long pattern_14[TRKSIZ], pattern_15[TRKSIZ]; 250 251 long *pattern_address[16]; /* pointers to pattern_* */ 252 253 /* 254 * Double buffer for scanning existing 255 * file systems and general scratch 256 */ 257 long scratch[TRKSIZ]; 258 long save[TRKSIZ]; 259 260 /* XXX */ 261 /* 262 * Flaw map stuff 263 */ 264 typedef struct { 265 long flaw_sync; 266 short flaw_cyl; 267 char flaw_trk; 268 char flaw_sec; 269 struct { 270 short flaw_offset; 271 short flaw_length; 272 } flaw_pos[4]; 273 char flaw_status; 274 char flaw_junk[1024]; /* Fill up 518 byte block */ 275 } flaw; 276 277 typedef struct { 278 long smde_sync; 279 unsigned adr_cyl : 12; 280 unsigned adr_trk : 8; 281 unsigned adr_sec : 8; 282 unsigned sec_flgs : 4; 283 unsigned alt_cyl : 12; 284 unsigned alt_trk : 8; 285 unsigned alt_sec : 8; 286 char smde_junk[1024]; 287 } smde_hdr; 288 289 #define CDCSYNC 0x1919 290 #define SMDSYNC 0x0019 291 #define SMDESYNC 0x0009 292 #define SMDE1SYNC 0x000d 293 294 /* XXX */ 295 296 /* 297 * Disk drive geometry definition. 298 */ 299 struct geometry { 300 u_short g_nsec; /* sectors/track */ 301 u_short g_ntrak; /* tracks/cylinder */ 302 u_int g_ncyl; /* cylinders/drive */ 303 }; 304 305 /* 306 * Flaw testing patterns. 307 */ 308 struct flawpat { 309 u_int fp_pat[16]; 310 }; 311 312 /* 313 * Disk drive configuration information. 314 */ 315 struct vdconfig { 316 char *vc_name; /* drive name for selection */ 317 struct geometry vc_geometry; /* disk geometry */ 318 #define vc_nsec vc_geometry.g_nsec 319 #define vc_ntrak vc_geometry.g_ntrak 320 #define vc_ncyl vc_geometry.g_ncyl 321 int vc_nslip; /* # of slip sectors */ 322 int vc_rpm; /* revolutions/minute */ 323 int vc_traksize; /* bits/track for flaw map interp */ 324 struct flawpat *vc_pat; /* flaw testing patterns */ 325 char *vc_type; /* informative description */ 326 }; 327 struct vdconfig vdconfig[]; 328 int ndrives; 329 int smddrives; 330