aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 21:50:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 21:50:29 +0200
commitd8aeba4eed8de9491abcecce27391c5d04c4f77e (patch)
treee5e97b663c0051fdcca140f3b1b5145b4e65762a
parente18255d1dadc9686daa328fa121423b47d2f6af4 (diff)
parentc7068455393e03a340fe8f64126973f28bc9fd3a (diff)
downloadbusybox-w32-d8aeba4eed8de9491abcecce27391c5d04c4f77e.tar.gz
busybox-w32-d8aeba4eed8de9491abcecce27391c5d04c4f77e.tar.bz2
busybox-w32-d8aeba4eed8de9491abcecce27391c5d04c4f77e.zip
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
-rw-r--r--libbb/appletlib.c23
-rw-r--r--miscutils/hdparm.c431
2 files changed, 237 insertions, 217 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 8f3729f71..7b3f27c36 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -633,15 +633,14 @@ static int busybox_main(char **argv)
633 if (!argv[1]) { 633 if (!argv[1]) {
634 /* Called without arguments */ 634 /* Called without arguments */
635 const char *a; 635 const char *a;
636 unsigned col, output_width; 636 int col;
637 unsigned output_width;
637 help: 638 help:
638 output_width = 80; 639 output_width = 80;
639 if (ENABLE_FEATURE_AUTOWIDTH) { 640 if (ENABLE_FEATURE_AUTOWIDTH) {
640 /* Obtain the terminal width */ 641 /* Obtain the terminal width */
641 get_terminal_width_height(0, &output_width, NULL); 642 get_terminal_width_height(0, &output_width, NULL);
642 } 643 }
643 /* leading tab and room to wrap */
644 output_width -= MAX_APPLET_NAME_LEN + 8;
645 644
646 dup2(1, 2); 645 dup2(1, 2);
647 full_write2_str(bb_banner); /* reuse const string... */ 646 full_write2_str(bb_banner); /* reuse const string... */
@@ -661,17 +660,23 @@ static int busybox_main(char **argv)
661 "Currently defined functions:\n"); 660 "Currently defined functions:\n");
662 col = 0; 661 col = 0;
663 a = applet_names; 662 a = applet_names;
663 /* prevent last comma to be in the very last pos */
664 output_width--;
664 while (*a) { 665 while (*a) {
665 int len; 666 int len2 = strlen(a) + 2;
666 if (col > output_width) { 667 if (col >= (int)output_width - len2) {
667 full_write2_str(",\n"); 668 full_write2_str(",\n");
668 col = 0; 669 col = 0;
669 } 670 }
670 full_write2_str(col ? ", " : "\t"); 671 if (col == 0) {
672 col = 6;
673 full_write2_str("\t");
674 } else {
675 full_write2_str(", ");
676 }
671 full_write2_str(a); 677 full_write2_str(a);
672 len = strlen(a); 678 col += len2;
673 col += len + 2; 679 a += len2 - 1;
674 a += len + 1;
675 } 680 }
676 full_write2_str("\n\n"); 681 full_write2_str("\n\n");
677 return 0; 682 return 0;
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index f9638887a..7034778e7 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -11,7 +11,6 @@
11 * hdparm.c - Command line interface to get/set hard disk parameters 11 * hdparm.c - Command line interface to get/set hard disk parameters
12 * - by Mark Lord (C) 1994-2002 -- freely distributable 12 * - by Mark Lord (C) 1994-2002 -- freely distributable
13 */ 13 */
14
15#include "libbb.h" 14#include "libbb.h"
16#include <linux/hdreg.h> 15#include <linux/hdreg.h>
17 16
@@ -232,6 +231,10 @@
232#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ 231#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
233 232
234 233
234#define IS_GET 1
235#define IS_SET 2
236
237
235enum { fd = 3 }; 238enum { fd = 3 };
236 239
237 240
@@ -241,19 +244,16 @@ struct globals {
241 smallint do_ctimings, do_timings; 244 smallint do_ctimings, do_timings;
242 smallint reread_partn; 245 smallint reread_partn;
243 smallint set_piomode, noisy_piomode; 246 smallint set_piomode, noisy_piomode;
244 smallint set_readahead, get_readahead; 247 smallint getset_readahead;
245 smallint set_readonly, get_readonly; 248 smallint getset_readonly;
246 smallint set_unmask, get_unmask; 249 smallint getset_unmask;
247 smallint set_mult, get_mult; 250 smallint getset_mult;
248#ifdef HDIO_GET_QDMA 251#ifdef HDIO_GET_QDMA
249 smallint get_dma_q; 252 smallint getset_dma_q;
250#ifdef HDIO_SET_QDMA
251 smallint set_dma_q;
252#endif
253#endif 253#endif
254 smallint set_nowerr, get_nowerr; 254 smallint getset_nowerr;
255 smallint set_keep, get_keep; 255 smallint getset_keep;
256 smallint set_io32bit, get_io32bit; 256 smallint getset_io32bit;
257 int piomode; 257 int piomode;
258 unsigned long Xreadahead; 258 unsigned long Xreadahead;
259 unsigned long readonly; 259 unsigned long readonly;
@@ -267,22 +267,22 @@ struct globals {
267 unsigned long io32bit; 267 unsigned long io32bit;
268#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA 268#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
269 unsigned long dma; 269 unsigned long dma;
270 smallint set_dma, get_dma; 270 smallint getset_dma;
271#endif 271#endif
272#ifdef HDIO_DRIVE_CMD 272#ifdef HDIO_DRIVE_CMD
273 smallint set_xfermode, get_xfermode; 273 smallint set_xfermode, get_xfermode;
274 smallint set_dkeep, get_dkeep; 274 smallint getset_dkeep;
275 smallint set_standby, get_standby; 275 smallint getset_standby;
276 smallint set_lookahead, get_lookahead; 276 smallint getset_lookahead;
277 smallint set_prefetch, get_prefetch; 277 smallint getset_prefetch;
278 smallint set_defects, get_defects; 278 smallint getset_defects;
279 smallint set_wcache, get_wcache; 279 smallint getset_wcache;
280 smallint set_doorlock, get_doorlock; 280 smallint getset_doorlock;
281 smallint set_seagate, get_seagate; 281 smallint set_seagate;
282 smallint set_standbynow, get_standbynow; 282 smallint set_standbynow;
283 smallint set_sleepnow, get_sleepnow; 283 smallint set_sleepnow;
284 smallint get_powermode; 284 smallint get_powermode;
285 smallint set_apmmode, get_apmmode; 285 smallint getset_apmmode;
286 int xfermode_requested; 286 int xfermode_requested;
287 unsigned long dkeep; 287 unsigned long dkeep;
288 unsigned long standby_requested; /* 0..255 */ 288 unsigned long standby_requested; /* 0..255 */
@@ -294,7 +294,7 @@ struct globals {
294 unsigned long apmmode; 294 unsigned long apmmode;
295#endif 295#endif
296 IF_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;) 296 IF_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;)
297 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint set_busstate, get_busstate;) 297 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint getset_busstate;)
298 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;) 298 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;)
299 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;) 299 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;)
300 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;) 300 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;)
@@ -323,22 +323,14 @@ struct BUG_G_too_big {
323#define reread_partn (G.reread_partn ) 323#define reread_partn (G.reread_partn )
324#define set_piomode (G.set_piomode ) 324#define set_piomode (G.set_piomode )
325#define noisy_piomode (G.noisy_piomode ) 325#define noisy_piomode (G.noisy_piomode )
326#define set_readahead (G.set_readahead ) 326#define getset_readahead (G.getset_readahead )
327#define get_readahead (G.get_readahead ) 327#define getset_readonly (G.getset_readonly )
328#define set_readonly (G.set_readonly ) 328#define getset_unmask (G.getset_unmask )
329#define get_readonly (G.get_readonly ) 329#define getset_mult (G.getset_mult )
330#define set_unmask (G.set_unmask ) 330#define getset_dma_q (G.getset_dma_q )
331#define get_unmask (G.get_unmask ) 331#define getset_nowerr (G.getset_nowerr )
332#define set_mult (G.set_mult ) 332#define getset_keep (G.getset_keep )
333#define get_mult (G.get_mult ) 333#define getset_io32bit (G.getset_io32bit )
334#define set_dma_q (G.set_dma_q )
335#define get_dma_q (G.get_dma_q )
336#define set_nowerr (G.set_nowerr )
337#define get_nowerr (G.get_nowerr )
338#define set_keep (G.set_keep )
339#define get_keep (G.get_keep )
340#define set_io32bit (G.set_io32bit )
341#define get_io32bit (G.get_io32bit )
342#define piomode (G.piomode ) 334#define piomode (G.piomode )
343#define Xreadahead (G.Xreadahead ) 335#define Xreadahead (G.Xreadahead )
344#define readonly (G.readonly ) 336#define readonly (G.readonly )
@@ -349,33 +341,21 @@ struct BUG_G_too_big {
349#define keep (G.keep ) 341#define keep (G.keep )
350#define io32bit (G.io32bit ) 342#define io32bit (G.io32bit )
351#define dma (G.dma ) 343#define dma (G.dma )
352#define set_dma (G.set_dma ) 344#define getset_dma (G.getset_dma )
353#define get_dma (G.get_dma )
354#define set_xfermode (G.set_xfermode ) 345#define set_xfermode (G.set_xfermode )
355#define get_xfermode (G.get_xfermode ) 346#define get_xfermode (G.get_xfermode )
356#define set_dkeep (G.set_dkeep ) 347#define getset_dkeep (G.getset_dkeep )
357#define get_dkeep (G.get_dkeep ) 348#define getset_standby (G.getset_standby )
358#define set_standby (G.set_standby ) 349#define getset_lookahead (G.getset_lookahead )
359#define get_standby (G.get_standby ) 350#define getset_prefetch (G.getset_prefetch )
360#define set_lookahead (G.set_lookahead ) 351#define getset_defects (G.getset_defects )
361#define get_lookahead (G.get_lookahead ) 352#define getset_wcache (G.getset_wcache )
362#define set_prefetch (G.set_prefetch ) 353#define getset_doorlock (G.getset_doorlock )
363#define get_prefetch (G.get_prefetch )
364#define set_defects (G.set_defects )
365#define get_defects (G.get_defects )
366#define set_wcache (G.set_wcache )
367#define get_wcache (G.get_wcache )
368#define set_doorlock (G.set_doorlock )
369#define get_doorlock (G.get_doorlock )
370#define set_seagate (G.set_seagate ) 354#define set_seagate (G.set_seagate )
371#define get_seagate (G.get_seagate )
372#define set_standbynow (G.set_standbynow ) 355#define set_standbynow (G.set_standbynow )
373#define get_standbynow (G.get_standbynow )
374#define set_sleepnow (G.set_sleepnow ) 356#define set_sleepnow (G.set_sleepnow )
375#define get_sleepnow (G.get_sleepnow )
376#define get_powermode (G.get_powermode ) 357#define get_powermode (G.get_powermode )
377#define set_apmmode (G.set_apmmode ) 358#define getset_apmmode (G.getset_apmmode )
378#define get_apmmode (G.get_apmmode )
379#define xfermode_requested (G.xfermode_requested ) 359#define xfermode_requested (G.xfermode_requested )
380#define dkeep (G.dkeep ) 360#define dkeep (G.dkeep )
381#define standby_requested (G.standby_requested ) 361#define standby_requested (G.standby_requested )
@@ -386,8 +366,7 @@ struct BUG_G_too_big {
386#define doorlock (G.doorlock ) 366#define doorlock (G.doorlock )
387#define apmmode (G.apmmode ) 367#define apmmode (G.apmmode )
388#define get_IDentity (G.get_IDentity ) 368#define get_IDentity (G.get_IDentity )
389#define set_busstate (G.set_busstate ) 369#define getset_busstate (G.getset_busstate )
390#define get_busstate (G.get_busstate )
391#define perform_reset (G.perform_reset ) 370#define perform_reset (G.perform_reset )
392#define perform_tristate (G.perform_tristate ) 371#define perform_tristate (G.perform_tristate )
393#define unregister_hwif (G.unregister_hwif ) 372#define unregister_hwif (G.unregister_hwif )
@@ -870,16 +849,27 @@ static void identify(uint16_t *val)
870 } else { 849 } else {
871 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ 850 /* 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]; 851 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
873 mm = 0; bbbig = 0; 852 mm = 0;
853 bbbig = 0;
874 if ((ll > 0x00FBFC10) && (!val[LCYLS])) 854 if ((ll > 0x00FBFC10) && (!val[LCYLS]))
875 printf("\tCHS addressing not supported\n"); 855 printf("\tCHS addressing not supported\n");
876 else { 856 else {
877 jj = val[WHATS_VALID] & OK_W54_58; 857 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", 858 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); 859 "\tcylinders\t%u\t%u\n"
860 "\theads\t\t%u\t%u\n"
861 "\tsectors/track\t%u\t%u\n"
862 "\t--\n",
863 val[LCYLS],
864 jj ? val[LCYLS_CUR] : 0,
865 val[LHEADS],
866 jj ? val[LHEADS_CUR] : 0,
867 val[LSECTS],
868 jj ? val[LSECTS_CUR] : 0);
880 869
881 if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) 870 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]); 871 printf("\tbytes/track: %u\tbytes/sector: %u\n",
872 val[TRACK_BYTES], val[SECT_BYTES]);
883 873
884 if (jj) { 874 if (jj) {
885 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; 875 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
@@ -921,22 +911,24 @@ static void identify(uint16_t *val)
921 printf("Capabilities:\n\t"); 911 printf("Capabilities:\n\t");
922 912
923 if (dev == ATAPI_DEV) { 913 if (dev == ATAPI_DEV) {
924 if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, "); 914 if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP))
925 if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, "); 915 printf("Cmd queuing, ");
916 if (val[CAPAB_0] & OVLP_SUP)
917 printf("Cmd overlap, ");
926 } 918 }
927 if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); 919 if (val[CAPAB_0] & LBA_SUP) printf("LBA, ");
928 920
929 if (like_std != 1) { 921 if (like_std != 1) {
930 printf("IORDY%s(can%s be disabled)\n", 922 printf("IORDY%s(can%s be disabled)\n",
931 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", 923 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
932 (val[CAPAB_0] & IORDY_OFF) ? "" :"not"); 924 (val[CAPAB_0] & IORDY_OFF) ? "" :"not");
933 } else 925 } else
934 printf("no IORDY\n"); 926 printf("no IORDY\n");
935 927
936 if ((like_std == 1) && val[BUF_TYPE]) { 928 if ((like_std == 1) && val[BUF_TYPE]) {
937 printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], 929 printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE],
938 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", 930 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
939 (val[BUF_TYPE] > 2) ? " with read caching ability" : ""); 931 (val[BUF_TYPE] > 2) ? " with read caching ability" : "");
940 } 932 }
941 933
942 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) { 934 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) {
@@ -953,9 +945,11 @@ static void identify(uint16_t *val)
953 if (like_std == 1) 945 if (like_std == 1)
954 printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : ""); 946 printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : "");
955 else { 947 else {
956 printf("\tStandby timer values: spec'd by %s", (val[CAPAB_0] & STD_STBY) ? "Standard" : "Vendor"); 948 printf("\tStandby timer values: spec'd by %s",
949 (val[CAPAB_0] & STD_STBY) ? "standard" : "vendor");
957 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) 950 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"); 951 printf(", %s device specific minimum\n",
952 (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no");
959 else 953 else
960 bb_putchar('\n'); 954 bb_putchar('\n');
961 } 955 }
@@ -983,7 +977,8 @@ static void identify(uint16_t *val)
983 } 977 }
984 if (like_std > 5 && val[ACOUSTIC]) { 978 if (like_std > 5 && val[ACOUSTIC]) {
985 printf("\tRecommended acoustic management value: %u, current value: %u\n", 979 printf("\tRecommended acoustic management value: %u, current value: %u\n",
986 (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); 980 (val[ACOUSTIC] >> 8) & 0x00ff,
981 val[ACOUSTIC] & 0x00ff);
987 } 982 }
988 } else { 983 } else {
989 /* ATAPI */ 984 /* ATAPI */
@@ -992,8 +987,11 @@ static void identify(uint16_t *val)
992 987
993 if (val[PKT_REL] || val[SVC_NBSY]) { 988 if (val[PKT_REL] || val[SVC_NBSY]) {
994 printf("\tOverlap support:"); 989 printf("\tOverlap support:");
995 if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]); 990 if (val[PKT_REL])
996 if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]); 991 printf(" %uus to release bus.", val[PKT_REL]);
992 if (val[SVC_NBSY])
993 printf(" %uus to clear BSY after SERVICE cmd.",
994 val[SVC_NBSY]);
997 bb_putchar('\n'); 995 bb_putchar('\n');
998 } 996 }
999 } 997 }
@@ -1057,14 +1055,17 @@ static void identify(uint16_t *val)
1057 if (val[WHATS_VALID] & OK_W64_70) { 1055 if (val[WHATS_VALID] & OK_W64_70) {
1058 if (val[PIO_NO_FLOW] || val[PIO_FLOW]) { 1056 if (val[PIO_NO_FLOW] || val[PIO_FLOW]) {
1059 printf("\t\tCycle time:"); 1057 printf("\t\tCycle time:");
1060 if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); 1058 if (val[PIO_NO_FLOW])
1061 if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); 1059 printf(" no flow control=%uns", val[PIO_NO_FLOW]);
1060 if (val[PIO_FLOW])
1061 printf(" IORDY flow control=%uns", val[PIO_FLOW]);
1062 bb_putchar('\n'); 1062 bb_putchar('\n');
1063 } 1063 }
1064 } 1064 }
1065 1065
1066 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) { 1066 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) {
1067 printf("Commands/features:\n\tEnabled\tSupported:\n"); 1067 printf("Commands/features:\n"
1068 "\tEnabled\tSupported:\n");
1068 jj = val[CMDS_SUPP_0]; 1069 jj = val[CMDS_SUPP_0];
1069 kk = val[CMDS_EN_0]; 1070 kk = val[CMDS_EN_0];
1070 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) { 1071 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) {
@@ -1098,11 +1099,14 @@ static void identify(uint16_t *val)
1098 jj = val[SECU_STATUS]; 1099 jj = val[SECU_STATUS];
1099 if (jj) { 1100 if (jj) {
1100 for (ii = 0; ii < NUM_SECU_STR; ii++) { 1101 for (ii = 0; ii < NUM_SECU_STR; ii++) {
1101 printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "", nth_string(secu_str, ii)); 1102 printf("\t%s\t%s\n",
1103 (!(jj & 0x0001)) ? "not" : "",
1104 nth_string(secu_str, ii));
1102 jj >>=1; 1105 jj >>=1;
1103 } 1106 }
1104 if (val[SECU_STATUS] & SECU_ENABLED) { 1107 if (val[SECU_STATUS] & SECU_ENABLED) {
1105 printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); 1108 printf("\tSecurity level %s\n",
1109 (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high");
1106 } 1110 }
1107 } 1111 }
1108 jj = val[ERASE_TIME] & ERASE_BITS; 1112 jj = val[ERASE_TIME] & ERASE_BITS;
@@ -1127,16 +1131,20 @@ static void identify(uint16_t *val)
1127 strng = " determined by CSEL"; 1131 strng = " determined by CSEL";
1128 else 1132 else
1129 strng = ""; 1133 strng = "";
1130 printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n", 1134 printf("HW reset results:\n"
1131 (val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng); 1135 "\tCBLID- %s Vih\n"
1136 "\tDevice num = %i%s\n",
1137 (val[HWRST_RSLT] & CBLID) ? "above" : "below",
1138 !(oo), strng);
1132 } 1139 }
1133 1140
1134 /* more stuff from std 5 */ 1141 /* more stuff from std 5 */
1135 if ((like_std > 4) && (eqpt != CDROM)) { 1142 if ((like_std > 4) && (eqpt != CDROM)) {
1136 if (val[CFA_PWR_MODE] & VALID_W160) { 1143 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", 1144 printf("CFA power mode 1:\n"
1138 (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : ""); 1145 "\t%s%s\n",
1139 1146 (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled",
1147 (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : "");
1140 if (val[CFA_PWR_MODE] & MAX_AMPS) 1148 if (val[CFA_PWR_MODE] & MAX_AMPS)
1141 printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS); 1149 printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS);
1142 } 1150 }
@@ -1184,11 +1192,12 @@ static void dump_identity(const struct hd_driveid *id)
1184 printf(" %s", nth_string(cfg_str, i)); 1192 printf(" %s", nth_string(cfg_str, i));
1185 } 1193 }
1186 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" 1194 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n"
1187 " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", 1195 " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u",
1188 id->cyls, id->heads, id->sectors, id->track_bytes, 1196 id->cyls, id->heads, id->sectors, id->track_bytes,
1189 id->sector_bytes, id->ecc_bytes, 1197 id->sector_bytes, id->ecc_bytes,
1190 id->buf_type, nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type), 1198 id->buf_type,
1191 id->buf_size/2, id->max_multsect); 1199 nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type),
1200 id->buf_size/2, id->max_multsect);
1192 if (id->max_multsect) { 1201 if (id->max_multsect) {
1193 printf(", MultSect="); 1202 printf(", MultSect=");
1194 if (!(id->multsect_valid & 1)) 1203 if (!(id->multsect_valid & 1))
@@ -1213,7 +1222,10 @@ static void dump_identity(const struct hd_driveid *id)
1213 if (id->capability & 2) 1222 if (id->capability & 2)
1214 printf(", LBAsects=%u", id->lba_capacity); 1223 printf(", LBAsects=%u", id->lba_capacity);
1215 1224
1216 printf("\n IORDY=%s", (id->capability & 8) ? (id->capability & 4) ? "on/off" : "yes" : "no"); 1225 printf("\n IORDY=%s",
1226 (id->capability & 8)
1227 ? ((id->capability & 4) ? "on/off" : "yes")
1228 : "no");
1217 1229
1218 if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2)) 1230 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); 1231 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
@@ -1242,7 +1254,7 @@ static void dump_identity(const struct hd_driveid *id)
1242 "*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0", 1254 "*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0",
1243 id->dma_1word, NULL); 1255 id->dma_1word, NULL);
1244 print_flags_separated(dma_wmode_masks, 1256 print_flags_separated(dma_wmode_masks,
1245 "*\0""mdma0\0""*\0""mdma1\0""*\0""mdma2\0""*\0""mdma?\0", 1257 "*\0""mdma0 \0""*\0""mdma1 \0""*\0""mdma2 \0""*\0""mdma? \0",
1246 id->dma_mword, NULL); 1258 id->dma_mword, NULL);
1247 } 1259 }
1248 } 1260 }
@@ -1285,12 +1297,14 @@ static void dump_identity(const struct hd_driveid *id)
1285 if ((id->minor_rev_num && id->minor_rev_num <= 31) 1297 if ((id->minor_rev_num && id->minor_rev_num <= 31)
1286 || (id->major_rev_num && id->minor_rev_num <= 31) 1298 || (id->major_rev_num && id->minor_rev_num <= 31)
1287 ) { 1299 ) {
1288 printf("\n Drive conforms to: %s: ", (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown"); 1300 printf("\n Drive conforms to: %s: ",
1289 if (id->major_rev_num != 0x0000 && /* NOVAL_0 */ 1301 (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown");
1290 id->major_rev_num != 0xFFFF) { /* NOVAL_1 */ 1302 if (id->major_rev_num != 0x0000 /* NOVAL_0 */
1303 && id->major_rev_num != 0xFFFF /* NOVAL_1 */
1304 ) {
1291 for (i = 0; i <= 15; i++) { 1305 for (i = 0; i <= 15; i++) {
1292 if (id->major_rev_num & (1<<i)) 1306 if (id->major_rev_num & (1<<i))
1293 printf(" ATA/ATAPI-%u", i); 1307 printf(" ATA/ATAPI-%u", i);
1294 } 1308 }
1295 } 1309 }
1296 } 1310 }
@@ -1450,10 +1464,10 @@ static void interpret_standby(uint8_t standby)
1450 printf("off"); 1464 printf("off");
1451 } else if (standby <= 240 || standby == 252 || standby == 255) { 1465 } else if (standby <= 240 || standby == 252 || standby == 255) {
1452 /* standby is in 5 sec units */ 1466 /* standby is in 5 sec units */
1453 printf("%u minutes %u seconds", standby / 12, (standby*5) % 60); 1467 printf("%u minutes %u seconds", standby / (60/5), standby % (60/5));
1454 } else if (standby <= 251) { 1468 } else if (standby <= 251) {
1455 unsigned t = (standby - 240); /* t is in 30 min units */; 1469 unsigned t = (standby - 240); /* t is in 30 min units */;
1456 printf("%u.%c hours", t / 2, (t & 1) ? '0' : '5'); 1470 printf("%u.%c hours", t / 2, (t & 1) ? '5' : '0');
1457 } 1471 }
1458 if (standby == 253) 1472 if (standby == 253)
1459 printf("vendor-specific"); 1473 printf("vendor-specific");
@@ -1536,8 +1550,8 @@ static void process_dev(char *devname)
1536 xmove_fd(xopen(devname, O_RDONLY | O_NONBLOCK), fd); 1550 xmove_fd(xopen(devname, O_RDONLY | O_NONBLOCK), fd);
1537 printf("\n%s:\n", devname); 1551 printf("\n%s:\n", devname);
1538 1552
1539 if (set_readahead) { 1553 if (getset_readahead == IS_SET) {
1540 print_flag(get_readahead, "fs readahead", Xreadahead); 1554 print_flag(getset_readahead, "fs readahead", Xreadahead);
1541 ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead); 1555 ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead);
1542 } 1556 }
1543#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF 1557#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
@@ -1547,7 +1561,7 @@ static void process_dev(char *devname)
1547 } 1561 }
1548#endif 1562#endif
1549#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF 1563#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
1550 if (scan_hwif) { 1564 if (scan_hwif == IS_SET) {
1551 printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq); 1565 printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq);
1552 args[0] = hwif_data; 1566 args[0] = hwif_data;
1553 args[1] = hwif_ctrl; 1567 args[1] = hwif_ctrl;
@@ -1571,103 +1585,103 @@ static void process_dev(char *devname)
1571 } 1585 }
1572 ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode); 1586 ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode);
1573 } 1587 }
1574 if (set_io32bit) { 1588 if (getset_io32bit == IS_SET) {
1575 print_flag(get_io32bit, "32-bit IO_support flag", io32bit); 1589 print_flag(getset_io32bit, "32-bit IO_support flag", io32bit);
1576 ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit); 1590 ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit);
1577 } 1591 }
1578 if (set_mult) { 1592 if (getset_mult == IS_SET) {
1579 print_flag(get_mult, "multcount", mult); 1593 print_flag(getset_mult, "multcount", mult);
1580#ifdef HDIO_DRIVE_CMD 1594#ifdef HDIO_DRIVE_CMD
1581 ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult); 1595 ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult);
1582#else 1596#else
1583 force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult)); 1597 force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult));
1584#endif 1598#endif
1585 } 1599 }
1586 if (set_readonly) { 1600 if (getset_readonly == IS_SET) {
1587 print_flag_on_off(get_readonly, "readonly", readonly); 1601 print_flag_on_off(getset_readonly, "readonly", readonly);
1588 ioctl_or_warn(fd, BLKROSET, &readonly); 1602 ioctl_or_warn(fd, BLKROSET, &readonly);
1589 } 1603 }
1590 if (set_unmask) { 1604 if (getset_unmask == IS_SET) {
1591 print_flag_on_off(get_unmask, "unmaskirq", unmask); 1605 print_flag_on_off(getset_unmask, "unmaskirq", unmask);
1592 ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask); 1606 ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask);
1593 } 1607 }
1594#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA 1608#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
1595 if (set_dma) { 1609 if (getset_dma == IS_SET) {
1596 print_flag_on_off(get_dma, "using_dma", dma); 1610 print_flag_on_off(getset_dma, "using_dma", dma);
1597 ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma); 1611 ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma);
1598 } 1612 }
1599#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */ 1613#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */
1600#ifdef HDIO_SET_QDMA 1614#ifdef HDIO_SET_QDMA
1601 if (set_dma_q) { 1615 if (getset_dma_q == IS_SET) {
1602 print_flag_on_off(get_dma_q, "DMA queue_depth", dma_q); 1616 print_flag_on_off(getset_dma_q, "DMA queue_depth", dma_q);
1603 ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q); 1617 ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q);
1604 } 1618 }
1605#endif 1619#endif
1606 if (set_nowerr) { 1620 if (getset_nowerr == IS_SET) {
1607 print_flag_on_off(get_nowerr, "nowerr", nowerr); 1621 print_flag_on_off(getset_nowerr, "nowerr", nowerr);
1608 ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr); 1622 ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr);
1609 } 1623 }
1610 if (set_keep) { 1624 if (getset_keep == IS_SET) {
1611 print_flag_on_off(get_keep, "keep_settings", keep); 1625 print_flag_on_off(getset_keep, "keep_settings", keep);
1612 ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep); 1626 ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep);
1613 } 1627 }
1614#ifdef HDIO_DRIVE_CMD 1628#ifdef HDIO_DRIVE_CMD
1615 if (set_doorlock) { 1629 if (getset_doorlock == IS_SET) {
1616 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; 1630 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
1617 args[2] = 0; 1631 args[2] = 0;
1618 print_flag_on_off(get_doorlock, "drive doorlock", doorlock); 1632 print_flag_on_off(getset_doorlock, "drive doorlock", doorlock);
1619 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1633 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1620 args[0] = WIN_SETFEATURES; 1634 args[0] = WIN_SETFEATURES;
1621 } 1635 }
1622 if (set_dkeep) { 1636 if (getset_dkeep == IS_SET) {
1623 /* lock/unlock the drive's "feature" settings */ 1637 /* lock/unlock the drive's "feature" settings */
1624 print_flag_on_off(get_dkeep, "drive keep features", dkeep); 1638 print_flag_on_off(getset_dkeep, "drive keep features", dkeep);
1625 args[2] = dkeep ? 0x66 : 0xcc; 1639 args[2] = dkeep ? 0x66 : 0xcc;
1626 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1640 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1627 } 1641 }
1628 if (set_defects) { 1642 if (getset_defects == IS_SET) {
1629 args[2] = defects ? 0x04 : 0x84; 1643 args[2] = defects ? 0x04 : 0x84;
1630 print_flag(get_defects, "drive defect-mgmt", defects); 1644 print_flag(getset_defects, "drive defect-mgmt", defects);
1631 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1645 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1632 } 1646 }
1633 if (set_prefetch) { 1647 if (getset_prefetch == IS_SET) {
1634 args[1] = prefetch; 1648 args[1] = prefetch;
1635 args[2] = 0xab; 1649 args[2] = 0xab;
1636 print_flag(get_prefetch, "drive prefetch", prefetch); 1650 print_flag(getset_prefetch, "drive prefetch", prefetch);
1637 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1651 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1638 args[1] = 0; 1652 args[1] = 0;
1639 } 1653 }
1640 if (set_xfermode) { 1654 if (set_xfermode) {
1641 args[1] = xfermode_requested; 1655 args[1] = xfermode_requested;
1642 args[2] = 3; 1656 args[2] = 3;
1643 if (get_xfermode) { 1657 print_flag(1, "xfermode", xfermode_requested);
1644 print_flag(1, "xfermode", xfermode_requested); 1658 interpret_xfermode(xfermode_requested);
1645 interpret_xfermode(xfermode_requested);
1646 }
1647 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1659 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1648 args[1] = 0; 1660 args[1] = 0;
1649 } 1661 }
1650 if (set_lookahead) { 1662 if (getset_lookahead == IS_SET) {
1651 args[2] = lookahead ? 0xaa : 0x55; 1663 args[2] = lookahead ? 0xaa : 0x55;
1652 print_flag_on_off(get_lookahead, "drive read-lookahead", lookahead); 1664 print_flag_on_off(getset_lookahead, "drive read-lookahead", lookahead);
1653 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1665 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1654 } 1666 }
1655 if (set_apmmode) { 1667 if (getset_apmmode == IS_SET) {
1656 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */ 1668 /* feature register */
1669 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */;
1657 args[1] = apmmode; /* sector count register 1-255 */ 1670 args[1] = apmmode; /* sector count register 1-255 */
1658 if (get_apmmode) 1671 printf(" setting APM level to %s 0x%02lX (%ld)\n",
1659 printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode); 1672 (apmmode == 255) ? "disabled" : "",
1673 apmmode, apmmode);
1660 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1674 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1661 args[1] = 0; 1675 args[1] = 0;
1662 } 1676 }
1663 if (set_wcache) { 1677 if (getset_wcache == IS_SET) {
1664#ifdef DO_FLUSHCACHE 1678#ifdef DO_FLUSHCACHE
1665#ifndef WIN_FLUSHCACHE 1679#ifndef WIN_FLUSHCACHE
1666#define WIN_FLUSHCACHE 0xe7 1680#define WIN_FLUSHCACHE 0xe7
1667#endif 1681#endif
1668#endif /* DO_FLUSHCACHE */ 1682#endif /* DO_FLUSHCACHE */
1669 args[2] = wcache ? 0x02 : 0x82; 1683 args[2] = wcache ? 0x02 : 0x82;
1670 print_flag_on_off(get_wcache, "drive write-caching", wcache); 1684 print_flag_on_off(getset_wcache, "drive write-caching", wcache);
1671#ifdef DO_FLUSHCACHE 1685#ifdef DO_FLUSHCACHE
1672 if (!wcache) 1686 if (!wcache)
1673 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache); 1687 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
@@ -1690,7 +1704,7 @@ static void process_dev(char *devname)
1690#ifndef WIN_STANDBYNOW2 1704#ifndef WIN_STANDBYNOW2
1691#define WIN_STANDBYNOW2 0x94 1705#define WIN_STANDBYNOW2 0x94
1692#endif 1706#endif
1693 if (get_standbynow) printf(" issuing standby command\n"); 1707 printf(" issuing standby command\n");
1694 args[0] = WIN_STANDBYNOW1; 1708 args[0] = WIN_STANDBYNOW1;
1695 ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2); 1709 ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2);
1696 } 1710 }
@@ -1701,22 +1715,20 @@ static void process_dev(char *devname)
1701#ifndef WIN_SLEEPNOW2 1715#ifndef WIN_SLEEPNOW2
1702#define WIN_SLEEPNOW2 0x99 1716#define WIN_SLEEPNOW2 0x99
1703#endif 1717#endif
1704 if (get_sleepnow) printf(" issuing sleep command\n"); 1718 printf(" issuing sleep command\n");
1705 args[0] = WIN_SLEEPNOW1; 1719 args[0] = WIN_SLEEPNOW1;
1706 ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2); 1720 ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2);
1707 } 1721 }
1708 if (set_seagate) { 1722 if (set_seagate) {
1709 args[0] = 0xfb; 1723 args[0] = 0xfb;
1710 if (get_seagate) printf(" disabling Seagate auto powersaving mode\n"); 1724 printf(" disabling Seagate auto powersaving mode\n");
1711 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1725 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1712 } 1726 }
1713 if (set_standby) { 1727 if (getset_standby == IS_SET) {
1714 args[0] = WIN_SETIDLE1; 1728 args[0] = WIN_SETIDLE1;
1715 args[1] = standby_requested; 1729 args[1] = standby_requested;
1716 if (get_standby) { 1730 print_flag(1, "standby", standby_requested);
1717 print_flag(1, "standby", standby_requested); 1731 interpret_standby(standby_requested);
1718 interpret_standby(standby_requested);
1719 }
1720 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); 1732 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1721 args[1] = 0; 1733 args[1] = 0;
1722 } 1734 }
@@ -1725,23 +1737,23 @@ static void process_dev(char *devname)
1725 char buf[512]; 1737 char buf[512];
1726 flush_buffer_cache(); 1738 flush_buffer_cache();
1727 if (-1 == read(fd, buf, sizeof(buf))) 1739 if (-1 == read(fd, buf, sizeof(buf)))
1728 bb_perror_msg("read(%d bytes) failed (rc=-1)", sizeof(buf)); 1740 bb_perror_msg("read of 512 bytes failed");
1729 } 1741 }
1730#endif /* HDIO_DRIVE_CMD */ 1742#endif /* HDIO_DRIVE_CMD */
1731 1743 if (getset_mult || get_identity) {
1732 if (get_mult || get_identity) {
1733 multcount = -1; 1744 multcount = -1;
1734 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { 1745 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) {
1735 if (get_mult && ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn. */ 1746 /* To be coherent with ioctl_or_warn. */
1747 if (getset_mult && ENABLE_IOCTL_HEX2STR_ERROR)
1736 bb_perror_msg("HDIO_GET_MULTCOUNT"); 1748 bb_perror_msg("HDIO_GET_MULTCOUNT");
1737 else 1749 else
1738 bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT); 1750 bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT);
1739 } else if (get_mult) { 1751 } else if (getset_mult) {
1740 printf(fmt, "multcount", multcount); 1752 printf(fmt, "multcount", multcount);
1741 on_off(multcount != 0); 1753 on_off(multcount != 0);
1742 } 1754 }
1743 } 1755 }
1744 if (get_io32bit) { 1756 if (getset_io32bit) {
1745 if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) { 1757 if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) {
1746 printf(" IO_support\t=%3ld (", parm); 1758 printf(" IO_support\t=%3ld (", parm);
1747 if (parm == 0) 1759 if (parm == 0)
@@ -1758,14 +1770,12 @@ static void process_dev(char *devname)
1758 printf("\?\?\?)\n"); 1770 printf("\?\?\?)\n");
1759 } 1771 }
1760 } 1772 }
1761 if (get_unmask) { 1773 if (getset_unmask) {
1762 if (!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm)) 1774 if (!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm))
1763 print_value_on_off("unmaskirq", parm); 1775 print_value_on_off("unmaskirq", parm);
1764 } 1776 }
1765
1766
1767#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA 1777#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
1768 if (get_dma) { 1778 if (getset_dma) {
1769 if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) { 1779 if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) {
1770 printf(fmt, "using_dma", parm); 1780 printf(fmt, "using_dma", parm);
1771 if (parm == 8) 1781 if (parm == 8)
@@ -1776,25 +1786,24 @@ static void process_dev(char *devname)
1776 } 1786 }
1777#endif 1787#endif
1778#ifdef HDIO_GET_QDMA 1788#ifdef HDIO_GET_QDMA
1779 if (get_dma_q) { 1789 if (getset_dma_q) {
1780 if (!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm)) 1790 if (!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm))
1781 print_value_on_off("queue_depth", parm); 1791 print_value_on_off("queue_depth", parm);
1782 } 1792 }
1783#endif 1793#endif
1784 if (get_keep) { 1794 if (getset_keep) {
1785 if (!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm)) 1795 if (!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm))
1786 print_value_on_off("keepsettings", parm); 1796 print_value_on_off("keepsettings", parm);
1787 } 1797 }
1788 1798 if (getset_nowerr) {
1789 if (get_nowerr) {
1790 if (!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm)) 1799 if (!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm))
1791 print_value_on_off("nowerr", parm); 1800 print_value_on_off("nowerr", parm);
1792 } 1801 }
1793 if (get_readonly) { 1802 if (getset_readonly) {
1794 if (!ioctl_or_warn(fd, BLKROGET, &parm)) 1803 if (!ioctl_or_warn(fd, BLKROGET, &parm))
1795 print_value_on_off("readonly", parm); 1804 print_value_on_off("readonly", parm);
1796 } 1805 }
1797 if (get_readahead) { 1806 if (getset_readahead) {
1798 if (!ioctl_or_warn(fd, BLKRAGET, &parm)) 1807 if (!ioctl_or_warn(fd, BLKRAGET, &parm))
1799 print_value_on_off("readahead", parm); 1808 print_value_on_off("readahead", parm);
1800 } 1809 }
@@ -1804,7 +1813,7 @@ static void process_dev(char *devname)
1804 1813
1805 if (!ioctl_or_warn(fd, HDIO_GETGEO, &g)) 1814 if (!ioctl_or_warn(fd, HDIO_GETGEO, &g))
1806 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", 1815 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n",
1807 g.cylinders, g.heads, g.sectors, parm, g.start); 1816 g.cylinders, g.heads, g.sectors, parm, g.start);
1808 } 1817 }
1809 } 1818 }
1810#ifdef HDIO_DRIVE_CMD 1819#ifdef HDIO_DRIVE_CMD
@@ -1872,14 +1881,12 @@ static void process_dev(char *devname)
1872 } 1881 }
1873#endif 1882#endif
1874#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF 1883#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
1875 if (set_busstate) { 1884 if (getset_busstate == IS_SET) {
1876 if (get_busstate) { 1885 print_flag(1, "bus state", busstate);
1877 print_flag(1, "bus state", busstate); 1886 bus_state_value(busstate);
1878 bus_state_value(busstate);
1879 }
1880 ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate); 1887 ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate);
1881 } 1888 }
1882 if (get_busstate) { 1889 if (getset_busstate) {
1883 if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) { 1890 if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) {
1884 printf(fmt, "bus state", parm); 1891 printf(fmt, "bus state", parm);
1885 bus_state_value(parm); 1892 bus_state_value(parm);
@@ -1935,21 +1942,31 @@ void identify_from_stdin(void);
1935#endif 1942#endif
1936 1943
1937/* busybox specific stuff */ 1944/* busybox specific stuff */
1938static void parse_opts(smallint *get, smallint *set, unsigned long *value, int min, int max) 1945static int parse_opts(unsigned long *value, int min, int max)
1939{ 1946{
1940 if (get) {
1941 *get = 1;
1942 }
1943 if (optarg) { 1947 if (optarg) {
1944 *set = 1;
1945 *value = xatol_range(optarg, min, max); 1948 *value = xatol_range(optarg, min, max);
1949 return IS_SET;
1946 } 1950 }
1951 return IS_GET;
1952}
1953static int parse_opts_0_max(unsigned long *value, int max)
1954{
1955 return parse_opts(value, 0, max);
1956}
1957static int parse_opts_0_1(unsigned long *value)
1958{
1959 return parse_opts(value, 0, 1);
1960}
1961static int parse_opts_0_INTMAX(unsigned long *value)
1962{
1963 return parse_opts(value, 0, INT_MAX);
1947} 1964}
1948 1965
1949static void parse_xfermode(int flag, smallint *get, smallint *set, int *value) 1966static void parse_xfermode(int flag, smallint *get, smallint *set, int *value)
1950{ 1967{
1951 if (flag) { 1968 if (flag) {
1952 *get = 1; 1969 *get = IS_GET;
1953 if (optarg) { 1970 if (optarg) {
1954 *value = translate_xfermode(optarg); 1971 *value = translate_xfermode(optarg);
1955 *set = (*value > -1); 1972 *set = (*value > -1);
@@ -1991,49 +2008,47 @@ int hdparm_main(int argc, char **argv)
1991 IF_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); 2008 IF_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i'));
1992 get_geom |= (c == 'g'); 2009 get_geom |= (c == 'g');
1993 do_flush |= (c == 'f'); 2010 do_flush |= (c == 'f');
1994 if (c == 'u') parse_opts(&get_unmask, &set_unmask, &unmask, 0, 1); 2011 if (c == 'u') getset_unmask = parse_opts_0_1(&unmask);
1995 IF_FEATURE_HDPARM_HDIO_GETSET_DMA(if (c == 'd') parse_opts(&get_dma, &set_dma, &dma, 0, 9)); 2012 IF_FEATURE_HDPARM_HDIO_GETSET_DMA(
1996 if (c == 'n') parse_opts(&get_nowerr, &set_nowerr, &nowerr, 0, 1); 2013 if (c == 'd') getset_dma = parse_opts_0_max(&dma, 9);
2014 )
2015 if (c == 'n') getset_nowerr = parse_opts_0_1(&nowerr);
1997 parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode); 2016 parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode);
1998 if (c == 'r') parse_opts(&get_readonly, &set_readonly, &readonly, 0, 1); 2017 if (c == 'r') getset_readonly = parse_opts_0_1(&readonly);
1999 if (c == 'm') parse_opts(&get_mult, &set_mult, &mult, 0, INT_MAX /*32*/); 2018 if (c == 'm') getset_mult = parse_opts_0_INTMAX(&mult /*32*/);
2000 if (c == 'c') parse_opts(&get_io32bit, &set_io32bit, &io32bit, 0, INT_MAX /*8*/); 2019 if (c == 'c') getset_io32bit = parse_opts_0_INTMAX(&io32bit /*8*/);
2001 if (c == 'k') parse_opts(&get_keep, &set_keep, &keep, 0, 1); 2020 if (c == 'k') getset_keep = parse_opts_0_1(&keep);
2002 if (c == 'a') parse_opts(&get_readahead, &set_readahead, &Xreadahead, 0, INT_MAX); 2021 if (c == 'a') getset_readahead = parse_opts_0_INTMAX(&Xreadahead);
2003 if (c == 'B') parse_opts(&get_apmmode, &set_apmmode, &apmmode, 1, 255); 2022 if (c == 'B') getset_apmmode = parse_opts(&apmmode, 1, 255);
2004 do_flush |= do_timings |= (c == 't'); 2023 do_flush |= do_timings |= (c == 't');
2005 do_flush |= do_ctimings |= (c == 'T'); 2024 do_flush |= do_ctimings |= (c == 'T');
2006#ifdef HDIO_DRIVE_CMD 2025#ifdef HDIO_DRIVE_CMD
2007 if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, 255); 2026 if (c == 'S') getset_standby = parse_opts_0_max(&standby_requested, 255);
2008 if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX); 2027 if (c == 'D') getset_defects = parse_opts_0_INTMAX(&defects);
2009 if (c == 'P') parse_opts(&get_prefetch, &set_prefetch, &prefetch, 0, INT_MAX); 2028 if (c == 'P') getset_prefetch = parse_opts_0_INTMAX(&prefetch);
2010 parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested); 2029 parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested);
2011 if (c == 'K') parse_opts(&get_dkeep, &set_dkeep, &prefetch, 0, 1); 2030 if (c == 'K') getset_dkeep = parse_opts_0_1(&prefetch);
2012 if (c == 'A') parse_opts(&get_lookahead, &set_lookahead, &lookahead, 0, 1); 2031 if (c == 'A') getset_lookahead = parse_opts_0_1(&lookahead);
2013 if (c == 'L') parse_opts(&get_doorlock, &set_doorlock, &doorlock, 0, 1); 2032 if (c == 'L') getset_doorlock = parse_opts_0_1(&doorlock);
2014 if (c == 'W') parse_opts(&get_wcache, &set_wcache, &wcache, 0, 1); 2033 if (c == 'W') getset_wcache = parse_opts_0_1(&wcache);
2015 get_powermode |= (c == 'C'); 2034 get_powermode |= (c == 'C');
2016 get_standbynow = set_standbynow |= (c == 'y'); 2035 set_standbynow |= (c == 'y');
2017 get_sleepnow = set_sleepnow |= (c == 'Y'); 2036 set_sleepnow |= (c == 'Y');
2018 reread_partn |= (c == 'z'); 2037 reread_partn |= (c == 'z');
2019 get_seagate = set_seagate |= (c == 'Z'); 2038 set_seagate |= (c == 'Z');
2020#endif 2039#endif
2021 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX)); 2040 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') unregister_hwif = parse_opts_0_INTMAX(&hwif));
2022#ifdef HDIO_GET_QDMA 2041#ifdef HDIO_GET_QDMA
2023 if (c == 'Q') { 2042 if (c == 'Q') {
2024#ifdef HDIO_SET_QDMA 2043 getset_dma_q = parse_opts_0_INTMAX(&dma_q);
2025 parse_opts(&get_dma_q, &set_dma_q, &dma_q, 0, INT_MAX);
2026#else
2027 parse_opts(&get_dma_q, NULL, NULL, 0, 0);
2028#endif
2029 } 2044 }
2030#endif 2045#endif
2031 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r')); 2046 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r'));
2032 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1)); 2047 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') perform_tristate = parse_opts_0_1(&tristate));
2033 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2)); 2048 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') getset_busstate = parse_opts_0_max(&busstate, 2));
2034#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF 2049#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
2035 if (c == 'R') { 2050 if (c == 'R') {
2036 parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX); 2051 scan_hwif = parse_opts_0_INTMAX(&hwif_data);
2037 hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : ""); 2052 hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : "");
2038 hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : ""); 2053 hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : "");
2039 /* Move past the 2 additional arguments */ 2054 /* Move past the 2 additional arguments */
@@ -2044,8 +2059,8 @@ int hdparm_main(int argc, char **argv)
2044 } 2059 }
2045 /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */ 2060 /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */
2046 if (!flagcount) { 2061 if (!flagcount) {
2047 get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1; 2062 getset_mult = getset_io32bit = getset_unmask = getset_keep = getset_readonly = getset_readahead = get_geom = IS_GET;
2048 IF_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1); 2063 IF_FEATURE_HDPARM_HDIO_GETSET_DMA(getset_dma = IS_GET);
2049 } 2064 }
2050 argv += optind; 2065 argv += optind;
2051 2066