aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/hdparm.c90
1 files changed, 42 insertions, 48 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 33f05be0c..911688f46 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -465,12 +465,23 @@ static const char * const secu_str[] = {
465static const char bb_msg_shared_mem[] = "could not %s sharedmem buf"; 465static const char bb_msg_shared_mem[] = "could not %s sharedmem buf";
466static const char bb_msg_op_not_supp[] = " operation not supported on %s disks"; 466static const char bb_msg_op_not_supp[] = " operation not supported on %s disks";
467 467
468static void bb_ioctl(int fd, int request, void *argp, const char *string) 468static int bb_ioctl(int fd, int request, void *argp, const char *string)
469{ 469{
470 if (ioctl (fd, request, argp) != 0) 470 int e = ioctl(fd, request, argp);
471 if (e && string)
471 bb_perror_msg(" %s", string); 472 bb_perror_msg(" %s", string);
473 return e;
472} 474}
473 475
476static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string)
477{
478 if (!ioctl(fd, cmd, args))
479 return 0;
480 args[0] = alt;
481 return bb_ioctl(fd, cmd, args, string);
482}
483
484
474static void if_printf(unsigned long i, char *fmt, ... ) 485static void if_printf(unsigned long i, char *fmt, ... )
475{ 486{
476 va_list ap; 487 va_list ap;
@@ -1454,7 +1465,7 @@ static void flush_buffer_cache (int fd)
1454#ifdef HDIO_DRIVE_CMD 1465#ifdef HDIO_DRIVE_CMD
1455 sleep(1); 1466 sleep(1);
1456 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ 1467 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
1457 bb_perror_msg("HDIO_DRIVE_CMD"); 1468 bb_perror_msg("HDIO_DRIVE_CMD");
1458#endif 1469#endif
1459} 1470}
1460 1471
@@ -2116,13 +2127,13 @@ static void process_dev (char *devname)
2116 args[2] = wcache ? 0x02 : 0x82; 2127 args[2] = wcache ? 0x02 : 0x82;
2117 if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache); 2128 if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache);
2118#ifdef DO_FLUSHCACHE 2129#ifdef DO_FLUSHCACHE
2119 if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) 2130 if (!wcache)
2120 bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); 2131 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
2121#endif /* DO_FLUSHCACHE */ 2132#endif /* DO_FLUSHCACHE */
2122 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); 2133 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
2123#ifdef DO_FLUSHCACHE 2134#ifdef DO_FLUSHCACHE
2124 if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) 2135 if (!wcache)
2125 bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); 2136 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
2126#endif /* DO_FLUSHCACHE */ 2137#endif /* DO_FLUSHCACHE */
2127 } 2138 }
2128 if (set_standbynow) 2139 if (set_standbynow)
@@ -2133,13 +2144,10 @@ static void process_dev (char *devname)
2133#ifndef WIN_STANDBYNOW2 2144#ifndef WIN_STANDBYNOW2
2134#define WIN_STANDBYNOW2 0x94 2145#define WIN_STANDBYNOW2 0x94
2135#endif 2146#endif
2136 static unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0};
2137 static unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0};
2138 no_scsi(); 2147 no_scsi();
2139 if_printf(get_standbynow," issuing standby command\n"); 2148 if_printf(get_standbynow," issuing standby command\n");
2140 if (ioctl(fd, HDIO_DRIVE_CMD, &args1) 2149 args[0] = WIN_STANDBYNOW1;
2141 && ioctl(fd, HDIO_DRIVE_CMD, &args2)) 2150 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)");
2142 bb_perror_msg("HDIO_DRIVE_CMD(standby)");
2143 } 2151 }
2144 if (set_sleepnow) 2152 if (set_sleepnow)
2145 { 2153 {
@@ -2149,13 +2157,10 @@ static void process_dev (char *devname)
2149#ifndef WIN_SLEEPNOW2 2157#ifndef WIN_SLEEPNOW2
2150#define WIN_SLEEPNOW2 0x99 2158#define WIN_SLEEPNOW2 0x99
2151#endif 2159#endif
2152 static unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0};
2153 static unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0};
2154 no_scsi(); 2160 no_scsi();
2155 if_printf(get_sleepnow," issuing sleep command\n"); 2161 if_printf(get_sleepnow," issuing sleep command\n");
2156 if (ioctl(fd, HDIO_DRIVE_CMD, &args1) 2162 args[0] = WIN_SLEEPNOW1;
2157 && ioctl(fd, HDIO_DRIVE_CMD, &args2)) 2163 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)");
2158 bb_perror_msg("HDIO_DRIVE_CMD(sleep)");
2159 } 2164 }
2160 if (set_seagate) 2165 if (set_seagate)
2161 { 2166 {
@@ -2207,9 +2212,7 @@ static void process_dev (char *devname)
2207 if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit) 2212 if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit)
2208 { 2213 {
2209 no_scsi_no_xt(); 2214 no_scsi_no_xt();
2210 if(ioctl(fd, HDIO_GET_32BIT, &parm)) 2215 if(!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT"))
2211 bb_perror_msg("HDIO_GET_32BIT");
2212 else
2213 { 2216 {
2214 printf(" IO_support =%3ld (", parm); 2217 printf(" IO_support =%3ld (", parm);
2215 switch (parm) 2218 switch (parm)
@@ -2245,9 +2248,7 @@ static void process_dev (char *devname)
2245#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA 2248#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
2246 if ((verbose && !is_scsi_hd) || get_dma) { 2249 if ((verbose && !is_scsi_hd) || get_dma) {
2247 no_scsi(); 2250 no_scsi();
2248 if(ioctl(fd, HDIO_GET_DMA, &parm)) 2251 if(!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA"))
2249 bb_perror_msg("HDIO_GET_DMA");
2250 else
2251 { 2252 {
2252 printf(" using_dma = %2ld", parm); 2253 printf(" using_dma = %2ld", parm);
2253 if (parm == 8) 2254 if (parm == 8)
@@ -2294,16 +2295,16 @@ static void process_dev (char *devname)
2294 static struct hd_big_geometry bg; 2295 static struct hd_big_geometry bg;
2295#endif 2296#endif
2296 2297
2297 if (ioctl(fd, BLKGETSIZE, &parm)) 2298 if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE"))
2298 bb_perror_msg("BLKGETSIZE"); 2299 {
2299#ifdef HDIO_GETGEO_BIG 2300#ifdef HDIO_GETGEO_BIG
2300 else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg)) 2301 if (!bb_ioctl(fd, HDIO_GETGEO_BIG, &bg, "HDIO_GETGEO_BIG"))
2301 printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start); 2302 printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start);
2303 else
2302#endif 2304#endif
2303 else if (ioctl(fd, HDIO_GETGEO, &g)) 2305 if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO"))
2304 bb_perror_msg("HDIO_GETGEO"); 2306 printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start);
2305 else 2307 }
2306 printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start);
2307 } 2308 }
2308#ifdef HDIO_DRIVE_CMD 2309#ifdef HDIO_DRIVE_CMD
2309 if (get_powermode) 2310 if (get_powermode)
@@ -2315,11 +2316,10 @@ static void process_dev (char *devname)
2315#define WIN_CHECKPOWERMODE2 0x98 2316#define WIN_CHECKPOWERMODE2 0x98
2316#endif 2317#endif
2317 const char *state; 2318 const char *state;
2319
2318 no_scsi(); 2320 no_scsi();
2319 args[0] = WIN_CHECKPOWERMODE1; 2321 args[0] = WIN_CHECKPOWERMODE1;
2320 if (ioctl(fd, HDIO_DRIVE_CMD, &args) 2322 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0))
2321 && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
2322 && ioctl(fd, HDIO_DRIVE_CMD, &args))
2323 { 2323 {
2324 if (errno != EIO || args[0] != 0 || args[1] != 0) 2324 if (errno != EIO || args[0] != 0 || args[1] != 0)
2325 state = "unknown"; 2325 state = "unknown";
@@ -2374,23 +2374,19 @@ static void process_dev (char *devname)
2374 2374
2375 if (get_IDentity) 2375 if (get_IDentity)
2376 { 2376 {
2377 unsigned char args1[4+512] = {WIN_IDENTIFY,0,0,1,}; 2377 unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
2378 unsigned i; 2378 unsigned i;
2379 2379
2380 no_scsi_no_xt(); 2380 no_scsi_no_xt();
2381 2381
2382 if (ioctl(fd, HDIO_DRIVE_CMD, &args1)) 2382 memset(args1, 0, sizeof(args1));
2383 { 2383 args1[0] = WIN_IDENTIFY;
2384 args[0] = WIN_PIDENTIFY; 2384 args1[3] = 1;
2385 if (ioctl(fd, HDIO_DRIVE_CMD, &args1)) 2385 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)"))
2386 { 2386 goto identify_abort;
2387 bb_perror_msg("HDIO_DRIVE_CMD(identify)"); 2387
2388 goto identify_abort;
2389 }
2390 }
2391 for(i=0; i<(sizeof args1)/2; i+=2) 2388 for(i=0; i<(sizeof args1)/2; i+=2)
2392 __le16_to_cpus((uint16_t *)(&args1[i])); 2389 __le16_to_cpus((uint16_t *)(&args1[i]));
2393
2394 identify((void *)&args1[4], NULL); 2390 identify((void *)&args1[4], NULL);
2395identify_abort: 2391identify_abort:
2396 /* VOID */; 2392 /* VOID */;
@@ -2412,9 +2408,7 @@ identify_abort:
2412 if (get_busstate) 2408 if (get_busstate)
2413 { 2409 {
2414 no_scsi(); 2410 no_scsi();
2415 if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) 2411 if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE"))
2416 bb_perror_msg("HDIO_GET_BUSSTATE");
2417 else
2418 { 2412 {
2419 printf(" busstate = %2ld", parm); 2413 printf(" busstate = %2ld", parm);
2420 bus_state_value(parm); 2414 bus_state_value(parm);