Skip to contentSkip to conversation

scsi disk block descriptor

PATCH In review Artyom Tarasenko 2 participants 3 messages Oct 13, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi disk block descriptor

The SCSI-2 documentation suggests, that although the block descriptor is optional for an arbitrary SCSI-2 device (chapter 8.2.10,
http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2/SCSI2-08.html ) it is mandatory for a disk: chapters 9.1.2, 9.3.3
( http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-09.html ) don't say "optional" any more, just "The block descriptor in the MODE SENSE data describes the block lengths that are used on the medium."

---

hw/scsi-disk.c +0 -0
index 3940726..b703379 100644
@@ -624,7 +624,9 @@ static int32_t scsi_send_command(SCSIDevice *d,

uint32_t tag,

         {
             uint8_t *p;
             int page;
-
+            int dbd;
+
+            dbd = buf[1]  & 0x8;
             page = buf[2] & 0x3f;
             DPRINTF("Mode Sense (page %d, len %d)\n", page, len);
             p = outbuf;
@@ -635,6 +637,24 @@ static int32_t scsi_send_command(SCSIDevice *d,
uint32_t tag,
                 outbuf[2] = 0x80; /* Readonly.  */
             }
             p += 4;

+ bdrv_get_geometry(s->dinfo->bdrv, &nb_sectors);
+ if ((~dbd) & nb_sectors) {
+ nb_sectors /= s->cluster_size;
+ if (nb_sectors > UINT32_MAX)
+ nb_sectors = UINT32_MAX;

+                nb_sectors--;
+                outbuf[3] = 8; /* Block descriptor length  */
+                p[0] = 0; /* media density code */
+                p[1] = (nb_sectors >> 16) & 0xff;
+                p[2] = (nb_sectors >> 8) & 0xff;
+                p[3] = nb_sectors & 0xff;
+                p[4] = 0; /* reserved */
+                p[5] = 0; /* bytes 5-7 are the sector size in bytes */
+                p[6] = s->cluster_size * 2;
+                p[7] = 0;
+                p += 8;
+            }
+
             if (page == 4) {
                 int cylinders, heads, secs;

---

hw/scsi-disk.c +21 -1
index 3940726..b703379 100644
@@ -624,7 +624,9 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
         {
             uint8_t *p;
             int page;
-
+            int dbd;
+            
+            dbd = buf[1]  & 0x8;
             page = buf[2] & 0x3f;
             DPRINTF("Mode Sense (page %d, len %d)\n", page, len);
             p = outbuf;
@@ -635,6 +637,24 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
                 outbuf[2] = 0x80; /* Readonly.  */
             }
             p += 4;
+            bdrv_get_geometry(s->dinfo->bdrv, &nb_sectors);
+            if ((~dbd) & nb_sectors) {
+                nb_sectors /= s->cluster_size;
+                if (nb_sectors > UINT32_MAX)
+                    nb_sectors = UINT32_MAX;
+                nb_sectors--;
+                outbuf[3] = 8; /* Block descriptor length  */
+                p[0] = 0; /* media density code */
+                p[1] = (nb_sectors >> 16) & 0xff;
+                p[2] = (nb_sectors >> 8) & 0xff;
+                p[3] = nb_sectors & 0xff;
+                p[4] = 0; /* reserved */
+                p[5] = 0; /* bytes 5-7 are the sector size in bytes */
+                p[6] = s->cluster_size * 2;
+                p[7] = 0;
+                p += 8;
+            }
+
             if (page == 4) {
                 int cylinders, heads, secs;
 
#1 lore raw
Quoted 43 lines

-----Original Message-----
From:
[email protected] [mailto:[email protected] rg] On Behalf Of Artyom Tarasenko
Sent: Tuesday, October 13, 2009 3:20 PM
To: qemu-devel; Blue Swirl
Subject: [Qemu-devel] [PATCH] scsi disk block descriptor

The SCSI-2 documentation suggests, that although the block descriptor is optional for an arbitrary SCSI-2 device (chapter 8.2.10,
http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2/SCSI2-08.html ) it is mandatory for a disk: chapters 9.1.2, 9.3.3
( http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-09.html ) don't say "optional" any more, just "The block descriptor in the MODE SENSE data describes the block lengths that are used on the medium."

---

hw/scsi-disk.c +3 -1
index 3940726..b703379 100644
@@ -624,7 +624,9 @@ static int32_t scsi_send_command(SCSIDevice *d,
 uint32_t tag,
         {
             uint8_t *p;
             int page;
-
+            int dbd;
+
+            dbd = buf[1]  & 0x8;
             page = buf[2] & 0x3f;
             DPRINTF("Mode Sense (page %d, len %d)\n", page, len);
             p = outbuf;
hw/scsi-disk.c +1 -0
@@ -635,6 +637,24 @@ static int32_t scsi_send_command(SCSIDevice *d,
 uint32_t tag,
                 outbuf[2] = 0x80; /* Readonly.  */
             }
             p += 4;
+            bdrv_get_geometry(s->dinfo->bdrv, &nb_sectors);

hw/scsi-disk.c static int32_t scsi_send_command(SCSIDevice *d, · line 651

Quoted 10 lines
hw/scsi-disk.c +10 -0
+            if ((~dbd) & nb_sectors) {
+                nb_sectors /= s->cluster_size;
+                if (nb_sectors > UINT32_MAX)
+                    nb_sectors = UINT32_MAX;
+                nb_sectors--;
+                outbuf[3] = 8; /* Block descriptor length  */
+                p[0] = 0; /* media density code */
+                p[1] = (nb_sectors >> 16) & 0xff;
+                p[2] = (nb_sectors >> 8) & 0xff;
+                p[3] = nb_sectors & 0xff;

Hello Artyom,

Above you limit to 32 bits - 1, then you use the bottom 24 bits. Would it be better to limit to 24 bits - 1, then a drive with more than 24 bits of sectors will show as maximum size rather than a random size?

Thanks

Chris

Quoted 11 lines
hw/scsi-disk.c +2 -0
+                p[4] = 0; /* reserved */
+                p[5] = 0; /* bytes 5-7 are the sector size 

in bytes */

hw/scsi-disk.c +5 -0
+                p[6] = s->cluster_size * 2;
+                p[7] = 0;
+                p += 8;
+            }
+
             if (page == 4) {
                 int cylinders, heads, secs;
#2 lore raw

2009/10/13 Krumme, Chris <[email protected]>:

Quoted 56 lines
Quoted 45 lines

-----Original Message-----
From:
[email protected] [mailto:[email protected] rg] On Behalf Of Artyom Tarasenko
Sent: Tuesday, October 13, 2009 3:20 PM
To: qemu-devel; Blue Swirl
Subject: [Qemu-devel] [PATCH] scsi disk block descriptor

The SCSI-2 documentation suggests, that although the block descriptor is optional for an arbitrary SCSI-2 device (chapter 8.2.10,
http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2/SCSI2-08.html ) it is mandatory for a disk: chapters 9.1.2, 9.3.3
( http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-09.html ) don't say "optional" any more, just "The block descriptor in the MODE SENSE data describes the block lengths that are used on the medium."

---

hw/scsi-disk.c +3 -1
index 3940726..b703379 100644
@@ -624,7 +624,9 @@ static int32_t scsi_send_command(SCSIDevice *d,
 uint32_t tag,
          {
              uint8_t *p;
              int page;
-
+            int dbd;
+
+            dbd = buf[1]  & 0x8;
              page = buf[2] & 0x3f;
              DPRINTF("Mode Sense (page %d, len %d)\n", page, len);

             p = outbuf;

hw/scsi-disk.c +0 -0
@@ -635,6 +637,24 @@ static int32_t scsi_send_command(SCSIDevice *d,
 uint32_t tag,

                 outbuf[2] = 0x80; /* Readonly.  */ }
             p += 4;
+            bdrv_get_geometry(s->dinfo->bdrv, &nb_sectors);
+            if ((~dbd) & nb_sectors) {
+                nb_sectors /= s->cluster_size;

Quoted 8 lines

+                if (nb_sectors > UINT32_MAX)
+                    nb_sectors = UINT32_MAX;
+                nb_sectors--;
+                outbuf[3] = 8; /* Block descriptor length  */
+                p[0] = 0; /* media density code */
+                p[1] = (nb_sectors >> 16) & 0xff;
+                p[2] = (nb_sectors >> 8) & 0xff;
+                p[3] = nb_sectors & 0xff;

Hello Artyom,

Quoted 3 lines

Above you limit to 32 bits - 1, then you use the bottom 24 bits.  Would it be better to limit to 24 bits - 1, then a drive with more than 24 bits of sectors will show as maximum size rather than a random size?

Thanks, Chris!