diff options
Diffstat (limited to 'miscutils/hdparm.c')
-rw-r--r-- | miscutils/hdparm.c | 113 |
1 files changed, 51 insertions, 62 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index b3c240835..396328f72 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -482,19 +482,43 @@ static void print_value_on_off(const char *str, unsigned long argp) | |||
482 | } | 482 | } |
483 | 483 | ||
484 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY | 484 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY |
485 | static void print_ascii(uint16_t *p, uint8_t length); | 485 | static void print_ascii(const char *p, int length) |
486 | { | ||
487 | #if BB_BIG_ENDIAN | ||
488 | #define LE_ONLY(x) | ||
489 | enum { ofs = 0 }; | ||
490 | #else | ||
491 | #define LE_ONLY(x) x | ||
492 | /* every 16bit word is big-endian (i.e. inverted) */ | ||
493 | /* accessing bytes in 1,0, 3,2, 5,4... sequence */ | ||
494 | int ofs = 1; | ||
495 | #endif | ||
496 | |||
497 | length *= 2; | ||
498 | /* find first non-space & print it */ | ||
499 | while (length && p[ofs] != ' ') { | ||
500 | p++; | ||
501 | LE_ONLY(ofs = -ofs;) | ||
502 | length--; | ||
503 | } | ||
504 | while (length && p[ofs]) { | ||
505 | bb_putchar(p[ofs]); | ||
506 | p++; | ||
507 | LE_ONLY(ofs = -ofs;) | ||
508 | length--; | ||
509 | } | ||
510 | bb_putchar('\n'); | ||
511 | #undef LE_ONLY | ||
512 | } | ||
486 | 513 | ||
487 | static void xprint_ascii(uint16_t *val, int i, const char *string, int n) | 514 | static void xprint_ascii(uint16_t *val, int i, const char *string, int n) |
488 | { | 515 | { |
489 | if (val[i]) { | 516 | if (val[i]) { |
490 | printf("\t%-20s", string); | 517 | printf("\t%-20s", string); |
491 | print_ascii(&val[i], n); | 518 | print_ascii((void*)&val[i], n); |
492 | } | 519 | } |
493 | } | 520 | } |
494 | #endif | ||
495 | /* end of busybox specific stuff */ | ||
496 | 521 | ||
497 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY | ||
498 | static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode) | 522 | static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode) |
499 | { | 523 | { |
500 | uint16_t ii; | 524 | uint16_t ii; |
@@ -515,41 +539,11 @@ static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t * | |||
515 | return err_dma; | 539 | return err_dma; |
516 | } | 540 | } |
517 | 541 | ||
518 | static void print_ascii(uint16_t *p, uint8_t length) | ||
519 | { | ||
520 | uint8_t ii; | ||
521 | char cl; | ||
522 | |||
523 | /* find first non-space & print it */ | ||
524 | for (ii = 0; ii < length; ii++) { | ||
525 | if ((char)((*p)>>8) != ' ') | ||
526 | break; | ||
527 | cl = (char)(*p); | ||
528 | if (cl != ' ') { | ||
529 | if (cl != '\0') | ||
530 | printf("%c", cl); | ||
531 | p++; | ||
532 | ii++; | ||
533 | break; | ||
534 | } | ||
535 | p++; | ||
536 | } | ||
537 | /* print the rest */ | ||
538 | for (; ii< length; ii++) { | ||
539 | if (!(*p)) | ||
540 | break; /* some older devices have NULLs */ | ||
541 | printf("%c%c", (char)((*p)>>8), (char)(*p)); | ||
542 | p++; | ||
543 | } | ||
544 | puts(""); | ||
545 | } | ||
546 | |||
547 | // Parse 512 byte disk identification block and print much crap. | 542 | // Parse 512 byte disk identification block and print much crap. |
548 | 543 | ||
549 | static void identify(uint16_t *id_supplied) | 544 | static void identify(uint16_t *val) |
550 | { | 545 | { |
551 | uint16_t buf[256]; | 546 | uint16_t ii, jj, kk; |
552 | uint16_t *val, ii, jj, kk; | ||
553 | uint16_t like_std = 1, std = 0, min_std = 0xffff; | 547 | uint16_t like_std = 1, std = 0, min_std = 0xffff; |
554 | uint16_t dev = NO_DEV, eqpt = NO_DEV; | 548 | uint16_t dev = NO_DEV, eqpt = NO_DEV; |
555 | uint8_t have_mode = 0, err_dma = 0; | 549 | uint8_t have_mode = 0, err_dma = 0; |
@@ -557,19 +551,15 @@ static void identify(uint16_t *id_supplied) | |||
557 | uint32_t ll, mm, nn, oo; | 551 | uint32_t ll, mm, nn, oo; |
558 | uint64_t bbbig; /* (:) */ | 552 | uint64_t bbbig; /* (:) */ |
559 | const char *strng; | 553 | const char *strng; |
554 | #if BB_BIG_ENDIAN | ||
555 | uint16_t buf[256]; | ||
560 | 556 | ||
561 | // Adjust for endianness if necessary. | 557 | // Adjust for endianness |
562 | 558 | swab(val, buf, sizeof(buf)); | |
563 | if (BB_BIG_ENDIAN) { | 559 | val = buf; |
564 | swab(id_supplied, buf, sizeof(buf)); | 560 | #endif |
565 | val = buf; | ||
566 | } else | ||
567 | val = id_supplied; | ||
568 | |||
569 | chksum &= 0xff; | ||
570 | |||
571 | /* check if we recognise the device type */ | 561 | /* check if we recognise the device type */ |
572 | puts(""); | 562 | bb_putchar('\n'); |
573 | if (!(val[GEN_CONFIG] & NOT_ATA)) { | 563 | if (!(val[GEN_CONFIG] & NOT_ATA)) { |
574 | dev = ATA_DEV; | 564 | dev = ATA_DEV; |
575 | printf("ATA device, with "); | 565 | printf("ATA device, with "); |
@@ -686,7 +676,7 @@ static void identify(uint16_t *id_supplied) | |||
686 | else if (like_std > std) | 676 | else if (like_std > std) |
687 | printf("& some of %u\n", like_std); | 677 | printf("& some of %u\n", like_std); |
688 | else | 678 | else |
689 | puts(""); | 679 | bb_putchar('\n'); |
690 | } else { | 680 | } else { |
691 | /* TBD: do CDROM stuff more thoroughly. For now... */ | 681 | /* TBD: do CDROM stuff more thoroughly. For now... */ |
692 | kk = 0; | 682 | kk = 0; |
@@ -786,7 +776,7 @@ static void identify(uint16_t *id_supplied) | |||
786 | if (bbbig > 1000) | 776 | if (bbbig > 1000) |
787 | printf("(%"PRIu64" GB)\n", bbbig/1000); | 777 | printf("(%"PRIu64" GB)\n", bbbig/1000); |
788 | else | 778 | else |
789 | puts(""); | 779 | bb_putchar('\n'); |
790 | } | 780 | } |
791 | 781 | ||
792 | /* hw support of commands (capabilities) */ | 782 | /* hw support of commands (capabilities) */ |
@@ -829,7 +819,7 @@ static void identify(uint16_t *id_supplied) | |||
829 | if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) | 819 | if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
830 | printf(", %s device specific minimum\n", (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no"); | 820 | printf(", %s device specific minimum\n", (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no"); |
831 | else | 821 | else |
832 | puts(""); | 822 | bb_putchar('\n'); |
833 | } | 823 | } |
834 | printf("\tR/W multiple sector transfer: "); | 824 | printf("\tR/W multiple sector transfer: "); |
835 | if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER)) | 825 | if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER)) |
@@ -866,7 +856,7 @@ static void identify(uint16_t *id_supplied) | |||
866 | printf("\tOverlap support:"); | 856 | printf("\tOverlap support:"); |
867 | if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]); | 857 | if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]); |
868 | if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]); | 858 | if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]); |
869 | puts(""); | 859 | bb_putchar('\n'); |
870 | } | 860 | } |
871 | } | 861 | } |
872 | 862 | ||
@@ -893,7 +883,7 @@ static void identify(uint16_t *id_supplied) | |||
893 | err_dma += mode_loop(jj, kk, 'u', &have_mode); | 883 | err_dma += mode_loop(jj, kk, 'u', &have_mode); |
894 | } | 884 | } |
895 | if (err_dma || !have_mode) printf("(?)"); | 885 | if (err_dma || !have_mode) printf("(?)"); |
896 | puts(""); | 886 | bb_putchar('\n'); |
897 | 887 | ||
898 | if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)) | 888 | if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)) |
899 | printf("\t\tInterleaved DMA support\n"); | 889 | printf("\t\tInterleaved DMA support\n"); |
@@ -904,7 +894,7 @@ static void identify(uint16_t *id_supplied) | |||
904 | printf("\t\tCycle time:"); | 894 | printf("\t\tCycle time:"); |
905 | if (val[DMA_TIME_MIN]) printf(" min=%uns", val[DMA_TIME_MIN]); | 895 | if (val[DMA_TIME_MIN]) printf(" min=%uns", val[DMA_TIME_MIN]); |
906 | if (val[DMA_TIME_NORM]) printf(" recommended=%uns", val[DMA_TIME_NORM]); | 896 | if (val[DMA_TIME_NORM]) printf(" recommended=%uns", val[DMA_TIME_NORM]); |
907 | puts(""); | 897 | bb_putchar('\n'); |
908 | } | 898 | } |
909 | } | 899 | } |
910 | 900 | ||
@@ -918,11 +908,11 @@ static void identify(uint16_t *id_supplied) | |||
918 | if (jj & 0x0001) printf("pio%d ", ii); | 908 | if (jj & 0x0001) printf("pio%d ", ii); |
919 | jj >>=1; | 909 | jj >>=1; |
920 | } | 910 | } |
921 | puts(""); | 911 | bb_putchar('\n'); |
922 | } else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE)) { | 912 | } else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE)) { |
923 | for (ii = 0; ii <= val[PIO_MODE]>>8; ii++) | 913 | for (ii = 0; ii <= val[PIO_MODE]>>8; ii++) |
924 | printf("pio%d ", ii); | 914 | printf("pio%d ", ii); |
925 | puts(""); | 915 | bb_putchar('\n'); |
926 | } else | 916 | } else |
927 | printf("unknown\n"); | 917 | printf("unknown\n"); |
928 | 918 | ||
@@ -931,7 +921,7 @@ static void identify(uint16_t *id_supplied) | |||
931 | printf("\t\tCycle time:"); | 921 | printf("\t\tCycle time:"); |
932 | if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); | 922 | if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); |
933 | if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); | 923 | if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); |
934 | puts(""); | 924 | bb_putchar('\n'); |
935 | } | 925 | } |
936 | } | 926 | } |
937 | 927 | ||
@@ -982,7 +972,7 @@ static void identify(uint16_t *id_supplied) | |||
982 | printf("\t"); | 972 | printf("\t"); |
983 | if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, ""); | 973 | if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, ""); |
984 | if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED "); | 974 | if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED "); |
985 | puts(""); | 975 | bb_putchar('\n'); |
986 | } | 976 | } |
987 | } | 977 | } |
988 | 978 | ||
@@ -1134,7 +1124,7 @@ static void dump_identity(const struct hd_driveid *id) | |||
1134 | else | 1124 | else |
1135 | printf("off"); | 1125 | printf("off"); |
1136 | } | 1126 | } |
1137 | puts(""); | 1127 | bb_putchar('\n'); |
1138 | 1128 | ||
1139 | if (!(id->field_valid & 1)) | 1129 | if (!(id->field_valid & 1)) |
1140 | printf(" (maybe):"); | 1130 | printf(" (maybe):"); |
@@ -1905,7 +1895,7 @@ static void parse_xfermode(int flag, smallint *get, smallint *set, int *value) | |||
1905 | 1895 | ||
1906 | /*------- getopt short options --------*/ | 1896 | /*------- getopt short options --------*/ |
1907 | static const char hdparm_options[] ALIGN1 = | 1897 | static const char hdparm_options[] ALIGN1 = |
1908 | "gfu::n::p:r::m::c::k::a::B:tTh" | 1898 | "gfu::n::p:r::m::c::k::a::B:tT" |
1909 | USE_FEATURE_HDPARM_GET_IDENTITY("iI") | 1899 | USE_FEATURE_HDPARM_GET_IDENTITY("iI") |
1910 | USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::") | 1900 | USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::") |
1911 | #ifdef HDIO_DRIVE_CMD | 1901 | #ifdef HDIO_DRIVE_CMD |
@@ -1933,7 +1923,6 @@ int hdparm_main(int argc, char **argv) | |||
1933 | 1923 | ||
1934 | while ((c = getopt(argc, argv, hdparm_options)) >= 0) { | 1924 | while ((c = getopt(argc, argv, hdparm_options)) >= 0) { |
1935 | flagcount++; | 1925 | flagcount++; |
1936 | if (c == 'h') bb_show_usage(); /* EXIT */ | ||
1937 | USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I')); | 1926 | USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I')); |
1938 | USE_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); | 1927 | USE_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); |
1939 | get_geom |= (c == 'g'); | 1928 | get_geom |= (c == 'g'); |
@@ -1999,7 +1988,7 @@ int hdparm_main(int argc, char **argv) | |||
1999 | if (!*argv) { | 1988 | if (!*argv) { |
2000 | if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO)) | 1989 | if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO)) |
2001 | identify_from_stdin(); /* EXIT */ | 1990 | identify_from_stdin(); /* EXIT */ |
2002 | else bb_show_usage(); | 1991 | bb_show_usage(); |
2003 | } | 1992 | } |
2004 | 1993 | ||
2005 | do { | 1994 | do { |