Commit 091d055b3e6cab13ac3d6b151fcacdcfc059f03e

Authored by balrog
1 parent a60de947

Fix ATAPI GET_CONFIGURATION function (Alexander Graf, Carlo Marcelo Arenas Belon).

The current implementation of GET_CONFIGURATION in the ATAPI stack of qemu
replies a different length depending on the buffer, the data should be
written into.

On the other hand the SCSI spec defines that length information has to be
consistent and independent of return buffer lengths.

This patch makes the ATAPI emulation behave according to the spec and fixes
the Darwin DVD driver.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Kevin Wolf <kwolf@suse.de>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4649 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 12 additions and 15 deletions
hw/ide.c
@@ -1715,6 +1715,7 @@ static void ide_atapi_cmd(IDEState *s) @@ -1715,6 +1715,7 @@ static void ide_atapi_cmd(IDEState *s)
1715 case GPCMD_GET_CONFIGURATION: 1715 case GPCMD_GET_CONFIGURATION:
1716 { 1716 {
1717 uint32_t len; 1717 uint32_t len;
  1718 + uint8_t index = 0;
1718 1719
1719 /* only feature 0 is supported */ 1720 /* only feature 0 is supported */
1720 if (packet[2] != 0 || packet[3] != 0) { 1721 if (packet[2] != 0 || packet[3] != 0) {
@@ -1725,12 +1726,13 @@ static void ide_atapi_cmd(IDEState *s) @@ -1725,12 +1726,13 @@ static void ide_atapi_cmd(IDEState *s)
1725 1726
1726 /* XXX: could result in alignment problems in some architectures */ 1727 /* XXX: could result in alignment problems in some architectures */
1727 max_len = ube16_to_cpu(packet + 7); 1728 max_len = ube16_to_cpu(packet + 7);
  1729 +
1728 /* 1730 /*
1729 - * XXX: avoid overflow for io_buffer if max_len is bigger than the  
1730 - * size of that buffer (dimensioned to max number of sectors  
1731 - * to transfer at once) 1731 + * XXX: avoid overflow for io_buffer if max_len is bigger than
  1732 + * the size of that buffer (dimensioned to max number of
  1733 + * sectors to transfer at once)
1732 * 1734 *
1733 - * Only a problem if the feature/profiles grow exponentially. 1735 + * Only a problem if the feature/profiles grow.
1734 */ 1736 */
1735 if (max_len > 512) /* XXX: assume 1 sector */ 1737 if (max_len > 512) /* XXX: assume 1 sector */
1736 max_len = 512; 1738 max_len = 512;
@@ -1743,22 +1745,17 @@ static void ide_atapi_cmd(IDEState *s) @@ -1743,22 +1745,17 @@ static void ide_atapi_cmd(IDEState *s)
1743 * XXX: fails to detect correctly DVDs with less data burned 1745 * XXX: fails to detect correctly DVDs with less data burned
1744 * than what a CD can hold 1746 * than what a CD can hold
1745 */ 1747 */
1746 - if ((s -> nb_sectors)) {  
1747 - if ((s -> nb_sectors > CD_MAX_SECTORS)) 1748 + if (s -> nb_sectors) {
  1749 + if (s -> nb_sectors > CD_MAX_SECTORS)
1748 cpu_to_ube16(buf + 6, MMC_PROFILE_DVD_ROM); 1750 cpu_to_ube16(buf + 6, MMC_PROFILE_DVD_ROM);
1749 else 1751 else
1750 cpu_to_ube16(buf + 6, MMC_PROFILE_CD_ROM); 1752 cpu_to_ube16(buf + 6, MMC_PROFILE_CD_ROM);
1751 } 1753 }
1752 1754
1753 - len = 8; /* header completed */  
1754 - if (max_len > len) {  
1755 - uint8_t index = 0;  
1756 -  
1757 - buf[10] = 0x02 | 0x01; /* persistent and current */  
1758 - len += 4; /* header */  
1759 - len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_DVD_ROM);  
1760 - len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_CD_ROM);  
1761 - } 1755 + buf[10] = 0x02 | 0x01; /* persistent and current */
  1756 + len = 12; /* headers: 8 + 4 */
  1757 + len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_DVD_ROM);
  1758 + len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_CD_ROM);
1762 cpu_to_ube32(buf, len - 4); /* data length */ 1759 cpu_to_ube32(buf, len - 4); /* data length */
1763 1760
1764 ide_atapi_cmd_reply(s, len, max_len); 1761 ide_atapi_cmd_reply(s, len, max_len);