[checkers] handle >512 sector size in readsector0
authorJohn Kingman <kingman@storagegear.com>
Wed, 4 Jul 2007 21:38:53 +0000 (23:38 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Wed, 4 Jul 2007 21:38:53 +0000 (23:38 +0200)
I encountered a problem with the sg_read() routine in readsector0.c
while testing an InfiniBand target having 4096 byte sectors.  The
sg_read() routine assumes that sectors are 512 bytes long.

A patch for the problem follows.

Signed-off-by: Christophe Varoqui <christophe.varoqui@free.fr>
libcheckers/libsg.c
libcheckers/readsector0.c

index f426aaf..9171b10 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <sys/ioctl.h>
 #include <errno.h>
+#include <sys/stat.h>
 
 #include "checkers.h"
 #include "libsg.h"
@@ -25,8 +26,12 @@ sg_read (int sg_fd, unsigned char * buff, unsigned char * senseBuff)
        int res;
        int rd_opcode[] = {0x8, 0x28, 0xa8, 0x88};
        int sz_ind;
+       struct stat filestatus;
        int retry_count = 3;
-       
+
+       if (fstat(sg_fd, &filestatus) != 0)
+               return PATH_DOWN;
+       bs = (filestatus.st_blksize > 4096)? 4096: filestatus.st_blksize;
        memset(rdCmd, 0, cdbsz);
        sz_ind = 1;
        rdCmd[0] = rd_opcode[sz_ind];
index 3cddfa8..bef0eb6 100644 (file)
@@ -26,7 +26,7 @@ void readsector0_free (struct checker * c)
 extern int
 readsector0 (struct checker * c)
 {
-       unsigned char buf[512];
+       unsigned char buf[4096];
        unsigned char sbuf[SENSE_BUFF_LEN];
        int ret;