aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-28 10:25:32 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-28 10:25:32 +0000
commit0d3c6afc93c8a6216fee9d60ecaa6a9d52687a65 (patch)
tree02f4672aa95cc616ddd3265092a1eb5ad554d438
parent86076775298353137c49e8c001528fab02a0fbd2 (diff)
downloadbusybox-w32-0d3c6afc93c8a6216fee9d60ecaa6a9d52687a65.tar.gz
busybox-w32-0d3c6afc93c8a6216fee9d60ecaa6a9d52687a65.tar.bz2
busybox-w32-0d3c6afc93c8a6216fee9d60ecaa6a9d52687a65.zip
hdparm: get rid of static variables
process_dev 5309 5311 +2 unregister_hwif 1 - -1 ........... Xreadahead 4 - -4 seek_to_zero 25 17 -8 hdparm_main 1242 1227 -15 do_time 547 480 -67 ------------------------------------------------------------------------------ (add/remove: 0/83 grow/shrink: 1/3 up/down: 2/-248) Total: -246 bytes
-rw-r--r--miscutils/hdparm.c276
1 files changed, 179 insertions, 97 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 39e4990f5..a3a5a7336 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -379,11 +379,6 @@ static const char *const cmd_feat_str[] = {
379 "SMART self-test ", /* word 84 bit 1 */ 379 "SMART self-test ", /* word 84 bit 1 */
380 "SMART error logging " /* word 84 bit 0 */ 380 "SMART error logging " /* word 84 bit 0 */
381}; 381};
382
383static void identify(uint16_t *id_supplied) ATTRIBUTE_NORETURN;
384static void identify_from_stdin(void) ATTRIBUTE_NORETURN;
385#else
386void identify_from_stdin(void);
387#endif 382#endif
388 383
389 384
@@ -444,6 +439,162 @@ static const char *const secu_str[] = {
444 439
445enum { fd = 3 }; 440enum { fd = 3 };
446 441
442
443struct globals {
444 smallint get_identity, get_geom;
445 smallint do_flush;
446 smallint do_ctimings, do_timings;
447 smallint reread_partn;
448 smallint set_piomode, noisy_piomode;
449 smallint set_readahead, get_readahead;
450 smallint set_readonly, get_readonly;
451 smallint set_unmask, get_unmask;
452 smallint set_mult, get_mult;
453 smallint set_dma_q, get_dma_q;
454 smallint set_nowerr, get_nowerr;
455 smallint set_keep, get_keep;
456 smallint set_io32bit, get_io32bit;
457 int piomode;
458 unsigned long Xreadahead;
459 unsigned long readonly;
460 unsigned long unmask;
461 unsigned long mult;
462 unsigned long dma_q;
463 unsigned long nowerr;
464 unsigned long keep;
465 unsigned long io32bit;
466#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
467 unsigned long dma;
468 smallint set_dma, get_dma;
469#endif
470#ifdef HDIO_DRIVE_CMD
471 smallint set_xfermode, get_xfermode;
472 smallint set_dkeep, get_dkeep;
473 smallint set_standby, get_standby;
474 smallint set_lookahead, get_lookahead;
475 smallint set_prefetch, get_prefetch;
476 smallint set_defects, get_defects;
477 smallint set_wcache, get_wcache;
478 smallint set_doorlock, get_doorlock;
479 smallint set_seagate, get_seagate;
480 smallint set_standbynow, get_standbynow;
481 smallint set_sleepnow, get_sleepnow;
482 smallint get_powermode;
483 smallint set_apmmode, get_apmmode;
484 int xfermode_requested;
485 unsigned long dkeep;
486 unsigned long standby_requested;
487 unsigned long lookahead;
488 unsigned long prefetch;
489 unsigned long defects;
490 unsigned long wcache;
491 unsigned long doorlock;
492 unsigned long apmmode;
493#endif
494 USE_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;)
495 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint set_busstate, get_busstate;)
496 USE_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;)
497 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;)
498 USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;)
499 USE_FEATURE_HDPARM_HDIO_SCAN_HWIF( smallint scan_hwif;)
500 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long busstate;)
501 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long tristate;)
502 USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(unsigned long hwif;)
503#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
504 unsigned long hwif_data;
505 unsigned long hwif_ctrl;
506 unsigned long hwif_irq;
507#endif
508};
509#define G (*(struct globals*)&bb_common_bufsiz1)
510struct BUG_G_too_big {
511 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
512};
513#define get_identity (G.get_identity )
514#define get_geom (G.get_geom )
515#define do_flush (G.do_flush )
516#define do_ctimings (G.do_ctimings )
517#define do_timings (G.do_timings )
518#define reread_partn (G.reread_partn )
519#define set_piomode (G.set_piomode )
520#define noisy_piomode (G.noisy_piomode )
521#define set_readahead (G.set_readahead )
522#define get_readahead (G.get_readahead )
523#define set_readonly (G.set_readonly )
524#define get_readonly (G.get_readonly )
525#define set_unmask (G.set_unmask )
526#define get_unmask (G.get_unmask )
527#define set_mult (G.set_mult )
528#define get_mult (G.get_mult )
529#define set_dma_q (G.set_dma_q )
530#define get_dma_q (G.get_dma_q )
531#define set_nowerr (G.set_nowerr )
532#define get_nowerr (G.get_nowerr )
533#define set_keep (G.set_keep )
534#define get_keep (G.get_keep )
535#define set_io32bit (G.set_io32bit )
536#define get_io32bit (G.get_io32bit )
537#define piomode (G.piomode )
538#define Xreadahead (G.Xreadahead )
539#define readonly (G.readonly )
540#define unmask (G.unmask )
541#define mult (G.mult )
542#define dma_q (G.dma_q )
543#define nowerr (G.nowerr )
544#define keep (G.keep )
545#define io32bit (G.io32bit )
546#define dma (G.dma )
547#define set_dma (G.set_dma )
548#define get_dma (G.get_dma )
549#define set_xfermode (G.set_xfermode )
550#define get_xfermode (G.get_xfermode )
551#define set_dkeep (G.set_dkeep )
552#define get_dkeep (G.get_dkeep )
553#define set_standby (G.set_standby )
554#define get_standby (G.get_standby )
555#define set_lookahead (G.set_lookahead )
556#define get_lookahead (G.get_lookahead )
557#define set_prefetch (G.set_prefetch )
558#define get_prefetch (G.get_prefetch )
559#define set_defects (G.set_defects )
560#define get_defects (G.get_defects )
561#define set_wcache (G.set_wcache )
562#define get_wcache (G.get_wcache )
563#define set_doorlock (G.set_doorlock )
564#define get_doorlock (G.get_doorlock )
565#define set_seagate (G.set_seagate )
566#define get_seagate (G.get_seagate )
567#define set_standbynow (G.set_standbynow )
568#define get_standbynow (G.get_standbynow )
569#define set_sleepnow (G.set_sleepnow )
570#define get_sleepnow (G.get_sleepnow )
571#define get_powermode (G.get_powermode )
572#define set_apmmode (G.set_apmmode )
573#define get_apmmode (G.get_apmmode )
574#define xfermode_requested (G.xfermode_requested )
575#define dkeep (G.dkeep )
576#define standby_requested (G.standby_requested )
577#define lookahead (G.lookahead )
578#define prefetch (G.prefetch )
579#define defects (G.defects )
580#define wcache (G.wcache )
581#define doorlock (G.doorlock )
582#define apmmode (G.apmmode )
583#define get_IDentity (G.get_IDentity )
584#define set_busstate (G.set_busstate )
585#define get_busstate (G.get_busstate )
586#define perform_reset (G.perform_reset )
587#define perform_tristate (G.perform_tristate )
588#define unregister_hwif (G.unregister_hwif )
589#define scan_hwif (G.scan_hwif )
590#define busstate (G.busstate )
591#define tristate (G.tristate )
592#define hwif (G.hwif )
593#define hwif_data (G.hwif_data )
594#define hwif_ctrl (G.hwif_ctrl )
595#define hwif_irq (G.hwif_irq )
596
597
447/* Busybox messages and functions */ 598/* Busybox messages and functions */
448#if ENABLE_IOCTL_HEX2STR_ERROR 599#if ENABLE_IOCTL_HEX2STR_ERROR
449static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt, const char *string) 600static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt, const char *string)
@@ -544,6 +695,7 @@ static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *
544 695
545// Parse 512 byte disk identification block and print much crap. 696// Parse 512 byte disk identification block and print much crap.
546 697
698static void identify(uint16_t *val) ATTRIBUTE_NORETURN;
547static void identify(uint16_t *val) 699static void identify(uint16_t *val)
548{ 700{
549 uint16_t ii, jj, kk; 701 uint16_t ii, jj, kk;
@@ -1012,72 +1164,6 @@ static void identify(uint16_t *val)
1012} 1164}
1013#endif 1165#endif
1014 1166
1015static smallint get_identity, get_geom;
1016static smallint do_flush;
1017static smallint do_ctimings, do_timings;
1018static smallint reread_partn;
1019
1020static smallint set_piomode, noisy_piomode;
1021static smallint set_readahead, get_readahead;
1022static smallint set_readonly, get_readonly;
1023static smallint set_unmask, get_unmask;
1024static smallint set_mult, get_mult;
1025static smallint set_dma_q, get_dma_q;
1026static smallint set_nowerr, get_nowerr;
1027static smallint set_keep, get_keep;
1028static smallint set_io32bit, get_io32bit;
1029static int piomode;
1030static unsigned long Xreadahead;
1031static unsigned long readonly;
1032static unsigned long unmask;
1033static unsigned long mult;
1034static unsigned long dma_q;
1035static unsigned long nowerr;
1036static unsigned long keep;
1037static unsigned long io32bit;
1038#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
1039static unsigned long dma;
1040static smallint set_dma, get_dma;
1041#endif
1042#ifdef HDIO_DRIVE_CMD
1043static smallint set_xfermode, get_xfermode;
1044static smallint set_dkeep, get_dkeep;
1045static smallint set_standby, get_standby;
1046static smallint set_lookahead, get_lookahead;
1047static smallint set_prefetch, get_prefetch;
1048static smallint set_defects, get_defects;
1049static smallint set_wcache, get_wcache;
1050static smallint set_doorlock, get_doorlock;
1051static smallint set_seagate, get_seagate;
1052static smallint set_standbynow, get_standbynow;
1053static smallint set_sleepnow, get_sleepnow;
1054static smallint get_powermode;
1055static smallint set_apmmode, get_apmmode;
1056static int xfermode_requested;
1057static unsigned long dkeep;
1058static unsigned long standby_requested;
1059static unsigned long lookahead;
1060static unsigned long prefetch;
1061static unsigned long defects;
1062static unsigned long wcache;
1063static unsigned long doorlock;
1064static unsigned long apmmode;
1065#endif
1066USE_FEATURE_HDPARM_GET_IDENTITY( static smallint get_IDentity;)
1067USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( static smallint set_busstate, get_busstate;)
1068USE_FEATURE_HDPARM_HDIO_DRIVE_RESET( static smallint perform_reset;)
1069USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( static smallint perform_tristate;)
1070USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(static smallint unregister_hwif;)
1071USE_FEATURE_HDPARM_HDIO_SCAN_HWIF( static smallint scan_hwif;)
1072USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( static unsigned long busstate;)
1073USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( static unsigned long tristate;)
1074USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(static unsigned long hwif;)
1075#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
1076static unsigned long hwif_data;
1077static unsigned long hwif_ctrl;
1078static unsigned long hwif_irq;
1079#endif
1080
1081// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then 1167// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
1082// then the HDIO_GET_IDENTITY only returned 142 bytes. 1168// then the HDIO_GET_IDENTITY only returned 142 bytes.
1083// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes, 1169// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes,
@@ -1251,11 +1337,9 @@ static void flush_buffer_cache(/*int fd*/ void)
1251#endif 1337#endif
1252} 1338}
1253 1339
1254static int seek_to_zero(/*int fd*/ void) 1340static void seek_to_zero(/*int fd*/ void)
1255{ 1341{
1256 if (lseek(fd, (off_t) 0, SEEK_SET)) 1342 xlseek(fd, (off_t) 0, SEEK_SET);
1257 return 1;
1258 return 0;
1259} 1343}
1260 1344
1261static int read_big_block(/*int fd,*/ char *buf) 1345static int read_big_block(/*int fd,*/ char *buf)
@@ -1273,18 +1357,18 @@ static int read_big_block(/*int fd,*/ char *buf)
1273 return 0; 1357 return 0;
1274} 1358}
1275 1359
1276static int do_blkgetsize(/*int fd,*/ unsigned long long *blksize64) 1360static unsigned long long do_blkgetsize(/*int fd*/ void)
1277{ 1361{
1278 int rc; 1362 union {
1279 unsigned blksize32 = 0; 1363 unsigned long long blksize64;
1364 unsigned blksize32;
1365 } u;
1280 1366
1281 if (0 == ioctl(fd, BLKGETSIZE64, blksize64)) { // returns bytes 1367 if (0 == ioctl(fd, BLKGETSIZE64, &u.blksize64)) { // returns bytes
1282 *blksize64 /= 512; 1368 return u.blksize64 / 512;
1283 return 0;
1284 } 1369 }
1285 rc = ioctl_or_warn(fd, BLKGETSIZE, &blksize32); // returns sectors 1370 xioctl(fd, BLKGETSIZE, &u.blksize32); // returns sectors
1286 *blksize64 = blksize32; 1371 return u.blksize32;
1287 return rc;
1288} 1372}
1289 1373
1290static void print_timing(unsigned t, double e) 1374static void print_timing(unsigned t, double e)
@@ -1303,25 +1387,20 @@ static void do_time(int flag /*,int fd*/)
1303 struct itimerval itv; 1387 struct itimerval itv;
1304 unsigned elapsed, elapsed2; 1388 unsigned elapsed, elapsed2;
1305 unsigned max_iterations, total_MB, iterations; 1389 unsigned max_iterations, total_MB, iterations;
1306 unsigned long long blksize; 1390 char *buf = xmalloc(TIMING_BUF_BYTES);
1307 RESERVE_CONFIG_BUFFER(buf, TIMING_BUF_BYTES);
1308 1391
1309 if (mlock(buf, TIMING_BUF_BYTES)) { 1392 if (mlock(buf, TIMING_BUF_BYTES)) {
1310 bb_perror_msg("mlock"); 1393 bb_perror_msg("mlock");
1311 goto quit2; 1394 goto quit2;
1312 } 1395 }
1313 1396
1314 max_iterations = 1024; 1397 max_iterations = do_blkgetsize() / (2 * 1024) / TIMING_BUF_MB;
1315 if (0 == do_blkgetsize(&blksize)) {
1316 max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB;
1317 }
1318 1398
1319 /* Clear out the device request queues & give them time to complete */ 1399 /* Clear out the device request queues & give them time to complete */
1320 sync(); 1400 sync();
1321 sleep(2); 1401 sleep(2);
1322 if (flag == 0) { /* Time cache */ 1402 if (flag == 0) { /* Time cache */
1323 if (seek_to_zero()) 1403 seek_to_zero();
1324 goto quit;
1325 if (read_big_block(buf)) 1404 if (read_big_block(buf))
1326 goto quit; 1405 goto quit;
1327 printf(" Timing buffer-cache reads: "); 1406 printf(" Timing buffer-cache reads: ");
@@ -1334,12 +1413,13 @@ static void do_time(int flag /*,int fd*/)
1334 * getitimer() is used rather than gettimeofday() because 1413 * getitimer() is used rather than gettimeofday() because
1335 * it is much more consistent (on my machine, at least). 1414 * it is much more consistent (on my machine, at least).
1336 */ 1415 */
1416//TODO: get rid of
1337 setitimer(ITIMER_REAL, &thousand, NULL); 1417 setitimer(ITIMER_REAL, &thousand, NULL);
1338 /* Now do the timing */ 1418 /* Now do the timing */
1339 do { 1419 do {
1340 ++iterations; 1420 ++iterations;
1341 if ((flag == 0) && seek_to_zero()) 1421 if (flag == 0)
1342 goto quit; 1422 seek_to_zero();
1343 if (read_big_block(buf)) 1423 if (read_big_block(buf))
1344 goto quit; 1424 goto quit;
1345 getitimer(ITIMER_REAL, &itv); 1425 getitimer(ITIMER_REAL, &itv);
@@ -1351,8 +1431,7 @@ static void do_time(int flag /*,int fd*/)
1351 /* Now remove the lseek() and getitimer() overheads from the elapsed time */ 1431 /* Now remove the lseek() and getitimer() overheads from the elapsed time */
1352 setitimer(ITIMER_REAL, &thousand, NULL); 1432 setitimer(ITIMER_REAL, &thousand, NULL);
1353 do { 1433 do {
1354 if (seek_to_zero()) 1434 seek_to_zero();
1355 goto quit;
1356 getitimer(ITIMER_REAL, &itv); 1435 getitimer(ITIMER_REAL, &itv);
1357 elapsed2 = (1000 - itv.it_value.tv_sec) * 1000000 1436 elapsed2 = (1000 - itv.it_value.tv_sec) * 1000000
1358 - itv.it_value.tv_usec; 1437 - itv.it_value.tv_usec;
@@ -1365,7 +1444,7 @@ static void do_time(int flag /*,int fd*/)
1365 quit: 1444 quit:
1366 munlock(buf, TIMING_BUF_BYTES); 1445 munlock(buf, TIMING_BUF_BYTES);
1367 quit2: 1446 quit2:
1368 RELEASE_CONFIG_BUFFER(buf); 1447 free(buf);
1369} 1448}
1370 1449
1371#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF 1450#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
@@ -1851,6 +1930,7 @@ static int fromhex(unsigned char c)
1851 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c); 1930 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
1852} 1931}
1853 1932
1933static void identify_from_stdin(void) ATTRIBUTE_NORETURN;
1854static void identify_from_stdin(void) 1934static void identify_from_stdin(void)
1855{ 1935{
1856 uint16_t sbuf[256]; 1936 uint16_t sbuf[256];
@@ -1872,6 +1952,8 @@ static void identify_from_stdin(void)
1872 1952
1873 identify(sbuf); 1953 identify(sbuf);
1874} 1954}
1955#else
1956void identify_from_stdin(void);
1875#endif 1957#endif
1876 1958
1877/* busybox specific stuff */ 1959/* busybox specific stuff */