* [Qemu-devel] [PATCH] scsi disk block descriptor v2
@ 2009-10-13 21:46 Artyom Tarasenko
0 siblings, 0 replies; only message in thread
From: Artyom Tarasenko @ 2009-10-13 21:46 UTC (permalink / raw)
To: qemu-devel, Blue Swirl, Krumme, Chris
[-- Attachment #1: Type: text/plain, Size: 2018 bytes --]
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."
v2: limit the number of sectors reported in the block descriptor to 24 bits.
Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
---
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 3940726..2a9268a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -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;
+ nb_sectors--;
+ if (nb_sectors > 0xffffff)
+ nb_sectors = 0xffffff;
+ 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;
[-- Attachment #2: 0001-scsi-disk-block-descriptor.patch --]
[-- Type: application/octet-stream, Size: 1518 bytes --]
Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
---
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 3940726..2a9268a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -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;
+ nb_sectors--;
+ if (nb_sectors > 0xffffff)
+ nb_sectors = 0xffffff;
+ 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;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-10-13 21:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-13 21:46 [Qemu-devel] [PATCH] scsi disk block descriptor v2 Artyom Tarasenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).