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