1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * This file contains routines to analyze the surface of a disk. 28 */ 29 #include "global.h" 30 #include "analyze.h" 31 #include <stdlib.h> 32 #include <errno.h> 33 #include "misc.h" 34 #include "defect.h" 35 #include "label.h" 36 #include "param.h" 37 #include "checkdev.h" 38 39 40 /* 41 * These global variables control the surface analysis process. They 42 * are set from a command in the defect menu. 43 */ 44 int scan_entire = 1; /* scan whole disk flag */ 45 diskaddr_t scan_lower = 0; /* lower bound */ 46 diskaddr_t scan_upper = 0; /* upper bound */ 47 int scan_correct = 1; /* correct errors flag */ 48 int scan_stop = 0; /* stop after error flag */ 49 int scan_loop = 0; /* loop forever flag */ 50 int scan_passes = 2; /* number of passes */ 51 int scan_random = 0; /* random patterns flag */ 52 uint_t scan_size = 0; /* sectors/scan operation */ 53 int scan_auto = 1; /* scan after format flag */ 54 int scan_restore_defects = 1; /* restore defect list after writing */ 55 int scan_restore_label = 1; /* restore label after writing */ 56 57 /* 58 * These are summary variables to print out info after analysis. 59 * Values less than 0 imply they are invalid. 60 */ 61 offset_t scan_cur_block = -1; /* current block */ 62 int64_t scan_blocks_fixed = -1; /* # blocks repaired */ 63 64 /* 65 * This variable is used to tell whether the most recent surface 66 * analysis error was caused by a media defect or some other problem. 67 */ 68 int media_error; /* error was caused by defect */ 69 70 int disk_error; /* disk errors during analysis */ 71 72 /* 73 * These are the data patterns used if random patterns are not chosen. 74 * They are designed to show pattern dependent errors. 75 */ 76 static unsigned int scan_patterns[] = { 77 0xc6dec6de, 78 0x6db6db6d, 79 0x00000000, 80 0xffffffff, 81 0xaaaaaaaa, 82 }; 83 #define NPATTERNS 5 /* number of predefined patterns */ 84 85 /* 86 * These are the data patterns from the SunFed requirements document. 87 */ 88 static unsigned int purge_patterns[] = { /* patterns to be written */ 89 0xaaaaaaaa, /* 10101010... */ 90 0x55555555, /* 01010101... == UUUU... */ 91 0xaaaaaaaa, /* 10101010... */ 92 0xaaaaaaaa, /* 10101010... */ 93 }; 94 95 static unsigned int alpha_pattern = 0x40404040; /* 10000000... == @@@@... */ 96 97 static int scan_repair(diskaddr_t bn, int mode); 98 static int analyze_blocks(int flags, diskaddr_t blkno, uint_t blkcnt, 99 unsigned data, int init, int driver_flags, int *xfercntp); 100 static int handle_error_conditions(void); 101 static int verify_blocks(int flags, diskaddr_t blkno, uint_t blkcnt, 102 unsigned data, int driver_flags, int *xfercntp); 103 104 /* 105 * This routine performs a surface analysis based upon the global 106 * parameters. It is called from several commands in the defect menu, 107 * and from the format command in the command menu (if post-format 108 * analysis is enable). 109 */ 110 int 111 do_scan(int flags, int mode) 112 { 113 diskaddr_t start, end, curnt; 114 int pass, needinit, data = alpha_pattern; 115 uint_t size; 116 int status, founderr, i, j; 117 int error = 0; 118 int pattern = 0; 119 int xfercnt; 120 121 /* 122 * Check to be sure we aren't correcting without a defect list 123 * if the controller can correct the defect. 124 */ 125 if (scan_correct && !EMBEDDED_SCSI && (cur_ops->op_repair != NULL) && 126 (cur_list.list == NULL)) { 127 err_print("Current Defect List must be initialized "); 128 err_print("to do automatic repair.\n"); 129 return (-1); 130 } 131 /* 132 * Define the bounds of the scan. 133 */ 134 if (scan_entire) { 135 start = 0; 136 end = 0; 137 if (cur_label == L_TYPE_SOLARIS) { 138 if (cur_ctype->ctype_flags & CF_SCSI) 139 end = datasects() - 1; 140 else 141 end = physsects() - 1; 142 } else if (cur_label == L_TYPE_EFI) { 143 end = cur_parts->etoc->efi_last_lba; 144 } 145 } else { 146 start = scan_lower; 147 end = scan_upper; 148 } 149 /* 150 * Make sure the user knows if we are scanning over a mounted 151 * partition. 152 */ 153 if ((flags & (SCAN_PATTERN | SCAN_WRITE)) && 154 (checkmount(start, end))) { 155 err_print("Cannot do analysis on a mounted partition.\n"); 156 return (-1); 157 } 158 159 /* 160 * Make sure the user knows if we are scanning over a 161 * partition being used for swapping. 162 */ 163 if ((flags & (SCAN_PATTERN | SCAN_WRITE)) && 164 (checkswap(start, end))) { 165 err_print("Cannot do analysis on a partition \ 166 which is currently being used for swapping.\n"); 167 return (-1); 168 } 169 170 /* 171 * Check to see if any partitions used for svm, vxvm, ZFS zpool 172 * or live upgrade are on the disk. 173 */ 174 if ((flags & (SCAN_PATTERN | SCAN_WRITE)) && 175 (checkdevinuse(cur_disk->disk_name, (diskaddr_t)-1, 176 (diskaddr_t)-1, 0, 0))) { 177 err_print("Cannot do analysis on a partition " 178 "while it in use as described above.\n"); 179 return (-1); 180 } 181 182 /* 183 * If we are scanning destructively over certain sectors, 184 * we mark the defect list and/or label dirty so it will get rewritten. 185 */ 186 if (flags & (SCAN_PATTERN | SCAN_WRITE)) { 187 if (cur_label == L_TYPE_SOLARIS) { 188 if (start < (diskaddr_t)totalsects() && 189 end >= (diskaddr_t)datasects()) { 190 if (!EMBEDDED_SCSI) { 191 cur_list.flags |= LIST_DIRTY; 192 } 193 if (cur_disk->disk_flags & DSK_LABEL) 194 cur_flags |= LABEL_DIRTY; 195 } 196 } 197 if (start == 0) { 198 if (cur_disk->disk_flags & DSK_LABEL) 199 cur_flags |= LABEL_DIRTY; 200 } 201 } 202 /* 203 * Initialize the summary info on sectors repaired. 204 */ 205 scan_blocks_fixed = 0; 206 /* 207 * Loop through the passes of the scan. If required, loop forever. 208 */ 209 for (pass = 0; pass < scan_passes || scan_loop; pass++) { 210 /* 211 * Determine the data pattern to use if pattern testing 212 * is to be done. 213 */ 214 if (flags & SCAN_PATTERN) { 215 if (scan_random) 216 data = (int)mrand48(); 217 else 218 data = scan_patterns[pass % NPPATTERNS]; 219 220 if (flags & SCAN_PURGE) { 221 flags &= ~(SCAN_PURGE_READ_PASS 222 | SCAN_PURGE_ALPHA_PASS); 223 switch (pattern % (NPPATTERNS + 1)) { 224 case NPPATTERNS: 225 pattern = 0; 226 if (!error) { 227 fmt_print( 228 "\nThe last %d passes were successful, running alpha pattern pass", NPPATTERNS); 229 flags |= SCAN_PURGE_ALPHA_PASS; 230 data = alpha_pattern; 231 } else { 232 data = purge_patterns[pattern]; 233 pattern++; 234 }; 235 break; 236 case READPATTERN: 237 flags |= SCAN_PURGE_READ_PASS; 238 /* FALLTHROUGH */ 239 default: 240 data = purge_patterns[pattern]; 241 pattern++; 242 break; 243 } 244 } 245 fmt_print("\n pass %d", pass); 246 fmt_print(" - pattern = 0x%x", data); 247 } else 248 fmt_print("\n pass %d", pass); 249 250 fmt_print("\n"); 251 /* 252 * Mark the pattern buffer as corrupt, since it 253 * hasn't been initialized. 254 */ 255 needinit = 1; 256 /* 257 * Print the first block number to the log file if 258 * logging is on so there is some record of what 259 * analysis was performed. 260 */ 261 if (log_file) { 262 pr_dblock(log_print, start); 263 log_print("\n"); 264 } 265 /* 266 * Loop through this pass, each time analyzing an amount 267 * specified by the global parameters. 268 */ 269 xfercnt = 0; 270 for (curnt = start; curnt <= end; curnt += size) { 271 if ((end - curnt) < scan_size) 272 size = end - curnt + 1; 273 else 274 size = scan_size; 275 /* 276 * Print out where we are, so we don't look dead. 277 * Also store it in summary info for logging. 278 */ 279 scan_cur_block = curnt; 280 nolog_print(" "); 281 pr_dblock(nolog_print, curnt); 282 nolog_print(" \015"); 283 (void) fflush(stdout); 284 disk_error = 0; 285 /* 286 * Do the actual analysis. 287 */ 288 status = analyze_blocks(flags, curnt, size, 289 (unsigned)data, needinit, (F_ALLERRS | F_SILENT), 290 &xfercnt); 291 /* 292 * If there were no errors, the pattern buffer is 293 * still initialized, and we just loop to next chunk. 294 */ 295 needinit = 0; 296 if (!status) 297 continue; 298 /* 299 * There was an error. Check if surface analysis 300 * can be continued. 301 */ 302 if (handle_error_conditions()) { 303 scan_blocks_fixed = scan_cur_block = -1; 304 return (-1); 305 } 306 /* 307 * There was an error. Mark the pattern buffer 308 * corrupt so it will get reinitialized. 309 */ 310 needinit = 1; 311 /* 312 * If it was not a media error, ignore it. 313 */ 314 if (!media_error) 315 continue; 316 /* 317 * Loop 5 times through each sector of the chunk, 318 * analyzing them individually. 319 */ 320 nolog_print(" "); 321 pr_dblock(nolog_print, curnt); 322 nolog_print(" \015"); 323 (void) fflush(stdout); 324 founderr = 0; 325 for (j = 0; j < size * 5; j++) { 326 i = j % size; 327 disk_error = 0; 328 status = analyze_blocks(flags, (curnt + i), 1, 329 (unsigned)data, needinit, F_ALLERRS, NULL); 330 needinit = 0; 331 if (!status) 332 continue; 333 /* 334 * There was an error. Check if surface analysis 335 * can be continued. 336 */ 337 if (handle_error_conditions()) { 338 scan_blocks_fixed = scan_cur_block = -1; 339 return (-1); 340 } 341 /* 342 * An error occurred. Mark the buffer 343 * corrupt and see if it was media 344 * related. 345 */ 346 needinit = 1; 347 if (!media_error) 348 continue; 349 /* 350 * We found a bad sector. Print out a message 351 * and fix it if required. 352 */ 353 founderr = 1; 354 if (scan_correct && (flags != SCAN_VALID)) { 355 if (scan_repair(curnt+i, mode)) { 356 error = -1; 357 } 358 } else 359 err_print("\n"); 360 /* 361 * Stop after the error if required. 362 */ 363 if (scan_stop) 364 goto out; 365 } 366 /* 367 * Mark the pattern buffer corrupt to be safe. 368 */ 369 needinit = 1; 370 /* 371 * We didn't find an individual sector that was bad. 372 * Print out a warning. 373 */ 374 if (!founderr) { 375 err_print("Warning: unable to pinpoint "); 376 err_print("defective block.\n"); 377 } 378 } 379 /* 380 * Print the end of each pass to the log file. 381 */ 382 enter_critical(); 383 if (log_file) { 384 pr_dblock(log_print, scan_cur_block); 385 log_print("\n"); 386 } 387 scan_cur_block = -1; 388 exit_critical(); 389 fmt_print("\n"); 390 391 /* 392 * alternate the read and write for SCAN_VERIFY test 393 */ 394 if (flags & SCAN_VERIFY) { 395 flags ^= SCAN_VERIFY_READ_PASS; 396 } 397 } 398 out: 399 /* 400 * We got here either by giving up after an error or falling 401 * through after all passes were completed. 402 */ 403 fmt_print("\n"); 404 enter_critical(); 405 /* 406 * If the defect list is dirty, write it to disk, 407 * if scan_restore_defects (the default) is true. 408 */ 409 if (!EMBEDDED_SCSI && (cur_list.flags & LIST_DIRTY) && 410 (scan_restore_defects)) { 411 cur_list.flags = 0; 412 write_deflist(&cur_list); 413 } 414 /* 415 * If the label is dirty, write it to disk. 416 * if scan_restore_label (the default) is true. 417 */ 418 if ((cur_flags & LABEL_DIRTY) && (scan_restore_label)) { 419 cur_flags &= ~LABEL_DIRTY; 420 (void) write_label(); 421 } 422 /* 423 * If we dropped down to here after an error, we need to write 424 * the final block number to the log file for record keeping. 425 */ 426 if (log_file && scan_cur_block >= 0) { 427 pr_dblock(log_print, scan_cur_block); 428 log_print("\n"); 429 } 430 fmt_print("Total of %lld defective blocks repaired.\n", 431 scan_blocks_fixed); 432 /* 433 * Reinitialize the logging variables so they don't get used 434 * when they are not really valid. 435 */ 436 scan_blocks_fixed = scan_cur_block = -1; 437 exit_critical(); 438 return (error); 439 } 440 441 442 /* 443 * This routine is called to repair a bad block discovered 444 * during a scan operation. Return 0 for success, 1 for failure. 445 * (This has been extracted out of do_scan(), to simplify it.) 446 */ 447 static int 448 scan_repair(diskaddr_t bn, int mode) 449 { 450 int status; 451 int result = 1; 452 char *buf; 453 int buf_is_good; 454 int i; 455 456 if (cur_ops->op_repair == NULL) { 457 err_print("Warning: Controller does "); 458 err_print("not support repairing.\n\n"); 459 return (result); 460 } 461 462 buf = malloc(cur_blksz); 463 if (buf == NULL) { 464 err_print("Warning: no memory.\n\n"); 465 return (result); 466 } 467 enter_critical(); 468 469 /* 470 * Determine if the error appears to be hard or soft. We 471 * already assume there's an error. If we can get any 472 * good data out of the sector, write that data back 473 * after the repair. 474 */ 475 buf_is_good = 0; 476 for (i = 0; i < 5; i++) { 477 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, bn, 1, 478 buf, F_SILENT, NULL); 479 if (status == 0) { 480 buf_is_good = 1; 481 break; 482 } 483 } 484 485 fmt_print("Repairing %s error on %llu (", 486 buf_is_good ? "soft" : "hard", bn); 487 pr_dblock(fmt_print, bn); 488 fmt_print(")..."); 489 490 status = (*cur_ops->op_repair)(bn, mode); 491 if (status) { 492 /* 493 * If the repair failed, we note it and will return the 494 * failure. However, the analysis goes on. 495 */ 496 fmt_print("failed.\n\n"); 497 } else { 498 /* 499 * The repair worked. Write the good data we could 500 * recover from the failed block, if possible. 501 * If not, zero the block. In doing so, try to 502 * determine if the new block appears ok. 503 */ 504 if (!buf_is_good) { 505 bzero(buf, cur_blksz); 506 fmt_print("Warning: Block %llu zero-filled.\n", bn); 507 } else { 508 fmt_print("ok.\n"); 509 } 510 status = (*cur_ops->op_rdwr)(DIR_WRITE, cur_file, bn, 511 1, buf, (F_SILENT | F_ALLERRS), NULL); 512 if (status == 0) { 513 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, bn, 514 1, buf, (F_SILENT | F_ALLERRS), NULL); 515 } 516 if (status) { 517 fmt_print("The new block also appears defective.\n"); 518 } 519 fmt_print("\n"); 520 /* 521 * add the defect to the list and write the list out. 522 * Also, kill the working list so it will get resynced 523 * with the current list. 524 * 525 * For embedded scsi, we don't require a defect list. 526 * However, if we have one, add the defect if the 527 * list includes the grown list. If not, kill it 528 * to force a resync if we need the list later. 529 */ 530 if (EMBEDDED_SCSI) { 531 if (cur_list.list != NULL) { 532 if (cur_list.flags & LIST_PGLIST) { 533 add_ldef(bn, &cur_list); 534 } else { 535 kill_deflist(&cur_list); 536 } 537 } 538 /* 539 * The next "if" statement reflects the fix for 540 * bug id 1026096 where format keeps adding the 541 * same defect to the defect list. 542 */ 543 } else if (cur_ctype->ctype_flags & CF_WLIST) { 544 kill_deflist(&cur_list); 545 if (*cur_ops->op_ex_cur != NULL) { 546 (void) (*cur_ops->op_ex_cur)(&cur_list); 547 fmt_print("Current list updated\n"); 548 } 549 } else { 550 add_ldef(bn, &cur_list); 551 write_deflist(&cur_list); 552 } 553 kill_deflist(&work_list); 554 555 /* Log the repair. */ 556 scan_blocks_fixed++; 557 558 /* return ok */ 559 result = 0; 560 } 561 562 exit_critical(); 563 free(buf); 564 return (result); 565 } 566 567 568 /* 569 * This routine analyzes a set of sectors on the disk. It simply returns 570 * an error if a defect is found. It is called by do_scan(). 571 */ 572 static int 573 analyze_blocks(int flags, diskaddr_t blkno, uint_t blkcnt, unsigned data, 574 int init, int driver_flags, int *xfercntp) 575 { 576 int corrupt = 0; 577 int status; 578 diskaddr_t i, nints; 579 unsigned *ptr = (uint_t *)pattern_buf; 580 581 media_error = 0; 582 if (flags & SCAN_VERIFY) { 583 return (verify_blocks(flags, blkno, blkcnt, data, 584 driver_flags, xfercntp)); 585 } 586 587 /* 588 * Initialize the pattern buffer if necessary. 589 */ 590 nints = (diskaddr_t)blkcnt * cur_blksz / sizeof (int); 591 if ((flags & SCAN_PATTERN) && init) { 592 for (i = 0; i < nints; i++) 593 *((int *)((int *)pattern_buf + i)) = data; 594 } 595 /* 596 * Lock out interrupts so we can insure valid data will get 597 * restored. This is necessary because there are modes 598 * of scanning that corrupt the disk data then restore it at 599 * the end of the analysis. 600 */ 601 enter_critical(); 602 /* 603 * If the disk data is valid, read it into the data buffer. 604 */ 605 if (flags & SCAN_VALID) { 606 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, blkno, 607 blkcnt, (caddr_t)cur_buf, driver_flags, xfercntp); 608 if (status) 609 goto bad; 610 } 611 /* 612 * If we are doing pattern testing, write and read the pattern 613 * from the pattern buffer. 614 */ 615 if (flags & SCAN_PATTERN) { 616 /* 617 * If the disk data was valid, mark it corrupt so we know 618 * to restore it later. 619 */ 620 if (flags & SCAN_VALID) 621 corrupt++; 622 /* 623 * Only write if we're not on the read pass of SCAN_PURGE. 624 */ 625 if (!(flags & SCAN_PURGE_READ_PASS)) { 626 status = (*cur_ops->op_rdwr)(DIR_WRITE, cur_file, blkno, 627 blkcnt, (caddr_t)pattern_buf, driver_flags, 628 xfercntp); 629 if (status) 630 goto bad; 631 } 632 /* 633 * Only read if we are on the read pass of SCAN_PURGE, if we 634 * are purging. 635 */ 636 if ((!(flags & SCAN_PURGE)) || (flags & SCAN_PURGE_READ_PASS)) { 637 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, blkno, 638 blkcnt, (caddr_t)pattern_buf, driver_flags, 639 xfercntp); 640 if (status) 641 goto bad; 642 } 643 } 644 /* 645 * If we are doing a data compare, make sure the pattern 646 * came back intact. 647 * Only compare if we are on the read pass of SCAN_PURGE, or 648 * we wrote random data instead of the expected data pattern. 649 */ 650 if ((flags & SCAN_COMPARE) || (flags & SCAN_PURGE_READ_PASS)) { 651 for (i = nints, ptr = (uint_t *)pattern_buf; i; i--) 652 if (*ptr++ != data) { 653 err_print("Data miscompare error (expecting "); 654 err_print("0x%x, got 0x%x) at ", data, 655 *((int *)((int *)pattern_buf + 656 (nints - i)))); 657 pr_dblock(err_print, blkno); 658 err_print(", offset = 0x%llx.\n", 659 (nints - i) * sizeof (int)); 660 goto bad; 661 } 662 } 663 /* 664 * If we are supposed to write data out, do so. 665 */ 666 if (flags & SCAN_WRITE) { 667 status = (*cur_ops->op_rdwr)(DIR_WRITE, cur_file, blkno, 668 blkcnt, (caddr_t)cur_buf, driver_flags, xfercntp); 669 if (status) 670 goto bad; 671 } 672 exit_critical(); 673 /* 674 * No errors occurred, return ok. 675 */ 676 return (0); 677 bad: 678 /* 679 * There was an error. If the data was corrupted, we write it 680 * out from the data buffer to restore it. 681 */ 682 if (corrupt) { 683 if ((*cur_ops->op_rdwr)(DIR_WRITE, cur_file, blkno, 684 blkcnt, (caddr_t)cur_buf, F_NORMAL, xfercntp)) 685 err_print( 686 "Warning: unable to restore original data.\n"); 687 } 688 exit_critical(); 689 /* 690 * Return the error. 691 */ 692 return (-1); 693 } 694 695 696 /* 697 * This routine analyzes a set of sectors on the disk. It simply returns 698 * an error if a defect is found. It is called by analyze_blocks(). 699 * For simplicity, this is done as a separate function instead of 700 * making the analyze_block routine complex. 701 * 702 * This routine implements the 'verify' command. It writes the disk 703 * by writing unique data for each block; after the write pass, it 704 * reads the data and verifies for correctness. Note that the entire 705 * disk (or the range of disk) is fully written first and then read. 706 * This should eliminate any caching effect on the drives. 707 */ 708 static int 709 verify_blocks(int flags, diskaddr_t blkno, uint_t blkcnt, unsigned data, 710 int driver_flags, int *xfercntp) 711 { 712 int status, i, nints; 713 unsigned *ptr = (uint_t *)pattern_buf; 714 715 nints = cur_blksz / sizeof (int); 716 717 /* 718 * Initialize the pattern buffer if we are in write pass. 719 * Use the block number itself as data, each block has unique 720 * buffer data that way. 721 */ 722 if (!(flags & SCAN_VERIFY_READ_PASS)) { 723 for (data = blkno; data < blkno + blkcnt; data++) { 724 for (i = 0; i < nints; i++) { 725 *ptr++ = data; 726 } 727 } 728 ptr = (uint_t *)pattern_buf; 729 } 730 731 /* 732 * Only write if we're not on the read pass of SCAN_VERIFY. 733 */ 734 if (!(flags & SCAN_VERIFY_READ_PASS)) { 735 status = (*cur_ops->op_rdwr)(DIR_WRITE, cur_file, blkno, 736 blkcnt, (caddr_t)pattern_buf, driver_flags, xfercntp); 737 if (status) 738 goto bad; 739 } else { 740 /* 741 * Only read if we are on the read pass of SCAN_VERIFY 742 */ 743 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, blkno, 744 blkcnt, (caddr_t)pattern_buf, driver_flags, xfercntp); 745 if (status) 746 goto bad; 747 /* 748 * compare and make sure the pattern came back intact. 749 */ 750 for (data = blkno; data < blkno + blkcnt; data++) { 751 for (i = 0; i < nints; i++) { 752 if (*ptr++ != data) { 753 ptr--; 754 err_print("Data miscompare error " 755 "(expecting 0x%x, got 0x%x) at ", 756 data, *ptr); 757 pr_dblock(err_print, blkno); 758 err_print(", offset = 0x%x.\n", 759 (ptr - (uint_t *)pattern_buf) * 760 sizeof (int)); 761 goto bad; 762 } 763 } 764 } 765 } 766 /* 767 * No errors occurred, return ok. 768 */ 769 return (0); 770 bad: 771 return (-1); 772 } 773 774 775 static int 776 handle_error_conditions(void) 777 { 778 779 /* 780 * Check if the errno is ENXIO. 781 */ 782 if (errno == ENXIO) { 783 fmt_print("\n\nWarning:Cannot access drive, "); 784 fmt_print("aborting surface analysis.\n"); 785 return (-1); 786 } 787 /* 788 * check for disk errors 789 */ 790 switch (disk_error) { 791 case DISK_STAT_RESERVED: 792 case DISK_STAT_UNAVAILABLE: 793 fmt_print("\n\nWarning:Drive may be reserved "); 794 fmt_print("or has been removed, "); 795 fmt_print("aborting surface analysis.\n"); 796 return (-1); 797 case DISK_STAT_NOTREADY: 798 fmt_print("\n\nWarning: Drive not ready, "); 799 fmt_print("aborting surface analysis.\n"); 800 return (-1); 801 case DISK_STAT_DATA_PROTECT: 802 fmt_print("\n\nWarning: Drive is write protected, "); 803 fmt_print("aborting surface analysis.\n"); 804 return (-1); 805 default: 806 break; 807 } 808 return (0); 809 } 810