1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ 28*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */ 29*0Sstevel@tonic-gate /* All Rights Reserved */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate /* 32*0Sstevel@tonic-gate * Copyrighted as an unpublished work. 33*0Sstevel@tonic-gate * (c) Copyright INTERACTIVE Systems Corporation 1986, 1988, 1990 34*0Sstevel@tonic-gate * All rights reserved. 35*0Sstevel@tonic-gate */ 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate #include <stdio.h> 40*0Sstevel@tonic-gate #include <fcntl.h> 41*0Sstevel@tonic-gate #include <memory.h> 42*0Sstevel@tonic-gate #include <sys/types.h> 43*0Sstevel@tonic-gate #include <sys/param.h> 44*0Sstevel@tonic-gate #include <sys/stat.h> 45*0Sstevel@tonic-gate #include <sys/mkdev.h> 46*0Sstevel@tonic-gate #include <sys/vtoc.h> 47*0Sstevel@tonic-gate #include <sys/dkio.h> 48*0Sstevel@tonic-gate #include <errno.h> 49*0Sstevel@tonic-gate #include <sys/scsi/generic/commands.h> 50*0Sstevel@tonic-gate #include <sys/scsi/impl/commands.h> 51*0Sstevel@tonic-gate #include <sys/scsi/impl/uscsi.h> 52*0Sstevel@tonic-gate #include "badsec.h" 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate char *devname; /* name of device */ 55*0Sstevel@tonic-gate int devfd; /* device file descriptor */ 56*0Sstevel@tonic-gate struct dk_geom dkg; /* geometry */ 57*0Sstevel@tonic-gate struct vtoc vtoc; /* table of contents */ 58*0Sstevel@tonic-gate char *progname; 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate extern struct badsec_lst *badsl_chain; 61*0Sstevel@tonic-gate extern int badsl_chain_cnt; 62*0Sstevel@tonic-gate extern struct badsec_lst *gbadsl_chain; 63*0Sstevel@tonic-gate extern int gbadsl_chain_cnt; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate int alts_fd; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate void 68*0Sstevel@tonic-gate main(argc, argv) 69*0Sstevel@tonic-gate int argc; 70*0Sstevel@tonic-gate char *argv[]; 71*0Sstevel@tonic-gate { 72*0Sstevel@tonic-gate extern int optind; 73*0Sstevel@tonic-gate extern char *optarg; 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate static char options[] = "Ipa:f:"; 76*0Sstevel@tonic-gate char numbuf[100]; 77*0Sstevel@tonic-gate char *nxtarg; 78*0Sstevel@tonic-gate char *alts_name; 79*0Sstevel@tonic-gate minor_t minor_val; 80*0Sstevel@tonic-gate struct stat statbuf; 81*0Sstevel@tonic-gate struct partition *part = NULL; 82*0Sstevel@tonic-gate int alts_slice = -1; 83*0Sstevel@tonic-gate int l; 84*0Sstevel@tonic-gate int p; 85*0Sstevel@tonic-gate int init_flag = 0; 86*0Sstevel@tonic-gate int print_flag = 0; 87*0Sstevel@tonic-gate int c; 88*0Sstevel@tonic-gate int i; 89*0Sstevel@tonic-gate FILE *badsecfd = NULL; 90*0Sstevel@tonic-gate struct badsec_lst *blc_p; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate progname = argv[0]; 93*0Sstevel@tonic-gate while ( (c=getopt(argc, argv, options)) != EOF ) { 94*0Sstevel@tonic-gate switch (c) { 95*0Sstevel@tonic-gate case 'I': 96*0Sstevel@tonic-gate init_flag = 1; 97*0Sstevel@tonic-gate break; 98*0Sstevel@tonic-gate case 'p': 99*0Sstevel@tonic-gate print_flag = 1; 100*0Sstevel@tonic-gate break; 101*0Sstevel@tonic-gate case 'a': 102*0Sstevel@tonic-gate nxtarg = optarg; 103*0Sstevel@tonic-gate for (;*nxtarg != '\0';) 104*0Sstevel@tonic-gate add_gbad(strtol(nxtarg, &nxtarg, 0)); 105*0Sstevel@tonic-gate break; 106*0Sstevel@tonic-gate case 'f': 107*0Sstevel@tonic-gate if ((badsecfd = fopen(optarg, "r")) == NULL) { 108*0Sstevel@tonic-gate fprintf(stderr, "%s: unable to open %s file\n", progname, optarg); 109*0Sstevel@tonic-gate exit(1); 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate break; 112*0Sstevel@tonic-gate default: 113*0Sstevel@tonic-gate giveusage(); 114*0Sstevel@tonic-gate exit(2); 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate /* get the last argument -- device stanza */ 119*0Sstevel@tonic-gate if (argc != optind+1) { 120*0Sstevel@tonic-gate fprintf(stderr, "Missing disk device name\n"); 121*0Sstevel@tonic-gate giveusage(); 122*0Sstevel@tonic-gate exit(3); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate devname = argv[optind]; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate if (stat(devname, &statbuf)) { 127*0Sstevel@tonic-gate fprintf(stderr, "%s: invalid device %s, stat failed\n", progname, devname); 128*0Sstevel@tonic-gate giveusage(); 129*0Sstevel@tonic-gate exit(4); 130*0Sstevel@tonic-gate } 131*0Sstevel@tonic-gate if ((statbuf.st_mode & S_IFMT) != S_IFCHR) { 132*0Sstevel@tonic-gate fprintf(stderr, "%s: device %s is not character special\n", progname, devname); 133*0Sstevel@tonic-gate giveusage(); 134*0Sstevel@tonic-gate exit(5); 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate minor_val = minor(statbuf.st_rdev); 137*0Sstevel@tonic-gate /* 138*0Sstevel@tonic-gate * NEED A DEFINE FOR THE PHYSICAL BIT (0x10) 139*0Sstevel@tonic-gate */ 140*0Sstevel@tonic-gate if ((minor_val & 0x10) == 0) { 141*0Sstevel@tonic-gate fprintf(stderr, "%s: device %s is not a physical slice\n", progname, devname); 142*0Sstevel@tonic-gate giveusage(); 143*0Sstevel@tonic-gate exit(6); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate if ((minor_val % V_NUMPAR) != 0) { 146*0Sstevel@tonic-gate fprintf(stderr, "%s: device %s is not a slice 0 device\n", progname, devname); 147*0Sstevel@tonic-gate giveusage(); 148*0Sstevel@tonic-gate exit(7); 149*0Sstevel@tonic-gate } 150*0Sstevel@tonic-gate if ((devfd=open(devname, O_RDWR)) == -1) { 151*0Sstevel@tonic-gate fprintf(stderr, "%s: open of %s failed\n", progname ,devname); 152*0Sstevel@tonic-gate perror(""); 153*0Sstevel@tonic-gate exit(8); 154*0Sstevel@tonic-gate } 155*0Sstevel@tonic-gate if ((ioctl (devfd, DKIOCGGEOM, &dkg)) == -1) { 156*0Sstevel@tonic-gate fprintf(stderr, "%s: unable to get disk geometry.\n", progname); 157*0Sstevel@tonic-gate perror(""); 158*0Sstevel@tonic-gate exit(9); 159*0Sstevel@tonic-gate } 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate if (ioctl(devfd, DKIOCGVTOC, &vtoc) == -1) 162*0Sstevel@tonic-gate { 163*0Sstevel@tonic-gate fprintf(stderr, "%s: could not get VTOC.\n", progname); 164*0Sstevel@tonic-gate giveusage(); 165*0Sstevel@tonic-gate exit(14); 166*0Sstevel@tonic-gate } 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate if ((vtoc.v_sanity != VTOC_SANE) || (vtoc.v_version != V_VERSION)) { 169*0Sstevel@tonic-gate fprintf(stderr, "%s: invalid VTOC found.\n", progname); 170*0Sstevel@tonic-gate giveusage(); 171*0Sstevel@tonic-gate exit(15); 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate if (badsecfd) 174*0Sstevel@tonic-gate rd_gbad(badsecfd); 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate #ifdef ADDBAD_DEBUG 177*0Sstevel@tonic-gate printf("\n main: Total bad sectors found= %d\n", gbadsl_chain_cnt); 178*0Sstevel@tonic-gate for (blc_p=gbadsl_chain; blc_p; blc_p=blc_p->bl_nxt) { 179*0Sstevel@tonic-gate for (i=0; i<blc_p->bl_cnt; i++) 180*0Sstevel@tonic-gate printf(" badsec=%d ", blc_p->bl_sec[i]); 181*0Sstevel@tonic-gate } 182*0Sstevel@tonic-gate printf("\n"); 183*0Sstevel@tonic-gate #endif 184*0Sstevel@tonic-gate #ifdef PPP 185*0Sstevel@tonic-gate /* 186*0Sstevel@tonic-gate * If init_flag is set, run to completion. 187*0Sstevel@tonic-gate */ 188*0Sstevel@tonic-gate if (gbadsl_chain_cnt == 0 && init_flag == 0) 189*0Sstevel@tonic-gate /* 190*0Sstevel@tonic-gate * No defects and not initializing 191*0Sstevel@tonic-gate */ 192*0Sstevel@tonic-gate exit (0); 193*0Sstevel@tonic-gate #endif 194*0Sstevel@tonic-gate if (gbadsl_chain_cnt != 0) 195*0Sstevel@tonic-gate { 196*0Sstevel@tonic-gate if (try_hw_remap () == SUCCESS) 197*0Sstevel@tonic-gate exit (0); 198*0Sstevel@tonic-gate } 199*0Sstevel@tonic-gate /* 200*0Sstevel@tonic-gate * get ALTS slice 201*0Sstevel@tonic-gate */ 202*0Sstevel@tonic-gate for (i = 0; i < V_NUMPAR && alts_slice == -1; i++) 203*0Sstevel@tonic-gate { 204*0Sstevel@tonic-gate if (vtoc.v_part[i].p_tag == V_ALTSCTR) 205*0Sstevel@tonic-gate { 206*0Sstevel@tonic-gate alts_slice = i; 207*0Sstevel@tonic-gate part = &vtoc.v_part[i]; 208*0Sstevel@tonic-gate } 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate if (alts_slice == -1) 211*0Sstevel@tonic-gate { 212*0Sstevel@tonic-gate fprintf(stderr, "%s: No alternates slice.\n", progname); 213*0Sstevel@tonic-gate exit(16); 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate l = strlen (devname); 216*0Sstevel@tonic-gate sprintf (numbuf, "%d", alts_slice); 217*0Sstevel@tonic-gate p = strlen (numbuf); 218*0Sstevel@tonic-gate alts_name = (char *)malloc (l + p); 219*0Sstevel@tonic-gate strcpy (alts_name, devname); 220*0Sstevel@tonic-gate alts_name[l - 2] = 's'; 221*0Sstevel@tonic-gate strcpy (&alts_name[l - 1], numbuf); 222*0Sstevel@tonic-gate alts_name[l + p - 1] = '\0'; 223*0Sstevel@tonic-gate if ((alts_fd=open(alts_name, O_RDWR)) == -1) { 224*0Sstevel@tonic-gate fprintf(stderr, "%s: open of %s failed\n", progname ,alts_name); 225*0Sstevel@tonic-gate perror(""); 226*0Sstevel@tonic-gate exit(9); 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate if (print_flag) 229*0Sstevel@tonic-gate { 230*0Sstevel@tonic-gate print_altsec (part); 231*0Sstevel@tonic-gate exit (0); 232*0Sstevel@tonic-gate } 233*0Sstevel@tonic-gate updatebadsec(part, init_flag); 234*0Sstevel@tonic-gate wr_altsctr(); 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate if (ioctl(devfd, DKIOCADDBAD, NULL) == -1) { 237*0Sstevel@tonic-gate fprintf(stderr, "Warning: DKIOCADDBAD io control failed. System must be re-booted\n"); 238*0Sstevel@tonic-gate fprintf(stderr, "for alternate sectors to be usable.\n"); 239*0Sstevel@tonic-gate exit(17); 240*0Sstevel@tonic-gate } 241*0Sstevel@tonic-gate sync(); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate fclose(badsecfd); 244*0Sstevel@tonic-gate close (alts_fd); 245*0Sstevel@tonic-gate close (devfd); 246*0Sstevel@tonic-gate exit(0); 247*0Sstevel@tonic-gate } 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate /* 250*0Sstevel@tonic-gate * Giveusage () 251*0Sstevel@tonic-gate * Give a (not so) concise message on how to use this program. 252*0Sstevel@tonic-gate */ 253*0Sstevel@tonic-gate giveusage() 254*0Sstevel@tonic-gate { 255*0Sstevel@tonic-gate fprintf(stderr, "%s [-p] [-a sector] [-f filename] raw-device\n", progname); 256*0Sstevel@tonic-gate fprintf(stderr, " p - Print existing bad block map\n"); 257*0Sstevel@tonic-gate fprintf(stderr, " a - Add the given sectors to the bad block list\n"); 258*0Sstevel@tonic-gate fprintf(stderr, " f - Add the sectors from <filename> to the bad block list\n"); 259*0Sstevel@tonic-gate if (devfd) 260*0Sstevel@tonic-gate close(devfd); 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gate /* 265*0Sstevel@tonic-gate * read in the additional growing bad sectors 266*0Sstevel@tonic-gate */ 267*0Sstevel@tonic-gate rd_gbad(badsecfd) 268*0Sstevel@tonic-gate FILE *badsecfd; 269*0Sstevel@tonic-gate { 270*0Sstevel@tonic-gate int badsec_entry; 271*0Sstevel@tonic-gate int status; 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate status = fscanf(badsecfd, "%d", &badsec_entry); 274*0Sstevel@tonic-gate while (status!=EOF) { 275*0Sstevel@tonic-gate add_gbad(badsec_entry); 276*0Sstevel@tonic-gate status = fscanf(badsecfd, "%d", &badsec_entry); 277*0Sstevel@tonic-gate } 278*0Sstevel@tonic-gate } 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate add_gbad(badsec_entry) 281*0Sstevel@tonic-gate int badsec_entry; 282*0Sstevel@tonic-gate { 283*0Sstevel@tonic-gate struct badsec_lst *blc_p; 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate if (!gbadsl_chain) { 286*0Sstevel@tonic-gate blc_p = (struct badsec_lst *)malloc(BADSLSZ); 287*0Sstevel@tonic-gate if (!blc_p) { 288*0Sstevel@tonic-gate fprintf(stderr, "Unable to allocate memory for additional bad sectors\n"); 289*0Sstevel@tonic-gate exit(18); 290*0Sstevel@tonic-gate } 291*0Sstevel@tonic-gate gbadsl_chain = blc_p; 292*0Sstevel@tonic-gate blc_p->bl_cnt = 0; 293*0Sstevel@tonic-gate blc_p->bl_nxt = 0; 294*0Sstevel@tonic-gate } 295*0Sstevel@tonic-gate for (blc_p = gbadsl_chain; blc_p->bl_nxt; ) 296*0Sstevel@tonic-gate blc_p = blc_p->bl_nxt; 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate if (blc_p->bl_cnt == MAXBLENT) { 299*0Sstevel@tonic-gate blc_p->bl_nxt = (struct badsec_lst *)malloc(BADSLSZ); 300*0Sstevel@tonic-gate if (!blc_p->bl_nxt) { 301*0Sstevel@tonic-gate fprintf(stderr, "Unable to allocate memory for additional bad sectors\n"); 302*0Sstevel@tonic-gate exit(19); 303*0Sstevel@tonic-gate } 304*0Sstevel@tonic-gate blc_p = blc_p->bl_nxt; 305*0Sstevel@tonic-gate blc_p->bl_cnt = 0; 306*0Sstevel@tonic-gate blc_p->bl_nxt = 0; 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate blc_p->bl_sec[blc_p->bl_cnt++] = badsec_entry; 309*0Sstevel@tonic-gate gbadsl_chain_cnt++; 310*0Sstevel@tonic-gate } 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gate /* 313*0Sstevel@tonic-gate * Map a block using hardware (SCSI) techniques. 314*0Sstevel@tonic-gate */ 315*0Sstevel@tonic-gate /*ARGSUSED*/ 316*0Sstevel@tonic-gate int 317*0Sstevel@tonic-gate hardware_remap (bn) 318*0Sstevel@tonic-gate int bn; 319*0Sstevel@tonic-gate { 320*0Sstevel@tonic-gate u_int byte_swap_32 (u_int); 321*0Sstevel@tonic-gate u_short byte_swap_16 (u_short); 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate struct uscsi_cmd ucmd; 324*0Sstevel@tonic-gate union scsi_cdb cdb; 325*0Sstevel@tonic-gate struct scsi_reassign_blk defect_list; 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate /* 328*0Sstevel@tonic-gate * Build and execute the uscsi ioctl 329*0Sstevel@tonic-gate */ 330*0Sstevel@tonic-gate (void) memset((char *)&ucmd, 0, sizeof (ucmd)); 331*0Sstevel@tonic-gate (void) memset((char *)&cdb, 0, sizeof (union scsi_cdb)); 332*0Sstevel@tonic-gate (void) memset((char *)&defect_list, 0, 333*0Sstevel@tonic-gate sizeof (struct scsi_reassign_blk)); 334*0Sstevel@tonic-gate cdb.scc_cmd = SCMD_REASSIGN_BLOCK; 335*0Sstevel@tonic-gate ucmd.uscsi_cdb = (caddr_t) &cdb; 336*0Sstevel@tonic-gate ucmd.uscsi_cdblen = CDB_GROUP0; 337*0Sstevel@tonic-gate ucmd.uscsi_bufaddr = (caddr_t) &defect_list; 338*0Sstevel@tonic-gate ucmd.uscsi_buflen = sizeof (struct scsi_reassign_blk); 339*0Sstevel@tonic-gate defect_list.length = byte_swap_16 (sizeof (defect_list.defect)); 340*0Sstevel@tonic-gate defect_list.defect = byte_swap_32 (bn); 341*0Sstevel@tonic-gate /* 342*0Sstevel@tonic-gate printf ("length - %x %x\n", sizeof (defect_list.defect), defect_list.length); 343*0Sstevel@tonic-gate printf ("defect - %x %x\n", bn, defect_list.defect); 344*0Sstevel@tonic-gate */ 345*0Sstevel@tonic-gate /* 346*0Sstevel@tonic-gate * Set function flags for driver. 347*0Sstevel@tonic-gate */ 348*0Sstevel@tonic-gate ucmd.uscsi_flags = USCSI_ISOLATE | USCSI_DIAGNOSE | USCSI_SILENT; 349*0Sstevel@tonic-gate ucmd.uscsi_timeout = 30; /* 30 seconds */ 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gate /* 352*0Sstevel@tonic-gate * Execute the ioctl 353*0Sstevel@tonic-gate */ 354*0Sstevel@tonic-gate if (ioctl(devfd, USCSICMD, &ucmd) == -1) 355*0Sstevel@tonic-gate { 356*0Sstevel@tonic-gate if (errno != ENOTTY) 357*0Sstevel@tonic-gate { 358*0Sstevel@tonic-gate perror ("SCSI hardware re-assign failed"); 359*0Sstevel@tonic-gate /* 360*0Sstevel@tonic-gate * It looks like a failure but by returning success 361*0Sstevel@tonic-gate * the upper layer will not try to do 362*0Sstevel@tonic-gate * software remapping. 363*0Sstevel@tonic-gate */ 364*0Sstevel@tonic-gate return (SUCCESS); 365*0Sstevel@tonic-gate } 366*0Sstevel@tonic-gate return (FAILURE); 367*0Sstevel@tonic-gate } 368*0Sstevel@tonic-gate return (SUCCESS); 369*0Sstevel@tonic-gate } 370*0Sstevel@tonic-gate 371*0Sstevel@tonic-gate u_int 372*0Sstevel@tonic-gate byte_swap_32 (u_int nav) 373*0Sstevel@tonic-gate { 374*0Sstevel@tonic-gate u_int rc; 375*0Sstevel@tonic-gate rc = ((nav & 0xff000000) >> 24) | ((nav & 0x00ff0000) >> 8) | 376*0Sstevel@tonic-gate ((nav & 0x0000ff00) << 8) | ((nav & 0x000000ff) << 24); 377*0Sstevel@tonic-gate return (rc); 378*0Sstevel@tonic-gate } 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate u_short 381*0Sstevel@tonic-gate byte_swap_16 (u_short niv) 382*0Sstevel@tonic-gate { 383*0Sstevel@tonic-gate u_short rc; 384*0Sstevel@tonic-gate rc = (u_short)((int)(niv & 0xff00) >> 8) | ((niv & 0x00ff) << 8); 385*0Sstevel@tonic-gate return (rc); 386*0Sstevel@tonic-gate } 387*0Sstevel@tonic-gate 388*0Sstevel@tonic-gate try_hw_remap () 389*0Sstevel@tonic-gate { 390*0Sstevel@tonic-gate struct badsec_lst *blc_p; 391*0Sstevel@tonic-gate int i; 392*0Sstevel@tonic-gate 393*0Sstevel@tonic-gate for (blc_p = gbadsl_chain; blc_p != 0; blc_p = blc_p->bl_nxt) 394*0Sstevel@tonic-gate { 395*0Sstevel@tonic-gate 396*0Sstevel@tonic-gate for (i = 0; i < blc_p->bl_cnt; i++) 397*0Sstevel@tonic-gate if (hardware_remap (blc_p->bl_sec[i]) == FAILURE) 398*0Sstevel@tonic-gate return (FAILURE); 399*0Sstevel@tonic-gate } 400*0Sstevel@tonic-gate return (SUCCESS); 401*0Sstevel@tonic-gate } 402