Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 May 2009 16:18:38 GMT
From:      Alexander Motin <mav@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 162653 for review
Message-ID:  <200905241618.n4OGIcSw061462@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=162653

Change 162653 by mav@mav_mavbook on 2009/05/24 16:18:04

	Add byte-order swap for ATA_IDENTIFY command result.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#2 edit

Differences ...

==== //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#2 (text+ko) ====

@@ -29,6 +29,7 @@
 
 #include <sys/param.h>
 #include <sys/bus.h>
+#include <sys/endian.h>
 #include <sys/systm.h>
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -183,6 +184,50 @@
 }
 
 static void
+bswap(int8_t *buf, int len)
+{
+    u_int16_t *ptr = (u_int16_t*)(buf + len);
+
+    while (--ptr >= (u_int16_t*)buf)
+	*ptr = ntohs(*ptr);
+}
+
+static void
+btrim(int8_t *buf, int len)
+{
+    int8_t *ptr;
+
+    for (ptr = buf; ptr < buf+len; ++ptr)
+	if (!*ptr || *ptr == '_')
+	    *ptr = ' ';
+    for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
+	*ptr = 0;
+}
+
+static void
+bpack(int8_t *src, int8_t *dst, int len)
+{
+    int i, j, blank;
+
+    for (i = j = blank = 0 ; i < len; i++) {
+	if (blank && src[i] == ' ') continue;
+	if (blank && src[i] != ' ') {
+	    dst[j++] = src[i];
+	    blank = 0;
+	    continue;
+	}
+	if (src[i] == ' ') {
+	    blank = 1;
+	    if (i == 0)
+		continue;
+	}
+	dst[j++] = src[i];
+    }
+    if (j < len)
+	dst[j] = 0x00;
+}
+
+static void
 probe_periph_init()
 {
 }
@@ -438,10 +483,30 @@
 	{
 		if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
 			struct ata_params *ident_buf;
+			int16_t *ptr;
 
 			path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
 			ident_buf = &path->device->ident_data;
 
+			for (ptr = (int16_t *)ident_buf;
+			     ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
+				*ptr = le16toh(*ptr);
+			}
+			if (strncmp(ident_buf->model, "FX", 2) &&
+			    strncmp(ident_buf->model, "NEC", 3) &&
+			    strncmp(ident_buf->model, "Pioneer", 7) &&
+			    strncmp(ident_buf->model, "SHARP", 5)) {
+				bswap(ident_buf->model, sizeof(ident_buf->model));
+				bswap(ident_buf->revision, sizeof(ident_buf->revision));
+				bswap(ident_buf->serial, sizeof(ident_buf->serial));
+			}
+			btrim(ident_buf->model, sizeof(ident_buf->model));
+			bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
+			btrim(ident_buf->revision, sizeof(ident_buf->revision));
+			bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
+			btrim(ident_buf->serial, sizeof(ident_buf->serial));
+			bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
+
 			scsi_find_quirk(path->device);
 
 			ata_devise_transport(path);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905241618.n4OGIcSw061462>