1 /* vdfmt.h 1.2 86/11/04 */ 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 234 /* 235 * Pattern buffers and the sort 236 */ 237 fmt_free free_tbl[NUMREL*MAXTRKS][MAXSECS_PER_TRK]; 238 fmt_mdcb mdcb; /* Master device control block */ 239 fmt_dcb dcb; /* Device control blocks */ 240 241 long pattern_0[TRKSIZ], pattern_1[TRKSIZ]; 242 long pattern_2[TRKSIZ], pattern_3[TRKSIZ]; 243 long pattern_4[TRKSIZ], pattern_5[TRKSIZ]; 244 long pattern_6[TRKSIZ], pattern_7[TRKSIZ]; 245 long pattern_8[TRKSIZ], pattern_9[TRKSIZ]; 246 long pattern_10[TRKSIZ], pattern_11[TRKSIZ]; 247 long pattern_12[TRKSIZ], pattern_13[TRKSIZ]; 248 long pattern_14[TRKSIZ], pattern_15[TRKSIZ]; 249 250 long *pattern_address[16]; /* pointers to pattern_* */ 251 252 /* 253 * Double buffer for scanning existing 254 * file systems and general scratch 255 */ 256 long scratch[TRKSIZ]; 257 long save[TRKSIZ]; 258 259 /* XXX */ 260 /* 261 * Flaw map stuff 262 */ 263 typedef struct { 264 long flaw_sync; 265 short flaw_cyl; 266 char flaw_trk; 267 char flaw_sec; 268 struct { 269 short flaw_offset; 270 short flaw_length; 271 } flaw_pos[4]; 272 char flaw_status; 273 char flaw_junk[1024]; /* Fill up 518 byte block */ 274 } flaw; 275 276 typedef struct { 277 long smde_sync; 278 unsigned adr_cyl : 12; 279 unsigned adr_trk : 8; 280 unsigned adr_sec : 8; 281 unsigned sec_flgs : 4; 282 unsigned alt_cyl : 12; 283 unsigned alt_trk : 8; 284 unsigned alt_sec : 8; 285 char smde_junk[1024]; 286 } smde_hdr; 287 288 #define CDCSYNC 0x1919 289 #define SMDSYNC 0x0019 290 #define SMDESYNC 0x0009 291 #define SMDE1SYNC 0x000d 292 293 /* XXX */ 294 295 /* 296 * Disk drive geometry definition. 297 */ 298 struct geometry { 299 u_short g_nsec; /* sectors/track */ 300 u_short g_ntrak; /* tracks/cylinder */ 301 u_int g_ncyl; /* cylinders/drive */ 302 }; 303 304 /* 305 * Flaw testing patterns. 306 */ 307 struct flawpat { 308 u_int fp_pat[16]; 309 }; 310 311 /* 312 * Disk drive configuration information. 313 */ 314 struct vdconfig { 315 char *vc_name; /* drive name for selection */ 316 struct geometry vc_geometry; /* disk geometry */ 317 #define vc_nsec vc_geometry.g_nsec 318 #define vc_ntrak vc_geometry.g_ntrak 319 #define vc_ncyl vc_geometry.g_ncyl 320 int vc_nslip; /* # of slip sectors */ 321 int vc_rpm; /* revolutions/minute */ 322 int vc_traksize; /* bits/track for flaw map interp */ 323 struct flawpat *vc_pat; /* flaw testing patterns */ 324 char *vc_type; /* informative description */ 325 }; 326 struct vdconfig vdconfig[]; 327 int ndrives; 328 int smddrives; 329