kern

changeset 80:4db99a52863e

fixed the "endianess" of the text messages in the ATA identify info block. this is the first time I've seen wrong byteorder in ascii text, the ATA committee should be commended.
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 06 Dec 2011 13:35:39 +0200
parents 2dda077c1d38
children 9c979413cfbf
files src/ata.c
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/src/ata.c	Tue Dec 06 12:59:38 2011 +0200
     1.2 +++ b/src/ata.c	Tue Dec 06 13:35:39 2011 +0200
     1.3 @@ -55,6 +55,7 @@
     1.4  static inline void write_reg8(struct device *dev, int reg, uint8_t val);
     1.5  static inline void write_reg16(struct device *dev, int reg, uint16_t val);
     1.6  static void ata_intr(int inum);
     1.7 +static void *atastr(void *res, void *src, int n);
     1.8  static char *size_str(uint64_t nsect, char *buf);
     1.9  
    1.10  /* last drive selected on each bus */
    1.11 @@ -125,13 +126,8 @@
    1.12  	read_data(dev, info);
    1.13  
    1.14  	/* print model and serial */
    1.15 -	memcpy(textbuf, info + 27, 40);
    1.16 -	textbuf[40] = 0;
    1.17 -	printf("- found ata drive (%d,%d): %s\n", dev->iface, dev->id, textbuf);
    1.18 -
    1.19 -	memcpy(textbuf, info + 10, 20);
    1.20 -	textbuf[20] = 0;
    1.21 -	printf("  s/n: %s\n", textbuf);
    1.22 +	printf("- found ata drive (%d,%d): %s\n", dev->iface, dev->id, atastr(textbuf, info + 27, 40));
    1.23 +	printf("  s/n: %s\n", atastr(textbuf, info + 10, 20));
    1.24  
    1.25  	dev->nsect_lba = *(uint32_t*)(info + 60);
    1.26  	dev->nsect_lba48 = *(uint64_t*)(info + 100) & 0xffffffffffffull;
    1.27 @@ -231,6 +227,20 @@
    1.28  	printf("ATA interrupt\n");
    1.29  }
    1.30  
    1.31 +static void *atastr(void *res, void *src, int n)
    1.32 +{
    1.33 +	int i;
    1.34 +	uint16_t *sptr = (uint16_t*)src;
    1.35 +	char *dptr = res;
    1.36 +
    1.37 +	for(i=0; i<n/2; i++) {
    1.38 +		*dptr++ = (*sptr & 0xff00) >> 8;
    1.39 +		*dptr++ = *sptr++ & 0xff;
    1.40 +	}
    1.41 +	*dptr = 0;
    1.42 +	return res;
    1.43 +}
    1.44 +
    1.45  static char *size_str(uint64_t nsect, char *buf)
    1.46  {
    1.47  	static const char *suffix[] = {"kb", "mb", "gb", "tb", "pb", 0};