From 0753f4a15e34149c47ae9a886328803e03289a85 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 7 Jun 2006 00:27:25 +0000 Subject: 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. --- miscutils/hdparm.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'miscutils/hdparm.c') 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 -- cgit v1.2.3