[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#243310: discover: Unaligned traps when executed on alpha



tags  + patch
thanks

According to
<URL:http://www.tldp.org/HOWTO/SCSI-Generic-HOWTO/scsi_g_idlun.html>,
the code in disk.c is broken.  It assumes that 'unsigned long int' is
4 bytes, and that idlun[0] is the least significant bits in the int.
Neither is true on all archs.

here is a patch to implement the reading using a struct, and without
casting to a pointer with higher aligment requirement.  This should
get it working on alpha, and keep it working on all archs.

I'm assuming here that the info given at the URL above is correct.  I
have no knowledge about SCSI ioctl()s in the linux kernel. :)

--- disk.c.~1.1.1.1.~	Wed Dec 31 01:12:54 2003
+++ disk.c	Sun May  2 22:01:23 2004
@@ -38,7 +38,16 @@
   struct disk_info *result = (struct disk_info *)NULL;
   static struct disk_info *first = (struct disk_info *)NULL;
   int fd;
-  unsigned char idlun[8];
+
+  /*
+   * struct copied from
+   * <URL:http://www.tldp.org/HOWTO/SCSI-Generic-HOWTO/scsi_g_idlun.html>
+   */
+  struct {
+    int four_in_one;    /* 4 separate bytes of info compacted into 1 int */
+    int host_unique_id; /* distinguishes adapter cards from same supplier */
+  } idlun;
+
   struct hd_geometry geometry;
    
   if(first){
@@ -117,8 +126,8 @@
           result->cylinders = geometry.cylinders;
           result->size = result->sectors * result->cylinders * 
                                                           result->heads;
-          result->did = idlun[0];
-          result->host = *((unsigned long *) (idlun + 4));
+          result->did = (idlun.four_in_one & 0xff);
+          result->host = idlun.host_unique_id;
         }/*endif*/
         close(fd);
       }/*endif*/




Reply to: