diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-03-19 10:53:52 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-03-19 10:53:52 +0000 |
commit | 06d4ec2a4b96ca793a0de124be7dc655378343a1 (patch) | |
tree | 2f8d224932a6ead68c42a5ca87d14c80dac597c7 | |
parent | 16767e2377210fb7489ee4d7d79ad1850c7c932d (diff) | |
download | busybox-w32-06d4ec2a4b96ca793a0de124be7dc655378343a1.tar.gz busybox-w32-06d4ec2a4b96ca793a0de124be7dc655378343a1.tar.bz2 busybox-w32-06d4ec2a4b96ca793a0de124be7dc655378343a1.zip |
Fix broken arg parsing (was not passing pointer to items so p, argc, and argv
were only modified locally). Fix error reporting to properly describe why
ioctls fail.
-rw-r--r-- | miscutils/hdparm.c | 249 |
1 files changed, 117 insertions, 132 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index eaa61c102..099f40fac 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -383,7 +383,7 @@ static const char *cmd_feat_str[] = { | |||
383 | "SET FEATURES subcommand required to spinup after power up", | 383 | "SET FEATURES subcommand required to spinup after power up", |
384 | "Power-Up In Standby feature set", /* word 83 bit 5 */ | 384 | "Power-Up In Standby feature set", /* word 83 bit 5 */ |
385 | "Removable Media Status Notification feature set", | 385 | "Removable Media Status Notification feature set", |
386 | "Advanced Power Management feature set",/* word 83 bit 3 */ | 386 | "Adv. Power Management feature set",/* word 83 bit 3 */ |
387 | "CFA feature set", /* word 83 bit 2 */ | 387 | "CFA feature set", /* word 83 bit 2 */ |
388 | "READ/WRITE DMA QUEUED", /* word 83 bit 1 */ | 388 | "READ/WRITE DMA QUEUED", /* word 83 bit 1 */ |
389 | "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */ | 389 | "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */ |
@@ -473,7 +473,7 @@ const char * const bb_msg_op_not_supp =" operation not supported on %s disks"; | |||
473 | static void bb_ioctl(int fd, int request, void *argp, const char *string) | 473 | static void bb_ioctl(int fd, int request, void *argp, const char *string) |
474 | { | 474 | { |
475 | if (ioctl (fd, request, argp) != 0) | 475 | if (ioctl (fd, request, argp) != 0) |
476 | bb_error_msg(" %s", string); | 476 | bb_perror_msg(" %s", string); |
477 | } | 477 | } |
478 | 478 | ||
479 | static void if_printf(unsigned long i, char *fmt, ... ) | 479 | static void if_printf(unsigned long i, char *fmt, ... ) |
@@ -500,7 +500,7 @@ static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string, | |||
500 | const char * fmt) | 500 | const char * fmt) |
501 | { | 501 | { |
502 | if (ioctl (fd, request, &argp) != 0) | 502 | if (ioctl (fd, request, &argp) != 0) |
503 | bb_error_msg(" %s", string); | 503 | bb_perror_msg(" %s", string); |
504 | else | 504 | else |
505 | { | 505 | { |
506 | printf(fmt, (unsigned long) argp); | 506 | printf(fmt, (unsigned long) argp); |
@@ -556,20 +556,7 @@ static void check_if_maj_and_set_val(uint16_t a, uint16_t b) | |||
556 | a = b; | 556 | a = b; |
557 | } | 557 | } |
558 | 558 | ||
559 | char * check_ptr(char *p, int argc, char **argv) | 559 | static |
560 | { | ||
561 | if (!*p && argc && isdigit(**argv)) | ||
562 | p = *argv++, --argc; | ||
563 | return p; | ||
564 | } | ||
565 | |||
566 | char * check_ptr_v2(char *p, int argc, char **argv) | ||
567 | { | ||
568 | if (!*p && argc && isalnum(**argv)) | ||
569 | p = *argv++, --argc; | ||
570 | return p; | ||
571 | } | ||
572 | |||
573 | unsigned long int set_flag(char *p, char max) | 560 | unsigned long int set_flag(char *p, char max) |
574 | { | 561 | { |
575 | if (*p >= '0' && *p <= max ) | 562 | if (*p >= '0' && *p <= max ) |
@@ -1238,7 +1225,7 @@ static int verbose = 0, get_identity = 0, get_geom = 0, noisy = 1, quiet = 0; | |||
1238 | static int flagcount = 0, do_flush = 0, is_scsi_hd = 0, is_xt_hd = 0; | 1225 | static int flagcount = 0, do_flush = 0, is_scsi_hd = 0, is_xt_hd = 0; |
1239 | static int do_ctimings, do_timings = 0; | 1226 | static int do_ctimings, do_timings = 0; |
1240 | 1227 | ||
1241 | static unsigned long set_readahead= 0, get_readahead= 0, bbreadahead= 0; | 1228 | static unsigned long set_readahead= 0, get_readahead= 0, readahead= 0; |
1242 | static unsigned long set_readonly = 0, get_readonly = 0, readonly = 0; | 1229 | static unsigned long set_readonly = 0, get_readonly = 0, readonly = 0; |
1243 | static unsigned long set_unmask = 0, get_unmask = 0, unmask = 0; | 1230 | static unsigned long set_unmask = 0, get_unmask = 0, unmask = 0; |
1244 | static unsigned long set_mult = 0, get_mult = 0, mult = 0; | 1231 | static unsigned long set_mult = 0, get_mult = 0, mult = 0; |
@@ -1470,7 +1457,7 @@ static void flush_buffer_cache (int fd) | |||
1470 | #ifdef HDIO_DRIVE_CMD | 1457 | #ifdef HDIO_DRIVE_CMD |
1471 | sleep(1); | 1458 | sleep(1); |
1472 | if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ | 1459 | if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ |
1473 | bb_error_msg("HDIO_DRIVE_CMD"); | 1460 | bb_perror_msg("HDIO_DRIVE_CMD"); |
1474 | #endif | 1461 | #endif |
1475 | } | 1462 | } |
1476 | 1463 | ||
@@ -1511,7 +1498,7 @@ static int read_big_block (int fd, char *buf) | |||
1511 | 1498 | ||
1512 | static double correction = 0.0; | 1499 | static double correction = 0.0; |
1513 | 1500 | ||
1514 | void do_time (int flag, int fd) | 1501 | static void do_time (int flag, int fd) |
1515 | /* | 1502 | /* |
1516 | flag = 0 time_cache | 1503 | flag = 0 time_cache |
1517 | flag = 1 time_device | 1504 | flag = 1 time_device |
@@ -1948,8 +1935,8 @@ static void process_dev (char *devname) | |||
1948 | 1935 | ||
1949 | if (set_readahead) | 1936 | if (set_readahead) |
1950 | { | 1937 | { |
1951 | if_printf(get_readahead," setting fs readahead to %ld\n", bbreadahead); | 1938 | if_printf(get_readahead," setting fs readahead to %ld\n", readahead); |
1952 | bb_ioctl(fd, BLKRASET,(int *)bbreadahead,"BLKRASET"); | 1939 | bb_ioctl(fd, BLKRASET,(int *)readahead,"BLKRASET"); |
1953 | } | 1940 | } |
1954 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | 1941 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
1955 | if (unregister_hwif) | 1942 | if (unregister_hwif) |
@@ -2003,7 +1990,7 @@ static void process_dev (char *devname) | |||
2003 | no_xt(); | 1990 | no_xt(); |
2004 | if_printf(get_mult, " setting multcount to %ld\n", mult); | 1991 | if_printf(get_mult, " setting multcount to %ld\n", mult); |
2005 | if(ioctl(fd, HDIO_SET_MULTCOUNT, mult)) | 1992 | if(ioctl(fd, HDIO_SET_MULTCOUNT, mult)) |
2006 | bb_error_msg("HDIO_SET_MULTCOUNT"); | 1993 | bb_perror_msg("HDIO_SET_MULTCOUNT"); |
2007 | #ifndef HDIO_DRIVE_CMD | 1994 | #ifndef HDIO_DRIVE_CMD |
2008 | else | 1995 | else |
2009 | force_operation = 1; | 1996 | force_operation = 1; |
@@ -2150,12 +2137,12 @@ static void process_dev (char *devname) | |||
2150 | if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache); | 2137 | if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache); |
2151 | #ifdef DO_FLUSHCACHE | 2138 | #ifdef DO_FLUSHCACHE |
2152 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) | 2139 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) |
2153 | bb_error_msg ("HDIO_DRIVE_CMD(flushcache)"); | 2140 | bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); |
2154 | #endif /* DO_FLUSHCACHE */ | 2141 | #endif /* DO_FLUSHCACHE */ |
2155 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); | 2142 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); |
2156 | #ifdef DO_FLUSHCACHE | 2143 | #ifdef DO_FLUSHCACHE |
2157 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) | 2144 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) |
2158 | bb_error_msg ("HDIO_DRIVE_CMD(flushcache)"); | 2145 | bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); |
2159 | #endif /* DO_FLUSHCACHE */ | 2146 | #endif /* DO_FLUSHCACHE */ |
2160 | } | 2147 | } |
2161 | if (set_standbynow) | 2148 | if (set_standbynow) |
@@ -2172,7 +2159,7 @@ static void process_dev (char *devname) | |||
2172 | if_printf(get_standbynow," issuing standby command\n"); | 2159 | if_printf(get_standbynow," issuing standby command\n"); |
2173 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) | 2160 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) |
2174 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) | 2161 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) |
2175 | bb_error_msg("HDIO_DRIVE_CMD(standby)"); | 2162 | bb_perror_msg("HDIO_DRIVE_CMD(standby)"); |
2176 | } | 2163 | } |
2177 | if (set_sleepnow) | 2164 | if (set_sleepnow) |
2178 | { | 2165 | { |
@@ -2188,7 +2175,7 @@ static void process_dev (char *devname) | |||
2188 | if_printf(get_sleepnow," issuing sleep command\n"); | 2175 | if_printf(get_sleepnow," issuing sleep command\n"); |
2189 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) | 2176 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) |
2190 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) | 2177 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) |
2191 | bb_error_msg("HDIO_DRIVE_CMD(sleep)"); | 2178 | bb_perror_msg("HDIO_DRIVE_CMD(sleep)"); |
2192 | } | 2179 | } |
2193 | if (set_seagate) | 2180 | if (set_seagate) |
2194 | { | 2181 | { |
@@ -2230,7 +2217,7 @@ static void process_dev (char *devname) | |||
2230 | if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) | 2217 | if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) |
2231 | { | 2218 | { |
2232 | if ((verbose && !is_xt_hd) || get_mult) | 2219 | if ((verbose && !is_xt_hd) || get_mult) |
2233 | bb_error_msg("HDIO_GET_MULTCOUNT"); | 2220 | bb_perror_msg("HDIO_GET_MULTCOUNT"); |
2234 | } | 2221 | } |
2235 | else if (verbose | get_mult) | 2222 | else if (verbose | get_mult) |
2236 | { | 2223 | { |
@@ -2243,7 +2230,7 @@ static void process_dev (char *devname) | |||
2243 | no_scsi(); | 2230 | no_scsi(); |
2244 | no_xt(); | 2231 | no_xt(); |
2245 | if(ioctl(fd, HDIO_GET_32BIT, &parm)) | 2232 | if(ioctl(fd, HDIO_GET_32BIT, &parm)) |
2246 | bb_error_msg("HDIO_GET_32BIT"); | 2233 | bb_perror_msg("HDIO_GET_32BIT"); |
2247 | else | 2234 | else |
2248 | { | 2235 | { |
2249 | printf(" IO_support =%3ld (", parm); | 2236 | printf(" IO_support =%3ld (", parm); |
@@ -2282,7 +2269,7 @@ static void process_dev (char *devname) | |||
2282 | if ((verbose && !is_scsi_hd) || get_dma) { | 2269 | if ((verbose && !is_scsi_hd) || get_dma) { |
2283 | no_scsi(); | 2270 | no_scsi(); |
2284 | if(ioctl(fd, HDIO_GET_DMA, &parm)) | 2271 | if(ioctl(fd, HDIO_GET_DMA, &parm)) |
2285 | bb_error_msg("HDIO_GET_DMA"); | 2272 | bb_perror_msg("HDIO_GET_DMA"); |
2286 | else | 2273 | else |
2287 | { | 2274 | { |
2288 | printf(" using_dma = %2ld", parm); | 2275 | printf(" using_dma = %2ld", parm); |
@@ -2333,13 +2320,13 @@ static void process_dev (char *devname) | |||
2333 | #endif | 2320 | #endif |
2334 | 2321 | ||
2335 | if (ioctl(fd, BLKGETSIZE, &parm)) | 2322 | if (ioctl(fd, BLKGETSIZE, &parm)) |
2336 | bb_error_msg("BLKGETSIZE"); | 2323 | bb_perror_msg("BLKGETSIZE"); |
2337 | #ifdef HDIO_GETGEO_BIG | 2324 | #ifdef HDIO_GETGEO_BIG |
2338 | else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg)) | 2325 | else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg)) |
2339 | printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start); | 2326 | printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start); |
2340 | #endif | 2327 | #endif |
2341 | else if (ioctl(fd, HDIO_GETGEO, &g)) | 2328 | else if (ioctl(fd, HDIO_GETGEO, &g)) |
2342 | bb_error_msg("HDIO_GETGEO"); | 2329 | bb_perror_msg("HDIO_GETGEO"); |
2343 | else | 2330 | else |
2344 | printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start); | 2331 | printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start); |
2345 | } | 2332 | } |
@@ -2409,7 +2396,7 @@ static void process_dev (char *devname) | |||
2409 | else if (errno == -ENOMSG) | 2396 | else if (errno == -ENOMSG) |
2410 | printf(" no identification info available\n"); | 2397 | printf(" no identification info available\n"); |
2411 | else | 2398 | else |
2412 | bb_error_msg("HDIO_GET_IDENTITY"); | 2399 | bb_perror_msg("HDIO_GET_IDENTITY"); |
2413 | } | 2400 | } |
2414 | 2401 | ||
2415 | if (get_IDentity) | 2402 | if (get_IDentity) |
@@ -2425,7 +2412,7 @@ static void process_dev (char *devname) | |||
2425 | args[0] = WIN_PIDENTIFY; | 2412 | args[0] = WIN_PIDENTIFY; |
2426 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | 2413 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) |
2427 | { | 2414 | { |
2428 | bb_error_msg("HDIO_DRIVE_CMD(identify)"); | 2415 | bb_perror_msg("HDIO_DRIVE_CMD(identify)"); |
2429 | goto identify_abort; | 2416 | goto identify_abort; |
2430 | } | 2417 | } |
2431 | } | 2418 | } |
@@ -2454,7 +2441,7 @@ identify_abort: | |||
2454 | { | 2441 | { |
2455 | no_scsi(); | 2442 | no_scsi(); |
2456 | if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) | 2443 | if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) |
2457 | bb_error_msg("HDIO_GET_BUSSTATE"); | 2444 | bb_perror_msg("HDIO_GET_BUSSTATE"); |
2458 | else | 2445 | else |
2459 | { | 2446 | { |
2460 | printf(" busstate = %2ld", parm); | 2447 | printf(" busstate = %2ld", parm); |
@@ -2475,6 +2462,35 @@ identify_abort: | |||
2475 | close (fd); | 2462 | close (fd); |
2476 | } | 2463 | } |
2477 | 2464 | ||
2465 | static char * GET_NUMBER(char *p, unsigned long *flag, unsigned long *num) | ||
2466 | { | ||
2467 | *num = 0; | ||
2468 | while (isdigit(*p)) { | ||
2469 | *flag = 1; | ||
2470 | *num = (*num * 10) + (*p++ - '0'); | ||
2471 | } | ||
2472 | return p; | ||
2473 | } | ||
2474 | |||
2475 | static char * GET_STRING(char *p, unsigned long *flag, int *num) | ||
2476 | { | ||
2477 | char *tmpstr; | ||
2478 | char name[32]; | ||
2479 | tmpstr = name; | ||
2480 | tmpstr[0] = '\0'; | ||
2481 | while (isalnum(*p) && (tmpstr - name) < 31) { | ||
2482 | tmpstr[0] = *p++; | ||
2483 | tmpstr[1] = '\0'; | ||
2484 | ++tmpstr; | ||
2485 | } | ||
2486 | *num = translate_xfermode(name); | ||
2487 | if (*num == -1) | ||
2488 | *flag = 0; | ||
2489 | else | ||
2490 | *flag = 1; | ||
2491 | return p; | ||
2492 | } | ||
2493 | |||
2478 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | 2494 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
2479 | static int fromhex (unsigned char c) | 2495 | static int fromhex (unsigned char c) |
2480 | { | 2496 | { |
@@ -2510,8 +2526,6 @@ int hdparm_main(int argc, char **argv) | |||
2510 | { | 2526 | { |
2511 | const char * const bb_msg_missing_value ="missing value"; | 2527 | const char * const bb_msg_missing_value ="missing value"; |
2512 | char c, *p; | 2528 | char c, *p; |
2513 | char *tmpstr; | ||
2514 | char name[32]; | ||
2515 | /*int neg;*/ | 2529 | /*int neg;*/ |
2516 | 2530 | ||
2517 | ++argv; | 2531 | ++argv; |
@@ -2565,7 +2579,8 @@ int hdparm_main(int argc, char **argv) | |||
2565 | case 'u': | 2579 | case 'u': |
2566 | get_unmask = noisy; | 2580 | get_unmask = noisy; |
2567 | noisy = 1; | 2581 | noisy = 1; |
2568 | p = check_ptr(p,argc,argv); | 2582 | if (!*p && argc && isdigit(**argv)) |
2583 | p = *argv++, --argc; | ||
2569 | if((set_unmask = set_flag(p,'1'))==1) | 2584 | if((set_unmask = set_flag(p,'1'))==1) |
2570 | unmask = *p++ - '0'; | 2585 | unmask = *p++ - '0'; |
2571 | break; | 2586 | break; |
@@ -2573,7 +2588,8 @@ int hdparm_main(int argc, char **argv) | |||
2573 | case 'd': | 2588 | case 'd': |
2574 | get_dma = noisy; | 2589 | get_dma = noisy; |
2575 | noisy = 1; | 2590 | noisy = 1; |
2576 | p = check_ptr(p,argc,argv); | 2591 | if (!*p && argc && isdigit(**argv)) |
2592 | p = *argv++, --argc; | ||
2577 | if((set_dma = set_flag(p,'9'))==1) | 2593 | if((set_dma = set_flag(p,'9'))==1) |
2578 | dma = *p++ - '0'; | 2594 | dma = *p++ - '0'; |
2579 | break; | 2595 | break; |
@@ -2581,65 +2597,47 @@ int hdparm_main(int argc, char **argv) | |||
2581 | case 'n': | 2597 | case 'n': |
2582 | get_nowerr = noisy; | 2598 | get_nowerr = noisy; |
2583 | noisy = 1; | 2599 | noisy = 1; |
2584 | p = check_ptr(p,argc,argv); | 2600 | if (!*p && argc && isdigit(**argv)) |
2601 | p = *argv++, --argc; | ||
2585 | if((set_nowerr = set_flag(p,'1'))==1) | 2602 | if((set_nowerr = set_flag(p,'1'))==1) |
2586 | nowerr = *p++ - '0'; | 2603 | nowerr = *p++ - '0'; |
2587 | break; | 2604 | break; |
2588 | case 'p': | 2605 | case 'p': |
2589 | noisy_piomode = noisy; | 2606 | noisy_piomode = noisy; |
2590 | noisy = 1; | 2607 | noisy = 1; |
2591 | p = check_ptr_v2(p,argc,argv); | 2608 | if (!*p && argc && isalnum(**argv)) |
2592 | tmpstr = name; | 2609 | p = *argv++, --argc; |
2593 | tmpstr[0] = '\0'; | 2610 | p=GET_STRING(p,&set_piomode,&piomode); |
2594 | while (isalnum(*p) && (tmpstr - name) < 31) | ||
2595 | { | ||
2596 | tmpstr[0] = *p++; | ||
2597 | tmpstr[1] = '\0'; | ||
2598 | ++tmpstr; | ||
2599 | } | ||
2600 | piomode = translate_xfermode(name); | ||
2601 | if (piomode == -1) | ||
2602 | set_piomode = 0; | ||
2603 | else | ||
2604 | set_piomode = 1; | ||
2605 | break; | 2611 | break; |
2606 | case 'r': | 2612 | case 'r': |
2607 | get_readonly = noisy; | 2613 | get_readonly = noisy; |
2608 | noisy = 1; | 2614 | noisy = 1; |
2609 | p = check_ptr(p,argc,argv); | 2615 | if (!*p && argc && isdigit(**argv)) |
2616 | p = *argv++, --argc; | ||
2610 | if((set_readonly = set_flag(p,'1'))==1) | 2617 | if((set_readonly = set_flag(p,'1'))==1) |
2611 | readonly = *p++ - '0'; | 2618 | readonly = *p++ - '0'; |
2612 | break; | 2619 | break; |
2613 | case 'm': | 2620 | case 'm': |
2614 | get_mult = noisy; | 2621 | get_mult = noisy; |
2615 | noisy = 1; | 2622 | noisy = 1; |
2616 | p = check_ptr(p,argc,argv); | 2623 | if (!*p && argc && isalnum(**argv)) |
2617 | while (isdigit(*p)) | 2624 | p = *argv++, --argc; |
2618 | { | 2625 | p=GET_NUMBER(p,&set_mult,&mult); |
2619 | set_mult = 1; | ||
2620 | mult = (mult * 10) + (*p++ - '0'); | ||
2621 | } | ||
2622 | break; | 2626 | break; |
2623 | case 'c': | 2627 | case 'c': |
2624 | get_io32bit = noisy; | 2628 | get_io32bit = noisy; |
2625 | noisy = 1; | 2629 | noisy = 1; |
2626 | p = check_ptr(p,argc,argv); | 2630 | if (!*p && argc && isalnum(**argv)) |
2627 | while (isdigit(*p)) | 2631 | p = *argv++, --argc; |
2628 | { | 2632 | p=GET_NUMBER(p,&set_io32bit,&io32bit); |
2629 | set_io32bit = 1; | ||
2630 | io32bit = (io32bit * 10) + (*p++ - '0'); | ||
2631 | } | ||
2632 | break; | 2633 | break; |
2633 | #ifdef HDIO_DRIVE_CMD | 2634 | #ifdef HDIO_DRIVE_CMD |
2634 | case 'S': | 2635 | case 'S': |
2635 | get_standby = noisy; | 2636 | get_standby = noisy; |
2636 | noisy = 1; | 2637 | noisy = 1; |
2637 | p = check_ptr(p,argc,argv); | 2638 | if (!*p && argc && isalnum(**argv)) |
2638 | while (isdigit(*p)) | 2639 | p = *argv++, --argc; |
2639 | { | 2640 | p=GET_NUMBER(p,&set_standby,&standby_requested); |
2640 | set_standby = 1; | ||
2641 | standby_requested = (standby_requested * 10) + (*p++ - '0'); | ||
2642 | } | ||
2643 | if (!set_standby) | 2641 | if (!set_standby) |
2644 | bb_error_msg("-S: %s", bb_msg_missing_value); | 2642 | bb_error_msg("-S: %s", bb_msg_missing_value); |
2645 | break; | 2643 | break; |
@@ -2647,24 +2645,18 @@ int hdparm_main(int argc, char **argv) | |||
2647 | case 'D': | 2645 | case 'D': |
2648 | get_defects = noisy; | 2646 | get_defects = noisy; |
2649 | noisy = 1; | 2647 | noisy = 1; |
2650 | p = check_ptr(p,argc,argv); | 2648 | if (!*p && argc && isalnum(**argv)) |
2651 | while (isdigit(*p)) | 2649 | p = *argv++, --argc; |
2652 | { | 2650 | p=GET_NUMBER(p,&set_defects,&defects); |
2653 | set_defects = 1; | ||
2654 | defects = (defects * 10) + (*p++ - '0'); | ||
2655 | } | ||
2656 | if (!set_defects) | 2651 | if (!set_defects) |
2657 | bb_error_msg("-D: %s", bb_msg_missing_value); | 2652 | bb_error_msg("-D: %s", bb_msg_missing_value); |
2658 | break; | 2653 | break; |
2659 | case 'P': | 2654 | case 'P': |
2660 | get_prefetch = noisy; | 2655 | get_prefetch = noisy; |
2661 | noisy = 1; | 2656 | noisy = 1; |
2662 | p = check_ptr(p,argc,argv); | 2657 | if (!*p && argc && isalnum(**argv)) |
2663 | while (isdigit(*p)) | 2658 | p = *argv++, --argc; |
2664 | { | 2659 | p=GET_NUMBER(p,&set_prefetch,&prefetch); |
2665 | set_prefetch = 1; | ||
2666 | prefetch = (prefetch * 10) + (*p++ - '0'); | ||
2667 | } | ||
2668 | if (!set_prefetch) | 2660 | if (!set_prefetch) |
2669 | bb_error_msg("-P: %s", bb_msg_missing_value); | 2661 | bb_error_msg("-P: %s", bb_msg_missing_value); |
2670 | break; | 2662 | break; |
@@ -2672,20 +2664,9 @@ int hdparm_main(int argc, char **argv) | |||
2672 | case 'X': | 2664 | case 'X': |
2673 | get_xfermode = noisy; | 2665 | get_xfermode = noisy; |
2674 | noisy = 1; | 2666 | noisy = 1; |
2675 | p = check_ptr_v2(p,argc,argv); | 2667 | if (!*p && argc && isalnum(**argv)) |
2676 | tmpstr = name; | 2668 | p = *argv++, --argc; |
2677 | tmpstr[0] = '\0'; | 2669 | p=GET_STRING(p,&set_xfermode,&xfermode_requested); |
2678 | while (isalnum(*p) && (tmpstr - name) < 31) | ||
2679 | { | ||
2680 | tmpstr[0] = *p++; | ||
2681 | tmpstr[1] = '\0'; | ||
2682 | ++tmpstr; | ||
2683 | } | ||
2684 | xfermode_requested = translate_xfermode(name); | ||
2685 | if (xfermode_requested == -1) | ||
2686 | set_xfermode = 0; | ||
2687 | else | ||
2688 | set_xfermode = 1; | ||
2689 | if (!set_xfermode) | 2670 | if (!set_xfermode) |
2690 | bb_error_msg("-X: %s", bb_msg_missing_value); | 2671 | bb_error_msg("-X: %s", bb_msg_missing_value); |
2691 | break; | 2672 | break; |
@@ -2693,7 +2674,8 @@ int hdparm_main(int argc, char **argv) | |||
2693 | case 'K': | 2674 | case 'K': |
2694 | get_dkeep = noisy; | 2675 | get_dkeep = noisy; |
2695 | noisy = 1; | 2676 | noisy = 1; |
2696 | p = check_ptr(p,argc,argv); | 2677 | if (!*p && argc && isdigit(**argv)) |
2678 | p = *argv++, --argc; | ||
2697 | if((set_dkeep = set_flag(p,'1'))==1) | 2679 | if((set_dkeep = set_flag(p,'1'))==1) |
2698 | dkeep = *p++ - '0'; | 2680 | dkeep = *p++ - '0'; |
2699 | else | 2681 | else |
@@ -2703,7 +2685,8 @@ int hdparm_main(int argc, char **argv) | |||
2703 | case 'A': | 2685 | case 'A': |
2704 | get_lookahead = noisy; | 2686 | get_lookahead = noisy; |
2705 | noisy = 1; | 2687 | noisy = 1; |
2706 | p = check_ptr(p,argc,argv); | 2688 | if (!*p && argc && isdigit(**argv)) |
2689 | p = *argv++, --argc; | ||
2707 | if((set_lookahead = set_flag(p,'1'))==1) | 2690 | if((set_lookahead = set_flag(p,'1'))==1) |
2708 | lookahead = *p++ - '0'; | 2691 | lookahead = *p++ - '0'; |
2709 | else | 2692 | else |
@@ -2713,7 +2696,8 @@ int hdparm_main(int argc, char **argv) | |||
2713 | case 'L': | 2696 | case 'L': |
2714 | get_doorlock = noisy; | 2697 | get_doorlock = noisy; |
2715 | noisy = 1; | 2698 | noisy = 1; |
2716 | p = check_ptr(p,argc,argv); | 2699 | if (!*p && argc && isdigit(**argv)) |
2700 | p = *argv++, --argc; | ||
2717 | if((set_doorlock = set_flag(p,'1'))==1) | 2701 | if((set_doorlock = set_flag(p,'1'))==1) |
2718 | doorlock = *p++ - '0'; | 2702 | doorlock = *p++ - '0'; |
2719 | else | 2703 | else |
@@ -2723,7 +2707,8 @@ int hdparm_main(int argc, char **argv) | |||
2723 | case 'W': | 2707 | case 'W': |
2724 | get_wcache = noisy; | 2708 | get_wcache = noisy; |
2725 | noisy = 1; | 2709 | noisy = 1; |
2726 | p = check_ptr(p,argc,argv); | 2710 | if (!*p && argc && isdigit(**argv)) |
2711 | p = *argv++, --argc; | ||
2727 | if((set_wcache = set_flag(p,'1'))==1) | 2712 | if((set_wcache = set_flag(p,'1'))==1) |
2728 | wcache = *p++ - '0'; | 2713 | wcache = *p++ - '0'; |
2729 | else | 2714 | else |
@@ -2760,13 +2745,15 @@ int hdparm_main(int argc, char **argv) | |||
2760 | case 'k': | 2745 | case 'k': |
2761 | get_keep = noisy; | 2746 | get_keep = noisy; |
2762 | noisy = 1; | 2747 | noisy = 1; |
2763 | p = check_ptr(p,argc,argv); | 2748 | if (!*p && argc && isdigit(**argv)) |
2749 | p = *argv++, --argc; | ||
2764 | if((set_keep = set_flag(p,'1'))==1) | 2750 | if((set_keep = set_flag(p,'1'))==1) |
2765 | keep = *p++ - '0'; | 2751 | keep = *p++ - '0'; |
2766 | break; | 2752 | break; |
2767 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | 2753 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
2768 | case 'U': | 2754 | case 'U': |
2769 | p = check_ptr(p,argc,argv); | 2755 | if (!*p && argc && isdigit(**argv)) |
2756 | p = *argv++, --argc; | ||
2770 | if(! p) | 2757 | if(! p) |
2771 | goto error; /* "expected hwif_nr" */ | 2758 | goto error; /* "expected hwif_nr" */ |
2772 | 2759 | ||
@@ -2777,7 +2764,8 @@ int hdparm_main(int argc, char **argv) | |||
2777 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */ | 2764 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */ |
2778 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF | 2765 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
2779 | case 'R': | 2766 | case 'R': |
2780 | p = check_ptr(p,argc,argv); | 2767 | if (!*p && argc && isdigit(**argv)) |
2768 | p = *argv++, --argc; | ||
2781 | if(! p) | 2769 | if(! p) |
2782 | goto error; /* "expected hwif_data" */ | 2770 | goto error; /* "expected hwif_data" */ |
2783 | 2771 | ||
@@ -2804,19 +2792,20 @@ error: | |||
2804 | break; | 2792 | break; |
2805 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */ | 2793 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */ |
2806 | case 'Q': | 2794 | case 'Q': |
2795 | #ifdef HDIO_GET_QDMA | ||
2807 | get_dma_q = noisy; | 2796 | get_dma_q = noisy; |
2808 | noisy = 1; | 2797 | noisy = 1; |
2809 | /* neg = 0; */ | 2798 | #ifdef HDIO_SET_QDMA |
2810 | p = check_ptr(p,argc,argv); | 2799 | if (!*p && argc && isalnum(**argv)) |
2811 | while (isdigit(*p)) | 2800 | p = *argv++, --argc; |
2812 | { | 2801 | p=GET_NUMBER(p,&set_dma_q,&dma_q); |
2813 | set_dma_q = 1; | 2802 | #ifdef HDIO_GET_QDMA |
2814 | dma_q = (dma_q * 10) + (*p++ - '0'); | 2803 | dma_q = -dma_q; |
2815 | } | 2804 | #endif |
2816 | /* what is this for ? as neg = 0 (see above) it seems to do nothing */ | 2805 | #endif |
2817 | /*if (neg) | 2806 | #endif |
2818 | dma_q = -dma_q;*/ | ||
2819 | break; | 2807 | break; |
2808 | |||
2820 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET | 2809 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET |
2821 | case 'w': | 2810 | case 'w': |
2822 | perform_reset = 1; | 2811 | perform_reset = 1; |
@@ -2824,7 +2813,8 @@ error: | |||
2824 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ | 2813 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
2825 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | 2814 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
2826 | case 'x': | 2815 | case 'x': |
2827 | p = check_ptr(p,argc,argv); | 2816 | if (!*p && argc && isdigit(**argv)) |
2817 | p = *argv++, --argc; | ||
2828 | if((perform_tristate = set_flag(p,'1'))==1) | 2818 | if((perform_tristate = set_flag(p,'1'))==1) |
2829 | tristate = *p++ - '0'; | 2819 | tristate = *p++ - '0'; |
2830 | else | 2820 | else |
@@ -2835,22 +2825,16 @@ error: | |||
2835 | case 'a': | 2825 | case 'a': |
2836 | get_readahead = noisy; | 2826 | get_readahead = noisy; |
2837 | noisy = 1; | 2827 | noisy = 1; |
2838 | p = check_ptr(p,argc,argv); | 2828 | if (!*p && argc && isalnum(**argv)) |
2839 | while (isdigit(*p)) | 2829 | p = *argv++, --argc; |
2840 | { | 2830 | p=GET_NUMBER(p,&set_readahead,&readahead); |
2841 | set_readahead = 1; | ||
2842 | bbreadahead = (bbreadahead * 10) + (*p++ - '0'); | ||
2843 | } | ||
2844 | break; | 2831 | break; |
2845 | case 'B': | 2832 | case 'B': |
2846 | get_apmmode = noisy; | 2833 | get_apmmode = noisy; |
2847 | noisy = 1; | 2834 | noisy = 1; |
2848 | p = check_ptr(p,argc,argv); | 2835 | if (!*p && argc && isalnum(**argv)) |
2849 | while (isdigit(*p)) | 2836 | p = *argv++, --argc; |
2850 | { | 2837 | p=GET_NUMBER(p,&set_apmmode,&apmmode); |
2851 | set_apmmode = 1; | ||
2852 | apmmode = (io32bit * 10) + (*p++ - '0'); | ||
2853 | } | ||
2854 | if (!set_apmmode) | 2838 | if (!set_apmmode) |
2855 | printf("-B: %s (1-255)", bb_msg_missing_value); | 2839 | printf("-B: %s (1-255)", bb_msg_missing_value); |
2856 | break; | 2840 | break; |
@@ -2866,7 +2850,8 @@ error: | |||
2866 | case 'b': | 2850 | case 'b': |
2867 | get_busstate = noisy; | 2851 | get_busstate = noisy; |
2868 | noisy = 1; | 2852 | noisy = 1; |
2869 | p = check_ptr(p,argc,argv); | 2853 | if (!*p && argc && isdigit(**argv)) |
2854 | p = *argv++, --argc; | ||
2870 | if((set_busstate = set_flag(p,'2'))==1) | 2855 | if((set_busstate = set_flag(p,'2'))==1) |
2871 | busstate = *p++ - '0'; | 2856 | busstate = *p++ - '0'; |
2872 | break; | 2857 | break; |
@@ -2878,9 +2863,9 @@ error: | |||
2878 | } | 2863 | } |
2879 | if (!argc) | 2864 | if (!argc) |
2880 | bb_show_usage(); | 2865 | bb_show_usage(); |
2881 | } | 2866 | } else { |
2882 | else | ||
2883 | process_dev (p); | 2867 | process_dev (p); |
2868 | } | ||
2884 | } | 2869 | } |
2885 | return 0 ; | 2870 | return 0 ; |
2886 | } | 2871 | } |