From: Rob Landley Date: Wed, 7 Jun 2006 00:27:25 +0000 (-0000) Subject: Callers to identify() converted the endianness of the buffer. So did X-Git-Tag: 1_2_0~203 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0753f4a15e34149c47ae9a886328803e03289a85;p=oweals%2Fbusybox.git 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. --- 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) { printf("\n"); } -/* identify() is the only extern function used across two source files. The - others, though, were declared in hdparm.c with global scope; since other - functions in that file have static (file) scope, I assume the difference is - intentional. */ +// Parse 512 byte disk identification block and print much crap. + static void identify(uint16_t *id_supplied) { uint16_t buf[256]; @@ -581,6 +579,8 @@ static void identify(uint16_t *id_supplied) uint64_t bbbig; /* (:) */ const char *strng; + // Adjust for endianness if necessary. + if (BB_BIG_ENDIAN) { swab(id_supplied, buf, sizeof(buf)); val = buf; @@ -1997,16 +1997,12 @@ static void process_dev(char *devname) if (get_IDentity) { unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */ - unsigned i; memset(args1, 0, sizeof(args1)); args1[0] = WIN_IDENTIFY; args1[3] = 1; - if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) { - uint16_t *ptr = (uint16_t *)args1; - for (i=0; i= 4; ++i) + // Convert the newline-separated hex data into an identify block. + + for (i = 0; i<256; i++) { - sbuf[i] = SWAP_LE16((fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3])); - b += 5; - count -= 5; + int j; + for(j=0;j<4;j++) sbuf[i] = (sbuf[i] <<4) + fromhex(*(b++)); } + + // Parse the data. + identify(sbuf); } #endif