aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 14:48:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 14:48:03 +0200
commit6d335be21167bbc93b7d8cd434333d78463b5b92 (patch)
tree81ced7ef1be41ba98a5880452de0813c63aad1ac
parent73f379923625fcbe9b8ea9497309356977e7c33d (diff)
downloadbusybox-w32-6d335be21167bbc93b7d8cd434333d78463b5b92.tar.gz
busybox-w32-6d335be21167bbc93b7d8cd434333d78463b5b92.tar.bz2
busybox-w32-6d335be21167bbc93b7d8cd434333d78463b5b92.zip
hdparm: correct (t & 1) ? '0' : '5' thinko; wrap 80+ col lines
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/hdparm.c126
1 files changed, 83 insertions, 43 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index f9638887a..ece01fb08 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -870,16 +870,27 @@ static void identify(uint16_t *val)
870 } else { 870 } else {
871 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ 871 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
872 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; 872 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
873 mm = 0; bbbig = 0; 873 mm = 0;
874 bbbig = 0;
874 if ((ll > 0x00FBFC10) && (!val[LCYLS])) 875 if ((ll > 0x00FBFC10) && (!val[LCYLS]))
875 printf("\tCHS addressing not supported\n"); 876 printf("\tCHS addressing not supported\n");
876 else { 877 else {
877 jj = val[WHATS_VALID] & OK_W54_58; 878 jj = val[WHATS_VALID] & OK_W54_58;
878 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", 879 printf("\tLogical\t\tmax\tcurrent\n"
879 val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0); 880 "\tcylinders\t%u\t%u\n"
881 "\theads\t\t%u\t%u\n"
882 "\tsectors/track\t%u\t%u\n"
883 "\t--\n",
884 val[LCYLS],
885 jj ? val[LCYLS_CUR] : 0,
886 val[LHEADS],
887 jj ? val[LHEADS_CUR] : 0,
888 val[LSECTS],
889 jj ? val[LSECTS_CUR] : 0);
880 890
881 if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) 891 if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES]))
882 printf("\tbytes/track: %u\tbytes/sector: %u\n", val[TRACK_BYTES], val[SECT_BYTES]); 892 printf("\tbytes/track: %u\tbytes/sector: %u\n",
893 val[TRACK_BYTES], val[SECT_BYTES]);
883 894
884 if (jj) { 895 if (jj) {
885 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; 896 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
@@ -921,22 +932,24 @@ static void identify(uint16_t *val)
921 printf("Capabilities:\n\t"); 932 printf("Capabilities:\n\t");
922 933
923 if (dev == ATAPI_DEV) { 934 if (dev == ATAPI_DEV) {
924 if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, "); 935 if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP))
925 if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, "); 936 printf("Cmd queuing, ");
937 if (val[CAPAB_0] & OVLP_SUP)
938 printf("Cmd overlap, ");
926 } 939 }
927 if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); 940 if (val[CAPAB_0] & LBA_SUP) printf("LBA, ");
928 941
929 if (like_std != 1) { 942 if (like_std != 1) {
930 printf("IORDY%s(can%s be disabled)\n", 943 printf("IORDY%s(can%s be disabled)\n",
931 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", 944 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
932 (val[CAPAB_0] & IORDY_OFF) ? "" :"not"); 945 (val[CAPAB_0] & IORDY_OFF) ? "" :"not");
933 } else 946 } else
934 printf("no IORDY\n"); 947 printf("no IORDY\n");
935 948
936 if ((like_std == 1) && val[BUF_TYPE]) { 949 if ((like_std == 1) && val[BUF_TYPE]) {
937 printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], 950 printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE],
938 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", 951 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
939 (val[BUF_TYPE] > 2) ? " with read caching ability" : ""); 952 (val[BUF_TYPE] > 2) ? " with read caching ability" : "");
940 } 953 }
941 954
942 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) { 955 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) {
@@ -953,9 +966,11 @@ static void identify(uint16_t *val)
953 if (like_std == 1) 966 if (like_std == 1)
954 printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : ""); 967 printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : "");
955 else { 968 else {
956 printf("\tStandby timer values: spec'd by %s", (val[CAPAB_0] & STD_STBY) ? "Standard" : "Vendor"); 969 printf("\tStandby timer values: spec'd by %s",
970 (val[CAPAB_0] & STD_STBY) ? "standard" : "vendor");
957 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) 971 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
958 printf(", %s device specific minimum\n", (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no"); 972 printf(", %s device specific minimum\n",
973 (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no");
959 else 974 else
960 bb_putchar('\n'); 975 bb_putchar('\n');
961 } 976 }
@@ -983,7 +998,8 @@ static void identify(uint16_t *val)
983 } 998 }
984 if (like_std > 5 && val[ACOUSTIC]) { 999 if (like_std > 5 && val[ACOUSTIC]) {
985 printf("\tRecommended acoustic management value: %u, current value: %u\n", 1000 printf("\tRecommended acoustic management value: %u, current value: %u\n",
986 (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); 1001 (val[ACOUSTIC] >> 8) & 0x00ff,
1002 val[ACOUSTIC] & 0x00ff);
987 } 1003 }
988 } else { 1004 } else {
989 /* ATAPI */ 1005 /* ATAPI */
@@ -992,8 +1008,11 @@ static void identify(uint16_t *val)
992 1008
993 if (val[PKT_REL] || val[SVC_NBSY]) { 1009 if (val[PKT_REL] || val[SVC_NBSY]) {
994 printf("\tOverlap support:"); 1010 printf("\tOverlap support:");
995 if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]); 1011 if (val[PKT_REL])
996 if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]); 1012 printf(" %uus to release bus.", val[PKT_REL]);
1013 if (val[SVC_NBSY])
1014 printf(" %uus to clear BSY after SERVICE cmd.",
1015 val[SVC_NBSY]);
997 bb_putchar('\n'); 1016 bb_putchar('\n');
998 } 1017 }
999 } 1018 }
@@ -1057,14 +1076,17 @@ static void identify(uint16_t *val)
1057 if (val[WHATS_VALID] & OK_W64_70) { 1076 if (val[WHATS_VALID] & OK_W64_70) {
1058 if (val[PIO_NO_FLOW] || val[PIO_FLOW]) { 1077 if (val[PIO_NO_FLOW] || val[PIO_FLOW]) {
1059 printf("\t\tCycle time:"); 1078 printf("\t\tCycle time:");
1060 if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); 1079 if (val[PIO_NO_FLOW])
1061 if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); 1080 printf(" no flow control=%uns", val[PIO_NO_FLOW]);
1081 if (val[PIO_FLOW])
1082 printf(" IORDY flow control=%uns", val[PIO_FLOW]);
1062 bb_putchar('\n'); 1083 bb_putchar('\n');
1063 } 1084 }
1064 } 1085 }
1065 1086
1066 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) { 1087 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) {
1067 printf("Commands/features:\n\tEnabled\tSupported:\n"); 1088 printf("Commands/features:\n"
1089 "\tEnabled\tSupported:\n");
1068 jj = val[CMDS_SUPP_0]; 1090 jj = val[CMDS_SUPP_0];
1069 kk = val[CMDS_EN_0]; 1091 kk = val[CMDS_EN_0];
1070 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) { 1092 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) {
@@ -1098,11 +1120,14 @@ static void identify(uint16_t *val)
1098 jj = val[SECU_STATUS]; 1120 jj = val[SECU_STATUS];
1099 if (jj) { 1121 if (jj) {
1100 for (ii = 0; ii < NUM_SECU_STR; ii++) { 1122 for (ii = 0; ii < NUM_SECU_STR; ii++) {
1101 printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "", nth_string(secu_str, ii)); 1123 printf("\t%s\t%s\n",
1124 (!(jj & 0x0001)) ? "not" : "",
1125 nth_string(secu_str, ii));
1102 jj >>=1; 1126 jj >>=1;
1103 } 1127 }
1104 if (val[SECU_STATUS] & SECU_ENABLED) { 1128 if (val[SECU_STATUS] & SECU_ENABLED) {
1105 printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); 1129 printf("\tSecurity level %s\n",
1130 (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high");
1106 } 1131 }
1107 } 1132 }
1108 jj = val[ERASE_TIME] & ERASE_BITS; 1133 jj = val[ERASE_TIME] & ERASE_BITS;
@@ -1127,16 +1152,20 @@ static void identify(uint16_t *val)
1127 strng = " determined by CSEL"; 1152 strng = " determined by CSEL";
1128 else 1153 else
1129 strng = ""; 1154 strng = "";
1130 printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n", 1155 printf("HW reset results:\n"
1131 (val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng); 1156 "\tCBLID- %s Vih\n"
1157 "\tDevice num = %i%s\n",
1158 (val[HWRST_RSLT] & CBLID) ? "above" : "below",
1159 !(oo), strng);
1132 } 1160 }
1133 1161
1134 /* more stuff from std 5 */ 1162 /* more stuff from std 5 */
1135 if ((like_std > 4) && (eqpt != CDROM)) { 1163 if ((like_std > 4) && (eqpt != CDROM)) {
1136 if (val[CFA_PWR_MODE] & VALID_W160) { 1164 if (val[CFA_PWR_MODE] & VALID_W160) {
1137 printf("CFA power mode 1:\n\t%s%s\n", (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled", 1165 printf("CFA power mode 1:\n"
1138 (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : ""); 1166 "\t%s%s\n",
1139 1167 (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled",
1168 (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : "");
1140 if (val[CFA_PWR_MODE] & MAX_AMPS) 1169 if (val[CFA_PWR_MODE] & MAX_AMPS)
1141 printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS); 1170 printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS);
1142 } 1171 }
@@ -1184,11 +1213,12 @@ static void dump_identity(const struct hd_driveid *id)
1184 printf(" %s", nth_string(cfg_str, i)); 1213 printf(" %s", nth_string(cfg_str, i));
1185 } 1214 }
1186 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" 1215 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n"
1187 " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", 1216 " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u",
1188 id->cyls, id->heads, id->sectors, id->track_bytes, 1217 id->cyls, id->heads, id->sectors, id->track_bytes,
1189 id->sector_bytes, id->ecc_bytes, 1218 id->sector_bytes, id->ecc_bytes,
1190 id->buf_type, nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type), 1219 id->buf_type,
1191 id->buf_size/2, id->max_multsect); 1220 nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type),
1221 id->buf_size/2, id->max_multsect);
1192 if (id->max_multsect) { 1222 if (id->max_multsect) {
1193 printf(", MultSect="); 1223 printf(", MultSect=");
1194 if (!(id->multsect_valid & 1)) 1224 if (!(id->multsect_valid & 1))
@@ -1213,7 +1243,10 @@ static void dump_identity(const struct hd_driveid *id)
1213 if (id->capability & 2) 1243 if (id->capability & 2)
1214 printf(", LBAsects=%u", id->lba_capacity); 1244 printf(", LBAsects=%u", id->lba_capacity);
1215 1245
1216 printf("\n IORDY=%s", (id->capability & 8) ? (id->capability & 4) ? "on/off" : "yes" : "no"); 1246 printf("\n IORDY=%s",
1247 (id->capability & 8)
1248 ? ((id->capability & 4) ? "on/off" : "yes")
1249 : "no");
1217 1250
1218 if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2)) 1251 if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2))
1219 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); 1252 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
@@ -1285,12 +1318,14 @@ static void dump_identity(const struct hd_driveid *id)
1285 if ((id->minor_rev_num && id->minor_rev_num <= 31) 1318 if ((id->minor_rev_num && id->minor_rev_num <= 31)
1286 || (id->major_rev_num && id->minor_rev_num <= 31) 1319 || (id->major_rev_num && id->minor_rev_num <= 31)
1287 ) { 1320 ) {
1288 printf("\n Drive conforms to: %s: ", (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown"); 1321 printf("\n Drive conforms to: %s: ",
1289 if (id->major_rev_num != 0x0000 && /* NOVAL_0 */ 1322 (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown");
1290 id->major_rev_num != 0xFFFF) { /* NOVAL_1 */ 1323 if (id->major_rev_num != 0x0000 /* NOVAL_0 */
1324 && id->major_rev_num != 0xFFFF /* NOVAL_1 */
1325 ) {
1291 for (i = 0; i <= 15; i++) { 1326 for (i = 0; i <= 15; i++) {
1292 if (id->major_rev_num & (1<<i)) 1327 if (id->major_rev_num & (1<<i))
1293 printf(" ATA/ATAPI-%u", i); 1328 printf(" ATA/ATAPI-%u", i);
1294 } 1329 }
1295 } 1330 }
1296 } 1331 }
@@ -1450,10 +1485,10 @@ static void interpret_standby(uint8_t standby)
1450 printf("off"); 1485 printf("off");
1451 } else if (standby <= 240 || standby == 252 || standby == 255) { 1486 } else if (standby <= 240 || standby == 252 || standby == 255) {
1452 /* standby is in 5 sec units */ 1487 /* standby is in 5 sec units */
1453 printf("%u minutes %u seconds", standby / 12, (standby*5) % 60); 1488 printf("%u minutes %u seconds", standby / (60/5), standby % (60/5));
1454 } else if (standby <= 251) { 1489 } else if (standby <= 251) {
1455 unsigned t = (standby - 240); /* t is in 30 min units */; 1490 unsigned t = (standby - 240); /* t is in 30 min units */;
1456 printf("%u.%c hours", t / 2, (t & 1) ? '0' : '5'); 1491 printf("%u.%c hours", t / 2, (t & 1) ? '5' : '0');
1457 } 1492 }
1458 if (standby == 253) 1493 if (standby == 253)
1459 printf("vendor-specific"); 1494 printf("vendor-specific");
@@ -1653,10 +1688,13 @@ static void process_dev(char *devname)
1653 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1688 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1654 } 1689 }
1655 if (set_apmmode) { 1690 if (set_apmmode) {
1656 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */ 1691 /* feature register */
1692 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */;
1657 args[1] = apmmode; /* sector count register 1-255 */ 1693 args[1] = apmmode; /* sector count register 1-255 */
1658 if (get_apmmode) 1694 if (get_apmmode)
1659 printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode); 1695 printf(" setting APM level to %s 0x%02lX (%ld)\n",
1696 (apmmode == 255) ? "disabled" : "",
1697 apmmode, apmmode);
1660 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1698 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1661 args[1] = 0; 1699 args[1] = 0;
1662 } 1700 }
@@ -1707,7 +1745,8 @@ static void process_dev(char *devname)
1707 } 1745 }
1708 if (set_seagate) { 1746 if (set_seagate) {
1709 args[0] = 0xfb; 1747 args[0] = 0xfb;
1710 if (get_seagate) printf(" disabling Seagate auto powersaving mode\n"); 1748 if (get_seagate)
1749 printf(" disabling Seagate auto powersaving mode\n");
1711 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1750 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1712 } 1751 }
1713 if (set_standby) { 1752 if (set_standby) {
@@ -1725,14 +1764,15 @@ static void process_dev(char *devname)
1725 char buf[512]; 1764 char buf[512];
1726 flush_buffer_cache(); 1765 flush_buffer_cache();
1727 if (-1 == read(fd, buf, sizeof(buf))) 1766 if (-1 == read(fd, buf, sizeof(buf)))
1728 bb_perror_msg("read(%d bytes) failed (rc=-1)", sizeof(buf)); 1767 bb_perror_msg("read of 512 bytes failed");
1729 } 1768 }
1730#endif /* HDIO_DRIVE_CMD */ 1769#endif /* HDIO_DRIVE_CMD */
1731 1770
1732 if (get_mult || get_identity) { 1771 if (get_mult || get_identity) {
1733 multcount = -1; 1772 multcount = -1;
1734 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { 1773 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) {
1735 if (get_mult && ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn. */ 1774 /* To be coherent with ioctl_or_warn. */
1775 if (get_mult && ENABLE_IOCTL_HEX2STR_ERROR)
1736 bb_perror_msg("HDIO_GET_MULTCOUNT"); 1776 bb_perror_msg("HDIO_GET_MULTCOUNT");
1737 else 1777 else
1738 bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT); 1778 bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT);
@@ -1804,7 +1844,7 @@ static void process_dev(char *devname)
1804 1844
1805 if (!ioctl_or_warn(fd, HDIO_GETGEO, &g)) 1845 if (!ioctl_or_warn(fd, HDIO_GETGEO, &g))
1806 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", 1846 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n",
1807 g.cylinders, g.heads, g.sectors, parm, g.start); 1847 g.cylinders, g.heads, g.sectors, parm, g.start);
1808 } 1848 }
1809 } 1849 }
1810#ifdef HDIO_DRIVE_CMD 1850#ifdef HDIO_DRIVE_CMD