diff options
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/hdparm.c | 884 |
1 files changed, 350 insertions, 534 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 5b51f71d0..bf24a2d3a 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
| @@ -181,11 +181,11 @@ static const char * const pkt_str[] = { | |||
| 181 | "", /* word 0, bits 12-8 = 1c */ | 181 | "", /* word 0, bits 12-8 = 1c */ |
| 182 | "", /* word 0, bits 12-8 = 1d */ | 182 | "", /* word 0, bits 12-8 = 1d */ |
| 183 | "", /* word 0, bits 12-8 = 1e */ | 183 | "", /* word 0, bits 12-8 = 1e */ |
| 184 | "Unknown", /* word 0, bits 12-8 = 1f */ | 184 | "Unknown", /* word 0, bits 12-8 = 1f */ |
| 185 | }; | 185 | }; |
| 186 | 186 | ||
| 187 | static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */ | 187 | static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */ |
| 188 | "reserved", /* bit 0 */ | 188 | "Reserved", /* bit 0 */ |
| 189 | "hard sectored", /* bit 1 */ | 189 | "hard sectored", /* bit 1 */ |
| 190 | "soft sectored", /* bit 2 */ | 190 | "soft sectored", /* bit 2 */ |
| 191 | "not MFM encoded ", /* bit 3 */ | 191 | "not MFM encoded ", /* bit 3 */ |
| @@ -263,39 +263,39 @@ static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */ | |||
| 263 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | 263 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
| 264 | static const char *minor_str[MINOR_MAX+2] = { /* word 81 value: */ | 264 | static const char *minor_str[MINOR_MAX+2] = { /* word 81 value: */ |
| 265 | "Unspecified", /* 0x0000 */ | 265 | "Unspecified", /* 0x0000 */ |
| 266 | "ATA-1 X3T9.2 781D prior to revision 4", /* 0x0001 */ | 266 | "ATA-1 X3T9.2 781D prior to rev.4", /* 0x0001 */ |
| 267 | "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */ | 267 | "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */ |
| 268 | "ATA-1 X3T9.2 781D revision 4", /* 0x0003 */ | 268 | "ATA-1 X3T9.2 781D rev.4", /* 0x0003 */ |
| 269 | "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */ | 269 | "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */ |
| 270 | "ATA-2 X3T10 948D prior to revision 2k", /* 0x0005 */ | 270 | "ATA-2 X3T10 948D prior to rev.2k", /* 0x0005 */ |
| 271 | "ATA-3 X3T10 2008D revision 1", /* 0x0006 */ | 271 | "ATA-3 X3T10 2008D rev.1", /* 0x0006 */ |
| 272 | "ATA-2 X3T10 948D revision 2k", /* 0x0007 */ | 272 | "ATA-2 X3T10 948D rev.2k", /* 0x0007 */ |
| 273 | "ATA-3 X3T10 2008D revision 0", /* 0x0008 */ | 273 | "ATA-3 X3T10 2008D rev.0", /* 0x0008 */ |
| 274 | "ATA-2 X3T10 948D revision 3", /* 0x0009 */ | 274 | "ATA-2 X3T10 948D rev.3", /* 0x0009 */ |
| 275 | "ATA-3 published, ANSI X3.298-199x", /* 0x000a */ | 275 | "ATA-3 published, ANSI X3.298-199x", /* 0x000a */ |
| 276 | "ATA-3 X3T10 2008D revision 6", /* 0x000b */ | 276 | "ATA-3 X3T10 2008D rev.6", /* 0x000b */ |
| 277 | "ATA-3 X3T13 2008D revision 7 and 7a", /* 0x000c */ | 277 | "ATA-3 X3T13 2008D rev.7 and 7a", /* 0x000c */ |
| 278 | "ATA/ATAPI-4 X3T13 1153D revision 6", /* 0x000d */ | 278 | "ATA/ATAPI-4 X3T13 1153D rev.6", /* 0x000d */ |
| 279 | "ATA/ATAPI-4 T13 1153D revision 13", /* 0x000e */ | 279 | "ATA/ATAPI-4 T13 1153D rev.13", /* 0x000e */ |
| 280 | "ATA/ATAPI-4 X3T13 1153D revision 7", /* 0x000f */ | 280 | "ATA/ATAPI-4 X3T13 1153D rev.7", /* 0x000f */ |
| 281 | "ATA/ATAPI-4 T13 1153D revision 18", /* 0x0010 */ | 281 | "ATA/ATAPI-4 T13 1153D rev.18", /* 0x0010 */ |
| 282 | "ATA/ATAPI-4 T13 1153D revision 15", /* 0x0011 */ | 282 | "ATA/ATAPI-4 T13 1153D rev.15", /* 0x0011 */ |
| 283 | "ATA/ATAPI-4 published, ANSI INCITS 317-1998", /* 0x0012 */ | 283 | "ATA/ATAPI-4 published, ANSI INCITS 317-1998", /* 0x0012 */ |
| 284 | "ATA/ATAPI-5 T13 1321D revision 3", | 284 | "ATA/ATAPI-5 T13 1321D rev.3", |
| 285 | "ATA/ATAPI-4 T13 1153D revision 14", /* 0x0014 */ | 285 | "ATA/ATAPI-4 T13 1153D rev.14", /* 0x0014 */ |
| 286 | "ATA/ATAPI-5 T13 1321D revision 1", /* 0x0015 */ | 286 | "ATA/ATAPI-5 T13 1321D rev.1", /* 0x0015 */ |
| 287 | "ATA/ATAPI-5 published, ANSI INCITS 340-2000", /* 0x0016 */ | 287 | "ATA/ATAPI-5 published, ANSI INCITS 340-2000", /* 0x0016 */ |
| 288 | "ATA/ATAPI-4 T13 1153D revision 17", /* 0x0017 */ | 288 | "ATA/ATAPI-4 T13 1153D rev.17", /* 0x0017 */ |
| 289 | "ATA/ATAPI-6 T13 1410D revision 0", /* 0x0018 */ | 289 | "ATA/ATAPI-6 T13 1410D rev.0", /* 0x0018 */ |
| 290 | "ATA/ATAPI-6 T13 1410D revision 3a", /* 0x0019 */ | 290 | "ATA/ATAPI-6 T13 1410D rev.3a", /* 0x0019 */ |
| 291 | "ATA/ATAPI-7 T13 1532D revision 1", /* 0x001a */ | 291 | "ATA/ATAPI-7 T13 1532D rev.1", /* 0x001a */ |
| 292 | "ATA/ATAPI-6 T13 1410D revision 2", /* 0x001b */ | 292 | "ATA/ATAPI-6 T13 1410D rev.2", /* 0x001b */ |
| 293 | "ATA/ATAPI-6 T13 1410D revision 1", /* 0x001c */ | 293 | "ATA/ATAPI-6 T13 1410D rev.1", /* 0x001c */ |
| 294 | "ATA/ATAPI-7 published, ANSI INCITS 397-2005", /* 0x001d */ | 294 | "ATA/ATAPI-7 published, ANSI INCITS 397-2005", /* 0x001d */ |
| 295 | "ATA/ATAPI-7 T13 1532D revision 0", /* 0x001e */ | 295 | "ATA/ATAPI-7 T13 1532D rev.0", /* 0x001e */ |
| 296 | "Reserved" /* 0x001f */ | 296 | "Reserved" /* 0x001f */ |
| 297 | "Reserved" /* 0x0020 */ | 297 | "Reserved" /* 0x0020 */ |
| 298 | "ATA/ATAPI-7 T13 1532D revision 4a", /* 0x0021 */ | 298 | "ATA/ATAPI-7 T13 1532D rev.4a", /* 0x0021 */ |
| 299 | "ATA/ATAPI-6 published, ANSI INCITS 361-2002", /* 0x0022 */ | 299 | "ATA/ATAPI-6 published, ANSI INCITS 361-2002", /* 0x0022 */ |
| 300 | "Reserved" /* 0x0023-0xfffe*/ | 300 | "Reserved" /* 0x0023-0xfffe*/ |
| 301 | }; | 301 | }; |
| @@ -368,8 +368,8 @@ static const char * const cmd_feat_str[] = { | |||
| 368 | /* --------------*/ | 368 | /* --------------*/ |
| 369 | "", /* word 83 bit 15: !valid bit */ | 369 | "", /* word 83 bit 15: !valid bit */ |
| 370 | "", /* word 83 bit 14: valid bit */ | 370 | "", /* word 83 bit 14: valid bit */ |
| 371 | "FLUSH CACHE EXT command", /* word 83 bit 13 */ | 371 | "FLUSH CACHE EXT cmd", /* word 83 bit 13 */ |
| 372 | "Mandatory FLUSH CACHE command ", /* word 83 bit 12 */ | 372 | "Mandatory FLUSH CACHE cmd ", /* word 83 bit 12 */ |
| 373 | "Device Configuration Overlay feature set ", | 373 | "Device Configuration Overlay feature set ", |
| 374 | "48-bit Address feature set ", /* word 83 bit 10 */ | 374 | "48-bit Address feature set ", /* word 83 bit 10 */ |
| 375 | "", | 375 | "", |
| @@ -465,10 +465,6 @@ static const char * const secu_str[] = { | |||
| 465 | #undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ | 465 | #undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ |
| 466 | 466 | ||
| 467 | /* Busybox messages and functions */ | 467 | /* Busybox messages and functions */ |
| 468 | |||
| 469 | static const char bb_msg_shared_mem[] = "could not %s sharedmem buf"; | ||
| 470 | static const char bb_msg_op_not_supp[] = " operation not supported on %s disks"; | ||
| 471 | |||
| 472 | static int bb_ioctl(int fd, int request, void *argp, const char *string) | 468 | static int bb_ioctl(int fd, int request, void *argp, const char *string) |
| 473 | { | 469 | { |
| 474 | int e = ioctl(fd, request, argp); | 470 | int e = ioctl(fd, request, argp); |
| @@ -485,51 +481,31 @@ static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const cha | |||
| 485 | return bb_ioctl(fd, cmd, args, string); | 481 | return bb_ioctl(fd, cmd, args, string); |
| 486 | } | 482 | } |
| 487 | 483 | ||
| 488 | |||
| 489 | static void if_printf(unsigned long i, char *fmt, ... ) | ||
| 490 | { | ||
| 491 | va_list ap; | ||
| 492 | va_start(ap, fmt); | ||
| 493 | if (i) | ||
| 494 | vprintf(fmt, ap); | ||
| 495 | va_end(ap); | ||
| 496 | } | ||
| 497 | |||
| 498 | static void on_off(unsigned int value); | 484 | static void on_off(unsigned int value); |
| 499 | 485 | ||
| 500 | static void if_printf_on_off(unsigned long get_arg,const char *fmt, unsigned long arg) | 486 | static void print_flag_on_off(unsigned long get_arg, const char *s, unsigned long arg) |
| 501 | { | 487 | { |
| 488 | |||
| 502 | if (get_arg) | 489 | if (get_arg) |
| 503 | { | 490 | { |
| 504 | printf(fmt, arg); | 491 | printf(" setting %s to %ld", s, arg); |
| 505 | on_off(arg); | 492 | on_off(arg); |
| 506 | } | 493 | } |
| 507 | } | 494 | } |
| 508 | 495 | ||
| 509 | static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string, | 496 | static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string, |
| 510 | const char * fmt) | 497 | const char * str) |
| 511 | { | 498 | { |
| 512 | if (ioctl(fd, request, &argp) != 0) | 499 | if (ioctl(fd, request, &argp) != 0) |
| 513 | bb_perror_msg(" %s", string); | 500 | bb_perror_msg(" %s", string); |
| 514 | else | 501 | else |
| 515 | { | 502 | { |
| 516 | printf(fmt, (unsigned long) argp); | 503 | printf(" %s\t= %2ld", str, (unsigned long) argp); |
| 517 | on_off((unsigned long) argp); | 504 | on_off((unsigned long) argp); |
| 518 | } | 505 | } |
| 519 | } | 506 | } |
| 520 | 507 | ||
| 521 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | 508 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
| 522 | static void if_else_printf(unsigned long i, char *fmt1, char *fmt2, ... ) | ||
| 523 | { | ||
| 524 | va_list ap; | ||
| 525 | va_start(ap, fmt2); | ||
| 526 | if (i) | ||
| 527 | vprintf(fmt1, ap); | ||
| 528 | else | ||
| 529 | vprintf(fmt2, ap); | ||
| 530 | va_end(ap); | ||
| 531 | } | ||
| 532 | |||
| 533 | static void print_ascii(uint16_t *p, uint8_t length); | 509 | static void print_ascii(uint16_t *p, uint8_t length); |
| 534 | 510 | ||
| 535 | static void xprint_ascii(uint16_t *val ,int i, char * string, int n) | 511 | static void xprint_ascii(uint16_t *val ,int i, char * string, int n) |
| @@ -547,27 +523,6 @@ static void if_strcat(unsigned long test, char *modes, char *string) | |||
| 547 | strcat(modes,string); | 523 | strcat(modes,string); |
| 548 | } | 524 | } |
| 549 | #endif | 525 | #endif |
| 550 | |||
| 551 | static void sync_and_sleep(int i) | ||
| 552 | { | ||
| 553 | sync(); | ||
| 554 | sleep(i); | ||
| 555 | } | ||
| 556 | |||
| 557 | static uint16_t check_if_min_and_set_val(uint16_t a, uint16_t b) | ||
| 558 | { | ||
| 559 | if ( a < b) | ||
| 560 | a = b; | ||
| 561 | return a; | ||
| 562 | } | ||
| 563 | |||
| 564 | static uint16_t check_if_maj_and_set_val(uint16_t a, uint16_t b) | ||
| 565 | { | ||
| 566 | if ( a > b) | ||
| 567 | a = b; | ||
| 568 | return a; | ||
| 569 | } | ||
| 570 | |||
| 571 | /* end of busybox specific stuff */ | 526 | /* end of busybox specific stuff */ |
| 572 | 527 | ||
| 573 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | 528 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
| @@ -605,7 +560,7 @@ static void print_ascii(uint16_t *p, uint8_t length) { | |||
| 605 | break; | 560 | break; |
| 606 | if ((cl = (char) 0x00ff&(*p)) != ' ') | 561 | if ((cl = (char) 0x00ff&(*p)) != ' ') |
| 607 | { | 562 | { |
| 608 | if_printf((cl != '\0'),"%c",cl); | 563 | if (cl != '\0') printf("%c",cl); |
| 609 | p++; | 564 | p++; |
| 610 | ii++; | 565 | ii++; |
| 611 | break; | 566 | break; |
| @@ -637,6 +592,7 @@ static void identify(uint16_t *id_supplied) | |||
| 637 | uint8_t chksum = 0; | 592 | uint8_t chksum = 0; |
| 638 | uint32_t ll, mm, nn, oo; | 593 | uint32_t ll, mm, nn, oo; |
| 639 | uint64_t bbbig; /* (:) */ | 594 | uint64_t bbbig; /* (:) */ |
| 595 | const char *strng; | ||
| 640 | 596 | ||
| 641 | if (BB_BIG_ENDIAN) { | 597 | if (BB_BIG_ENDIAN) { |
| 642 | swab(id_supplied, buf, sizeof(buf)); | 598 | swab(id_supplied, buf, sizeof(buf)); |
| @@ -669,9 +625,7 @@ static void identify(uint16_t *id_supplied) | |||
| 669 | /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/ | 625 | /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/ |
| 670 | bb_error_msg_and_die("Unknown device type"); | 626 | bb_error_msg_and_die("Unknown device type"); |
| 671 | 627 | ||
| 672 | if_printf(!(val[GEN_CONFIG] & MEDIA_REMOVABLE),"non-"); | 628 | printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : ""); |
| 673 | printf("removable media\n"); | ||
| 674 | |||
| 675 | /* Info from the specific configuration word says whether or not the | 629 | /* Info from the specific configuration word says whether or not the |
| 676 | * ID command completed correctly. It is only defined, however in | 630 | * ID command completed correctly. It is only defined, however in |
| 677 | * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior | 631 | * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior |
| @@ -683,10 +637,10 @@ static void identify(uint16_t *id_supplied) | |||
| 683 | (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) ) | 637 | (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) ) |
| 684 | { | 638 | { |
| 685 | like_std = 5; | 639 | like_std = 5; |
| 686 | if_printf(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)), | 640 | if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)) |
| 687 | "powers-up in standby; SET FEATURES subcmd spins-up.\n"); | 641 | printf("powers-up in standby; SET FEATURES subcmd spins-up.\n"); |
| 688 | if_printf((((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)), | 642 | if(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)) |
| 689 | "\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n"); | 643 | printf("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n"); |
| 690 | } | 644 | } |
| 691 | 645 | ||
| 692 | /* output the model and serial numbers and the fw revision */ | 646 | /* output the model and serial numbers and the fw revision */ |
| @@ -703,9 +657,9 @@ static void identify(uint16_t *id_supplied) | |||
| 703 | { | 657 | { |
| 704 | if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) | 658 | if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) |
| 705 | { | 659 | { |
| 706 | like_std=check_if_min_and_set_val(like_std, 3); | 660 | if(like_std < 3) like_std = 3; |
| 707 | std = actual_ver[val[MINOR]]; | 661 | std = actual_ver[val[MINOR]]; |
| 708 | if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]); | 662 | if(std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]); |
| 709 | 663 | ||
| 710 | } | 664 | } |
| 711 | /* looks like when they up-issue the std, they obsolete one; | 665 | /* looks like when they up-issue the std, they obsolete one; |
| @@ -726,17 +680,17 @@ static void identify(uint16_t *id_supplied) | |||
| 726 | like_std = ii; | 680 | like_std = ii; |
| 727 | kk = like_std >4 ? like_std-4: 0; | 681 | kk = like_std >4 ? like_std-4: 0; |
| 728 | } | 682 | } |
| 729 | min_std=check_if_maj_and_set_val(min_std, ii); | 683 | if(min_std > ii) min_std = ii; |
| 730 | } | 684 | } |
| 731 | jj <<= 1; | 685 | jj <<= 1; |
| 732 | } | 686 | } |
| 733 | like_std=check_if_min_and_set_val(like_std, 3); | 687 | if(like_std < 3) like_std = 3; |
| 734 | } | 688 | } |
| 735 | /* Figure out what standard the device is using if it hasn't told | 689 | /* Figure out what standard the device is using if it hasn't told |
| 736 | * us. If we know the std, check if the device is using any of | 690 | * us. If we know the std, check if the device is using any of |
| 737 | * the words from the next level up. It happens. | 691 | * the words from the next level up. It happens. |
| 738 | */ | 692 | */ |
| 739 | like_std=check_if_min_and_set_val(like_std, std); | 693 | if(like_std < std) like_std = std; |
| 740 | 694 | ||
| 741 | if (((std == 5) || (!std && (like_std < 6))) && | 695 | if (((std == 5) || (!std && (like_std < 6))) && |
| 742 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && | 696 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| @@ -798,11 +752,11 @@ static void identify(uint16_t *id_supplied) | |||
| 798 | jj = val[CDR_MAJOR] >> 1; | 752 | jj = val[CDR_MAJOR] >> 1; |
| 799 | for (ii = 1; ii <15; ii++) | 753 | for (ii = 1; ii <15; ii++) |
| 800 | { | 754 | { |
| 801 | if_printf((jj & 0x0001),"-%u ", ii); | 755 | if(jj & 0x0001) printf("-%u ", ii); |
| 802 | jj >>= 1; | 756 | jj >>= 1; |
| 803 | } | 757 | } |
| 804 | } | 758 | } |
| 805 | if_else_printf((!kk),"\n\tLikely used CD-ROM ATAPI-1\n","\n"); | 759 | printf("%s\n", (!kk) ? "\n\tLikely used CD-ROM ATAPI-1" : "" ); |
| 806 | /* the cdrom stuff is more like ATA-2 than anything else, so: */ | 760 | /* the cdrom stuff is more like ATA-2 than anything else, so: */ |
| 807 | like_std = 2; | 761 | like_std = 2; |
| 808 | } | 762 | } |
| @@ -817,41 +771,29 @@ static void identify(uint16_t *id_supplied) | |||
| 817 | jj = val[GEN_CONFIG] >> 1; | 771 | jj = val[GEN_CONFIG] >> 1; |
| 818 | for (ii = 1; ii < 15; ii++) | 772 | for (ii = 1; ii < 15; ii++) |
| 819 | { | 773 | { |
| 820 | if_printf((jj & 0x0001),"\t%s\n",ata1_cfg_str[ii]); | 774 | if(jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]); |
| 821 | jj >>=1; | 775 | jj >>=1; |
| 822 | } | 776 | } |
| 823 | } | 777 | } |
| 824 | if (dev == ATAPI_DEV) | 778 | if (dev == ATAPI_DEV) |
| 825 | { | 779 | { |
| 826 | printf("\tDRQ response: "); /* Data Request (DRQ) */ | 780 | if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_3MS_VAL) |
| 827 | switch(val[GEN_CONFIG] & DRQ_RESPONSE_TIME) | 781 | strng = "3ms"; |
| 828 | { | 782 | else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_INTR_VAL) |
| 829 | case DRQ_3MS_VAL : | 783 | strng = "<=10ms with INTRQ"; |
| 830 | printf("3ms.\n"); | 784 | else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL) |
| 831 | break; | 785 | strng ="50us"; |
| 832 | case DRQ_INTR_VAL : | 786 | else |
| 833 | printf("<=10ms with INTRQ\n"); | 787 | strng = "Unknown"; |
| 834 | break; | 788 | printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */ |
| 835 | case DRQ_50US_VAL : | 789 | |
| 836 | printf("50us.\n"); | 790 | if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_12_VAL) |
| 837 | break; | 791 | strng = "12 bytes"; |
| 838 | default : | 792 | else if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_16_VAL) |
| 839 | printf("unknown.\n"); | 793 | strng = "16 bytes"; |
| 840 | break; | 794 | else |
| 841 | } | 795 | strng = "Unknown"; |
| 842 | printf("\tPacket size: "); | 796 | puts(strng); |
| 843 | switch(val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) | ||
| 844 | { | ||
| 845 | case PKT_SIZE_12_VAL : | ||
| 846 | printf("12 bytes\n"); | ||
| 847 | break; | ||
| 848 | case PKT_SIZE_16_VAL : | ||
| 849 | printf("16 bytes\n"); | ||
| 850 | break; | ||
| 851 | default : | ||
| 852 | printf("Unknown\n"); | ||
| 853 | break; | ||
| 854 | } | ||
| 855 | } | 797 | } |
| 856 | else | 798 | else |
| 857 | { | 799 | { |
| @@ -866,8 +808,8 @@ static void identify(uint16_t *id_supplied) | |||
| 866 | printf("\tLogical\t\tmax\tcurrent\n\tcylinders\t%u\t%u\n\theads\t\t%u\t%u\n\tsectors/track\t%u\t%u\n\t--\n", | 808 | printf("\tLogical\t\tmax\tcurrent\n\tcylinders\t%u\t%u\n\theads\t\t%u\t%u\n\tsectors/track\t%u\t%u\n\t--\n", |
| 867 | val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0); | 809 | val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0); |
| 868 | 810 | ||
| 869 | if_printf(((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])), | 811 | if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) |
| 870 | "\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]); | 812 | printf("\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]); |
| 871 | 813 | ||
| 872 | if (jj) | 814 | if (jj) |
| 873 | { | 815 | { |
| @@ -901,8 +843,10 @@ static void identify(uint16_t *id_supplied) | |||
| 901 | bbbig = (bbbig<<9)/1000000; | 843 | bbbig = (bbbig<<9)/1000000; |
| 902 | printf("\tdevice size with M = 1000*1000: %11llu MBytes ",(long long unsigned int)bbbig); | 844 | printf("\tdevice size with M = 1000*1000: %11llu MBytes ",(long long unsigned int)bbbig); |
| 903 | 845 | ||
| 904 | if_else_printf((bbbig > 1000),"(%llu GB)\n","\n",bbbig/1000); | 846 | if (bbbig > 1000) |
| 905 | 847 | printf("(%llu GB)\n", bbbig/1000); | |
| 848 | else | ||
| 849 | printf("\n"); | ||
| 906 | } | 850 | } |
| 907 | 851 | ||
| 908 | /* hw support of commands (capabilities) */ | 852 | /* hw support of commands (capabilities) */ |
| @@ -910,48 +854,39 @@ static void identify(uint16_t *id_supplied) | |||
| 910 | 854 | ||
| 911 | if (dev == ATAPI_DEV) | 855 | if (dev == ATAPI_DEV) |
| 912 | { | 856 | { |
| 913 | if (eqpt != CDROM) | 857 | if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, "); |
| 914 | if_printf((val[CAPAB_0] & CMD_Q_SUP),"Cmd queuing, "); | 858 | if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, "); |
| 915 | |||
| 916 | if_printf((val[CAPAB_0] & OVLP_SUP),"Cmd overlap, "); | ||
| 917 | } | 859 | } |
| 918 | if_printf((val[CAPAB_0] & LBA_SUP),"LBA, "); | 860 | if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); |
| 919 | 861 | ||
| 920 | if (like_std != 1) | 862 | if (like_std != 1) |
| 921 | { | 863 | { |
| 922 | printf("IORDY"); | 864 | printf("IORDY%s(can%s be disabled)\n", |
| 923 | if_printf((!(val[CAPAB_0] & IORDY_SUP)),"(may be)"); | 865 | !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", |
| 924 | if_else_printf((val[CAPAB_0] & IORDY_OFF),"(can","(cannot"); | 866 | (val[CAPAB_0] & IORDY_OFF) ? "" :"not"); |
| 925 | printf(" be disabled)\n"); | ||
| 926 | } | 867 | } |
| 927 | else | 868 | else |
| 928 | printf("no IORDY\n"); | 869 | printf("no IORDY\n"); |
| 929 | 870 | ||
| 930 | if ((like_std == 1) && val[BUF_TYPE]) | 871 | if ((like_std == 1) && val[BUF_TYPE]) |
| 931 | { | 872 | { |
| 932 | kk = val[BUF_TYPE]; | 873 | printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], |
| 933 | printf("\tBuffer type: %04x: ",kk); | 874 | (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", |
| 934 | if_else_printf((kk < 2),"single port, single-sector","dual port, multi-sector"); | 875 | (val[BUF_TYPE] > 2) ? " with read caching ability" : ""); |
| 935 | if_printf((kk > 2)," with read caching ability"); | ||
| 936 | printf("\n"); | ||
| 937 | } | 876 | } |
| 938 | jj = 0; | 877 | |
| 939 | if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) | 878 | if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) |
| 940 | { | 879 | { |
| 941 | printf("\tBuffer size: %.1fkB",(float)val[BUFFER__SIZE]/2); | 880 | printf("\tBuffer size: %.1fkB\n",(float)val[BUFFER__SIZE]/2); |
| 942 | jj = 1; | ||
| 943 | } | 881 | } |
| 944 | if ((min_std < 4) && (val[RW_LONG])) | 882 | if ((min_std < 4) && (val[RW_LONG])) |
| 945 | { | 883 | { |
| 946 | printf("\tbytes avail on r/w long: %u",val[RW_LONG]); | 884 | printf("\tbytes avail on r/w long: %u\n",val[RW_LONG]); |
| 947 | jj = 1; | ||
| 948 | } | 885 | } |
| 949 | if ((eqpt != CDROM) && (like_std > 3)) | 886 | if ((eqpt != CDROM) && (like_std > 3)) |
| 950 | { | 887 | { |
| 951 | printf("\tQueue depth: %u",(val[QUEUE_DEPTH] & DEPTH_BITS)+1); | 888 | printf("\tQueue depth: %u\n",(val[QUEUE_DEPTH] & DEPTH_BITS)+1); |
| 952 | jj = 1; | ||
| 953 | } | 889 | } |
| 954 | if_printf(jj,"\n"); | ||
| 955 | 890 | ||
| 956 | if (dev == ATA_DEV) | 891 | if (dev == ATA_DEV) |
| 957 | { | 892 | { |
| @@ -959,8 +894,7 @@ static void identify(uint16_t *id_supplied) | |||
| 959 | printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":""); | 894 | printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":""); |
| 960 | else | 895 | else |
| 961 | { | 896 | { |
| 962 | printf("\tStandby timer values: spec'd by "); | 897 | printf("\tStandby timer values: spec'd by %s", (val[CAPAB_0] & STD_STBY) ? "Standard" : "Vendor"); |
| 963 | if_else_printf((val[CAPAB_0] & STD_STBY),"Standard","Vendor"); | ||
| 964 | if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) | 898 | if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
| 965 | printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no"); | 899 | printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no"); |
| 966 | else | 900 | else |
| @@ -972,8 +906,10 @@ static void identify(uint16_t *id_supplied) | |||
| 972 | else | 906 | else |
| 973 | { | 907 | { |
| 974 | printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER); | 908 | printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER); |
| 975 | if_else_printf((val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID), | 909 | if (val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID) |
| 976 | "%u\n","?\n",val[SECTOR_XFER_CUR] & SECTOR_XFER); | 910 | printf("%u\n", val[SECTOR_XFER_CUR] & SECTOR_XFER); |
| 911 | else | ||
| 912 | printf("?\n"); | ||
| 977 | } | 913 | } |
| 978 | if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) | 914 | if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) |
| 979 | { | 915 | { |
| @@ -989,23 +925,22 @@ static void identify(uint16_t *id_supplied) | |||
| 989 | else | 925 | else |
| 990 | printf("unknown setting (0x%04x)\n", val[ADV_PWR]); | 926 | printf("unknown setting (0x%04x)\n", val[ADV_PWR]); |
| 991 | } | 927 | } |
| 992 | if (like_std > 5) | 928 | if (like_std > 5 && val[ACOUSTIC]) { |
| 993 | { | 929 | printf("\tRecommended acoustic management value: %u, current value: %u\n", |
| 994 | if_printf(val[ACOUSTIC],"\tRecommended acoustic management value: %u, current value: %u\n", | ||
| 995 | (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); | 930 | (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); |
| 996 | } | 931 | } |
| 997 | } | 932 | } |
| 998 | else | 933 | else |
| 999 | { | 934 | { |
| 1000 | /* ATAPI */ | 935 | /* ATAPI */ |
| 1001 | if (eqpt != CDROM) | 936 | if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ)) |
| 1002 | if_printf((val[CAPAB_0] & SWRST_REQ),"\tATA sw reset required\n"); | 937 | printf("\tATA sw reset required\n"); |
| 1003 | 938 | ||
| 1004 | if (val[PKT_REL] || val[SVC_NBSY]) | 939 | if (val[PKT_REL] || val[SVC_NBSY]) |
| 1005 | { | 940 | { |
| 1006 | printf("\tOverlap support:"); | 941 | printf("\tOverlap support:"); |
| 1007 | if_printf(val[PKT_REL]," %uus to release bus.",val[PKT_REL]); | 942 | if (val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]); |
| 1008 | if_printf(val[SVC_NBSY]," %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]); | 943 | if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]); |
| 1009 | printf("\n"); | 944 | printf("\n"); |
| 1010 | } | 945 | } |
| 1011 | } | 946 | } |
| @@ -1016,8 +951,8 @@ static void identify(uint16_t *id_supplied) | |||
| 1016 | printf("not supported\n"); | 951 | printf("not supported\n"); |
| 1017 | else | 952 | else |
| 1018 | { | 953 | { |
| 1019 | if_printf((val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]), | 954 | if (val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]) |
| 1020 | " sdma%u\n",(val[DMA_MODE] & MODE) >> 8); | 955 | printf(" sdma%u\n",(val[DMA_MODE] & MODE) >> 8); |
| 1021 | if (val[SINGLE_DMA]) | 956 | if (val[SINGLE_DMA]) |
| 1022 | { | 957 | { |
| 1023 | jj = val[SINGLE_DMA]; | 958 | jj = val[SINGLE_DMA]; |
| @@ -1036,18 +971,18 @@ static void identify(uint16_t *id_supplied) | |||
| 1036 | kk = val[ULTRA_DMA] >> 8; | 971 | kk = val[ULTRA_DMA] >> 8; |
| 1037 | err_dma += mode_loop(jj,kk,'u',&have_mode); | 972 | err_dma += mode_loop(jj,kk,'u',&have_mode); |
| 1038 | } | 973 | } |
| 1039 | if_printf((err_dma || !have_mode),"(?)"); | 974 | if (err_dma || !have_mode) printf("(?)"); |
| 1040 | printf("\n"); | 975 | printf("\n"); |
| 1041 | 976 | ||
| 1042 | if_printf(((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)), | 977 | if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)) |
| 1043 | "\t Interleaved DMA support\n"); | 978 | printf("\t\tInterleaved DMA support\n"); |
| 1044 | 979 | ||
| 1045 | if ((val[WHATS_VALID] & OK_W64_70) && | 980 | if ((val[WHATS_VALID] & OK_W64_70) && |
| 1046 | (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])) | 981 | (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])) |
| 1047 | { | 982 | { |
| 1048 | printf("\t Cycle time:"); | 983 | printf("\t\tCycle time:"); |
| 1049 | if_printf(val[DMA_TIME_MIN]," min=%uns",val[DMA_TIME_MIN]); | 984 | if (val[DMA_TIME_MIN]) printf(" min=%uns",val[DMA_TIME_MIN]); |
| 1050 | if_printf(val[DMA_TIME_NORM]," recommended=%uns",val[DMA_TIME_NORM]); | 985 | if (val[DMA_TIME_NORM]) printf(" recommended=%uns",val[DMA_TIME_NORM]); |
| 1051 | printf("\n"); | 986 | printf("\n"); |
| 1052 | } | 987 | } |
| 1053 | } | 988 | } |
| @@ -1061,7 +996,7 @@ static void identify(uint16_t *id_supplied) | |||
| 1061 | jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007; | 996 | jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007; |
| 1062 | for (ii = 0; ii <= PIO_MODE_MAX ; ii++) | 997 | for (ii = 0; ii <= PIO_MODE_MAX ; ii++) |
| 1063 | { | 998 | { |
| 1064 | if_printf((jj & 0x0001),"pio%d ",ii); | 999 | if (jj & 0x0001) printf("pio%d ",ii); |
| 1065 | jj >>=1; | 1000 | jj >>=1; |
| 1066 | } | 1001 | } |
| 1067 | printf("\n"); | 1002 | printf("\n"); |
| @@ -1079,9 +1014,9 @@ static void identify(uint16_t *id_supplied) | |||
| 1079 | { | 1014 | { |
| 1080 | if (val[PIO_NO_FLOW] || val[PIO_FLOW]) | 1015 | if (val[PIO_NO_FLOW] || val[PIO_FLOW]) |
| 1081 | { | 1016 | { |
| 1082 | printf("\t Cycle time:"); | 1017 | printf("\t\tCycle time:"); |
| 1083 | if_printf(val[PIO_NO_FLOW]," no flow control=%uns", val[PIO_NO_FLOW]); | 1018 | if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); |
| 1084 | if_printf(val[PIO_FLOW]," IORDY flow control=%uns", val[PIO_FLOW]); | 1019 | if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); |
| 1085 | printf("\n"); | 1020 | printf("\n"); |
| 1086 | } | 1021 | } |
| 1087 | } | 1022 | } |
| @@ -1095,8 +1030,7 @@ static void identify(uint16_t *id_supplied) | |||
| 1095 | { | 1030 | { |
| 1096 | if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0')) | 1031 | if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0')) |
| 1097 | { | 1032 | { |
| 1098 | if_else_printf((kk & 0x8000),"\t *","\t"); | 1033 | printf("\t%s\t%s\n", (kk & 0x8000) ? " *" : "", cmd_feat_str[ii]); |
| 1099 | printf("\t%s\n",cmd_feat_str[ii]); | ||
| 1100 | } | 1034 | } |
| 1101 | jj <<=1; kk<<=1; | 1035 | jj <<=1; kk<<=1; |
| 1102 | if (ii%16 == 15) | 1036 | if (ii%16 == 15) |
| @@ -1111,8 +1045,9 @@ static void identify(uint16_t *id_supplied) | |||
| 1111 | } | 1045 | } |
| 1112 | } | 1046 | } |
| 1113 | } | 1047 | } |
| 1114 | if_printf(((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP), | 1048 | /* Removable Media Status Notification feature set */ |
| 1115 | "\tRemovable Media Status Notification feature set supported\n"); | 1049 | if((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) |
| 1050 | printf("\t%s supported\n", cmd_feat_str[27]); | ||
| 1116 | 1051 | ||
| 1117 | 1052 | ||
| 1118 | /* security */ | 1053 | /* security */ |
| @@ -1120,20 +1055,19 @@ static void identify(uint16_t *id_supplied) | |||
| 1120 | (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])) | 1055 | (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])) |
| 1121 | { | 1056 | { |
| 1122 | printf("Security: \n"); | 1057 | printf("Security: \n"); |
| 1123 | if_printf((val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)), | 1058 | if (val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)) |
| 1124 | "\tMaster password revision code = %u\n",val[PSWD_CODE]); | 1059 | printf("\tMaster password revision code = %u\n",val[PSWD_CODE]); |
| 1125 | jj = val[SECU_STATUS]; | 1060 | jj = val[SECU_STATUS]; |
| 1126 | if (jj) | 1061 | if (jj) |
| 1127 | { | 1062 | { |
| 1128 | for (ii = 0; ii < NUM_SECU_STR; ii++) | 1063 | for (ii = 0; ii < NUM_SECU_STR; ii++) |
| 1129 | { | 1064 | { |
| 1130 | if_else_printf((!(jj & 0x0001)),"\tnot\t%s\n", "\t\t%s\n", secu_str[ii]); | 1065 | printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "", secu_str[ii]); |
| 1131 | jj >>=1; | 1066 | jj >>=1; |
| 1132 | } | 1067 | } |
| 1133 | if (val[SECU_STATUS] & SECU_ENABLED) | 1068 | if (val[SECU_STATUS] & SECU_ENABLED) |
| 1134 | { | 1069 | { |
| 1135 | printf("\tSecurity level "); | 1070 | printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); |
| 1136 | if_else_printf((val[SECU_STATUS] & SECU_LEVEL),"maximum\n","high\n"); | ||
| 1137 | } | 1071 | } |
| 1138 | } | 1072 | } |
| 1139 | jj = val[ERASE_TIME] & ERASE_BITS; | 1073 | jj = val[ERASE_TIME] & ERASE_BITS; |
| @@ -1141,34 +1075,26 @@ static void identify(uint16_t *id_supplied) | |||
| 1141 | if (jj || kk) | 1075 | if (jj || kk) |
| 1142 | { | 1076 | { |
| 1143 | printf("\t"); | 1077 | printf("\t"); |
| 1144 | if_printf(jj,"%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1); | 1078 | if (jj) printf("%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1); |
| 1145 | if_printf(kk,"%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1); | 1079 | if (kk) printf("%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1); |
| 1146 | printf("\n"); | 1080 | printf("\n"); |
| 1147 | } | 1081 | } |
| 1148 | } | 1082 | } |
| 1149 | 1083 | ||
| 1150 | /* reset result */ | 1084 | /* reset result */ |
| 1151 | if ((val[HWRST_RSLT] & VALID) == VALID_VAL) | 1085 | jj = val[HWRST_RSLT]; |
| 1086 | if ((jj & VALID) == VALID_VAL) | ||
| 1152 | { | 1087 | { |
| 1153 | printf("HW reset results:\n"); | 1088 | if (!(oo = (jj & RST0))) |
| 1154 | if_else_printf((val[HWRST_RSLT] & CBLID),"\tCBLID- above Vih\n","\tCBLID- below Vih\n"); | 1089 | jj >>= 8; |
| 1155 | |||
| 1156 | if (val[HWRST_RSLT] & RST0) | ||
| 1157 | { | ||
| 1158 | printf("\tDevice num = 0"); | ||
| 1159 | jj = val[HWRST_RSLT]; | ||
| 1160 | } | ||
| 1161 | else | ||
| 1162 | { | ||
| 1163 | printf("\tDevice num = 1"); | ||
| 1164 | jj = val[HWRST_RSLT] >> 8; | ||
| 1165 | } | ||
| 1166 | |||
| 1167 | if ((jj & DEV_DET) == JUMPER_VAL) | 1090 | if ((jj & DEV_DET) == JUMPER_VAL) |
| 1168 | printf(" determined by the jumper"); | 1091 | strng = " determined by the jumper"; |
| 1169 | else if ((jj & DEV_DET) == CSEL_VAL) | 1092 | else if ((jj & DEV_DET) == CSEL_VAL) |
| 1170 | printf(" determined by CSEL"); | 1093 | strng = " determined by CSEL"; |
| 1171 | printf("\n"); | 1094 | else |
| 1095 | strng = ""; | ||
| 1096 | printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n", | ||
| 1097 | (val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng); | ||
| 1172 | } | 1098 | } |
| 1173 | 1099 | ||
| 1174 | /* more stuff from std 5 */ | 1100 | /* more stuff from std 5 */ |
| @@ -1176,23 +1102,18 @@ static void identify(uint16_t *id_supplied) | |||
| 1176 | { | 1102 | { |
| 1177 | if (val[CFA_PWR_MODE] & VALID_W160) | 1103 | if (val[CFA_PWR_MODE] & VALID_W160) |
| 1178 | { | 1104 | { |
| 1179 | printf("CFA power mode 1:\n\t"); | 1105 | printf("CFA power mode 1:\n\t%s%s\n", (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled", |
| 1180 | if_else_printf((val[CFA_PWR_MODE] & PWR_MODE_OFF),"disabled","enabled"); | 1106 | (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : ""); |
| 1181 | |||
| 1182 | if_printf((val[CFA_PWR_MODE] & PWR_MODE_REQ)," and required by some commands"); | ||
| 1183 | printf("\n"); | ||
| 1184 | 1107 | ||
| 1185 | if_printf((val[CFA_PWR_MODE] & MAX_AMPS),"\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS); | 1108 | if (val[CFA_PWR_MODE] & MAX_AMPS) printf("\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS); |
| 1186 | } | 1109 | } |
| 1187 | if ((val[INTEGRITY] & SIG) == SIG_VAL) | 1110 | if ((val[INTEGRITY] & SIG) == SIG_VAL) |
| 1188 | { | 1111 | { |
| 1189 | printf("Checksum: "); | 1112 | printf("Checksum: %scorrect\n", chksum ? "in" : ""); |
| 1190 | if_printf(chksum,"in"); | ||
| 1191 | printf("correct\n"); | ||
| 1192 | } | 1113 | } |
| 1193 | } | 1114 | } |
| 1194 | 1115 | ||
| 1195 | exit(0); | 1116 | exit(EXIT_SUCCESS); |
| 1196 | } | 1117 | } |
| 1197 | #endif | 1118 | #endif |
| 1198 | 1119 | ||
| @@ -1267,13 +1188,13 @@ static unsigned long perform_tristate, tristate; | |||
| 1267 | 1188 | ||
| 1268 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | 1189 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
| 1269 | static const char * const cfg_str[] = | 1190 | static const char * const cfg_str[] = |
| 1270 | { "", " HardSect", " SoftSect", " NotMFM", | 1191 | { "", "HardSect", "SoftSect", "NotMFM", |
| 1271 | " HdSw>15uSec", " SpinMotCtl", " Fixed", " Removeable", | 1192 | "HdSw>15uSec", "SpinMotCtl", "Fixed", "Removeable", |
| 1272 | " DTR<=5Mbs", " DTR>5Mbs", " DTR>10Mbs", " RotSpdTol>.5%", | 1193 | "DTR<=5Mbs", "DTR>5Mbs", "DTR>10Mbs", "RotSpdTol>.5%", |
| 1273 | " dStbOff", " TrkOff", " FmtGapReq", " nonMagnetic" | 1194 | "dStbOff", "TrkOff", "FmtGapReq", "nonMagnetic" |
| 1274 | }; | 1195 | }; |
| 1275 | 1196 | ||
| 1276 | static const char * const BuffType[] = {"unknown", "1Sect", "DualPort", "DualPortCache"}; | 1197 | static const char * const BuffType[] = {"Unknown", "1Sect", "DualPort", "DualPortCache"}; |
| 1277 | 1198 | ||
| 1278 | static void dump_identity(const struct hd_driveid *id) | 1199 | static void dump_identity(const struct hd_driveid *id) |
| 1279 | { | 1200 | { |
| @@ -1286,19 +1207,16 @@ static void dump_identity(const struct hd_driveid *id) | |||
| 1286 | 1207 | ||
| 1287 | printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={", | 1208 | printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={", |
| 1288 | id->model, id->fw_rev, id->serial_no); | 1209 | id->model, id->fw_rev, id->serial_no); |
| 1289 | for (i=0; i<=15; i++) | 1210 | for (i=0; i<=15; i++) { |
| 1290 | if_printf((id->config & (1<<i)),"%s", cfg_str[i]); | 1211 | if (id->config & (1<<i)) |
| 1291 | 1212 | printf(" %s", cfg_str[i]); | |
| 1292 | printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n", | 1213 | } |
| 1214 | printf( " }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" | ||
| 1215 | " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", | ||
| 1293 | id->cyls, id->heads, id->sectors, id->track_bytes, | 1216 | id->cyls, id->heads, id->sectors, id->track_bytes, |
| 1294 | id->sector_bytes, id->ecc_bytes); | 1217 | id->sector_bytes, id->ecc_bytes, |
| 1295 | 1218 | id->buf_type, BuffType[(id->buf_type > 3) ? 0 : id->buf_type], | |
| 1296 | if (id->buf_type > 3) | 1219 | id->buf_size/2, id->max_multsect); |
| 1297 | printf("%s%u", " BuffType=", id->buf_type); | ||
| 1298 | else | ||
| 1299 | printf("%s%s", " BuffType=", BuffType[id->buf_type]); | ||
| 1300 | |||
| 1301 | printf(", BuffSize=%ukB, MaxMultSect=%u", id->buf_size/2, id->max_multsect); | ||
| 1302 | if (id->max_multsect) | 1220 | if (id->max_multsect) |
| 1303 | { | 1221 | { |
| 1304 | printf(", MultSect="); | 1222 | printf(", MultSect="); |
| @@ -1317,14 +1235,14 @@ static void dump_identity(const struct hd_driveid *id) | |||
| 1317 | if_strcat((id->tPIO >= 2), pmodes, "pio2 "); | 1235 | if_strcat((id->tPIO >= 2), pmodes, "pio2 "); |
| 1318 | 1236 | ||
| 1319 | } | 1237 | } |
| 1320 | if_printf((!(id->field_valid&1))," (maybe):"); | 1238 | if(!(id->field_valid&1)) printf(" (maybe):"); |
| 1321 | if (BB_BIG_ENDIAN) capacity = (id->cur_capacity0 << 16) | id->cur_capacity1; | 1239 | if (BB_BIG_ENDIAN) capacity = (id->cur_capacity0 << 16) | id->cur_capacity1; |
| 1322 | else capacity = (id->cur_capacity1 << 16) | id->cur_capacity0; | 1240 | else capacity = (id->cur_capacity1 << 16) | id->cur_capacity0; |
| 1323 | printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads, | 1241 | printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads, |
| 1324 | id->cur_sectors, capacity , | 1242 | id->cur_sectors, capacity , |
| 1325 | ((id->capability&2)==0)?"no":"yes"); | 1243 | ((id->capability&2)==0)?"no":"yes"); |
| 1326 | 1244 | ||
| 1327 | if_printf((id->capability&2),", LBAsects=%u", id->lba_capacity); | 1245 | if (id->capability&2) printf(", LBAsects=%u", id->lba_capacity); |
| 1328 | 1246 | ||
| 1329 | if (id->capability&1) | 1247 | if (id->capability&1) |
| 1330 | { | 1248 | { |
| @@ -1391,11 +1309,11 @@ static void dump_identity(const struct hd_driveid *id) | |||
| 1391 | } | 1309 | } |
| 1392 | } | 1310 | } |
| 1393 | } | 1311 | } |
| 1394 | if_printf(((id->capability&1) && (id->field_valid&2)), | 1312 | if ((id->capability&1) && (id->field_valid&2)) |
| 1395 | ", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time); | 1313 | printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time); |
| 1396 | printf("\n PIO modes: %s", pmodes); | 1314 | printf("\n PIO modes: %s", pmodes); |
| 1397 | if_printf((*dmodes),"\n DMA modes: %s", dmodes); | 1315 | if (*dmodes) printf("\n DMA modes: %s", dmodes); |
| 1398 | if_printf((*umodes),"\n UDMA modes: %s", umodes); | 1316 | if (*umodes) printf("\n UDMA modes: %s", umodes); |
| 1399 | 1317 | ||
| 1400 | printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes"); | 1318 | printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes"); |
| 1401 | if (id_regs[83] & 8) | 1319 | if (id_regs[83] & 8) |
| @@ -1407,16 +1325,17 @@ static void dump_identity(const struct hd_driveid *id) | |||
| 1407 | else | 1325 | else |
| 1408 | printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF); | 1326 | printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF); |
| 1409 | } | 1327 | } |
| 1410 | if_printf( (id_regs[82]&0x20)," WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled"); | 1328 | if (id_regs[82]&0x20) printf(" WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled"); |
| 1411 | #ifdef __NEW_HD_DRIVE_ID | 1329 | #ifdef __NEW_HD_DRIVE_ID |
| 1412 | if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31)) | 1330 | if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31)) |
| 1413 | { | 1331 | { |
| 1414 | printf("\n Drive conforms to: "); | 1332 | printf("\n Drive conforms to: %s: ", (id->minor_rev_num <= 31) ? minor_str[id->minor_rev_num] : "Unknown"); |
| 1415 | if_else_printf((id->minor_rev_num <= 31),"%s: ","unknown: ", minor_str[id->minor_rev_num]); | ||
| 1416 | if (id->major_rev_num != 0x0000 && /* NOVAL_0 */ | 1333 | if (id->major_rev_num != 0x0000 && /* NOVAL_0 */ |
| 1417 | id->major_rev_num != 0xFFFF) { /* NOVAL_1 */ | 1334 | id->major_rev_num != 0xFFFF) { /* NOVAL_1 */ |
| 1418 | for (i=0; i <= 15; i++) | 1335 | for (i=0; i <= 15; i++) { |
| 1419 | if_printf((id->major_rev_num & (1<<i))," ATA/ATAPI-%u", i); | 1336 | if (id->major_rev_num & (1<<i)) |
| 1337 | printf(" ATA/ATAPI-%u", i); | ||
| 1338 | } | ||
| 1420 | } | 1339 | } |
| 1421 | } | 1340 | } |
| 1422 | #endif /* __NEW_HD_DRIVE_ID */ | 1341 | #endif /* __NEW_HD_DRIVE_ID */ |
| @@ -1444,22 +1363,10 @@ static int seek_to_zero(int fd) | |||
| 1444 | 1363 | ||
| 1445 | static int read_big_block(int fd, char *buf) | 1364 | static int read_big_block(int fd, char *buf) |
| 1446 | { | 1365 | { |
| 1447 | const char *string; | 1366 | int i; |
| 1448 | int i, rc; | 1367 | |
| 1449 | if ((rc = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) | 1368 | if ((i = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) { |
| 1450 | { | 1369 | bb_error_msg("read(%d bytes) failed (rc=%d)", TIMING_BUF_BYTES, i); |
| 1451 | switch(rc) | ||
| 1452 | { | ||
| 1453 | case -1: | ||
| 1454 | string = "read()"; | ||
| 1455 | break; | ||
| 1456 | case 0: | ||
| 1457 | string = "read() hit EOF - device too small"; | ||
| 1458 | break; | ||
| 1459 | default: | ||
| 1460 | string = "read(%u) returned %u bytes"; | ||
| 1461 | } | ||
| 1462 | bb_error_msg(string, TIMING_BUF_BYTES, rc); | ||
| 1463 | return 1; | 1370 | return 1; |
| 1464 | } | 1371 | } |
| 1465 | 1372 | ||
| @@ -1469,7 +1376,29 @@ static int read_big_block(int fd, char *buf) | |||
| 1469 | return 0; | 1376 | return 0; |
| 1470 | } | 1377 | } |
| 1471 | 1378 | ||
| 1472 | static double correction; | 1379 | static void print_timing(int t, double e) |
| 1380 | { | ||
| 1381 | if (t >= e) /* more than 1MB/s */ | ||
| 1382 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n", t, e, t / e); | ||
| 1383 | else | ||
| 1384 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n", t, e, t / e * 1024); | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | static int do_blkgetsize (int fd, unsigned long long *blksize64) | ||
| 1388 | { | ||
| 1389 | int rc; | ||
| 1390 | unsigned int blksize32 = 0; | ||
| 1391 | |||
| 1392 | if (0 == ioctl(fd, BLKGETSIZE64, blksize64)) { // returns bytes | ||
| 1393 | *blksize64 /= 512; | ||
| 1394 | return 0; | ||
| 1395 | } | ||
| 1396 | rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors | ||
| 1397 | if (rc) | ||
| 1398 | bb_perror_msg("BLKGETSIZE"); | ||
| 1399 | *blksize64 = blksize32; | ||
| 1400 | return rc; | ||
| 1401 | } | ||
| 1473 | 1402 | ||
| 1474 | static void do_time(int flag, int fd) | 1403 | static void do_time(int flag, int fd) |
| 1475 | /* | 1404 | /* |
| @@ -1477,91 +1406,78 @@ static void do_time(int flag, int fd) | |||
| 1477 | flag = 1 time_device | 1406 | flag = 1 time_device |
| 1478 | */ | 1407 | */ |
| 1479 | { | 1408 | { |
| 1480 | int i; | ||
| 1481 | char *buf; | 1409 | char *buf; |
| 1482 | double elapsed; | ||
| 1483 | struct itimerval e1, e2; | 1410 | struct itimerval e1, e2; |
| 1484 | int shmid; | 1411 | int shmid; |
| 1485 | int timing_MB = TIMING_MB; | 1412 | double elapsed, elapsed2; |
| 1413 | unsigned int max_iterations = 1024, total_MB, iterations; | ||
| 1414 | unsigned long long blksize; | ||
| 1415 | |||
| 1416 | if (0 == do_blkgetsize(fd, &blksize)) { | ||
| 1417 | max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB; | ||
| 1418 | } | ||
| 1486 | 1419 | ||
| 1487 | if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) | 1420 | if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) |
| 1488 | { | 1421 | { |
| 1489 | bb_error_msg(bb_msg_shared_mem,"allocate"); /*"could not allocate sharedmem buf"*/ | 1422 | bb_perror_msg("shmget"); /*"could not allocate sharedmem buf"*/ |
| 1490 | return; | 1423 | return; |
| 1491 | } | 1424 | } |
| 1492 | if (shmctl(shmid, SHM_LOCK, NULL) == -1) | 1425 | if (shmctl(shmid, SHM_LOCK, NULL) == -1) |
| 1493 | { | 1426 | { |
| 1494 | bb_error_msg(bb_msg_shared_mem,"lock"); /*"could not lock sharedmem buf"*/ | 1427 | bb_perror_msg("shmctl"); /*"could not lock sharedmem buf"*/ |
| 1495 | (void) shmctl(shmid, IPC_RMID, NULL); | 1428 | (void) shmctl(shmid, IPC_RMID, NULL); |
| 1496 | return; | 1429 | return; |
| 1497 | } | 1430 | } |
| 1498 | if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) | 1431 | if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) |
| 1499 | { | 1432 | { |
| 1500 | bb_error_msg(bb_msg_shared_mem,"attach"); /*"could not attach sharedmem buf"*/ | 1433 | bb_perror_msg("shmat"); /*"could not attach sharedmem buf"*/ |
| 1501 | (void) shmctl(shmid, IPC_RMID, NULL); | 1434 | (void) shmctl(shmid, IPC_RMID, NULL); |
| 1502 | return; | 1435 | return; |
| 1503 | } | 1436 | } |
| 1504 | if (shmctl(shmid, IPC_RMID, NULL) == -1) | 1437 | if (shmctl(shmid, IPC_RMID, NULL) == -1) |
| 1505 | bb_error_msg("shmctl(,IPC_RMID,)"); | 1438 | bb_perror_msg("shmctl"); |
| 1506 | 1439 | ||
| 1507 | /* Clear out the device request queues & give them time to complete */ | 1440 | /* Clear out the device request queues & give them time to complete */ |
| 1508 | sync_and_sleep(3); | 1441 | sync(); |
| 1442 | sleep(3); | ||
| 1443 | |||
| 1444 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); | ||
| 1509 | 1445 | ||
| 1510 | if (flag == 0) /* Time cache */ | 1446 | if (flag == 0) /* Time cache */ |
| 1511 | { | 1447 | { |
| 1512 | /* Calculate a correction factor for the basic | 1448 | if (seek_to_zero (fd)) return; |
| 1513 | * overhead of doing a read() from the buffer cache. | 1449 | if (read_big_block (fd, buf)) return; |
| 1514 | * To do this, we read the data once to "cache it" and | 1450 | printf(" Timing cached reads: "); |
| 1515 | * to force full preallocation of our timing buffer, | ||
| 1516 | * and then we re-read it 10 times while timing it. | ||
| 1517 | * | ||
| 1518 | * getitimer() is used rather than gettimeofday() because | ||
| 1519 | * it is much more consistent (on my machine, at least). | ||
| 1520 | */ | ||
| 1521 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); | ||
| 1522 | if (seek_to_zero(fd)) | ||
| 1523 | return; | ||
| 1524 | if (read_big_block(fd, buf)) | ||
| 1525 | return; | ||
| 1526 | printf(" Timing buffer-cache reads: "); | ||
| 1527 | fflush(stdout); | 1451 | fflush(stdout); |
| 1528 | 1452 | ||
| 1529 | /* Clear out the device request queues & give them time to complete */ | 1453 | /* Now do the timing */ |
| 1530 | sync_and_sleep(1); | 1454 | iterations = 0; |
| 1531 | |||
| 1532 | /* Time re-reading from the buffer-cache */ | ||
| 1533 | getitimer(ITIMER_REAL, &e1); | 1455 | getitimer(ITIMER_REAL, &e1); |
| 1534 | for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i) | 1456 | do { |
| 1535 | { | 1457 | ++iterations; |
| 1536 | if (seek_to_zero(fd)) | 1458 | if (seek_to_zero (fd) || read_big_block (fd, buf)) |
| 1537 | goto quit; | 1459 | goto quit; |
| 1538 | if (read_big_block(fd, buf)) | 1460 | getitimer(ITIMER_REAL, &e2); |
| 1539 | goto quit; | 1461 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1540 | } | 1462 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
| 1541 | getitimer(ITIMER_REAL, &e2); | 1463 | } while (elapsed < 2.0); |
| 1542 | correction = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | 1464 | total_MB = iterations * TIMING_BUF_MB; |
| 1543 | 1465 | ||
| 1544 | /* Now remove the lseek() from the correction factor */ | 1466 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1467 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | ||
| 1468 | |||
| 1469 | /* Now remove the lseek() and getitimer() overheads from the elapsed time */ | ||
| 1545 | getitimer(ITIMER_REAL, &e1); | 1470 | getitimer(ITIMER_REAL, &e1); |
| 1546 | for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i) | 1471 | do { |
| 1547 | { | 1472 | if (seek_to_zero (fd)) |
| 1548 | if (seek_to_zero(fd)) | ||
| 1549 | goto quit; | 1473 | goto quit; |
| 1550 | } | 1474 | getitimer(ITIMER_REAL, &e2); |
| 1551 | getitimer(ITIMER_REAL, &e2); | 1475 | elapsed2 = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1552 | correction -= (e1.it_value.tv_sec - e2.it_value.tv_sec) | 1476 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
| 1553 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | 1477 | } while (--iterations); |
| 1554 | 1478 | ||
| 1555 | if ((BUFCACHE_FACTOR * timing_MB) >= correction) /* more than 1MB/s */ | 1479 | elapsed -= elapsed2; |
| 1556 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n", | 1480 | print_timing(BUFCACHE_FACTOR * total_MB, elapsed); |
| 1557 | (BUFCACHE_FACTOR * timing_MB), correction, | ||
| 1558 | (BUFCACHE_FACTOR * timing_MB) / correction); | ||
| 1559 | else | ||
| 1560 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n", | ||
| 1561 | (BUFCACHE_FACTOR * timing_MB), correction, | ||
| 1562 | (BUFCACHE_FACTOR * timing_MB) / correction * 1024); | ||
| 1563 | correction /= BUFCACHE_FACTOR; | ||
| 1564 | |||
| 1565 | flush_buffer_cache(fd); | 1481 | flush_buffer_cache(fd); |
| 1566 | sleep(1); | 1482 | sleep(1); |
| 1567 | } | 1483 | } |
| @@ -1569,49 +1485,28 @@ static void do_time(int flag, int fd) | |||
| 1569 | { | 1485 | { |
| 1570 | printf(" Timing buffered disk reads: "); | 1486 | printf(" Timing buffered disk reads: "); |
| 1571 | fflush(stdout); | 1487 | fflush(stdout); |
| 1572 | |||
| 1573 | /* | 1488 | /* |
| 1574 | * getitimer() is used rather than gettimeofday() because | 1489 | * getitimer() is used rather than gettimeofday() because |
| 1575 | * it is much more consistent (on my machine, at least). | 1490 | * it is much more consistent (on my machine, at least). |
| 1576 | */ | 1491 | */ |
| 1577 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); | ||
| 1578 | |||
| 1579 | /* Now do the timings for real */ | 1492 | /* Now do the timings for real */ |
| 1493 | iterations = 0; | ||
| 1580 | getitimer(ITIMER_REAL, &e1); | 1494 | getitimer(ITIMER_REAL, &e1); |
| 1581 | for (i = TIMING_BUF_COUNT; i > 0; --i) | 1495 | do { |
| 1582 | { | 1496 | ++iterations; |
| 1583 | if (read_big_block(fd, buf)) | 1497 | if (read_big_block (fd, buf)) |
| 1584 | goto quit; | 1498 | goto quit; |
| 1585 | } | 1499 | getitimer(ITIMER_REAL, &e2); |
| 1586 | getitimer(ITIMER_REAL, &e2); | 1500 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1587 | 1501 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | |
| 1588 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | 1502 | } while (elapsed < 3.0 && iterations < max_iterations); |
| 1589 | 1503 | ||
| 1590 | if (timing_MB >= elapsed) /* more than 1MB/s */ | 1504 | total_MB = iterations * TIMING_BUF_MB; |
| 1591 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",timing_MB, elapsed, timing_MB / elapsed); | 1505 | print_timing(total_MB, elapsed); |
| 1592 | else | ||
| 1593 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",timing_MB, elapsed, timing_MB / elapsed * 1024); | ||
| 1594 | |||
| 1595 | /*"Hmm.. suspicious results: probably not enough free memory for a proper test.");*/ | ||
| 1596 | if (elapsed <= (correction * 2)) | ||
| 1597 | bb_error_msg(bb_msg_memory_exhausted); | ||
| 1598 | |||
| 1599 | #if 0 /* the "estimate" is just plain wrong for many systems.. */ | ||
| 1600 | else if (correction != 0.0) { | ||
| 1601 | printf(" Estimating raw driver speed: "); | ||
| 1602 | elapsed -= correction; | ||
| 1603 | if (timing_MB >= elapsed) /* more than 1MB/s */ | ||
| 1604 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n", | ||
| 1605 | timing_MB, elapsed, timing_MB / elapsed); | ||
| 1606 | else | ||
| 1607 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n", | ||
| 1608 | timing_MB, elapsed, timing_MB / elapsed * 1024); | ||
| 1609 | } | ||
| 1610 | #endif | ||
| 1611 | } | 1506 | } |
| 1612 | quit: | 1507 | quit: |
| 1613 | if (-1 == shmdt(buf)) | 1508 | if (-1 == shmdt(buf)) |
| 1614 | bb_error_msg(bb_msg_shared_mem,"detach"); /*"could not detach sharedmem buf"*/ | 1509 | bb_perror_msg("shmdt"); /*"could not detach sharedmem buf"*/ |
| 1615 | } | 1510 | } |
| 1616 | 1511 | ||
| 1617 | static void on_off (unsigned int value) | 1512 | static void on_off (unsigned int value) |
| @@ -1622,70 +1517,42 @@ static void on_off (unsigned int value) | |||
| 1622 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | 1517 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
| 1623 | static void bus_state_value(unsigned int value) | 1518 | static void bus_state_value(unsigned int value) |
| 1624 | { | 1519 | { |
| 1625 | const char *string; | 1520 | if (value == BUSSTATE_ON) |
| 1626 | 1521 | on_off(1); | |
| 1627 | switch (value) | 1522 | else if (value == BUSSTATE_OFF) |
| 1628 | { | 1523 | on_off(0); |
| 1629 | case BUSSTATE_ON: | 1524 | else if (value == BUSSTATE_TRISTATE) |
| 1630 | string = " (on)\n"; | 1525 | printf(" (tristate)\n"); |
| 1631 | break; | 1526 | else |
| 1632 | case BUSSTATE_OFF: | 1527 | printf(" (unknown: %d)\n", value); |
| 1633 | string = " (off)\n"; | ||
| 1634 | break; | ||
| 1635 | case BUSSTATE_TRISTATE: | ||
| 1636 | string = " (tristate)\n"; | ||
| 1637 | break; | ||
| 1638 | default: | ||
| 1639 | string = " (unknown: %d)\n"; | ||
| 1640 | break; | ||
| 1641 | } | ||
| 1642 | printf(string, value); | ||
| 1643 | } | 1528 | } |
| 1644 | #endif | 1529 | #endif |
| 1645 | 1530 | ||
| 1646 | #ifdef HDIO_DRIVE_CMD | 1531 | #ifdef HDIO_DRIVE_CMD |
| 1647 | static void interpret_standby(unsigned int standby) | 1532 | static void interpret_standby(unsigned int standby) |
| 1648 | { | 1533 | { |
| 1649 | printf(" ("); | 1534 | unsigned int t; |
| 1650 | switch(standby) | 1535 | |
| 1651 | { | 1536 | |
| 1652 | case 0: | 1537 | if (standby == 0) |
| 1653 | printf("off"); | 1538 | printf("off"); |
| 1654 | break; | 1539 | else if (standby == 252) |
| 1655 | case 252: | 1540 | printf("21 minutes"); |
| 1656 | printf("21 minutes"); | 1541 | else if (standby == 253) |
| 1657 | break; | 1542 | printf("vendor-specific"); |
| 1658 | case 253: | 1543 | else if (standby == 254) |
| 1659 | printf("vendor-specific"); | 1544 | printf("Reserved"); |
| 1660 | break; | 1545 | else if (standby == 255) |
| 1661 | case 254: | 1546 | printf("21 minutes + 15 seconds"); |
| 1662 | printf("?reserved"); | 1547 | else { |
| 1663 | break; | 1548 | if (standby <= 240) { |
| 1664 | case 255: | 1549 | t = standby * 5; |
| 1665 | printf("21 minutes + 15 seconds"); | 1550 | printf("%u minutes + %u seconds", t / 60, t % 60); |
| 1666 | break; | 1551 | } else if (standby <= 251) { |
| 1667 | default: | 1552 | t = (standby - 240) * 30; |
| 1668 | if (standby <= 240) | 1553 | printf("%u hours + %u minutes", t / 60, t % 60); |
| 1669 | { | 1554 | } else |
| 1670 | unsigned int secs = standby * 5; | 1555 | printf("illegal value"); |
| 1671 | unsigned int mins = secs / 60; | ||
| 1672 | secs %= 60; | ||
| 1673 | if_printf(mins,"%u minutes", mins); | ||
| 1674 | if_printf((mins && secs)," + "); | ||
| 1675 | if_printf(secs,"%u seconds", secs); | ||
| 1676 | } | ||
| 1677 | else if (standby <= 251) | ||
| 1678 | { | ||
| 1679 | unsigned int mins = (standby - 240) * 30; | ||
| 1680 | unsigned int hrs = mins / 60; | ||
| 1681 | mins %= 60; | ||
| 1682 | if_printf(hrs,"%u hours", hrs); | ||
| 1683 | if_printf((hrs && mins)," + "); | ||
| 1684 | if_printf(mins,"%u minutes", mins); | ||
| 1685 | } | ||
| 1686 | else | ||
| 1687 | printf("illegal value"); | ||
| 1688 | break; | ||
| 1689 | } | 1556 | } |
| 1690 | printf(")\n"); | 1557 | printf(")\n"); |
| 1691 | } | 1558 | } |
| @@ -1742,7 +1609,6 @@ static int translate_xfermode(char * name) | |||
| 1742 | { | 1609 | { |
| 1743 | if (!strcmp(name, tmp->name)) | 1610 | if (!strcmp(name, tmp->name)) |
| 1744 | return tmp->val; | 1611 | return tmp->val; |
| 1745 | |||
| 1746 | } | 1612 | } |
| 1747 | 1613 | ||
| 1748 | val = strtol(name, &endptr, 10); | 1614 | val = strtol(name, &endptr, 10); |
| @@ -1755,61 +1621,30 @@ static int translate_xfermode(char * name) | |||
| 1755 | static void interpret_xfermode(unsigned int xfermode) | 1621 | static void interpret_xfermode(unsigned int xfermode) |
| 1756 | { | 1622 | { |
| 1757 | printf(" ("); | 1623 | printf(" ("); |
| 1758 | switch(xfermode) { | 1624 | if (xfermode == 0) |
| 1759 | case 0: | 1625 | printf("default PIO mode"); |
| 1760 | printf("default PIO mode"); | 1626 | else if (xfermode == 1) |
| 1761 | break; | 1627 | printf("default PIO mode, disable IORDY"); |
| 1762 | case 1: | 1628 | else if (xfermode >= 8 && xfermode <= 15) |
| 1763 | printf("default PIO mode, disable IORDY"); | 1629 | printf("PIO flow control mode%u", xfermode-8); |
| 1764 | break; | 1630 | else if (xfermode >= 16 && xfermode <= 23) |
| 1765 | case 8: | 1631 | printf("singleword DMA mode%u", xfermode-16); |
| 1766 | case 9: | 1632 | else if (xfermode >= 32 && xfermode <= 39) |
| 1767 | case 10: | 1633 | printf("multiword DMA mode%u", xfermode-32); |
| 1768 | case 11: | 1634 | else if (xfermode >= 64 && xfermode <= 71) |
| 1769 | case 12: | 1635 | printf("UltraDMA mode%u", xfermode-64); |
| 1770 | case 13: | 1636 | else |
| 1771 | case 14: | 1637 | printf("Unknown"); |
| 1772 | case 15: | ||
| 1773 | printf("PIO flow control mode%u", xfermode-8); | ||
| 1774 | break; | ||
| 1775 | case 16: | ||
| 1776 | case 17: | ||
| 1777 | case 18: | ||
| 1778 | case 19: | ||
| 1779 | case 20: | ||
| 1780 | case 21: | ||
| 1781 | case 22: | ||
| 1782 | case 23: | ||
| 1783 | printf("singleword DMA mode%u", xfermode-16); | ||
| 1784 | break; | ||
| 1785 | case 32: | ||
| 1786 | case 33: | ||
| 1787 | case 34: | ||
| 1788 | case 35: | ||
| 1789 | case 36: | ||
| 1790 | case 37: | ||
| 1791 | case 38: | ||
| 1792 | case 39: | ||
| 1793 | printf("multiword DMA mode%u", xfermode-32); | ||
| 1794 | break; | ||
| 1795 | case 64: | ||
| 1796 | case 65: | ||
| 1797 | case 66: | ||
| 1798 | case 67: | ||
| 1799 | case 68: | ||
| 1800 | case 69: | ||
| 1801 | case 70: | ||
| 1802 | case 71: | ||
| 1803 | printf("UltraDMA mode%u", xfermode-64); | ||
| 1804 | break; | ||
| 1805 | default: | ||
| 1806 | printf("unknown, probably not valid"); | ||
| 1807 | break; | ||
| 1808 | } | ||
| 1809 | printf(")\n"); | 1638 | printf(")\n"); |
| 1810 | } | 1639 | } |
| 1811 | #endif /* HDIO_DRIVE_CMD */ | 1640 | #endif /* HDIO_DRIVE_CMD */ |
| 1812 | 1641 | ||
| 1642 | static void print_flag(unsigned long flag, char *s, unsigned long value) | ||
| 1643 | { | ||
| 1644 | if(flag) | ||
| 1645 | printf(" setting %s to %ld\n", s, value); | ||
| 1646 | } | ||
| 1647 | |||
| 1813 | static void process_dev(char *devname) | 1648 | static void process_dev(char *devname) |
| 1814 | { | 1649 | { |
| 1815 | int fd; | 1650 | int fd; |
| @@ -1820,13 +1655,14 @@ static void process_dev(char *devname) | |||
| 1820 | /* Please restore args[n] to these values after each ioctl | 1655 | /* Please restore args[n] to these values after each ioctl |
| 1821 | except for args[2] */ | 1656 | except for args[2] */ |
| 1822 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; | 1657 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
| 1658 | const char *fmt = " %s\t= %2ld"; | ||
| 1823 | 1659 | ||
| 1824 | fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK); | 1660 | fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK); |
| 1825 | if_printf(!quiet, "\n%s:\n", devname); | 1661 | if (!quiet) printf("\n%s:\n", devname); |
| 1826 | 1662 | ||
| 1827 | if (set_readahead) | 1663 | if (set_readahead) |
| 1828 | { | 1664 | { |
| 1829 | if_printf(get_readahead," setting fs readahead to %ld\n", Xreadahead); | 1665 | print_flag(get_readahead,"fs readahead", Xreadahead); |
| 1830 | bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET"); | 1666 | bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET"); |
| 1831 | } | 1667 | } |
| 1832 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | 1668 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
| @@ -1866,12 +1702,12 @@ static void process_dev(char *devname) | |||
| 1866 | } | 1702 | } |
| 1867 | if (set_io32bit) | 1703 | if (set_io32bit) |
| 1868 | { | 1704 | { |
| 1869 | if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit); | 1705 | print_flag(get_io32bit,"32-bit IO_support flag", io32bit); |
| 1870 | bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT"); | 1706 | bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT"); |
| 1871 | } | 1707 | } |
| 1872 | if (set_mult) | 1708 | if (set_mult) |
| 1873 | { | 1709 | { |
| 1874 | if_printf(get_mult, " setting multcount to %ld\n", mult); | 1710 | print_flag(get_mult, "multcount", mult); |
| 1875 | if (ioctl(fd, HDIO_SET_MULTCOUNT, mult)) | 1711 | if (ioctl(fd, HDIO_SET_MULTCOUNT, mult)) |
| 1876 | bb_perror_msg("HDIO_SET_MULTCOUNT"); | 1712 | bb_perror_msg("HDIO_SET_MULTCOUNT"); |
| 1877 | #ifndef HDIO_DRIVE_CMD | 1713 | #ifndef HDIO_DRIVE_CMD |
| @@ -1881,34 +1717,34 @@ static void process_dev(char *devname) | |||
| 1881 | } | 1717 | } |
| 1882 | if (set_readonly) | 1718 | if (set_readonly) |
| 1883 | { | 1719 | { |
| 1884 | if_printf_on_off(get_readonly," setting readonly to %ld", readonly); | 1720 | print_flag_on_off(get_readonly,"readonly", readonly); |
| 1885 | bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET"); | 1721 | bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET"); |
| 1886 | } | 1722 | } |
| 1887 | if (set_unmask) | 1723 | if (set_unmask) |
| 1888 | { | 1724 | { |
| 1889 | if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask); | 1725 | print_flag_on_off(get_unmask,"unmaskirq", unmask); |
| 1890 | bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR"); | 1726 | bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR"); |
| 1891 | } | 1727 | } |
| 1892 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA | 1728 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
| 1893 | if (set_dma) | 1729 | if (set_dma) |
| 1894 | { | 1730 | { |
| 1895 | if_printf_on_off(get_dma," setting using_dma to %ld", dma); | 1731 | print_flag_on_off(get_dma, "using_dma", dma); |
| 1896 | bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA"); | 1732 | bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA"); |
| 1897 | } | 1733 | } |
| 1898 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */ | 1734 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */ |
| 1899 | if (set_dma_q) | 1735 | if (set_dma_q) |
| 1900 | { | 1736 | { |
| 1901 | if_printf_on_off(get_dma_q," setting DMA queue_depth to %ld", dma_q); | 1737 | print_flag_on_off(get_dma_q,"DMA queue_depth", dma_q); |
| 1902 | bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA"); | 1738 | bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA"); |
| 1903 | } | 1739 | } |
| 1904 | if (set_nowerr) | 1740 | if (set_nowerr) |
| 1905 | { | 1741 | { |
| 1906 | if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr); | 1742 | print_flag_on_off(get_nowerr,"nowerr", nowerr); |
| 1907 | bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR"); | 1743 | bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR"); |
| 1908 | } | 1744 | } |
| 1909 | if (set_keep) | 1745 | if (set_keep) |
| 1910 | { | 1746 | { |
| 1911 | if_printf_on_off(get_keep," setting keep_settings to %ld", keep); | 1747 | print_flag_on_off(get_keep,"keep_settings", keep); |
| 1912 | bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS"); | 1748 | bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS"); |
| 1913 | } | 1749 | } |
| 1914 | #ifdef HDIO_DRIVE_CMD | 1750 | #ifdef HDIO_DRIVE_CMD |
| @@ -1916,28 +1752,28 @@ static void process_dev(char *devname) | |||
| 1916 | { | 1752 | { |
| 1917 | args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; | 1753 | args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; |
| 1918 | args[2] = 0; | 1754 | args[2] = 0; |
| 1919 | if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock); | 1755 | print_flag_on_off(get_doorlock,"drive doorlock", doorlock); |
| 1920 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)"); | 1756 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)"); |
| 1921 | args[0] = WIN_SETFEATURES; | 1757 | args[0] = WIN_SETFEATURES; |
| 1922 | } | 1758 | } |
| 1923 | if (set_dkeep) | 1759 | if (set_dkeep) |
| 1924 | { | 1760 | { |
| 1925 | /* lock/unlock the drive's "feature" settings */ | 1761 | /* lock/unlock the drive's "feature" settings */ |
| 1926 | if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep); | 1762 | print_flag_on_off(get_dkeep,"drive keep features", dkeep); |
| 1927 | args[2] = dkeep ? 0x66 : 0xcc; | 1763 | args[2] = dkeep ? 0x66 : 0xcc; |
| 1928 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)"); | 1764 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)"); |
| 1929 | } | 1765 | } |
| 1930 | if (set_defects) | 1766 | if (set_defects) |
| 1931 | { | 1767 | { |
| 1932 | args[2] = defects ? 0x04 : 0x84; | 1768 | args[2] = defects ? 0x04 : 0x84; |
| 1933 | if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects); | 1769 | print_flag(get_defects,"drive defect-mgmt", defects); |
| 1934 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)"); | 1770 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)"); |
| 1935 | } | 1771 | } |
| 1936 | if (set_prefetch) | 1772 | if (set_prefetch) |
| 1937 | { | 1773 | { |
| 1938 | args[1] = prefetch; | 1774 | args[1] = prefetch; |
| 1939 | args[2] = 0xab; | 1775 | args[2] = 0xab; |
| 1940 | if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch); | 1776 | print_flag(get_prefetch,"drive prefetch", prefetch); |
| 1941 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)"); | 1777 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)"); |
| 1942 | args[1] = 0; | 1778 | args[1] = 0; |
| 1943 | } | 1779 | } |
| @@ -1947,7 +1783,7 @@ static void process_dev(char *devname) | |||
| 1947 | args[2] = 3; | 1783 | args[2] = 3; |
| 1948 | if (get_xfermode) | 1784 | if (get_xfermode) |
| 1949 | { | 1785 | { |
| 1950 | printf(" setting xfermode to %d", xfermode_requested); | 1786 | print_flag(1,/*" setting */"xfermode"/* to %d"*/, xfermode_requested); |
| 1951 | interpret_xfermode(xfermode_requested); | 1787 | interpret_xfermode(xfermode_requested); |
| 1952 | } | 1788 | } |
| 1953 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)"); | 1789 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)"); |
| @@ -1956,27 +1792,15 @@ static void process_dev(char *devname) | |||
| 1956 | if (set_lookahead) | 1792 | if (set_lookahead) |
| 1957 | { | 1793 | { |
| 1958 | args[2] = lookahead ? 0xaa : 0x55; | 1794 | args[2] = lookahead ? 0xaa : 0x55; |
| 1959 | if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead); | 1795 | print_flag_on_off(get_lookahead,"drive read-lookahead", lookahead); |
| 1960 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)"); | 1796 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)"); |
| 1961 | } | 1797 | } |
| 1962 | if (set_apmmode) | 1798 | if (set_apmmode) |
| 1963 | { | 1799 | { |
| 1964 | apmmode=check_if_min_and_set_val(apmmode,1); | 1800 | args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */ |
| 1965 | apmmode=check_if_maj_and_set_val(apmmode,255); | 1801 | args[1] = apmmode; /* sector count register 1-255 */ |
| 1966 | if_printf(get_apmmode," setting APM level to"); | 1802 | if (get_apmmode) |
| 1967 | if (apmmode==255) | 1803 | printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode); |
| 1968 | { | ||
| 1969 | /* disable Advanced Power Management */ | ||
| 1970 | args[2] = 0x85; /* feature register */ | ||
| 1971 | if_printf(get_apmmode," disabled\n"); | ||
| 1972 | } | ||
| 1973 | else | ||
| 1974 | { | ||
| 1975 | /* set Advanced Power Management mode */ | ||
| 1976 | args[2] = 0x05; /* feature register */ | ||
| 1977 | args[1] = apmmode; /* sector count register */ | ||
| 1978 | if_printf(get_apmmode," 0x%02lX (%ld)\n",apmmode,apmmode); | ||
| 1979 | } | ||
| 1980 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD"); | 1804 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD"); |
| 1981 | args[1] = 0; | 1805 | args[1] = 0; |
| 1982 | } | 1806 | } |
| @@ -1989,7 +1813,7 @@ static void process_dev(char *devname) | |||
| 1989 | static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0}; | 1813 | static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0}; |
| 1990 | #endif /* DO_FLUSHCACHE */ | 1814 | #endif /* DO_FLUSHCACHE */ |
| 1991 | args[2] = wcache ? 0x02 : 0x82; | 1815 | args[2] = wcache ? 0x02 : 0x82; |
| 1992 | if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache); | 1816 | print_flag_on_off(get_wcache,"drive write-caching", wcache); |
| 1993 | #ifdef DO_FLUSHCACHE | 1817 | #ifdef DO_FLUSHCACHE |
| 1994 | if (!wcache) | 1818 | if (!wcache) |
| 1995 | bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)"); | 1819 | bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)"); |
| @@ -2013,7 +1837,7 @@ static void process_dev(char *devname) | |||
| 2013 | #ifndef WIN_STANDBYNOW2 | 1837 | #ifndef WIN_STANDBYNOW2 |
| 2014 | #define WIN_STANDBYNOW2 0x94 | 1838 | #define WIN_STANDBYNOW2 0x94 |
| 2015 | #endif | 1839 | #endif |
| 2016 | if_printf(get_standbynow," issuing standby command\n"); | 1840 | if (get_standbynow) printf(" issuing standby command\n"); |
| 2017 | args[0] = WIN_STANDBYNOW1; | 1841 | args[0] = WIN_STANDBYNOW1; |
| 2018 | bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)"); | 1842 | bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)"); |
| 2019 | } | 1843 | } |
| @@ -2025,14 +1849,14 @@ static void process_dev(char *devname) | |||
| 2025 | #ifndef WIN_SLEEPNOW2 | 1849 | #ifndef WIN_SLEEPNOW2 |
| 2026 | #define WIN_SLEEPNOW2 0x99 | 1850 | #define WIN_SLEEPNOW2 0x99 |
| 2027 | #endif | 1851 | #endif |
| 2028 | if_printf(get_sleepnow," issuing sleep command\n"); | 1852 | if (get_sleepnow) printf(" issuing sleep command\n"); |
| 2029 | args[0] = WIN_SLEEPNOW1; | 1853 | args[0] = WIN_SLEEPNOW1; |
| 2030 | bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)"); | 1854 | bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)"); |
| 2031 | } | 1855 | } |
| 2032 | if (set_seagate) | 1856 | if (set_seagate) |
| 2033 | { | 1857 | { |
| 2034 | args[0] = 0xfb; | 1858 | args[0] = 0xfb; |
| 2035 | if_printf(get_seagate," disabling Seagate auto powersaving mode\n"); | 1859 | if (get_seagate) printf(" disabling Seagate auto powersaving mode\n"); |
| 2036 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)"); | 1860 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)"); |
| 2037 | } | 1861 | } |
| 2038 | if (set_standby) | 1862 | if (set_standby) |
| @@ -2041,7 +1865,7 @@ static void process_dev(char *devname) | |||
| 2041 | args[1] = standby_requested; | 1865 | args[1] = standby_requested; |
| 2042 | if (get_standby) | 1866 | if (get_standby) |
| 2043 | { | 1867 | { |
| 2044 | printf(" setting standby to %lu", standby_requested); | 1868 | print_flag(1, /*" setting */"standby"/* to %lu"*/, standby_requested); |
| 2045 | interpret_standby(standby_requested); | 1869 | interpret_standby(standby_requested); |
| 2046 | } | 1870 | } |
| 2047 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)"); | 1871 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)"); |
| @@ -2053,7 +1877,7 @@ static void process_dev(char *devname) | |||
| 2053 | char buf[512]; | 1877 | char buf[512]; |
| 2054 | flush_buffer_cache(fd); | 1878 | flush_buffer_cache(fd); |
| 2055 | if (-1 == read(fd, buf, sizeof(buf))) | 1879 | if (-1 == read(fd, buf, sizeof(buf))) |
| 2056 | bb_error_msg("access failed"); | 1880 | bb_perror_msg("read(%d bytes) failed (rc=%d)", sizeof(buf), -1); |
| 2057 | } | 1881 | } |
| 2058 | #endif /* HDIO_DRIVE_CMD */ | 1882 | #endif /* HDIO_DRIVE_CMD */ |
| 2059 | 1883 | ||
| @@ -2070,7 +1894,7 @@ static void process_dev(char *devname) | |||
| 2070 | } | 1894 | } |
| 2071 | else if (verbose | get_mult) | 1895 | else if (verbose | get_mult) |
| 2072 | { | 1896 | { |
| 2073 | printf(" multcount = %2ld", multcount); | 1897 | printf(fmt, "multcount", multcount); |
| 2074 | on_off(multcount); | 1898 | on_off(multcount); |
| 2075 | } | 1899 | } |
| 2076 | } | 1900 | } |
| @@ -2078,33 +1902,25 @@ static void process_dev(char *devname) | |||
| 2078 | { | 1902 | { |
| 2079 | if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT")) | 1903 | if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT")) |
| 2080 | { | 1904 | { |
| 2081 | printf(" IO_support =%3ld (", parm); | 1905 | printf(" IO_support\t=%3ld (", parm); |
| 2082 | switch (parm) | 1906 | if (parm == 0) |
| 2083 | { | 1907 | printf("default 16-bit)\n"); |
| 2084 | case 0: | 1908 | else if (parm == 2) |
| 2085 | printf("default "); | 1909 | printf("16-bit)\n"); |
| 2086 | case 2: | 1910 | else if (parm == 1) |
| 2087 | printf("16-bit)\n"); | 1911 | printf("32-bit)\n"); |
| 2088 | break; | 1912 | else if (parm == 3) |
| 2089 | case 1: | 1913 | printf("32-bit w/sync)\n"); |
| 2090 | printf("32-bit)\n"); | 1914 | else if (parm == 8) |
| 2091 | break; | 1915 | printf("Request-Queue-Bypass)\n"); |
| 2092 | case 3: | 1916 | else |
| 2093 | printf("32-bit w/sync)\n"); | 1917 | printf("\?\?\?)\n"); |
| 2094 | break; | ||
| 2095 | case 8: | ||
| 2096 | printf("Request-Queue-Bypass)\n"); | ||
| 2097 | break; | ||
| 2098 | default: | ||
| 2099 | printf("\?\?\?)\n"); | ||
| 2100 | /*esac*/ | ||
| 2101 | } | ||
| 2102 | } | 1918 | } |
| 2103 | } | 1919 | } |
| 2104 | if (verbose || get_unmask) | 1920 | if (verbose || get_unmask) |
| 2105 | { | 1921 | { |
| 2106 | bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm, | 1922 | bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm, |
| 2107 | "HDIO_GET_UNMASKINTR"," unmaskirq = %2ld"); | 1923 | "HDIO_GET_UNMASKINTR","unmaskirq"); |
| 2108 | } | 1924 | } |
| 2109 | 1925 | ||
| 2110 | 1926 | ||
| @@ -2112,7 +1928,7 @@ static void process_dev(char *devname) | |||
| 2112 | if (verbose || get_dma) { | 1928 | if (verbose || get_dma) { |
| 2113 | if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA")) | 1929 | if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA")) |
| 2114 | { | 1930 | { |
| 2115 | printf(" using_dma = %2ld", parm); | 1931 | printf(fmt, "using_dma", parm); |
| 2116 | if (parm == 8) | 1932 | if (parm == 8) |
| 2117 | printf(" (DMA-Assisted-PIO)\n"); | 1933 | printf(" (DMA-Assisted-PIO)\n"); |
| 2118 | else | 1934 | else |
| @@ -2123,28 +1939,28 @@ static void process_dev(char *devname) | |||
| 2123 | if (get_dma_q) | 1939 | if (get_dma_q) |
| 2124 | { | 1940 | { |
| 2125 | bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm, | 1941 | bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm, |
| 2126 | "HDIO_GET_QDMA"," queue_depth = %2ld"); | 1942 | "HDIO_GET_QDMA","queue_depth"); |
| 2127 | } | 1943 | } |
| 2128 | if (verbose || get_keep) | 1944 | if (verbose || get_keep) |
| 2129 | { | 1945 | { |
| 2130 | bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm, | 1946 | bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm, |
| 2131 | "HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld"); | 1947 | "HDIO_GET_KEEPSETTINGS","keepsettings"); |
| 2132 | } | 1948 | } |
| 2133 | 1949 | ||
| 2134 | if (get_nowerr) | 1950 | if (get_nowerr) |
| 2135 | { | 1951 | { |
| 2136 | bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm, | 1952 | bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm, |
| 2137 | " HDIO_GET_NOWERR"," nowerr = %2ld"); | 1953 | "HDIO_GET_NOWERR","nowerr"); |
| 2138 | } | 1954 | } |
| 2139 | if (verbose || get_readonly) | 1955 | if (verbose || get_readonly) |
| 2140 | { | 1956 | { |
| 2141 | bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm, | 1957 | bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm, |
| 2142 | " BLKROGET"," readonly = %2ld"); | 1958 | "BLKROGET","readonly"); |
| 2143 | } | 1959 | } |
| 2144 | if (verbose || get_readahead) | 1960 | if (verbose || get_readahead) |
| 2145 | { | 1961 | { |
| 2146 | bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm, | 1962 | bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm, |
| 2147 | " BLKRAGET"," readahead = %2ld"); | 1963 | "BLKRAGET","readahead"); |
| 2148 | } | 1964 | } |
| 2149 | if (verbose || get_geom) | 1965 | if (verbose || get_geom) |
| 2150 | { | 1966 | { |
| @@ -2153,7 +1969,7 @@ static void process_dev(char *devname) | |||
| 2153 | struct hd_geometry g; | 1969 | struct hd_geometry g; |
| 2154 | 1970 | ||
| 2155 | if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO")) | 1971 | if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO")) |
| 2156 | printf(" geometry = %u/%u/%u, sectors = %ld, start = %ld\n", | 1972 | printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", |
| 2157 | g.cylinders, g.heads, g.sectors, parm, g.start); | 1973 | g.cylinders, g.heads, g.sectors, parm, g.start); |
| 2158 | } | 1974 | } |
| 2159 | } | 1975 | } |
| @@ -2172,7 +1988,7 @@ static void process_dev(char *devname) | |||
| 2172 | if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0)) | 1988 | if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0)) |
| 2173 | { | 1989 | { |
| 2174 | if (errno != EIO || args[0] != 0 || args[1] != 0) | 1990 | if (errno != EIO || args[0] != 0 || args[1] != 0) |
| 2175 | state = "unknown"; | 1991 | state = "Unknown"; |
| 2176 | else | 1992 | else |
| 2177 | state = "sleeping"; | 1993 | state = "sleeping"; |
| 2178 | } | 1994 | } |
| @@ -2239,7 +2055,7 @@ static void process_dev(char *devname) | |||
| 2239 | { | 2055 | { |
| 2240 | if (get_busstate) | 2056 | if (get_busstate) |
| 2241 | { | 2057 | { |
| 2242 | printf(" setting bus state to %ld", busstate); | 2058 | print_flag(1, "bus state", busstate); |
| 2243 | bus_state_value(busstate); | 2059 | bus_state_value(busstate); |
| 2244 | } | 2060 | } |
| 2245 | bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE"); | 2061 | bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE"); |
| @@ -2250,7 +2066,7 @@ static void process_dev(char *devname) | |||
| 2250 | { | 2066 | { |
| 2251 | if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE")) | 2067 | if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE")) |
| 2252 | { | 2068 | { |
| 2253 | printf(" busstate = %2ld", parm); | 2069 | printf(fmt, "bus state", parm); |
| 2254 | bus_state_value(parm); | 2070 | bus_state_value(parm); |
| 2255 | } | 2071 | } |
| 2256 | } | 2072 | } |
| @@ -2285,7 +2101,7 @@ static void identify_from_stdin(void) | |||
| 2285 | int i, count = read(0, buf, 1280); | 2101 | int i, count = read(0, buf, 1280); |
| 2286 | 2102 | ||
| 2287 | if (count != 1280) | 2103 | if (count != 1280) |
| 2288 | bb_error_msg_and_die("read(1280 bytes) failed (rc=%d)", count); | 2104 | bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count); |
| 2289 | for (i = 0; count >= 4; ++i) | 2105 | for (i = 0; count >= 4; ++i) |
| 2290 | { | 2106 | { |
| 2291 | sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]); | 2107 | sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]); |
| @@ -2386,11 +2202,11 @@ int hdparm_main(int argc, char **argv) | |||
| 2386 | exit(EXIT_SUCCESS); | 2202 | exit(EXIT_SUCCESS); |
| 2387 | } | 2203 | } |
| 2388 | 2204 | ||
| 2389 | verbose = (c == 'v'); | 2205 | verbose |= (c == 'v'); |
| 2390 | USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity = (c == 'I')); | 2206 | USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity = (c == 'I')); |
| 2391 | USE_FEATURE_HDPARM_GET_IDENTITY(get_identity = (c == 'i')); | 2207 | USE_FEATURE_HDPARM_GET_IDENTITY(get_identity = (c == 'i')); |
| 2392 | get_geom = (c == 'g'); | 2208 | get_geom |= (c == 'g'); |
| 2393 | do_flush = (c == 'f'); | 2209 | do_flush |= (c == 'f'); |
| 2394 | if (c == 'q') { | 2210 | if (c == 'q') { |
| 2395 | quiet = 1; | 2211 | quiet = 1; |
| 2396 | noisy = 0; | 2212 | noisy = 0; |
| @@ -2405,8 +2221,8 @@ int hdparm_main(int argc, char **argv) | |||
| 2405 | if (c == 'k') parse_opts(&get_keep, &set_keep, &keep, 0, 1); | 2221 | if (c == 'k') parse_opts(&get_keep, &set_keep, &keep, 0, 1); |
| 2406 | if (c == 'a') parse_opts(&get_readahead, &set_readahead, &Xreadahead, 0, INT_MAX); | 2222 | if (c == 'a') parse_opts(&get_readahead, &set_readahead, &Xreadahead, 0, INT_MAX); |
| 2407 | if (c == 'B') parse_opts(&get_apmmode, &set_apmmode, &apmmode, 1, 255); | 2223 | if (c == 'B') parse_opts(&get_apmmode, &set_apmmode, &apmmode, 1, 255); |
| 2408 | do_flush |= do_timings = (c == 't'); | 2224 | do_flush |= do_timings |= (c == 't'); |
| 2409 | do_flush |= do_ctimings = (c == 'T'); | 2225 | do_flush |= do_ctimings |= (c == 'T'); |
| 2410 | #ifdef HDIO_DRIVE_CMD | 2226 | #ifdef HDIO_DRIVE_CMD |
| 2411 | if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX); | 2227 | if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX); |
| 2412 | if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX); | 2228 | if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX); |
| @@ -2419,7 +2235,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2419 | parse_opts_v3((c == 'C'), &get_powermode, NULL, NULL); | 2235 | parse_opts_v3((c == 'C'), &get_powermode, NULL, NULL); |
| 2420 | parse_opts_v2((c == 'y'), &get_standbynow, &set_standbynow); | 2236 | parse_opts_v2((c == 'y'), &get_standbynow, &set_standbynow); |
| 2421 | parse_opts_v2((c == 'Y'), &get_sleepnow, &set_sleepnow); | 2237 | parse_opts_v2((c == 'Y'), &get_sleepnow, &set_sleepnow); |
| 2422 | reread_partn = (c == 'z'); | 2238 | reread_partn |= (c == 'z'); |
| 2423 | parse_opts_v2((c == 'Z'), &get_seagate, &set_seagate); | 2239 | parse_opts_v2((c == 'Z'), &get_seagate, &set_seagate); |
| 2424 | #endif | 2240 | #endif |
| 2425 | USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX)); | 2241 | USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX)); |
