diff options
author | Rob Landley <rob@landley.net> | 2006-06-07 00:27:25 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-06-07 00:27:25 +0000 |
commit | 0753f4a15e34149c47ae9a886328803e03289a85 (patch) | |
tree | 6e81da9d85a76e0d01366b5eeb415d848bb4a997 | |
parent | eb29d6ce6a097893b4f476967122686f588c8d09 (diff) | |
download | busybox-w32-0753f4a15e34149c47ae9a886328803e03289a85.tar.gz busybox-w32-0753f4a15e34149c47ae9a886328803e03289a85.tar.bz2 busybox-w32-0753f4a15e34149c47ae9a886328803e03289a85.zip |
Callers to identify() converted the endianness of the buffer. So did
identify(). This meant big endian systems had a NUXI problem. Removed
the redundant conversion from the callers, and made some in-passing cleanups
while I was there.
-rw-r--r-- | miscutils/hdparm.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 24962dd25..5ac7bdcb7 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -565,10 +565,8 @@ static void print_ascii(uint16_t *p, uint8_t length) { | |||
565 | printf("\n"); | 565 | printf("\n"); |
566 | } | 566 | } |
567 | 567 | ||
568 | /* identify() is the only extern function used across two source files. The | 568 | // Parse 512 byte disk identification block and print much crap. |
569 | others, though, were declared in hdparm.c with global scope; since other | 569 | |
570 | functions in that file have static (file) scope, I assume the difference is | ||
571 | intentional. */ | ||
572 | static void identify(uint16_t *id_supplied) | 570 | static void identify(uint16_t *id_supplied) |
573 | { | 571 | { |
574 | uint16_t buf[256]; | 572 | uint16_t buf[256]; |
@@ -581,6 +579,8 @@ static void identify(uint16_t *id_supplied) | |||
581 | uint64_t bbbig; /* (:) */ | 579 | uint64_t bbbig; /* (:) */ |
582 | const char *strng; | 580 | const char *strng; |
583 | 581 | ||
582 | // Adjust for endianness if necessary. | ||
583 | |||
584 | if (BB_BIG_ENDIAN) { | 584 | if (BB_BIG_ENDIAN) { |
585 | swab(id_supplied, buf, sizeof(buf)); | 585 | swab(id_supplied, buf, sizeof(buf)); |
586 | val = buf; | 586 | val = buf; |
@@ -1997,16 +1997,12 @@ static void process_dev(char *devname) | |||
1997 | if (get_IDentity) | 1997 | if (get_IDentity) |
1998 | { | 1998 | { |
1999 | unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */ | 1999 | unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */ |
2000 | unsigned i; | ||
2001 | 2000 | ||
2002 | memset(args1, 0, sizeof(args1)); | 2001 | memset(args1, 0, sizeof(args1)); |
2003 | args1[0] = WIN_IDENTIFY; | 2002 | args1[0] = WIN_IDENTIFY; |
2004 | args1[3] = 1; | 2003 | args1[3] = 1; |
2005 | if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) { | 2004 | if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) |
2006 | uint16_t *ptr = (uint16_t *)args1; | 2005 | identify((void *)(args1 + 4)); |
2007 | for (i=0; i<sizeof(args1)/2; i++) ptr[i] = SWAP_LE16(ptr[i]); | ||
2008 | identify((void *)(ptr+2)); | ||
2009 | } | ||
2010 | } | 2006 | } |
2011 | #endif | 2007 | #endif |
2012 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | 2008 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
@@ -2053,19 +2049,23 @@ static int fromhex(unsigned char c) | |||
2053 | 2049 | ||
2054 | static void identify_from_stdin(void) | 2050 | static void identify_from_stdin(void) |
2055 | { | 2051 | { |
2056 | uint16_t sbuf[800]; | 2052 | uint16_t sbuf[256]; |
2057 | unsigned char buf[1600], *b = (unsigned char *)buf; | 2053 | unsigned char buf[1280], *b = (unsigned char *)buf; |
2058 | int i, count = read(0, buf, 1280); | 2054 | int i, count = read(0, buf, 1280); |
2059 | 2055 | ||
2060 | if (count != 1280) | 2056 | if (count != 1280) |
2061 | bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count); | 2057 | bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count); |
2062 | 2058 | ||
2063 | for (i = 0; count >= 4; ++i) | 2059 | // Convert the newline-separated hex data into an identify block. |
2060 | |||
2061 | for (i = 0; i<256; i++) | ||
2064 | { | 2062 | { |
2065 | sbuf[i] = SWAP_LE16((fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3])); | 2063 | int j; |
2066 | b += 5; | 2064 | for(j=0;j<4;j++) sbuf[i] = (sbuf[i] <<4) + fromhex(*(b++)); |
2067 | count -= 5; | ||
2068 | } | 2065 | } |
2066 | |||
2067 | // Parse the data. | ||
2068 | |||
2069 | identify(sbuf); | 2069 | identify(sbuf); |
2070 | } | 2070 | } |
2071 | #endif | 2071 | #endif |